transition sockmap testing to test_progs
Subsystems (5)
v2 cover transition sockmap testing to test_progs
Its much easier to write and read tests than it was when sockmap was originally created. At that time we created a test_sockmap prog that did sockmap tests. But, its showing its age now. For example it reads user vars out of maps, is hard to run targetted tests, has a different format from the familiar test_progs and so on.
I recently thought there was an issue with pop helpers so I created some tests to try and track it down. It turns out it was a bug in the BPF program we had not the kernel. But, I think it makes sense to start deprecating test_sockmap and converting these to the nicer test_progs.
So this is a first round of test_prog tests for sockmap cork and pop helpers. I'll add push and pull tests shortly. I think its fine, maybe preferred to review smaller patchsets, to send these incrementally as I get them created.
Thanks!
v2: fix unint vars in some branches from make RELEASE=1
John Fastabend (4):
bpf: sockmap, add test for sk_msg prog pop msg helper
bpf: sockmap, add a sendmsg test so we can check that path
bpf: sockmap, add a cork to force buffering of the scatterlist
bpf: sockmap test cork and pop combined
.../bpf/prog_tests/sockmap_helpers.h | 18 + .../bpf/prog_tests/sockmap_msg_helpers.c | 353 ++++++++++++++++++ .../bpf/progs/test_sockmap_msg_helpers.c | 67 ++++ 3 files changed, 438 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c
Signature · 1 line
2.33.0
PATCH v2 1/4 bpf: sockmap, add test for sk_msg prog pop msg helper
For msg_pop sk_msg helpers we only have older tests in test_sockmap, but these are showing their age. They don't use any of the newer style BPF and also require running test_sockmap. Lets use the prog_test framework and add a test for msg_pop.
This is a much nicer test env using newer style BPF. We can extend this to support all the other helpers shortly.
The bpf program is a template that lets us run through all the helpers so we can cover not just pop, but all the other helpers as well.
--- .../bpf/prog_tests/sockmap_helpers.h | 10 + .../bpf/prog_tests/sockmap_msg_helpers.c | 210 ++++++++++++++++++ .../bpf/progs/test_sockmap_msg_helpers.c | 52 +++++ 3 files changed, 272 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c
tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h +10 -0
@@ -112,6 +112,16 @@ __ret; \ }) +#define xrecv_nonblock (fd, buf, len, flags) \ + ({ \ + ssize_t __ret = recv_timeout((fd), (buf), (len), (flags), \ + IO_TIMEOUT_SEC); \ + if (__ret == -1) \ + FAIL_ERRNO("recv"); \ + __ret; \ + }) + +#define xsocket (family, sotype, flags) \ ({ \ int __ret = socket(family, sotype, flags); \
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c new file +210 -0
210 lines not on this page · raw message
tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.33.0
Re: [PATCH bpf-next v2 1/4] bpf: sockmap, add test for sk_msg prog pop msg helper
Quoted 20 lines · John Fastabend
For
msg_popsk_msghelpers we only have older tests intest_sockmap, but these are showing their age. They don't use any of the newer style BPF and also require runningtest_sockmap. Lets use theprog_testframework and add a test formsg_pop.This is a much nicer test env using newer style BPF. We can extend this to support all the other helpers shortly.
The bpf program is a template that lets us run through all the helpers so we can cover not just pop, but all the other helpers as well.
Signed-off-by John Fastabend <[email protected]>--- .../bpf/prog_tests/sockmap_helpers.h | 10 + .../bpf/prog_tests/sockmap_msg_helpers.c | 210 ++++++++++++++++++ .../bpf/progs/test_sockmap_msg_helpers.c | 52 +++++ 3 files changed, 272 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c
[...]
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c line 2
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c new file +2
-0@@ -0,0 +1,210 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Cloudflare
Thanks, but we can't take the credit for this brand new file ;-)
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c line 14
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c new file +12
-0+#include <error.h> +#include <netinet/tcp.h> +#include <sys/epoll.h> + +#include "test_progs.h" +#include "test_sockmap_msg_helpers.skel.h" +#include "sockmap_helpers.h" + +#define TCP_REPAIR 19/* TCP sock is under repair right now */ + +#define TCP_REPAIR_ON 1 +#define TCP_REPAIR_OFF_NO_WP -1/* Turn off without window probes */
These defines are not unused by this module. Copy-pasted by mistake?
[...]
tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c line 2
Quoted 8 lines
tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c new file +2
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Cloudflare
^ :-)
[...]
Re: [PATCH bpf-next v2 1/4] bpf: sockmap, add test for sk_msg prog pop msg helper
Quoted 24 lines · Jakub Sitnicki
Quoted 20 lines · John Fastabend
For
msg_popsk_msghelpers we only have older tests intest_sockmap, but these are showing their age. They don't use any of the newer style BPF and also require runningtest_sockmap. Lets use theprog_testframework and add a test formsg_pop.This is a much nicer test env using newer style BPF. We can extend this to support all the other helpers shortly.
The bpf program is a template that lets us run through all the helpers so we can cover not just pop, but all the other helpers as well.
Signed-off-by John Fastabend <[email protected]>--- .../bpf/prog_tests/sockmap_helpers.h | 10 + .../bpf/prog_tests/sockmap_msg_helpers.c | 210 ++++++++++++++++++ .../bpf/progs/test_sockmap_msg_helpers.c | 52 +++++ 3 files changed, 272 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c[...]
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c line 2
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c new file +2
-0@@ -0,0 +1,210 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Cloudflare Thanks, but we can't take the credit for this brand new file ;-)
Ah yep seems I cut'n'pasted it from one of your files. I'll update it.
Quoted 15 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c line 14
Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c new file +12
-0+#include <error.h> +#include <netinet/tcp.h> +#include <sys/epoll.h> + +#include "test_progs.h" +#include "test_sockmap_msg_helpers.skel.h" +#include "sockmap_helpers.h" + +#define TCP_REPAIR 19/* TCP sock is under repair right now */ + +#define TCP_REPAIR_ON 1 +#define TCP_REPAIR_OFF_NO_WP -1/* Turn off without window probes */ These defines are not unused by this module. Copy-pasted by mistake?
Yep first iteration I used these will drop them. Thanks.
Quoted 15 lines
[...]
tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c line 2
Quoted 8 lines
tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c new file +2
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Cloudflare ^ :-)
[...]
PATCH v2 2/4 bpf: sockmap, add a sendmsg test so we can check that path
In reply to John FastabendSendmsg path with multiple buffers is slightly different from a single send in how we have to handle and walk the sg when doing pops. Lets ensure this walk is correct.
--- .../bpf/prog_tests/sockmap_helpers.h | 8 +++ .../bpf/prog_tests/sockmap_msg_helpers.c | 53 +++++++++++++++++++ 2 files changed, 61 insertions(+)
tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h +8 -0
@@ -103,6 +103,14 @@ __ret; \ }) +#define xsendmsg (fd, msg, flags) \ + ({ \ + ssize_t __ret = sendmsg((fd), (msg), (flags)); \ + if (__ret == -1) \ + FAIL_ERRNO("sendmsg"); \ + __ret; \ + }) +#define xrecv_nonblock (fd, buf, len, flags) \ ({ \ ssize_t __ret = recv_timeout((fd), (buf), (len), (flags), \
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +53 -0
65 lines not on this page · raw message
Signature · 1 line
2.33.0
Re: [PATCH bpf-next v2 2/4] bpf: sockmap, add a sendmsg test so we can check that path
Quoted 38 lines · John Fastabend
Sendmsg path with multiple buffers is slightly different from a single send in how we have to handle and walk the sg when doing pops. Lets ensure this walk is correct.
Signed-off-by John Fastabend <[email protected]>--- .../bpf/prog_tests/sockmap_helpers.h | 8 +++ .../bpf/prog_tests/sockmap_msg_helpers.c | 53 +++++++++++++++++++ 2 files changed, 61 insertions(+)tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h +8
-0@@ -103,6 +103,14 @@ __ret; \ }) +#define xsendmsg (fd, msg, flags) \ + ({ \ + ssize_t __ret = sendmsg((fd), (msg), (flags)); \ + if (__ret == -1) \ + FAIL_ERRNO("sendmsg"); \ + __ret; \ + }) +#define xrecv_nonblock (fd, buf, len, flags) \ ({ \ ssize_t __ret = recv_timeout((fd), (buf), (len), (flags), \tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +1
-0@@ -52,6 +52,50 @@ static void pop_simple_send(struct msg_test_opts *opts, int start, int len)ASSERT_OK (cmp,"pop cmp end bytes failed" ); } +static void pop_complex_send (struct msg_test_opts *opts,int start,int len)
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c static void pop_simple_send(struct msg_test_opts *opts, int start, int len) · line 65
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +10
-0+{ +struct test_sockmap_msg_helpers *skel = opts->skel; +char buf[] ="abcdefghijklmnopqrstuvwxyz" ; +size_t sent, recv, total =0 ; +struct msghdr msg = {0 }; +struct iovec iov[15 ]; +char *recvbuf; +int i; + +for (i =0 ; i <15 ; i++) {
Always nice to use ARRAY_SIZE.
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c static void pop_simple_send(struct msg_test_opts *opts, int start, int len) · line 73
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +8
-0+ iov[i].iov_base = buf; + iov[i].iov_len =sizeof (buf); + total +=sizeof (buf); + } + + recvbuf =malloc (total); +if (!recvbuf) +FAIL ("pop complex send malloc failure\n" );
390 bytes, why not have it on stack?
Quoted 30 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +25
-0+ + msg.msg_iov = iov; + msg.msg_iovlen =15 ; + + skel->bss->pop = true; + +if (start ==-1 ) + start =sizeof (buf) - len -1 ; + + skel->bss->pop_start = start; + skel->bss->pop_len = len; + + sent =xsendmsg (opts->client, &msg,0 ); +if (sent != total) +FAIL ("xsend failed" ); + +ASSERT_OK (skel->bss->err,"pop error" ); + + recv =xrecv_nonblock (opts->server, recvbuf, total,0 ); +if (recv != sent - skel->bss->pop_len) +FAIL ("Received incorrect number number of bytes after pop" ); + +free (recvbuf); +} +static void test_sockmap_pop (void ) {struct msg_test_opts opts;@@ -92,6 +136,15 @@ static void test_sockmap_pop(void)/* Pop from end */
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c static void test_sockmap_pop(void) · line 146
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +8
-0pop_simple_send (&opts,POP_END ,5 ); +/* Empty pop from start of sendmsg */ +pop_complex_send (&opts,0 ,0 ); +/* Pop from start of sendmsg */ +pop_complex_send (&opts,0 ,10 ); +/* Pop from middle of sendmsg */ +pop_complex_send (&opts,100 ,10 ); +/* Pop from end of sendmsg */ +pop_complex_send (&opts,394 ,10 );
Isn't the start offset here past the end? 15*26=390?
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +1
-0+ close_sockets:close (client);close (server);
Re: [PATCH bpf-next v2 2/4] bpf: sockmap, add a sendmsg test so we can check that path
Quoted 1 line · Jakub Sitnicki
On Wed, Jan 24, 2024 at 10:54 AM -08, John Fastabend wrote:
[...]
Quoted 4 lines
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +0
-0@@ -92,6 +136,15 @@ static void test_sockmap_pop(void)/* Pop from end */ pop_simple_send (&opts,POP_END ,5 );
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c static void test_sockmap_pop(void) · line 146
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +8
-0+/* Empty pop from start of sendmsg */ +pop_complex_send (&opts,0 ,0 ); +/* Pop from start of sendmsg */ +pop_complex_send (&opts,0 ,10 ); +/* Pop from middle of sendmsg */ +pop_complex_send (&opts,100 ,10 ); +/* Pop from end of sendmsg */ +pop_complex_send (&opts,394 ,10 );Isn't the start offset here past the end? 15*26=390?
Plus terminating null bytes. Nevermind. I can't count.
Re: [PATCH bpf-next v2 2/4] bpf: sockmap, add a sendmsg test so we can check that path
In reply to Jakub SitnickiQuoted 38 lines · Jakub Sitnicki
Quoted 37 lines · John Fastabend
Sendmsg path with multiple buffers is slightly different from a single send in how we have to handle and walk the sg when doing pops. Lets ensure this walk is correct.
Signed-off-by John Fastabend <[email protected]>--- .../bpf/prog_tests/sockmap_helpers.h | 8 +++ .../bpf/prog_tests/sockmap_msg_helpers.c | 53 +++++++++++++++++++ 2 files changed, 61 insertions(+)tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h +8
-0@@ -103,6 +103,14 @@ __ret; \ }) +#define xsendmsg (fd, msg, flags) \ + ({ \ + ssize_t __ret = sendmsg((fd), (msg), (flags)); \ + if (__ret == -1) \ + FAIL_ERRNO("sendmsg"); \ + __ret; \ + }) +#define xrecv_nonblock (fd, buf, len, flags) \ ({ \ ssize_t __ret = recv_timeout((fd), (buf), (len), (flags), \tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +0
-0@@ -52,6 +52,50 @@ static void pop_simple_send(struct msg_test_opts *opts, int start, int len)ASSERT_OK (cmp,"pop cmp end bytes failed" ); }
Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c static void pop_simple_send(struct msg_test_opts *opts, int start, int len) · line 65
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +11
-0+static void pop_complex_send (struct msg_test_opts *opts,int start,int len) +{ +struct test_sockmap_msg_helpers *skel = opts->skel; +char buf[] ="abcdefghijklmnopqrstuvwxyz" ; +size_t sent, recv, total =0 ; +struct msghdr msg = {0 }; +struct iovec iov[15 ]; +char *recvbuf; +int i; + +for (i =0 ; i <15 ; i++) {Always nice to use
ARRAY_SIZE.
Agree will do.
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c static void pop_simple_send(struct msg_test_opts *opts, int start, int len) · line 73
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +8
-0+ iov[i].iov_base = buf; + iov[i].iov_len =sizeof (buf); + total +=sizeof (buf); + } + + recvbuf =malloc (total); +if (!recvbuf) +FAIL ("pop complex send malloc failure\n" );390 bytes, why not have it on stack?
Sure one less thing that could fail seems like a win.
PATCH v2 3/4 bpf: sockmap, add a cork to force buffering of the scatterlist
In reply to John FastabendBy using cork we can force multiple sends into a single scatterlist and test that first the cork gives us the correct number of bytes, but then also test the pop over the corked data.
--- .../bpf/prog_tests/sockmap_msg_helpers.c | 81 +++++++++++++++++++ .../bpf/progs/test_sockmap_msg_helpers.c | 3 + 2 files changed, 84 insertions(+)
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +81 -0
@@ -21,6 +21,85 @@ struct msg_test_opts {#define POP_END -1 +static void cork_send (struct msg_test_opts *opts,int cork) +{ +struct test_sockmap_msg_helpers *skel = opts->skel; +char buf[] ="abcdefghijklmnopqrstuvwxyz" ; +size_t sent, total =0 , recv; +char *recvbuf; +int i; + + skel->bss->pop = false; + skel->bss->cork = cork; + +/* Send N bytes in 27B chunks */ +for (i =0 ; i < cork /sizeof (buf); i++) { + sent =xsend (opts->client, buf,sizeof (buf),0 ); +if (sent <sizeof (buf)) +FAIL ("xsend failed" ); + total += sent; + } + + recvbuf =malloc (total); +if (!recvbuf) +FAIL ("cork send malloc failure\n" ); + +ASSERT_OK (skel->bss->err,"cork error" ); +ASSERT_EQ (skel->bss->size, cork,"cork did not receive all bytes" ); + + recv =xrecv_nonblock (opts->server, recvbuf, total,0 ); +if (recv != total) +FAIL ("Received incorrect number of bytes" ); + +free (recvbuf); +} + +static void test_sockmap_cork () +{ +struct test_sockmap_msg_helpers *skel; +struct msg_test_opts opts; +int s, client, server; +int err, map, prog; + + skel =test_sockmap_msg_helpers__open_and_load (); +if (!ASSERT_OK_PTR (skel,"open_and_load" )) +return ; + + map =bpf_map__fd (skel->maps.sock_map); + prog =bpf_program__fd (skel->progs.msg_helpers); + err =bpf_prog_attach (prog, map,BPF_SK_MSG_VERDICT ,0 ); +if (!ASSERT_OK (err,"bpf_prog_attach" )) + goto out; + + s =socket_loopback (AF_INET ,SOCK_STREAM ); +if (s <0 ) + goto out; + + err =create_pair (s,AF_INET ,SOCK_STREAM , &client, &server); +if (err <0 ) + goto close_loopback; + + err =add_to_sockmap (map, client, server); +if (err <0 ) + goto close_sockets; + + opts.client = client; + opts.server = server; + opts.skel = skel; + +/* Small cork */ +cork_send (&opts,54 ); +/* Full cork */ +cork_send (&opts,270 ); +close_sockets: +close (client); +close (server); +close_loopback: +close (s); +out: +test_sockmap_msg_helpers__destroy (skel); +} +static void pop_simple_send (struct msg_test_opts *opts,int start,int len) {struct test_sockmap_msg_helpers *skel = opts->skel;
@@ -260,4 +339,6 @@ void test_sockmap_msg_helpers(void)test_sockmap_pop ();if (test__start_subtest ("sockmap pop errors" ))test_sockmap_pop_errors (); +if (test__start_subtest ("sockmap cork" )) +test_sockmap_cork (); }
tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c +3 -0
@@ -30,10 +30,13 @@ int pop_start = 0;int pop_len =0 ;int err; +int size; SEC("sk_msg")int msg_helpers (struct sk_msg_md *msg) { + size = msg->size; +if (cork) err =bpf_msg_cork_bytes (msg, cork);
Signature · 1 line
2.33.0
Re: [PATCH bpf-next v2 3/4] bpf: sockmap, add a cork to force buffering of the scatterlist
Quoted 17 lines · John Fastabend
By using cork we can force multiple sends into a single scatterlist and test that first the cork gives us the correct number of bytes, but then also test the pop over the corked data.
Signed-off-by John Fastabend <[email protected]>--- .../bpf/prog_tests/sockmap_msg_helpers.c | 81 +++++++++++++++++++ .../bpf/progs/test_sockmap_msg_helpers.c | 3 + 2 files changed, 84 insertions(+)tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +0
-0@@ -21,6 +21,85 @@ struct msg_test_opts {#define POP_END -1
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c struct msg_test_opts { · line 32
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +9
-0+static void cork_send (struct msg_test_opts *opts,int cork) +{ +struct test_sockmap_msg_helpers *skel = opts->skel; +char buf[] ="abcdefghijklmnopqrstuvwxyz" ; +size_t sent, total =0 , recv; +char *recvbuf; +int i; + + skel->bss->pop = false;
Why reset it? Every subtest loads new program & creates new maps.
Quoted 23 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +23
-0+ skel->bss->cork = cork; + +/* Send N bytes in 27B chunks */ +for (i =0 ; i < cork /sizeof (buf); i++) { + sent =xsend (opts->client, buf,sizeof (buf),0 ); +if (sent <sizeof (buf)) +FAIL ("xsend failed" ); + total += sent; + } + + recvbuf =malloc (total); +if (!recvbuf) +FAIL ("cork send malloc failure\n" ); + +ASSERT_OK (skel->bss->err,"cork error" ); +ASSERT_EQ (skel->bss->size, cork,"cork did not receive all bytes" ); + + recv =xrecv_nonblock (opts->server, recvbuf, total,0 ); +if (recv != total) +FAIL ("Received incorrect number of bytes" ); + +free (recvbuf); +}
[...]
Re: [PATCH bpf-next v2 3/4] bpf: sockmap, add a cork to force buffering of the scatterlist
Quoted 19 lines · Jakub Sitnicki
Quoted 18 lines · John Fastabend
By using cork we can force multiple sends into a single scatterlist and test that first the cork gives us the correct number of bytes, but then also test the pop over the corked data.
Signed-off-by John Fastabend <[email protected]>--- .../bpf/prog_tests/sockmap_msg_helpers.c | 81 +++++++++++++++++++ .../bpf/progs/test_sockmap_msg_helpers.c | 3 + 2 files changed, 84 insertions(+)tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +0
-0@@ -21,6 +21,85 @@ struct msg_test_opts {#define POP_END -1
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c struct msg_test_opts { · line 32
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +9
-0+static void cork_send (struct msg_test_opts *opts,int cork) +{ +struct test_sockmap_msg_helpers *skel = opts->skel; +char buf[] ="abcdefghijklmnopqrstuvwxyz" ; +size_t sent, total =0 , recv; +char *recvbuf; +int i; + + skel->bss->pop = false;Why reset it? Every subtest loads new program & creates new maps.
Agree I'lld elete it.
Quoted 26 lines
Quoted 24 lines
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +23
-0+ skel->bss->cork = cork; + +/* Send N bytes in 27B chunks */ +for (i =0 ; i < cork /sizeof (buf); i++) { + sent =xsend (opts->client, buf,sizeof (buf),0 ); +if (sent <sizeof (buf)) +FAIL ("xsend failed" ); + total += sent; + } + + recvbuf =malloc (total); +if (!recvbuf) +FAIL ("cork send malloc failure\n" ); + +ASSERT_OK (skel->bss->err,"cork error" ); +ASSERT_EQ (skel->bss->size, cork,"cork did not receive all bytes" ); + + recv =xrecv_nonblock (opts->server, recvbuf, total,0 ); +if (recv != total) +FAIL ("Received incorrect number of bytes" ); + +free (recvbuf); +}[...]
PATCH v2 4/4 bpf: sockmap test cork and pop combined
In reply to John FastabendIts possible to cork data for some N bytes and then pop a some bytes off that scatterlist. Test combining cork and pop here.
--- .../bpf/prog_tests/sockmap_msg_helpers.c | 19 ++++++++++++++----- .../bpf/progs/test_sockmap_msg_helpers.c | 14 +++++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c +14 -5
@@ -21,7 +21,7 @@ struct msg_test_opts {#define POP_END -1 -static void cork_send (struct msg_test_opts *opts,int cork) +static void cork_send (struct msg_test_opts *opts,int cork,int start,int len) {struct test_sockmap_msg_helpers *skel = opts->skel;char buf[] ="abcdefghijklmnopqrstuvwxyz" ;
@@ -29,9 +29,12 @@ static void cork_send(struct msg_test_opts *opts, int cork)char *recvbuf;int i; - skel->bss->pop = false; + skel->bss->pop = !!len; skel->bss->cork = cork; + skel->bss->pop_start = start; + skel->bss->pop_len = len; +/* Send N bytes in 27B chunks */ for (i =0 ; i < cork /sizeof (buf); i++) { sent =xsend (opts->client, buf,sizeof (buf),0 );
@@ -48,7 +51,7 @@ static void cork_send(struct msg_test_opts *opts, int cork)ASSERT_EQ (skel->bss->size, cork,"cork did not receive all bytes" ); recv =xrecv_nonblock (opts->server, recvbuf, total,0 ); -if (recv != total) +if (recv != total - len)FAIL ("Received incorrect number of bytes" );free (recvbuf);
@@ -88,9 +91,15 @@ static void test_sockmap_cork() opts.skel = skel;/* Small cork */ -cork_send (&opts,54 ); +cork_send (&opts,54 ,0 ,0 );/* Full cork */ -cork_send (&opts,270 ); +cork_send (&opts,270 ,0 ,0 ); + +/* Combine cork and pop small */ +cork_send (&opts,54 ,0 ,10 ); +/* Full cork and pop */ +cork_send (&opts,270 ,200 ,50 ); + close_sockets:close (client);close (server);
tools/testing/selftests/bpf/progs/test_sockmap_msg_helpers.c +13 -1
@@ -37,8 +37,19 @@ int msg_helpers(struct sk_msg_md *msg) { size = msg->size; -if (cork) +/* If message is not yet fully cork'ed skip push, pull, pop */ +if (cork && cork > msg->size) { err =bpf_msg_cork_bytes (msg, cork); + goto out; + }else if (cork) { +/* If we previously corked the msg we need to clear the cork +* otherwise next pop would cause datapath to wait for the +* popped bytes to actually do the send. +*/ + err =bpf_msg_cork_bytes (msg,0 ); +if (err) + goto out; + }if (pull) err =bpf_msg_pull_data (msg, pull_start, pull_end,0 );
@@ -49,6 +60,7 @@ int msg_helpers(struct sk_msg_md *msg)if (pop) err =bpf_msg_pop_data (msg, pop_start, pop_len,0 ); +out:return SK_PASS ; }
Signature · 1 line
2.33.0
Quoted 12 lines · John Fastabend
Its much easier to write and read tests than it was when sockmap was originally created. At that time we created a
test_sockmapprog that did sockmap tests. But, its showing its age now. For example it reads user vars out of maps, is hard to run targetted tests, has a different format from the familiartest_progsand so on.I recently thought there was an issue with pop helpers so I created some tests to try and track it down. It turns out it was a bug in the BPF program we had not the kernel. But, I think it makes sense to start deprecating
test_sockmapand converting these to the nicertest_progs.
Quoted 8 lines
So this is a first round of
test_progtests for sockmap cork and pop helpers. I'll add push and pull tests shortly. I think its fine, maybe preferred to review smaller patchsets, to send these incrementally as I get them created.Thanks!
v2: fix unint vars in some branches from
make RELEASE=1
I'll wait a bit to see if there is any additional feedback, but on bpf-next these tests were stable. When we backported to 6.1 they became a bit flaky because recv() would sometimes only get part of the msg. I'll take a look, but this should be fine adding a retry logic to the recv() so it does a few recv's before giving up allows it to recv partial messages, but still pass the test.
Thanks,
John
Quoted 12 lines · John Fastabend
Its much easier to write and read tests than it was when sockmap was originally created. At that time we created a
test_sockmapprog that did sockmap tests. But, its showing its age now. For example it reads user vars out of maps, is hard to run targetted tests, has a different format from the familiartest_progsand so on.I recently thought there was an issue with pop helpers so I created some tests to try and track it down. It turns out it was a bug in the BPF program we had not the kernel. But, I think it makes sense to start deprecating
test_sockmapand converting these to the nicertest_progs.
Quoted 4 lines
So this is a first round of
test_progtests for sockmap cork and pop helpers. I'll add push and pull tests shortly. I think its fine, maybe preferred to review smaller patchsets, to send these incrementally as I get them created.
Cool to see this transition starting.
Quoted 13 lines · Jakub Sitnicki
Quoted 12 lines · John Fastabend
Its much easier to write and read tests than it was when sockmap was originally created. At that time we created a
test_sockmapprog that did sockmap tests. But, its showing its age now. For example it reads user vars out of maps, is hard to run targetted tests, has a different format from the familiartest_progsand so on.I recently thought there was an issue with pop helpers so I created some tests to try and track it down. It turns out it was a bug in the BPF program we had not the kernel. But, I think it makes sense to start deprecating
test_sockmapand converting these to the nicertest_progs.
Quoted 6 lines
Quoted 4 lines
So this is a first round of
test_progtests for sockmap cork and pop helpers. I'll add push and pull tests shortly. I think its fine, maybe preferred to review smaller patchsets, to send these incrementally as I get them created.Cool to see this transition starting.
Thanks for the review.