Author: Siva Chandra Reddy Date: 2021-01-06T15:07:44-08:00 New Revision: f9e858f5fd74d0a1b127bf8979dc36bcad8b06d2
URL: https://github.com/llvm/llvm-project/commit/f9e858f5fd74d0a1b127bf8979dc36bcad8b06d2 DIFF: https://github.com/llvm/llvm-project/commit/f9e858f5fd74d0a1b127bf8979dc36bcad8b06d2.diff LOG: [libc] Use a wrapper for rand instead of calling std::rand in fma tests. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D94198 Added: libc/utils/testutils/RandUtils.cpp libc/utils/testutils/RandUtils.h Modified: libc/test/src/math/FmaTest.h libc/utils/testutils/CMakeLists.txt Removed: ################################################################################ diff --git a/libc/test/src/math/FmaTest.h b/libc/test/src/math/FmaTest.h index c39c4ad0f1da..9f90c8627af9 100644 --- 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 <random> +#include "utils/testutils/RandUtils.h" namespace mpfr = __llvm_libc::testing::mpfr; @@ -32,8 +31,9 @@ class FmaTestTemplate : public __llvm_libc::testing::Test { 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/libc/utils/testutils/CMakeLists.txt b/libc/utils/testutils/CMakeLists.txt index 70237ddc1f8d..c39a8399895d 100644 --- a/libc/utils/testutils/CMakeLists.txt +++ b/libc/utils/testutils/CMakeLists.txt @@ -5,6 +5,8 @@ endif() add_llvm_library( libc_test_utils + RandUtils.cpp + RandUtils.h StreamWrapper.cpp StreamWrapper.h ${EFFile} diff --git a/libc/utils/testutils/RandUtils.cpp b/libc/utils/testutils/RandUtils.cpp new file mode 100644 index 000000000000..0ccc62327f05 --- /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 <cstdlib> + +namespace __llvm_libc { +namespace testutils { + +int rand() { return std::rand(); } + +} // namespace testutils +} // namespace __llvm_libc diff --git a/libc/utils/testutils/RandUtils.h b/libc/utils/testutils/RandUtils.h new file mode 100644 index 000000000000..b65a98bfed21 --- /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 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits