Skip to content

Commit 2a9e160

Browse files
committed
tests: add -help for command-line options
Add a help message for the test suite, documenting available options, defaults, and backward-compatible positional arguments.
1 parent cb76d69 commit 2a9e160

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/unit_test.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ static int parse_arg(const char* key, const char* value, struct Args* out) {
7373
return 0;
7474
}
7575

76+
static void help(void) {
77+
printf("Usage: ./tests [options]\n\n");
78+
printf("Run the test suite for the project with optional configuration.\n\n");
79+
printf("Options:\n");
80+
printf(" -help Show this help message and exit\n");
81+
printf(" -j=<num>, -jobs=<num> Number of parallel worker processes (default: 0 = sequential)\n");
82+
printf(" -iter=<num>, -iterations=<num> Number of iterations for each test (default: 64)\n");
83+
printf(" -seed=<hex> Set a specific RNG seed (default: random)\n");
84+
printf("\n");
85+
printf("Notes:\n");
86+
printf(" - All arguments must be provided in the form '-key=value'.\n");
87+
printf(" - Unknown arguments are reported but ignored.\n");
88+
printf(" - Sequential execution occurs if -jobs=0 or unspecified.\n");
89+
printf(" - The first two positional arguments (iterations and seed) are also supported for backward compatibility.\n");
90+
}
91+
7692
static int parse_jobs_count(const char* key, const char* value, struct Args* out) {
7793
char* ptr_val;
7894
long val = strtol(value, &ptr_val, 10); /* base 10 */
@@ -259,6 +275,12 @@ int main(int argc, char** argv) {
259275
_exit(EXIT_FAILURE);
260276
}
261277

278+
/* Check if we need to print help */
279+
if (argv[1] && strcmp(argv[1], "-help") == 0) {
280+
help();
281+
_exit(EXIT_SUCCESS);
282+
}
283+
262284
/* Compatibility Note: The first two args were the number of iterations and the seed. */
263285
/* If provided, parse them and adjust the starting index for named arguments accordingly. */
264286
if (argv[1] && argv[1][0] != '-') {

0 commit comments

Comments
 (0)