Skip to content

Commit 832669c

Browse files
committed
chore: update tests
1 parent 26baea9 commit 832669c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

libc/test/src/stdfix/IdivTest.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "test/UnitTest/Test.h"
1010

1111
#include "src/__support/fixed_point/fx_rep.h"
12+
#include "src/__support/macros/sanitizer.h"
13+
14+
#include <signal.h>
1215

1316
template <typename T, typename XType>
1417
class IdivTest : public LIBC_NAMESPACE::testing::Test {
@@ -45,19 +48,44 @@ class IdivTest : public LIBC_NAMESPACE::testing::Test {
4548
EXPECT_EQ(func(4.2, 6.9), static_cast<XType>(0));
4649
EXPECT_EQ(func(4.5, 2.2), static_cast<XType>(2));
4750
EXPECT_EQ(func(2.2, 1.1), static_cast<XType>(2));
51+
EXPECT_EQ(func(2.25, 1.0), static_cast<XType>(2));
52+
EXPECT_EQ(func(2.25, 3.0), static_cast<XType>(0));
4853

4954
if constexpr (is_signed) {
5055
EXPECT_EQ(func(4.2, -6.9), static_cast<XType>(0));
5156
EXPECT_EQ(func(-6.9, 4.2), static_cast<XType>(-1));
5257
EXPECT_EQ(func(-2.5, 1.25), static_cast<XType>(-2));
58+
EXPECT_EQ(func(-2.25, 1.0), static_cast<XType>(-2));
59+
EXPECT_EQ(func(2.25, -3.0), static_cast<XType>(0));
5360
}
5461
}
5562
}
63+
64+
void testInvalidNumbers(IdivFunc func) {
65+
constexpr bool has_integral = (FXRep::INTEGRAL_LEN > 0);
66+
67+
EXPECT_DEATH([func] { func(0.5, 0.0); }, WITH_SIGNAL(SIGILL));
68+
if constexpr (has_integral) {
69+
EXPECT_DEATH([func] { func(2.5, 0.0); }, WITH_SIGNAL(SIGSEGV));
70+
}
71+
}
5672
};
5773

74+
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
75+
#define LIST_IDIV_TESTS(Name, T, XTYpe, func) \
76+
using LlvmLibcIdiv##Name##Test = IdivTest<T, XType>; \
77+
TEST_F(LlvmLibcIdiv##Name##Test, InvalidNumbers) { \
78+
testInvalidNumbers(&func); \
79+
} \
80+
TEST_F(LlvmLibcIdiv##Name##Test, SpecialNumbers) { \
81+
testSpecialNumbers(&func); \
82+
} \
83+
static_assert(true, "Require semicolon.")
84+
#else
5885
#define LIST_IDIV_TESTS(Name, T, XType, func) \
5986
using LlvmLibcIdiv##Name##Test = IdivTest<T, XType>; \
6087
TEST_F(LlvmLibcIdiv##Name##Test, SpecialNumbers) { \
6188
testSpecialNumbers(&func); \
6289
} \
6390
static_assert(true, "Require semicolon.")
91+
#endif // LIBC_HAS_ADDRESS_SANITIZER

0 commit comments

Comments
 (0)