On systems where IPv6 isn't enabled or not configured to support
SOCK_STREAM, the test_memcg_sock test always fails. The purpose
of the test_memcg_sock test is to verify that memory.stat.sock and
memory.current values are close. If the socket() call fails, there is
no way we can test that. I believe it is better to just skip the test
in this case instead of reporting a test failure hinting that there
may be something wrong with the memcg code.

Fixes: 5f8f019380b8 ("selftests: cgroup/memcontrol: add basic test for socket 
accounting")
Signed-off-by: Waiman Long <[email protected]>
---
 tools/testing/selftests/cgroup/test_memcontrol.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c 
b/tools/testing/selftests/cgroup/test_memcontrol.c
index 2fb096a2a9f9..3c13ef67fafb 100644
--- a/tools/testing/selftests/cgroup/test_memcontrol.c
+++ b/tools/testing/selftests/cgroup/test_memcontrol.c
@@ -1280,8 +1280,11 @@ static int tcp_server(const char *cgroup, void *arg)
        saddr.sin6_port = htons(srv_args->port);
 
        sk = socket(AF_INET6, SOCK_STREAM, 0);
-       if (sk < 0)
+       if (sk < 0) {
+               /* Pass back errno to the ctl_fd */
+               write(ctl_fd, &errno, sizeof(errno));
                return ret;
+       }
 
        if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0)
                goto cleanup;
@@ -1414,6 +1417,9 @@ static int test_memcg_sock(const char *root)
 
                if (!err)
                        break;
+               if (err == EAFNOSUPPORT)
+                       /* Skip if address family not supported by protocol */
+                       goto skip;
                if (err != EADDRINUSE)
                        goto cleanup;
 
@@ -1460,6 +1466,9 @@ static int test_memcg_sock(const char *root)
        free(memcg);
 
        return ret;
+skip:
+       ret = KSFT_SKIP;
+       goto cleanup;
 }
 
 /*
-- 
2.53.0


Reply via email to