selftests/bpf: Convert atomics test to light skeleton.
authorAlexei Starovoitov <ast@kernel.org>
Fri, 14 May 2021 00:36:21 +0000 (17:36 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 18 May 2021 22:41:56 +0000 (00:41 +0200)
Convert prog_tests/atomics.c to lskel.h

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210514003623.28033-20-alexei.starovoitov@gmail.com
tools/testing/selftests/bpf/Makefile
tools/testing/selftests/bpf/prog_tests/atomics.c

index fdc7785ff82d7f8f0162f4d8c54d58b0b6be436a..b29862339222bcad2af8f882da86b090d91bf0cc 100644 (file)
@@ -313,7 +313,7 @@ LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h               \
                linked_vars.skel.h linked_maps.skel.h
 
 LSKELS := kfunc_call_test.c fentry_test.c fexit_test.c fexit_sleep.c \
-       test_ksyms_module.c test_ringbuf.c
+       test_ksyms_module.c test_ringbuf.c atomics.c
 SKEL_BLACKLIST += $$(LSKELS)
 
 test_static_linked.skel.h-deps := test_static_linked1.o test_static_linked2.o
index 21efe7bbf10d2fc22adb4d51df49619a9cee353e..ba0e1efe5a45fe434db300add468addc203f8093 100644 (file)
@@ -2,19 +2,19 @@
 
 #include <test_progs.h>
 
-#include "atomics.skel.h"
+#include "atomics.lskel.h"
 
 static void test_add(struct atomics *skel)
 {
        int err, prog_fd;
        __u32 duration = 0, retval;
-       struct bpf_link *link;
+       int link_fd;
 
-       link = bpf_program__attach(skel->progs.add);
-       if (CHECK(IS_ERR(link), "attach(add)", "err: %ld\n", PTR_ERR(link)))
+       link_fd = atomics__add__attach(skel);
+       if (!ASSERT_GT(link_fd, 0, "attach(add)"))
                return;
 
-       prog_fd = bpf_program__fd(skel->progs.add);
+       prog_fd = skel->progs.add.prog_fd;
        err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
                                NULL, NULL, &retval, &duration);
        if (CHECK(err || retval, "test_run add",
@@ -33,20 +33,20 @@ static void test_add(struct atomics *skel)
        ASSERT_EQ(skel->data->add_noreturn_value, 3, "add_noreturn_value");
 
 cleanup:
-       bpf_link__destroy(link);
+       close(link_fd);
 }
 
 static void test_sub(struct atomics *skel)
 {
        int err, prog_fd;
        __u32 duration = 0, retval;
-       struct bpf_link *link;
+       int link_fd;
 
-       link = bpf_program__attach(skel->progs.sub);
-       if (CHECK(IS_ERR(link), "attach(sub)", "err: %ld\n", PTR_ERR(link)))
+       link_fd = atomics__sub__attach(skel);
+       if (!ASSERT_GT(link_fd, 0, "attach(sub)"))
                return;
 
-       prog_fd = bpf_program__fd(skel->progs.sub);
+       prog_fd = skel->progs.sub.prog_fd;
        err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
                                NULL, NULL, &retval, &duration);
        if (CHECK(err || retval, "test_run sub",
@@ -66,20 +66,20 @@ static void test_sub(struct atomics *skel)
        ASSERT_EQ(skel->data->sub_noreturn_value, -1, "sub_noreturn_value");
 
 cleanup:
-       bpf_link__destroy(link);
+       close(link_fd);
 }
 
 static void test_and(struct atomics *skel)
 {
        int err, prog_fd;
        __u32 duration = 0, retval;
-       struct bpf_link *link;
+       int link_fd;
 
-       link = bpf_program__attach(skel->progs.and);
-       if (CHECK(IS_ERR(link), "attach(and)", "err: %ld\n", PTR_ERR(link)))
+       link_fd = atomics__and__attach(skel);
+       if (!ASSERT_GT(link_fd, 0, "attach(and)"))
                return;
 
-       prog_fd = bpf_program__fd(skel->progs.and);
+       prog_fd = skel->progs.and.prog_fd;
        err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
                                NULL, NULL, &retval, &duration);
        if (CHECK(err || retval, "test_run and",
@@ -94,20 +94,20 @@ static void test_and(struct atomics *skel)
 
        ASSERT_EQ(skel->data->and_noreturn_value, 0x010ull << 32, "and_noreturn_value");
 cleanup:
-       bpf_link__destroy(link);
+       close(link_fd);
 }
 
 static void test_or(struct atomics *skel)
 {
        int err, prog_fd;
        __u32 duration = 0, retval;
-       struct bpf_link *link;
+       int link_fd;
 
-       link = bpf_program__attach(skel->progs.or);
-       if (CHECK(IS_ERR(link), "attach(or)", "err: %ld\n", PTR_ERR(link)))
+       link_fd = atomics__or__attach(skel);
+       if (!ASSERT_GT(link_fd, 0, "attach(or)"))
                return;
 
-       prog_fd = bpf_program__fd(skel->progs.or);
+       prog_fd = skel->progs.or.prog_fd;
        err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
                                NULL, NULL, &retval, &duration);
        if (CHECK(err || retval, "test_run or",
@@ -123,20 +123,20 @@ static void test_or(struct atomics *skel)
 
        ASSERT_EQ(skel->data->or_noreturn_value, 0x111ull << 32, "or_noreturn_value");
 cleanup:
-       bpf_link__destroy(link);
+       close(link_fd);
 }
 
 static void test_xor(struct atomics *skel)
 {
        int err, prog_fd;
        __u32 duration = 0, retval;
-       struct bpf_link *link;
+       int link_fd;
 
-       link = bpf_program__attach(skel->progs.xor);
-       if (CHECK(IS_ERR(link), "attach(xor)", "err: %ld\n", PTR_ERR(link)))
+       link_fd = atomics__xor__attach(skel);
+       if (!ASSERT_GT(link_fd, 0, "attach(xor)"))
                return;
 
-       prog_fd = bpf_program__fd(skel->progs.xor);
+       prog_fd = skel->progs.xor.prog_fd;
        err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
                                NULL, NULL, &retval, &duration);
        if (CHECK(err || retval, "test_run xor",
@@ -151,20 +151,20 @@ static void test_xor(struct atomics *skel)
 
        ASSERT_EQ(skel->data->xor_noreturn_value, 0x101ull << 32, "xor_nxoreturn_value");
 cleanup:
-       bpf_link__destroy(link);
+       close(link_fd);
 }
 
 static void test_cmpxchg(struct atomics *skel)
 {
        int err, prog_fd;
        __u32 duration = 0, retval;
-       struct bpf_link *link;
+       int link_fd;
 
-       link = bpf_program__attach(skel->progs.cmpxchg);
-       if (CHECK(IS_ERR(link), "attach(cmpxchg)", "err: %ld\n", PTR_ERR(link)))
+       link_fd = atomics__cmpxchg__attach(skel);
+       if (!ASSERT_GT(link_fd, 0, "attach(cmpxchg)"))
                return;
 
-       prog_fd = bpf_program__fd(skel->progs.cmpxchg);
+       prog_fd = skel->progs.cmpxchg.prog_fd;
        err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
                                NULL, NULL, &retval, &duration);
        if (CHECK(err || retval, "test_run add",
@@ -180,20 +180,20 @@ static void test_cmpxchg(struct atomics *skel)
        ASSERT_EQ(skel->bss->cmpxchg32_result_succeed, 1, "cmpxchg_result_succeed");
 
 cleanup:
-       bpf_link__destroy(link);
+       close(link_fd);
 }
 
 static void test_xchg(struct atomics *skel)
 {
        int err, prog_fd;
        __u32 duration = 0, retval;
-       struct bpf_link *link;
+       int link_fd;
 
-       link = bpf_program__attach(skel->progs.xchg);
-       if (CHECK(IS_ERR(link), "attach(xchg)", "err: %ld\n", PTR_ERR(link)))
+       link_fd = atomics__xchg__attach(skel);
+       if (!ASSERT_GT(link_fd, 0, "attach(xchg)"))
                return;
 
-       prog_fd = bpf_program__fd(skel->progs.xchg);
+       prog_fd = skel->progs.xchg.prog_fd;
        err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
                                NULL, NULL, &retval, &duration);
        if (CHECK(err || retval, "test_run add",
@@ -207,7 +207,7 @@ static void test_xchg(struct atomics *skel)
        ASSERT_EQ(skel->bss->xchg32_result, 1, "xchg32_result");
 
 cleanup:
-       bpf_link__destroy(link);
+       close(link_fd);
 }
 
 void test_atomics(void)