Message ID | 20211006185619.364369-12-fallentree@fb.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | selftests/bpf: Add parallelism to test_progs | expand |
On Wed, Oct 6, 2021 at 11:56 AM Yucong Sun <fallentree@fb.com> wrote: > > From: Yucong Sun <sunyucong@gmail.com> > > This patch adds random delay on waiting for the signal to arrive, > making the test more robust. > > Signed-off-by: Yucong Sun <sunyucong@gmail.com> > --- > tools/testing/selftests/bpf/prog_tests/send_signal.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c b/tools/testing/selftests/bpf/prog_tests/send_signal.c > index 776916b61c40..6200256243f2 100644 > --- a/tools/testing/selftests/bpf/prog_tests/send_signal.c > +++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c > @@ -19,6 +19,7 @@ static void test_send_signal_common(struct perf_event_attr *attr, > int err = -1, pmu_fd = -1; > char buf[256]; > pid_t pid; > + int attempts = 100; > > if (!ASSERT_OK(pipe(pipe_c2p), "pipe_c2p")) > return; > @@ -63,7 +64,10 @@ static void test_send_signal_common(struct perf_event_attr *attr, > ASSERT_EQ(read(pipe_p2c[0], buf, 1), 1, "pipe_read"); > > /* wait a little for signal handler */ > - sleep(1); > + while (attempts > 0 && !sigusr1_received) { This is not reliable, sigusr1_received has to be volatile or sig_atomic_t, please fix. I haven't applied this patch yet. Also, previously we slept for a second, now we can, technically, sleep only up to 100ms, would that cause any problems in practice? cc Yonghong > + attempts--; > + usleep(500 + rand() % 500); > + } > > buf[0] = sigusr1_received ? '2' : '0'; > ASSERT_EQ(write(pipe_c2p[1], buf, 1), 1, "pipe_write"); > -- > 2.30.2 >
diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c b/tools/testing/selftests/bpf/prog_tests/send_signal.c index 776916b61c40..6200256243f2 100644 --- a/tools/testing/selftests/bpf/prog_tests/send_signal.c +++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c @@ -19,6 +19,7 @@ static void test_send_signal_common(struct perf_event_attr *attr, int err = -1, pmu_fd = -1; char buf[256]; pid_t pid; + int attempts = 100; if (!ASSERT_OK(pipe(pipe_c2p), "pipe_c2p")) return; @@ -63,7 +64,10 @@ static void test_send_signal_common(struct perf_event_attr *attr, ASSERT_EQ(read(pipe_p2c[0], buf, 1), 1, "pipe_read"); /* wait a little for signal handler */ - sleep(1); + while (attempts > 0 && !sigusr1_received) { + attempts--; + usleep(500 + rand() % 500); + } buf[0] = sigusr1_received ? '2' : '0'; ASSERT_EQ(write(pipe_c2p[1], buf, 1), 1, "pipe_write");