99
1010#include <bennet/prelude.h>
1111#include <bennet/state/rand_alloc.h>
12+ #include <bennet/utils.h>
13+ #include <bennet/utils/hash_table.h>
1214#include <cn-executable/utils.h>
1315#include <cn-testing/result.h>
1416#include <cn-testing/test.h>
@@ -138,6 +140,10 @@ void cn_trap(void) {
138140 _cn_trap ();
139141}
140142
143+ typedef const char * const_char_ptr ;
144+ BENNET_HASH_TABLE_DECL (const_char_ptr , uint8_t )
145+ BENNET_HASH_TABLE_IMPL (const_char_ptr , uint8_t )
146+
141147struct cn_test_reproduction {
142148 size_t size ;
143149 bennet_rand_checkpoint checkpoint ;
@@ -153,6 +159,12 @@ int cn_test_main(int argc, char* argv[]) {
153159 set_cn_logging_level (CN_LOGGING_NONE );
154160
155161 bennet_srand (bennet_get_milliseconds ());
162+
163+ // Initialize test filter hash table
164+ bennet_hash_table (const_char_ptr , uint8_t ) test_filter ;
165+ bennet_hash_table_init (const_char_ptr , uint8_t )(
166+ & test_filter , string_hash , string_equal );
167+
156168 enum cn_test_gen_progress progress_level = CN_TEST_GEN_PROGRESS_ALL ;
157169 uint64_t seed = bennet_rand ();
158170 enum cn_logging_level logging_level = CN_LOGGING_ERROR ;
@@ -314,6 +326,32 @@ int cn_test_main(int argc, char* argv[]) {
314326 } else if (strcmp ("--max-input-alloc" , arg ) == 0 ) {
315327 bennet_rand_alloc_set_mem_size (strtoul (argv [i + 1 ], NULL , 10 ));
316328 i ++ ;
329+ } else if (strcmp ("--only" , arg ) == 0 ) {
330+ char * test_names = argv [i + 1 ];
331+ char * test_names_copy = strdup (test_names );
332+ assert (test_names_copy != NULL );
333+
334+ // Parse comma-separated test names
335+ char * token = strtok (test_names_copy , "," );
336+ while (token != NULL ) {
337+ // Trim leading/trailing whitespace
338+ while (* token == ' ' || * token == '\t' )
339+ token ++ ;
340+ char * end = token + strlen (token ) - 1 ;
341+ while (end > token && (* end == ' ' || * end == '\t' ))
342+ end -- ;
343+ * (end + 1 ) = '\0' ;
344+
345+ // Add to filter (store the original token pointer)
346+ char * stored_name = strdup (token );
347+ assert (stored_name != NULL );
348+ bennet_hash_table_set (const_char_ptr , uint8_t )(& test_filter , stored_name , true);
349+
350+ token = strtok (NULL , "," );
351+ }
352+
353+ free (test_names_copy );
354+ i ++ ;
317355 }
318356 }
319357
@@ -360,6 +398,14 @@ int cn_test_main(int argc, char* argv[]) {
360398 continue ;
361399 }
362400
401+ // Skip tests not in the filter if filter is non-empty
402+ if (bennet_hash_table_size (const_char_ptr , uint8_t )(& test_filter ) > 0 ) {
403+ if (!bennet_hash_table_contains (const_char_ptr , uint8_t )(
404+ & test_filter , test_cases [i ].name )) {
405+ continue ;
406+ }
407+ }
408+
363409 if (output_tyche || print_size_info ) {
364410 bennet_info_sizes_set_function_under_test (test_cases [i ].name );
365411 }
@@ -524,5 +570,8 @@ outside_loop:;
524570 bennet_info_timing_print_info ();
525571 }
526572
573+ // Clean up test filter hash table
574+ bennet_hash_table_free (const_char_ptr , uint8_t )(& test_filter );
575+
527576 return !(failed == 0 && errored == 0 );
528577}
0 commit comments