public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Corbet <corbet@lwn.net>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: shuah@kernel.org, linux-kernel@vger.kernel.org,
	Andy Lutomirski <luto@amacapital.net>,
	Kees Cook <keescook@chromium.org>, Will Drewry <wad@chromium.org>,
	linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v3 0/6] Add kselftest_harness.h
Date: Tue, 16 May 2017 14:29:01 -0600	[thread overview]
Message-ID: <20170516142901.080336b6@lwn.net> (raw)
In-Reply-To: <099b067d-89ff-35e0-7a64-7c7ccc31cf4d@digikod.net>

On Tue, 16 May 2017 22:12:39 +0200
Mickaël Salaün <mic@digikod.net> wrote:

> > I will have to defer to Jon Corbet for Documentation related changes
> > and patches. Jon! Could you please review and give me an Ack.  
> 
> Jonathan, what do you think about this patches?

Sorry, I missed that completely, looking now...

> Add metadata to kselftest_harness.h to be able to include the comments
> in the Sphinx documentation.
> 
> Changes since v2:
> * add reference to the full documentation in the header file (suggested
>   by Kees Cook)
> 
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> Acked-by: Kees Cook <keescook@chromium.org>
> Cc: Andy Lutomirski <luto@amacapital.net>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Will Drewry <wad@chromium.org>
> ---
>  Documentation/dev-tools/kselftest.rst       |  58 +++++++
>  tools/testing/selftests/kselftest_harness.h | 259 ++++++++++++++++++++--------
>  2 files changed, 245 insertions(+), 72 deletions(-)
> 
> diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst
> index 9232ce94612c..92fc7cc3094b 100644
> --- a/Documentation/dev-tools/kselftest.rst
> +++ b/Documentation/dev-tools/kselftest.rst
> @@ -120,3 +120,61 @@ 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 *tools/testing/selftests/seccomp/seccomp_bpf.c* can be used as
> +examples.

Minor quibble: in the spirit of minimizing markup, I'd probably not mark up
the file names in this way.

> +
> +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

So this was moved from the .h file.  That's fine if you want to do it that
way, but you could have also left it in place and included it with a :doc:
directive.  Up to you.

> +
> +Helpers
> +-------
> +
> +.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
> +    :doc: helpers
> +
> +
> +Operators
> +---------
> +
> +.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
> +    :doc: operators
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index 8ba227db46aa..b55be9807af4 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -4,37 +4,7 @@
>   *
>   * kselftest_harness.h: simple C unit test helper.
>   *
> - * Usage:
> - *   #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
> + * See documentation in Documentation/dev-tools/kselftest.rst
>   *
>   * API inspired by code.google.com/p/googletest
>   */
> @@ -58,7 +28,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

It would be nicer to document these as actual functions, rather than using
DOC: blocks.  It gives you all the standard formatting, index entries,
cross-references, etc.  A normal kerneldoc header will work with a macro
like this.

I guess that's my most substantive comment.  If you really want to do it
this way instead I'll not raise a big fuss, but I would be curious to know
what the reason is?

Thanks,

jon

  reply	other threads:[~2017-05-16 20:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-03 22:26 [PATCH v3 0/6] Add kselftest_harness.h Mickaël Salaün
2017-05-03 22:26 ` [PATCH v3 1/6] selftests: Make test_harness.h more generally available Mickaël Salaün
2017-05-03 22:26 ` [PATCH v3 2/6] selftests: Cosmetic renames in kselftest_harness.h Mickaël Salaün
2017-05-03 22:26 ` [PATCH v3 3/6] selftests/seccomp: Force rebuild according to dependencies Mickaël Salaün
2017-05-03 22:26 ` [PATCH v3 4/6] Documentation/dev-tools: Add kselftest Mickaël Salaün
2017-05-03 22:26 ` [PATCH v3 5/6] Documentation/dev-tools: Use reStructuredText markups for kselftest Mickaël Salaün
2017-05-03 22:26 ` [PATCH v3 6/6] Documentation/dev-tools: Add kselftest_harness documentation Mickaël Salaün
2017-05-04 13:58 ` [PATCH v3 0/6] Add kselftest_harness.h Shuah Khan
2017-05-16 20:12   ` Mickaël Salaün
2017-05-16 20:29     ` Jonathan Corbet [this message]
2017-05-16 21:48       ` Mickaël Salaün

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170516142901.080336b6@lwn.net \
    --to=corbet@lwn.net \
    --cc=keescook@chromium.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mic@digikod.net \
    --cc=shuah@kernel.org \
    --cc=wad@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox