Skip to content

Commit

Permalink
selftests/bpf: test_progs: test__skip
Browse files Browse the repository at this point in the history
Export test__skip() to indicate skipped tests and use it in
test_send_signal_nmi().

Cc: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
fomichev authored and borkmann committed Aug 27, 2019
1 parent 08eea4f commit cd9c21d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/prog_tests/send_signal.c
Expand Up @@ -204,6 +204,7 @@ static int test_send_signal_nmi(void)
if (errno == ENOENT) {
printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n",
__func__);
test__skip();
return 0;
}
/* Let the test fail with a more informative message */
Expand Down
20 changes: 18 additions & 2 deletions tools/testing/selftests/bpf/test_progs.c
Expand Up @@ -17,6 +17,7 @@ struct prog_test_def {
bool force_log;
int pass_cnt;
int error_cnt;
int skip_cnt;
bool tested;

const char *subtest_name;
Expand Down Expand Up @@ -56,6 +57,14 @@ static void dump_test_log(const struct prog_test_def *test, bool failed)
fseeko(stdout, 0, SEEK_SET); /* rewind */
}

static void skip_account(void)
{
if (env.test->skip_cnt) {
env.skip_cnt++;
env.test->skip_cnt = 0;
}
}

void test__end_subtest()
{
struct prog_test_def *test = env.test;
Expand All @@ -65,6 +74,7 @@ void test__end_subtest()
env.fail_cnt++;
else
env.sub_succ_cnt++;
skip_account();

dump_test_log(test, sub_error_cnt);

Expand Down Expand Up @@ -105,6 +115,11 @@ void test__force_log() {
env.test->force_log = true;
}

void test__skip(void)
{
env.test->skip_cnt++;
}

struct ipv4_packet pkt_v4 = {
.eth.h_proto = __bpf_constant_htons(ETH_P_IP),
.iph.ihl = 5,
Expand Down Expand Up @@ -510,6 +525,7 @@ int main(int argc, char **argv)
env.fail_cnt++;
else
env.succ_cnt++;
skip_account();

dump_test_log(test, test->error_cnt);

Expand All @@ -518,8 +534,8 @@ int main(int argc, char **argv)
test->error_cnt ? "FAIL" : "OK");
}
stdio_restore();
printf("Summary: %d/%d PASSED, %d FAILED\n",
env.succ_cnt, env.sub_succ_cnt, env.fail_cnt);
printf("Summary: %d/%d PASSED, %d SKIPPED, %d FAILED\n",
env.succ_cnt, env.sub_succ_cnt, env.skip_cnt, env.fail_cnt);

free(env.test_selector.num_set);
free(env.subtest_selector.num_set);
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/bpf/test_progs.h
Expand Up @@ -64,6 +64,7 @@ struct test_env {
int succ_cnt; /* successful tests */
int sub_succ_cnt; /* successful sub-tests */
int fail_cnt; /* total failed tests + sub-tests */
int skip_cnt; /* skipped tests */
};

extern int error_cnt;
Expand All @@ -72,6 +73,7 @@ extern struct test_env env;

extern void test__force_log();
extern bool test__start_subtest(const char *name);
extern void test__skip(void);

#define MAGIC_BYTES 123

Expand Down

0 comments on commit cd9c21d

Please sign in to comment.