tools/bpf: change selftest test_btf for both jit and non-jit
The selftest test_btf is changed to test both jit and non-jit. The test result should be the same regardless of whether jit is enabled or not. Signed-off-by: Yonghong Song <yhs@fb.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
ba64e7d852
commit
812dd689da
|
@ -29,7 +29,6 @@
|
||||||
static uint32_t pass_cnt;
|
static uint32_t pass_cnt;
|
||||||
static uint32_t error_cnt;
|
static uint32_t error_cnt;
|
||||||
static uint32_t skip_cnt;
|
static uint32_t skip_cnt;
|
||||||
static bool jit_enabled;
|
|
||||||
|
|
||||||
#define CHECK(condition, format...) ({ \
|
#define CHECK(condition, format...) ({ \
|
||||||
int __ret = !!(condition); \
|
int __ret = !!(condition); \
|
||||||
|
@ -65,24 +64,6 @@ static int __base_pr(const char *format, ...)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_jit_enabled(void)
|
|
||||||
{
|
|
||||||
const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable";
|
|
||||||
bool enabled = false;
|
|
||||||
int sysctl_fd;
|
|
||||||
|
|
||||||
sysctl_fd = open(jit_sysctl, 0, O_RDONLY);
|
|
||||||
if (sysctl_fd != -1) {
|
|
||||||
char tmpc;
|
|
||||||
|
|
||||||
if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1)
|
|
||||||
enabled = (tmpc != '0');
|
|
||||||
close(sysctl_fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BTF_INFO_ENC(kind, root, vlen) \
|
#define BTF_INFO_ENC(kind, root, vlen) \
|
||||||
((!!(root) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
|
((!!(root) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
|
||||||
|
|
||||||
|
@ -2547,8 +2528,8 @@ static int do_test_file(unsigned int test_num)
|
||||||
test->btf_kv_notfound))
|
test->btf_kv_notfound))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (!jit_enabled || !has_btf_ext)
|
if (!has_btf_ext)
|
||||||
goto skip_jit;
|
goto skip;
|
||||||
|
|
||||||
/* get necessary program info */
|
/* get necessary program info */
|
||||||
info_len = sizeof(struct bpf_prog_info);
|
info_len = sizeof(struct bpf_prog_info);
|
||||||
|
@ -2636,7 +2617,7 @@ static int do_test_file(unsigned int test_num)
|
||||||
finfo = (void *)finfo + rec_size;
|
finfo = (void *)finfo + rec_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_jit:
|
skip:
|
||||||
fprintf(stderr, "OK");
|
fprintf(stderr, "OK");
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
@ -3270,12 +3251,6 @@ static int do_test_func_type(int test_num)
|
||||||
err = -1;
|
err = -1;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (!jit_enabled) {
|
|
||||||
skip_cnt++;
|
|
||||||
fprintf(stderr, "SKIPPED, please enable sysctl bpf_jit_enable\n");
|
|
||||||
err = 0;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get necessary lens */
|
/* get necessary lens */
|
||||||
info_len = sizeof(struct bpf_prog_info);
|
info_len = sizeof(struct bpf_prog_info);
|
||||||
|
@ -3452,8 +3427,6 @@ int main(int argc, char **argv)
|
||||||
if (args.always_log)
|
if (args.always_log)
|
||||||
libbpf_set_print(__base_pr, __base_pr, __base_pr);
|
libbpf_set_print(__base_pr, __base_pr, __base_pr);
|
||||||
|
|
||||||
jit_enabled = is_jit_enabled();
|
|
||||||
|
|
||||||
if (args.raw_test)
|
if (args.raw_test)
|
||||||
err |= test_raw();
|
err |= test_raw();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue