public inbox for [email protected]
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected],
	Willy Tarreau <[email protected]>,
	"Paul E . McKenney" <[email protected]>
Subject: [PATCH nolibc 05/18] selftests/nolibc: support a test definition format
Date: Wed, 31 Aug 2022 11:21:35 -0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <20220831182113.GA2697286@paulmck-ThinkPad-P17-Gen-1>

From: Willy Tarreau <[email protected]>

It now becomes possible to pass a string either in argv[1] or in the
NOLIBC_TEST environment variable (the former having precedence), to
specify which tests to run. The format is:

   testname[:range]*[,testname...]

Where a range is either a single value or the min and max numbers of the
test IDs in a sequence, delimited by a dash. Multiple ranges are possible.
This should provide enough flexibility to focus on certain failing parts
just by playing with the boot command line in a boot loader or in qemu
depending on what is accessible.

Signed-off-by: Willy Tarreau <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 91 ++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 6c050d4381fec..49177ea9943cc 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -17,6 +17,12 @@
 /* will be used by nolibc by getenv() */
 char **environ;
 
+/* definition of a series of tests */
+struct test {
+	const char *name;              // test name
+	int (*func)(int min, int max); // handler
+};
+
 #define CASE_ERR(err) \
 	case err: return #err
 
@@ -376,19 +382,104 @@ static int expect_strne(const char *expr, int llen, const char *cmp)
 	return ret;
 }
 
+
 /* declare tests based on line numbers. There must be exactly one test per line. */
 #define CASE_TEST(name) \
 	case __LINE__: llen += printf("%d %s", test, #name);
 
 
+/* This is the definition of known test names, with their functions */
+static struct test test_names[] = {
+	/* add new tests here */
+	{ 0 }
+};
+
 int main(int argc, char **argv, char **envp)
 {
 	int min = 0;
 	int max = __INT_MAX__;
 	int ret = 0;
+	int err;
+	int idx;
+	char *test;
 
 	environ = envp;
 
+	/* the definition of a series of tests comes from either argv[1] or the
+	 * "NOLIBC_TEST" environment variable. It's made of a comma-delimited
+	 * series of test names and optional ranges:
+	 *    syscall:5-15[:.*],stdlib:8-10
+	 */
+	test = argv[1];
+	if (!test)
+		test = getenv("NOLIBC_TEST");
+
+	if (test) {
+		char *comma, *colon, *dash, *value;
+
+		do {
+			comma = strchr(test, ',');
+			if (comma)
+				*(comma++) = '\0';
+
+			colon = strchr(test, ':');
+			if (colon)
+				*(colon++) = '\0';
+
+			for (idx = 0; test_names[idx].name; idx++) {
+				if (strcmp(test, test_names[idx].name) == 0)
+					break;
+			}
+
+			if (test_names[idx].name) {
+				/* The test was named, it will be called at least
+				 * once. We may have an optional range at <colon>
+				 * here, which defaults to the full range.
+				 */
+				do {
+					min = 0; max = __INT_MAX__;
+					value = colon;
+					if (value && *value) {
+						colon = strchr(value, ':');
+						if (colon)
+							*(colon++) = '\0';
+
+						dash = strchr(value, '-');
+						if (dash)
+							*(dash++) = '\0';
+
+						/* support :val: :min-max: :min-: :-max: */
+						if (*value)
+							min = atoi(value);
+						if (!dash)
+							max = min;
+						else if (*dash)
+							max = atoi(dash);
+
+						value = colon;
+					}
+
+					/* now's time to call the test */
+					printf("Running test '%s'\n", test_names[idx].name);
+					err = test_names[idx].func(min, max);
+					ret += err;
+					printf("Errors during this test: %d\n\n", err);
+				} while (colon && *colon);
+			} else
+				printf("Ignoring unknown test name '%s'\n", test);
+
+			test = comma;
+		} while (test && *test);
+	} else {
+		/* no test mentioned, run everything */
+		for (idx = 0; test_names[idx].name; idx++) {
+			printf("Running test '%s'\n", test_names[idx].name);
+			err = test_names[idx].func(min, max);
+			ret += err;
+			printf("Errors during this test: %d\n\n", err);
+		}
+	}
+
 	printf("Total number of errors: %d\n", ret);
 	printf("Exiting with status %d\n", !!ret);
 	return !!ret;
-- 
2.31.1.189.g2e36527f23


  parent reply	other threads:[~2022-08-31 18:21 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 18:21 [PATCH nolibc 0/18] nolibc updates for v6.1 Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 01/18] tools/nolibc: make argc 32-bit in riscv startup code Paul E. McKenney
2022-08-31 18:21 ` [PATCH rcu 1/2] torture: Optionally flush printk() buffers before powering off Paul E. McKenney
2022-09-01  9:12   ` John Ogness
2022-09-01 10:17     ` Paul E. McKenney
2022-08-31 18:21 ` [PATCH rcu 2/2] rcutorture: Use the barrier operation specified by cur_ops Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 02/18] tools/nolibc: fix build warning in sys_mmap() when my_syscall6 is not defined Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 03/18] tools/nolibc: make sys_mmap() automatically use the right __NR_mmap definition Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 04/18] selftests/nolibc: add basic infrastructure to ease creation of nolibc tests Paul E. McKenney
2022-08-31 18:21 ` Paul E. McKenney [this message]
2022-08-31 18:21 ` [PATCH nolibc 06/18] selftests/nolibc: implement a few tests for various syscalls Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 07/18] selftests/nolibc: add a few tests for some libc functions Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 08/18] selftests/nolibc: exit with poweroff on success when getpid() == 1 Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 09/18] selftests/nolibc: on x86, support exiting with isa-debug-exit Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 10/18] selftests/nolibc: recreate and populate /dev and /proc if missing Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 11/18] selftests/nolibc: condition some tests on /proc existence Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 12/18] selftests/nolibc: support glibc as well Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 13/18] selftests/nolibc: add a "kernel" target to build the kernel with the initramfs Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 14/18] selftests/nolibc: add a "defconfig" target Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 15/18] selftests/nolibc: add a "run" target to start the kernel in QEMU Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 16/18] selftests/nolibc: "sysroot" target installs a local copy of the sysroot Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 17/18] selftests/nolibc: add a "help" target Paul E. McKenney
2022-08-31 18:21 ` [PATCH nolibc 18/18] selftests/nolibc: Avoid generated files being committed Paul E. McKenney

Reply instructions:

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

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

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

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

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

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

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