BPF List
 help / color / mirror / Atom feed
From: Jakub Sitnicki <jakub@cloudflare.com>
To: bpf@vger.kernel.org
Cc: Martin Lau <kafai@fb.com>, kernel-team@cloudflare.com
Subject: [PATCH bpf-next 06/10] selftests/bpf: Run reuseport tests in a loop
Date: Thu, 12 Dec 2019 11:22:55 +0100	[thread overview]
Message-ID: <20191212102259.418536-7-jakub@cloudflare.com> (raw)
In-Reply-To: <20191212102259.418536-1-jakub@cloudflare.com>

Prepare for switching reuseport tests to test_progs framework. Loop over
the tests and perform setup/cleanup for each test separately, remembering
that with test_progs we can select tests to run.

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
---
 .../selftests/bpf/test_select_reuseport.c     | 55 ++++++++++++-------
 1 file changed, 34 insertions(+), 21 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_select_reuseport.c b/tools/testing/selftests/bpf/test_select_reuseport.c
index 63ce2e75e758..cfff958da570 100644
--- a/tools/testing/selftests/bpf/test_select_reuseport.c
+++ b/tools/testing/selftests/bpf/test_select_reuseport.c
@@ -643,7 +643,8 @@ static void prepare_sk_fds(int type, sa_family_t family, bool inany)
 	}
 }
 
-static void setup_per_test(int type, sa_family_t family, bool inany)
+static void setup_per_test(int type, sa_family_t family, bool inany,
+			   bool no_inner_map)
 {
 	int ovr = -1, err;
 
@@ -652,9 +653,18 @@ static void setup_per_test(int type, sa_family_t family, bool inany)
 				  BPF_ANY);
 	CHECK(err == -1, "update_elem(tmp_index_ovr_map, 0, -1)",
 	      "err:%d errno:%d\n", err, errno);
+
+	/* Install reuseport_array to outer_map? */
+	if (no_inner_map)
+		return;
+
+	err = bpf_map_update_elem(outer_map, &index_zero, &reuseport_array,
+				  BPF_ANY);
+	CHECK(err == -1, "update_elem(outer_map, 0, reuseport_array)",
+	      "err:%d errno:%d\n", err, errno);
 }
 
-static void cleanup_per_test(void)
+static void cleanup_per_test(bool no_inner_map)
 {
 	int i, err;
 
@@ -662,6 +672,10 @@ static void cleanup_per_test(void)
 		close(sk_fds[i]);
 	close(epfd);
 
+	/* Delete reuseport_array from outer_map? */
+	if (no_inner_map)
+		return;
+
 	err = bpf_map_delete_elem(outer_map, &index_zero);
 	CHECK(err == -1, "delete_elem(outer_map)",
 	      "err:%d errno:%d\n", err, errno);
@@ -700,31 +714,30 @@ static const char *sotype_str(int sotype)
 
 static void test_config(int type, sa_family_t family, bool inany)
 {
-	int err;
+	const struct test {
+		void (*fn)(int sotype, sa_family_t family);
+		bool no_inner_map;
+	} tests[] = {
+		{ test_err_inner_map, true /* no_inner_map */ },
+		{ test_err_skb_data },
+		{ test_err_sk_select_port },
+		{ test_pass },
+		{ test_syncookie },
+		{ test_pass_on_err },
+		{ test_detach_bpf },
+	};
+	const struct test *t;
 
 	printf("######## %s/%s %s ########\n",
 	       family_str(family), sotype_str(type),
 	       inany ? " INANY  " : "LOOPBACK");
 
-	setup_per_test(type, family, inany);
-
-	test_err_inner_map(type, family);
-
-	/* Install reuseport_array to the outer_map */
-	err = bpf_map_update_elem(outer_map, &index_zero,
-				  &reuseport_array, BPF_ANY);
-	CHECK(err == -1, "update_elem(outer_map)",
-	      "err:%d errno:%d\n", err, errno);
-
-	test_err_skb_data(type, family);
-	test_err_sk_select_port(type, family);
-	test_pass(type, family);
-	test_syncookie(type, family);
-	test_pass_on_err(type, family);
-	/* Must be the last test */
-	test_detach_bpf(type, family);
+	for (t = tests; t < tests + ARRAY_SIZE(tests); t++) {
+		setup_per_test(type, family, inany, t->no_inner_map);
+		t->fn(type, family);
+		cleanup_per_test(t->no_inner_map);
+	}
 
-	cleanup_per_test();
 	printf("\n");
 }
 
-- 
2.23.0


  parent reply	other threads:[~2019-12-12 10:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-12 10:22 [PATCH bpf-next 00/10] Switch reuseport tests for test_progs framework Jakub Sitnicki
2019-12-12 10:22 ` [PATCH bpf-next 01/10] libbpf: Recognize SK_REUSEPORT programs from section name Jakub Sitnicki
2019-12-12 10:22 ` [PATCH bpf-next 02/10] selftests/bpf: Let libbpf determine program type " Jakub Sitnicki
2019-12-12 10:22 ` [PATCH bpf-next 03/10] selftests/bpf: Use sa_family_t everywhere in reuseport tests Jakub Sitnicki
2019-12-12 10:22 ` [PATCH bpf-next 04/10] selftests/bpf: Add helpers for getting socket family & type name Jakub Sitnicki
2019-12-12 10:22 ` [PATCH bpf-next 05/10] selftests/bpf: Unroll the main loop in reuseport test Jakub Sitnicki
2019-12-12 10:22 ` Jakub Sitnicki [this message]
2019-12-12 10:22 ` [PATCH bpf-next 07/10] selftests/bpf: Propagate errors during setup for reuseport tests Jakub Sitnicki
2019-12-12 10:22 ` [PATCH bpf-next 08/10] selftests/bpf: Pull up printing the test name into test runner Jakub Sitnicki
2019-12-12 10:22 ` [PATCH bpf-next 09/10] selftests/bpf: Move reuseport tests under prog_tests/ Jakub Sitnicki
2019-12-12 10:22 ` [PATCH bpf-next 10/10] selftests/bpf: Switch reuseport tests for test_progs framework Jakub Sitnicki
2019-12-13  5:36 ` [PATCH bpf-next 00/10] " Alexei Starovoitov
2019-12-13 16:30   ` Martin Lau
2019-12-13 20:41     ` Alexei Starovoitov

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=20191212102259.418536-7-jakub@cloudflare.com \
    --to=jakub@cloudflare.com \
    --cc=bpf@vger.kernel.org \
    --cc=kafai@fb.com \
    --cc=kernel-team@cloudflare.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