@@ -53,6 +53,11 @@ static int parse_arg(const char* key, const char* value, struct TestFramework* t
53
53
if (strcmp (key , "t" ) == 0 || strcmp (key , "target" ) == 0 ) {
54
54
return parse_target (value , tf );
55
55
}
56
+ /* Logging */
57
+ if (strcmp (key , "log" ) == 0 ) {
58
+ tf -> args .logging = value && strcmp (value , "1" ) == 0 ;
59
+ return 0 ;
60
+ }
56
61
57
62
/* Unknown key: report just so typos don’t silently pass. */
58
63
printf ("Unknown argument '-%s=%s'\n" , key , value );
@@ -79,6 +84,7 @@ static void help(void) {
79
84
printf (" -seed=<hex> Set a specific RNG seed (default: random)\n" );
80
85
printf (" -target=<test name>, -t=<name> Run a specific test (can be provided multiple times)\n" );
81
86
printf (" -target=<module name>, -t=<module> Run all tests within a specific module (can be provided multiple times)\n" );
87
+ printf (" -log=<0|1> Enable or disable test execution logging (default: 0 = disabled)\n" );
82
88
printf ("\n" );
83
89
printf ("Notes:\n" );
84
90
printf (" - All arguments must be provided in the form '-key=value'.\n" );
@@ -181,18 +187,21 @@ static int read_args(int argc, char** argv, int start, struct TestFramework* tf)
181
187
return 0 ;
182
188
}
183
189
184
- static void run_test (const struct TestEntry * t ) {
190
+ static void run_test_log (const struct TestEntry * t ) {
191
+ int64_t start_time = gettime_i64 ();
185
192
printf ("Running %s..\n" , t -> name );
186
193
t -> func ();
187
- printf ("%s PASSED\n" , t -> name );
194
+ printf ("Test %s PASSED (%.3f sec) \n" , t -> name , ( double )( gettime_i64 () - start_time ) / 1000000 );
188
195
}
189
196
197
+ static void run_test (const struct TestEntry * t ) { t -> func (); }
198
+
190
199
/* Process tests in sequential order */
191
200
static int run_sequential (struct TestFramework * tf ) {
192
201
int it ;
193
202
for (it = 0 ; it < tf -> args .targets .size ; it ++ ) {
194
203
TestRef * index = & tf -> args .targets .slots [it ];
195
- run_test (& tf -> registry_modules [index -> group ].data [index -> idx ]);
204
+ tf -> fn_run_test (& tf -> registry_modules [index -> group ].data [index -> idx ]);
196
205
}
197
206
return EXIT_SUCCESS ;
198
207
}
@@ -230,7 +239,7 @@ static int run_concurrent(struct TestFramework* tf) {
230
239
TestRef tref ;
231
240
close (pipes [it ][1 ]); /* Close write end */
232
241
while (read (pipes [it ][0 ], & tref , sizeof (tref )) == sizeof (tref )) {
233
- run_test (& tf -> registry_modules [tref .group ].data [tref .idx ]);
242
+ tf -> fn_run_test (& tf -> registry_modules [tref .group ].data [tref .idx ]);
234
243
}
235
244
_exit (EXIT_SUCCESS ); /* finish child process */
236
245
} else {
@@ -277,6 +286,7 @@ static int tf_init(struct TestFramework* tf, int argc, char** argv)
277
286
tf -> args .num_processes = 0 ;
278
287
tf -> args .custom_seed = NULL ;
279
288
tf -> args .targets .size = 0 ;
289
+ tf -> args .logging = 0 ;
280
290
281
291
/* Disable buffering for stdout to improve reliability of getting
282
292
* diagnostic information. Happens right at the start of main because
@@ -322,6 +332,7 @@ static int tf_init(struct TestFramework* tf, int argc, char** argv)
322
332
}
323
333
}
324
334
335
+ tf -> fn_run_test = tf -> args .logging ? run_test_log : run_test ;
325
336
return EXIT_SUCCESS ;
326
337
}
327
338
@@ -334,6 +345,12 @@ static int tf_run(struct TestFramework* tf) {
334
345
int it ;
335
346
/* Initial test time */
336
347
int64_t start_time = gettime_i64 (); /* maybe move this after the slots set */
348
+ /* Verify 'tf_init' has been called */
349
+ if (!tf -> fn_run_test ) {
350
+ fprintf (stderr , "Error: No test runner set. You must call 'tf_init' first to initialize the framework "
351
+ "or manually assign 'fn_run_test' before calling 'tf_run'.\n" );
352
+ return EXIT_FAILURE ;
353
+ }
337
354
338
355
/* Populate targets with all tests if none were explicitly specified */
339
356
run_all = tf -> args .targets .size == 0 ;
@@ -354,12 +371,14 @@ static int tf_run(struct TestFramework* tf) {
354
371
tf -> args .targets .size = slot ;
355
372
}
356
373
374
+ if (!tf -> args .logging ) printf ("Tests running silently. Use '-log=1' to enable detailed logging\n" );
375
+
357
376
/* Run test RNG tests (must run before we really initialize the test RNG) */
358
377
/* Note: currently, these tests are executed sequentially because there */
359
378
/* is really only one test. */
360
379
for (it = 0 ; tf -> registry_no_rng && it < tf -> registry_no_rng -> size ; it ++ ) {
361
380
if (run_all ) { /* future: support filtering */
362
- run_test (& tf -> registry_no_rng -> data [it ]);
381
+ tf -> fn_run_test (& tf -> registry_no_rng -> data [it ]);
363
382
}
364
383
}
365
384
0 commit comments