From: Wang Yufen <wangyufen@huawei.com>
To: <andrii@kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
<martin.lau@linux.dev>, <song@kernel.org>, <yhs@fb.com>,
<john.fastabend@gmail.com>, <kpsingh@kernel.org>,
<sdf@google.com>, <haoluo@google.com>, <jolsa@kernel.org>,
<paul.walmsley@sifive.com>, <palmer@dabbelt.com>,
<aou@eecs.berkeley.edu>, <davem@davemloft.net>, <kuba@kernel.org>,
<hawk@kernel.org>, <nathan@kernel.org>, <ndesaulniers@google.com>,
<trix@redhat.com>
Cc: <bpf@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<netdev@vger.kernel.org>, <llvm@lists.linux.dev>
Subject: [bpf-next v2 2/2] selftests/bpf: Add testcases for pinning to errpath
Date: Fri, 16 Sep 2022 15:37:00 +0800 [thread overview]
Message-ID: <1663313820-29918-2-git-send-email-wangyufen@huawei.com> (raw)
In-Reply-To: <1663313820-29918-1-git-send-email-wangyufen@huawei.com>
Add testcases for map and prog pin to errpath.
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
---
tools/testing/selftests/bpf/prog_tests/pinning.c | 67 ++++++++++++++++++++++
.../selftests/bpf/progs/test_pinning_path.c | 19 ++++++
2 files changed, 86 insertions(+)
create mode 100644 tools/testing/selftests/bpf/progs/test_pinning_path.c
diff --git a/tools/testing/selftests/bpf/prog_tests/pinning.c b/tools/testing/selftests/bpf/prog_tests/pinning.c
index d95cee5..ab7780f 100644
--- a/tools/testing/selftests/bpf/prog_tests/pinning.c
+++ b/tools/testing/selftests/bpf/prog_tests/pinning.c
@@ -24,6 +24,61 @@ __u32 get_map_id(struct bpf_object *obj, const char *name)
return map_info.id;
}
+static void test_pin_path(void)
+{
+ const char *progfile = "./test_pinning_path.bpf.o";
+ const char *progpinpath = "/sys/fs/bpf/test_pinpath";
+ char errpath[PATH_MAX + 1];
+ char command[64];
+ int prog_fd, err;
+ struct bpf_object *obj;
+ __u32 duration = 0;
+
+ /* Use libbpf 1.0 API mode */
+ libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
+
+ err = bpf_prog_test_load(progfile, BPF_PROG_TYPE_SOCK_OPS, &obj,
+ &prog_fd);
+ CHECK(err, "bpf_prog_test_load", "err %d errno %d\n", err, errno);
+
+ memset(&errpath, 't', PATH_MAX);
+ err = bpf_object__pin_maps(obj, errpath);
+ if (CHECK(err != -ENAMETOOLONG, "pin maps errpath", "err %d errno %d\n", err, errno))
+ goto out;
+
+ err = bpf_object__pin_maps(obj, progpinpath);
+ if (CHECK(err, "pin maps", "err %d errno %d\n", err, errno))
+ goto out;
+
+ err = bpf_object__pin_programs(obj, errpath);
+ if (CHECK(err != -ENAMETOOLONG, "pin progs errpath", "err %d errno %d\n", err, errno))
+ goto out;
+
+ err = bpf_object__pin_programs(obj, progpinpath);
+ if (CHECK(err, "pin prog", "err %d errno %d\n", err, errno))
+ goto out;
+
+ err = bpf_object__unpin_programs(obj, errpath);
+ if (CHECK(err != -ENAMETOOLONG, "pin progs errpath", "err %d errno %d\n", err, errno))
+ goto out;
+
+ err = bpf_object__unpin_programs(obj, progpinpath);
+ if (CHECK(err, "pin prog", "err %d errno %d\n", err, errno))
+ goto out;
+
+ err = bpf_object__unpin_maps(obj, errpath);
+ if (CHECK(err != -ENAMETOOLONG, "pin maps errpath", "err %d errno %d\n", err, errno))
+ goto out;
+
+ err = bpf_object__unpin_maps(obj, progpinpath);
+ if (CHECK(err, "pin maps", "err %d errno %d\n", err, errno))
+ goto out;
+out:
+ bpf_object__close(obj);
+ sprintf(command, "rm -r %s", progpinpath);
+ system(command);
+}
+
void test_pinning(void)
{
const char *file_invalid = "./test_pinning_invalid.bpf.o";
@@ -32,6 +87,7 @@ void test_pinning(void)
const char *nopinpath2 = "/sys/fs/bpf/nopinmap2";
const char *custpath = "/sys/fs/bpf/custom";
const char *pinpath = "/sys/fs/bpf/pinmap";
+ char errpath[PATH_MAX + 1];
const char *file = "./test_pinning.bpf.o";
__u32 map_id, map_id2, duration = 0;
struct stat statbuf = {};
@@ -206,7 +262,17 @@ void test_pinning(void)
bpf_object__close(obj);
+ /* test auto-pinning at err path with open opt */
+ memset(&errpath, 't', PATH_MAX);
+ opts.pin_root_path = errpath;
+ obj = bpf_object__open_file(file, &opts);
+ if (CHECK_FAIL(libbpf_get_error(obj) != -ENAMETOOLONG)) {
+ obj = NULL;
+ goto out;
+ }
+
/* test auto-pinning at custom path with open opt */
+ opts.pin_root_path = custpath;
obj = bpf_object__open_file(file, &opts);
if (CHECK_FAIL(libbpf_get_error(obj))) {
obj = NULL;
@@ -277,4 +343,5 @@ void test_pinning(void)
rmdir(custpath);
if (obj)
bpf_object__close(obj);
+ test_pin_path();
}
diff --git a/tools/testing/selftests/bpf/progs/test_pinning_path.c b/tools/testing/selftests/bpf/progs/test_pinning_path.c
new file mode 100644
index 0000000..b4e2099
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_pinning_path.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+
+struct {
+ __uint(type, BPF_MAP_TYPE_SOCKHASH);
+ __uint(max_entries, 64);
+ __type(key, __u32);
+ __type(value, __u64);
+} sock_ops_map SEC(".maps");
+
+SEC("sockops")
+int bpf_sockmap(struct bpf_sock_ops *skops)
+{
+ return 0;
+}
+
+char _license[] SEC("license") = "GPL";
--
1.8.3.1
next prev parent reply other threads:[~2022-09-16 7:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-16 7:36 [bpf-next v2 1/2] libbpf: Add pathname_concat() helper Wang Yufen
2022-09-16 7:37 ` Wang Yufen [this message]
2022-09-16 15:53 ` Daniel Borkmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1663313820-29918-2-git-send-email-wangyufen@huawei.com \
--to=wangyufen@huawei.com \
--cc=andrii@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=haoluo@google.com \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=martin.lau@linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=trix@redhat.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox