Skip to content

Commit 5b260cf

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 5bfddc4 commit 5b260cf

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
@@ -64,6 +64,7 @@ static void help(void) {
6464
printf("Run the test suite for the project with optional configuration.\n\n");
6565
printf("Options:\n");
6666
printf(" -help, -h Show this help message\n");
67+
printf(" -print_tests Display list of all available tests and modules\n");
6768
printf(" -j=<num>, -jobs=<num> Number of parallel worker processes (default: 0 = sequential)\n");
6869
printf(" -iter=<num>, -iterations=<num> Number of iterations for each test (default: 16)\n");
6970
printf(" -seed=<hex> Set a specific RNG seed (default: random)\n");
@@ -77,6 +78,24 @@ static void help(void) {
7778
printf(" - The first two positional arguments (iterations and seed) are also supported for backward compatibility.\n");
7879
}
7980

81+
/* Print all tests in registry */
82+
static void print_test_list(struct TestFramework* tf) {
83+
int m, t, total = 0;
84+
printf("\nAvailable tests (%d modules):\n", tf->num_modules);
85+
printf("========================================\n");
86+
for (m = 0; m < tf->num_modules; m++) {
87+
struct TestModule* mod = &tf->registry_modules[m];
88+
printf("Module: %s (%d tests)\n", mod->name, mod->size);
89+
for (t = 0; t < mod->size; t++) {
90+
printf("\t[%3d] %s\n", total + 1, mod->data[t].name);
91+
total++;
92+
}
93+
printf("----------------------------------------\n");
94+
}
95+
printf("\nRun specific module: ./tests -t=<module_name>\n");
96+
printf("Run specific test: ./tests -t=<test_name>\n\n");
97+
}
98+
8099
static int parse_jobs_count(const char* key, const char* value, struct Args* out) {
81100
char* ptr_val;
82101
long val = strtol(value, &ptr_val, 10); /* base 10 */
@@ -275,6 +294,12 @@ static int tf_init(struct TestFramework* tf, int argc, char** argv)
275294
exit(EXIT_SUCCESS);
276295
}
277296

297+
/* Check if we need to print the available tests */
298+
if (argv[1] && strcmp(argv[1], "-print_tests") == 0) {
299+
print_test_list(tf);
300+
exit(EXIT_SUCCESS);
301+
}
302+
278303
/* Compatibility Note: The first two args were the number of iterations and the seed. */
279304
/* If provided, parse them and adjust the starting index for named arguments accordingly. */
280305
if (argv[1] && argv[1][0] != '-') {

0 commit comments

Comments
 (0)