netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bpf-next PATCH 0/2] bpf: test_sockmap updates
@ 2018-08-28 16:10 John Fastabend
  2018-08-28 16:10 ` [bpf-next PATCH 1/2] bpf: sockmap test remove shutdown() calls John Fastabend
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: John Fastabend @ 2018-08-28 16:10 UTC (permalink / raw)
  To: alexei.starovoitov, daniel; +Cc: netdev

Two small test sockmap updates for bpf-next. These help me run some
additional tests with test_sockmap.

---

John Fastabend (2):
      bpf: sockmap test remove shutdown() calls
      bpf: use --cgroup in test_suite if supplied


 tools/testing/selftests/bpf/test_sockmap.c |   56 ++++++++++++++++------------
 1 file changed, 31 insertions(+), 25 deletions(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [bpf-next PATCH 1/2] bpf: sockmap test remove shutdown() calls
  2018-08-28 16:10 [bpf-next PATCH 0/2] bpf: test_sockmap updates John Fastabend
@ 2018-08-28 16:10 ` John Fastabend
  2018-08-28 16:10 ` [bpf-next PATCH 2/2] bpf: use --cgroup in test_suite if supplied John Fastabend
  2018-08-29 15:38 ` [bpf-next PATCH 0/2] bpf: test_sockmap updates Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: John Fastabend @ 2018-08-28 16:10 UTC (permalink / raw)
  To: alexei.starovoitov, daniel; +Cc: netdev

Currently, we do a shutdown(sk, SHUT_RDWR) on both peer sockets and
a shutdown on the sender as well. However, this is incorrect and can
occasionally cause issues if you happen to have bad timing. First
peer1 or peer2 may still be in use depending on the test and timing.
Second we really should only be closing the read side and/or write
side depending on if the test is receiving or sending.

But, really none of this is needed just remove the shutdown calls.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 tools/testing/selftests/bpf/test_sockmap.c |    3 ---
 1 file changed, 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index 0c7d9e5..a0e77c6 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -469,8 +469,6 @@ static int sendmsg_test(struct sockmap_options *opt)
 			fprintf(stderr,
 				"msg_loop_rx: iov_count %i iov_buf %i cnt %i err %i\n",
 				iov_count, iov_buf, cnt, err);
-		shutdown(p2, SHUT_RDWR);
-		shutdown(p1, SHUT_RDWR);
 		if (s.end.tv_sec - s.start.tv_sec) {
 			sent_Bps = sentBps(s);
 			recvd_Bps = recvdBps(s);
@@ -500,7 +498,6 @@ static int sendmsg_test(struct sockmap_options *opt)
 			fprintf(stderr,
 				"msg_loop_tx: iov_count %i iov_buf %i cnt %i err %i\n",
 				iov_count, iov_buf, cnt, err);
-		shutdown(c1, SHUT_RDWR);
 		if (s.end.tv_sec - s.start.tv_sec) {
 			sent_Bps = sentBps(s);
 			recvd_Bps = recvdBps(s);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bpf-next PATCH 2/2] bpf: use --cgroup in test_suite if supplied
  2018-08-28 16:10 [bpf-next PATCH 0/2] bpf: test_sockmap updates John Fastabend
  2018-08-28 16:10 ` [bpf-next PATCH 1/2] bpf: sockmap test remove shutdown() calls John Fastabend
@ 2018-08-28 16:10 ` John Fastabend
  2018-08-29 15:38 ` [bpf-next PATCH 0/2] bpf: test_sockmap updates Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: John Fastabend @ 2018-08-28 16:10 UTC (permalink / raw)
  To: alexei.starovoitov, daniel; +Cc: netdev

If the user supplies a --cgroup value in the arguments when running
the test_suite go ahaead and run the self tests there. I use this
to test with multiple cgroup users.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 tools/testing/selftests/bpf/test_sockmap.c |   53 ++++++++++++++++------------
 1 file changed, 31 insertions(+), 22 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index a0e77c6..ac7de38 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -1345,9 +1345,9 @@ static int populate_progs(char *bpf_file)
 	return 0;
 }
 
-static int __test_suite(char *bpf_file)
+static int __test_suite(int cg_fd, char *bpf_file)
 {
-	int cg_fd, err;
+	int err, cleanup = cg_fd;
 
 	err = populate_progs(bpf_file);
 	if (err < 0) {
@@ -1355,22 +1355,24 @@ static int __test_suite(char *bpf_file)
 		return err;
 	}
 
-	if (setup_cgroup_environment()) {
-		fprintf(stderr, "ERROR: cgroup env failed\n");
-		return -EINVAL;
-	}
-
-	cg_fd = create_and_get_cgroup(CG_PATH);
 	if (cg_fd < 0) {
-		fprintf(stderr,
-			"ERROR: (%i) open cg path failed: %s\n",
-			cg_fd, optarg);
-		return cg_fd;
-	}
+		if (setup_cgroup_environment()) {
+			fprintf(stderr, "ERROR: cgroup env failed\n");
+			return -EINVAL;
+		}
+
+		cg_fd = create_and_get_cgroup(CG_PATH);
+		if (cg_fd < 0) {
+			fprintf(stderr,
+				"ERROR: (%i) open cg path failed: %s\n",
+				cg_fd, optarg);
+			return cg_fd;
+		}
 
-	if (join_cgroup(CG_PATH)) {
-		fprintf(stderr, "ERROR: failed to join cgroup\n");
-		return -EINVAL;
+		if (join_cgroup(CG_PATH)) {
+			fprintf(stderr, "ERROR: failed to join cgroup\n");
+			return -EINVAL;
+		}
 	}
 
 	/* Tests basic commands and APIs with range of iov values */
@@ -1391,20 +1393,24 @@ static int __test_suite(char *bpf_file)
 
 out:
 	printf("Summary: %i PASSED %i FAILED\n", passed, failed);
-	cleanup_cgroup_environment();
-	close(cg_fd);
+	if (cleanup < 0) {
+		cleanup_cgroup_environment();
+		close(cg_fd);
+	}
 	return err;
 }
 
-static int test_suite(void)
+static int test_suite(int cg_fd)
 {
 	int err;
 
-	err = __test_suite(BPF_SOCKMAP_FILENAME);
+	err = __test_suite(cg_fd, BPF_SOCKMAP_FILENAME);
 	if (err)
 		goto out;
-	err = __test_suite(BPF_SOCKHASH_FILENAME);
+	err = __test_suite(cg_fd, BPF_SOCKHASH_FILENAME);
 out:
+	if (cg_fd > -1)
+		close(cg_fd);
 	return err;
 }
 
@@ -1417,7 +1423,7 @@ int main(int argc, char **argv)
 	int test = PING_PONG;
 
 	if (argc < 2)
-		return test_suite();
+		return test_suite(-1);
 
 	while ((opt = getopt_long(argc, argv, ":dhvc:r:i:l:t:",
 				  long_options, &longindex)) != -1) {
@@ -1483,6 +1489,9 @@ int main(int argc, char **argv)
 		}
 	}
 
+	if (argc <= 3 && cg_fd)
+		return test_suite(cg_fd);
+
 	if (!cg_fd) {
 		fprintf(stderr, "%s requires cgroup option: --cgroup <path>\n",
 			argv[0]);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [bpf-next PATCH 0/2] bpf: test_sockmap updates
  2018-08-28 16:10 [bpf-next PATCH 0/2] bpf: test_sockmap updates John Fastabend
  2018-08-28 16:10 ` [bpf-next PATCH 1/2] bpf: sockmap test remove shutdown() calls John Fastabend
  2018-08-28 16:10 ` [bpf-next PATCH 2/2] bpf: use --cgroup in test_suite if supplied John Fastabend
@ 2018-08-29 15:38 ` Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2018-08-29 15:38 UTC (permalink / raw)
  To: John Fastabend, alexei.starovoitov; +Cc: netdev

On 08/28/2018 06:10 PM, John Fastabend wrote:
> Two small test sockmap updates for bpf-next. These help me run some
> additional tests with test_sockmap.

Applied to bpf-next, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-29 19:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-28 16:10 [bpf-next PATCH 0/2] bpf: test_sockmap updates John Fastabend
2018-08-28 16:10 ` [bpf-next PATCH 1/2] bpf: sockmap test remove shutdown() calls John Fastabend
2018-08-28 16:10 ` [bpf-next PATCH 2/2] bpf: use --cgroup in test_suite if supplied John Fastabend
2018-08-29 15:38 ` [bpf-next PATCH 0/2] bpf: test_sockmap updates Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).