3
3
*/
4
4
#define _GNU_SOURCE
5
5
#include "test_progs.h"
6
+ #include "testing_helpers.h"
6
7
#include "cgroup_helpers.h"
7
8
#include <argp.h>
8
9
#include <pthread.h>
@@ -84,12 +85,13 @@ static bool should_run(struct test_selector *sel, int num, const char *name)
84
85
int i ;
85
86
86
87
for (i = 0 ; i < sel -> blacklist .cnt ; i ++ ) {
87
- if (glob_match (name , sel -> blacklist .strs [i ]))
88
+ if (glob_match (name , sel -> blacklist .tests [i ].name ) &&
89
+ !sel -> blacklist .tests [i ].subtest_cnt )
88
90
return false;
89
91
}
90
92
91
93
for (i = 0 ; i < sel -> whitelist .cnt ; i ++ ) {
92
- if (glob_match (name , sel -> whitelist .strs [i ]))
94
+ if (glob_match (name , sel -> whitelist .tests [i ]. name ))
93
95
return true;
94
96
}
95
97
@@ -99,6 +101,46 @@ static bool should_run(struct test_selector *sel, int num, const char *name)
99
101
return num < sel -> num_set_len && sel -> num_set [num ];
100
102
}
101
103
104
+ static bool should_run_subtest (struct test_selector * sel ,
105
+ struct test_selector * subtest_sel ,
106
+ int subtest_num ,
107
+ const char * test_name ,
108
+ const char * subtest_name )
109
+ {
110
+ int i , j ;
111
+
112
+ for (i = 0 ; i < sel -> blacklist .cnt ; i ++ ) {
113
+ if (glob_match (test_name , sel -> blacklist .tests [i ].name )) {
114
+ if (!sel -> blacklist .tests [i ].subtest_cnt )
115
+ return false;
116
+
117
+ for (j = 0 ; j < sel -> blacklist .tests [i ].subtest_cnt ; j ++ ) {
118
+ if (glob_match (subtest_name ,
119
+ sel -> blacklist .tests [i ].subtests [j ]))
120
+ return false;
121
+ }
122
+ }
123
+ }
124
+
125
+ for (i = 0 ; i < sel -> whitelist .cnt ; i ++ ) {
126
+ if (glob_match (test_name , sel -> whitelist .tests [i ].name )) {
127
+ if (!sel -> whitelist .tests [i ].subtest_cnt )
128
+ return true;
129
+
130
+ for (j = 0 ; j < sel -> whitelist .tests [i ].subtest_cnt ; j ++ ) {
131
+ if (glob_match (subtest_name ,
132
+ sel -> whitelist .tests [i ].subtests [j ]))
133
+ return true;
134
+ }
135
+ }
136
+ }
137
+
138
+ if (!sel -> whitelist .cnt && !subtest_sel -> num_set )
139
+ return true;
140
+
141
+ return subtest_num < subtest_sel -> num_set_len && subtest_sel -> num_set [subtest_num ];
142
+ }
143
+
102
144
static void dump_test_log (const struct prog_test_def * test , bool failed )
103
145
{
104
146
if (stdout == env .stdout )
@@ -135,7 +177,6 @@ static void stdio_restore(void);
135
177
*/
136
178
static void reset_affinity (void )
137
179
{
138
-
139
180
cpu_set_t cpuset ;
140
181
int i , err ;
141
182
@@ -196,7 +237,7 @@ void test__end_subtest(void)
196
237
test -> subtest_name = NULL ;
197
238
}
198
239
199
- bool test__start_subtest (const char * name )
240
+ bool test__start_subtest (const char * subtest_name )
200
241
{
201
242
struct prog_test_def * test = env .test ;
202
243
@@ -205,17 +246,21 @@ bool test__start_subtest(const char *name)
205
246
206
247
test -> subtest_num ++ ;
207
248
208
- if (!name || !name [0 ]) {
249
+ if (!subtest_name || !subtest_name [0 ]) {
209
250
fprintf (env .stderr ,
210
251
"Subtest #%d didn't provide sub-test name!\n" ,
211
252
test -> subtest_num );
212
253
return false;
213
254
}
214
255
215
- if (!should_run (& env .subtest_selector , test -> subtest_num , name ))
256
+ if (!should_run_subtest (& env .test_selector ,
257
+ & env .subtest_selector ,
258
+ test -> subtest_num ,
259
+ test -> test_name ,
260
+ subtest_name ))
216
261
return false;
217
262
218
- test -> subtest_name = strdup (name );
263
+ test -> subtest_name = strdup (subtest_name );
219
264
if (!test -> subtest_name ) {
220
265
fprintf (env .stderr ,
221
266
"Subtest #%d: failed to copy subtest name!\n" ,
@@ -527,63 +572,29 @@ static int libbpf_print_fn(enum libbpf_print_level level,
527
572
return 0 ;
528
573
}
529
574
530
- static void free_str_set (const struct str_set * set )
575
+ static void free_test_filter_set (const struct test_filter_set * set )
531
576
{
532
- int i ;
577
+ int i , j ;
533
578
534
579
if (!set )
535
580
return ;
536
581
537
- for (i = 0 ; i < set -> cnt ; i ++ )
538
- free ((void * )set -> strs [i ]);
539
- free (set -> strs );
540
- }
541
-
542
- static int parse_str_list (const char * s , struct str_set * set , bool is_glob_pattern )
543
- {
544
- char * input , * state = NULL , * next , * * tmp , * * strs = NULL ;
545
- int i , cnt = 0 ;
582
+ for (i = 0 ; i < set -> cnt ; i ++ ) {
583
+ free ((void * )set -> tests [i ].name );
584
+ for (j = 0 ; j < set -> tests [i ].subtest_cnt ; j ++ )
585
+ free ((void * )set -> tests [i ].subtests [j ]);
546
586
547
- input = strdup (s );
548
- if (!input )
549
- return - ENOMEM ;
550
-
551
- while ((next = strtok_r (state ? NULL : input , "," , & state ))) {
552
- tmp = realloc (strs , sizeof (* strs ) * (cnt + 1 ));
553
- if (!tmp )
554
- goto err ;
555
- strs = tmp ;
556
-
557
- if (is_glob_pattern ) {
558
- strs [cnt ] = strdup (next );
559
- if (!strs [cnt ])
560
- goto err ;
561
- } else {
562
- strs [cnt ] = malloc (strlen (next ) + 2 + 1 );
563
- if (!strs [cnt ])
564
- goto err ;
565
- sprintf (strs [cnt ], "*%s*" , next );
566
- }
567
-
568
- cnt ++ ;
587
+ free ((void * )set -> tests [i ].subtests );
569
588
}
570
589
571
- tmp = realloc (set -> strs , sizeof (* strs ) * (cnt + set -> cnt ));
572
- if (!tmp )
573
- goto err ;
574
- memcpy (tmp + set -> cnt , strs , sizeof (* strs ) * cnt );
575
- set -> strs = (const char * * )tmp ;
576
- set -> cnt += cnt ;
590
+ free ((void * )set -> tests );
591
+ }
577
592
578
- free (input );
579
- free (strs );
580
- return 0 ;
581
- err :
582
- for (i = 0 ; i < cnt ; i ++ )
583
- free (strs [i ]);
584
- free (strs );
585
- free (input );
586
- return - ENOMEM ;
593
+ static void free_test_selector (struct test_selector * test_selector )
594
+ {
595
+ free_test_filter_set (& test_selector -> blacklist );
596
+ free_test_filter_set (& test_selector -> whitelist );
597
+ free (test_selector -> num_set );
587
598
}
588
599
589
600
extern int extra_prog_load_log_flags ;
@@ -615,33 +626,17 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
615
626
}
616
627
case ARG_TEST_NAME_GLOB_ALLOWLIST :
617
628
case ARG_TEST_NAME : {
618
- char * subtest_str = strchr (arg , '/' );
619
-
620
- if (subtest_str ) {
621
- * subtest_str = '\0' ;
622
- if (parse_str_list (subtest_str + 1 ,
623
- & env -> subtest_selector .whitelist ,
624
- key == ARG_TEST_NAME_GLOB_ALLOWLIST ))
625
- return - ENOMEM ;
626
- }
627
- if (parse_str_list (arg , & env -> test_selector .whitelist ,
628
- key == ARG_TEST_NAME_GLOB_ALLOWLIST ))
629
+ if (parse_test_list (arg ,
630
+ & env -> test_selector .whitelist ,
631
+ key == ARG_TEST_NAME_GLOB_ALLOWLIST ))
629
632
return - ENOMEM ;
630
633
break ;
631
634
}
632
635
case ARG_TEST_NAME_GLOB_DENYLIST :
633
636
case ARG_TEST_NAME_BLACKLIST : {
634
- char * subtest_str = strchr (arg , '/' );
635
-
636
- if (subtest_str ) {
637
- * subtest_str = '\0' ;
638
- if (parse_str_list (subtest_str + 1 ,
639
- & env -> subtest_selector .blacklist ,
640
- key == ARG_TEST_NAME_GLOB_DENYLIST ))
641
- return - ENOMEM ;
642
- }
643
- if (parse_str_list (arg , & env -> test_selector .blacklist ,
644
- key == ARG_TEST_NAME_GLOB_DENYLIST ))
637
+ if (parse_test_list (arg ,
638
+ & env -> test_selector .blacklist ,
639
+ key == ARG_TEST_NAME_GLOB_DENYLIST ))
645
640
return - ENOMEM ;
646
641
break ;
647
642
}
@@ -1493,12 +1488,8 @@ int main(int argc, char **argv)
1493
1488
out :
1494
1489
if (!env .list_test_names && env .has_testmod )
1495
1490
unload_bpf_testmod ();
1496
- free_str_set (& env .test_selector .blacklist );
1497
- free_str_set (& env .test_selector .whitelist );
1498
- free (env .test_selector .num_set );
1499
- free_str_set (& env .subtest_selector .blacklist );
1500
- free_str_set (& env .subtest_selector .whitelist );
1501
- free (env .subtest_selector .num_set );
1491
+
1492
+ free_test_selector (& env .test_selector );
1502
1493
1503
1494
if (env .succ_cnt + env .fail_cnt + env .skip_cnt == 0 )
1504
1495
return EXIT_NO_TEST ;
0 commit comments