This will be needed for KTAP output. Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx> --- tools/testing/selftests/nolibc/nolibc-test.c | 30 +++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 76bd6a0a8132..03f64ce1dda6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -65,6 +65,13 @@ struct test { int (*func)(unsigned int min, unsigned int max); /* handler */ }; +#define COUNT_SUBTESTS (-1) + +static unsigned int count_subtests(const struct test *test) +{ + return test->func(COUNT_SUBTESTS, COUNT_SUBTESTS); +} + #ifndef _NOLIBC_STDLIB_H char *itoa(int i) { @@ -571,10 +578,10 @@ static int expect_strne(const char *expr, int llen, const char *cmp) case __LINE__: llen += printf("%d %s", test, #name); #define SWITCH_TEST \ - switch (test + __LINE__ + 1) { + int _tests_start = __LINE__; switch (test + __LINE__ + 1) { #define SWITCH_TEST_END \ - case __LINE__: return ret; } + case __LINE__: return ret; default: return __LINE__ - _tests_start - 1; } int run_startup(unsigned int min, unsigned int max) @@ -592,7 +599,7 @@ int run_startup(unsigned int min, unsigned int max) test_auxv = _auxv; #endif - for (test = min; test >= 0 && test <= max; test++) { + for (test = min; test == COUNT_SUBTESTS || (test >= 0 && test <= max); test++) { int llen = 0; /* line length */ /* avoid leaving empty lines below, this will insert holes into @@ -801,7 +808,7 @@ int run_syscall(unsigned int min, unsigned int max) has_gettid = __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30); #endif - for (test = min; test >= 0 && test <= max; test++) { + for (test = min; test == COUNT_SUBTESTS || (test >= 0 && test <= max); test++) { int llen = 0; /* line length */ /* avoid leaving empty lines below, this will insert holes into @@ -892,7 +899,7 @@ int run_stdlib(unsigned int min, unsigned int max) int ret = 0; void *p1, *p2; - for (test = min; test >= 0 && test <= max; test++) { + for (test = min; test == COUNT_SUBTESTS || (test >= 0 && test <= max); test++) { int llen = 0; /* line length */ /* avoid leaving empty lines below, this will insert holes into @@ -1032,7 +1039,7 @@ static int run_vfprintf(unsigned int min, unsigned int max) int ret = 0; void *p1, *p2; - for (test = min; test >= 0 && test <= max; test++) { + for (test = min; test == COUNT_SUBTESTS || (test >= 0 && test <= max); test++) { int llen = 0; /* line length */ /* avoid leaving empty lines below, this will insert holes into @@ -1070,6 +1077,9 @@ static int run_protection(unsigned int min, unsigned int max) pid_t pid; int llen = 0, status; + if (min == COUNT_SUBTESTS) + return 1; + llen += printf("0 -fstackprotector "); #if !defined(_NOLIBC_STACKPROTECTOR) @@ -1219,6 +1229,7 @@ int main(int argc, char **argv, char **envp) int ret = 0; int err; int idx; + unsigned int subtests; char *test; argv0 = argv[0]; @@ -1265,6 +1276,8 @@ int main(int argc, char **argv, char **envp) * once. We may have an optional range at <colon> * here, which defaults to the full range. */ + + subtests = count_subtests(&test_names[idx]); do { min = 0; max = INT_MAX; value = colon; @@ -1285,11 +1298,14 @@ int main(int argc, char **argv, char **envp) else if (*dash) max = atoi(dash); + if (max > subtests) + max = subtests; + value = colon; } /* now's time to call the test */ - printf("Running test '%s'\n", test_names[idx].name); + printf("Running test '%s' (%d-%d of %d)\n", test_names[idx].name, min, max, subtests); err = test_names[idx].func(min, max); ret += err; printf("Errors during this test: %d\n\n", err); -- 2.41.0