@@ -74,6 +74,23 @@ static int parse_arg(const char* key, const char* value, struct tf_framework* tf
7474 return -1 ;
7575}
7676
77+ static void help (void ) {
78+ printf ("Usage: ./tests [options]\n\n" );
79+ printf ("Run the test suite for the project with optional configuration.\n\n" );
80+ printf ("Options:\n" );
81+ printf (" --help, -h Show this help message\n" );
82+ printf (" --jobs=<num>, -j=<num> Number of parallel worker processes (default: 0 = sequential)\n" );
83+ printf (" --iterations=<num>, -i=<num> Number of iterations for each test (default: 16)\n" );
84+ printf (" --seed=<hex> Set a specific RNG seed (default: random)\n" );
85+ printf ("\n" );
86+ printf ("Notes:\n" );
87+ printf (" - All arguments must be provided in the form '--key=value', '-key=value' or '-k=value'.\n" );
88+ printf (" - Single or double dashes are allowed for multi character options.\n" );
89+ printf (" - Unknown arguments are reported but ignored.\n" );
90+ printf (" - Sequential execution occurs if -jobs=0 or unspecified.\n" );
91+ printf (" - Iterations and seed can also be passed as positional arguments before any other argument for backward compatibility.\n" );
92+ }
93+
7794static int parse_jobs_count (const char * key , const char * value , struct tf_framework * tf ) {
7895 char * ptr_val ;
7996 long val = strtol (value , & ptr_val , 10 ); /* base 10 */
@@ -157,6 +174,11 @@ static int read_args(int argc, char** argv, int start, struct tf_framework* tf)
157174
158175 eq = strchr (raw_arg , '=' );
159176 if (!eq || eq == raw_arg + 1 ) {
177+ /* Allowed options without value */
178+ if (strcmp (key , "h" ) == 0 || strcmp (key , "help" ) == 0 ) {
179+ tf -> args .help = 1 ;
180+ return 0 ;
181+ }
160182 fprintf (stderr , "Invalid arg '%s': must be -k=value or --key=value\n" , raw_arg );
161183 return -1 ;
162184 }
@@ -264,6 +286,7 @@ static int tf_init(struct tf_framework* tf, int argc, char** argv)
264286 /* Initialize command-line options */
265287 tf -> args .num_processes = 0 ;
266288 tf -> args .custom_seed = NULL ;
289+ tf -> args .help = 0 ;
267290
268291 /* Disable buffering for stdout to improve reliability of getting
269292 * diagnostic information. Happens right at the start of main because
@@ -295,6 +318,11 @@ static int tf_init(struct tf_framework* tf, int argc, char** argv)
295318 if (read_args (argc , argv , named_arg_start , tf ) != 0 ) {
296319 return EXIT_FAILURE ;
297320 }
321+
322+ if (tf -> args .help ) {
323+ help ();
324+ exit (EXIT_SUCCESS );
325+ }
298326 }
299327
300328 return EXIT_SUCCESS ;
0 commit comments