Skip to content

Commit fd8feee

Browse files
yonghong-songgregkh
authored andcommitted
selftests/bpf: Fix flaky send_signal test
[ Upstream commit b16ac5b ] libbpf CI has reported send_signal test is flaky although I am not able to reproduce it in my local environment. But I am able to reproduce with on-demand libbpf CI ([1]). Through code analysis, the following is possible reason. The failed subtest runs bpf program in softirq environment. Since bpf_send_signal() only sends to a fork of "test_progs" process. If the underlying current task is not "test_progs", bpf_send_signal() will not be triggered and the subtest will fail. To reduce the chances where the underlying process is not the intended one, this patch boosted scheduling priority to -20 (highest allowed by setpriority() call). And I did 10 runs with on-demand libbpf CI with this patch and I didn't observe any failures. [1] https://github.com/libbpf/libbpf/actions/workflows/ondemand.yml Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20210817190923.3186725-1-yhs@fb.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2a456db commit fd8feee

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎tools/testing/selftests/bpf/prog_tests/send_signal.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <test_progs.h>
3+
#include <sys/time.h>
4+
#include <sys/resource.h>
35
#include "test_send_signal_kern.skel.h"
46

57
static volatile int sigusr1_received = 0;
@@ -41,12 +43,23 @@ static void test_send_signal_common(struct perf_event_attr *attr,
4143
}
4244

4345
if (pid == 0) {
46+
int old_prio;
47+
4448
/* install signal handler and notify parent */
4549
signal(SIGUSR1, sigusr1_handler);
4650

4751
close(pipe_c2p[0]); /* close read */
4852
close(pipe_p2c[1]); /* close write */
4953

54+
/* boost with a high priority so we got a higher chance
55+
* that if an interrupt happens, the underlying task
56+
* is this process.
57+
*/
58+
errno = 0;
59+
old_prio = getpriority(PRIO_PROCESS, 0);
60+
ASSERT_OK(errno, "getpriority");
61+
ASSERT_OK(setpriority(PRIO_PROCESS, 0, -20), "setpriority");
62+
5063
/* notify parent signal handler is installed */
5164
CHECK(write(pipe_c2p[1], buf, 1) != 1, "pipe_write", "err %d\n", -errno);
5265

@@ -62,6 +75,9 @@ static void test_send_signal_common(struct perf_event_attr *attr,
6275
/* wait for parent notification and exit */
6376
CHECK(read(pipe_p2c[0], buf, 1) != 1, "pipe_read", "err %d\n", -errno);
6477

78+
/* restore the old priority */
79+
ASSERT_OK(setpriority(PRIO_PROCESS, 0, old_prio), "setpriority");
80+
6581
close(pipe_c2p[1]);
6682
close(pipe_p2c[0]);
6783
exit(0);

0 commit comments

Comments
 (0)