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

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
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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 \
	test_ringbuf.c atomics.c trace_printk.c trace_vprintk.c
# 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)

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)
	$(Q)$$(BPFTOOL) gen object $$(<:.o=.linked2.o) $$(<:.o=.linked1.o)
	$(Q)$$(BPFTOOL) gen object $$(<:.o=.linked3.o) $$(<:.o=.linked2.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)
	$$(call msg,LINK-BPF,$(TRUNNER_BINARY),$$(@:.skel.h=.o))
+17 −17
Original line number Diff line number Diff line
@@ -4,13 +4,13 @@

#include "atomics.lskel.h"

static void test_add(struct atomics *skel)
static void test_add(struct atomics_lskel *skel)
{
	int err, prog_fd;
	__u32 duration = 0, retval;
	int link_fd;

	link_fd = atomics__add__attach(skel);
	link_fd = atomics_lskel__add__attach(skel);
	if (!ASSERT_GT(link_fd, 0, "attach(add)"))
		return;

@@ -36,13 +36,13 @@ static void test_add(struct atomics *skel)
	close(link_fd);
}

static void test_sub(struct atomics *skel)
static void test_sub(struct atomics_lskel *skel)
{
	int err, prog_fd;
	__u32 duration = 0, retval;
	int link_fd;

	link_fd = atomics__sub__attach(skel);
	link_fd = atomics_lskel__sub__attach(skel);
	if (!ASSERT_GT(link_fd, 0, "attach(sub)"))
		return;

@@ -69,13 +69,13 @@ static void test_sub(struct atomics *skel)
	close(link_fd);
}

static void test_and(struct atomics *skel)
static void test_and(struct atomics_lskel *skel)
{
	int err, prog_fd;
	__u32 duration = 0, retval;
	int link_fd;

	link_fd = atomics__and__attach(skel);
	link_fd = atomics_lskel__and__attach(skel);
	if (!ASSERT_GT(link_fd, 0, "attach(and)"))
		return;

@@ -97,13 +97,13 @@ static void test_and(struct atomics *skel)
	close(link_fd);
}

static void test_or(struct atomics *skel)
static void test_or(struct atomics_lskel *skel)
{
	int err, prog_fd;
	__u32 duration = 0, retval;
	int link_fd;

	link_fd = atomics__or__attach(skel);
	link_fd = atomics_lskel__or__attach(skel);
	if (!ASSERT_GT(link_fd, 0, "attach(or)"))
		return;

@@ -126,13 +126,13 @@ static void test_or(struct atomics *skel)
	close(link_fd);
}

static void test_xor(struct atomics *skel)
static void test_xor(struct atomics_lskel *skel)
{
	int err, prog_fd;
	__u32 duration = 0, retval;
	int link_fd;

	link_fd = atomics__xor__attach(skel);
	link_fd = atomics_lskel__xor__attach(skel);
	if (!ASSERT_GT(link_fd, 0, "attach(xor)"))
		return;

@@ -154,13 +154,13 @@ static void test_xor(struct atomics *skel)
	close(link_fd);
}

static void test_cmpxchg(struct atomics *skel)
static void test_cmpxchg(struct atomics_lskel *skel)
{
	int err, prog_fd;
	__u32 duration = 0, retval;
	int link_fd;

	link_fd = atomics__cmpxchg__attach(skel);
	link_fd = atomics_lskel__cmpxchg__attach(skel);
	if (!ASSERT_GT(link_fd, 0, "attach(cmpxchg)"))
		return;

@@ -183,13 +183,13 @@ static void test_cmpxchg(struct atomics *skel)
	close(link_fd);
}

static void test_xchg(struct atomics *skel)
static void test_xchg(struct atomics_lskel *skel)
{
	int err, prog_fd;
	__u32 duration = 0, retval;
	int link_fd;

	link_fd = atomics__xchg__attach(skel);
	link_fd = atomics_lskel__xchg__attach(skel);
	if (!ASSERT_GT(link_fd, 0, "attach(xchg)"))
		return;

@@ -212,10 +212,10 @@ static void test_xchg(struct atomics *skel)

void test_atomics(void)
{
	struct atomics *skel;
	struct atomics_lskel *skel;
	__u32 duration = 0;

	skel = atomics__open_and_load();
	skel = atomics_lskel__open_and_load();
	if (CHECK(!skel, "skel_load", "atomics skeleton failed\n"))
		return;

@@ -243,5 +243,5 @@ void test_atomics(void)
		test_xchg(skel);

cleanup:
	atomics__destroy(skel);
	atomics_lskel__destroy(skel);
}
+8 −8
Original line number Diff line number Diff line
@@ -6,23 +6,23 @@

void test_fentry_fexit(void)
{
	struct fentry_test *fentry_skel = NULL;
	struct fexit_test *fexit_skel = NULL;
	struct fentry_test_lskel *fentry_skel = NULL;
	struct fexit_test_lskel *fexit_skel = NULL;
	__u64 *fentry_res, *fexit_res;
	__u32 duration = 0, retval;
	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"))
		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"))
		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))
		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))
		goto close_prog;

@@ -44,6 +44,6 @@ void test_fentry_fexit(void)
	}

close_prog:
	fentry_test__destroy(fentry_skel);
	fexit_test__destroy(fexit_skel);
	fentry_test_lskel__destroy(fentry_skel);
	fexit_test_lskel__destroy(fexit_skel);
}
+7 −7
Original line number Diff line number Diff line
@@ -3,19 +3,19 @@
#include <test_progs.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;
	__u32 duration = 0, retval;
	int link_fd;
	__u64 *result;

	err = fentry_test__attach(fentry_skel);
	err = fentry_test_lskel__attach(fentry_skel);
	if (!ASSERT_OK(err, "fentry_attach"))
		return err;

	/* 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"))
		return -1;

@@ -31,7 +31,7 @@ static int fentry_test(struct fentry_test *fentry_skel)
			return -1;
	}

	fentry_test__detach(fentry_skel);
	fentry_test_lskel__detach(fentry_skel);

	/* zero results for re-attach test */
	memset(fentry_skel->bss, 0, sizeof(*fentry_skel->bss));
@@ -40,10 +40,10 @@ static int fentry_test(struct fentry_test *fentry_skel)

void test_fentry_test(void)
{
	struct fentry_test *fentry_skel = NULL;
	struct fentry_test_lskel *fentry_skel = NULL;
	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"))
		goto cleanup;

@@ -55,5 +55,5 @@ void test_fentry_test(void)
	ASSERT_OK(err, "fentry_second_attach");

cleanup:
	fentry_test__destroy(fentry_skel);
	fentry_test_lskel__destroy(fentry_skel);
}
+6 −6
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@

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 ts2 = { .tv_sec = 10 };

@@ -25,16 +25,16 @@ static char child_stack[STACK_SIZE];

void test_fexit_sleep(void)
{
	struct fexit_sleep *fexit_skel = NULL;
	struct fexit_sleep_lskel *fexit_skel = NULL;
	int wstatus, duration = 0;
	pid_t cpid;
	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"))
		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))
		goto cleanup;

@@ -60,7 +60,7 @@ void test_fexit_sleep(void)
	 */
	close(fexit_skel->progs.nanosleep_fentry.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(cpid, 9);
@@ -78,5 +78,5 @@ void test_fexit_sleep(void)
		goto cleanup;

cleanup:
	fexit_sleep__destroy(fexit_skel);
	fexit_sleep_lskel__destroy(fexit_skel);
}
Loading