@@ -155,6 +155,7 @@ struct prog_test_def {
155
155
void (* run_serial_test )(void );
156
156
bool should_run ;
157
157
bool need_cgroup_cleanup ;
158
+ bool should_tmon ;
158
159
};
159
160
160
161
/* Override C runtime library's usleep() implementation to ensure nanosleep()
@@ -192,46 +193,59 @@ static bool should_run(struct test_selector *sel, int num, const char *name)
192
193
return num < sel -> num_set_len && sel -> num_set [num ];
193
194
}
194
195
195
- static bool should_run_subtest (struct test_selector * sel ,
196
- struct test_selector * subtest_sel ,
197
- int subtest_num ,
198
- const char * test_name ,
199
- const char * subtest_name )
196
+ static bool match_subtest (struct test_filter_set * filter ,
197
+ const char * test_name ,
198
+ const char * subtest_name )
200
199
{
201
200
int i , j ;
202
201
203
- for (i = 0 ; i < sel -> blacklist .cnt ; i ++ ) {
204
- if (glob_match (test_name , sel -> blacklist .tests [i ].name )) {
205
- if (!sel -> blacklist .tests [i ].subtest_cnt )
206
- return false;
207
-
208
- for (j = 0 ; j < sel -> blacklist .tests [i ].subtest_cnt ; j ++ ) {
209
- if (glob_match (subtest_name ,
210
- sel -> blacklist .tests [i ].subtests [j ]))
211
- return false;
212
- }
213
- }
214
- }
215
-
216
- for (i = 0 ; i < sel -> whitelist .cnt ; i ++ ) {
217
- if (glob_match (test_name , sel -> whitelist .tests [i ].name )) {
218
- if (!sel -> whitelist .tests [i ].subtest_cnt )
202
+ for (i = 0 ; i < filter -> cnt ; i ++ ) {
203
+ if (glob_match (test_name , filter -> tests [i ].name )) {
204
+ if (!filter -> tests [i ].subtest_cnt )
219
205
return true;
220
206
221
- for (j = 0 ; j < sel -> whitelist . tests [i ].subtest_cnt ; j ++ ) {
207
+ for (j = 0 ; j < filter -> tests [i ].subtest_cnt ; j ++ ) {
222
208
if (glob_match (subtest_name ,
223
- sel -> whitelist . tests [i ].subtests [j ]))
209
+ filter -> tests [i ].subtests [j ]))
224
210
return true;
225
211
}
226
212
}
227
213
}
228
214
215
+ return false;
216
+ }
217
+
218
+ static bool should_run_subtest (struct test_selector * sel ,
219
+ struct test_selector * subtest_sel ,
220
+ int subtest_num ,
221
+ const char * test_name ,
222
+ const char * subtest_name )
223
+ {
224
+ if (match_subtest (& sel -> blacklist , test_name , subtest_name ))
225
+ return false;
226
+
227
+ if (match_subtest (& sel -> whitelist , test_name , subtest_name ))
228
+ return true;
229
+
229
230
if (!sel -> whitelist .cnt && !subtest_sel -> num_set )
230
231
return true;
231
232
232
233
return subtest_num < subtest_sel -> num_set_len && subtest_sel -> num_set [subtest_num ];
233
234
}
234
235
236
+ static bool should_tmon (struct test_selector * sel , const char * name )
237
+ {
238
+ int i ;
239
+
240
+ for (i = 0 ; i < sel -> whitelist .cnt ; i ++ ) {
241
+ if (glob_match (name , sel -> whitelist .tests [i ].name ) &&
242
+ !sel -> whitelist .tests [i ].subtest_cnt )
243
+ return true;
244
+ }
245
+
246
+ return false;
247
+ }
248
+
235
249
static char * test_result (bool failed , bool skipped )
236
250
{
237
251
return failed ? "FAIL" : (skipped ? "SKIP" : "OK" );
@@ -488,6 +502,10 @@ bool test__start_subtest(const char *subtest_name)
488
502
return false;
489
503
}
490
504
505
+ subtest_state -> should_tmon = match_subtest (& env .tmon_selector .whitelist ,
506
+ test -> test_name ,
507
+ subtest_name );
508
+
491
509
env .subtest_state = subtest_state ;
492
510
stdio_hijack_init (& subtest_state -> log_buf , & subtest_state -> log_cnt );
493
511
@@ -667,7 +685,8 @@ enum ARG_KEYS {
667
685
ARG_TEST_NAME_GLOB_DENYLIST = 'd' ,
668
686
ARG_NUM_WORKERS = 'j' ,
669
687
ARG_DEBUG = -1 ,
670
- ARG_JSON_SUMMARY = 'J'
688
+ ARG_JSON_SUMMARY = 'J' ,
689
+ ARG_TRAFFIC_MONITOR = 'm' ,
671
690
};
672
691
673
692
static const struct argp_option opts [] = {
@@ -694,6 +713,10 @@ static const struct argp_option opts[] = {
694
713
{ "debug" , ARG_DEBUG , NULL , 0 ,
695
714
"print extra debug information for test_progs." },
696
715
{ "json-summary" , ARG_JSON_SUMMARY , "FILE" , 0 , "Write report in json format to this file." },
716
+ #ifdef TRAFFIC_MONITOR
717
+ { "traffic-monitor" , ARG_TRAFFIC_MONITOR , "NAMES" , 0 ,
718
+ "Monitor network traffic of tests with name matching the pattern (supports '*' wildcard)." },
719
+ #endif
697
720
{},
698
721
};
699
722
@@ -905,6 +928,18 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
905
928
break ;
906
929
case ARGP_KEY_END :
907
930
break ;
931
+ #ifdef TRAFFIC_MONITOR
932
+ case ARG_TRAFFIC_MONITOR :
933
+ if (arg [0 ] == '@' )
934
+ err = parse_test_list_file (arg + 1 ,
935
+ & env -> tmon_selector .whitelist ,
936
+ true);
937
+ else
938
+ err = parse_test_list (arg ,
939
+ & env -> tmon_selector .whitelist ,
940
+ true);
941
+ break ;
942
+ #endif
908
943
default :
909
944
return ARGP_ERR_UNKNOWN ;
910
945
}
@@ -1736,6 +1771,8 @@ int main(int argc, char **argv)
1736
1771
test -> test_num , test -> test_name , test -> test_name , test -> test_name );
1737
1772
exit (EXIT_ERR_SETUP_INFRA );
1738
1773
}
1774
+ if (test -> should_run )
1775
+ test -> should_tmon = should_tmon (& env .tmon_selector , test -> test_name );
1739
1776
}
1740
1777
1741
1778
/* ignore workers if we are just listing */
@@ -1820,6 +1857,7 @@ int main(int argc, char **argv)
1820
1857
1821
1858
free_test_selector (& env .test_selector );
1822
1859
free_test_selector (& env .subtest_selector );
1860
+ free_test_selector (& env .tmon_selector );
1823
1861
free_test_states ();
1824
1862
1825
1863
if (env .succ_cnt + env .fail_cnt + env .skip_cnt == 0 )
0 commit comments