Skip to content

Commit 8160bae

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: add test selectors by number and name to test_progs
Add ability to specify either test number or test name substring to narrow down a set of test to run. Usage: sudo ./test_progs -n 1 sudo ./test_progs -t attach_probe Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 766f2a5 commit 8160bae

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

tools/testing/selftests/bpf/test_progs.c

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "test_progs.h"
55
#include "bpf_rlimit.h"
66
#include <argp.h>
7+
#include <string.h>
78

89
int error_cnt, pass_cnt;
910
bool jit_enabled;
@@ -164,6 +165,7 @@ void *spin_lock_thread(void *arg)
164165

165166
struct prog_test_def {
166167
const char *test_name;
168+
int test_num;
167169
void (*run_test)(void);
168170
};
169171

@@ -181,26 +183,49 @@ const char *argp_program_bug_address = "<[email protected]>";
181183
const char argp_program_doc[] = "BPF selftests test runner";
182184

183185
enum ARG_KEYS {
186+
ARG_TEST_NUM = 'n',
187+
ARG_TEST_NAME = 't',
184188
ARG_VERIFIER_STATS = 's',
185189
};
186190

187191
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" },
188196
{ "verifier-stats", ARG_VERIFIER_STATS, NULL, 0,
189197
"Output verifier statistics", },
190198
{},
191199
};
192200

193201
struct test_env {
202+
int test_num_selector;
203+
const char *test_name_selector;
194204
bool verifier_stats;
195205
};
196206

197-
static struct test_env env = {};
207+
static struct test_env env = {
208+
.test_num_selector = -1,
209+
};
198210

199211
static error_t parse_arg(int key, char *arg, struct argp_state *state)
200212
{
201213
struct test_env *env = state->input;
202214

203215
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;
204229
case ARG_VERIFIER_STATS:
205230
env->verifier_stats = true;
206231
break;
@@ -223,7 +248,7 @@ int main(int argc, char **argv)
223248
.parser = parse_arg,
224249
.doc = argp_program_doc,
225250
};
226-
const struct prog_test_def *def;
251+
struct prog_test_def *test;
227252
int err, i;
228253

229254
err = argp_parse(&argp, argc, argv, 0, NULL, &env);
@@ -237,8 +262,18 @@ int main(int argc, char **argv)
237262
verifier_stats = env.verifier_stats;
238263

239264
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();
242277
}
243278

244279
printf("Summary: %d PASSED, %d FAILED\n", pass_cnt, error_cnt);

0 commit comments

Comments
 (0)