mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Bastien Curutchet (eBPF Foundation)" <bastien.curutchet@bootlin.com>
To: Alexei Starovoitov <ast@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	 Martin KaFai Lau <martin.lau@linux.dev>,
	 Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	 Yonghong Song <yonghong.song@linux.dev>,
	 John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	 Stanislav Fomichev <sdf@fomichev.me>,
	Hao Luo <haoluo@google.com>,  Jiri Olsa <jolsa@kernel.org>,
	Mykola Lysenko <mykolal@fb.com>,  Shuah Khan <shuah@kernel.org>
Cc: Alexis Lothore <alexis.lothore@bootlin.com>,
	 Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	bpf@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	 "Bastien Curutchet (eBPF Foundation)"
	<bastien.curutchet@bootlin.com>
Subject: [PATCH bpf-next v2 2/4] selftests/bpf: Optionally open a dedicated namespace to run test in it
Date: Wed, 19 Feb 2025 15:53:01 +0100	[thread overview]
Message-ID: <20250219-b4-tc_links-v2-2-14504db136b7@bootlin.com> (raw)
In-Reply-To: <20250219-b4-tc_links-v2-0-14504db136b7@bootlin.com>

Some tests are serialized to prevent interference with others.

Open a dedicated network namespace when a test name starts with 'ns_' to
allow more test parallelization. Use the test name as namespace name to
avoid conflict between namespaces.

Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@bootlin.com>
---
 tools/testing/selftests/bpf/test_progs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index c9e745d49493e594b55d79ac26061b0466f9a039..0cb759632225d27ad8df7bc478bf1adb5651bf33 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -1365,10 +1365,19 @@ static int recv_message(int sock, struct msg *msg)
 	return ret;
 }
 
+static bool ns_is_needed(const char *test_name)
+{
+	if (strlen(test_name) < 3)
+		return false;
+
+	return !strncmp(test_name, "ns_", 3);
+}
+
 static void run_one_test(int test_num)
 {
 	struct prog_test_def *test = &prog_test_defs[test_num];
 	struct test_state *state = &test_states[test_num];
+	struct netns_obj *ns = NULL;
 
 	env.test = test;
 	env.test_state = state;
@@ -1376,10 +1385,13 @@ static void run_one_test(int test_num)
 	stdio_hijack(&state->log_buf, &state->log_cnt);
 
 	watchdog_start();
+	if (ns_is_needed(test->test_name))
+		ns = netns_new(test->test_name, true);
 	if (test->run_test)
 		test->run_test();
 	else if (test->run_serial_test)
 		test->run_serial_test();
+	netns_free(ns);
 	watchdog_stop();
 
 	/* ensure last sub-test is finalized properly */

-- 
2.48.1


  parent reply	other threads:[~2025-02-19 14:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-19 14:52 [PATCH bpf-next v2 0/4] selftests/bpf: tc_links/tc_opts: Unserialize tests Bastien Curutchet (eBPF Foundation)
2025-02-19 14:53 ` [PATCH bpf-next v2 1/4] selftests/bpf: ns_current_pid_tgid: Rename the test function Bastien Curutchet (eBPF Foundation)
2025-02-19 14:53 ` Bastien Curutchet (eBPF Foundation) [this message]
2025-02-19 14:53 ` [PATCH bpf-next v2 3/4] selftests/bpf: tc_links/tc_opts: Unserialize tests Bastien Curutchet (eBPF Foundation)
2025-02-19 14:53 ` [PATCH bpf-next v2 4/4] selftests/bpf: ns_current_pid_tgid: Use test_progs's ns_ feature Bastien Curutchet (eBPF Foundation)
2025-02-19 16:05 ` [PATCH bpf-next v2 0/4] selftests/bpf: tc_links/tc_opts: Unserialize tests Stanislav Fomichev
2025-02-19 18:00 ` patchwork-bot+netdevbpf

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=20250219-b4-tc_links-v2-2-14504db136b7@bootlin.com \
    --to=bastien.curutchet@bootlin.com \
    --cc=alexis.lothore@bootlin.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=yonghong.song@linux.dev \
    /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

all inboxes | Powered by JetHome®