diff mbox series

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

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

Checks

Context Check Description
netdev/cover_letter success Series has a cover letter
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 10 maintainers not CCed: linux-kselftest@vger.kernel.org netdev@vger.kernel.org shuah@kernel.org kafai@fb.com daniel@iogearbox.net yhs@fb.com john.fastabend@gmail.com songliubraving@fb.com kpsingh@kernel.org ast@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success No static functions without inline keyword in header files
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary

Commit Message

Yucong Sun Oct. 6, 2021, 6:56 p.m. UTC
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(-)

Comments

Andrii Nakryiko Oct. 8, 2021, 10:27 p.m. UTC | #1
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 mbox series

Patch

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");