Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1634665
| Path | csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Kees Cook <keescook@chromium.org> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v2 6/6] Documentation/dev-tools: Add kselftest_harness documentation |
| Date | Wed, 03 May 2017 01:20:02 +0200 |
| Message-ID | <tCPfk-4KZ-13@gated-at.bofh.it> (permalink) |
| References | <tCOsV-4g8-3@gated-at.bofh.it> <tCOsW-4g8-9@gated-at.bofh.it> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=luClF+inPX2Z9xMMSX9blIEtvzeg3Vls1ESdtV6UiXQ=; b=r9g2cO2cX+Qh4wQNxntv9BDfSHBpS8c7T3y5CRFCZ569xmCRyooIR0tg+cMml4aifi MezmcSPB6amf+K4UQS/D+Z7dzdWM6ePk3lonm3qPCioWKkcCJWGjt7ss3La+MyjLBt71 HIHaNIhlgFdFzlgHpvg1I2nW1T/i8TjmPCznPPXXLKQgyvqhMJq3bJ2YEQuFGyxl8tQt gfvhe7bXladLCVhOQaO3PDxS/brGf86579mt99ahaMhs4OrevXGFIvxSBzpDC4MTxEGU kWLooiKatRaDiALDFVb7bKiIYCUMpT1lY9nu1251FWePVxTjSQLnfj9un+rhzppXopfk 7xmg== |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=luClF+inPX2Z9xMMSX9blIEtvzeg3Vls1ESdtV6UiXQ=; b=VEDIrgeV9QvPqvz2y/zTbrQSCRcW0SE0Bz8DkURMeYAgxLKdq9uz/O/94Dk3hbajmD B6zW9JewwK1eKlHIeoPfVU4xZX7zXSm4XtSDer1ze0zMvgej2Sh4ObWzftXrwxCElDeA 3tig+g/HO373uH4oX4ouXVrPr06adLQTXoPAo= |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=luClF+inPX2Z9xMMSX9blIEtvzeg3Vls1ESdtV6UiXQ=; b=lgUeoYiLCKKWqrjNRbwE4oiLPRrep3S58LwG/FCpuD9FMn1yIF1Wr+3Uz2GZbEkDCI 6GgwyLVoUSFL/Kua0MxgaVfdqU1jccXdiFuYD6fIZujtCPhtdkvptjpC+yt1KjZKSPN9 CTvuFISpH/sCplt7UXmvPUAku3djL/ZnjgAx5W882jfQ/ot3W5LMJ6ZDVwD8jI/ofRez woIzbB76Qz4BQFu+oU2QxYga+wCwuAhO5IWn8BfK2VgEQlJYbog81RJ7rt5IHd+VbzRa gUdMoF7XbCM5EdzwP/Fsz7zurZGYDXLb9FAMeVtZCJqFVu/3u7HW3tASGtEqFoCHTky3 ZVDg== |
| X-Gm-Message-State | AN3rC/4tgPIkilYqU5d4hjgHlpD52kh0+sdXzozEkYLN/sKn+GGeQT/g xoWBd/YRUb3DREiqOIuKd8mwbnyj5JJE |
| X-Received | by 10.36.60.214 with SMTP id m205mr6546270ita.6.1493766909800; Tue, 02 May 2017 16:15:09 -0700 (PDT) |
| MIME-Version | 1.0 |
| X-Google-Sender-Auth | K_W6UksJSScWHFCDkGwF6L0vFWQ |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 473 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | LKML <linux-kernel@vger.kernel.org>, Andy Lutomirski <luto@amacapital.net>, Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>, Will Drewry <wad@chromium.org>, "linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>, linux-kselftest@vger.kernel.org |
| X-Original-Date | Tue, 2 May 2017 16:15:09 -0700 |
| X-Original-Message-ID | <CAGXu5jK1p4hn7Rv1oV9wRDRZ_RM7=_i3yOtrcx8cQEjfTTHZyg@mail.gmail.com> |
| X-Original-References | <20170502222641.7142-1-mic@digikod.net> <20170502222641.7142-7-mic@digikod.net> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1634665 |
Show key headers only | View raw
On Tue, May 2, 2017 at 3:26 PM, Mickaël Salaün <mic@digikod.net> wrote:
> Add metadata to kselftest_harness.h to be able to include the comments
> in the Sphinx documentation.
>
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> Cc: Andy Lutomirski <luto@amacapital.net>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Will Drewry <wad@chromium.org>
> ---
> Documentation/dev-tools/kselftest.rst | 57 ++++++
> tools/testing/selftests/kselftest_harness.h | 259 ++++++++++++++++++++--------
> 2 files changed, 243 insertions(+), 73 deletions(-)
>
> diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst
> index 39af2cb3d248..cf1e1f262c44 100644
> --- a/Documentation/dev-tools/kselftest.rst
> +++ b/Documentation/dev-tools/kselftest.rst
> @@ -138,3 +138,60 @@ Contributing new tests (details)
> executable which is not tested by default.
> TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
> test.
> +
> +Test Harness
> +------------
> +
> +The *kselftest_harness.h* file contains useful helpers to build tests. The
> +tests from seccomp/seccomp_bpf.c can be used as examples.
> +
> +Example
> +~~~~~~~
> +
> +.. code-block:: c
> +
> + #include "../kselftest_harness.h"
> +
> + TEST(standalone_test) {
> + do_some_stuff;
> + EXPECT_GT(10, stuff) {
> + stuff_state_t state;
> + enumerate_stuff_state(&state);
> + TH_LOG("expectation failed with state: %s", state.msg);
> + }
> + more_stuff;
> + ASSERT_NE(some_stuff, NULL) TH_LOG("how did it happen?!");
> + last_stuff;
> + EXPECT_EQ(0, last_stuff);
> + }
> +
> + FIXTURE(my_fixture) {
> + mytype_t *data;
> + int awesomeness_level;
> + };
> + FIXTURE_SETUP(my_fixture) {
> + self->data = mytype_new();
> + ASSERT_NE(NULL, self->data);
> + }
> + FIXTURE_TEARDOWN(my_fixture) {
> + mytype_free(self->data);
> + }
> + TEST_F(my_fixture, data_is_good) {
> + EXPECT_EQ(1, is_my_data_good(self->data));
> + }
> +
> + TEST_HARNESS_MAIN
> +
> +
> +Helpers
> +~~~~~~~~~
> +
> +.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
> + :doc: helpers
> +
> +
> +Operators
> +~~~~~~~~~
> +
> +.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
> + :doc: operators
Awesome! Yay docs!
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index 8ba227db46aa..eddddfe50c80 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -4,38 +4,6 @@
> *
> * kselftest_harness.h: simple C unit test helper.
> *
> - * Usage:
Can you add a pointer to the .rst file so someone looking at the
header file will find out where to get an example?
Otherwise, looks great!
-Kees
> - * #include "../kselftest_harness.h"
> - * TEST(standalone_test) {
> - * do_some_stuff;
> - * EXPECT_GT(10, stuff) {
> - * stuff_state_t state;
> - * enumerate_stuff_state(&state);
> - * TH_LOG("expectation failed with state: %s", state.msg);
> - * }
> - * more_stuff;
> - * ASSERT_NE(some_stuff, NULL) TH_LOG("how did it happen?!");
> - * last_stuff;
> - * EXPECT_EQ(0, last_stuff);
> - * }
> - *
> - * FIXTURE(my_fixture) {
> - * mytype_t *data;
> - * int awesomeness_level;
> - * };
> - * FIXTURE_SETUP(my_fixture) {
> - * self->data = mytype_new();
> - * ASSERT_NE(NULL, self->data);
> - * }
> - * FIXTURE_TEARDOWN(my_fixture) {
> - * mytype_free(self->data);
> - * }
> - * TEST_F(my_fixture, data_is_good) {
> - * EXPECT_EQ(1, is_my_data_good(self->data));
> - * }
> - *
> - * TEST_HARNESS_MAIN
> - *
> * API inspired by code.google.com/p/googletest
> */
>
> @@ -58,7 +26,13 @@
> * Exported APIs
> */
>
> -/* TEST(name) { implementation }
> +/**
> + * DOC: helpers
> + *
> + * .. code-block:: c
> + *
> + * TEST(name) { implementation }
> + *
> * Defines a test by name.
> * Names must be unique and tests must not be run in parallel. The
> * implementation containing block is a function and scoping should be treated
> @@ -68,7 +42,13 @@
> */
> #define TEST TEST_API(TEST)
>
> -/* TEST_SIGNAL(name, signal) { implementation }
> +/**
> + * DOC: helpers
> + *
> + * .. code-block:: c
> + *
> + * TEST_SIGNAL(name, signal) { implementation }
> + *
> * Defines a test by name and the expected term signal.
> * Names must be unique and tests must not be run in parallel. The
> * implementation containing block is a function and scoping should be treated
> @@ -78,25 +58,43 @@
> */
> #define TEST_SIGNAL TEST_API(TEST_SIGNAL)
>
> -/* FIXTURE(datatype name) {
> - * type property1;
> - * ...
> - * };
> - * Defines the data provided to TEST_F()-defined tests as |self|. It should be
> +/**
> + * DOC: helpers
> + *
> + * .. code-block:: c
> + *
> + * FIXTURE(datatype name) {
> + * type property1;
> + * ...
> + * };
> + *
> + * Defines the data provided to TEST_F()-defined tests as \|self\|. It should be
> * populated and cleaned up using FIXTURE_SETUP and FIXTURE_TEARDOWN.
> */
> #define FIXTURE TEST_API(FIXTURE)
>
> -/* FIXTURE_DATA(datatype name)
> +/**
> + * DOC: helpers
> + *
> + * .. code-block:: c
> + *
> + * FIXTURE_DATA(datatype name)
> + *
> * This call may be used when the type of the fixture data
> * is needed. In general, this should not be needed unless
> - * the |self| is being passed to a helper directly.
> + * the \|self\| is being passed to a helper directly.
> */
> #define FIXTURE_DATA TEST_API(FIXTURE_DATA)
>
> -/* FIXTURE_SETUP(fixture name) { implementation }
> +/**
> + * DOC: helpers
> + *
> + * .. code-block:: c
> + *
> + * FIXTURE_SETUP(fixture name) { implementation }
> + *
> * Populates the required "setup" function for a fixture. An instance of the
> - * datatype defined with _FIXTURE_DATA will be exposed as |self| for the
> + * datatype defined with _FIXTURE_DATA will be exposed as \|self\| for the
> * implementation.
> *
> * ASSERT_* are valid for use in this context and will prempt the execution
> @@ -106,84 +104,199 @@
> */
> #define FIXTURE_SETUP TEST_API(FIXTURE_SETUP)
>
> -/* FIXTURE_TEARDOWN(fixture name) { implementation }
> +/**
> + * DOC: helpers
> + *
> + * .. code-block:: c
> + *
> + * FIXTURE_TEARDOWN(fixture name) { implementation }
> + *
> * Populates the required "teardown" function for a fixture. An instance of the
> - * datatype defined with _FIXTURE_DATA will be exposed as |self| for the
> + * datatype defined with _FIXTURE_DATA will be exposed as \|self\| for the
> * implementation to clean up.
> *
> * A bare "return;" statement may be used to return early.
> */
> #define FIXTURE_TEARDOWN TEST_API(FIXTURE_TEARDOWN)
>
> -/* TEST_F(fixture, name) { implementation }
> +/**
> + * DOC: helpers
> + *
> + * .. code-block:: c
> + *
> + * TEST_F(fixture, name) { implementation }
> + *
> * Defines a test that depends on a fixture (e.g., is part of a test case).
> - * Very similar to TEST() except that |self| is the setup instance of fixture's
> + * Very similar to TEST() except that \|self\| is the setup instance of fixture's
> * datatype exposed for use by the implementation.
> */
> #define TEST_F TEST_API(TEST_F)
>
> #define TEST_F_SIGNAL TEST_API(TEST_F_SIGNAL)
>
> -/* Use once to append a main() to the test file. E.g.,
> - * TEST_HARNESS_MAIN
> +/**
> + * DOC: helpers
> + *
> + * .. code-block:: c
> + *
> + * TEST_HARNESS_MAIN
> + *
> + * Use once to append a main() to the test file.
> */
> #define TEST_HARNESS_MAIN TEST_API(TEST_HARNESS_MAIN)
>
> -/*
> +/**
> + * DOC: operators
> + *
> * Operators for use in TEST and TEST_F.
> * ASSERT_* calls will stop test execution immediately.
> * EXPECT_* calls will emit a failure warning, note it, and continue.
> */
>
> -/* ASSERT_EQ(expected, measured): expected == measured */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_EQ(expected, measured): expected == measured
> + */
> #define ASSERT_EQ TEST_API(ASSERT_EQ)
> -/* ASSERT_NE(expected, measured): expected != measured */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_NE(expected, measured): expected != measured
> + */
> #define ASSERT_NE TEST_API(ASSERT_NE)
> -/* ASSERT_LT(expected, measured): expected < measured */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_LT(expected, measured): expected < measured
> + */
> #define ASSERT_LT TEST_API(ASSERT_LT)
> -/* ASSERT_LE(expected, measured): expected <= measured */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_LE(expected, measured): expected <= measured
> + */
> #define ASSERT_LE TEST_API(ASSERT_LE)
> -/* ASSERT_GT(expected, measured): expected > measured */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_GT(expected, measured): expected > measured
> + */
> #define ASSERT_GT TEST_API(ASSERT_GT)
> -/* ASSERT_GE(expected, measured): expected >= measured */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_GE(expected, measured): expected >= measured
> + */
> #define ASSERT_GE TEST_API(ASSERT_GE)
> -/* ASSERT_NULL(measured): NULL == measured */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_NULL(measured): NULL == measured
> + */
> #define ASSERT_NULL TEST_API(ASSERT_NULL)
> -/* ASSERT_TRUE(measured): measured != 0 */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_TRUE(measured): measured != 0
> + */
> #define ASSERT_TRUE TEST_API(ASSERT_TRUE)
> -/* ASSERT_FALSE(measured): measured == 0 */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_FALSE(measured): measured == 0
> + */
> #define ASSERT_FALSE TEST_API(ASSERT_FALSE)
> -/* ASSERT_STREQ(expected, measured): !strcmp(expected, measured) */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_STREQ(expected, measured): !strcmp(expected, measured)
> + */
> #define ASSERT_STREQ TEST_API(ASSERT_STREQ)
> -/* ASSERT_STRNE(expected, measured): strcmp(expected, measured) */
> +/**
> + * DOC: operators
> + *
> + * * ASSERT_STRNE(expected, measured): strcmp(expected, measured)
> + */
> #define ASSERT_STRNE TEST_API(ASSERT_STRNE)
> -/* EXPECT_EQ(expected, measured): expected == measured */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_EQ(expected, measured): expected == measured
> + */
> #define EXPECT_EQ TEST_API(EXPECT_EQ)
> -/* EXPECT_NE(expected, measured): expected != measured */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_NE(expected, measured): expected != measured
> + */
> #define EXPECT_NE TEST_API(EXPECT_NE)
> -/* EXPECT_LT(expected, measured): expected < measured */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_LT(expected, measured): expected < measured
> + */
> #define EXPECT_LT TEST_API(EXPECT_LT)
> -/* EXPECT_LE(expected, measured): expected <= measured */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_LE(expected, measured): expected <= measured
> + */
> #define EXPECT_LE TEST_API(EXPECT_LE)
> -/* EXPECT_GT(expected, measured): expected > measured */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_GT(expected, measured): expected > measured
> + */
> #define EXPECT_GT TEST_API(EXPECT_GT)
> -/* EXPECT_GE(expected, measured): expected >= measured */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_GE(expected, measured): expected >= measured
> + */
> #define EXPECT_GE TEST_API(EXPECT_GE)
> -/* EXPECT_NULL(measured): NULL == measured */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_NULL(measured): NULL == measured
> + */
> #define EXPECT_NULL TEST_API(EXPECT_NULL)
> -/* EXPECT_TRUE(measured): 0 != measured */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_TRUE(measured): 0 != measured
> + */
> #define EXPECT_TRUE TEST_API(EXPECT_TRUE)
> -/* EXPECT_FALSE(measured): 0 == measured */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_FALSE(measured): 0 == measured
> + */
> #define EXPECT_FALSE TEST_API(EXPECT_FALSE)
> -/* EXPECT_STREQ(expected, measured): !strcmp(expected, measured) */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_STREQ(expected, measured): !strcmp(expected, measured)
> + */
> #define EXPECT_STREQ TEST_API(EXPECT_STREQ)
> -/* EXPECT_STRNE(expected, measured): strcmp(expected, measured) */
> +/**
> + * DOC: operators
> + *
> + * * EXPECT_STRNE(expected, measured): strcmp(expected, measured)
> + */
> #define EXPECT_STRNE TEST_API(EXPECT_STRNE)
>
> -/* TH_LOG(format, ...)
> +/**
> + * DOC: helpers
> + *
> + * .. code-block:: c
> + *
> + * TH_LOG(format, ...)
> + *
> * Optional debug logging function available for use in tests.
> * Logging may be enabled or disabled by defining TH_LOG_ENABLED.
> * E.g., #define TH_LOG_ENABLED 1
> + *
> * If no definition is provided, logging is enabled by default.
> */
> #define TH_LOG TEST_API(TH_LOG)
> --
> 2.11.0
>
--
Kees Cook
Pixel Security
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2 0/6] Add kselftest_harness.h Mickaël Salaün <mic@digikod.net> - 2017-05-03 00:30 +0200
[PATCH v2 5/6] Documentation/dev-tools: Use reStructuredText markups for kselftest Mickaël Salaün <mic@digikod.net> - 2017-05-03 00:30 +0200
Re: [PATCH v2 5/6] Documentation/dev-tools: Use reStructuredText markups for kselftest Kees Cook <keescook@chromium.org> - 2017-05-03 01:20 +0200
[PATCH v2 4/6] Documentation/dev-tools: Add kselftest Mickaël Salaün <mic@digikod.net> - 2017-05-03 00:30 +0200
[PATCH v2 6/6] Documentation/dev-tools: Add kselftest_harness documentation Mickaël Salaün <mic@digikod.net> - 2017-05-03 00:30 +0200
Re: [PATCH v2 6/6] Documentation/dev-tools: Add kselftest_harness documentation Kees Cook <keescook@chromium.org> - 2017-05-03 01:20 +0200
[PATCH v2 3/6] selftests/seccomp: Force rebuild according to dependencies Mickaël Salaün <mic@digikod.net> - 2017-05-03 00:30 +0200
[PATCH v2 1/6] selftests: Make test_harness.h more generally available Mickaël Salaün <mic@digikod.net> - 2017-05-03 00:30 +0200
[PATCH v2 2/6] selftests: Cosmetic renames in kselftest_harness.h Mickaël Salaün <mic@digikod.net> - 2017-05-03 00:30 +0200
Re: [PATCH v2 0/6] Add kselftest_harness.h Kees Cook <keescook@chromium.org> - 2017-05-03 01:20 +0200
csiph-web