tests: introduce TEST_NETLINK and TEST_NETLINK_ macros

* tests/test_netlink.h: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
* tests/netlink_sock_diag.c: Include "test_netlink.h"
instead of "netlink.h".
(TEST_SOCK_DIAG): New macro.
(test_unix_diag_req, test_unix_diag_msg,
test_netlink_diag_req, test_netlink_diag_msg,
test_packet_diag_req, test_packet_diag_msg,
test_inet_diag_req, test_inet_diag_req_v2,
test_inet_diag_msg, test_smc_diag_req,
test_smc_diag_msg): Use it.
(test_odd_family_req, test_odd_family_msg,
test_inet_diag_sockid): Use TEST_NETLINK macro.
This commit is contained in:
JingPiao Chen 2017-07-08 16:36:46 +08:00 committed by Dmitry V. Levin
parent 9f40073dc1
commit c254454365
3 changed files with 377 additions and 1259 deletions

View File

@ -63,6 +63,7 @@ libtests_a_SOURCES = \
skip_unavailable.c \
sprintrc.c \
tail_alloc.c \
test_netlink.h \
test_nlattr.h \
tests.h \
tprintf.c \

File diff suppressed because it is too large Load Diff

47
tests/test_netlink.h Normal file
View File

@ -0,0 +1,47 @@
#include "tests.h"
#include "print_fields.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/socket.h>
#include "netlink.h"
#define TEST_NETLINK_(fd_, nlh0_, \
type_, type_str_, \
flags_, flags_str_, \
data_len_, src_, slen_, ...) \
do { \
struct nlmsghdr *const TEST_NETLINK_nlh = \
(nlh0_) - (slen_); \
const unsigned int msg_len = \
NLMSG_HDRLEN + (data_len_); \
\
SET_STRUCT(struct nlmsghdr, TEST_NETLINK_nlh, \
.nlmsg_len = msg_len, \
.nlmsg_type = (type_), \
.nlmsg_flags = (flags_) \
); \
memcpy(NLMSG_DATA(TEST_NETLINK_nlh), (src_), (slen_)); \
\
const char *const errstr = \
sprintrc(sendto((fd_), TEST_NETLINK_nlh, \
msg_len, MSG_DONTWAIT, \
NULL, 0)); \
\
printf("sendto(%d, {{len=%u, type=%s" \
", flags=%s, seq=0, pid=0}, ", \
(fd_), msg_len, (type_str_), (flags_str_)); \
\
{ __VA_ARGS__; } \
\
printf("}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", \
msg_len, errstr); \
} while (0)
#define TEST_NETLINK(fd_, nlh0_, type_, flags_, \
data_len_, src_, slen_, ...) \
TEST_NETLINK_((fd_), (nlh0_), \
(type_), #type_, \
(flags_), #flags_, \
(data_len_), (src_), (slen_), __VA_ARGS__)