[PATCH 2/4] selftests/nolibc: add rerun support

Zhangjin Wu falcon at tinylab.org
Tue May 30 04:03:30 PDT 2023


The global 'run' setting is added to allow specify the running
iterations, for example:

    NOLIBC_TEST=run:5,syscall:1

This setting allows to run the first syscall for 5 times.

Signed-off-by: Zhangjin Wu <falcon at tinylab.org>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 53 ++++++++++++++------
 1 file changed, 38 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index be718fa5dc86..b8fd7fcf56a6 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -956,9 +956,12 @@ int main(int argc, char **argv, char **envp)
 {
 	int min = 0;
 	int max = INT_MAX;
+	int run = 1;
+	int selected = 0;
 	int ret = 0;
 	int err;
 	int idx;
+	int i;
 	char *test;
 
 	environ = envp;
@@ -974,7 +977,7 @@ int main(int argc, char **argv, char **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
+	 *    run:3,syscall:5-15[:.*],stdlib:8-10
 	 */
 	test = argv[1];
 	if (!test)
@@ -992,14 +995,27 @@ int main(int argc, char **argv, char **envp)
 			if (colon)
 				*(colon++) = '\0';
 
-			for (idx = 0; test_names[idx].name; idx++) {
-				if (strcmp(test, test_names[idx].name) == 0)
+			if (strcmp(test, "run") != 0) {
+				for (idx = 0; test_names[idx].name; idx++) {
+					if (strcmp(test, test_names[idx].name) == 0)
+						break;
+				}
+			} else {
+				value = colon;
+				if (value && *value)
+					run = atoi(value);
+
+				test = comma;
+				if (test && *test)
+					continue;
+				else
 					break;
 			}
 
 			if (!test_names[idx].name) {
 				printf("Ignoring unknown test name '%s'\n", test);
 			} else {
+				selected++;
 				test_names[idx].run = 1;
 
 				/* The test was named, it will be called at least
@@ -1038,24 +1054,31 @@ int main(int argc, char **argv, char **envp)
 		} while (test && *test);
 
 		/* disable the left tests */
-		for (idx = 0; test_names[idx].name; idx++) {
-			if (test_names[idx].run != 1)
-				test_names[idx].run = 0;
+		if (selected != 0) {
+			for (idx = 0; test_names[idx].name; idx++) {
+				if (test_names[idx].run != 1)
+					test_names[idx].run = 0;
+			}
 		}
 	}
 
 	/* run everything or the test mentioned */
-	for (idx = 0; test_names[idx].name; idx++) {
-		if (test_names[idx].run != 0) {
-			printf("Running test '%s', from %d to %d\n", test_names[idx].name, test_names[idx].min, test_names[idx].max);
-			err = test_names[idx].func(test_names[idx].min, test_names[idx].max);
-			ret += err;
-			printf("Errors during this test: %d\n\n", err);
-		}
-	}
+	printf("Running iteration(s): %d\n\n", run);
+	for (i = 0; i < run; i++) {
+		printf("Current iteration: %d\n\n", i + 1);
 
+		ret = 0;
+		for (idx = 0; test_names[idx].name; idx++) {
+			if (test_names[idx].run != 0) {
+				printf("Running test '%s', from %d to %d\n", test_names[idx].name, test_names[idx].min, test_names[idx].max);
+				err = test_names[idx].func(test_names[idx].min, test_names[idx].max);
+				ret += err;
+				printf("Errors during this test: %d\n\n", err);
+			}
+		}
 
-	printf("Total number of errors: %d\n", ret);
+		printf("Total number of errors in the %d iteration(s): %d\n\n", i + 1, ret);
+	}
 
 	if (getpid() == 1) {
 		/* we're running as init, there's no other process on the
-- 
2.25.1




More information about the linux-riscv mailing list