Skip to content

Commit

Permalink
Merge branch 'Parallelize verif_scale selftests'
Browse files Browse the repository at this point in the history
Andrii Nakryiko says:

====================

Reduce amount of waiting time when running test_progs in parallel mode (-j) by
splitting bpf_verif_scale selftests into multiple tests. Previously it was
structured as a test with multiple subtests, but subtests are not easily
parallelizable with test_progs' infra. Also in practice each scale subtest is
really an independent test with nothing shared across all substest.

This patch set changes how test_progs test discovery works. Now it is possible
to define multiple tests within a single source code file. One of the patches
also marks tc_redirect selftests as serial, because it's extremely harmful to
the test system when run in parallel mode.
====================

Acked-by: Yucong Sun <sunyucong@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Alexei Starovoitov committed Oct 25, 2021
2 parents c825f5f + 3762a39 commit 57c8d36
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 88 deletions.
7 changes: 3 additions & 4 deletions tools/testing/selftests/bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,9 @@ ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
$(TRUNNER_TESTS_DIR)-tests-hdr := y
$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
$$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
$$(shell ( cd $(TRUNNER_TESTS_DIR); \
echo '/* Generated header, do not edit */'; \
ls *.c 2> /dev/null | \
sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@'; \
$$(shell (echo '/* Generated header, do not edit */'; \
sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p' \
$(TRUNNER_TESTS_DIR)/*.c | sort ; \
) > $$@)
endif

Expand Down
220 changes: 152 additions & 68 deletions tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,82 +39,166 @@ struct scale_test_def {
bool fails;
};

void test_bpf_verif_scale(void)
{
struct scale_test_def tests[] = {
{ "loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */ },

{ "test_verif_scale1.o", BPF_PROG_TYPE_SCHED_CLS },
{ "test_verif_scale2.o", BPF_PROG_TYPE_SCHED_CLS },
{ "test_verif_scale3.o", BPF_PROG_TYPE_SCHED_CLS },

{ "pyperf_global.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
{ "pyperf_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT },

/* full unroll by llvm */
{ "pyperf50.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
{ "pyperf100.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
{ "pyperf180.o", BPF_PROG_TYPE_RAW_TRACEPOINT },

/* partial unroll. llvm will unroll loop ~150 times.
* C loop count -> 600.
* Asm loop count -> 4.
* 16k insns in loop body.
* Total of 5 such loops. Total program size ~82k insns.
*/
{ "pyperf600.o", BPF_PROG_TYPE_RAW_TRACEPOINT },

/* no unroll at all.
* C loop count -> 600.
* ASM loop count -> 600.
* ~110 insns in loop body.
* Total of 5 such loops. Total program size ~1500 insns.
*/
{ "pyperf600_nounroll.o", BPF_PROG_TYPE_RAW_TRACEPOINT },

{ "loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
{ "loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
{ "loop4.o", BPF_PROG_TYPE_SCHED_CLS },
{ "loop5.o", BPF_PROG_TYPE_SCHED_CLS },
{ "loop6.o", BPF_PROG_TYPE_KPROBE },

/* partial unroll. 19k insn in a loop.
* Total program size 20.8k insn.
* ~350k processed_insns
*/
{ "strobemeta.o", BPF_PROG_TYPE_RAW_TRACEPOINT },

/* no unroll, tiny loops */
{ "strobemeta_nounroll1.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
{ "strobemeta_nounroll2.o", BPF_PROG_TYPE_RAW_TRACEPOINT },

/* non-inlined subprogs */
{ "strobemeta_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT },

{ "test_sysctl_loop1.o", BPF_PROG_TYPE_CGROUP_SYSCTL },
{ "test_sysctl_loop2.o", BPF_PROG_TYPE_CGROUP_SYSCTL },

{ "test_xdp_loop.o", BPF_PROG_TYPE_XDP },
{ "test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL },
};
static void scale_test(const char *file,
enum bpf_prog_type attach_type,
bool should_fail)
{
libbpf_print_fn_t old_print_fn = NULL;
int err, i;
int err;

if (env.verifier_stats) {
test__force_log();
old_print_fn = libbpf_set_print(libbpf_debug_print);
}

for (i = 0; i < ARRAY_SIZE(tests); i++) {
const struct scale_test_def *test = &tests[i];

if (!test__start_subtest(test->file))
continue;

err = check_load(test->file, test->attach_type);
CHECK_FAIL(err && !test->fails);
}
err = check_load(file, attach_type);
if (should_fail)
ASSERT_ERR(err, "expect_error");
else
ASSERT_OK(err, "expect_success");

if (env.verifier_stats)
libbpf_set_print(old_print_fn);
}

void test_verif_scale1()
{
scale_test("test_verif_scale1.o", BPF_PROG_TYPE_SCHED_CLS, false);
}

void test_verif_scale2()
{
scale_test("test_verif_scale2.o", BPF_PROG_TYPE_SCHED_CLS, false);
}

void test_verif_scale3()
{
scale_test("test_verif_scale3.o", BPF_PROG_TYPE_SCHED_CLS, false);
}

void test_verif_scale_pyperf_global()
{
scale_test("pyperf_global.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_pyperf_subprogs()
{
scale_test("pyperf_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_pyperf50()
{
/* full unroll by llvm */
scale_test("pyperf50.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_pyperf100()
{
/* full unroll by llvm */
scale_test("pyperf100.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_pyperf180()
{
/* full unroll by llvm */
scale_test("pyperf180.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_pyperf600()
{
/* partial unroll. llvm will unroll loop ~150 times.
* C loop count -> 600.
* Asm loop count -> 4.
* 16k insns in loop body.
* Total of 5 such loops. Total program size ~82k insns.
*/
scale_test("pyperf600.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_pyperf600_nounroll()
{
/* no unroll at all.
* C loop count -> 600.
* ASM loop count -> 600.
* ~110 insns in loop body.
* Total of 5 such loops. Total program size ~1500 insns.
*/
scale_test("pyperf600_nounroll.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_loop1()
{
scale_test("loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_loop2()
{
scale_test("loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_loop3_fail()
{
scale_test("loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */);
}

void test_verif_scale_loop4()
{
scale_test("loop4.o", BPF_PROG_TYPE_SCHED_CLS, false);
}

void test_verif_scale_loop5()
{
scale_test("loop5.o", BPF_PROG_TYPE_SCHED_CLS, false);
}

void test_verif_scale_loop6()
{
scale_test("loop6.o", BPF_PROG_TYPE_KPROBE, false);
}

void test_verif_scale_strobemeta()
{
/* partial unroll. 19k insn in a loop.
* Total program size 20.8k insn.
* ~350k processed_insns
*/
scale_test("strobemeta.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_strobemeta_nounroll1()
{
/* no unroll, tiny loops */
scale_test("strobemeta_nounroll1.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_strobemeta_nounroll2()
{
/* no unroll, tiny loops */
scale_test("strobemeta_nounroll2.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_strobemeta_subprogs()
{
/* non-inlined subprogs */
scale_test("strobemeta_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}

void test_verif_scale_sysctl_loop1()
{
scale_test("test_sysctl_loop1.o", BPF_PROG_TYPE_CGROUP_SYSCTL, false);
}

void test_verif_scale_sysctl_loop2()
{
scale_test("test_sysctl_loop2.o", BPF_PROG_TYPE_CGROUP_SYSCTL, false);
}

void test_verif_scale_xdp_loop()
{
scale_test("test_xdp_loop.o", BPF_PROG_TYPE_XDP, false);
}

void test_verif_scale_seg6_loop()
{
scale_test("test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL, false);
}
2 changes: 1 addition & 1 deletion tools/testing/selftests/bpf/prog_tests/btf_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static char *dump_buf;
static size_t dump_buf_sz;
static FILE *dump_buf_file;

void test_btf_dump_incremental(void)
static void test_btf_dump_incremental(void)
{
struct btf *btf = NULL;
struct btf_dump *d = NULL;
Expand Down
10 changes: 4 additions & 6 deletions tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ static int resolve_symbols(void)
return 0;
}

int test_resolve_btfids(void)
void test_resolve_btfids(void)
{
__u32 *test_list, *test_lists[] = { test_list_local, test_list_global };
unsigned int i, j;
int ret = 0;

if (resolve_symbols())
return -1;
return;

/* Check BTF_ID_LIST(test_list_local) and
* BTF_ID_LIST_GLOBAL(test_list_global) IDs
Expand All @@ -138,7 +138,7 @@ int test_resolve_btfids(void)
test_symbols[i].name,
test_list[i], test_symbols[i].id);
if (ret)
return ret;
return;
}
}

Expand All @@ -161,9 +161,7 @@ int test_resolve_btfids(void)

if (i > 0) {
if (!ASSERT_LE(test_set.ids[i - 1], test_set.ids[i], "sort_check"))
return -1;
return;
}
}

return ret;
}
2 changes: 1 addition & 1 deletion tools/testing/selftests/bpf/prog_tests/signal_pending.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void test_signal_pending_by_type(enum bpf_prog_type prog_type)
signal(SIGALRM, SIG_DFL);
}

void test_signal_pending(enum bpf_prog_type prog_type)
void test_signal_pending(void)
{
test_signal_pending_by_type(BPF_PROG_TYPE_SOCKET_FILTER);
test_signal_pending_by_type(BPF_PROG_TYPE_FLOW_DISSECTOR);
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#define EXP_NO_BUF_RET 29

void test_snprintf_positive(void)
static void test_snprintf_positive(void)
{
char exp_addr_out[] = EXP_ADDR_OUT;
char exp_sym_out[] = EXP_SYM_OUT;
Expand Down Expand Up @@ -103,7 +103,7 @@ static int load_single_snprintf(char *fmt)
return ret;
}

void test_snprintf_negative(void)
static void test_snprintf_negative(void)
{
ASSERT_OK(load_single_snprintf("valid %d"), "valid usage");

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/bpf/prog_tests/tc_redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ static void *test_tc_redirect_run_tests(void *arg)
return NULL;
}

void test_tc_redirect(void)
void serial_test_tc_redirect(void)
{
pthread_t test_thread;
int err;
Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <test_progs.h>
#include <network_helpers.h>

void test_xdp_adjust_tail_shrink(void)
static void test_xdp_adjust_tail_shrink(void)
{
const char *file = "./test_xdp_adjust_tail_shrink.o";
__u32 duration, retval, size, expect_sz;
Expand Down Expand Up @@ -30,7 +30,7 @@ void test_xdp_adjust_tail_shrink(void)
bpf_object__close(obj);
}

void test_xdp_adjust_tail_grow(void)
static void test_xdp_adjust_tail_grow(void)
{
const char *file = "./test_xdp_adjust_tail_grow.o";
struct bpf_object *obj;
Expand Down Expand Up @@ -58,7 +58,7 @@ void test_xdp_adjust_tail_grow(void)
bpf_object__close(obj);
}

void test_xdp_adjust_tail_grow2(void)
static void test_xdp_adjust_tail_grow2(void)
{
const char *file = "./test_xdp_adjust_tail_grow.o";
char buf[4096]; /* avoid segfault: large buf to hold grow results */
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define IFINDEX_LO 1

void test_xdp_with_devmap_helpers(void)
static void test_xdp_with_devmap_helpers(void)
{
struct test_xdp_with_devmap_helpers *skel;
struct bpf_prog_info info = {};
Expand Down Expand Up @@ -60,7 +60,7 @@ void test_xdp_with_devmap_helpers(void)
test_xdp_with_devmap_helpers__destroy(skel);
}

void test_neg_xdp_devmap_helpers(void)
static void test_neg_xdp_devmap_helpers(void)
{
struct test_xdp_devmap_helpers *skel;

Expand Down

0 comments on commit 57c8d36

Please sign in to comment.