[libc-commits] [libc] [libc] Remove RandUtils.(h|cpp). (PR #88044)

via libc-commits libc-commits at lists.llvm.org
Mon Apr 8 14:23:02 PDT 2024


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/88044

None

>From a7980acc634b6b47a8a370f867781499a72c1387 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Mon, 8 Apr 2024 21:20:56 +0000
Subject: [PATCH] [libc] Remove RandUtils.(h|cpp).

---
 libc/test/src/CMakeLists.txt      |  2 +-
 libc/test/src/math/CMakeLists.txt | 12 ++----------
 libc/test/src/math/FmaTest.h      |  5 ++---
 libc/test/src/math/RandUtils.cpp  | 19 -------------------
 libc/test/src/math/RandUtils.h    | 21 ---------------------
 5 files changed, 5 insertions(+), 54 deletions(-)
 delete mode 100644 libc/test/src/math/RandUtils.cpp
 delete mode 100644 libc/test/src/math/RandUtils.h

diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index 95f1768c96aac3..a5e7a2a4dee725 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -24,7 +24,7 @@ function(add_fp_unittest name)
       message(FATAL_ERROR "Hermetic math test cannot require MPFR.")
     endif()
     set(test_type UNIT_TEST_ONLY)
-    list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPFRWrapper libc_math_test_utils -lmpfr -lgmp)
+    list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPFRWrapper -lmpfr -lgmp)
   endif()
   list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
 
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 01416eefc15ef8..274018e59da5ac 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1,15 +1,5 @@
 add_custom_target(libc-math-unittests)
 
-# FIXME: We shouldn't have regular libraries created because we could be
-#        cross-compiling the tests and running through an emulator.
-if(NOT LIBC_TARGET_OS_IS_GPU)
-  add_library(
-    libc_math_test_utils
-    RandUtils.cpp
-    RandUtils.h
-  )
-endif()
-
 add_fp_unittest(
   cosf_test
   NEED_MPFR
@@ -1280,6 +1270,7 @@ add_fp_unittest(
     fmaf_test.cpp
   DEPENDS
     libc.src.math.fmaf
+    libc.src.stdlib.rand
     libc.src.__support.FPUtil.fp_bits
   FLAGS
     FMA_OPT__ONLY
@@ -1294,6 +1285,7 @@ add_fp_unittest(
     fma_test.cpp
   DEPENDS
     libc.src.math.fma
+    libc.src.stdlib.rand
     libc.src.__support.FPUtil.fp_bits
 )
 
diff --git a/libc/test/src/math/FmaTest.h b/libc/test/src/math/FmaTest.h
index 0c93ec858a12cd..a3b1c9bb8f9b8f 100644
--- a/libc/test/src/math/FmaTest.h
+++ b/libc/test/src/math/FmaTest.h
@@ -10,9 +10,9 @@
 #define LLVM_LIBC_TEST_SRC_MATH_FMATEST_H
 
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/stdlib/rand.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
-#include "test/src/math/RandUtils.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 
 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
@@ -43,8 +43,7 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::Test {
   StorageType get_random_bit_pattern() {
     StorageType bits{0};
     for (StorageType i = 0; i < sizeof(StorageType) / 2; ++i) {
-      bits = (bits << 2) +
-             static_cast<uint16_t>(LIBC_NAMESPACE::testutils::rand());
+      bits = (bits << 2) + static_cast<uint16_t>(LIBC_NAMESPACE::rand());
     }
     return bits;
   }
diff --git a/libc/test/src/math/RandUtils.cpp b/libc/test/src/math/RandUtils.cpp
deleted file mode 100644
index 0d09764f6056d6..00000000000000
--- a/libc/test/src/math/RandUtils.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-//===-- 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 LIBC_NAMESPACE {
-namespace testutils {
-
-int rand() { return std::rand(); }
-
-} // namespace testutils
-} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/math/RandUtils.h b/libc/test/src/math/RandUtils.h
deleted file mode 100644
index fecbd8eaabf2cd..00000000000000
--- a/libc/test/src/math/RandUtils.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- 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
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_TEST_SRC_MATH_RANDUTILS_H
-#define LLVM_LIBC_TEST_SRC_MATH_RANDUTILS_H
-
-namespace LIBC_NAMESPACE {
-namespace testutils {
-
-// Wrapper for std::rand.
-int rand();
-
-} // namespace testutils
-} // namespace LIBC_NAMESPACE
-
-#endif // LLVM_LIBC_TEST_SRC_MATH_RANDUTILS_H



More information about the libc-commits mailing list