Skip to content

Commit 71ffc1f

Browse files
authored
[libc] Initialize rand for fma tests (#88055)
Summary: The GPU build will have some random garbage here since we do not support initializers for the underlying implementation. Manually set the seed to 1.
1 parent 614a578 commit 71ffc1f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

libc/test/src/math/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ add_fp_unittest(
12711271
DEPENDS
12721272
libc.src.math.fmaf
12731273
libc.src.stdlib.rand
1274+
libc.src.stdlib.srand
12741275
libc.src.__support.FPUtil.fp_bits
12751276
FLAGS
12761277
FMA_OPT__ONLY
@@ -1286,6 +1287,7 @@ add_fp_unittest(
12861287
DEPENDS
12871288
libc.src.math.fma
12881289
libc.src.stdlib.rand
1290+
libc.src.stdlib.srand
12891291
libc.src.__support.FPUtil.fp_bits
12901292
)
12911293

libc/test/src/math/FmaTest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "src/__support/FPUtil/FPBits.h"
1313
#include "src/stdlib/rand.h"
14+
#include "src/stdlib/srand.h"
1415
#include "test/UnitTest/FPMatcher.h"
1516
#include "test/UnitTest/Test.h"
1617
#include "utils/MPFRWrapper/MPFRUtils.h"
@@ -76,6 +77,7 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::Test {
7677
void test_subnormal_range(Func func) {
7778
constexpr StorageType COUNT = 100'001;
7879
constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
80+
LIBC_NAMESPACE::srand(1);
7981
for (StorageType v = MIN_SUBNORMAL, w = MAX_SUBNORMAL;
8082
v <= MAX_SUBNORMAL && w >= MIN_SUBNORMAL; v += STEP, w -= STEP) {
8183
T x = FPBits(get_random_bit_pattern()).get_val(), y = FPBits(v).get_val(),
@@ -89,6 +91,7 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::Test {
8991
void test_normal_range(Func func) {
9092
constexpr StorageType COUNT = 100'001;
9193
constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
94+
LIBC_NAMESPACE::srand(1);
9295
for (StorageType v = MIN_NORMAL, w = MAX_NORMAL;
9396
v <= MAX_NORMAL && w >= MIN_NORMAL; v += STEP, w -= STEP) {
9497
T x = FPBits(v).get_val(), y = FPBits(w).get_val(),

0 commit comments

Comments
 (0)