From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shuah Khan Subject: Re: [RFC v2 01/14] kunit: test: add KUnit test runner core Date: Fri, 2 Nov 2018 12:44:46 -0600 Message-ID: <017b111f-d960-c1ef-46ae-eb0eb639fe5b@kernel.org> References: <20181023235750.103146-1-brendanhiggins@google.com> <20181023235750.103146-2-brendanhiggins@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20181023235750.103146-2-brendanhiggins-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> Content-Language: en-US List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org Sender: "Linux-nvdimm" To: Brendan Higgins , gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org, keescook-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org, mcgrof-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org Cc: brakmo-b10kYP2dOMg@public.gmane.org, robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, richard-/L3Ra7n9ekc@public.gmane.org, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org, mpe-Gsx/Oe8HsFggBc27wqDAHg@public.gmane.org, Tim.Bird-7U/KSKJipcs@public.gmane.org, linux-um-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, rostedt-nx8X9YLhiw1AfugRpC6u6w@public.gmane.org, kieran.bingham-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org, julia.lawall-L2FTfq7BK8M@public.gmane.org, joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org, linux-kselftest-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, khilman-rdvid1DuHRBWk0Htik3J/w@public.gmane.org, joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org, daniel-/w4YWyX8dFk@public.gmane.org, Shuah Khan , jdike-OPE4K8JWMJJBDgjK7y7TUQ@public.gmane.org, kunit-dev-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-Id: dri-devel@lists.freedesktop.org On 10/23/2018 05:57 PM, Brendan Higgins wrote: > Add core facilities for defining unit tests; this provides a common way > to define test cases, functions that execute code which is under test > and determine whether the code under test behaves as expected; this also > provides a way to group together related test cases in test suites (here > we call them test_modules). > > Just define test cases and how to execute them for now; setting > expectations on code will be defined later. > > Signed-off-by: Brendan Higgins > --- > include/kunit/test.h | 165 ++++++++++++++++++++++++++++++++++++++++++ > kunit/Kconfig | 17 +++++ > kunit/Makefile | 1 + > kunit/test.c | 168 +++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 351 insertions(+) > create mode 100644 include/kunit/test.h > create mode 100644 kunit/Kconfig > create mode 100644 kunit/Makefile > create mode 100644 kunit/test.c > > diff --git a/include/kunit/test.h b/include/kunit/test.h > new file mode 100644 > index 0000000000000..e0b14b227ac44 > --- /dev/null > +++ b/include/kunit/test.h > @@ -0,0 +1,165 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Base unit test (KUnit) API. > + * > + * Copyright (C) 2018, Google LLC. > + * Author: Brendan Higgins > + */ > + > +#ifndef _KUNIT_TEST_H > +#define _KUNIT_TEST_H > + > +#include > +#include > + > +struct test; > + > +/** > + * struct test_case - represents an individual test case. > + * @run_case: the function representing the actual test case. > + * @name: the name of the test case. > + * > + * A test case is a function with the signature, ``void (*)(struct test *)`` > + * that makes expectations (see TEST_EXPECT_TRUE()) about code under test. Each > + * test case is associated with a &struct test_module and will be run after the > + * module's init function and followed by the module's exit function. > + * > + * A test case should be static and should only be created with the TEST_CASE() > + * macro; additionally, every array of test cases should be terminated with an > + * empty test case. > + * > + * Example: > + * > + * .. code-block:: c > + * > + * void add_test_basic(struct test *test) > + * { > + * TEST_EXPECT_EQ(test, 1, add(1, 0)); > + * TEST_EXPECT_EQ(test, 2, add(1, 1)); > + * TEST_EXPECT_EQ(test, 0, add(-1, 1)); > + * TEST_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX)); > + * TEST_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN)); > + * } > + * > + * static struct test_case example_test_cases[] = { > + * TEST_CASE(add_test_basic), > + * {}, > + * }; > + * > + */ > +struct test_case { > + void (*run_case)(struct test *test); > + const char name[256]; > + > + /* private: internal use only. */ > + bool success; > +}; > + Introducing a prefix kunit_* might be a good idea for the API. This comment applies to the rest of patches as well. thanks, -- Shuah