Re: [PATCH bpf-next v2 2/4] bpf: sockmap, add a sendmsg test so we can check that path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jakub Sitnicki wrote:
> On Wed, Jan 24, 2024 at 10:54 AM -08, John Fastabend wrote:
> > 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 <john.fastabend@xxxxxxxxx>
> > ---
> >  .../bpf/prog_tests/sockmap_helpers.h          |  8 +++
> >  .../bpf/prog_tests/sockmap_msg_helpers.c      | 53 +++++++++++++++++++
> >  2 files changed, 61 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h b/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h
> > index 781cbdf01d7b..4d8d24482032 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h
> > +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h
> > @@ -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),      \
> > diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c b/tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c
> > index 9ffe02f45808..e5e618e84950 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_msg_helpers.c
> > @@ -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)
> > +{
> > +	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.

> 
> > +		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.




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux