[PATCH RFC 1/7] selftests/nolibc: statically calculate number of testsuites

From: Thomas Weißschuh
Date: Tue Jul 18 2023 - 18:05:48 EST


This makes it slightly nicer to report the number of suites.

Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
tools/testing/selftests/nolibc/nolibc-test.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 03b1d30f5507..698af242d3e4 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -45,6 +45,8 @@
#define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2)))
#define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1)

+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+
/* will be used to test initialization of environ */
static char **test_envp;

@@ -1184,7 +1186,6 @@ static const struct test test_names[] = {
{ .name = "stdlib", .func = run_stdlib },
{ .name = "vfprintf", .func = run_vfprintf },
{ .name = "protection", .func = run_protection },
- { 0 }
};

int is_setting_valid(char *test)
@@ -1259,7 +1260,7 @@ int main(int argc, char **argv, char **envp)
if (colon)
*(colon++) = '\0';

- for (idx = 0; test_names[idx].name; idx++) {
+ for (idx = 0; idx < ARRAY_SIZE(test_names); idx++) {
if (strcmp(test, test_names[idx].name) == 0)
break;
}
@@ -1305,7 +1306,7 @@ int main(int argc, char **argv, char **envp)
} while (test && *test);
} else {
/* no test mentioned, run everything */
- for (idx = 0; test_names[idx].name; idx++) {
+ for (idx = 0; idx < ARRAY_SIZE(test_names); idx++) {
printf("Running test '%s'\n", test_names[idx].name);
err = test_names[idx].func(min, max);
ret += err;

--
2.41.0