[libc] Use a wrapper for rand instead of calling std::rand in fma tests.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D94198
GitOrigin-RevId: f9e858f5fd74d0a1b127bf8979dc36bcad8b06d2
diff --git a/test/src/math/FmaTest.h b/test/src/math/FmaTest.h
index c39c4ad..9f90c86 100644
--- a/test/src/math/FmaTest.h
+++ b/test/src/math/FmaTest.h
@@ -13,8 +13,7 @@
#include "utils/FPUtil/TestHelpers.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
#include "utils/UnitTest/Test.h"
-
-#include <random>
+#include "utils/testutils/RandUtils.h"
namespace mpfr = __llvm_libc::testing::mpfr;
@@ -32,8 +31,9 @@
UIntType getRandomBitPattern() {
UIntType bits{0};
- for (size_t i = 0; i < sizeof(UIntType) / 2; ++i) {
- bits = (bits << 2) + static_cast<uint16_t>(std::rand());
+ for (UIntType i = 0; i < sizeof(UIntType) / 2; ++i) {
+ bits =
+ (bits << 2) + static_cast<uint16_t>(__llvm_libc::testutils::rand());
}
return bits;
}
diff --git a/utils/testutils/CMakeLists.txt b/utils/testutils/CMakeLists.txt
index 70237dd..c39a839 100644
--- a/utils/testutils/CMakeLists.txt
+++ b/utils/testutils/CMakeLists.txt
@@ -5,6 +5,8 @@
add_llvm_library(
libc_test_utils
+ RandUtils.cpp
+ RandUtils.h
StreamWrapper.cpp
StreamWrapper.h
${EFFile}
diff --git a/utils/testutils/RandUtils.cpp b/utils/testutils/RandUtils.cpp
new file mode 100644
index 0000000..0ccc623
--- /dev/null
+++ b/utils/testutils/RandUtils.cpp
@@ -0,0 +1,19 @@
+//===-- RandUtils.cpp -----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "RandUtils.h"
+
+#include <cstdlib>
+
+namespace __llvm_libc {
+namespace testutils {
+
+int rand() { return std::rand(); }
+
+} // namespace testutils
+} // namespace __llvm_libc
diff --git a/utils/testutils/RandUtils.h b/utils/testutils/RandUtils.h
new file mode 100644
index 0000000..b65a98b
--- /dev/null
+++ b/utils/testutils/RandUtils.h
@@ -0,0 +1,16 @@
+//===-- RandUtils.h ---------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+namespace __llvm_libc {
+namespace testutils {
+
+// Wrapper for std::rand.
+int rand();
+
+} // namespace testutils
+} // namespace __llvm_libc