Message ID | 20231204221932.1465004-3-rmoar@google.com |
---|---|
State | New |
Headers | show |
Series | [v3,1/6] kunit: move KUNIT_TABLE out of INIT_DATA | expand |
On Tue, 5 Dec 2023 at 06:19, Rae Moar <rmoar@google.com> wrote: > > Add example_init_test_suite to allow for testing the feature of running > test suites marked as init to indicate they use init data and/or > functions. > > This suite should always pass and uses a simple init function. > > This suite can also be used to test the is_init attribute introduced in > the next patch. > > Signed-off-by: Rae Moar <rmoar@google.com> > --- Can we make the actual test function __init as well? I don't think it should be _necessary_ for this to work, but I'd like us to have the option of entire tests being marked __init, and so discarded after boot. This seems to work here if the test is marked __init, and the example_init_test_cases and example_init_test_suite are marked __initdata. But, as mentioned in the previous patch, that might not work if we need to ensure example_init_test_suite and other metadata still exists. So maybe we can document that here? Otherwise, looks good. Reviewed-by: David Gow <davidgow@google.com> Cheers, -- David > lib/kunit/kunit-example-test.c | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c > index 6bb5c2ef6696..262a68a59800 100644 > --- a/lib/kunit/kunit-example-test.c > +++ b/lib/kunit/kunit-example-test.c > @@ -287,4 +287,33 @@ static struct kunit_suite example_test_suite = { > */ > kunit_test_suites(&example_test_suite); > > +static int __init init_add(int x, int y) > +{ > + return (x + y); > +} > + > +/* > + * This test should always pass. Can be used to test init suites. > + */ > +static void example_init_test(struct kunit *test) > +{ > + KUNIT_EXPECT_EQ(test, init_add(1, 1), 2); > +} > + > +static struct kunit_case example_init_test_cases[] = { > + KUNIT_CASE(example_init_test), > + {} > +}; > + > +static struct kunit_suite example_init_test_suite = { > + .name = "example_init", > + .test_cases = example_init_test_cases, > +}; > + > +/* > + * This registers the test suite and marks the suite as using init data > + * and/or functions. > + */ > +kunit_test_init_section_suites(&example_init_test_suite); > + > MODULE_LICENSE("GPL v2"); > -- > 2.43.0.rc2.451.g8631bc7472-goog >
diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index 6bb5c2ef6696..262a68a59800 100644 --- a/lib/kunit/kunit-example-test.c +++ b/lib/kunit/kunit-example-test.c @@ -287,4 +287,33 @@ static struct kunit_suite example_test_suite = { */ kunit_test_suites(&example_test_suite); +static int __init init_add(int x, int y) +{ + return (x + y); +} + +/* + * This test should always pass. Can be used to test init suites. + */ +static void example_init_test(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, init_add(1, 1), 2); +} + +static struct kunit_case example_init_test_cases[] = { + KUNIT_CASE(example_init_test), + {} +}; + +static struct kunit_suite example_init_test_suite = { + .name = "example_init", + .test_cases = example_init_test_cases, +}; + +/* + * This registers the test suite and marks the suite as using init data + * and/or functions. + */ +kunit_test_init_section_suites(&example_init_test_suite); + MODULE_LICENSE("GPL v2");
Add example_init_test_suite to allow for testing the feature of running test suites marked as init to indicate they use init data and/or functions. This suite should always pass and uses a simple init function. This suite can also be used to test the is_init attribute introduced in the next patch. Signed-off-by: Rae Moar <rmoar@google.com> --- lib/kunit/kunit-example-test.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)