2019-04-02 04:27:48 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// Copyright (c) 2019 Facebook
|
|
|
|
#include <test_progs.h>
|
|
|
|
static int libbpf_debug_print(enum libbpf_print_level level,
|
|
|
|
const char *format, va_list args)
|
|
|
|
{
|
|
|
|
if (level != LIBBPF_DEBUG)
|
2019-06-15 19:12:24 +00:00
|
|
|
return vfprintf(stderr, format, args);
|
2019-04-02 04:27:48 +00:00
|
|
|
|
|
|
|
if (!strstr(format, "verifier log"))
|
|
|
|
return 0;
|
|
|
|
return vfprintf(stderr, "%s", args);
|
|
|
|
}
|
|
|
|
|
2019-05-22 03:14:21 +00:00
|
|
|
static int check_load(const char *file, enum bpf_prog_type type)
|
2019-04-02 04:27:48 +00:00
|
|
|
{
|
|
|
|
struct bpf_prog_load_attr attr;
|
2019-05-08 16:49:32 +00:00
|
|
|
struct bpf_object *obj = NULL;
|
2019-04-02 04:27:48 +00:00
|
|
|
int err, prog_fd;
|
|
|
|
|
|
|
|
memset(&attr, 0, sizeof(struct bpf_prog_load_attr));
|
|
|
|
attr.file = file;
|
2019-05-22 03:14:21 +00:00
|
|
|
attr.prog_type = type;
|
2019-04-02 04:27:48 +00:00
|
|
|
attr.log_level = 4;
|
selftests: bpf: enable hi32 randomization for all tests
The previous libbpf patch allows user to specify "prog_flags" to bpf
program load APIs. To enable high 32-bit randomization for a test, we need
to set BPF_F_TEST_RND_HI32 in "prog_flags".
To enable such randomization for all tests, we need to make sure all places
are passing BPF_F_TEST_RND_HI32. Changing them one by one is not
convenient, also, it would be better if a test could be switched to
"normal" running mode without code change.
Given the program load APIs used across bpf selftests are mostly:
bpf_prog_load: load from file
bpf_load_program: load from raw insns
A test_stub.c is implemented for bpf seltests, it offers two functions for
testing purpose:
bpf_prog_test_load
bpf_test_load_program
The are the same as "bpf_prog_load" and "bpf_load_program", except they
also set BPF_F_TEST_RND_HI32. Given *_xattr functions are the APIs to
customize any "prog_flags", it makes little sense to put these two
functions into libbpf.
Then, the following CFLAGS are passed to compilations for host programs:
-Dbpf_prog_load=bpf_prog_test_load
-Dbpf_load_program=bpf_test_load_program
They migrate the used load APIs to the test version, hence enable high
32-bit randomization for these tests without changing source code.
Besides all these, there are several testcases are using
"bpf_prog_load_attr" directly, their call sites are updated to pass
BPF_F_TEST_RND_HI32.
Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-05-24 22:25:21 +00:00
|
|
|
attr.prog_flags = BPF_F_TEST_RND_HI32;
|
2019-04-02 04:27:48 +00:00
|
|
|
err = bpf_prog_load_xattr(&attr, &obj, &prog_fd);
|
|
|
|
bpf_object__close(obj);
|
|
|
|
if (err)
|
|
|
|
error_cnt++;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_bpf_verif_scale(void)
|
|
|
|
{
|
2019-06-15 19:12:24 +00:00
|
|
|
const char *sched_cls[] = {
|
|
|
|
"./test_verif_scale1.o", "./test_verif_scale2.o", "./test_verif_scale3.o",
|
2019-05-22 03:14:21 +00:00
|
|
|
};
|
2019-06-15 19:12:24 +00:00
|
|
|
const char *raw_tp[] = {
|
|
|
|
/* full unroll by llvm */
|
|
|
|
"./pyperf50.o", "./pyperf100.o", "./pyperf180.o",
|
|
|
|
|
|
|
|
/* 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",
|
|
|
|
|
|
|
|
/* 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",
|
|
|
|
|
|
|
|
"./loop1.o", "./loop2.o",
|
|
|
|
|
|
|
|
/* partial unroll. 19k insn in a loop.
|
|
|
|
* Total program size 20.8k insn.
|
|
|
|
* ~350k processed_insns
|
|
|
|
*/
|
|
|
|
"./strobemeta.o",
|
|
|
|
|
|
|
|
/* no unroll, tiny loops */
|
|
|
|
"./strobemeta_nounroll1.o",
|
|
|
|
"./strobemeta_nounroll2.o",
|
|
|
|
};
|
|
|
|
const char *cg_sysctl[] = {
|
|
|
|
"./test_sysctl_loop1.o", "./test_sysctl_loop2.o",
|
2019-05-22 03:14:21 +00:00
|
|
|
};
|
|
|
|
int err, i;
|
2019-04-02 04:27:48 +00:00
|
|
|
|
|
|
|
if (verifier_stats)
|
|
|
|
libbpf_set_print(libbpf_debug_print);
|
|
|
|
|
2019-06-15 19:12:24 +00:00
|
|
|
err = check_load("./loop3.o", BPF_PROG_TYPE_RAW_TRACEPOINT);
|
|
|
|
printf("test_scale:loop3:%s\n", err ? (error_cnt--, "OK") : "FAIL");
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(sched_cls); i++) {
|
|
|
|
err = check_load(sched_cls[i], BPF_PROG_TYPE_SCHED_CLS);
|
|
|
|
printf("test_scale:%s:%s\n", sched_cls[i], err ? "FAIL" : "OK");
|
2019-05-22 03:14:21 +00:00
|
|
|
}
|
|
|
|
|
2019-06-15 19:12:24 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(raw_tp); i++) {
|
|
|
|
err = check_load(raw_tp[i], BPF_PROG_TYPE_RAW_TRACEPOINT);
|
|
|
|
printf("test_scale:%s:%s\n", raw_tp[i], err ? "FAIL" : "OK");
|
2019-05-22 03:14:21 +00:00
|
|
|
}
|
2019-06-15 19:12:24 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(cg_sysctl); i++) {
|
|
|
|
err = check_load(cg_sysctl[i], BPF_PROG_TYPE_CGROUP_SYSCTL);
|
|
|
|
printf("test_scale:%s:%s\n", cg_sysctl[i], err ? "FAIL" : "OK");
|
|
|
|
}
|
|
|
|
err = check_load("./test_xdp_loop.o", BPF_PROG_TYPE_XDP);
|
|
|
|
printf("test_scale:test_xdp_loop:%s\n", err ? "FAIL" : "OK");
|
|
|
|
|
|
|
|
err = check_load("./test_seg6_loop.o", BPF_PROG_TYPE_LWT_SEG6LOCAL);
|
|
|
|
printf("test_scale:test_seg6_loop:%s\n", err ? "FAIL" : "OK");
|
2019-04-02 04:27:48 +00:00
|
|
|
}
|