From: Zhibin Li <08826794brmt@gmail.com> Date: Tue, 24 Jul 2018 08:59:15 +0000 (+0800) Subject: tests: check decoding of setsockopt(PACKET_[R|T]X_RING) X-Git-Tag: v4.24~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7ecd1096bfea1bf69052eb2eecd481a2bb893466;p=strace tests: check decoding of setsockopt(PACKET_[R|T]X_RING) * tests/net-tpacket_req.c: New file. * tests/.gitignore: Add net-tpacket_req. * tests/pure_executables.list: Likewise. * tests/gen_tests.in (net-tpacket_req): New test. --- diff --git a/tests/.gitignore b/tests/.gitignore index b98d535c..011e3132 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -253,6 +253,7 @@ net-accept-connect net-icmp_filter net-packet_mreq net-sockaddr +net-tpacket_req net-y-unix net-yy-inet net-yy-inet6 diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 44d6d715..c3cd1a0b 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -236,6 +236,7 @@ nanosleep -a20 net-icmp_filter -e trace=getsockopt,setsockopt net-packet_mreq -e trace=setsockopt net-sockaddr -a24 -e trace=connect +net-tpacket_req -e trace=setsockopt net-yy-inet6 +net-yy-inet.test netlink_audit +netlink_sock_diag.test netlink_crypto +netlink_sock_diag.test diff --git a/tests/net-tpacket_req.c b/tests/net-tpacket_req.c new file mode 100644 index 00000000..06955873 --- /dev/null +++ b/tests/net-tpacket_req.c @@ -0,0 +1,52 @@ +#include "tests.h" +#include +#include +#include + +static const char *errstr; + +static long +set_tpacket_req(int optname, void *optval, socklen_t len) +{ + long rc = setsockopt(-1, SOL_PACKET, optname, optval, len); + errstr = sprintrc(rc); + return rc; +} + +static void +test_tpacket_req(const int optname, const char *const optname_str) +{ + TAIL_ALLOC_OBJECT_CONST_PTR(struct tpacket_req, tpreq); + socklen_t len; + + /* setsockopt with optname unknown */ + set_tpacket_req(-1, NULL, 0); + printf("setsockopt(-1, SOL_PACKET, %#x /* PACKET_??? */, NULL, 0) = %s\n", + -1, errstr); + + /* classic setsockopt */ + len = sizeof(struct tpacket_req); + set_tpacket_req(optname, tpreq, len); + printf("setsockopt(-1, SOL_PACKET, %s, {tp_block_size=%u," + " tp_block_nr=%u, tp_frame_size=%u, tp_frame_nr=%u}, %d) = %s\n", + optname_str, tpreq->tp_block_size, tpreq->tp_block_nr, + tpreq->tp_frame_size, tpreq->tp_frame_nr, len, errstr); + + /* setsockopt with optlen larger than usual */ + len = len + 1; + set_tpacket_req(optname, tpreq, len); + printf("setsockopt(-1, SOL_PACKET, %s, %p," + " %d) = %s\n", optname_str, tpreq, len, errstr); +} + +int +main(void) +{ + test_tpacket_req(ARG_STR(PACKET_RX_RING)); +#ifdef PACKET_TX_RING + test_tpacket_req(ARG_STR(PACKET_TX_RING)); +#endif + + puts("+++ exited with 0 +++"); + return 0; +} diff --git a/tests/pure_executables.list b/tests/pure_executables.list index af6883f1..e8345252 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -207,6 +207,7 @@ nanosleep net-icmp_filter net-packet_mreq net-sockaddr +net-tpacket_req net-y-unix net-yy-inet net-yy-inet6