Commit b0d754ef authored by tannerlove's avatar tannerlove Committed by David S. Miller

selftests/net: add ipv6 test coverage in rxtimestamp test

Add the options --ipv4, --ipv6 to specify running over ipv4 and/or
ipv6. If neither is specified, then run both.
Signed-off-by: default avatarTanner Love <tannerlove@google.com>
Acked-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a2116491
...@@ -117,6 +117,8 @@ static struct option long_options[] = { ...@@ -117,6 +117,8 @@ static struct option long_options[] = {
{ "udp", no_argument, 0, 'u' }, { "udp", no_argument, 0, 'u' },
{ "ip", no_argument, 0, 'i' }, { "ip", no_argument, 0, 'i' },
{ "strict", no_argument, 0, 'S' }, { "strict", no_argument, 0, 'S' },
{ "ipv4", no_argument, 0, '4' },
{ "ipv6", no_argument, 0, '6' },
{ NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 },
}; };
...@@ -272,37 +274,55 @@ void config_so_flags(int rcv, struct options o) ...@@ -272,37 +274,55 @@ void config_so_flags(int rcv, struct options o)
error(1, errno, "Failed to set SO_TIMESTAMPING"); error(1, errno, "Failed to set SO_TIMESTAMPING");
} }
bool run_test_case(struct socket_type s, struct test_case t) bool run_test_case(struct socket_type *s, int test_num, char ip_version,
bool strict)
{ {
int port = (s.type == SOCK_RAW) ? 0 : next_port++; union {
struct sockaddr_in6 addr6;
struct sockaddr_in addr4;
struct sockaddr addr_un;
} addr;
int read_size = op_size; int read_size = op_size;
struct sockaddr_in addr; int src, dst, rcv, port;
socklen_t addr_size;
bool failed = false; bool failed = false;
int src, dst, rcv;
src = socket(AF_INET, s.type, s.protocol); port = (s->type == SOCK_RAW) ? 0 : next_port++;
memset(&addr, 0, sizeof(addr));
if (ip_version == '4') {
addr.addr4.sin_family = AF_INET;
addr.addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.addr4.sin_port = htons(port);
addr_size = sizeof(addr.addr4);
if (s->type == SOCK_RAW)
read_size += 20; /* for IPv4 header */
} else {
addr.addr6.sin6_family = AF_INET6;
addr.addr6.sin6_addr = in6addr_loopback;
addr.addr6.sin6_port = htons(port);
addr_size = sizeof(addr.addr6);
}
printf("Starting testcase %d over ipv%c...\n", test_num, ip_version);
src = socket(addr.addr_un.sa_family, s->type,
s->protocol);
if (src < 0) if (src < 0)
error(1, errno, "Failed to open src socket"); error(1, errno, "Failed to open src socket");
dst = socket(AF_INET, s.type, s.protocol); dst = socket(addr.addr_un.sa_family, s->type,
s->protocol);
if (dst < 0) if (dst < 0)
error(1, errno, "Failed to open dst socket"); error(1, errno, "Failed to open dst socket");
memset(&addr, 0, sizeof(addr)); if (bind(dst, &addr.addr_un, addr_size) < 0)
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(port);
if (bind(dst, (struct sockaddr *)&addr, sizeof(addr)) < 0)
error(1, errno, "Failed to bind to port %d", port); error(1, errno, "Failed to bind to port %d", port);
if (s.type == SOCK_STREAM && (listen(dst, 1) < 0)) if (s->type == SOCK_STREAM && (listen(dst, 1) < 0))
error(1, errno, "Failed to listen"); error(1, errno, "Failed to listen");
if (connect(src, (struct sockaddr *)&addr, sizeof(addr)) < 0) if (connect(src, &addr.addr_un, addr_size) < 0)
error(1, errno, "Failed to connect"); error(1, errno, "Failed to connect");
if (s.type == SOCK_STREAM) { if (s->type == SOCK_STREAM) {
rcv = accept(dst, NULL, NULL); rcv = accept(dst, NULL, NULL);
if (rcv < 0) if (rcv < 0)
error(1, errno, "Failed to accept"); error(1, errno, "Failed to accept");
...@@ -311,17 +331,22 @@ bool run_test_case(struct socket_type s, struct test_case t) ...@@ -311,17 +331,22 @@ bool run_test_case(struct socket_type s, struct test_case t)
rcv = dst; rcv = dst;
} }
config_so_flags(rcv, t.sockopt); config_so_flags(rcv, test_cases[test_num].sockopt);
usleep(20000); /* setsockopt for SO_TIMESTAMPING is asynchronous */ usleep(20000); /* setsockopt for SO_TIMESTAMPING is asynchronous */
do_send(src); do_send(src);
if (s.type == SOCK_RAW) failed = do_recv(rcv, read_size, test_cases[test_num].expected);
read_size += 20; /* for IP header */
failed = do_recv(rcv, read_size, t.expected);
close(rcv); close(rcv);
close(src); close(src);
if (failed) {
printf("FAILURE in testcase %d over ipv%c ", test_num,
ip_version);
print_test_case(&test_cases[test_num]);
if (!strict && test_cases[test_num].warn_on_fail)
failed = false;
}
return failed; return failed;
} }
...@@ -329,6 +354,8 @@ int main(int argc, char **argv) ...@@ -329,6 +354,8 @@ int main(int argc, char **argv)
{ {
bool all_protocols = true; bool all_protocols = true;
bool all_tests = true; bool all_tests = true;
bool cfg_ipv4 = false;
bool cfg_ipv6 = false;
bool strict = false; bool strict = false;
int arg_index = 0; int arg_index = 0;
int failures = 0; int failures = 0;
...@@ -369,6 +396,12 @@ int main(int argc, char **argv) ...@@ -369,6 +396,12 @@ int main(int argc, char **argv)
case 'S': case 'S':
strict = true; strict = true;
break; break;
case '4':
cfg_ipv4 = true;
break;
case '6':
cfg_ipv6 = true;
break;
default: default:
error(1, 0, "Failed to parse parameters."); error(1, 0, "Failed to parse parameters.");
} }
...@@ -382,14 +415,14 @@ int main(int argc, char **argv) ...@@ -382,14 +415,14 @@ int main(int argc, char **argv)
for (t = 0; t < ARRAY_SIZE(test_cases); t++) { for (t = 0; t < ARRAY_SIZE(test_cases); t++) {
if (!all_tests && !test_cases[t].enabled) if (!all_tests && !test_cases[t].enabled)
continue; continue;
if (cfg_ipv4 || !cfg_ipv6)
printf("Starting testcase %d...\n", t); if (run_test_case(&socket_types[s], t, '4',
if (run_test_case(socket_types[s], test_cases[t])) { strict))
if (strict || !test_cases[t].warn_on_fail) failures++;
if (cfg_ipv6 || !cfg_ipv4)
if (run_test_case(&socket_types[s], t, '6',
strict))
failures++; failures++;
printf("FAILURE in test case ");
print_test_case(&test_cases[t]);
}
} }
} }
if (!failures) if (!failures)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment