From mboxrd@z Thu Jan 1 00:00:00 1970 From: Brendan Higgins Subject: Re: [RFC v3 01/19] kunit: test: add KUnit test runner core Date: Fri, 30 Nov 2018 18:08:36 -0800 Message-ID: References: <20181128193636.254378-1-brendanhiggins@google.com> <20181128193636.254378-2-brendanhiggins@google.com> <20181130032802.GG18410@garbanzo.do-not-panic.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20181130032802.GG18410-dAjH6bxAqesAS62YNPtMr3dQhYtBYE6JAL8bYrjMMd8@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org Sender: "Linux-nvdimm" To: mcgrof-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org Cc: brakmo-b10kYP2dOMg@public.gmane.org, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, linux-kselftest-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, shuah-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, Rob Herring , Frank Rowand , linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org, richard-/L3Ra7n9ekc@public.gmane.org, Knut Omang , kieran.bingham-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org, Joel Stanley , jdike-OPE4K8JWMJJBDgjK7y7TUQ@public.gmane.org, Tim.Bird-7U/KSKJipcs@public.gmane.org, Kees Cook , linux-um-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org, Julia Lawall , kunit-dev-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org, Greg KH , Linux Kernel Mailing List , Daniel Vetter , mpe-Gsx/Oe8HsFggBc27wqDAHg@public.gmane.org, joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org, khilman-rdvid1DuHRBWk0Htik3J/w@public.gmane.org List-Id: linux-nvdimm@lists.01.org On Thu, Nov 29, 2018 at 7:28 PM Luis Chamberlain wrote: > > > +static void kunit_run_case_internal(struct kunit *test, > > + struct kunit_module *module, > > + struct kunit_case *test_case) > > +{ > > + int ret; > > + > > + if (module->init) { > > + ret = module->init(test); > > + if (ret) { > > + kunit_err(test, "failed to initialize: %d", ret); > > + kunit_set_success(test, false); > > + return; > > + } > > + } > > + > > + test_case->run_case(test); > > +} > > <-- snip --> > > > +static bool kunit_run_case(struct kunit *test, > > + struct kunit_module *module, > > + struct kunit_case *test_case) > > +{ > > + kunit_set_success(test, true); > > + > > + kunit_run_case_internal(test, module, test_case); > > + kunit_run_case_cleanup(test, module, test_case); > > + > > + return kunit_get_success(test); > > +} > > So we are running the module->init() for each test case... is that > correct? Shouldn't the init run once? Also, typically init calls are Yep, it's correct. `module->init()` should run once before every test case, reason being that the kunit_module serves as a test fixture in which each test cases should be run completely independently of every other. init and exit is supposed to allow code common to all test cases to run since it is so common to have dependencies needed for a test to be common to every test case. Maybe it is confusing that I call it kunit_module? Maybe I should call it kunit_fixture or something? > pegged with __init so we free them later. You seem to have skipped the > init annotations. Why? Like I said above, these aren't normal init functions. A kunit_module->init() function should run once before each test case and thus should reside in the same linker section as any other KUnit test code. Cheers