From: Hangbin Liu <liuhangbin@gmail.com>
To: netdev@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Mykola Lysenko <mykolal@fb.com>,
Felix Maurer <fmaurer@redhat.com>,
Nicolas Rybowski <nicolas.rybowski@tessares.net>,
Hangbin Liu <liuhangbin@gmail.com>
Subject: [PATCH bpf] selftests/bpf: enable mptcp before testing
Date: Fri, 10 Feb 2023 17:32:05 +0800 [thread overview]
Message-ID: <20230210093205.1378597-1-liuhangbin@gmail.com> (raw)
Some distros may not enable mptcp by default. Enable it before start the
mptcp server. To use the {read/write}_int_sysctl() functions, I moved
them to test_progs.c
Fixes: 8039d353217c ("selftests/bpf: Add MPTCP test base")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
.../testing/selftests/bpf/prog_tests/mptcp.c | 15 ++++++-
.../bpf/prog_tests/select_reuseport.c | 43 -------------------
tools/testing/selftests/bpf/test_progs.c | 36 ++++++++++++++++
tools/testing/selftests/bpf/test_progs.h | 9 ++++
4 files changed, 59 insertions(+), 44 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index 59f08d6d1d53..c0a0ee7abd06 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -11,6 +11,8 @@
#define TCP_CA_NAME_MAX 16
#endif
+#define MPTCP_ENABLED_SYSCTL "/proc/sys/net/mptcp/enabled"
+
struct mptcp_storage {
__u32 invoked;
__u32 is_mptcp;
@@ -138,7 +140,7 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp)
static void test_base(void)
{
- int server_fd, cgroup_fd;
+ int server_fd, cgroup_fd, saved_mptcp_enabled = -1;
cgroup_fd = test__join_cgroup("/mptcp");
if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
@@ -155,6 +157,14 @@ static void test_base(void)
with_mptcp:
/* with MPTCP */
+ saved_mptcp_enabled = read_int_sysctl(MPTCP_ENABLED_SYSCTL);
+ if (saved_mptcp_enabled < 0)
+ goto close_cgroup_fd;
+
+ if (saved_mptcp_enabled == 0 &&
+ write_int_sysctl(MPTCP_ENABLED_SYSCTL, 1))
+ goto close_cgroup_fd;
+
server_fd = start_mptcp_server(AF_INET, NULL, 0, 0);
if (!ASSERT_GE(server_fd, 0, "start_mptcp_server"))
goto close_cgroup_fd;
@@ -164,6 +174,9 @@ static void test_base(void)
close(server_fd);
close_cgroup_fd:
+ if (saved_mptcp_enabled == 0)
+ write_int_sysctl(MPTCP_ENABLED_SYSCTL, saved_mptcp_enabled);
+
close(cgroup_fd);
}
diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
index 64c5f5eb2994..cdf9dd626877 100644
--- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
+++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
@@ -56,13 +56,6 @@ static union sa46 {
} \
})
-#define RET_ERR(condition, tag, format...) ({ \
- if (CHECK_FAIL(condition)) { \
- printf(tag " " format); \
- return -1; \
- } \
-})
-
static int create_maps(enum bpf_map_type inner_type)
{
LIBBPF_OPTS(bpf_map_create_opts, opts);
@@ -157,42 +150,6 @@ static void sa46_init_inany(union sa46 *sa, sa_family_t family)
sa->v4.sin_addr.s_addr = INADDR_ANY;
}
-static int read_int_sysctl(const char *sysctl)
-{
- char buf[16];
- int fd, ret;
-
- fd = open(sysctl, 0);
- RET_ERR(fd == -1, "open(sysctl)",
- "sysctl:%s fd:%d errno:%d\n", sysctl, fd, errno);
-
- ret = read(fd, buf, sizeof(buf));
- RET_ERR(ret <= 0, "read(sysctl)",
- "sysctl:%s ret:%d errno:%d\n", sysctl, ret, errno);
-
- close(fd);
- return atoi(buf);
-}
-
-static int write_int_sysctl(const char *sysctl, int v)
-{
- int fd, ret, size;
- char buf[16];
-
- fd = open(sysctl, O_RDWR);
- RET_ERR(fd == -1, "open(sysctl)",
- "sysctl:%s fd:%d errno:%d\n", sysctl, fd, errno);
-
- size = snprintf(buf, sizeof(buf), "%d", v);
- ret = write(fd, buf, size);
- RET_ERR(ret != size, "write(sysctl)",
- "sysctl:%s ret:%d size:%d errno:%d\n",
- sysctl, ret, size, errno);
-
- close(fd);
- return 0;
-}
-
static void restore_sysctls(void)
{
if (saved_tcp_fo != -1)
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 4716e38e153a..d50599ccba9a 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -967,6 +967,42 @@ int write_sysctl(const char *sysctl, const char *value)
return 0;
}
+int read_int_sysctl(const char *sysctl)
+{
+ char buf[16];
+ int fd, ret;
+
+ fd = open(sysctl, 0);
+ RET_ERR(fd == -1, "open(sysctl)",
+ "sysctl:%s fd:%d errno:%d\n", sysctl, fd, errno);
+
+ ret = read(fd, buf, sizeof(buf));
+ RET_ERR(ret <= 0, "read(sysctl)",
+ "sysctl:%s ret:%d errno:%d\n", sysctl, ret, errno);
+
+ close(fd);
+ return atoi(buf);
+}
+
+int write_int_sysctl(const char *sysctl, int v)
+{
+ int fd, ret, size;
+ char buf[16];
+
+ fd = open(sysctl, O_RDWR);
+ RET_ERR(fd == -1, "open(sysctl)",
+ "sysctl:%s fd:%d errno:%d\n", sysctl, fd, errno);
+
+ size = snprintf(buf, sizeof(buf), "%d", v);
+ ret = write(fd, buf, size);
+ RET_ERR(ret != size, "write(sysctl)",
+ "sysctl:%s ret:%d size:%d errno:%d\n",
+ sysctl, ret, size, errno);
+
+ close(fd);
+ return 0;
+}
+
#define MAX_BACKTRACE_SZ 128
void crash_handler(int signum)
{
diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h
index 3f058dfadbaf..1522ea930bf6 100644
--- a/tools/testing/selftests/bpf/test_progs.h
+++ b/tools/testing/selftests/bpf/test_progs.h
@@ -376,6 +376,13 @@ int test__join_cgroup(const char *path);
___ok; \
})
+#define RET_ERR(condition, tag, format...) ({ \
+ if (CHECK_FAIL(condition)) { \
+ printf(tag " " format); \
+ return -1; \
+ } \
+})
+
static inline __u64 ptr_to_u64(const void *ptr)
{
return (__u64) (unsigned long) ptr;
@@ -394,6 +401,8 @@ int kern_sync_rcu(void);
int trigger_module_test_read(int read_sz);
int trigger_module_test_write(int write_sz);
int write_sysctl(const char *sysctl, const char *value);
+int read_int_sysctl(const char *sysctl);
+int write_int_sysctl(const char *sysctl, int v);
#ifdef __x86_64__
#define SYS_NANOSLEEP_KPROBE_NAME "__x64_sys_nanosleep"
--
2.38.1
next reply other threads:[~2023-02-10 9:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 9:32 Hangbin Liu [this message]
2023-02-10 16:22 ` [PATCH bpf] selftests/bpf: enable mptcp before testing Matthieu Baerts
2023-02-13 4:10 ` Hangbin Liu
2023-02-13 16:28 ` Matthieu Baerts
2023-02-14 3:11 ` Hangbin Liu
2023-02-14 19:22 ` Martin KaFai Lau
2023-02-15 3:43 ` Hangbin Liu
2023-02-15 9:58 ` Matthieu Baerts
2023-02-16 8:13 ` Hangbin Liu
2023-02-17 7:04 ` Martin KaFai Lau
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=20230210093205.1378597-1-liuhangbin@gmail.com \
--to=liuhangbin@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=fmaurer@redhat.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.rybowski@tessares.net \
--cc=sdf@google.com \
--cc=song@kernel.org \
--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