Skip to contentSkip to conversation

selftests/bpf: Poll for receive in cg_storage_multi test

PATCH Superseded YiFei Zhu 3 participants 3 messages Apr 3, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

YiFei Zhu

author
#0 lore raw

PATCH 1/1 selftests/bpf: Poll for receive in cg_storage_multi test

In some cases the loopback latency might be large enough, causing the assertion on invocations to be run before ingress prog getting executed. The assertion would fail and the test would flake.

This can be reliably reproduced by arbitrarily increaing the loopback latency (thanks to [1]):
tc qdisc add dev lo root handle 1: htb default 12
tc class add dev lo parent 1:1 classid 1:12 htb rate 20kbps ceil 20kbps tc qdisc add dev lo parent 1:12 netem delay 100ms

Fix this by polling on the receive end and waiting for up to a second, instead of instantly returning to the assert.

[1] https://gist.github.com/kstevens715/4598301

Fixes 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")
---
 .../testing/selftests/bpf/prog_tests/cg_storage_multi.c  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c +8 -1
index 621c57222191..3b0094a2a353 100644
@@ -7,6 +7,7 @@
 #include <test_progs.h>
 #include <cgroup_helpers.h>
 #include <network_helpers.h>
+#include <poll.h>
 
 #include "progs/cg_storage_multi.h"
 
@@ -56,8 +57,9 @@ static bool assert_storage_noexist(struct bpf_map *map, const void *key)
 
 static bool connect_send(const char *cgroup_path)
 {
-	bool res = true;
 	int server_fd = -1, client_fd = -1;
+	struct pollfd pollfd;
+	bool res = true;
 
 	if (join_cgroup(cgroup_path))
 		goto out_clean;
@@ -73,6 +75,11 @@ static bool connect_send(const char *cgroup_path)
 	if (send(client_fd, "message", strlen("message"), 0) < 0)
 		goto out_clean;
 
+	pollfd.fd = server_fd;
+	pollfd.events = POLLIN;
+	if (poll(&pollfd, 1, 1000) != 1)
+		goto out_clean;
+
 	res = false;
 
 out_clean:
Signature · 1 line
2.40.0.348.gf938b09366-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · YiFei Zhu

In some cases the loopback latency might be large enough, causing the assertion on invocations to be run before ingress prog getting executed. The assertion would fail and the test would flake.

This can be reliably reproduced by arbitrarily increaing the loopback latency (thanks to [1]):
tc qdisc add dev lo root handle 1: htb default 12
tc class add dev lo parent 1:1 classid 1:12 htb rate 20kbps ceil 20kbps tc qdisc add dev lo parent 1:12 netem delay 100ms

Fix this by polling on the receive end and waiting for up to a second, instead of instantly returning to the assert.

Quoted 6 lines

[1] https://gist.github.com/kstevens715/4598301

Fixes 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")

Thank you!

Quoted 42 lines
---
 .../testing/selftests/bpf/prog_tests/cg_storage_multi.c  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c +8 -2
index 621c57222191..3b0094a2a353 100644
@@ -7,6 +7,7 @@
 #include <test_progs.h>
 #include <cgroup_helpers.h>
 #include <network_helpers.h>
+#include <poll.h>
 
 #include "progs/cg_storage_multi.h"
 
@@ -56,8 +57,9 @@ static bool assert_storage_noexist(struct bpf_map *map, const void *key)
 
 static bool connect_send(const char *cgroup_path)
 {
-       bool res = true;
        int server_fd = -1, client_fd = -1;
+       struct pollfd pollfd;
+       bool res = true;
 
        if (join_cgroup(cgroup_path))
                goto out_clean;
@@ -73,6 +75,11 @@ static bool connect_send(const char *cgroup_path)
        if (send(client_fd, "message", strlen("message"), 0) < 0)
                goto out_clean;
 
+       pollfd.fd = server_fd;
+       pollfd.events = POLLIN;
+       if (poll(&pollfd, 1, 1000) != 1)
+               goto out_clean;
+
        res = false;
 
 out_clean:
--

2.40.0.348.gf938b09366-goog

#2 lore raw
In reply to YiFei Zhu
Quoted 47 lines · YiFei Zhu

In some cases the loopback latency might be large enough, causing the assertion on invocations to be run before ingress prog getting executed. The assertion would fail and the test would flake.

This can be reliably reproduced by arbitrarily increaing the loopback latency (thanks to [1]):
tc qdisc add dev lo root handle 1: htb default 12
tc class add dev lo parent 1:1 classid 1:12 htb rate 20kbps ceil 20kbps tc qdisc add dev lo parent 1:12 netem delay 100ms

Fix this by polling on the receive end and waiting for up to a second, instead of instantly returning to the assert.

[1] https://gist.github.com/kstevens715/4598301

Fixes 3573f384014f ("selftests/bpf: Test CGROUP_STORAGE behavior on shared egress + ingress")
---
  .../testing/selftests/bpf/prog_tests/cg_storage_multi.c  | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c +3 -1
index 621c57222191..3b0094a2a353 100644
@@ -7,6 +7,7 @@
  #include <test_progs.h>
  #include <cgroup_helpers.h>
  #include <network_helpers.h>
+#include <poll.h>
 
  #include "progs/cg_storage_multi.h"
 
@@ -56,8 +57,9 @@ static bool assert_storage_noexist(struct bpf_map *map, const void *key)
 
  static bool connect_send(const char *cgroup_path)
  {
-	bool res = true;
  	int server_fd = -1, client_fd = -1;
+	struct pollfd pollfd;
+	bool res = true;
 
  	if (join_cgroup(cgroup_path))
  		goto out_clean;

tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c static bool connect_send(const char *cgroup_path) · line 81

Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/cg_storage_multi.c +4 -0
@@ -73,6 +75,11 @@ static bool connect_send(const char *cgroup_path)
  	if (send(client_fd, "message", strlen("message"), 0) < 0)
  		goto out_clean;
 
+	pollfd.fd = server_fd;
+	pollfd.events = POLLIN;
+	if (poll(&pollfd, 1, 1000) != 1)
+		goto out_clean;

Thanks for the fix. The slowness explanation makes sense.

A nit. All start_server() has a 3s SO_RCVTIMEO by default. How about a read() here instead of a poll(). Easier to change the default read timeout for all tests if needed.