summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJakub Sitnicki <jakub@cloudflare.com>2019-12-12 11:22:53 +0100
committerAlexei Starovoitov <ast@kernel.org>2019-12-13 12:38:00 -0800
commita9ce4cf4e47c55ab40641b92551bc9e1de4bfa61 (patch)
treef8040169492f470614b2e963c386ca339601d763 /tools
parent11f80355d4d27c7c798fc9890b4056c5d98af992 (diff)
downloadlinux-stable-a9ce4cf4e47c55ab40641b92551bc9e1de4bfa61.tar.gz
linux-stable-a9ce4cf4e47c55ab40641b92551bc9e1de4bfa61.tar.bz2
linux-stable-a9ce4cf4e47c55ab40641b92551bc9e1de4bfa61.zip
selftests/bpf: Add helpers for getting socket family & type name
Having string arrays to map socket family & type to a name prevents us from unrolling the test runner loop in the subsequent patch. Introduce helpers that do the same thing. Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20191212102259.418536-5-jakub@cloudflare.com
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/bpf/test_select_reuseport.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/tools/testing/selftests/bpf/test_select_reuseport.c b/tools/testing/selftests/bpf/test_select_reuseport.c
index a295a087a026..ef98a7de6704 100644
--- a/tools/testing/selftests/bpf/test_select_reuseport.c
+++ b/tools/testing/selftests/bpf/test_select_reuseport.c
@@ -674,12 +674,34 @@ static void cleanup(void)
bpf_object__close(obj);
}
+static const char *family_str(sa_family_t family)
+{
+ switch (family) {
+ case AF_INET:
+ return "IPv4";
+ case AF_INET6:
+ return "IPv6";
+ default:
+ return "unknown";
+ }
+}
+
+static const char *sotype_str(int sotype)
+{
+ switch (sotype) {
+ case SOCK_STREAM:
+ return "TCP";
+ case SOCK_DGRAM:
+ return "UDP";
+ default:
+ return "unknown";
+ }
+}
+
static void test_all(void)
{
/* Extra SOCK_STREAM to test bind_inany==true */
const int types[] = { SOCK_STREAM, SOCK_DGRAM, SOCK_STREAM };
- const char * const type_strings[] = { "TCP", "UDP", "TCP" };
- const char * const family_strings[] = { "IPv6", "IPv4" };
const sa_family_t families[] = { AF_INET6, AF_INET };
const bool bind_inany[] = { false, false, true };
int t, f, err;
@@ -692,7 +714,7 @@ static void test_all(void)
int type = types[t];
printf("######## %s/%s %s ########\n",
- family_strings[f], type_strings[t],
+ family_str(family), sotype_str(type),
inany ? " INANY " : "LOOPBACK");
setup_per_test(type, family, inany);