Commit 087cba79 authored by Kumar Kartikeya Dwivedi's avatar Kumar Kartikeya Dwivedi Committed by Alexei Starovoitov

selftests/bpf: Add weak/typeless ksym test for light skeleton

Also, avoid using CO-RE features, as lskel doesn't support CO-RE, yet.
Include both light and libbpf skeleton in same file to test both of them
together.

In c48e51c8 ("bpf: selftests: Add selftests for module kfunc support"),
I added support for generating both lskel and libbpf skel for a BPF
object, however the name parameter for bpftool caused collisions when
included in same file together. This meant that every test needed a
separate file for a libbpf/light skeleton separation instead of
subtests.

Change that by appending a "_lskel" suffix to the name for files using
light skeleton, and convert all existing users.
Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211028063501.2239335-7-memxor@gmail.com
parent 92274e24
...@@ -325,7 +325,7 @@ LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h \ ...@@ -325,7 +325,7 @@ LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h \
LSKELS := kfunc_call_test.c fentry_test.c fexit_test.c fexit_sleep.c \ LSKELS := kfunc_call_test.c fentry_test.c fexit_test.c fexit_sleep.c \
test_ringbuf.c atomics.c trace_printk.c trace_vprintk.c test_ringbuf.c atomics.c trace_printk.c trace_vprintk.c
# Generate both light skeleton and libbpf skeleton for these # Generate both light skeleton and libbpf skeleton for these
LSKELS_EXTRA := test_ksyms_module.c LSKELS_EXTRA := test_ksyms_module.c test_ksyms_weak.c
SKEL_BLACKLIST += $$(LSKELS) SKEL_BLACKLIST += $$(LSKELS)
test_static_linked.skel.h-deps := test_static_linked1.o test_static_linked2.o test_static_linked.skel.h-deps := test_static_linked1.o test_static_linked2.o
...@@ -404,7 +404,7 @@ $(TRUNNER_BPF_LSKELS): %.lskel.h: %.o $(BPFTOOL) | $(TRUNNER_OUTPUT) ...@@ -404,7 +404,7 @@ $(TRUNNER_BPF_LSKELS): %.lskel.h: %.o $(BPFTOOL) | $(TRUNNER_OUTPUT)
$(Q)$$(BPFTOOL) gen object $$(<:.o=.linked2.o) $$(<:.o=.linked1.o) $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked2.o) $$(<:.o=.linked1.o)
$(Q)$$(BPFTOOL) gen object $$(<:.o=.linked3.o) $$(<:.o=.linked2.o) $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked3.o) $$(<:.o=.linked2.o)
$(Q)diff $$(<:.o=.linked2.o) $$(<:.o=.linked3.o) $(Q)diff $$(<:.o=.linked2.o) $$(<:.o=.linked3.o)
$(Q)$$(BPFTOOL) gen skeleton -L $$(<:.o=.linked3.o) name $$(notdir $$(<:.o=)) > $$@ $(Q)$$(BPFTOOL) gen skeleton -L $$(<:.o=.linked3.o) name $$(notdir $$(<:.o=_lskel)) > $$@
$(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_BPF_OBJS) $(BPFTOOL) | $(TRUNNER_OUTPUT) $(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_BPF_OBJS) $(BPFTOOL) | $(TRUNNER_OUTPUT)
$$(call msg,LINK-BPF,$(TRUNNER_BINARY),$$(@:.skel.h=.o)) $$(call msg,LINK-BPF,$(TRUNNER_BINARY),$$(@:.skel.h=.o))
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
#include "atomics.lskel.h" #include "atomics.lskel.h"
static void test_add(struct atomics *skel) static void test_add(struct atomics_lskel *skel)
{ {
int err, prog_fd; int err, prog_fd;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int link_fd; int link_fd;
link_fd = atomics__add__attach(skel); link_fd = atomics_lskel__add__attach(skel);
if (!ASSERT_GT(link_fd, 0, "attach(add)")) if (!ASSERT_GT(link_fd, 0, "attach(add)"))
return; return;
...@@ -36,13 +36,13 @@ static void test_add(struct atomics *skel) ...@@ -36,13 +36,13 @@ static void test_add(struct atomics *skel)
close(link_fd); close(link_fd);
} }
static void test_sub(struct atomics *skel) static void test_sub(struct atomics_lskel *skel)
{ {
int err, prog_fd; int err, prog_fd;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int link_fd; int link_fd;
link_fd = atomics__sub__attach(skel); link_fd = atomics_lskel__sub__attach(skel);
if (!ASSERT_GT(link_fd, 0, "attach(sub)")) if (!ASSERT_GT(link_fd, 0, "attach(sub)"))
return; return;
...@@ -69,13 +69,13 @@ static void test_sub(struct atomics *skel) ...@@ -69,13 +69,13 @@ static void test_sub(struct atomics *skel)
close(link_fd); close(link_fd);
} }
static void test_and(struct atomics *skel) static void test_and(struct atomics_lskel *skel)
{ {
int err, prog_fd; int err, prog_fd;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int link_fd; int link_fd;
link_fd = atomics__and__attach(skel); link_fd = atomics_lskel__and__attach(skel);
if (!ASSERT_GT(link_fd, 0, "attach(and)")) if (!ASSERT_GT(link_fd, 0, "attach(and)"))
return; return;
...@@ -97,13 +97,13 @@ static void test_and(struct atomics *skel) ...@@ -97,13 +97,13 @@ static void test_and(struct atomics *skel)
close(link_fd); close(link_fd);
} }
static void test_or(struct atomics *skel) static void test_or(struct atomics_lskel *skel)
{ {
int err, prog_fd; int err, prog_fd;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int link_fd; int link_fd;
link_fd = atomics__or__attach(skel); link_fd = atomics_lskel__or__attach(skel);
if (!ASSERT_GT(link_fd, 0, "attach(or)")) if (!ASSERT_GT(link_fd, 0, "attach(or)"))
return; return;
...@@ -126,13 +126,13 @@ static void test_or(struct atomics *skel) ...@@ -126,13 +126,13 @@ static void test_or(struct atomics *skel)
close(link_fd); close(link_fd);
} }
static void test_xor(struct atomics *skel) static void test_xor(struct atomics_lskel *skel)
{ {
int err, prog_fd; int err, prog_fd;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int link_fd; int link_fd;
link_fd = atomics__xor__attach(skel); link_fd = atomics_lskel__xor__attach(skel);
if (!ASSERT_GT(link_fd, 0, "attach(xor)")) if (!ASSERT_GT(link_fd, 0, "attach(xor)"))
return; return;
...@@ -154,13 +154,13 @@ static void test_xor(struct atomics *skel) ...@@ -154,13 +154,13 @@ static void test_xor(struct atomics *skel)
close(link_fd); close(link_fd);
} }
static void test_cmpxchg(struct atomics *skel) static void test_cmpxchg(struct atomics_lskel *skel)
{ {
int err, prog_fd; int err, prog_fd;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int link_fd; int link_fd;
link_fd = atomics__cmpxchg__attach(skel); link_fd = atomics_lskel__cmpxchg__attach(skel);
if (!ASSERT_GT(link_fd, 0, "attach(cmpxchg)")) if (!ASSERT_GT(link_fd, 0, "attach(cmpxchg)"))
return; return;
...@@ -183,13 +183,13 @@ static void test_cmpxchg(struct atomics *skel) ...@@ -183,13 +183,13 @@ static void test_cmpxchg(struct atomics *skel)
close(link_fd); close(link_fd);
} }
static void test_xchg(struct atomics *skel) static void test_xchg(struct atomics_lskel *skel)
{ {
int err, prog_fd; int err, prog_fd;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int link_fd; int link_fd;
link_fd = atomics__xchg__attach(skel); link_fd = atomics_lskel__xchg__attach(skel);
if (!ASSERT_GT(link_fd, 0, "attach(xchg)")) if (!ASSERT_GT(link_fd, 0, "attach(xchg)"))
return; return;
...@@ -212,10 +212,10 @@ static void test_xchg(struct atomics *skel) ...@@ -212,10 +212,10 @@ static void test_xchg(struct atomics *skel)
void test_atomics(void) void test_atomics(void)
{ {
struct atomics *skel; struct atomics_lskel *skel;
__u32 duration = 0; __u32 duration = 0;
skel = atomics__open_and_load(); skel = atomics_lskel__open_and_load();
if (CHECK(!skel, "skel_load", "atomics skeleton failed\n")) if (CHECK(!skel, "skel_load", "atomics skeleton failed\n"))
return; return;
...@@ -243,5 +243,5 @@ void test_atomics(void) ...@@ -243,5 +243,5 @@ void test_atomics(void)
test_xchg(skel); test_xchg(skel);
cleanup: cleanup:
atomics__destroy(skel); atomics_lskel__destroy(skel);
} }
...@@ -6,23 +6,23 @@ ...@@ -6,23 +6,23 @@
void test_fentry_fexit(void) void test_fentry_fexit(void)
{ {
struct fentry_test *fentry_skel = NULL; struct fentry_test_lskel *fentry_skel = NULL;
struct fexit_test *fexit_skel = NULL; struct fexit_test_lskel *fexit_skel = NULL;
__u64 *fentry_res, *fexit_res; __u64 *fentry_res, *fexit_res;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int err, prog_fd, i; int err, prog_fd, i;
fentry_skel = fentry_test__open_and_load(); fentry_skel = fentry_test_lskel__open_and_load();
if (CHECK(!fentry_skel, "fentry_skel_load", "fentry skeleton failed\n")) if (CHECK(!fentry_skel, "fentry_skel_load", "fentry skeleton failed\n"))
goto close_prog; goto close_prog;
fexit_skel = fexit_test__open_and_load(); fexit_skel = fexit_test_lskel__open_and_load();
if (CHECK(!fexit_skel, "fexit_skel_load", "fexit skeleton failed\n")) if (CHECK(!fexit_skel, "fexit_skel_load", "fexit skeleton failed\n"))
goto close_prog; goto close_prog;
err = fentry_test__attach(fentry_skel); err = fentry_test_lskel__attach(fentry_skel);
if (CHECK(err, "fentry_attach", "fentry attach failed: %d\n", err)) if (CHECK(err, "fentry_attach", "fentry attach failed: %d\n", err))
goto close_prog; goto close_prog;
err = fexit_test__attach(fexit_skel); err = fexit_test_lskel__attach(fexit_skel);
if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err)) if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err))
goto close_prog; goto close_prog;
...@@ -44,6 +44,6 @@ void test_fentry_fexit(void) ...@@ -44,6 +44,6 @@ void test_fentry_fexit(void)
} }
close_prog: close_prog:
fentry_test__destroy(fentry_skel); fentry_test_lskel__destroy(fentry_skel);
fexit_test__destroy(fexit_skel); fexit_test_lskel__destroy(fexit_skel);
} }
...@@ -3,19 +3,19 @@ ...@@ -3,19 +3,19 @@
#include <test_progs.h> #include <test_progs.h>
#include "fentry_test.lskel.h" #include "fentry_test.lskel.h"
static int fentry_test(struct fentry_test *fentry_skel) static int fentry_test(struct fentry_test_lskel *fentry_skel)
{ {
int err, prog_fd, i; int err, prog_fd, i;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int link_fd; int link_fd;
__u64 *result; __u64 *result;
err = fentry_test__attach(fentry_skel); err = fentry_test_lskel__attach(fentry_skel);
if (!ASSERT_OK(err, "fentry_attach")) if (!ASSERT_OK(err, "fentry_attach"))
return err; return err;
/* Check that already linked program can't be attached again. */ /* Check that already linked program can't be attached again. */
link_fd = fentry_test__test1__attach(fentry_skel); link_fd = fentry_test_lskel__test1__attach(fentry_skel);
if (!ASSERT_LT(link_fd, 0, "fentry_attach_link")) if (!ASSERT_LT(link_fd, 0, "fentry_attach_link"))
return -1; return -1;
...@@ -31,7 +31,7 @@ static int fentry_test(struct fentry_test *fentry_skel) ...@@ -31,7 +31,7 @@ static int fentry_test(struct fentry_test *fentry_skel)
return -1; return -1;
} }
fentry_test__detach(fentry_skel); fentry_test_lskel__detach(fentry_skel);
/* zero results for re-attach test */ /* zero results for re-attach test */
memset(fentry_skel->bss, 0, sizeof(*fentry_skel->bss)); memset(fentry_skel->bss, 0, sizeof(*fentry_skel->bss));
...@@ -40,10 +40,10 @@ static int fentry_test(struct fentry_test *fentry_skel) ...@@ -40,10 +40,10 @@ static int fentry_test(struct fentry_test *fentry_skel)
void test_fentry_test(void) void test_fentry_test(void)
{ {
struct fentry_test *fentry_skel = NULL; struct fentry_test_lskel *fentry_skel = NULL;
int err; int err;
fentry_skel = fentry_test__open_and_load(); fentry_skel = fentry_test_lskel__open_and_load();
if (!ASSERT_OK_PTR(fentry_skel, "fentry_skel_load")) if (!ASSERT_OK_PTR(fentry_skel, "fentry_skel_load"))
goto cleanup; goto cleanup;
...@@ -55,5 +55,5 @@ void test_fentry_test(void) ...@@ -55,5 +55,5 @@ void test_fentry_test(void)
ASSERT_OK(err, "fentry_second_attach"); ASSERT_OK(err, "fentry_second_attach");
cleanup: cleanup:
fentry_test__destroy(fentry_skel); fentry_test_lskel__destroy(fentry_skel);
} }
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
static int do_sleep(void *skel) static int do_sleep(void *skel)
{ {
struct fexit_sleep *fexit_skel = skel; struct fexit_sleep_lskel *fexit_skel = skel;
struct timespec ts1 = { .tv_nsec = 1 }; struct timespec ts1 = { .tv_nsec = 1 };
struct timespec ts2 = { .tv_sec = 10 }; struct timespec ts2 = { .tv_sec = 10 };
...@@ -25,16 +25,16 @@ static char child_stack[STACK_SIZE]; ...@@ -25,16 +25,16 @@ static char child_stack[STACK_SIZE];
void test_fexit_sleep(void) void test_fexit_sleep(void)
{ {
struct fexit_sleep *fexit_skel = NULL; struct fexit_sleep_lskel *fexit_skel = NULL;
int wstatus, duration = 0; int wstatus, duration = 0;
pid_t cpid; pid_t cpid;
int err, fexit_cnt; int err, fexit_cnt;
fexit_skel = fexit_sleep__open_and_load(); fexit_skel = fexit_sleep_lskel__open_and_load();
if (CHECK(!fexit_skel, "fexit_skel_load", "fexit skeleton failed\n")) if (CHECK(!fexit_skel, "fexit_skel_load", "fexit skeleton failed\n"))
goto cleanup; goto cleanup;
err = fexit_sleep__attach(fexit_skel); err = fexit_sleep_lskel__attach(fexit_skel);
if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err)) if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err))
goto cleanup; goto cleanup;
...@@ -60,7 +60,7 @@ void test_fexit_sleep(void) ...@@ -60,7 +60,7 @@ void test_fexit_sleep(void)
*/ */
close(fexit_skel->progs.nanosleep_fentry.prog_fd); close(fexit_skel->progs.nanosleep_fentry.prog_fd);
close(fexit_skel->progs.nanosleep_fexit.prog_fd); close(fexit_skel->progs.nanosleep_fexit.prog_fd);
fexit_sleep__detach(fexit_skel); fexit_sleep_lskel__detach(fexit_skel);
/* kill the thread to unwind sys_nanosleep stack through the trampoline */ /* kill the thread to unwind sys_nanosleep stack through the trampoline */
kill(cpid, 9); kill(cpid, 9);
...@@ -78,5 +78,5 @@ void test_fexit_sleep(void) ...@@ -78,5 +78,5 @@ void test_fexit_sleep(void)
goto cleanup; goto cleanup;
cleanup: cleanup:
fexit_sleep__destroy(fexit_skel); fexit_sleep_lskel__destroy(fexit_skel);
} }
...@@ -3,19 +3,19 @@ ...@@ -3,19 +3,19 @@
#include <test_progs.h> #include <test_progs.h>
#include "fexit_test.lskel.h" #include "fexit_test.lskel.h"
static int fexit_test(struct fexit_test *fexit_skel) static int fexit_test(struct fexit_test_lskel *fexit_skel)
{ {
int err, prog_fd, i; int err, prog_fd, i;
__u32 duration = 0, retval; __u32 duration = 0, retval;
int link_fd; int link_fd;
__u64 *result; __u64 *result;
err = fexit_test__attach(fexit_skel); err = fexit_test_lskel__attach(fexit_skel);
if (!ASSERT_OK(err, "fexit_attach")) if (!ASSERT_OK(err, "fexit_attach"))
return err; return err;
/* Check that already linked program can't be attached again. */ /* Check that already linked program can't be attached again. */
link_fd = fexit_test__test1__attach(fexit_skel); link_fd = fexit_test_lskel__test1__attach(fexit_skel);
if (!ASSERT_LT(link_fd, 0, "fexit_attach_link")) if (!ASSERT_LT(link_fd, 0, "fexit_attach_link"))
return -1; return -1;
...@@ -31,7 +31,7 @@ static int fexit_test(struct fexit_test *fexit_skel) ...@@ -31,7 +31,7 @@ static int fexit_test(struct fexit_test *fexit_skel)
return -1; return -1;
} }
fexit_test__detach(fexit_skel); fexit_test_lskel__detach(fexit_skel);
/* zero results for re-attach test */ /* zero results for re-attach test */
memset(fexit_skel->bss, 0, sizeof(*fexit_skel->bss)); memset(fexit_skel->bss, 0, sizeof(*fexit_skel->bss));
...@@ -40,10 +40,10 @@ static int fexit_test(struct fexit_test *fexit_skel) ...@@ -40,10 +40,10 @@ static int fexit_test(struct fexit_test *fexit_skel)
void test_fexit_test(void) void test_fexit_test(void)
{ {
struct fexit_test *fexit_skel = NULL; struct fexit_test_lskel *fexit_skel = NULL;
int err; int err;
fexit_skel = fexit_test__open_and_load(); fexit_skel = fexit_test_lskel__open_and_load();
if (!ASSERT_OK_PTR(fexit_skel, "fexit_skel_load")) if (!ASSERT_OK_PTR(fexit_skel, "fexit_skel_load"))
goto cleanup; goto cleanup;
...@@ -55,5 +55,5 @@ void test_fexit_test(void) ...@@ -55,5 +55,5 @@ void test_fexit_test(void)
ASSERT_OK(err, "fexit_second_attach"); ASSERT_OK(err, "fexit_second_attach");
cleanup: cleanup:
fexit_test__destroy(fexit_skel); fexit_test_lskel__destroy(fexit_skel);
} }
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
static void test_main(void) static void test_main(void)
{ {
struct kfunc_call_test *skel; struct kfunc_call_test_lskel *skel;
int prog_fd, retval, err; int prog_fd, retval, err;
skel = kfunc_call_test__open_and_load(); skel = kfunc_call_test_lskel__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel")) if (!ASSERT_OK_PTR(skel, "skel"))
return; return;
...@@ -26,7 +26,7 @@ static void test_main(void) ...@@ -26,7 +26,7 @@ static void test_main(void)
ASSERT_OK(err, "bpf_prog_test_run(test2)"); ASSERT_OK(err, "bpf_prog_test_run(test2)");
ASSERT_EQ(retval, 3, "test2-retval"); ASSERT_EQ(retval, 3, "test2-retval");
kfunc_call_test__destroy(skel); kfunc_call_test_lskel__destroy(skel);
} }
static void test_subprog(void) static void test_subprog(void)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "test_ksyms_btf.skel.h" #include "test_ksyms_btf.skel.h"
#include "test_ksyms_btf_null_check.skel.h" #include "test_ksyms_btf_null_check.skel.h"
#include "test_ksyms_weak.skel.h" #include "test_ksyms_weak.skel.h"
#include "test_ksyms_weak.lskel.h"
static int duration; static int duration;
...@@ -89,11 +90,11 @@ static void test_weak_syms(void) ...@@ -89,11 +90,11 @@ static void test_weak_syms(void)
int err; int err;
skel = test_ksyms_weak__open_and_load(); skel = test_ksyms_weak__open_and_load();
if (CHECK(!skel, "test_ksyms_weak__open_and_load", "failed\n")) if (!ASSERT_OK_PTR(skel, "test_ksyms_weak__open_and_load"))
return; return;
err = test_ksyms_weak__attach(skel); err = test_ksyms_weak__attach(skel);
if (CHECK(err, "test_ksyms_weak__attach", "skeleton attach failed: %d\n", err)) if (!ASSERT_OK(err, "test_ksyms_weak__attach"))
goto cleanup; goto cleanup;
/* trigger tracepoint */ /* trigger tracepoint */
...@@ -109,6 +110,33 @@ static void test_weak_syms(void) ...@@ -109,6 +110,33 @@ static void test_weak_syms(void)
test_ksyms_weak__destroy(skel); test_ksyms_weak__destroy(skel);
} }
static void test_weak_syms_lskel(void)
{
struct test_ksyms_weak_lskel *skel;
struct test_ksyms_weak_lskel__data *data;
int err;
skel = test_ksyms_weak_lskel__open_and_load();
if (!ASSERT_OK_PTR(skel, "test_ksyms_weak_lskel__open_and_load"))
return;
err = test_ksyms_weak_lskel__attach(skel);
if (!ASSERT_OK(err, "test_ksyms_weak_lskel__attach"))
goto cleanup;
/* trigger tracepoint */
usleep(1);
data = skel->data;
ASSERT_EQ(data->out__existing_typed, 0, "existing typed ksym");
ASSERT_NEQ(data->out__existing_typeless, -1, "existing typeless ksym");
ASSERT_EQ(data->out__non_existent_typeless, 0, "nonexistent typeless ksym");
ASSERT_EQ(data->out__non_existent_typed, 0, "nonexistent typed ksym");
cleanup:
test_ksyms_weak_lskel__destroy(skel);
}
void test_ksyms_btf(void) void test_ksyms_btf(void)
{ {
int percpu_datasec; int percpu_datasec;
...@@ -136,4 +164,7 @@ void test_ksyms_btf(void) ...@@ -136,4 +164,7 @@ void test_ksyms_btf(void)
if (test__start_subtest("weak_ksyms")) if (test__start_subtest("weak_ksyms"))
test_weak_syms(); test_weak_syms();
if (test__start_subtest("weak_ksyms_lskel"))
test_weak_syms_lskel();
} }
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
#include <test_progs.h> #include <test_progs.h>
#include <network_helpers.h> #include <network_helpers.h>
#include "test_ksyms_module.lskel.h" #include "test_ksyms_module.lskel.h"
#include "test_ksyms_module.skel.h"
void test_ksyms_module(void) void test_ksyms_module_lskel(void)
{ {
struct test_ksyms_module *skel; struct test_ksyms_module_lskel *skel;
int retval; int retval;
int err; int err;
...@@ -16,8 +17,8 @@ void test_ksyms_module(void) ...@@ -16,8 +17,8 @@ void test_ksyms_module(void)
return; return;
} }
skel = test_ksyms_module__open_and_load(); skel = test_ksyms_module_lskel__open_and_load();
if (!ASSERT_OK_PTR(skel, "test_ksyms_module__open_and_load")) if (!ASSERT_OK_PTR(skel, "test_ksyms_module_lskel__open_and_load"))
return; return;
err = bpf_prog_test_run(skel->progs.load.prog_fd, 1, &pkt_v4, sizeof(pkt_v4), err = bpf_prog_test_run(skel->progs.load.prog_fd, 1, &pkt_v4, sizeof(pkt_v4),
NULL, NULL, (__u32 *)&retval, NULL); NULL, NULL, (__u32 *)&retval, NULL);
...@@ -25,6 +26,37 @@ void test_ksyms_module(void) ...@@ -25,6 +26,37 @@ void test_ksyms_module(void)
goto cleanup; goto cleanup;
ASSERT_EQ(retval, 0, "retval"); ASSERT_EQ(retval, 0, "retval");
ASSERT_EQ(skel->bss->out_bpf_testmod_ksym, 42, "bpf_testmod_ksym"); ASSERT_EQ(skel->bss->out_bpf_testmod_ksym, 42, "bpf_testmod_ksym");
cleanup:
test_ksyms_module_lskel__destroy(skel);
}
void test_ksyms_module_libbpf(void)
{
struct test_ksyms_module *skel;
int retval, err;
if (!env.has_testmod) {
test__skip();
return;
}
skel = test_ksyms_module__open_and_load();
if (!ASSERT_OK_PTR(skel, "test_ksyms_module__open"))
return;
err = bpf_prog_test_run(bpf_program__fd(skel->progs.load), 1, &pkt_v4,
sizeof(pkt_v4), NULL, NULL, (__u32 *)&retval, NULL);
if (!ASSERT_OK(err, "bpf_prog_test_run"))
goto cleanup;
ASSERT_EQ(retval, 0, "retval");
ASSERT_EQ(skel->bss->out_bpf_testmod_ksym, 42, "bpf_testmod_ksym");
cleanup: cleanup:
test_ksyms_module__destroy(skel); test_ksyms_module__destroy(skel);
} }
void test_ksyms_module(void)
{
if (test__start_subtest("lskel"))
test_ksyms_module_lskel();
if (test__start_subtest("libbpf"))
test_ksyms_module_libbpf();
}
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include <network_helpers.h>
#include "test_ksyms_module.skel.h"
void test_ksyms_module_libbpf(void)
{
struct test_ksyms_module *skel;
int retval, err;
if (!env.has_testmod) {
test__skip();
return;
}
skel = test_ksyms_module__open_and_load();
if (!ASSERT_OK_PTR(skel, "test_ksyms_module__open"))
return;
err = bpf_prog_test_run(bpf_program__fd(skel->progs.load), 1, &pkt_v4,
sizeof(pkt_v4), NULL, NULL, (__u32 *)&retval, NULL);
if (!ASSERT_OK(err, "bpf_prog_test_run"))
goto cleanup;
ASSERT_EQ(retval, 0, "retval");
ASSERT_EQ(skel->bss->out_bpf_testmod_ksym, 42, "bpf_testmod_ksym");
cleanup:
test_ksyms_module__destroy(skel);
}
...@@ -58,7 +58,7 @@ static int process_sample(void *ctx, void *data, size_t len) ...@@ -58,7 +58,7 @@ static int process_sample(void *ctx, void *data, size_t len)
} }
} }
static struct test_ringbuf *skel; static struct test_ringbuf_lskel *skel;
static struct ring_buffer *ringbuf; static struct ring_buffer *ringbuf;
static void trigger_samples() static void trigger_samples()
...@@ -90,13 +90,13 @@ void test_ringbuf(void) ...@@ -90,13 +90,13 @@ void test_ringbuf(void)
int page_size = getpagesize(); int page_size = getpagesize();
void *mmap_ptr, *tmp_ptr; void *mmap_ptr, *tmp_ptr;
skel = test_ringbuf__open(); skel = test_ringbuf_lskel__open();
if (CHECK(!skel, "skel_open", "skeleton open failed\n")) if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
return; return;
skel->maps.ringbuf.max_entries = page_size; skel->maps.ringbuf.max_entries = page_size;
err = test_ringbuf__load(skel); err = test_ringbuf_lskel__load(skel);
if (CHECK(err != 0, "skel_load", "skeleton load failed\n")) if (CHECK(err != 0, "skel_load", "skeleton load failed\n"))
goto cleanup; goto cleanup;
...@@ -154,7 +154,7 @@ void test_ringbuf(void) ...@@ -154,7 +154,7 @@ void test_ringbuf(void)
if (CHECK(!ringbuf, "ringbuf_create", "failed to create ringbuf\n")) if (CHECK(!ringbuf, "ringbuf_create", "failed to create ringbuf\n"))
goto cleanup; goto cleanup;
err = test_ringbuf__attach(skel); err = test_ringbuf_lskel__attach(skel);
if (CHECK(err, "skel_attach", "skeleton attachment failed: %d\n", err)) if (CHECK(err, "skel_attach", "skeleton attachment failed: %d\n", err))
goto cleanup; goto cleanup;
...@@ -292,8 +292,8 @@ void test_ringbuf(void) ...@@ -292,8 +292,8 @@ void test_ringbuf(void)
CHECK(skel->bss->discarded != 1, "err_discarded", "exp %ld, got %ld\n", CHECK(skel->bss->discarded != 1, "err_discarded", "exp %ld, got %ld\n",
1L, skel->bss->discarded); 1L, skel->bss->discarded);
test_ringbuf__detach(skel); test_ringbuf_lskel__detach(skel);
cleanup: cleanup:
ring_buffer__free(ringbuf); ring_buffer__free(ringbuf);
test_ringbuf__destroy(skel); test_ringbuf_lskel__destroy(skel);
} }
...@@ -10,27 +10,27 @@ ...@@ -10,27 +10,27 @@
void serial_test_trace_printk(void) void serial_test_trace_printk(void)
{ {
struct trace_printk_lskel__bss *bss;
int err = 0, iter = 0, found = 0; int err = 0, iter = 0, found = 0;
struct trace_printk__bss *bss; struct trace_printk_lskel *skel;
struct trace_printk *skel;
char *buf = NULL; char *buf = NULL;
FILE *fp = NULL; FILE *fp = NULL;
size_t buflen; size_t buflen;
skel = trace_printk__open(); skel = trace_printk_lskel__open();
if (!ASSERT_OK_PTR(skel, "trace_printk__open")) if (!ASSERT_OK_PTR(skel, "trace_printk__open"))
return; return;
ASSERT_EQ(skel->rodata->fmt[0], 'T', "skel->rodata->fmt[0]"); ASSERT_EQ(skel->rodata->fmt[0], 'T', "skel->rodata->fmt[0]");
skel->rodata->fmt[0] = 't'; skel->rodata->fmt[0] = 't';
err = trace_printk__load(skel); err = trace_printk_lskel__load(skel);
if (!ASSERT_OK(err, "trace_printk__load")) if (!ASSERT_OK(err, "trace_printk__load"))
goto cleanup; goto cleanup;
bss = skel->bss; bss = skel->bss;
err = trace_printk__attach(skel); err = trace_printk_lskel__attach(skel);
if (!ASSERT_OK(err, "trace_printk__attach")) if (!ASSERT_OK(err, "trace_printk__attach"))
goto cleanup; goto cleanup;
...@@ -43,7 +43,7 @@ void serial_test_trace_printk(void) ...@@ -43,7 +43,7 @@ void serial_test_trace_printk(void)
/* wait for tracepoint to trigger */ /* wait for tracepoint to trigger */
usleep(1); usleep(1);
trace_printk__detach(skel); trace_printk_lskel__detach(skel);
if (!ASSERT_GT(bss->trace_printk_ran, 0, "bss->trace_printk_ran")) if (!ASSERT_GT(bss->trace_printk_ran, 0, "bss->trace_printk_ran"))
goto cleanup; goto cleanup;
...@@ -65,7 +65,7 @@ void serial_test_trace_printk(void) ...@@ -65,7 +65,7 @@ void serial_test_trace_printk(void)
goto cleanup; goto cleanup;
cleanup: cleanup:
trace_printk__destroy(skel); trace_printk_lskel__destroy(skel);
free(buf); free(buf);
if (fp) if (fp)
fclose(fp); fclose(fp);
......
...@@ -10,20 +10,20 @@ ...@@ -10,20 +10,20 @@
void serial_test_trace_vprintk(void) void serial_test_trace_vprintk(void)
{ {
struct trace_vprintk_lskel__bss *bss;
int err = 0, iter = 0, found = 0; int err = 0, iter = 0, found = 0;
struct trace_vprintk__bss *bss; struct trace_vprintk_lskel *skel;
struct trace_vprintk *skel;
char *buf = NULL; char *buf = NULL;
FILE *fp = NULL; FILE *fp = NULL;
size_t buflen; size_t buflen;
skel = trace_vprintk__open_and_load(); skel = trace_vprintk_lskel__open_and_load();
if (!ASSERT_OK_PTR(skel, "trace_vprintk__open_and_load")) if (!ASSERT_OK_PTR(skel, "trace_vprintk__open_and_load"))
goto cleanup; goto cleanup;
bss = skel->bss; bss = skel->bss;
err = trace_vprintk__attach(skel); err = trace_vprintk_lskel__attach(skel);
if (!ASSERT_OK(err, "trace_vprintk__attach")) if (!ASSERT_OK(err, "trace_vprintk__attach"))
goto cleanup; goto cleanup;
...@@ -36,7 +36,7 @@ void serial_test_trace_vprintk(void) ...@@ -36,7 +36,7 @@ void serial_test_trace_vprintk(void)
/* wait for tracepoint to trigger */ /* wait for tracepoint to trigger */
usleep(1); usleep(1);
trace_vprintk__detach(skel); trace_vprintk_lskel__detach(skel);
if (!ASSERT_GT(bss->trace_vprintk_ran, 0, "bss->trace_vprintk_ran")) if (!ASSERT_GT(bss->trace_vprintk_ran, 0, "bss->trace_vprintk_ran"))
goto cleanup; goto cleanup;
...@@ -61,7 +61,7 @@ void serial_test_trace_vprintk(void) ...@@ -61,7 +61,7 @@ void serial_test_trace_vprintk(void)
goto cleanup; goto cleanup;
cleanup: cleanup:
trace_vprintk__destroy(skel); trace_vprintk_lskel__destroy(skel);
free(buf); free(buf);
if (fp) if (fp)
fclose(fp); fclose(fp);
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
void test_verif_stats(void) void test_verif_stats(void)
{ {
__u32 len = sizeof(struct bpf_prog_info); __u32 len = sizeof(struct bpf_prog_info);
struct trace_vprintk_lskel *skel;
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
struct trace_vprintk *skel;
int err; int err;
skel = trace_vprintk__open_and_load(); skel = trace_vprintk_lskel__open_and_load();
if (!ASSERT_OK_PTR(skel, "trace_vprintk__open_and_load")) if (!ASSERT_OK_PTR(skel, "trace_vprintk__open_and_load"))
goto cleanup; goto cleanup;
...@@ -24,5 +24,5 @@ void test_verif_stats(void) ...@@ -24,5 +24,5 @@ void test_verif_stats(void)
goto cleanup; goto cleanup;
cleanup: cleanup:
trace_vprintk__destroy(skel); trace_vprintk_lskel__destroy(skel);
} }
...@@ -38,7 +38,7 @@ int pass_handler(const void *ctx) ...@@ -38,7 +38,7 @@ int pass_handler(const void *ctx)
/* tests existing symbols. */ /* tests existing symbols. */
rq = (struct rq *)bpf_per_cpu_ptr(&runqueues, 0); rq = (struct rq *)bpf_per_cpu_ptr(&runqueues, 0);
if (rq) if (rq)
out__existing_typed = rq->cpu; out__existing_typed = 0;
out__existing_typeless = (__u64)&bpf_prog_active; out__existing_typeless = (__u64)&bpf_prog_active;
/* tests non-existent symbols. */ /* tests non-existent symbols. */
......
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