Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2476984imd; Fri, 2 Nov 2018 12:05:22 -0700 (PDT) X-Google-Smtp-Source: AJdET5fP3yqPSZHGxEaVemRJh4Khb3g5dQK2+/RLoV9uEq8fJBu2ypBU7LPl39qrZZuSOkuLcbdg X-Received: by 2002:a63:f210:: with SMTP id v16-v6mr11563936pgh.371.1541185522556; Fri, 02 Nov 2018 12:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541185522; cv=none; d=google.com; s=arc-20160816; b=yH8DFhn0J88KXaU/Q4Dq3AAvwI1orjei57NWAdohXK7G9bB53zAIBJqGiJ+8l7jhQg Tsi3TPAx9VbjwsvvGePBmjWXclaQ10Gf6kZ6XMK+htQ5jK7XxtybtUYN+NkBmRclRs2r oQDbLMC5U5xVnRow7BMLkImxykZV2pcYupapjjVkbFHyiF27eUu6Z7u3GJ0qnUx0C/ac VJaNbfceVM28slRnGIq+mI9hEw4gsTNo4K6nQOmLPr2h5eD/SdTV3gCfblg/Br1K1Wve EtnrDRPNKM0ZkgUHfUSXekujM3AEIHLEHyMva9NRsA2WsQmYrgLMhyrT8WCuCWg0212b RT0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=A6ewqS5kIzdMZCkAiM0W9b7Ffl5dPR9kvISUAzUWOUE=; b=zfoOQzTY0s4/L9oKW4zng+REjTSSWgC1GjPYEUXDUPdC94KPXpVNLffXhzkD96O+Ru /If+5eAtIQ4l/hQaBZku83rvolccBCtXQVFhupoSA+JWpPqDEd8N+dThH+r2JLYwowD8 nuomY5Gro0m+sq2A45Xpno1fmFUkVtWb/89wAn4m/3dRxzUh+Ecy5OTP0/mL/4BNHwz8 ElePVR1nxi/G/N/s2dSra4MtqL18V4FnVPRNCXBetXHWMx2YPPRWrFHRR06D553UJ2yo vDxG6fb+WroVWca7UpgafMzybe+Gb8npJtGLAPG5z/vdE1HdHQq3XwLScrVi5OYY+dos TXHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FpfVtp1B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z20-v6si34457780pfe.245.2018.11.02.12.05.08; Fri, 02 Nov 2018 12:05:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FpfVtp1B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730078AbeKCDxC (ORCPT + 99 others); Fri, 2 Nov 2018 23:53:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:48388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726849AbeKCDxB (ORCPT ); Fri, 2 Nov 2018 23:53:01 -0400 Received: from [192.168.1.87] (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1264E20854; Fri, 2 Nov 2018 18:44:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184288; bh=SM4Wpf2zBYd2WEx0/iln+4jyJvWCFLDbN2IDUHvNxh0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=FpfVtp1Bd3578fIAWWRbMbv9zTJRPBU7e/3mMog6/9rkAw7EUNOcuzN4nvoivSRK5 6JERz6wq6z/5Ns/UsuM/GsDz4ON7Df2/Q+pgXO+UtfTGhDzT84zpWBwztDlEnOEf0c pKz7e+EDXpN6Zxvy7deciH3vApc2m5WjPTkvsXm0= Subject: Re: [RFC v2 01/14] kunit: test: add KUnit test runner core To: Brendan Higgins , gregkh@linuxfoundation.org, keescook@google.com, mcgrof@kernel.org Cc: joel@jms.id.au, mpe@ellerman.id.au, joe@perches.com, brakmo@fb.com, rostedt@goodmis.org, Tim.Bird@sony.com, khilman@baylibre.com, julia.lawall@lip6.fr, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, jdike@addtoit.com, richard@nod.at, linux-um@lists.infradead.org, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, robh@kernel.org, dan.j.williams@intel.com, linux-nvdimm@lists.01.org, kieran.bingham@ideasonboard.com, Shuah Khan References: <20181023235750.103146-1-brendanhiggins@google.com> <20181023235750.103146-2-brendanhiggins@google.com> From: Shuah Khan Message-ID: <017b111f-d960-c1ef-46ae-eb0eb639fe5b@kernel.org> Date: Fri, 2 Nov 2018 12:44:46 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181023235750.103146-2-brendanhiggins@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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