2019-11-14 10:57:11 -08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/* Copyright (c) 2019 Facebook */
|
|
|
|
#include <test_progs.h>
|
2021-05-13 17:36:20 -07:00
|
|
|
#include "fentry_test.lskel.h"
|
|
|
|
#include "fexit_test.lskel.h"
|
2019-12-13 17:43:39 -08:00
|
|
|
|
2019-11-14 10:57:11 -08:00
|
|
|
void test_fentry_fexit(void)
|
|
|
|
{
|
2021-10-28 12:04:59 +05:30
|
|
|
struct fentry_test_lskel *fentry_skel = NULL;
|
|
|
|
struct fexit_test_lskel *fexit_skel = NULL;
|
2019-12-13 17:43:39 -08:00
|
|
|
__u64 *fentry_res, *fexit_res;
|
2020-03-04 20:18:52 +01:00
|
|
|
int err, prog_fd, i;
|
2022-02-02 15:54:20 -08:00
|
|
|
LIBBPF_OPTS(bpf_test_run_opts, topts);
|
2019-12-13 17:43:39 -08:00
|
|
|
|
2021-10-28 12:04:59 +05:30
|
|
|
fentry_skel = fentry_test_lskel__open_and_load();
|
2022-02-02 15:54:20 -08:00
|
|
|
if (!ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"))
|
2019-11-14 10:57:11 -08:00
|
|
|
goto close_prog;
|
2021-10-28 12:04:59 +05:30
|
|
|
fexit_skel = fexit_test_lskel__open_and_load();
|
2022-02-02 15:54:20 -08:00
|
|
|
if (!ASSERT_OK_PTR(fexit_skel, "fexit_skel_load"))
|
2019-11-14 10:57:11 -08:00
|
|
|
goto close_prog;
|
|
|
|
|
2021-10-28 12:04:59 +05:30
|
|
|
err = fentry_test_lskel__attach(fentry_skel);
|
2022-02-02 15:54:20 -08:00
|
|
|
if (!ASSERT_OK(err, "fentry_attach"))
|
2019-11-14 10:57:11 -08:00
|
|
|
goto close_prog;
|
2021-10-28 12:04:59 +05:30
|
|
|
err = fexit_test_lskel__attach(fexit_skel);
|
2022-02-02 15:54:20 -08:00
|
|
|
if (!ASSERT_OK(err, "fexit_attach"))
|
2019-11-14 10:57:11 -08:00
|
|
|
goto close_prog;
|
|
|
|
|
2021-05-13 17:36:20 -07:00
|
|
|
prog_fd = fexit_skel->progs.test1.prog_fd;
|
2022-02-02 15:54:20 -08:00
|
|
|
err = bpf_prog_test_run_opts(prog_fd, &topts);
|
|
|
|
ASSERT_OK(err, "ipv6 test_run");
|
|
|
|
ASSERT_OK(topts.retval, "ipv6 test retval");
|
2019-11-14 10:57:11 -08:00
|
|
|
|
2019-12-13 17:43:39 -08:00
|
|
|
fentry_res = (__u64 *)fentry_skel->bss;
|
|
|
|
fexit_res = (__u64 *)fexit_skel->bss;
|
|
|
|
printf("%lld\n", fentry_skel->bss->test1_result);
|
bpf: Add tests for PTR_TO_BTF_ID vs. null comparison
Add two tests for PTR_TO_BTF_ID vs. null ptr comparison,
one for PTR_TO_BTF_ID in the ctx structure and the
other for PTR_TO_BTF_ID after one level pointer chasing.
In both cases, the test ensures condition is not
removed.
For example, for this test
struct bpf_fentry_test_t {
struct bpf_fentry_test_t *a;
};
int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
{
if (arg == 0)
test7_result = 1;
return 0;
}
Before the previous verifier change, we have xlated codes:
int test7(long long unsigned int * ctx):
; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
0: (79) r1 = *(u64 *)(r1 +0)
; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
1: (b4) w0 = 0
2: (95) exit
After the previous verifier change, we have:
int test7(long long unsigned int * ctx):
; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
0: (79) r1 = *(u64 *)(r1 +0)
; if (arg == 0)
1: (55) if r1 != 0x0 goto pc+4
; test7_result = 1;
2: (18) r1 = map[id:6][0]+48
4: (b7) r2 = 1
5: (7b) *(u64 *)(r1 +0) = r2
; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
6: (b4) w0 = 0
7: (95) exit
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200630171241.2523875-1-yhs@fb.com
2020-06-30 10:12:41 -07:00
|
|
|
for (i = 0; i < 8; i++) {
|
2022-02-02 15:54:20 -08:00
|
|
|
ASSERT_EQ(fentry_res[i], 1, "fentry result");
|
|
|
|
ASSERT_EQ(fexit_res[i], 1, "fexit result");
|
2019-12-13 17:43:39 -08:00
|
|
|
}
|
2019-11-14 10:57:11 -08:00
|
|
|
|
|
|
|
close_prog:
|
2021-10-28 12:04:59 +05:30
|
|
|
fentry_test_lskel__destroy(fentry_skel);
|
|
|
|
fexit_test_lskel__destroy(fexit_skel);
|
2019-11-14 10:57:11 -08:00
|
|
|
}
|