Re: [PATCH v4 linux-kselftest-test 5/6] kunit: allow kunit to be loaded as a module
From: Alan Maguire
Date: Wed Nov 20 2019 - 08:49:39 EST
On Tue, 19 Nov 2019, Stephen Boyd wrote:
> Quoting Alan Maguire (2019-11-15 02:16:11)
> > diff --git a/lib/kunit/test.c b/lib/kunit/test.c
> > index 87b5cf1..41ef71a 100644
> > --- a/lib/kunit/test.c
> > +++ b/lib/kunit/test.c
> > @@ -486,3 +486,16 @@ void kunit_cleanup(struct kunit *test)
> > }
> > }
> > EXPORT_SYMBOL_GPL(kunit_cleanup);
> > +
> > +static int kunit_init(void)
>
> Missing __init?
>
Oops, will fix.
> > +{
> > + return 0;
> > +}
> > +late_initcall(kunit_init);
>
> It looks pretty weird that this doesn't do anything in the module init
> or exit path. How does it work? And why does it need to be late init if
> nothing is called from here?
>
I used a late_initcall() here because if there is initialization code in
the future (say setting up debugfs, sysctl tables etc), it will get run
irrespective of whether kunit is built as a module or not. For the module
case, we need init/exit to ensure the module can be unloaded
successfully.
> > +
> > +static void __exit kunit_exit(void)
> > +{
> > +}
> > +module_exit(kunit_exit);
> > +
> > +MODULE_LICENSE("GPL");
>
> I guess should be "GPL v2"?
>
Good catch, will fix here and elsewhere, thanks!
BTW in replying to your review of patch 1 I made a mistake; we do in fact
need to add the "#include <linux/kernel.h>" in assert.h as we are removing
the "#include <kunit/string-stream.h>". The latter indirectly includes
linux/kernel.h which allows us to find definition for "struct va_format"
used in the struct kunit_assert definition. Apologies about this.
I'll have a go at generating v5 using -C as requested. Thanks again for
the careful review!
Alan