From: Joe Stringer <joe@wand.net.nz>
To: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org, daniel@iogearbox.net, ast@kernel.org,
eric.dumazet@gmail.com, lmb@cloudflare.com
Subject: [PATCH bpf-next 7/7] selftests: bpf: Improve debuggability of sk_assign
Date: Thu, 12 Mar 2020 16:36:48 -0700 [thread overview]
Message-ID: <20200312233648.1767-8-joe@wand.net.nz> (raw)
In-Reply-To: <20200312233648.1767-1-joe@wand.net.nz>
This test was a bit obtuse before, add a shorter timeout when
connectivity doesn't work and a '-d' debug flag for extra output.
Signed-off-by: Joe Stringer <joe@wand.net.nz>
---
tools/testing/selftests/bpf/test_sk_assign.c | 42 +++++++++++++++++++
tools/testing/selftests/bpf/test_sk_assign.sh | 2 +-
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/test_sk_assign.c b/tools/testing/selftests/bpf/test_sk_assign.c
index 4b7b9bbe7859..51d3d01d5476 100644
--- a/tools/testing/selftests/bpf/test_sk_assign.c
+++ b/tools/testing/selftests/bpf/test_sk_assign.c
@@ -3,6 +3,8 @@
// Copyright (c) 2019 Cloudflare
// Copyright (c) 2020 Isovalent. Inc.
+#include <fcntl.h>
+#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@@ -20,6 +22,14 @@
#define TEST_DADDR (0xC0A80203)
+static bool debug;
+
+#define debugf(format, ...) \
+do { \
+ if (debug) \
+ printf(format, ##__VA_ARGS__); \
+} while (0)
+
static int start_server(const struct sockaddr *addr, socklen_t len)
{
int fd;
@@ -49,6 +59,17 @@ static int start_server(const struct sockaddr *addr, socklen_t len)
return fd;
}
+static void handle_timeout(int signum)
+{
+ if (signum == SIGALRM)
+ log_err("Timed out while connecting to server");
+ kill(0, SIGKILL);
+}
+
+static struct sigaction timeout_action = {
+ .sa_handler = handle_timeout,
+};
+
static int connect_to_server(const struct sockaddr *addr, socklen_t len)
{
int fd = -1;
@@ -59,6 +80,12 @@ static int connect_to_server(const struct sockaddr *addr, socklen_t len)
goto out;
}
+ if (sigaction(SIGALRM, &timeout_action, NULL)) {
+ log_err("Failed to configure timeout signal");
+ goto out;
+ }
+
+ alarm(3);
if (connect(fd, addr, len) == -1) {
log_err("Fail to connect to server");
goto close_out;
@@ -141,6 +168,17 @@ int main(int argc, char **argv)
int server_v6 = -1;
int err = 1;
+ if (argc > 1) {
+ if (!memcmp(argv[1], "-h", 2)) {
+ printf("usage: %s.sh [FLAGS]\n", argv[0]);
+ printf(" -d\tEnable debug logs\n");
+ printf(" -h\tPrint help message\n");
+ exit(1);
+ }
+ if (!memcmp(argv[1], "-d", 2))
+ debug = true;
+ }
+
memset(&addr4, 0, sizeof(addr4));
addr4.sin_family = AF_INET;
addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
@@ -166,9 +204,11 @@ int main(int argc, char **argv)
if (run_test(server, (const struct sockaddr *)&addr4, sizeof(addr4)))
goto out;
+ debugf("ipv4 port: ok\n");
if (run_test(server_v6, (const struct sockaddr *)&addr6, sizeof(addr6)))
goto out;
+ debugf("ipv6 port: ok\n");
/* Connect to unbound addresses */
addr4.sin_addr.s_addr = htonl(TEST_DADDR);
@@ -176,9 +216,11 @@ int main(int argc, char **argv)
if (run_test(server, (const struct sockaddr *)&addr4, sizeof(addr4)))
goto out;
+ debugf("ipv4 addr: ok\n");
if (run_test(server_v6, (const struct sockaddr *)&addr6, sizeof(addr6)))
goto out;
+ debugf("ipv6 addr: ok\n");
printf("ok\n");
err = 0;
diff --git a/tools/testing/selftests/bpf/test_sk_assign.sh b/tools/testing/selftests/bpf/test_sk_assign.sh
index de1df4e438de..5a84ad18f85a 100755
--- a/tools/testing/selftests/bpf/test_sk_assign.sh
+++ b/tools/testing/selftests/bpf/test_sk_assign.sh
@@ -19,4 +19,4 @@ tc qdisc add dev lo clsact
tc filter add dev lo ingress bpf direct-action object-file ./test_sk_assign.o \
section "sk_assign_test"
-exec ./test_sk_assign
+exec ./test_sk_assign "$@"
--
2.20.1
prev parent reply other threads:[~2020-03-12 23:37 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-12 23:36 [PATCH bpf-next 0/7] Add bpf_sk_assign eBPF helper Joe Stringer
2020-03-12 23:36 ` [PATCH bpf-next 1/7] dst: Move skb_dst_drop to skbuff.c Joe Stringer
2020-03-12 23:36 ` [PATCH bpf-next 2/7] dst: Add socket prefetch metadata destinations Joe Stringer
2020-03-12 23:36 ` [PATCH bpf-next 3/7] bpf: Add socket assign support Joe Stringer
2020-03-16 10:08 ` Jakub Sitnicki
2020-03-16 21:23 ` Joe Stringer
2020-03-16 22:57 ` Martin KaFai Lau
2020-03-17 3:06 ` Joe Stringer
2020-03-17 6:26 ` Martin KaFai Lau
2020-03-18 0:46 ` Joe Stringer
2020-03-18 10:03 ` Jakub Sitnicki
2020-03-19 5:49 ` Joe Stringer
2020-03-18 18:48 ` Martin KaFai Lau
2020-03-19 6:24 ` Joe Stringer
2020-03-20 1:54 ` Martin KaFai Lau
2020-03-20 4:28 ` Joe Stringer
2020-03-17 10:09 ` Lorenz Bauer
2020-03-18 1:10 ` Joe Stringer
2020-03-18 2:03 ` Joe Stringer
2020-03-12 23:36 ` [PATCH bpf-next 4/7] dst: Prefetch established socket destinations Joe Stringer
2020-03-16 23:03 ` Martin KaFai Lau
2020-03-17 3:17 ` Joe Stringer
2020-03-12 23:36 ` [PATCH bpf-next 5/7] selftests: bpf: add test for sk_assign Joe Stringer
2020-03-17 6:30 ` Martin KaFai Lau
2020-03-17 20:56 ` Joe Stringer
2020-03-18 17:27 ` Martin KaFai Lau
2020-03-19 5:45 ` Joe Stringer
2020-03-19 17:36 ` Andrii Nakryiko
2020-03-12 23:36 ` [PATCH bpf-next 6/7] selftests: bpf: Extend sk_assign for address proxy Joe Stringer
2020-03-12 23:36 ` Joe Stringer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200312233648.1767-8-joe@wand.net.nz \
--to=joe@wand.net.nz \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eric.dumazet@gmail.com \
--cc=lmb@cloudflare.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).