Using a fixed delay of 1ms is proven flaky in slow CPU environment, eg. github action CI system. This patch adds exponential backoff with a cap of 50ms, to reduce the flakyness of the test. Signed-off-by: Yucong Sun <fallentree@xxxxxx> --- tools/testing/selftests/bpf/test_maps.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index 14cea869235b..ed92d56c19cf 100644 --- a/tools/testing/selftests/bpf/test_maps.c +++ b/tools/testing/selftests/bpf/test_maps.c @@ -1400,11 +1400,16 @@ static void test_map_stress(void) static int map_update_retriable(int map_fd, const void *key, const void *value, int flags, int attempts) { + int delay = 1; + while (bpf_map_update_elem(map_fd, key, value, flags)) { if (!attempts || (errno != EAGAIN && errno != EBUSY)) return -errno; - usleep(1); + if (delay < 50) + delay *= 2; + + usleep(delay); attempts--; } -- 2.30.2