Skip to content

Commit 0b3c74f

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 5e135df commit 0b3c74f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/unit_test.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static void help(void) {
7777
printf("Run the test suite for the project with optional configuration.\n\n");
7878
printf("Options:\n");
7979
printf(" -help, -h Show this help message\n");
80+
printf(" -print_tests Display list of all available tests and modules\n");
8081
printf(" -j=<num>, -jobs=<num> Number of parallel worker processes (default: 0 = sequential)\n");
8182
printf(" -iter=<num>, -iterations=<num> Number of iterations for each test (default: 16)\n");
8283
printf(" -seed=<hex> Set a specific RNG seed (default: random)\n");
@@ -90,6 +91,24 @@ static void help(void) {
9091
printf(" - The first two positional arguments (iterations and seed) are also supported for backward compatibility.\n");
9192
}
9293

94+
/* Print all tests in registry */
95+
static void print_test_list(struct TestFramework* tf) {
96+
int m, t, total = 0;
97+
printf("\nAvailable tests (%d modules):\n", tf->num_modules);
98+
printf("========================================\n");
99+
for (m = 0; m < tf->num_modules; m++) {
100+
struct TestModule* mod = &tf->registry_modules[m];
101+
printf("Module: %s (%d tests)\n", mod->name, mod->size);
102+
for (t = 0; t < mod->size; t++) {
103+
printf("\t[%3d] %s\n", total + 1, mod->data[t].name);
104+
total++;
105+
}
106+
printf("----------------------------------------\n");
107+
}
108+
printf("\nRun specific module: ./tests -t=<module_name>\n");
109+
printf("Run specific test: ./tests -t=<test_name>\n\n");
110+
}
111+
93112
static int parse_jobs_count(const char* key, const char* value, struct Args* out) {
94113
char* ptr_val;
95114
long val = strtol(value, &ptr_val, 10); /* base 10 */
@@ -287,6 +306,12 @@ static int tf_init(struct TestFramework* tf, int argc, char** argv)
287306
exit(EXIT_SUCCESS);
288307
}
289308

309+
/* Check if we need to print the available tests */
310+
if (argv[1] && strcmp(argv[1], "-print_tests") == 0) {
311+
print_test_list(tf);
312+
exit(EXIT_SUCCESS);
313+
}
314+
290315
/* Compatibility Note: The first two args were the number of iterations and the seed. */
291316
/* If provided, parse them and adjust the starting index for named arguments accordingly. */
292317
if (argv[1] && argv[1][0] != '-') {

0 commit comments

Comments
 (0)