Skip to content

Commit 95b9953

Browse files
committed
test: Add option to display all available tests
Useful option to avoid opening the large tests.c file just to find the test case you want to run.
1 parent 953f7b0 commit 95b9953

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/unit_test.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ static void help(void) {
8181
printf("Run the test suite for the project with optional configuration.\n\n");
8282
printf("Options:\n");
8383
printf(" --help, -h Show this help message\n");
84+
printf(" --list_tests, -l Display list of all available tests and modules\n");
8485
printf(" --jobs=<num>, -j=<num> Number of parallel worker processes (default: 0 = sequential)\n");
8586
printf(" --iterations=<num>, -i=<num> Number of iterations for each test (default: 16)\n");
8687
printf(" --seed=<hex> Set a specific RNG seed (default: random)\n");
@@ -95,6 +96,24 @@ static void help(void) {
9596
printf(" - Iterations and seed can also be passed as positional arguments before any other argument for backward compatibility.\n");
9697
}
9798

99+
/* Print all tests in registry */
100+
static void print_test_list(struct tf_framework* tf) {
101+
int m, t, total = 0;
102+
printf("\nAvailable tests (%d modules):\n", tf->num_modules);
103+
printf("========================================\n");
104+
for (m = 0; m < tf->num_modules; m++) {
105+
const struct tf_test_module* mod = &tf->registry_modules[m];
106+
printf("Module: %s (%d tests)\n", mod->name, mod->size);
107+
for (t = 0; t < mod->size; t++) {
108+
printf("\t[%3d] %s\n", total + 1, mod->data[t].name);
109+
total++;
110+
}
111+
printf("----------------------------------------\n");
112+
}
113+
printf("\nRun specific module: ./tests -t=<module_name>\n");
114+
printf("Run specific test: ./tests -t=<test_name>\n\n");
115+
}
116+
98117
static int parse_jobs_count(const char* key, const char* value, struct tf_framework* tf) {
99118
char* ptr_val;
100119
long val = strtol(value, &ptr_val, 10); /* base 10 */
@@ -180,7 +199,7 @@ static int parse_target(const char* key, const char* value, struct tf_framework*
180199
if (add_all) return 0;
181200
}
182201
fprintf(stderr, "Error: target '%s' not found (missing or module disabled).\n"
183-
"Run program with -print_tests option to display available tests and modules.\n", value);
202+
"Run program with -list_tests option to display available tests and modules.\n", value);
184203
return -1;
185204
}
186205

@@ -211,6 +230,10 @@ static int read_args(int argc, char** argv, int start, struct tf_framework* tf)
211230
tf->args.help = 1;
212231
return 0;
213232
}
233+
if (strcmp(key, "l") == 0 || strcmp(key, "list_tests") == 0) {
234+
tf->args.list_tests = 1;
235+
return 0;
236+
}
214237
fprintf(stderr, "Invalid arg '%s': must be -k=value or --key=value\n", raw_arg);
215238
return -1;
216239
}
@@ -324,6 +347,7 @@ static int tf_init(struct tf_framework* tf, int argc, char** argv)
324347
tf->args.custom_seed = NULL;
325348
tf->args.help = 0;
326349
tf->args.targets.size = 0;
350+
tf->args.list_tests = 0;
327351

328352
/* Disable buffering for stdout to improve reliability of getting
329353
* diagnostic information. Happens right at the start of main because
@@ -360,6 +384,11 @@ static int tf_init(struct tf_framework* tf, int argc, char** argv)
360384
help();
361385
exit(EXIT_SUCCESS);
362386
}
387+
388+
if (tf->args.list_tests) {
389+
print_test_list(tf);
390+
exit(EXIT_SUCCESS);
391+
}
363392
}
364393

365394
return EXIT_SUCCESS;

src/unit_test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ struct tf_args {
7777
const char* custom_seed;
7878
/* Whether to print the help msg */
7979
int help;
80+
/* Whether to print the tests list msg */
81+
int list_tests;
8082
/* Target tests indexes */
8183
struct tf_targets targets;
8284
};

0 commit comments

Comments
 (0)