@@ -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 );
@@ -70,6 +75,7 @@ static void help(void) {
70
75
printf (" -seed=<hex> Set a specific RNG seed (default: random)\n" );
71
76
printf (" -target=<test name>, -t=<name> Run a specific test (can be provided multiple times)\n" );
72
77
printf (" -target=<module name>, -t=<module> Run all tests within a specific module (can be provided multiple times)\n" );
78
+ printf (" -log=<0|1> Enable or disable test execution logging (default: 0 = disabled)\n" );
73
79
printf ("\n" );
74
80
printf ("Notes:\n" );
75
81
printf (" - All arguments must be provided in the form '-key=value'.\n" );
@@ -180,18 +186,21 @@ static int read_args(int argc, char** argv, int start, struct TestFramework* tf)
180
186
return 0 ;
181
187
}
182
188
183
- static void run_test (const struct TestEntry * t ) {
189
+ static void run_test_log (const struct TestEntry * t ) {
190
+ int64_t start_time = gettime_i64 ();
184
191
printf ("Running %s..\n" , t -> name );
185
192
t -> func ();
186
- printf ("%s PASSED\n" , t -> name );
193
+ printf ("Test %s PASSED (%.3f sec) \n" , t -> name , ( double )( gettime_i64 () - start_time ) / 1000000 );
187
194
}
188
195
196
+ static void run_test (const struct TestEntry * t ) { t -> func (); }
197
+
189
198
/* Process tests in sequential order */
190
199
static int run_sequential (struct TestFramework * tf ) {
191
200
int it ;
192
201
for (it = 0 ; it < tf -> args .targets .size ; it ++ ) {
193
202
TestRef * index = & tf -> args .targets .slots [it ];
194
- run_test (& tf -> registry_modules [index -> group ].data [index -> idx ]);
203
+ tf -> fn_run_test (& tf -> registry_modules [index -> group ].data [index -> idx ]);
195
204
}
196
205
return EXIT_SUCCESS ;
197
206
}
@@ -229,7 +238,7 @@ static int run_concurrent(struct TestFramework* tf) {
229
238
TestRef tref ;
230
239
close (pipes [it ][1 ]); /* Close write end */
231
240
while (read (pipes [it ][0 ], & tref , sizeof (tref )) == sizeof (tref )) {
232
- run_test (& tf -> registry_modules [tref .group ].data [tref .idx ]);
241
+ tf -> fn_run_test (& tf -> registry_modules [tref .group ].data [tref .idx ]);
233
242
}
234
243
_exit (EXIT_SUCCESS ); /* finish child process */
235
244
} else {
@@ -271,6 +280,7 @@ static int tf_init(struct TestFramework* tf, int argc, char** argv)
271
280
tf -> args .num_processes = 0 ;
272
281
tf -> args .custom_seed = NULL ;
273
282
tf -> args .targets .size = 0 ;
283
+ tf -> args .logging = 0 ;
274
284
275
285
/* Disable buffering for stdout to improve reliability of getting
276
286
* diagnostic information. Happens right at the start of main because
@@ -313,6 +323,7 @@ static int tf_init(struct TestFramework* tf, int argc, char** argv)
313
323
}
314
324
}
315
325
326
+ tf -> fn_run_test = tf -> args .logging ? run_test_log : run_test ;
316
327
return EXIT_SUCCESS ;
317
328
}
318
329
@@ -325,6 +336,12 @@ static int tf_run(struct TestFramework* tf) {
325
336
int it ;
326
337
/* Initial test time */
327
338
int64_t start_time = gettime_i64 (); /* maybe move this after the slots set */
339
+ /* Verify 'tf_init' has been called */
340
+ if (!tf -> fn_run_test ) {
341
+ fprintf (stderr , "Error: No test runner set. You must call 'tf_init' first to initialize the framework "
342
+ "or manually assign 'fn_run_test' before calling 'tf_run'.\n" );
343
+ return EXIT_FAILURE ;
344
+ }
328
345
329
346
/* Populate targets with all tests if none were explicitly specified */
330
347
run_all = tf -> args .targets .size == 0 ;
@@ -345,12 +362,14 @@ static int tf_run(struct TestFramework* tf) {
345
362
tf -> args .targets .size = slot ;
346
363
}
347
364
365
+ if (!tf -> args .logging ) printf ("Tests running silently. Use '-log=1' to enable detailed logging\n" );
366
+
348
367
/* Run test RNG tests (must run before we really initialize the test RNG) */
349
368
/* Note: currently, these tests are executed sequentially because there */
350
369
/* is really only one test. */
351
370
for (it = 0 ; tf -> registry_no_ctx && it < tf -> registry_no_ctx -> size ; it ++ ) {
352
371
if (run_all ) { /* future: support filtering */
353
- run_test (& tf -> registry_no_ctx -> data [it ]);
372
+ tf -> fn_run_test (& tf -> registry_no_ctx -> data [it ]);
354
373
}
355
374
}
356
375
0 commit comments