hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 898c11b700c66a7af54e09d33fea1d82a058f49e
parent 47283a38816d6f98c7ecf89bb973939a8f111e5e
Author: Lorenz (xha) <me@xha.li>
Date:   Sat, 25 Nov 2023 15:17:59 +0100

rt: make the signal test platform specific

Signed-off-by: Lorenz (xha) <me@xha.li>

Diffstat:
Mrt/+freebsd/signal.ha | 42++++++++++++++++++++++++++++++++++++++++++
Mrt/+linux/signal.ha | 42++++++++++++++++++++++++++++++++++++++++++
Drt/+test/signal_test.ha | 44--------------------------------------------
3 files changed, 84 insertions(+), 44 deletions(-)

diff --git a/rt/+freebsd/signal.ha b/rt/+freebsd/signal.ha @@ -38,3 +38,45 @@ export fn sigfillset(set: *sigset) (void | errno) = { set.__bits[i] = ~0u32; }; }; + +// Test sigset operations do not fail for valid signal numbers. +@test fn sigset_valid_signum() void = { + let set: sigset = sigset { ... }; + sigemptyset(&set); + + assert(!(sigismember(&set, 1) is errno), "Unexpected error"); + assert(!(sigismember(&set, 15) is errno), "Unexpected error"); + assert(!(sigismember(&set, NSIG) is errno), "Unexpected error"); + + assert(!(sigaddset(&set, 1) is errno), "Unexpected error"); + assert(!(sigaddset(&set, 15) is errno), "Unexpected error"); + assert(!(sigaddset(&set, NSIG) is errno), "Unexpected error"); + + // It's ok to add a signal that is already present in the set. + assert(!(sigaddset(&set, 1) is errno), "Unexpected error"); + + assert(!(sigdelset(&set, 1) is errno), "Unexpected error"); + assert(!(sigdelset(&set, 15) is errno), "Unexpected error"); + assert(!(sigdelset(&set, NSIG) is errno), "Unexpected error"); + + // It's ok to delete a signal that is not present in the set. + assert(!(sigdelset(&set, 10) is errno), "Unexpected error"); +}; + +// Test sigset operations fail for invalid signal numbers. +@test fn sigset_invalid_signum() void = { + let set: sigset = sigset { ... }; + sigemptyset(&set); + + assert(sigismember(&set, -1) is errno, "Expected error"); + assert(sigismember(&set, 0) is errno, "Expected error"); + assert(sigismember(&set, NSIG + 1) is errno, "Expected error"); + + assert(sigaddset(&set, -1) is errno, "Expected error"); + assert(sigaddset(&set, 0) is errno, "Expected error"); + assert(sigaddset(&set, NSIG + 1) is errno, "Expected error"); + + assert(sigdelset(&set, -1) is errno, "Expected error"); + assert(sigdelset(&set, 0) is errno, "Expected error"); + assert(sigdelset(&set, NSIG + 1) is errno, "Expected error"); +}; diff --git a/rt/+linux/signal.ha b/rt/+linux/signal.ha @@ -34,3 +34,45 @@ export fn sigismember(set: *sigset, signum: int) (bool | errno) = { export fn sigfillset(set: *sigset) void = { set.__val[0] = ~0u64; }; + +// Test sigset operations do not fail for valid signal numbers. +@test fn sigset_valid_signum() void = { + let set: sigset = sigset { ... }; + sigemptyset(&set); + + assert(!(sigismember(&set, 1) is errno), "Unexpected error"); + assert(!(sigismember(&set, 15) is errno), "Unexpected error"); + assert(!(sigismember(&set, NSIG) is errno), "Unexpected error"); + + assert(!(sigaddset(&set, 1) is errno), "Unexpected error"); + assert(!(sigaddset(&set, 15) is errno), "Unexpected error"); + assert(!(sigaddset(&set, NSIG) is errno), "Unexpected error"); + + // It's ok to add a signal that is already present in the set. + assert(!(sigaddset(&set, 1) is errno), "Unexpected error"); + + assert(!(sigdelset(&set, 1) is errno), "Unexpected error"); + assert(!(sigdelset(&set, 15) is errno), "Unexpected error"); + assert(!(sigdelset(&set, NSIG) is errno), "Unexpected error"); + + // It's ok to delete a signal that is not present in the set. + assert(!(sigdelset(&set, 10) is errno), "Unexpected error"); +}; + +// Test sigset operations fail for invalid signal numbers. +@test fn sigset_invalid_signum() void = { + let set: sigset = sigset { ... }; + sigemptyset(&set); + + assert(sigismember(&set, -1) is errno, "Expected error"); + assert(sigismember(&set, 0) is errno, "Expected error"); + assert(sigismember(&set, NSIG + 1) is errno, "Expected error"); + + assert(sigaddset(&set, -1) is errno, "Expected error"); + assert(sigaddset(&set, 0) is errno, "Expected error"); + assert(sigaddset(&set, NSIG + 1) is errno, "Expected error"); + + assert(sigdelset(&set, -1) is errno, "Expected error"); + assert(sigdelset(&set, 0) is errno, "Expected error"); + assert(sigdelset(&set, NSIG + 1) is errno, "Expected error"); +}; diff --git a/rt/+test/signal_test.ha b/rt/+test/signal_test.ha @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -// (c) Hare authors <https://harelang.org> - -// Test sigset operations do not fail for valid signal numbers. -@test fn sigset_valid_signum() void = { - let set = sigset { ... }; - sigemptyset(&set); - - assert(!(sigismember(&set, 1) is errno), "Unexpected error"); - assert(!(sigismember(&set, 15) is errno), "Unexpected error"); - assert(!(sigismember(&set, NSIG) is errno), "Unexpected error"); - - assert(!(sigaddset(&set, 1) is errno), "Unexpected error"); - assert(!(sigaddset(&set, 15) is errno), "Unexpected error"); - assert(!(sigaddset(&set, NSIG) is errno), "Unexpected error"); - - // It's ok to add a signal that is already present in the set. - assert(!(sigaddset(&set, 1) is errno), "Unexpected error"); - - assert(!(sigdelset(&set, 1) is errno), "Unexpected error"); - assert(!(sigdelset(&set, 15) is errno), "Unexpected error"); - assert(!(sigdelset(&set, NSIG) is errno), "Unexpected error"); - - // It's ok to delete a signal that is not present in the set. - assert(!(sigdelset(&set, 10) is errno), "Unexpected error"); -}; - -// Test sigset operations fail for invalid signal numbers. -@test fn sigset_invalid_signum() void = { - let set = sigset { ... }; - sigemptyset(&set); - - assert(sigismember(&set, -1) is errno, "Expected error"); - assert(sigismember(&set, 0) is errno, "Expected error"); - assert(sigismember(&set, NSIG + 1) is errno, "Expected error"); - - assert(sigaddset(&set, -1) is errno, "Expected error"); - assert(sigaddset(&set, 0) is errno, "Expected error"); - assert(sigaddset(&set, NSIG + 1) is errno, "Expected error"); - - assert(sigdelset(&set, -1) is errno, "Expected error"); - assert(sigdelset(&set, 0) is errno, "Expected error"); - assert(sigdelset(&set, NSIG + 1) is errno, "Expected error"); -};