4
4
#include "test_progs.h"
5
5
#include "bpf_rlimit.h"
6
6
#include <argp.h>
7
+ #include <string.h>
7
8
8
9
int error_cnt , pass_cnt ;
9
10
bool jit_enabled ;
@@ -164,6 +165,7 @@ void *spin_lock_thread(void *arg)
164
165
165
166
struct prog_test_def {
166
167
const char * test_name ;
168
+ int test_num ;
167
169
void (* run_test )(void );
168
170
};
169
171
181
183
const char argp_program_doc [] = "BPF selftests test runner" ;
182
184
183
185
enum ARG_KEYS {
186
+ ARG_TEST_NUM = 'n' ,
187
+ ARG_TEST_NAME = 't' ,
184
188
ARG_VERIFIER_STATS = 's' ,
185
189
};
186
190
187
191
static const struct argp_option opts [] = {
192
+ { "num" , ARG_TEST_NUM , "NUM" , 0 ,
193
+ "Run test number NUM only " },
194
+ { "name" , ARG_TEST_NAME , "NAME" , 0 ,
195
+ "Run tests with names containing NAME" },
188
196
{ "verifier-stats" , ARG_VERIFIER_STATS , NULL , 0 ,
189
197
"Output verifier statistics" , },
190
198
{},
191
199
};
192
200
193
201
struct test_env {
202
+ int test_num_selector ;
203
+ const char * test_name_selector ;
194
204
bool verifier_stats ;
195
205
};
196
206
197
- static struct test_env env = {};
207
+ static struct test_env env = {
208
+ .test_num_selector = -1 ,
209
+ };
198
210
199
211
static error_t parse_arg (int key , char * arg , struct argp_state * state )
200
212
{
201
213
struct test_env * env = state -> input ;
202
214
203
215
switch (key ) {
216
+ case ARG_TEST_NUM : {
217
+ int test_num ;
218
+
219
+ errno = 0 ;
220
+ test_num = strtol (arg , NULL , 10 );
221
+ if (errno )
222
+ return - errno ;
223
+ env -> test_num_selector = test_num ;
224
+ break ;
225
+ }
226
+ case ARG_TEST_NAME :
227
+ env -> test_name_selector = arg ;
228
+ break ;
204
229
case ARG_VERIFIER_STATS :
205
230
env -> verifier_stats = true;
206
231
break ;
@@ -223,7 +248,7 @@ int main(int argc, char **argv)
223
248
.parser = parse_arg ,
224
249
.doc = argp_program_doc ,
225
250
};
226
- const struct prog_test_def * def ;
251
+ struct prog_test_def * test ;
227
252
int err , i ;
228
253
229
254
err = argp_parse (& argp , argc , argv , 0 , NULL , & env );
@@ -237,8 +262,18 @@ int main(int argc, char **argv)
237
262
verifier_stats = env .verifier_stats ;
238
263
239
264
for (i = 0 ; i < ARRAY_SIZE (prog_test_defs ); i ++ ) {
240
- def = & prog_test_defs [i ];
241
- def -> run_test ();
265
+ test = & prog_test_defs [i ];
266
+
267
+ test -> test_num = i + 1 ;
268
+
269
+ if (env .test_num_selector >= 0 &&
270
+ test -> test_num != env .test_num_selector )
271
+ continue ;
272
+ if (env .test_name_selector &&
273
+ !strstr (test -> test_name , env .test_name_selector ))
274
+ continue ;
275
+
276
+ test -> run_test ();
242
277
}
243
278
244
279
printf ("Summary: %d PASSED, %d FAILED\n" , pass_cnt , error_cnt );
0 commit comments