test: Add option to display all available tests
What changed, and why it matters
This commit adds a simple command-line option to the project's test runner that prints a list of all available tests and modules. It is a pure test-infrastructure convenience feature with no effect on the cryptographic library or any production code paths.
No security action required; this is a benign test-framework usability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces a new --list_tests / -l flag to the unit-test framework (src/unit_test.c / src/unit_test.h). When supplied, the framework prints registered module/test names and exits. It also updates an existing error message to reference the new option. No cryptographic, parsing, memory-management, or network code is modified.
Changed components
src/unit_test.csrc/unit_test.hInspect captured patch +32 / −1
diff --git a/src/unit_test.c b/src/unit_test.c
index 513bc2c..4eace52 100644
--- a/src/unit_test.c
+++ b/src/unit_test.c
@@ -81,6 +81,7 @@ static void help(void) {
printf("Run the test suite for the project with optional configuration.\n\n");
printf("Options:\n");
printf(" --help, -h Show this help message\n");
+ printf(" --list_tests, -l Display list of all available tests and modules\n");
printf(" --jobs=<num>, -j=<num> Number of parallel worker processes (default: 0 = sequential)\n");
printf(" --iterations=<num>, -i=<num> Number of iterations for each test (default: 16)\n");
printf(" --seed=<hex> Set a specific RNG seed (default: random)\n");
@@ -95,6 +96,24 @@ static void help(void) {
printf(" - Iterations and seed can also be passed as positional arguments before any other argument for backward compatibility.\n");
}
+/* Print all tests in registry */
+static void print_test_list(struct tf_framework* tf) {
+ int m, t, total = 0;
+ printf("\nAvailable tests (%d modules):\n", tf->num_modules);
+ printf("========================================\n");
+ for (m = 0; m < tf->num_modules; m++) {
+ const struct tf_test_module* mod = &tf->registry_modules[m];
+ printf("Module: %s (%d tests)\n", mod->name, mod->size);
+ for (t = 0; t < mod->size; t++) {
+ printf("\t[%3d] %s\n", total + 1, mod->data[t].name);
+ total++;
+ }
+ printf("----------------------------------------\n");
+ }
+ printf("\nRun specific module: ./tests -t=<module_name>\n");
+ printf("Run specific test: ./tests -t=<test_name>\n\n");
+}
+
static int parse_jobs_count(const char* key, const char* value, struct tf_framework* tf) {
char* ptr_val;
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*
if (add_all) return 0;
}
fprintf(stderr, "Error: target '%s' not found (missing or module disabled).\n"
- "Run program with -print_tests option to display available tests and modules.\n", value);
+ "Run program with -list_tests option to display available tests and modules.\n", value);
return -1;
}
@@ -211,6 +230,10 @@ static int read_args(int argc, char** argv, int start, struct tf_framework* tf)
tf->args.help = 1;
return 0;
}
+ if (strcmp(key, "l") == 0 || strcmp(key, "list_tests") == 0) {
+ tf->args.list_tests = 1;
+ return 0;
+ }
fprintf(stderr, "Invalid arg '%s': must be -k=value or --key=value\n", raw_arg);
return -1;
}
@@ -324,6 +347,7 @@ static int tf_init(struct tf_framework* tf, int argc, char** argv)
tf->args.custom_seed = NULL;
tf->args.help = 0;
tf->args.targets.size = 0;
+ tf->args.list_tests = 0;
/* Disable buffering for stdout to improve reliability of getting
* 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)
help();
exit(EXIT_SUCCESS);
}
+
+ if (tf->args.list_tests) {
+ print_test_list(tf);
+ exit(EXIT_SUCCESS);
+ }
}
return EXIT_SUCCESS;
diff --git a/src/unit_test.h b/src/unit_test.h
index e76b8c0..b41e9f7 100644
--- a/src/unit_test.h
+++ b/src/unit_test.h
@@ -77,6 +77,8 @@ struct tf_args {
const char* custom_seed;
/* Whether to print the help msg */
int help;
+ /* Whether to print the tests list msg */
+ int list_tests;
/* Target tests indexes */
struct tf_targets targets;
};
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.