Commit 3762a39c authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

selftests/bpf: Split out bpf_verif_scale selftests into multiple tests

Instead of using subtests in bpf_verif_scale selftest, turn each scale
sub-test into its own test. Each subtest is compltely independent and
just reuses a bit of common test running logic, so the conversion is
trivial. For convenience, keep all of BPF verifier scale tests in one
file.

This conversion shaves off a significant amount of time when running
test_progs in parallel mode. E.g., just running scale tests (-t verif_scale):

BEFORE
======
Summary: 24/0 PASSED, 0 SKIPPED, 0 FAILED

real    0m22.894s
user    0m0.012s
sys     0m22.797s

AFTER
=====
Summary: 24/0 PASSED, 0 SKIPPED, 0 FAILED

real    0m12.044s
user    0m0.024s
sys     0m27.869s

Ten second saving right there. test_progs -j is not yet ready to be
turned on by default, unfortunately, and some tests fail almost every
time, but this is a good improvement nevertheless. Ignoring few
failures, here is sequential vs parallel run times when running all
tests now:

SEQUENTIAL
==========
Summary: 206/953 PASSED, 4 SKIPPED, 0 FAILED

real    1m5.625s
user    0m4.211s
sys     0m31.650s

PARALLEL
========
Summary: 204/952 PASSED, 4 SKIPPED, 2 FAILED

real    0m35.550s
user    0m4.998s
sys     0m39.890s
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211022223228.99920-5-andrii@kernel.org
parent 2c0f51ac
...@@ -39,82 +39,166 @@ struct scale_test_def { ...@@ -39,82 +39,166 @@ struct scale_test_def {
bool fails; bool fails;
}; };
void test_bpf_verif_scale(void) static void scale_test(const char *file,
enum bpf_prog_type attach_type,
bool should_fail)
{ {
struct scale_test_def tests[] = { libbpf_print_fn_t old_print_fn = NULL;
{ "loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */ }, int err;
if (env.verifier_stats) {
test__force_log();
old_print_fn = libbpf_set_print(libbpf_debug_print);
}
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);
}
{ "test_verif_scale1.o", BPF_PROG_TYPE_SCHED_CLS }, void test_verif_scale_pyperf_subprogs()
{ "test_verif_scale2.o", BPF_PROG_TYPE_SCHED_CLS }, {
{ "test_verif_scale3.o", BPF_PROG_TYPE_SCHED_CLS }, scale_test("pyperf_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
{ "pyperf_global.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, void test_verif_scale_pyperf50()
{ "pyperf_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, {
/* full unroll by llvm */
scale_test("pyperf50.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
void test_verif_scale_pyperf100()
{
/* full unroll by llvm */ /* full unroll by llvm */
{ "pyperf50.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, scale_test("pyperf100.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
{ "pyperf100.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, }
{ "pyperf180.o", BPF_PROG_TYPE_RAW_TRACEPOINT },
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. /* partial unroll. llvm will unroll loop ~150 times.
* C loop count -> 600. * C loop count -> 600.
* Asm loop count -> 4. * Asm loop count -> 4.
* 16k insns in loop body. * 16k insns in loop body.
* Total of 5 such loops. Total program size ~82k insns. * Total of 5 such loops. Total program size ~82k insns.
*/ */
{ "pyperf600.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, scale_test("pyperf600.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
void test_verif_scale_pyperf600_nounroll()
{
/* no unroll at all. /* no unroll at all.
* C loop count -> 600. * C loop count -> 600.
* ASM loop count -> 600. * ASM loop count -> 600.
* ~110 insns in loop body. * ~110 insns in loop body.
* Total of 5 such loops. Total program size ~1500 insns. * Total of 5 such loops. Total program size ~1500 insns.
*/ */
{ "pyperf600_nounroll.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, scale_test("pyperf600_nounroll.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
{ "loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, void test_verif_scale_loop1()
{ "loop2.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, {
{ "loop4.o", BPF_PROG_TYPE_SCHED_CLS }, scale_test("loop1.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
{ "loop5.o", BPF_PROG_TYPE_SCHED_CLS }, }
{ "loop6.o", BPF_PROG_TYPE_KPROBE },
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. /* partial unroll. 19k insn in a loop.
* Total program size 20.8k insn. * Total program size 20.8k insn.
* ~350k processed_insns * ~350k processed_insns
*/ */
{ "strobemeta.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, scale_test("strobemeta.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
void test_verif_scale_strobemeta_nounroll1()
{
/* no unroll, tiny loops */ /* no unroll, tiny loops */
{ "strobemeta_nounroll1.o", BPF_PROG_TYPE_RAW_TRACEPOINT }, scale_test("strobemeta_nounroll1.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
{ "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 }, void test_verif_scale_strobemeta_nounroll2()
{ "test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL }, {
}; /* no unroll, tiny loops */
libbpf_print_fn_t old_print_fn = NULL; scale_test("strobemeta_nounroll2.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
int err, i; }
if (env.verifier_stats) { void test_verif_scale_strobemeta_subprogs()
test__force_log(); {
old_print_fn = libbpf_set_print(libbpf_debug_print); /* non-inlined subprogs */
} scale_test("strobemeta_subprogs.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
for (i = 0; i < ARRAY_SIZE(tests); i++) { void test_verif_scale_sysctl_loop1()
const struct scale_test_def *test = &tests[i]; {
scale_test("test_sysctl_loop1.o", BPF_PROG_TYPE_CGROUP_SYSCTL, false);
}
if (!test__start_subtest(test->file)) void test_verif_scale_sysctl_loop2()
continue; {
scale_test("test_sysctl_loop2.o", BPF_PROG_TYPE_CGROUP_SYSCTL, false);
}
err = check_load(test->file, test->attach_type); void test_verif_scale_xdp_loop()
CHECK_FAIL(err && !test->fails); {
} scale_test("test_xdp_loop.o", BPF_PROG_TYPE_XDP, false);
}
if (env.verifier_stats) void test_verif_scale_seg6_loop()
libbpf_set_print(old_print_fn); {
scale_test("test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL, false);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment