Re: [PATCH bpf-next v6 11/14] selftests/bpf: adding random delay for send_signal test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 6, 2021 at 11:56 AM Yucong Sun <fallentree@xxxxxx> wrote:
>
> From: Yucong Sun <sunyucong@xxxxxxxxx>
>
> This patch adds random delay on waiting for the signal to arrive,
> making the test more robust.
>
> Signed-off-by: Yucong Sun <sunyucong@xxxxxxxxx>
> ---
>  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
>



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux