Following commit f3de1cf621f7 ("selftests/bpf: sockmap_listen cleanup: Drop
af_unix redir tests") and commit 9266e49d608c ("selftests/bpf:
sockmap_listen cleanup: Drop af_vsock redir tests"), sockmap_listen.c:
family_str() becomes functionally identical to select_reuseport.c:
family_str(). Move the logic to socket_helpers.h.

Suggested-by: Kuniyuki Iwashima <[email protected]>
Link: 
https://msgid.link/caavpqudulzzh58okkrayqgm9brtogb7whrzt+cznprmatm1...@mail.gmail.com
Signed-off-by: Michal Luczaj <[email protected]>
---
 .../selftests/bpf/prog_tests/select_reuseport.c    | 16 +++-------------
 .../selftests/bpf/prog_tests/socket_helpers.h      | 12 ++++++++++++
 .../selftests/bpf/prog_tests/sockmap_listen.c      | 22 +++-------------------
 3 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c 
b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
index 3dbcc091f16c..3b4b233e21d1 100644
--- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
+++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c
@@ -6,6 +6,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <errno.h>
+#include <error.h>
 #include <assert.h>
 #include <fcntl.h>
 #include <linux/bpf.h>
@@ -21,6 +22,7 @@
 #include "bpf_util.h"
 
 #include "test_progs.h"
+#include "socket_helpers.h"
 #include "test_select_reuseport_common.h"
 
 #define MAX_TEST_NAME 80
@@ -740,18 +742,6 @@ static const char *maptype_str(enum bpf_map_type type)
        }
 }
 
-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) {
@@ -794,7 +784,7 @@ static void test_config(int sotype, sa_family_t family, 
bool inany)
 
                snprintf(s, sizeof(s), "%s %s/%s %s %s",
                         maptype_str(inner_map_type),
-                        family_str(family), sotype_str(sotype),
+                        inet_family_str(family), sotype_str(sotype),
                         inany ? "INANY" : "LOOPBACK", t->name);
 
                if (!test__start_subtest(s))
diff --git a/tools/testing/selftests/bpf/prog_tests/socket_helpers.h 
b/tools/testing/selftests/bpf/prog_tests/socket_helpers.h
index 0d59503a0c73..4a570998612d 100644
--- a/tools/testing/selftests/bpf/prog_tests/socket_helpers.h
+++ b/tools/testing/selftests/bpf/prog_tests/socket_helpers.h
@@ -470,4 +470,16 @@ static inline const char *socket_kind_to_str(int sock_fd)
        return "???";
 }
 
+static inline const char *inet_family_str(sa_family_t family)
+{
+       switch (family) {
+       case AF_INET:
+               return "IPv4";
+       case AF_INET6:
+               return "IPv6";
+       default:
+               return "unknown";
+       }
+}
+
 #endif // __SOCKET_HELPERS__
diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c 
b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
index 1c96a3cf4b97..235e1d56f044 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
@@ -1232,22 +1232,6 @@ static void test_ops_cleanup(const struct bpf_map *map)
        }
 }
 
-static const char *family_str(sa_family_t family)
-{
-       switch (family) {
-       case AF_INET:
-               return "IPv4";
-       case AF_INET6:
-               return "IPv6";
-       case AF_UNIX:
-               return "Unix";
-       case AF_VSOCK:
-               return "VSOCK";
-       default:
-               return "unknown";
-       }
-}
-
 static const char *map_type_str(const struct bpf_map *map)
 {
        int type;
@@ -1315,7 +1299,7 @@ static void test_ops(struct test_sockmap_listen *skel, 
struct bpf_map *map,
        char s[MAX_TEST_NAME];
        int map_fd;
 
-       family_name = family_str(family);
+       family_name = inet_family_str(family);
        map_name = map_type_str(map);
        sotype_name = sotype_str(sotype);
        map_fd = bpf_map__fd(map);
@@ -1355,7 +1339,7 @@ static void test_redir(struct test_sockmap_listen *skel, 
struct bpf_map *map,
        const struct redir_test *t;
        char s[MAX_TEST_NAME];
 
-       family_name = family_str(family);
+       family_name = inet_family_str(family);
        map_name = map_type_str(map);
 
        for (t = tests; t < tests + ARRAY_SIZE(tests); t++) {
@@ -1387,7 +1371,7 @@ static void test_reuseport(struct test_sockmap_listen 
*skel,
        const struct reuseport_test *t;
        char s[MAX_TEST_NAME];
 
-       family_name = family_str(family);
+       family_name = inet_family_str(family);
        map_name = map_type_str(map);
        sotype_name = sotype_str(sotype);
 

---
base-commit: e1d84a37cba984388988d2f1ddc84561413f0db2
change-id: 20260724-selftests-sockmap_listen-cleanup-7ff21e9bedc6

Best regards,
--  
Michal Luczaj <[email protected]>


Reply via email to