Skip to contentSkip to conversation

Add kselftest_harness.h

PATCH Superseded Mickaël Salaün 3 participants 18 messages May 26, 2017 – Jun 5, 2017

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover Add kselftest_harness.h

Hi,

This patch series make the seccomp/test_harness.h more generally available [1] and update the kselftest documentation in the Sphinx format. It also improve the Makefile of seccomp tests to take into account any kselftest_harness.h update.

[1] https://lkml.kernel.org/r/CAGXu5j+8CVz8vL51DRYXqOY=xc3zuKFf=PTENe88XYHzFYidUQ@mail.gmail.com

Regards,

Mickaël Salaün (7):
selftests: Make test_harness.h more generally available
selftests: Cosmetic renames in kselftest_harness.h selftests/seccomp: Force rebuild according to dependencies Documentation/dev-tools: Add kselftest Documentation/dev-tools: Use reStructuredText markups for kselftest
selftests: Remove the TEST_API() wrapper from kselftest_harness.h Documentation/dev-tools: Add kselftest_harness documentation

 Documentation/00-INDEX                             |   2 -
 Documentation/dev-tools/index.rst                  |   1 +
 .../{kselftest.txt => dev-tools/kselftest.rst}     | 101 ++-
 MAINTAINERS                                        |   1 +
 .../test_harness.h => kselftest_harness.h}         | 691 +++++++++++++--------
 tools/testing/selftests/seccomp/Makefile           |   2 +
 tools/testing/selftests/seccomp/seccomp_bpf.c      |   2 +-
 7 files changed, 520 insertions(+), 280 deletions(-)
 rename Documentation/{kselftest.txt => dev-tools/kselftest.rst} (52%)
 rename tools/testing/selftests/{seccomp/test_harness.h => kselftest_harness.h} (52%)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v5 1/7 selftests: Make test_harness.h more generally available

The seccomp/test_harness.h file contains useful helpers to build tests. Moving it to the selftest directory should benefit to other test components.

Keep seccomp maintainers for this file.

Changes since v1:
* rename to kselftest_harness.h (suggested by Shuah Khan)
* keep maintainers

---
 MAINTAINERS                                                             | 1 +
 tools/testing/selftests/{seccomp/test_harness.h => kselftest_harness.h} | 0
 tools/testing/selftests/seccomp/seccomp_bpf.c                           | 2 +-
 3 files changed, 2 insertions(+), 1 deletion(-)
 rename tools/testing/selftests/{seccomp/test_harness.h => kselftest_harness.h} (100%)
MAINTAINERS +1 -0
index f7d568b8f133..ef292b8c771d 100644
@@ -11492,6 +11492,7 @@ F:	kernel/seccomp.c
 F:	include/uapi/linux/seccomp.h
 F:	include/linux/seccomp.h
 F:	tools/testing/selftests/seccomp/*
+F:	tools/testing/selftests/kselftest_harness.h
 K:	\bsecure_computing
 K:	\bTIF_SECCOMP\b
 
tools/testing/selftests/kselftest_harness.h renamed from tools/testing/selftests/seccomp/test_harness.h +0 -0
similarity index 100%
rename from tools/testing/selftests/seccomp/test_harness.h
rename to tools/testing/selftests/kselftest_harness.h
tools/testing/selftests/seccomp/seccomp_bpf.c +1 -1
index 03f1fa495d74..7ba94efb24fd 100644
@@ -37,7 +37,7 @@
 #include <unistd.h>
 #include <sys/syscall.h>
 
-#include "test_harness.h"
+#include "../kselftest_harness.h"
 
 #ifndef PR_SET_PTRACER
 # define PR_SET_PTRACER 0x59616d61
Signature · 1 line
2.11.0
#2 lore raw

PATCH v5 2/7 selftests: Cosmetic renames in kselftest_harness.h

In reply to Mickaël Salaün

Keep the content consistent with the new name.

---
 tools/testing/selftests/kselftest_harness.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
tools/testing/selftests/kselftest_harness.h +6 -5
index a786c69c7584..171e70aead9c 100644
@@ -2,10 +2,10 @@
  * Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
  * Use of this source code is governed by the GPLv2 license.
  *
- * test_harness.h: simple C unit test helper.
+ * kselftest_harness.h: simple C unit test helper.
  *
  * Usage:
- *   #include "test_harness.h"
+ *   #include "../kselftest_harness.h"
  *   TEST(standalone_test) {
  *     do_some_stuff;
  *     EXPECT_GT(10, stuff) {
@@ -38,8 +38,9 @@
  *
  * API inspired by code.google.com/p/googletest
  */
-#ifndef TEST_HARNESS_H_
-#define TEST_HARNESS_H_
+
+#ifndef __KSELFTEST_HARNESS_H
+#define __KSELFTEST_HARNESS_H
 
 #define _GNU_SOURCE
 #include <stdint.h>
@@ -532,4 +533,4 @@ static void __attribute__((constructor)) __constructor_order_first(void)
 		__constructor_order = _CONSTRUCTOR_ORDER_FORWARD;
 }
 
-#endif  /* TEST_HARNESS_H_ */
+#endif  /* __KSELFTEST_HARNESS_H */
Signature · 1 line
2.11.0
#3 lore raw

PATCH v5 3/7 selftests/seccomp: Force rebuild according to dependencies

In reply to Mickaël Salaün

Rebuild the seccomp tests when kselftest_harness.h is updated.

---
 tools/testing/selftests/seccomp/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/seccomp/Makefile +2 -0
index 5fa6fd2246b1..aeb0c805f3ca 100644
@@ -4,3 +4,5 @@ LDFLAGS += -lpthread
 
 include ../lib.mk
 
+$(TEST_GEN_PROGS): seccomp_bpf.c ../kselftest_harness.h
+	$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
Signature · 1 line
2.11.0
maintainer
#4 lore raw

Re: [PATCH v5 3/7] selftests/seccomp: Force rebuild according to dependencies

Hi Mickaël,

Quoted 17 lines · Mickaël Salaün

Rebuild the seccomp tests when kselftest_harness.h is updated.

---
 tools/testing/selftests/seccomp/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/seccomp/Makefile +0 -0
index 5fa6fd2246b1..aeb0c805f3ca 100644

tools/testing/selftests/seccomp/Makefile LDFLAGS += -lpthread · line 8

Quoted 5 lines
tools/testing/selftests/seccomp/Makefile +2 -0
@@ -4,3 +4,5 @@ LDFLAGS += -lpthread
 
 include ../lib.mk
 
+$(TEST_GEN_PROGS): seccomp_bpf.c ../kselftest_harness.h
+	$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@

This change breaks seccomp build:

make -C tools/testing/selftests/seccomp/
make: Entering directory '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp'
make: *** No rule to make target '../kselftest_harness.h', needed by '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp/seccomp_bpf'. Stop.
make: Leaving directory '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp'

shuah@mazurka:/mnt/data/lkml/linux_4.12$ cd tools/testing/selftests/seccomp/
shuah@mazurka:/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp$ make
make: *** No rule to make target '../kselftest_harness.h', needed by '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp/seccomp_bpf'.  Stop.

Did you happen to try building with this change?

thanks,
-- Shuah

#5 lore raw

Re: [PATCH v5 3/7] selftests/seccomp: Force rebuild according to dependencies

Hi Shuah,

Quoted 32 lines · Shuah Khan

Hi Mickaël,

Quoted 17 lines · Mickaël Salaün

Rebuild the seccomp tests when kselftest_harness.h is updated.

---
 tools/testing/selftests/seccomp/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/seccomp/Makefile +0 -0
index 5fa6fd2246b1..aeb0c805f3ca 100644

tools/testing/selftests/seccomp/Makefile LDFLAGS += -lpthread · line 8

Quoted 5 lines
tools/testing/selftests/seccomp/Makefile +2 -0
@@ -4,3 +4,5 @@ LDFLAGS += -lpthread
 
 include ../lib.mk
 
+$(TEST_GEN_PROGS): seccomp_bpf.c ../kselftest_harness.h
+	$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@

This change breaks seccomp build:

make -C tools/testing/selftests/seccomp/
make: Entering directory '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp'
make: *** No rule to make target '../kselftest_harness.h', needed by '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp/seccomp_bpf'. Stop.
make: Leaving directory '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp'

Quoted 6 lines
shuah@mazurka:/mnt/data/lkml/linux_4.12$ cd tools/testing/selftests/seccomp/
shuah@mazurka:/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp$ make
make: *** No rule to make target '../kselftest_harness.h', needed by '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp/seccomp_bpf'.  Stop.

Did you happen to try building with this change?

Yes I did, and it builds fine for me (with the same command and patches). There is only one warning from GCC with ../kselftest_harness.h:368 because of the trick from OPTIONAL_HANDLER(), which is intentional (and not modified by my patches).

I don't get why your "make" said that there is "No rule to make target" ../kselftest_harness.h . This file exists (patch 1/7) so there is no need to create it…
gen_kselftest_tar.sh works fine too.

Thanks,
Mickaël

maintainer
#6 lore raw

Re: [PATCH v5 3/7] selftests/seccomp: Force rebuild according to dependencies

Hi Mickaël,

Quoted 47 lines · Mickaël Salaün

Hi Shuah,

Quoted 32 lines · Shuah Khan

Hi Mickaël,

Quoted 17 lines · Mickaël Salaün

Rebuild the seccomp tests when kselftest_harness.h is updated.

---
 tools/testing/selftests/seccomp/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/seccomp/Makefile +0 -0
index 5fa6fd2246b1..aeb0c805f3ca 100644

tools/testing/selftests/seccomp/Makefile LDFLAGS += -lpthread · line 8

Quoted 5 lines
tools/testing/selftests/seccomp/Makefile +2 -0
@@ -4,3 +4,5 @@ LDFLAGS += -lpthread
 
 include ../lib.mk
 
+$(TEST_GEN_PROGS): seccomp_bpf.c ../kselftest_harness.h
+	$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@

This change breaks seccomp build:

make -C tools/testing/selftests/seccomp/
make: Entering directory '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp'
make: *** No rule to make target '../kselftest_harness.h', needed by '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp/seccomp_bpf'. Stop.
make: Leaving directory '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp'

Quoted 6 lines
shuah@mazurka:/mnt/data/lkml/linux_4.12$ cd tools/testing/selftests/seccomp/
shuah@mazurka:/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp$ make
make: *** No rule to make target '../kselftest_harness.h', needed by '/mnt/data/lkml/linux_4.12/tools/testing/selftests/seccomp/seccomp_bpf'.  Stop.

Did you happen to try building with this change?

Yes I did, and it builds fine for me (with the same command and patches). There is only one warning from GCC with ../kselftest_harness.h:368 because of the trick from OPTIONAL_HANDLER(), which is intentional (and not modified by my patches).

Quoted 5 lines

I don't get why your "make" said that there is "No rule to make target" ../kselftest_harness.h . This file exists (patch 1/7) so there is no need to create it…
gen_kselftest_tar.sh works fine too.

I think I know what's going on here. It is my bad. Never mind, we are good. I will apply this patch to linux-kselftest next.

thanks,
-- Shuah

#7 lore raw

PATCH v5 4/7 Documentation/dev-tools: Add kselftest

In reply to Mickaël Salaün

Move kselftest.txt to dev-tools/kselftest.rst .

---
 Documentation/00-INDEX                                   | 2 --
 Documentation/{kselftest.txt => dev-tools/kselftest.rst} | 0
 2 files changed, 2 deletions(-)
 rename Documentation/{kselftest.txt => dev-tools/kselftest.rst} (100%)
Documentation/00-INDEX +0 -2
index ed3e5e949fce..6daf51536153 100644
@@ -246,8 +246,6 @@ kprobes.txt
 	- documents the kernel probes debugging feature.
 kref.txt
 	- docs on adding reference counters (krefs) to kernel objects.
-kselftest.txt
-	- small unittests for (some) individual codepaths in the kernel.
 laptops/
 	- directory with laptop related info and laptop driver documentation.
 ldm.txt
Documentation/dev-tools/kselftest.rst renamed from Documentation/kselftest.txt +0 -0
similarity index 100%
rename from Documentation/kselftest.txt
rename to Documentation/dev-tools/kselftest.rst
Signature · 1 line
2.11.0
#8 lore raw

PATCH v5 5/7 Documentation/dev-tools: Use reStructuredText markups for kselftest

In reply to Mickaël Salaün

Include and convert kselftest to the Sphinx format.

Changes since v2:
* lighten the modifications (suggested by Kees Cook)

---
 Documentation/dev-tools/index.rst     |  1 +
 Documentation/dev-tools/kselftest.rst | 67 +++++++++++++++++++++--------------
 2 files changed, 41 insertions(+), 27 deletions(-)
Documentation/dev-tools/index.rst +1 -0
index 07d881147ef3..e50054c6aeaa 100644
@@ -23,6 +23,7 @@ whole; patches welcome!
    kmemleak
    kmemcheck
    gdb-kernel-debugging
+   kselftest
 
 
 .. only::  subproject and html
Documentation/dev-tools/kselftest.rst +40 -27

115 lines not on this page · raw message

Signature · 1 line
2.11.0
#9 lore raw

PATCH v5 6/7 selftests: Remove the TEST_API() wrapper from kselftest_harness.h

In reply to Mickaël Salaün

Remove the TEST_API() wrapper to expose the underlying macro arguments to the documentation tools.

Use "git diff --patience" to get a more readable patch.

Changes since v4:
* standalone patch to ease the review (requested by Kees Cook)

Cc Andy Lutomirski <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>
---
 tools/testing/selftests/kselftest_harness.h | 349 ++++++++++++----------------
 1 file changed, 147 insertions(+), 202 deletions(-)
tools/testing/selftests/kselftest_harness.h +147 -202
index 171e70aead9c..45f807ce37e1 100644
@@ -51,147 +51,6 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
-/* All exported functionality should be declared through this macro. */
-#define TEST_API(x) _##x
-
-/*
- * Exported APIs
- */
-
-/* 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
- * as such.  Returning early may be performed with a bare "return;" statement.
- *
- * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
- */
-#define TEST TEST_API(TEST)
-
-/* 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
- * as such.  Returning early may be performed with a bare "return;" statement.
- *
- * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
- */
-#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
- * populated and cleaned up using FIXTURE_SETUP and FIXTURE_TEARDOWN.
- */
-#define FIXTURE TEST_API(FIXTURE)
-
-/* 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.
- */
-#define FIXTURE_DATA TEST_API(FIXTURE_DATA)
-
-/* 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
- * implementation.
- *
- * ASSERT_* are valid for use in this context and will prempt the execution
- * of any dependent fixture tests.
- *
- * A bare "return;" statement may be used to return early.
- */
-#define FIXTURE_SETUP TEST_API(FIXTURE_SETUP)
-
-/* 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
- * 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 }
- * 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
- * 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
- */
-#define TEST_HARNESS_MAIN TEST_API(TEST_HARNESS_MAIN)
-
-/*
- * 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 */
-#define ASSERT_EQ TEST_API(ASSERT_EQ)
-/* ASSERT_NE(expected, measured): expected != measured */
-#define ASSERT_NE TEST_API(ASSERT_NE)
-/* ASSERT_LT(expected, measured): expected < measured */
-#define ASSERT_LT TEST_API(ASSERT_LT)
-/* ASSERT_LE(expected, measured): expected <= measured */
-#define ASSERT_LE TEST_API(ASSERT_LE)
-/* ASSERT_GT(expected, measured): expected > measured */
-#define ASSERT_GT TEST_API(ASSERT_GT)
-/* ASSERT_GE(expected, measured): expected >= measured */
-#define ASSERT_GE TEST_API(ASSERT_GE)
-/* ASSERT_NULL(measured): NULL == measured */
-#define ASSERT_NULL TEST_API(ASSERT_NULL)
-/* ASSERT_TRUE(measured): measured != 0 */
-#define ASSERT_TRUE TEST_API(ASSERT_TRUE)
-/* ASSERT_FALSE(measured): measured == 0 */
-#define ASSERT_FALSE TEST_API(ASSERT_FALSE)
-/* ASSERT_STREQ(expected, measured): !strcmp(expected, measured) */
-#define ASSERT_STREQ TEST_API(ASSERT_STREQ)
-/* ASSERT_STRNE(expected, measured): strcmp(expected, measured) */
-#define ASSERT_STRNE TEST_API(ASSERT_STRNE)
-/* EXPECT_EQ(expected, measured): expected == measured */
-#define EXPECT_EQ TEST_API(EXPECT_EQ)
-/* EXPECT_NE(expected, measured): expected != measured */
-#define EXPECT_NE TEST_API(EXPECT_NE)
-/* EXPECT_LT(expected, measured): expected < measured */
-#define EXPECT_LT TEST_API(EXPECT_LT)
-/* EXPECT_LE(expected, measured): expected <= measured */
-#define EXPECT_LE TEST_API(EXPECT_LE)
-/* EXPECT_GT(expected, measured): expected > measured */
-#define EXPECT_GT TEST_API(EXPECT_GT)
-/* EXPECT_GE(expected, measured): expected >= measured */
-#define EXPECT_GE TEST_API(EXPECT_GE)
-/* EXPECT_NULL(measured): NULL == measured */
-#define EXPECT_NULL TEST_API(EXPECT_NULL)
-/* EXPECT_TRUE(measured): 0 != measured */
-#define EXPECT_TRUE TEST_API(EXPECT_TRUE)
-/* EXPECT_FALSE(measured): 0 == measured */
-#define EXPECT_FALSE TEST_API(EXPECT_FALSE)
-/* EXPECT_STREQ(expected, measured): !strcmp(expected, measured) */
-#define EXPECT_STREQ TEST_API(EXPECT_STREQ)
-/* EXPECT_STRNE(expected, measured): strcmp(expected, measured) */
-#define EXPECT_STRNE TEST_API(EXPECT_STRNE)
-
-/* 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)
-
-/*
- * Internal implementation.
- *
- */
 
 /* Utilities exposed to the test definitions */
 #ifndef TH_LOG_STREAM
@@ -202,7 +61,13 @@
 #  define TH_LOG_ENABLED 1
 #endif
 
-#define _TH_LOG(fmt, ...) do { \
+/* 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(fmt, ...) do { \
 	if (TH_LOG_ENABLED) \
 		__TH_LOG(fmt, ##__VA_ARGS__); \
 } while (0)
@@ -212,10 +77,26 @@
 		fprintf(TH_LOG_STREAM, "%s:%d:%s:" fmt "\n", \
 			__FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
 
+/* 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
+ * as such.  Returning early may be performed with a bare "return;" statement.
+ *
+ * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
+ */
 /* Defines the test function and creates the registration stub. */
-#define _TEST(test_name) __TEST_IMPL(test_name, -1)
+#define TEST(test_name) __TEST_IMPL(test_name, -1)
 
-#define _TEST_SIGNAL(test_name, signal) __TEST_IMPL(test_name, signal)
+/* 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
+ * as such.  Returning early may be performed with a bare "return;" statement.
+ *
+ * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
+ */
+#define TEST_SIGNAL(test_name, signal) __TEST_IMPL(test_name, signal)
 
 #define __TEST_IMPL(test_name, _signal) \
 	static void test_name(struct __test_metadata *_metadata); \
@@ -229,50 +110,84 @@
 	static void test_name( \
 		struct __test_metadata __attribute__((unused)) *_metadata)
 
+/* 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.
+ */
 /* Wraps the struct name so we have one less argument to pass around. */
-#define _FIXTURE_DATA(fixture_name) struct _test_data_##fixture_name
+#define FIXTURE_DATA(datatype_name) struct _test_data_##datatype_name
 
+/* 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.
+ */
 /* Called once per fixture to setup the data and register. */
-#define _FIXTURE(fixture_name) \
+#define FIXTURE(fixture_name) \
 	static void __attribute__((constructor)) \
 	_register_##fixture_name##_data(void) \
 	{ \
 		__fixture_count++; \
 	} \
-	_FIXTURE_DATA(fixture_name)
+	FIXTURE_DATA(fixture_name)
 
+/* 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
+ * implementation.
+ *
+ * ASSERT_* are valid for use in this context and will prempt the execution
+ * of any dependent fixture tests.
+ *
+ * A bare "return;" statement may be used to return early.
+ */
 /* Prepares the setup function for the fixture.  |_metadata| is included
  * so that ASSERT_* work as a convenience.
  */
-#define _FIXTURE_SETUP(fixture_name) \
+#define FIXTURE_SETUP(fixture_name) \
 	void fixture_name##_setup( \
 		struct __test_metadata __attribute__((unused)) *_metadata, \
-		_FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
-#define _FIXTURE_TEARDOWN(fixture_name) \
+		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
+/* 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
+ * implementation to clean up.
+ *
+ * A bare "return;" statement may be used to return early.
+ */
+#define FIXTURE_TEARDOWN(fixture_name) \
 	void fixture_name##_teardown( \
 		struct __test_metadata __attribute__((unused)) *_metadata, \
-		_FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
+		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
+/* 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
+ * datatype exposed for use by the implementation.
+ */
 /* Emits test registration and helpers for fixture-based test
  * cases.
  * TODO(wad) register fixtures on dedicated test lists.
  */
-#define _TEST_F(fixture_name, test_name) \
+#define TEST_F(fixture_name, test_name) \
 	__TEST_F_IMPL(fixture_name, test_name, -1)
 
-#define _TEST_F_SIGNAL(fixture_name, test_name, signal) \
+#define TEST_F_SIGNAL(fixture_name, test_name, signal) \
 	__TEST_F_IMPL(fixture_name, test_name, signal)
 
 #define __TEST_F_IMPL(fixture_name, test_name, signal) \
 	static void fixture_name##_##test_name( \
 		struct __test_metadata *_metadata, \
-		_FIXTURE_DATA(fixture_name) *self); \
+		FIXTURE_DATA(fixture_name) *self); \
 	static inline void wrapper_##fixture_name##_##test_name( \
 		struct __test_metadata *_metadata) \
 	{ \
 		/* fixture data is alloced, setup, and torn down per call. */ \
-		_FIXTURE_DATA(fixture_name) self; \
-		memset(&self, 0, sizeof(_FIXTURE_DATA(fixture_name))); \
+		FIXTURE_DATA(fixture_name) self; \
+		memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \
 		fixture_name##_setup(_metadata, &self); \
 		/* Let setup failure terminate early. */ \
 		if (!_metadata->passed) \
@@ -293,10 +208,13 @@
 	} \
 	static void fixture_name##_##test_name( \
 		struct __test_metadata __attribute__((unused)) *_metadata, \
-		_FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
+		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
+/* Use once to append a main() to the test file. E.g.,
+ *   TEST_HARNESS_MAIN
+ */
 /* Exports a simple wrapper to run the test harness. */
-#define _TEST_HARNESS_MAIN \
+#define TEST_HARNESS_MAIN \
 	static void __attribute__((constructor)) \
 	__constructor_order_last(void) \
 	{ \
@@ -307,54 +225,81 @@
 		return test_harness_run(argc, argv); \
 	}
 
-#define _ASSERT_EQ(_expected, _seen) \
-	__EXPECT(_expected, _seen, ==, 1)
-#define _ASSERT_NE(_expected, _seen) \
-	__EXPECT(_expected, _seen, !=, 1)
-#define _ASSERT_LT(_expected, _seen) \
-	__EXPECT(_expected, _seen, <, 1)
-#define _ASSERT_LE(_expected, _seen) \
-	__EXPECT(_expected, _seen, <=, 1)
-#define _ASSERT_GT(_expected, _seen) \
-	__EXPECT(_expected, _seen, >, 1)
-#define _ASSERT_GE(_expected, _seen) \
-	__EXPECT(_expected, _seen, >=, 1)
-#define _ASSERT_NULL(_seen) \
-	__EXPECT(NULL, _seen, ==, 1)
+/*
+ * 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 */
+#define ASSERT_EQ(expected, seen) \
+	__EXPECT(expected, seen, ==, 1)
+/* ASSERT_NE(expected, measured): expected != measured */
+#define ASSERT_NE(expected, seen) \
+	__EXPECT(expected, seen, !=, 1)
+/* ASSERT_LT(expected, measured): expected < measured */
+#define ASSERT_LT(expected, seen) \
+	__EXPECT(expected, seen, <, 1)
+/* ASSERT_LE(expected, measured): expected <= measured */
+#define ASSERT_LE(expected, seen) \
+	__EXPECT(expected, seen, <=, 1)
+/* ASSERT_GT(expected, measured): expected > measured */
+#define ASSERT_GT(expected, seen) \
+	__EXPECT(expected, seen, >, 1)
+/* ASSERT_GE(expected, measured): expected >= measured */
+#define ASSERT_GE(expected, seen) \
+	__EXPECT(expected, seen, >=, 1)
+/* ASSERT_NULL(measured): NULL == measured */
+#define ASSERT_NULL(seen) \
+	__EXPECT(NULL, seen, ==, 1)
 
-#define _ASSERT_TRUE(_seen) \
-	_ASSERT_NE(0, _seen)
-#define _ASSERT_FALSE(_seen) \
-	_ASSERT_EQ(0, _seen)
-#define _ASSERT_STREQ(_expected, _seen) \
-	__EXPECT_STR(_expected, _seen, ==, 1)
-#define _ASSERT_STRNE(_expected, _seen) \
-	__EXPECT_STR(_expected, _seen, !=, 1)
+/* ASSERT_TRUE(measured): measured != 0 */
+#define ASSERT_TRUE(seen) \
+	ASSERT_NE(0, seen)
+/* ASSERT_FALSE(measured): measured == 0 */
+#define ASSERT_FALSE(seen) \
+	ASSERT_EQ(0, seen)
+/* ASSERT_STREQ(expected, measured): !strcmp(expected, measured) */
+#define ASSERT_STREQ(expected, seen) \
+	__EXPECT_STR(expected, seen, ==, 1)
+/* ASSERT_STRNE(expected, measured): strcmp(expected, measured) */
+#define ASSERT_STRNE(expected, seen) \
+	__EXPECT_STR(expected, seen, !=, 1)
 
-#define _EXPECT_EQ(_expected, _seen) \
-	__EXPECT(_expected, _seen, ==, 0)
-#define _EXPECT_NE(_expected, _seen) \
-	__EXPECT(_expected, _seen, !=, 0)
-#define _EXPECT_LT(_expected, _seen) \
-	__EXPECT(_expected, _seen, <, 0)
-#define _EXPECT_LE(_expected, _seen) \
-	__EXPECT(_expected, _seen, <=, 0)
-#define _EXPECT_GT(_expected, _seen) \
-	__EXPECT(_expected, _seen, >, 0)
-#define _EXPECT_GE(_expected, _seen) \
-	__EXPECT(_expected, _seen, >=, 0)
+/* EXPECT_EQ(expected, measured): expected == measured */
+#define EXPECT_EQ(expected, seen) \
+	__EXPECT(expected, seen, ==, 0)
+/* EXPECT_NE(expected, measured): expected != measured */
+#define EXPECT_NE(expected, seen) \
+	__EXPECT(expected, seen, !=, 0)
+/* EXPECT_LT(expected, measured): expected < measured */
+#define EXPECT_LT(expected, seen) \
+	__EXPECT(expected, seen, <, 0)
+/* EXPECT_LE(expected, measured): expected <= measured */
+#define EXPECT_LE(expected, seen) \
+	__EXPECT(expected, seen, <=, 0)
+/* EXPECT_GT(expected, measured): expected > measured */
+#define EXPECT_GT(expected, seen) \
+	__EXPECT(expected, seen, >, 0)
+/* EXPECT_GE(expected, measured): expected >= measured */
+#define EXPECT_GE(expected, seen) \
+	__EXPECT(expected, seen, >=, 0)
 
-#define _EXPECT_NULL(_seen) \
-	__EXPECT(NULL, _seen, ==, 0)
-#define _EXPECT_TRUE(_seen) \
-	_EXPECT_NE(0, _seen)
-#define _EXPECT_FALSE(_seen) \
-	_EXPECT_EQ(0, _seen)
+/* EXPECT_NULL(measured): NULL == measured */
+#define EXPECT_NULL(seen) \
+	__EXPECT(NULL, seen, ==, 0)
+/* EXPECT_TRUE(measured): 0 != measured */
+#define EXPECT_TRUE(seen) \
+	EXPECT_NE(0, seen)
+/* EXPECT_FALSE(measured): 0 == measured */
+#define EXPECT_FALSE(seen) \
+	EXPECT_EQ(0, seen)
 
-#define _EXPECT_STREQ(_expected, _seen) \
-	__EXPECT_STR(_expected, _seen, ==, 0)
-#define _EXPECT_STRNE(_expected, _seen) \
-	__EXPECT_STR(_expected, _seen, !=, 0)
+/* EXPECT_STREQ(expected, measured): !strcmp(expected, measured) */
+#define EXPECT_STREQ(expected, seen) \
+	__EXPECT_STR(expected, seen, ==, 0)
+/* EXPECT_STRNE(expected, measured): strcmp(expected, measured) */
+#define EXPECT_STRNE(expected, seen) \
+	__EXPECT_STR(expected, seen, !=, 0)
 
 #define ARRAY_SIZE(a)	(sizeof(a) / sizeof(a[0]))
 
Signature · 1 line
2.11.0
Acked-by on v5 6/7
#10 lore raw

Re: [PATCH v5 6/7] selftests: Remove the TEST_API() wrapper from kselftest_harness.h

Quoted 8 lines · Mickaël Salaün

Remove the TEST_API() wrapper to expose the underlying macro arguments to the documentation tools.

Use "git diff --patience" to get a more readable patch.

Changes since v4:
* standalone patch to ease the review (requested by Kees Cook)

Quoted 6 lines
Cc Andy Lutomirski <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>

Thanks for the split!

-Kees

Quoted 442 lines
---
 tools/testing/selftests/kselftest_harness.h | 349 ++++++++++++----------------
 1 file changed, 147 insertions(+), 202 deletions(-)
tools/testing/selftests/kselftest_harness.h +147 -203
index 171e70aead9c..45f807ce37e1 100644
@@ -51,147 +51,6 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
-/* All exported functionality should be declared through this macro. */
-#define TEST_API(x) _##x
-
-/*
- * Exported APIs
- */
-
-/* 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
- * as such.  Returning early may be performed with a bare "return;" statement.
- *
- * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
- */
-#define TEST TEST_API(TEST)
-
-/* 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
- * as such.  Returning early may be performed with a bare "return;" statement.
- *
- * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
- */
-#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
- * populated and cleaned up using FIXTURE_SETUP and FIXTURE_TEARDOWN.
- */
-#define FIXTURE TEST_API(FIXTURE)
-
-/* 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.
- */
-#define FIXTURE_DATA TEST_API(FIXTURE_DATA)
-
-/* 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
- * implementation.
- *
- * ASSERT_* are valid for use in this context and will prempt the execution
- * of any dependent fixture tests.
- *
- * A bare "return;" statement may be used to return early.
- */
-#define FIXTURE_SETUP TEST_API(FIXTURE_SETUP)
-
-/* 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
- * 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 }
- * 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
- * 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
- */
-#define TEST_HARNESS_MAIN TEST_API(TEST_HARNESS_MAIN)
-
-/*
- * 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 */
-#define ASSERT_EQ TEST_API(ASSERT_EQ)
-/* ASSERT_NE(expected, measured): expected != measured */
-#define ASSERT_NE TEST_API(ASSERT_NE)
-/* ASSERT_LT(expected, measured): expected < measured */
-#define ASSERT_LT TEST_API(ASSERT_LT)
-/* ASSERT_LE(expected, measured): expected <= measured */
-#define ASSERT_LE TEST_API(ASSERT_LE)
-/* ASSERT_GT(expected, measured): expected > measured */
-#define ASSERT_GT TEST_API(ASSERT_GT)
-/* ASSERT_GE(expected, measured): expected >= measured */
-#define ASSERT_GE TEST_API(ASSERT_GE)
-/* ASSERT_NULL(measured): NULL == measured */
-#define ASSERT_NULL TEST_API(ASSERT_NULL)
-/* ASSERT_TRUE(measured): measured != 0 */
-#define ASSERT_TRUE TEST_API(ASSERT_TRUE)
-/* ASSERT_FALSE(measured): measured == 0 */
-#define ASSERT_FALSE TEST_API(ASSERT_FALSE)
-/* ASSERT_STREQ(expected, measured): !strcmp(expected, measured) */
-#define ASSERT_STREQ TEST_API(ASSERT_STREQ)
-/* ASSERT_STRNE(expected, measured): strcmp(expected, measured) */
-#define ASSERT_STRNE TEST_API(ASSERT_STRNE)
-/* EXPECT_EQ(expected, measured): expected == measured */
-#define EXPECT_EQ TEST_API(EXPECT_EQ)
-/* EXPECT_NE(expected, measured): expected != measured */
-#define EXPECT_NE TEST_API(EXPECT_NE)
-/* EXPECT_LT(expected, measured): expected < measured */
-#define EXPECT_LT TEST_API(EXPECT_LT)
-/* EXPECT_LE(expected, measured): expected <= measured */
-#define EXPECT_LE TEST_API(EXPECT_LE)
-/* EXPECT_GT(expected, measured): expected > measured */
-#define EXPECT_GT TEST_API(EXPECT_GT)
-/* EXPECT_GE(expected, measured): expected >= measured */
-#define EXPECT_GE TEST_API(EXPECT_GE)
-/* EXPECT_NULL(measured): NULL == measured */
-#define EXPECT_NULL TEST_API(EXPECT_NULL)
-/* EXPECT_TRUE(measured): 0 != measured */
-#define EXPECT_TRUE TEST_API(EXPECT_TRUE)
-/* EXPECT_FALSE(measured): 0 == measured */
-#define EXPECT_FALSE TEST_API(EXPECT_FALSE)
-/* EXPECT_STREQ(expected, measured): !strcmp(expected, measured) */
-#define EXPECT_STREQ TEST_API(EXPECT_STREQ)
-/* EXPECT_STRNE(expected, measured): strcmp(expected, measured) */
-#define EXPECT_STRNE TEST_API(EXPECT_STRNE)
-
-/* 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)
-
-/*
- * Internal implementation.
- *
- */
 
 /* Utilities exposed to the test definitions */
 #ifndef TH_LOG_STREAM
@@ -202,7 +61,13 @@
 #  define TH_LOG_ENABLED 1
 #endif
 
-#define _TH_LOG(fmt, ...) do { \
+/* 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(fmt, ...) do { \
        if (TH_LOG_ENABLED) \
                __TH_LOG(fmt, ##__VA_ARGS__); \
 } while (0)
@@ -212,10 +77,26 @@
                fprintf(TH_LOG_STREAM, "%s:%d:%s:" fmt "\n", \
                        __FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
 
+/* 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
+ * as such.  Returning early may be performed with a bare "return;" statement.
+ *
+ * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
+ */
 /* Defines the test function and creates the registration stub. */
-#define _TEST(test_name) __TEST_IMPL(test_name, -1)
+#define TEST(test_name) __TEST_IMPL(test_name, -1)
 
-#define _TEST_SIGNAL(test_name, signal) __TEST_IMPL(test_name, signal)
+/* 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
+ * as such.  Returning early may be performed with a bare "return;" statement.
+ *
+ * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
+ */
+#define TEST_SIGNAL(test_name, signal) __TEST_IMPL(test_name, signal)
 
 #define __TEST_IMPL(test_name, _signal) \
        static void test_name(struct __test_metadata *_metadata); \
@@ -229,50 +110,84 @@
        static void test_name( \
                struct __test_metadata __attribute__((unused)) *_metadata)
 
+/* 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.
+ */
 /* Wraps the struct name so we have one less argument to pass around. */
-#define _FIXTURE_DATA(fixture_name) struct _test_data_##fixture_name
+#define FIXTURE_DATA(datatype_name) struct _test_data_##datatype_name
 
+/* 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.
+ */
 /* Called once per fixture to setup the data and register. */
-#define _FIXTURE(fixture_name) \
+#define FIXTURE(fixture_name) \
        static void __attribute__((constructor)) \
        _register_##fixture_name##_data(void) \
        { \
                __fixture_count++; \
        } \
-       _FIXTURE_DATA(fixture_name)
+       FIXTURE_DATA(fixture_name)
 
+/* 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
+ * implementation.
+ *
+ * ASSERT_* are valid for use in this context and will prempt the execution
+ * of any dependent fixture tests.
+ *
+ * A bare "return;" statement may be used to return early.
+ */
 /* Prepares the setup function for the fixture.  |_metadata| is included
  * so that ASSERT_* work as a convenience.
  */
-#define _FIXTURE_SETUP(fixture_name) \
+#define FIXTURE_SETUP(fixture_name) \
        void fixture_name##_setup( \
                struct __test_metadata __attribute__((unused)) *_metadata, \
-               _FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
-#define _FIXTURE_TEARDOWN(fixture_name) \
+               FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
+/* 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
+ * implementation to clean up.
+ *
+ * A bare "return;" statement may be used to return early.
+ */
+#define FIXTURE_TEARDOWN(fixture_name) \
        void fixture_name##_teardown( \
                struct __test_metadata __attribute__((unused)) *_metadata, \
-               _FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
+               FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
+/* 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
+ * datatype exposed for use by the implementation.
+ */
 /* Emits test registration and helpers for fixture-based test
  * cases.
  * TODO(wad) register fixtures on dedicated test lists.
  */
-#define _TEST_F(fixture_name, test_name) \
+#define TEST_F(fixture_name, test_name) \
        __TEST_F_IMPL(fixture_name, test_name, -1)
 
-#define _TEST_F_SIGNAL(fixture_name, test_name, signal) \
+#define TEST_F_SIGNAL(fixture_name, test_name, signal) \
        __TEST_F_IMPL(fixture_name, test_name, signal)
 
 #define __TEST_F_IMPL(fixture_name, test_name, signal) \
        static void fixture_name##_##test_name( \
                struct __test_metadata *_metadata, \
-               _FIXTURE_DATA(fixture_name) *self); \
+               FIXTURE_DATA(fixture_name) *self); \
        static inline void wrapper_##fixture_name##_##test_name( \
                struct __test_metadata *_metadata) \
        { \
                /* fixture data is alloced, setup, and torn down per call. */ \
-               _FIXTURE_DATA(fixture_name) self; \
-               memset(&self, 0, sizeof(_FIXTURE_DATA(fixture_name))); \
+               FIXTURE_DATA(fixture_name) self; \
+               memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \
                fixture_name##_setup(_metadata, &self); \
                /* Let setup failure terminate early. */ \
                if (!_metadata->passed) \
@@ -293,10 +208,13 @@
        } \
        static void fixture_name##_##test_name( \
                struct __test_metadata __attribute__((unused)) *_metadata, \
-               _FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
+               FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
+/* Use once to append a main() to the test file. E.g.,
+ *   TEST_HARNESS_MAIN
+ */
 /* Exports a simple wrapper to run the test harness. */
-#define _TEST_HARNESS_MAIN \
+#define TEST_HARNESS_MAIN \
        static void __attribute__((constructor)) \
        __constructor_order_last(void) \
        { \
@@ -307,54 +225,81 @@
                return test_harness_run(argc, argv); \
        }
 
-#define _ASSERT_EQ(_expected, _seen) \
-       __EXPECT(_expected, _seen, ==, 1)
-#define _ASSERT_NE(_expected, _seen) \
-       __EXPECT(_expected, _seen, !=, 1)
-#define _ASSERT_LT(_expected, _seen) \
-       __EXPECT(_expected, _seen, <, 1)
-#define _ASSERT_LE(_expected, _seen) \
-       __EXPECT(_expected, _seen, <=, 1)
-#define _ASSERT_GT(_expected, _seen) \
-       __EXPECT(_expected, _seen, >, 1)
-#define _ASSERT_GE(_expected, _seen) \
-       __EXPECT(_expected, _seen, >=, 1)
-#define _ASSERT_NULL(_seen) \
-       __EXPECT(NULL, _seen, ==, 1)
+/*
+ * 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 */
+#define ASSERT_EQ(expected, seen) \
+       __EXPECT(expected, seen, ==, 1)
+/* ASSERT_NE(expected, measured): expected != measured */
+#define ASSERT_NE(expected, seen) \
+       __EXPECT(expected, seen, !=, 1)
+/* ASSERT_LT(expected, measured): expected < measured */
+#define ASSERT_LT(expected, seen) \
+       __EXPECT(expected, seen, <, 1)
+/* ASSERT_LE(expected, measured): expected <= measured */
+#define ASSERT_LE(expected, seen) \
+       __EXPECT(expected, seen, <=, 1)
+/* ASSERT_GT(expected, measured): expected > measured */
+#define ASSERT_GT(expected, seen) \
+       __EXPECT(expected, seen, >, 1)
+/* ASSERT_GE(expected, measured): expected >= measured */
+#define ASSERT_GE(expected, seen) \
+       __EXPECT(expected, seen, >=, 1)
+/* ASSERT_NULL(measured): NULL == measured */
+#define ASSERT_NULL(seen) \
+       __EXPECT(NULL, seen, ==, 1)
 
-#define _ASSERT_TRUE(_seen) \
-       _ASSERT_NE(0, _seen)
-#define _ASSERT_FALSE(_seen) \
-       _ASSERT_EQ(0, _seen)
-#define _ASSERT_STREQ(_expected, _seen) \
-       __EXPECT_STR(_expected, _seen, ==, 1)
-#define _ASSERT_STRNE(_expected, _seen) \
-       __EXPECT_STR(_expected, _seen, !=, 1)
+/* ASSERT_TRUE(measured): measured != 0 */
+#define ASSERT_TRUE(seen) \
+       ASSERT_NE(0, seen)
+/* ASSERT_FALSE(measured): measured == 0 */
+#define ASSERT_FALSE(seen) \
+       ASSERT_EQ(0, seen)
+/* ASSERT_STREQ(expected, measured): !strcmp(expected, measured) */
+#define ASSERT_STREQ(expected, seen) \
+       __EXPECT_STR(expected, seen, ==, 1)
+/* ASSERT_STRNE(expected, measured): strcmp(expected, measured) */
+#define ASSERT_STRNE(expected, seen) \
+       __EXPECT_STR(expected, seen, !=, 1)
 
-#define _EXPECT_EQ(_expected, _seen) \
-       __EXPECT(_expected, _seen, ==, 0)
-#define _EXPECT_NE(_expected, _seen) \
-       __EXPECT(_expected, _seen, !=, 0)
-#define _EXPECT_LT(_expected, _seen) \
-       __EXPECT(_expected, _seen, <, 0)
-#define _EXPECT_LE(_expected, _seen) \
-       __EXPECT(_expected, _seen, <=, 0)
-#define _EXPECT_GT(_expected, _seen) \
-       __EXPECT(_expected, _seen, >, 0)
-#define _EXPECT_GE(_expected, _seen) \
-       __EXPECT(_expected, _seen, >=, 0)
+/* EXPECT_EQ(expected, measured): expected == measured */
+#define EXPECT_EQ(expected, seen) \
+       __EXPECT(expected, seen, ==, 0)
+/* EXPECT_NE(expected, measured): expected != measured */
+#define EXPECT_NE(expected, seen) \
+       __EXPECT(expected, seen, !=, 0)
+/* EXPECT_LT(expected, measured): expected < measured */
+#define EXPECT_LT(expected, seen) \
+       __EXPECT(expected, seen, <, 0)
+/* EXPECT_LE(expected, measured): expected <= measured */
+#define EXPECT_LE(expected, seen) \
+       __EXPECT(expected, seen, <=, 0)
+/* EXPECT_GT(expected, measured): expected > measured */
+#define EXPECT_GT(expected, seen) \
+       __EXPECT(expected, seen, >, 0)
+/* EXPECT_GE(expected, measured): expected >= measured */
+#define EXPECT_GE(expected, seen) \
+       __EXPECT(expected, seen, >=, 0)
 
-#define _EXPECT_NULL(_seen) \
-       __EXPECT(NULL, _seen, ==, 0)
-#define _EXPECT_TRUE(_seen) \
-       _EXPECT_NE(0, _seen)
-#define _EXPECT_FALSE(_seen) \
-       _EXPECT_EQ(0, _seen)
+/* EXPECT_NULL(measured): NULL == measured */
+#define EXPECT_NULL(seen) \
+       __EXPECT(NULL, seen, ==, 0)
+/* EXPECT_TRUE(measured): 0 != measured */
+#define EXPECT_TRUE(seen) \
+       EXPECT_NE(0, seen)
+/* EXPECT_FALSE(measured): 0 == measured */
+#define EXPECT_FALSE(seen) \
+       EXPECT_EQ(0, seen)
 
-#define _EXPECT_STREQ(_expected, _seen) \
-       __EXPECT_STR(_expected, _seen, ==, 0)
-#define _EXPECT_STRNE(_expected, _seen) \
-       __EXPECT_STR(_expected, _seen, !=, 0)
+/* EXPECT_STREQ(expected, measured): !strcmp(expected, measured) */
+#define EXPECT_STREQ(expected, seen) \
+       __EXPECT_STR(expected, seen, ==, 0)
+/* EXPECT_STRNE(expected, measured): strcmp(expected, measured) */
+#define EXPECT_STRNE(expected, seen) \
+       __EXPECT_STR(expected, seen, !=, 0)
 
 #define ARRAY_SIZE(a)  (sizeof(a) / sizeof(a[0]))
 
--

2.11.0

Signature · 2 lines
Kees Cook
Pixel Security
#11 lore raw

PATCH v5 7/7 Documentation/dev-tools: Add kselftest_harness documentation

In reply to Mickaël Salaün

Add ReST metadata to kselftest_harness.h to be able to include the comments in the Sphinx documentation.

Changes since v4:
* exclude the TEST_API() changes (requested by Kees Cook)

Changes since v3:
* document macros as actual functions (suggested by Jonathan Corbet)
* remove the TEST_API() wrapper to expose the underlying macro arguments to the documentation tools
* move and cleanup comments

Changes since v2:
* add reference to the full documentation in the header file (suggested by Kees Cook)

Cc Andy Lutomirski <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>
---
 Documentation/dev-tools/kselftest.rst       |  34 +++
 tools/testing/selftests/kselftest_harness.h | 415 ++++++++++++++++++++++------
 2 files changed, 364 insertions(+), 85 deletions(-)
Documentation/dev-tools/kselftest.rst +34 -0
index 9232ce94612c..a92fa181b6cf 100644
@@ -120,3 +120,37 @@ 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 example.
+
+Example
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: example
+
+
+Helpers
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: TH_LOG TEST TEST_SIGNAL FIXTURE FIXTURE_DATA FIXTURE_SETUP
+                FIXTURE_TEARDOWN TEST_F TEST_HARNESS_MAIN
+
+Operators
+---------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: operators
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE
+                ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE
+                ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT
+                EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE
+                EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE
+
tools/testing/selftests/kselftest_harness.h +330 -85

549 lines not on this page · raw message

Signature · 1 line
2.11.0
Acked-by on v5 7/7
#12 lore raw

Re: [PATCH v5 7/7] Documentation/dev-tools: Add kselftest_harness documentation

Quoted 16 lines · Mickaël Salaün

Add ReST metadata to kselftest_harness.h to be able to include the comments in the Sphinx documentation.

Changes since v4:
* exclude the TEST_API() changes (requested by Kees Cook)

Changes since v3:
* document macros as actual functions (suggested by Jonathan Corbet)
* remove the TEST_API() wrapper to expose the underlying macro arguments to the documentation tools
* move and cleanup comments

Changes since v2:
* add reference to the full documentation in the header file (suggested by Kees Cook)

Quoted 6 lines
Cc Andy Lutomirski <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>

Awesome, this is great to have. :) I wonder if we have a self-test doc section yet. Hmmm.

-Kees

Quoted 613 lines
---
 Documentation/dev-tools/kselftest.rst       |  34 +++
 tools/testing/selftests/kselftest_harness.h | 415 ++++++++++++++++++++++------
 2 files changed, 364 insertions(+), 85 deletions(-)
Documentation/dev-tools/kselftest.rst +34 -0
index 9232ce94612c..a92fa181b6cf 100644
@@ -120,3 +120,37 @@ 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 example.
+
+Example
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: example
+
+
+Helpers
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: TH_LOG TEST TEST_SIGNAL FIXTURE FIXTURE_DATA FIXTURE_SETUP
+                FIXTURE_TEARDOWN TEST_F TEST_HARNESS_MAIN
+
+Operators
+---------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: operators
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE
+                ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE
+                ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT
+                EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE
+                EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE
+
tools/testing/selftests/kselftest_harness.h +330 -86
index 45f807ce37e1..c56f72e07cd7 100644
@@ -4,41 +4,49 @@
  *
  * 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
  */
 
+/**
+ * DOC: 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
+ */
+
 #ifndef __KSELFTEST_HARNESS_H
 #define __KSELFTEST_HARNESS_H
 
@@ -61,10 +69,20 @@
 #  define TH_LOG_ENABLED 1
 #endif
 
-/* TH_LOG(format, ...)
+/**
+ * TH_LOG(fmt, ...)
+ *
+ * @fmt: format string
+ * @...: optional arguments
+ *
+ * .. 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(fmt, ...) do { \
@@ -77,7 +95,16 @@
                fprintf(TH_LOG_STREAM, "%s:%d:%s:" fmt "\n", \
                        __FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
 
-/* TEST(name) { implementation }
+/**
+ * TEST(test_name) - Defines the test function and creates the registration
+ * stub
+ *
+ * @test_name: test name
+ *
+ * .. 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
@@ -85,10 +112,18 @@
  *
  * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
  */
-/* Defines the test function and creates the registration stub. */
 #define TEST(test_name) __TEST_IMPL(test_name, -1)
 
-/* TEST_SIGNAL(name, signal) { implementation }
+/**
+ * TEST_SIGNAL(test_name, signal)
+ *
+ * @test_name: test name
+ * @signal: signal number
+ *
+ * .. 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
@@ -110,22 +145,38 @@
        static void test_name( \
                struct __test_metadata __attribute__((unused)) *_metadata)
 
-/* FIXTURE_DATA(datatype name)
+/**
+ * FIXTURE_DATA(datatype_name) - Wraps the struct name so we have one less
+ * argument to pass around
+ *
+ * @datatype_name: datatype name
+ *
+ * .. 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.
  */
-/* Wraps the struct name so we have one less argument to pass around. */
 #define FIXTURE_DATA(datatype_name) struct _test_data_##datatype_name
 
-/* 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.
+/**
+ * FIXTURE(fixture_name) - Called once per fixture to setup the data and
+ * register
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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().
  */
-/* Called once per fixture to setup the data and register. */
 #define FIXTURE(fixture_name) \
        static void __attribute__((constructor)) \
        _register_##fixture_name##_data(void) \
@@ -134,9 +185,18 @@
        } \
        FIXTURE_DATA(fixture_name)
 
-/* FIXTURE_SETUP(fixture name) { implementation }
+/**
+ * FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
+ * *_metadata* is included so that ASSERT_* work as a convenience
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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
@@ -144,16 +204,21 @@
  *
  * A bare "return;" statement may be used to return early.
  */
-/* Prepares the setup function for the fixture.  |_metadata| is included
- * so that ASSERT_* work as a convenience.
- */
 #define FIXTURE_SETUP(fixture_name) \
        void fixture_name##_setup( \
                struct __test_metadata __attribute__((unused)) *_metadata, \
                FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
-/* FIXTURE_TEARDOWN(fixture name) { implementation }
+/**
+ * FIXTURE_TEARDOWN(fixture_name)
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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.
@@ -163,15 +228,22 @@
                struct __test_metadata __attribute__((unused)) *_metadata, \
                FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
-/* TEST_F(fixture, name) { implementation }
+/**
+ * TEST_F(fixture_name, test_name) - Emits test registration and helpers for
+ * fixture-based test cases
+ *
+ * @fixture_name: fixture name
+ * @test_name: test name
+ *
+ * .. 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.
  */
-/* Emits test registration and helpers for fixture-based test
- * cases.
- * TODO(wad) register fixtures on dedicated test lists.
- */
+/* TODO(wad) register fixtures on dedicated test lists. */
 #define TEST_F(fixture_name, test_name) \
        __TEST_F_IMPL(fixture_name, test_name, -1)
 
@@ -210,10 +282,15 @@
                struct __test_metadata __attribute__((unused)) *_metadata, \
                FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
-/* Use once to append a main() to the test file. E.g.,
- *   TEST_HARNESS_MAIN
+/**
+ * TEST_HARNESS_MAIN - Simple wrapper to run the test harness
+ *
+ * .. code-block:: c
+ *
+ *     TEST_HARNESS_MAIN
+ *
+ * Use once to append a main() to the test file.
  */
-/* Exports a simple wrapper to run the test harness. */
 #define TEST_HARNESS_MAIN \
        static void __attribute__((constructor)) \
        __constructor_order_last(void) \
@@ -225,79 +302,247 @@
                return test_harness_run(argc, argv); \
        }
 
-/*
- * Operators for use in TEST and TEST_F.
+/**
+ * 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 */
+
+/**
+ * ASSERT_EQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_EQ(expected, measured): expected == measured
+ */
 #define ASSERT_EQ(expected, seen) \
        __EXPECT(expected, seen, ==, 1)
-/* ASSERT_NE(expected, measured): expected != measured */
+
+/**
+ * ASSERT_NE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_NE(expected, measured): expected != measured
+ */
 #define ASSERT_NE(expected, seen) \
        __EXPECT(expected, seen, !=, 1)
-/* ASSERT_LT(expected, measured): expected < measured */
+
+/**
+ * ASSERT_LT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_LT(expected, measured): expected < measured
+ */
 #define ASSERT_LT(expected, seen) \
        __EXPECT(expected, seen, <, 1)
-/* ASSERT_LE(expected, measured): expected <= measured */
+
+/**
+ * ASSERT_LE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_LE(expected, measured): expected <= measured
+ */
 #define ASSERT_LE(expected, seen) \
        __EXPECT(expected, seen, <=, 1)
-/* ASSERT_GT(expected, measured): expected > measured */
+
+/**
+ * ASSERT_GT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_GT(expected, measured): expected > measured
+ */
 #define ASSERT_GT(expected, seen) \
        __EXPECT(expected, seen, >, 1)
-/* ASSERT_GE(expected, measured): expected >= measured */
+
+/**
+ * ASSERT_GE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_GE(expected, measured): expected >= measured
+ */
 #define ASSERT_GE(expected, seen) \
        __EXPECT(expected, seen, >=, 1)
-/* ASSERT_NULL(measured): NULL == measured */
+
+/**
+ * ASSERT_NULL(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_NULL(measured): NULL == measured
+ */
 #define ASSERT_NULL(seen) \
        __EXPECT(NULL, seen, ==, 1)
 
-/* ASSERT_TRUE(measured): measured != 0 */
+/**
+ * ASSERT_TRUE(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_TRUE(measured): measured != 0
+ */
 #define ASSERT_TRUE(seen) \
        ASSERT_NE(0, seen)
-/* ASSERT_FALSE(measured): measured == 0 */
+
+/**
+ * ASSERT_FALSE(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_FALSE(measured): measured == 0
+ */
 #define ASSERT_FALSE(seen) \
        ASSERT_EQ(0, seen)
-/* ASSERT_STREQ(expected, measured): !strcmp(expected, measured) */
+
+/**
+ * ASSERT_STREQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_STREQ(expected, measured): !strcmp(expected, measured)
+ */
 #define ASSERT_STREQ(expected, seen) \
        __EXPECT_STR(expected, seen, ==, 1)
-/* ASSERT_STRNE(expected, measured): strcmp(expected, measured) */
+
+/**
+ * ASSERT_STRNE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_STRNE(expected, measured): strcmp(expected, measured)
+ */
 #define ASSERT_STRNE(expected, seen) \
        __EXPECT_STR(expected, seen, !=, 1)
 
-/* EXPECT_EQ(expected, measured): expected == measured */
+/**
+ * EXPECT_EQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_EQ(expected, measured): expected == measured
+ */
 #define EXPECT_EQ(expected, seen) \
        __EXPECT(expected, seen, ==, 0)
-/* EXPECT_NE(expected, measured): expected != measured */
+
+/**
+ * EXPECT_NE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_NE(expected, measured): expected != measured
+ */
 #define EXPECT_NE(expected, seen) \
        __EXPECT(expected, seen, !=, 0)
-/* EXPECT_LT(expected, measured): expected < measured */
+
+/**
+ * EXPECT_LT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_LT(expected, measured): expected < measured
+ */
 #define EXPECT_LT(expected, seen) \
        __EXPECT(expected, seen, <, 0)
-/* EXPECT_LE(expected, measured): expected <= measured */
+
+/**
+ * EXPECT_LE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_LE(expected, measured): expected <= measured
+ */
 #define EXPECT_LE(expected, seen) \
        __EXPECT(expected, seen, <=, 0)
-/* EXPECT_GT(expected, measured): expected > measured */
+
+/**
+ * EXPECT_GT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_GT(expected, measured): expected > measured
+ */
 #define EXPECT_GT(expected, seen) \
        __EXPECT(expected, seen, >, 0)
-/* EXPECT_GE(expected, measured): expected >= measured */
+
+/**
+ * EXPECT_GE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_GE(expected, measured): expected >= measured
+ */
 #define EXPECT_GE(expected, seen) \
        __EXPECT(expected, seen, >=, 0)
 
-/* EXPECT_NULL(measured): NULL == measured */
+/**
+ * EXPECT_NULL(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_NULL(measured): NULL == measured
+ */
 #define EXPECT_NULL(seen) \
        __EXPECT(NULL, seen, ==, 0)
-/* EXPECT_TRUE(measured): 0 != measured */
+
+/**
+ * EXPECT_TRUE(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_TRUE(measured): 0 != measured
+ */
 #define EXPECT_TRUE(seen) \
        EXPECT_NE(0, seen)
-/* EXPECT_FALSE(measured): 0 == measured */
+
+/**
+ * EXPECT_FALSE(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_FALSE(measured): 0 == measured
+ */
 #define EXPECT_FALSE(seen) \
        EXPECT_EQ(0, seen)
 
-/* EXPECT_STREQ(expected, measured): !strcmp(expected, measured) */
+/**
+ * EXPECT_STREQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_STREQ(expected, measured): !strcmp(expected, measured)
+ */
 #define EXPECT_STREQ(expected, seen) \
        __EXPECT_STR(expected, seen, ==, 0)
-/* EXPECT_STRNE(expected, measured): strcmp(expected, measured) */
+
+/**
+ * EXPECT_STRNE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_STRNE(expected, measured): strcmp(expected, measured)
+ */
 #define EXPECT_STRNE(expected, seen) \
        __EXPECT_STR(expected, seen, !=, 0)
 
--

2.11.0

Signature · 2 lines
Kees Cook
Pixel Security
maintainer
#13 lore raw

Re: [PATCH v5 7/7] Documentation/dev-tools: Add kselftest_harness documentation

In reply to Mickaël Salaün

Hi Mickaël,

Quoted 3 lines · Mickaël Salaün

Add ReST metadata to kselftest_harness.h to be able to include the comments in the Sphinx documentation.

These don't belong the change log. These types of changes are for reviewers benefit and should be added between the sign-of block and the start of diff.

I had to fix a few patches in this series before commit.

Quoted 14 lines

Changes since v4:
* exclude the TEST_API() changes (requested by Kees Cook)

Changes since v3:
* document macros as actual functions (suggested by Jonathan Corbet)
* remove the TEST_API() wrapper to expose the underlying macro arguments to the documentation tools
* move and cleanup comments

Changes since v2:
* add reference to the full documentation in the header file (suggested by Kees Cook)

Quoted 6 lines
Cc Andy Lutomirski <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>

git am isn't happy:

Applying: Documentation/dev-tools: Add kselftest_harness documentation .git/rebase-apply/patch:47: new blank line at EOF.
+
warning: 1 line adds whitespace errors.

Please fix and resend.

-- Shuah

Quoted 611 lines
---
 Documentation/dev-tools/kselftest.rst       |  34 +++
 tools/testing/selftests/kselftest_harness.h | 415 ++++++++++++++++++++++------
 2 files changed, 364 insertions(+), 85 deletions(-)
Documentation/dev-tools/kselftest.rst +34 -0
index 9232ce94612c..a92fa181b6cf 100644
@@ -120,3 +120,37 @@ 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 example.
+
+Example
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: example
+
+
+Helpers
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: TH_LOG TEST TEST_SIGNAL FIXTURE FIXTURE_DATA FIXTURE_SETUP
+                FIXTURE_TEARDOWN TEST_F TEST_HARNESS_MAIN
+
+Operators
+---------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: operators
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE
+                ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE
+                ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT
+                EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE
+                EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE
+
tools/testing/selftests/kselftest_harness.h +330 -85
index 45f807ce37e1..c56f72e07cd7 100644
@@ -4,41 +4,49 @@
  *
  * 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
  */
 
+/**
+ * DOC: 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
+ */
+
 #ifndef __KSELFTEST_HARNESS_H
 #define __KSELFTEST_HARNESS_H
 
@@ -61,10 +69,20 @@
 #  define TH_LOG_ENABLED 1
 #endif
 
-/* TH_LOG(format, ...)
+/**
+ * TH_LOG(fmt, ...)
+ *
+ * @fmt: format string
+ * @...: optional arguments
+ *
+ * .. 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(fmt, ...) do { \
@@ -77,7 +95,16 @@
 		fprintf(TH_LOG_STREAM, "%s:%d:%s:" fmt "\n", \
 			__FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
 
-/* TEST(name) { implementation }
+/**
+ * TEST(test_name) - Defines the test function and creates the registration
+ * stub
+ *
+ * @test_name: test name
+ *
+ * .. 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
@@ -85,10 +112,18 @@
  *
  * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
  */
-/* Defines the test function and creates the registration stub. */
 #define TEST(test_name) __TEST_IMPL(test_name, -1)
 
-/* TEST_SIGNAL(name, signal) { implementation }
+/**
+ * TEST_SIGNAL(test_name, signal)
+ *
+ * @test_name: test name
+ * @signal: signal number
+ *
+ * .. 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
@@ -110,22 +145,38 @@
 	static void test_name( \
 		struct __test_metadata __attribute__((unused)) *_metadata)
 
-/* FIXTURE_DATA(datatype name)
+/**
+ * FIXTURE_DATA(datatype_name) - Wraps the struct name so we have one less
+ * argument to pass around
+ *
+ * @datatype_name: datatype name
+ *
+ * .. 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.
  */
-/* Wraps the struct name so we have one less argument to pass around. */
 #define FIXTURE_DATA(datatype_name) struct _test_data_##datatype_name
 
-/* 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.
+/**
+ * FIXTURE(fixture_name) - Called once per fixture to setup the data and
+ * register
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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().
  */
-/* Called once per fixture to setup the data and register. */
 #define FIXTURE(fixture_name) \
 	static void __attribute__((constructor)) \
 	_register_##fixture_name##_data(void) \
@@ -134,9 +185,18 @@
 	} \
 	FIXTURE_DATA(fixture_name)
 
-/* FIXTURE_SETUP(fixture name) { implementation }
+/**
+ * FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
+ * *_metadata* is included so that ASSERT_* work as a convenience
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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
@@ -144,16 +204,21 @@
  *
  * A bare "return;" statement may be used to return early.
  */
-/* Prepares the setup function for the fixture.  |_metadata| is included
- * so that ASSERT_* work as a convenience.
- */
 #define FIXTURE_SETUP(fixture_name) \
 	void fixture_name##_setup( \
 		struct __test_metadata __attribute__((unused)) *_metadata, \
 		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
-/* FIXTURE_TEARDOWN(fixture name) { implementation }
+/**
+ * FIXTURE_TEARDOWN(fixture_name)
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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.
@@ -163,15 +228,22 @@
 		struct __test_metadata __attribute__((unused)) *_metadata, \
 		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
-/* TEST_F(fixture, name) { implementation }
+/**
+ * TEST_F(fixture_name, test_name) - Emits test registration and helpers for
+ * fixture-based test cases
+ *
+ * @fixture_name: fixture name
+ * @test_name: test name
+ *
+ * .. 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.
  */
-/* Emits test registration and helpers for fixture-based test
- * cases.
- * TODO(wad) register fixtures on dedicated test lists.
- */
+/* TODO(wad) register fixtures on dedicated test lists. */
 #define TEST_F(fixture_name, test_name) \
 	__TEST_F_IMPL(fixture_name, test_name, -1)
 
@@ -210,10 +282,15 @@
 		struct __test_metadata __attribute__((unused)) *_metadata, \
 		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
-/* Use once to append a main() to the test file. E.g.,
- *   TEST_HARNESS_MAIN
+/**
+ * TEST_HARNESS_MAIN - Simple wrapper to run the test harness
+ *
+ * .. code-block:: c
+ *
+ *     TEST_HARNESS_MAIN
+ *
+ * Use once to append a main() to the test file.
  */
-/* Exports a simple wrapper to run the test harness. */
 #define TEST_HARNESS_MAIN \
 	static void __attribute__((constructor)) \
 	__constructor_order_last(void) \
@@ -225,79 +302,247 @@
 		return test_harness_run(argc, argv); \
 	}
 
-/*
- * Operators for use in TEST and TEST_F.
+/**
+ * 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 */
+
+/**
+ * ASSERT_EQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_EQ(expected, measured): expected == measured
+ */
 #define ASSERT_EQ(expected, seen) \
 	__EXPECT(expected, seen, ==, 1)
-/* ASSERT_NE(expected, measured): expected != measured */
+
+/**
+ * ASSERT_NE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_NE(expected, measured): expected != measured
+ */
 #define ASSERT_NE(expected, seen) \
 	__EXPECT(expected, seen, !=, 1)
-/* ASSERT_LT(expected, measured): expected < measured */
+
+/**
+ * ASSERT_LT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_LT(expected, measured): expected < measured
+ */
 #define ASSERT_LT(expected, seen) \
 	__EXPECT(expected, seen, <, 1)
-/* ASSERT_LE(expected, measured): expected <= measured */
+
+/**
+ * ASSERT_LE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_LE(expected, measured): expected <= measured
+ */
 #define ASSERT_LE(expected, seen) \
 	__EXPECT(expected, seen, <=, 1)
-/* ASSERT_GT(expected, measured): expected > measured */
+
+/**
+ * ASSERT_GT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_GT(expected, measured): expected > measured
+ */
 #define ASSERT_GT(expected, seen) \
 	__EXPECT(expected, seen, >, 1)
-/* ASSERT_GE(expected, measured): expected >= measured */
+
+/**
+ * ASSERT_GE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_GE(expected, measured): expected >= measured
+ */
 #define ASSERT_GE(expected, seen) \
 	__EXPECT(expected, seen, >=, 1)
-/* ASSERT_NULL(measured): NULL == measured */
+
+/**
+ * ASSERT_NULL(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_NULL(measured): NULL == measured
+ */
 #define ASSERT_NULL(seen) \
 	__EXPECT(NULL, seen, ==, 1)
 
-/* ASSERT_TRUE(measured): measured != 0 */
+/**
+ * ASSERT_TRUE(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_TRUE(measured): measured != 0
+ */
 #define ASSERT_TRUE(seen) \
 	ASSERT_NE(0, seen)
-/* ASSERT_FALSE(measured): measured == 0 */
+
+/**
+ * ASSERT_FALSE(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_FALSE(measured): measured == 0
+ */
 #define ASSERT_FALSE(seen) \
 	ASSERT_EQ(0, seen)
-/* ASSERT_STREQ(expected, measured): !strcmp(expected, measured) */
+
+/**
+ * ASSERT_STREQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_STREQ(expected, measured): !strcmp(expected, measured)
+ */
 #define ASSERT_STREQ(expected, seen) \
 	__EXPECT_STR(expected, seen, ==, 1)
-/* ASSERT_STRNE(expected, measured): strcmp(expected, measured) */
+
+/**
+ * ASSERT_STRNE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_STRNE(expected, measured): strcmp(expected, measured)
+ */
 #define ASSERT_STRNE(expected, seen) \
 	__EXPECT_STR(expected, seen, !=, 1)
 
-/* EXPECT_EQ(expected, measured): expected == measured */
+/**
+ * EXPECT_EQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_EQ(expected, measured): expected == measured
+ */
 #define EXPECT_EQ(expected, seen) \
 	__EXPECT(expected, seen, ==, 0)
-/* EXPECT_NE(expected, measured): expected != measured */
+
+/**
+ * EXPECT_NE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_NE(expected, measured): expected != measured
+ */
 #define EXPECT_NE(expected, seen) \
 	__EXPECT(expected, seen, !=, 0)
-/* EXPECT_LT(expected, measured): expected < measured */
+
+/**
+ * EXPECT_LT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_LT(expected, measured): expected < measured
+ */
 #define EXPECT_LT(expected, seen) \
 	__EXPECT(expected, seen, <, 0)
-/* EXPECT_LE(expected, measured): expected <= measured */
+
+/**
+ * EXPECT_LE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_LE(expected, measured): expected <= measured
+ */
 #define EXPECT_LE(expected, seen) \
 	__EXPECT(expected, seen, <=, 0)
-/* EXPECT_GT(expected, measured): expected > measured */
+
+/**
+ * EXPECT_GT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_GT(expected, measured): expected > measured
+ */
 #define EXPECT_GT(expected, seen) \
 	__EXPECT(expected, seen, >, 0)
-/* EXPECT_GE(expected, measured): expected >= measured */
+
+/**
+ * EXPECT_GE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_GE(expected, measured): expected >= measured
+ */
 #define EXPECT_GE(expected, seen) \
 	__EXPECT(expected, seen, >=, 0)
 
-/* EXPECT_NULL(measured): NULL == measured */
+/**
+ * EXPECT_NULL(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_NULL(measured): NULL == measured
+ */
 #define EXPECT_NULL(seen) \
 	__EXPECT(NULL, seen, ==, 0)
-/* EXPECT_TRUE(measured): 0 != measured */
+
+/**
+ * EXPECT_TRUE(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_TRUE(measured): 0 != measured
+ */
 #define EXPECT_TRUE(seen) \
 	EXPECT_NE(0, seen)
-/* EXPECT_FALSE(measured): 0 == measured */
+
+/**
+ * EXPECT_FALSE(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_FALSE(measured): 0 == measured
+ */
 #define EXPECT_FALSE(seen) \
 	EXPECT_EQ(0, seen)
 
-/* EXPECT_STREQ(expected, measured): !strcmp(expected, measured) */
+/**
+ * EXPECT_STREQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_STREQ(expected, measured): !strcmp(expected, measured)
+ */
 #define EXPECT_STREQ(expected, seen) \
 	__EXPECT_STR(expected, seen, ==, 0)
-/* EXPECT_STRNE(expected, measured): strcmp(expected, measured) */
+
+/**
+ * EXPECT_STRNE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_STRNE(expected, measured): strcmp(expected, measured)
+ */
 #define EXPECT_STRNE(expected, seen) \
 	__EXPECT_STR(expected, seen, !=, 0)
 
#14 lore raw

Re: [PATCH v5 7/7] Documentation/dev-tools: Add kselftest_harness documentation

Quoted 10 lines · Shuah Khan

Hi Mickaël,

Quoted 3 lines · Mickaël Salaün

Add ReST metadata to kselftest_harness.h to be able to include the comments in the Sphinx documentation.

These don't belong the change log. These types of changes are for reviewers benefit and should be added between the sign-of block and the start of diff.

OK, I didn't know this rule, which seems different from one maintainer to another. I'll take this into account the next time.

Quoted 24 lines

I had to fix a few patches in this series before commit.

Quoted 14 lines

Changes since v4:
* exclude the TEST_API() changes (requested by Kees Cook)

Changes since v3:
* document macros as actual functions (suggested by Jonathan Corbet)
* remove the TEST_API() wrapper to expose the underlying macro arguments to the documentation tools
* move and cleanup comments

Changes since v2:
* add reference to the full documentation in the header file (suggested by Kees Cook)

Quoted 6 lines
Cc Andy Lutomirski <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>
Quoted 8 lines

git am isn't happy:

Applying: Documentation/dev-tools: Add kselftest_harness documentation .git/rebase-apply/patch:47: new blank line at EOF.
+
warning: 1 line adds whitespace errors.

Please fix and resend.

I didn't try to apply the series with "git am" since neither "git format-patch" nor scripts/checkpatch.pl output a warning.

This "git am" warning is about the last line of the ReST file which end with an empty line. I will fix it if needed.

Quoted 616 lines

-- Shuah

Quoted 611 lines
---
 Documentation/dev-tools/kselftest.rst       |  34 +++
 tools/testing/selftests/kselftest_harness.h | 415 ++++++++++++++++++++++------
 2 files changed, 364 insertions(+), 85 deletions(-)
Documentation/dev-tools/kselftest.rst +34 -0
index 9232ce94612c..a92fa181b6cf 100644
@@ -120,3 +120,37 @@ 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 example.
+
+Example
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: example
+
+
+Helpers
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: TH_LOG TEST TEST_SIGNAL FIXTURE FIXTURE_DATA FIXTURE_SETUP
+                FIXTURE_TEARDOWN TEST_F TEST_HARNESS_MAIN
+
+Operators
+---------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: operators
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE
+                ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE
+                ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT
+                EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE
+                EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE
+
tools/testing/selftests/kselftest_harness.h +330 -85
index 45f807ce37e1..c56f72e07cd7 100644
@@ -4,41 +4,49 @@
  *
  * 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
  */
 
+/**
+ * DOC: 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
+ */
+
 #ifndef __KSELFTEST_HARNESS_H
 #define __KSELFTEST_HARNESS_H
 
@@ -61,10 +69,20 @@
 #  define TH_LOG_ENABLED 1
 #endif
 
-/* TH_LOG(format, ...)
+/**
+ * TH_LOG(fmt, ...)
+ *
+ * @fmt: format string
+ * @...: optional arguments
+ *
+ * .. 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(fmt, ...) do { \
@@ -77,7 +95,16 @@
 		fprintf(TH_LOG_STREAM, "%s:%d:%s:" fmt "\n", \
 			__FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
 
-/* TEST(name) { implementation }
+/**
+ * TEST(test_name) - Defines the test function and creates the registration
+ * stub
+ *
+ * @test_name: test name
+ *
+ * .. 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
@@ -85,10 +112,18 @@
  *
  * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
  */
-/* Defines the test function and creates the registration stub. */
 #define TEST(test_name) __TEST_IMPL(test_name, -1)
 
-/* TEST_SIGNAL(name, signal) { implementation }
+/**
+ * TEST_SIGNAL(test_name, signal)
+ *
+ * @test_name: test name
+ * @signal: signal number
+ *
+ * .. 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
@@ -110,22 +145,38 @@
 	static void test_name( \
 		struct __test_metadata __attribute__((unused)) *_metadata)
 
-/* FIXTURE_DATA(datatype name)
+/**
+ * FIXTURE_DATA(datatype_name) - Wraps the struct name so we have one less
+ * argument to pass around
+ *
+ * @datatype_name: datatype name
+ *
+ * .. 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.
  */
-/* Wraps the struct name so we have one less argument to pass around. */
 #define FIXTURE_DATA(datatype_name) struct _test_data_##datatype_name
 
-/* 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.
+/**
+ * FIXTURE(fixture_name) - Called once per fixture to setup the data and
+ * register
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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().
  */
-/* Called once per fixture to setup the data and register. */
 #define FIXTURE(fixture_name) \
 	static void __attribute__((constructor)) \
 	_register_##fixture_name##_data(void) \
@@ -134,9 +185,18 @@
 	} \
 	FIXTURE_DATA(fixture_name)
 
-/* FIXTURE_SETUP(fixture name) { implementation }
+/**
+ * FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
+ * *_metadata* is included so that ASSERT_* work as a convenience
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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
@@ -144,16 +204,21 @@
  *
  * A bare "return;" statement may be used to return early.
  */
-/* Prepares the setup function for the fixture.  |_metadata| is included
- * so that ASSERT_* work as a convenience.
- */
 #define FIXTURE_SETUP(fixture_name) \
 	void fixture_name##_setup( \
 		struct __test_metadata __attribute__((unused)) *_metadata, \
 		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
-/* FIXTURE_TEARDOWN(fixture name) { implementation }
+/**
+ * FIXTURE_TEARDOWN(fixture_name)
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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.
@@ -163,15 +228,22 @@
 		struct __test_metadata __attribute__((unused)) *_metadata, \
 		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
-/* TEST_F(fixture, name) { implementation }
+/**
+ * TEST_F(fixture_name, test_name) - Emits test registration and helpers for
+ * fixture-based test cases
+ *
+ * @fixture_name: fixture name
+ * @test_name: test name
+ *
+ * .. 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.
  */
-/* Emits test registration and helpers for fixture-based test
- * cases.
- * TODO(wad) register fixtures on dedicated test lists.
- */
+/* TODO(wad) register fixtures on dedicated test lists. */
 #define TEST_F(fixture_name, test_name) \
 	__TEST_F_IMPL(fixture_name, test_name, -1)
 
@@ -210,10 +282,15 @@
 		struct __test_metadata __attribute__((unused)) *_metadata, \
 		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
-/* Use once to append a main() to the test file. E.g.,
- *   TEST_HARNESS_MAIN
+/**
+ * TEST_HARNESS_MAIN - Simple wrapper to run the test harness
+ *
+ * .. code-block:: c
+ *
+ *     TEST_HARNESS_MAIN
+ *
+ * Use once to append a main() to the test file.
  */
-/* Exports a simple wrapper to run the test harness. */
 #define TEST_HARNESS_MAIN \
 	static void __attribute__((constructor)) \
 	__constructor_order_last(void) \
@@ -225,79 +302,247 @@
 		return test_harness_run(argc, argv); \
 	}
 
-/*
- * Operators for use in TEST and TEST_F.
+/**
+ * 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 */
+
+/**
+ * ASSERT_EQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_EQ(expected, measured): expected == measured
+ */
 #define ASSERT_EQ(expected, seen) \
 	__EXPECT(expected, seen, ==, 1)
-/* ASSERT_NE(expected, measured): expected != measured */
+
+/**
+ * ASSERT_NE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_NE(expected, measured): expected != measured
+ */
 #define ASSERT_NE(expected, seen) \
 	__EXPECT(expected, seen, !=, 1)
-/* ASSERT_LT(expected, measured): expected < measured */
+
+/**
+ * ASSERT_LT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_LT(expected, measured): expected < measured
+ */
 #define ASSERT_LT(expected, seen) \
 	__EXPECT(expected, seen, <, 1)
-/* ASSERT_LE(expected, measured): expected <= measured */
+
+/**
+ * ASSERT_LE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_LE(expected, measured): expected <= measured
+ */
 #define ASSERT_LE(expected, seen) \
 	__EXPECT(expected, seen, <=, 1)
-/* ASSERT_GT(expected, measured): expected > measured */
+
+/**
+ * ASSERT_GT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_GT(expected, measured): expected > measured
+ */
 #define ASSERT_GT(expected, seen) \
 	__EXPECT(expected, seen, >, 1)
-/* ASSERT_GE(expected, measured): expected >= measured */
+
+/**
+ * ASSERT_GE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_GE(expected, measured): expected >= measured
+ */
 #define ASSERT_GE(expected, seen) \
 	__EXPECT(expected, seen, >=, 1)
-/* ASSERT_NULL(measured): NULL == measured */
+
+/**
+ * ASSERT_NULL(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_NULL(measured): NULL == measured
+ */
 #define ASSERT_NULL(seen) \
 	__EXPECT(NULL, seen, ==, 1)
 
-/* ASSERT_TRUE(measured): measured != 0 */
+/**
+ * ASSERT_TRUE(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_TRUE(measured): measured != 0
+ */
 #define ASSERT_TRUE(seen) \
 	ASSERT_NE(0, seen)
-/* ASSERT_FALSE(measured): measured == 0 */
+
+/**
+ * ASSERT_FALSE(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_FALSE(measured): measured == 0
+ */
 #define ASSERT_FALSE(seen) \
 	ASSERT_EQ(0, seen)
-/* ASSERT_STREQ(expected, measured): !strcmp(expected, measured) */
+
+/**
+ * ASSERT_STREQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_STREQ(expected, measured): !strcmp(expected, measured)
+ */
 #define ASSERT_STREQ(expected, seen) \
 	__EXPECT_STR(expected, seen, ==, 1)
-/* ASSERT_STRNE(expected, measured): strcmp(expected, measured) */
+
+/**
+ * ASSERT_STRNE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_STRNE(expected, measured): strcmp(expected, measured)
+ */
 #define ASSERT_STRNE(expected, seen) \
 	__EXPECT_STR(expected, seen, !=, 1)
 
-/* EXPECT_EQ(expected, measured): expected == measured */
+/**
+ * EXPECT_EQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_EQ(expected, measured): expected == measured
+ */
 #define EXPECT_EQ(expected, seen) \
 	__EXPECT(expected, seen, ==, 0)
-/* EXPECT_NE(expected, measured): expected != measured */
+
+/**
+ * EXPECT_NE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_NE(expected, measured): expected != measured
+ */
 #define EXPECT_NE(expected, seen) \
 	__EXPECT(expected, seen, !=, 0)
-/* EXPECT_LT(expected, measured): expected < measured */
+
+/**
+ * EXPECT_LT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_LT(expected, measured): expected < measured
+ */
 #define EXPECT_LT(expected, seen) \
 	__EXPECT(expected, seen, <, 0)
-/* EXPECT_LE(expected, measured): expected <= measured */
+
+/**
+ * EXPECT_LE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_LE(expected, measured): expected <= measured
+ */
 #define EXPECT_LE(expected, seen) \
 	__EXPECT(expected, seen, <=, 0)
-/* EXPECT_GT(expected, measured): expected > measured */
+
+/**
+ * EXPECT_GT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_GT(expected, measured): expected > measured
+ */
 #define EXPECT_GT(expected, seen) \
 	__EXPECT(expected, seen, >, 0)
-/* EXPECT_GE(expected, measured): expected >= measured */
+
+/**
+ * EXPECT_GE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_GE(expected, measured): expected >= measured
+ */
 #define EXPECT_GE(expected, seen) \
 	__EXPECT(expected, seen, >=, 0)
 
-/* EXPECT_NULL(measured): NULL == measured */
+/**
+ * EXPECT_NULL(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_NULL(measured): NULL == measured
+ */
 #define EXPECT_NULL(seen) \
 	__EXPECT(NULL, seen, ==, 0)
-/* EXPECT_TRUE(measured): 0 != measured */
+
+/**
+ * EXPECT_TRUE(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_TRUE(measured): 0 != measured
+ */
 #define EXPECT_TRUE(seen) \
 	EXPECT_NE(0, seen)
-/* EXPECT_FALSE(measured): 0 == measured */
+
+/**
+ * EXPECT_FALSE(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_FALSE(measured): 0 == measured
+ */
 #define EXPECT_FALSE(seen) \
 	EXPECT_EQ(0, seen)
 
-/* EXPECT_STREQ(expected, measured): !strcmp(expected, measured) */
+/**
+ * EXPECT_STREQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_STREQ(expected, measured): !strcmp(expected, measured)
+ */
 #define EXPECT_STREQ(expected, seen) \
 	__EXPECT_STR(expected, seen, ==, 0)
-/* EXPECT_STRNE(expected, measured): strcmp(expected, measured) */
+
+/**
+ * EXPECT_STRNE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_STRNE(expected, measured): strcmp(expected, measured)
+ */
 #define EXPECT_STRNE(expected, seen) \
 	__EXPECT_STR(expected, seen, !=, 0)
 
maintainer
#15 lore raw

Re: [PATCH v5 7/7] Documentation/dev-tools: Add kselftest_harness documentation

Quoted 9 lines · Mickaël Salaün
Quoted 7 lines · Shuah Khan

Hi Mickaël,

Quoted 3 lines · Mickaël Salaün

Add ReST metadata to kselftest_harness.h to be able to include the comments in the Sphinx documentation.

Quoted 6 lines
Quoted 3 lines

These don't belong the change log. These types of changes are for reviewers benefit and should be added between the sign-of block and the start of diff.

OK, I didn't know this rule, which seems different from one maintainer to another. I'll take this into account the next time.

It is a standard practice. Not just mine. If there is any information from these version to version differences that belong in the changelog, they need to be in the changelog format.

Quoted 32 lines
Quoted 32 lines

I had to fix a few patches in this series before commit.

Quoted 14 lines

Changes since v4:
* exclude the TEST_API() changes (requested by Kees Cook)

Changes since v3:
* document macros as actual functions (suggested by Jonathan Corbet)
* remove the TEST_API() wrapper to expose the underlying macro arguments to the documentation tools
* move and cleanup comments

Changes since v2:
* add reference to the full documentation in the header file (suggested by Kees Cook)

Quoted 6 lines
Cc Andy Lutomirski <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Will Drewry <[email protected]>

git am isn't happy:

Applying: Documentation/dev-tools: Add kselftest_harness documentation .git/rebase-apply/patch:47: new blank line at EOF.
+
warning: 1 line adds whitespace errors.

Quoted 7 lines
Quoted 1 line

Please fix and resend.

I didn't try to apply the series with "git am" since neither "git format-patch" nor scripts/checkpatch.pl output a warning.

This "git am" warning is about the last line of the ReST file which end with an empty line. I will fix it if needed.

Yeah that is what it is complaining about. Checkpatch didn't complain. Fix it and resend. I don't like git am complaining about patches. :)

-- Shuah

Quoted 618 lines
Quoted 617 lines

-- Shuah

Quoted 611 lines
---
 Documentation/dev-tools/kselftest.rst       |  34 +++
 tools/testing/selftests/kselftest_harness.h | 415 ++++++++++++++++++++++------
 2 files changed, 364 insertions(+), 85 deletions(-)
Documentation/dev-tools/kselftest.rst +34 -0
index 9232ce94612c..a92fa181b6cf 100644
@@ -120,3 +120,37 @@ 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 example.
+
+Example
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: example
+
+
+Helpers
+-------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: TH_LOG TEST TEST_SIGNAL FIXTURE FIXTURE_DATA FIXTURE_SETUP
+                FIXTURE_TEARDOWN TEST_F TEST_HARNESS_MAIN
+
+Operators
+---------
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :doc: operators
+
+.. kernel-doc:: tools/testing/selftests/kselftest_harness.h
+    :functions: ASSERT_EQ ASSERT_NE ASSERT_LT ASSERT_LE ASSERT_GT ASSERT_GE
+                ASSERT_NULL ASSERT_TRUE ASSERT_NULL ASSERT_TRUE ASSERT_FALSE
+                ASSERT_STREQ ASSERT_STRNE EXPECT_EQ EXPECT_NE EXPECT_LT
+                EXPECT_LE EXPECT_GT EXPECT_GE EXPECT_NULL EXPECT_TRUE
+                EXPECT_FALSE EXPECT_STREQ EXPECT_STRNE
+
tools/testing/selftests/kselftest_harness.h +330 -85
index 45f807ce37e1..c56f72e07cd7 100644
@@ -4,41 +4,49 @@
  *
  * 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
  */
 
+/**
+ * DOC: 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
+ */
+
 #ifndef __KSELFTEST_HARNESS_H
 #define __KSELFTEST_HARNESS_H
 
@@ -61,10 +69,20 @@
 #  define TH_LOG_ENABLED 1
 #endif
 
-/* TH_LOG(format, ...)
+/**
+ * TH_LOG(fmt, ...)
+ *
+ * @fmt: format string
+ * @...: optional arguments
+ *
+ * .. 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(fmt, ...) do { \
@@ -77,7 +95,16 @@
 		fprintf(TH_LOG_STREAM, "%s:%d:%s:" fmt "\n", \
 			__FILE__, __LINE__, _metadata->name, ##__VA_ARGS__)
 
-/* TEST(name) { implementation }
+/**
+ * TEST(test_name) - Defines the test function and creates the registration
+ * stub
+ *
+ * @test_name: test name
+ *
+ * .. 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
@@ -85,10 +112,18 @@
  *
  * EXPECT_* and ASSERT_* are valid in a TEST() { } context.
  */
-/* Defines the test function and creates the registration stub. */
 #define TEST(test_name) __TEST_IMPL(test_name, -1)
 
-/* TEST_SIGNAL(name, signal) { implementation }
+/**
+ * TEST_SIGNAL(test_name, signal)
+ *
+ * @test_name: test name
+ * @signal: signal number
+ *
+ * .. 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
@@ -110,22 +145,38 @@
 	static void test_name( \
 		struct __test_metadata __attribute__((unused)) *_metadata)
 
-/* FIXTURE_DATA(datatype name)
+/**
+ * FIXTURE_DATA(datatype_name) - Wraps the struct name so we have one less
+ * argument to pass around
+ *
+ * @datatype_name: datatype name
+ *
+ * .. 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.
  */
-/* Wraps the struct name so we have one less argument to pass around. */
 #define FIXTURE_DATA(datatype_name) struct _test_data_##datatype_name
 
-/* 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.
+/**
+ * FIXTURE(fixture_name) - Called once per fixture to setup the data and
+ * register
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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().
  */
-/* Called once per fixture to setup the data and register. */
 #define FIXTURE(fixture_name) \
 	static void __attribute__((constructor)) \
 	_register_##fixture_name##_data(void) \
@@ -134,9 +185,18 @@
 	} \
 	FIXTURE_DATA(fixture_name)
 
-/* FIXTURE_SETUP(fixture name) { implementation }
+/**
+ * FIXTURE_SETUP(fixture_name) - Prepares the setup function for the fixture.
+ * *_metadata* is included so that ASSERT_* work as a convenience
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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
@@ -144,16 +204,21 @@
  *
  * A bare "return;" statement may be used to return early.
  */
-/* Prepares the setup function for the fixture.  |_metadata| is included
- * so that ASSERT_* work as a convenience.
- */
 #define FIXTURE_SETUP(fixture_name) \
 	void fixture_name##_setup( \
 		struct __test_metadata __attribute__((unused)) *_metadata, \
 		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
-/* FIXTURE_TEARDOWN(fixture name) { implementation }
+/**
+ * FIXTURE_TEARDOWN(fixture_name)
+ *
+ * @fixture_name: fixture name
+ *
+ * .. 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.
@@ -163,15 +228,22 @@
 		struct __test_metadata __attribute__((unused)) *_metadata, \
 		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
-/* TEST_F(fixture, name) { implementation }
+/**
+ * TEST_F(fixture_name, test_name) - Emits test registration and helpers for
+ * fixture-based test cases
+ *
+ * @fixture_name: fixture name
+ * @test_name: test name
+ *
+ * .. 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.
  */
-/* Emits test registration and helpers for fixture-based test
- * cases.
- * TODO(wad) register fixtures on dedicated test lists.
- */
+/* TODO(wad) register fixtures on dedicated test lists. */
 #define TEST_F(fixture_name, test_name) \
 	__TEST_F_IMPL(fixture_name, test_name, -1)
 
@@ -210,10 +282,15 @@
 		struct __test_metadata __attribute__((unused)) *_metadata, \
 		FIXTURE_DATA(fixture_name) __attribute__((unused)) *self)
 
-/* Use once to append a main() to the test file. E.g.,
- *   TEST_HARNESS_MAIN
+/**
+ * TEST_HARNESS_MAIN - Simple wrapper to run the test harness
+ *
+ * .. code-block:: c
+ *
+ *     TEST_HARNESS_MAIN
+ *
+ * Use once to append a main() to the test file.
  */
-/* Exports a simple wrapper to run the test harness. */
 #define TEST_HARNESS_MAIN \
 	static void __attribute__((constructor)) \
 	__constructor_order_last(void) \
@@ -225,79 +302,247 @@
 		return test_harness_run(argc, argv); \
 	}
 
-/*
- * Operators for use in TEST and TEST_F.
+/**
+ * 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 */
+
+/**
+ * ASSERT_EQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_EQ(expected, measured): expected == measured
+ */
 #define ASSERT_EQ(expected, seen) \
 	__EXPECT(expected, seen, ==, 1)
-/* ASSERT_NE(expected, measured): expected != measured */
+
+/**
+ * ASSERT_NE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_NE(expected, measured): expected != measured
+ */
 #define ASSERT_NE(expected, seen) \
 	__EXPECT(expected, seen, !=, 1)
-/* ASSERT_LT(expected, measured): expected < measured */
+
+/**
+ * ASSERT_LT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_LT(expected, measured): expected < measured
+ */
 #define ASSERT_LT(expected, seen) \
 	__EXPECT(expected, seen, <, 1)
-/* ASSERT_LE(expected, measured): expected <= measured */
+
+/**
+ * ASSERT_LE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_LE(expected, measured): expected <= measured
+ */
 #define ASSERT_LE(expected, seen) \
 	__EXPECT(expected, seen, <=, 1)
-/* ASSERT_GT(expected, measured): expected > measured */
+
+/**
+ * ASSERT_GT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_GT(expected, measured): expected > measured
+ */
 #define ASSERT_GT(expected, seen) \
 	__EXPECT(expected, seen, >, 1)
-/* ASSERT_GE(expected, measured): expected >= measured */
+
+/**
+ * ASSERT_GE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_GE(expected, measured): expected >= measured
+ */
 #define ASSERT_GE(expected, seen) \
 	__EXPECT(expected, seen, >=, 1)
-/* ASSERT_NULL(measured): NULL == measured */
+
+/**
+ * ASSERT_NULL(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_NULL(measured): NULL == measured
+ */
 #define ASSERT_NULL(seen) \
 	__EXPECT(NULL, seen, ==, 1)
 
-/* ASSERT_TRUE(measured): measured != 0 */
+/**
+ * ASSERT_TRUE(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_TRUE(measured): measured != 0
+ */
 #define ASSERT_TRUE(seen) \
 	ASSERT_NE(0, seen)
-/* ASSERT_FALSE(measured): measured == 0 */
+
+/**
+ * ASSERT_FALSE(seen)
+ *
+ * @seen: measured value
+ *
+ * ASSERT_FALSE(measured): measured == 0
+ */
 #define ASSERT_FALSE(seen) \
 	ASSERT_EQ(0, seen)
-/* ASSERT_STREQ(expected, measured): !strcmp(expected, measured) */
+
+/**
+ * ASSERT_STREQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_STREQ(expected, measured): !strcmp(expected, measured)
+ */
 #define ASSERT_STREQ(expected, seen) \
 	__EXPECT_STR(expected, seen, ==, 1)
-/* ASSERT_STRNE(expected, measured): strcmp(expected, measured) */
+
+/**
+ * ASSERT_STRNE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * ASSERT_STRNE(expected, measured): strcmp(expected, measured)
+ */
 #define ASSERT_STRNE(expected, seen) \
 	__EXPECT_STR(expected, seen, !=, 1)
 
-/* EXPECT_EQ(expected, measured): expected == measured */
+/**
+ * EXPECT_EQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_EQ(expected, measured): expected == measured
+ */
 #define EXPECT_EQ(expected, seen) \
 	__EXPECT(expected, seen, ==, 0)
-/* EXPECT_NE(expected, measured): expected != measured */
+
+/**
+ * EXPECT_NE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_NE(expected, measured): expected != measured
+ */
 #define EXPECT_NE(expected, seen) \
 	__EXPECT(expected, seen, !=, 0)
-/* EXPECT_LT(expected, measured): expected < measured */
+
+/**
+ * EXPECT_LT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_LT(expected, measured): expected < measured
+ */
 #define EXPECT_LT(expected, seen) \
 	__EXPECT(expected, seen, <, 0)
-/* EXPECT_LE(expected, measured): expected <= measured */
+
+/**
+ * EXPECT_LE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_LE(expected, measured): expected <= measured
+ */
 #define EXPECT_LE(expected, seen) \
 	__EXPECT(expected, seen, <=, 0)
-/* EXPECT_GT(expected, measured): expected > measured */
+
+/**
+ * EXPECT_GT(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_GT(expected, measured): expected > measured
+ */
 #define EXPECT_GT(expected, seen) \
 	__EXPECT(expected, seen, >, 0)
-/* EXPECT_GE(expected, measured): expected >= measured */
+
+/**
+ * EXPECT_GE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_GE(expected, measured): expected >= measured
+ */
 #define EXPECT_GE(expected, seen) \
 	__EXPECT(expected, seen, >=, 0)
 
-/* EXPECT_NULL(measured): NULL == measured */
+/**
+ * EXPECT_NULL(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_NULL(measured): NULL == measured
+ */
 #define EXPECT_NULL(seen) \
 	__EXPECT(NULL, seen, ==, 0)
-/* EXPECT_TRUE(measured): 0 != measured */
+
+/**
+ * EXPECT_TRUE(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_TRUE(measured): 0 != measured
+ */
 #define EXPECT_TRUE(seen) \
 	EXPECT_NE(0, seen)
-/* EXPECT_FALSE(measured): 0 == measured */
+
+/**
+ * EXPECT_FALSE(seen)
+ *
+ * @seen: measured value
+ *
+ * EXPECT_FALSE(measured): 0 == measured
+ */
 #define EXPECT_FALSE(seen) \
 	EXPECT_EQ(0, seen)
 
-/* EXPECT_STREQ(expected, measured): !strcmp(expected, measured) */
+/**
+ * EXPECT_STREQ(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_STREQ(expected, measured): !strcmp(expected, measured)
+ */
 #define EXPECT_STREQ(expected, seen) \
 	__EXPECT_STR(expected, seen, ==, 0)
-/* EXPECT_STRNE(expected, measured): strcmp(expected, measured) */
+
+/**
+ * EXPECT_STRNE(expected, seen)
+ *
+ * @expected: expected value
+ * @seen: measured value
+ *
+ * EXPECT_STRNE(expected, measured): strcmp(expected, measured)
+ */
 #define EXPECT_STRNE(expected, seen) \
 	__EXPECT_STR(expected, seen, !=, 0)
 
#16 lore raw
In reply to Mickaël Salaün
Quoted 11 lines · Mickaël Salaün

Hi,

This patch series make the seccomp/test_harness.h more generally available [1] and update the kselftest documentation in the Sphinx format. It also improve the Makefile of seccomp tests to take into account any kselftest_harness.h update.

[1] https://lkml.kernel.org/r/CAGXu5j+8CVz8vL51DRYXqOY=xc3zuKFf=PTENe88XYHzFYidUQ@mail.gmail.com

Regards,

Quoted 8 lines

Mickaël Salaün (7):
selftests: Make test_harness.h more generally available
selftests: Cosmetic renames in kselftest_harness.h selftests/seccomp: Force rebuild according to dependencies Documentation/dev-tools: Add kselftest Documentation/dev-tools: Use reStructuredText markups for kselftest
selftests: Remove the TEST_API() wrapper from kselftest_harness.h Documentation/dev-tools: Add kselftest_harness documentation

I think this series looks great; I've added my two remaining Acks. Shuah, when you have time, please pull these into the selftest tree. Thanks!

-Kees

Quoted 15 lines
 Documentation/00-INDEX                             |   2 -
 Documentation/dev-tools/index.rst                  |   1 +
 .../{kselftest.txt => dev-tools/kselftest.rst}     | 101 ++-
 MAINTAINERS                                        |   1 +
 .../test_harness.h => kselftest_harness.h}         | 691 +++++++++++++--------
 tools/testing/selftests/seccomp/Makefile           |   2 +
 tools/testing/selftests/seccomp/seccomp_bpf.c      |   2 +-
 7 files changed, 520 insertions(+), 280 deletions(-)
 rename Documentation/{kselftest.txt => dev-tools/kselftest.rst} (52%)
 rename tools/testing/selftests/{seccomp/test_harness.h => kselftest_harness.h} (52%)

--
2.11.0

Signature · 2 lines
Kees Cook
Pixel Security
maintainer
#17 lore raw
Quoted 21 lines · Kees Cook
Quoted 11 lines · Mickaël Salaün

Hi,

This patch series make the seccomp/test_harness.h more generally available [1] and update the kselftest documentation in the Sphinx format. It also improve the Makefile of seccomp tests to take into account any kselftest_harness.h update.

[1] https://lkml.kernel.org/r/CAGXu5j+8CVz8vL51DRYXqOY=xc3zuKFf=PTENe88XYHzFYidUQ@mail.gmail.com

Regards,

Quoted 8 lines

Mickaël Salaün (7):
selftests: Make test_harness.h more generally available
selftests: Cosmetic renames in kselftest_harness.h selftests/seccomp: Force rebuild according to dependencies Documentation/dev-tools: Add kselftest Documentation/dev-tools: Use reStructuredText markups for kselftest
selftests: Remove the TEST_API() wrapper from kselftest_harness.h Documentation/dev-tools: Add kselftest_harness documentation

Quoted 5 lines

I think this series looks great; I've added my two remaining Acks. Shuah, when you have time, please pull these into the selftest tree. Thanks!

-Kees

Awesome. I will get this in this week.

-- Shuah

Quoted 19 lines
Quoted 16 lines

 Documentation/00-INDEX                             |   2 -
 Documentation/dev-tools/index.rst                  |   1 +
 .../{kselftest.txt => dev-tools/kselftest.rst}     | 101 ++-
 MAINTAINERS                                        |   1 +
 .../test_harness.h => kselftest_harness.h}         | 691 +++++++++++++--------
 tools/testing/selftests/seccomp/Makefile           |   2 +
 tools/testing/selftests/seccomp/seccomp_bpf.c      |   2 +-
 7 files changed, 520 insertions(+), 280 deletions(-)
 rename Documentation/{kselftest.txt => dev-tools/kselftest.rst} (52%)
 rename tools/testing/selftests/{seccomp/test_harness.h => kselftest_harness.h} (52%)

--
2.11.0