diff --git a/libc/test/src/math/FmaTest.h b/libc/test/src/math/FmaTest.h --- a/libc/test/src/math/FmaTest.h +++ b/libc/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 +#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(std::rand()); + for (UIntType i = 0; i < sizeof(UIntType) / 2; ++i) { + bits = + (bits << 2) + static_cast(__llvm_libc::testutils::rand()); } return bits; } diff --git a/libc/utils/testutils/CMakeLists.txt b/libc/utils/testutils/CMakeLists.txt --- a/libc/utils/testutils/CMakeLists.txt +++ b/libc/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/libc/utils/testutils/RandUtils.h b/libc/utils/testutils/RandUtils.h new file mode 100644 --- /dev/null +++ b/libc/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 diff --git a/libc/utils/testutils/RandUtils.cpp b/libc/utils/testutils/RandUtils.cpp new file mode 100644 --- /dev/null +++ b/libc/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 + +namespace __llvm_libc { +namespace testutils { + +int rand() { return std::rand(); } + +} // namespace testutils +} // namespace __llvm_libc