diff mbox series

[v2] waitid10: raise SIGFPE directly

Message ID 20220512131002.26093-1-chrubis@suse.cz
State Accepted
Headers show
Series [v2] waitid10: raise SIGFPE directly | expand

Commit Message

Cyril Hrubis May 12, 2022, 1:10 p.m. UTC
The SIGFPE for division by zero is actually not send for quite a few
architectures (ARM for instance) and even on x86 and x86_64 we need to
work around compiler to make it generate code that actually triggers the
condition.

So this patch fixes the test in the simplest way possible. the child
just directly raises SIGFPE instead.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/waitid/waitid10.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Jan Stancek May 12, 2022, 7:30 p.m. UTC | #1
On Thu, May 12, 2022 at 3:08 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> The SIGFPE for division by zero is actually not send for quite a few
> architectures (ARM for instance) and even on x86 and x86_64 we need to
> work around compiler to make it generate code that actually triggers the
> condition.
>
> So this patch fixes the test in the simplest way possible. the child
> just directly raises SIGFPE instead.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>

Acked-by: Jan Stancek <jstancek@redhat.com>
Li Wang May 13, 2022, 2:02 a.m. UTC | #2
On Thu, May 12, 2022 at 9:08 PM Cyril Hrubis <chrubis@suse.cz> wrote:

> The SIGFPE for division by zero is actually not send for quite a few
> architectures (ARM for instance) and even on x86 and x86_64 we need to
> work around compiler to make it generate code that actually triggers the
> condition.
>
> So this patch fixes the test in the simplest way possible. the child
> just directly raises SIGFPE instead.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  testcases/kernel/syscalls/waitid/waitid10.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/waitid/waitid10.c
> b/testcases/kernel/syscalls/waitid/waitid10.c
> index e75edd07e..388b31cc9 100644
> --- a/testcases/kernel/syscalls/waitid/waitid10.c
> +++ b/testcases/kernel/syscalls/waitid/waitid10.c
> @@ -24,12 +24,8 @@ static void run(void)
>         pid_t pidchild;
>
>         pidchild = SAFE_FORK();
> -       if (!pidchild) {
> -               volatile int a, zero = 0;
> -
> -               a = 1 / zero;
> -               exit(a);
> -       }
> +       if (!pidchild)
> +               raise(SIGFPE);
>

Better to have code comments to explain the reason here,
just for better readability.

And vote for merging before the new release as well.

Reviewed-by: Li Wang <liwang@redhat.com>




>
>         TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
>         TST_EXP_EQ_LI(infop->si_pid, pidchild);
> --
> 2.35.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
Cyril Hrubis May 13, 2022, 9:07 a.m. UTC | #3
Hi!
> Better to have code comments to explain the reason here,
> just for better readability.

What exactly should we comment there, something as:

Triggering SIGFPE by invalid instruction is not always possible, some
architectures does not trap division-by-zero at all and even when it's
possible we would have to fight the compiler optimizations that have
tendency to remove undefined operations.

> And vote for merging before the new release as well.

That's what I'm aiming for.
Li Wang May 13, 2022, 9:24 a.m. UTC | #4
> Triggering SIGFPE by invalid instruction is not always possible, some
> architectures does not trap division-by-zero at all and even when it's
> possible we would have to fight the compiler optimizations that have
> tendency to remove undefined operations.
>

Looks good.
Cyril Hrubis May 13, 2022, 12:38 p.m. UTC | #5
Hi!
Added comment and pushed, thanks for the reviews.
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/waitid/waitid10.c b/testcases/kernel/syscalls/waitid/waitid10.c
index e75edd07e..388b31cc9 100644
--- a/testcases/kernel/syscalls/waitid/waitid10.c
+++ b/testcases/kernel/syscalls/waitid/waitid10.c
@@ -24,12 +24,8 @@  static void run(void)
 	pid_t pidchild;
 
 	pidchild = SAFE_FORK();
-	if (!pidchild) {
-		volatile int a, zero = 0;
-
-		a = 1 / zero;
-		exit(a);
-	}
+	if (!pidchild)
+		raise(SIGFPE);
 
 	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
 	TST_EXP_EQ_LI(infop->si_pid, pidchild);