[libc-commits] [libc] df8c78c - [libc][NFC] Remove use of StreamWrapper from math differential tests.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Sun Apr 16 22:21:11 PDT 2023


Author: Siva Chandra Reddy
Date: 2023-04-17T05:20:53Z
New Revision: df8c78c5b5c0c41de7c5e274406c2e292c3f0259

URL: https://github.com/llvm/llvm-project/commit/df8c78c5b5c0c41de7c5e274406c2e292c3f0259
DIFF: https://github.com/llvm/llvm-project/commit/df8c78c5b5c0c41de7c5e274406c2e292c3f0259.diff

LOG: [libc][NFC] Remove use of StreamWrapper from math differential tests.

Along the way, the utility Timer has been moved to the math differential
test directory.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D148450

Added: 
    libc/test/src/math/differential_testing/Timer.cpp
    libc/test/src/math/differential_testing/Timer.h

Modified: 
    libc/test/src/math/differential_testing/BinaryOpSingleOutputDiff.h
    libc/test/src/math/differential_testing/CMakeLists.txt
    libc/test/src/math/differential_testing/SingleInputSingleOutputDiff.h
    libc/utils/testutils/CMakeLists.txt

Removed: 
    libc/utils/testutils/Timer.cpp
    libc/utils/testutils/Timer.h


################################################################################
diff  --git a/libc/test/src/math/
diff erential_testing/BinaryOpSingleOutputDiff.h b/libc/test/src/math/
diff erential_testing/BinaryOpSingleOutputDiff.h
index 62f9e7fa6da5d..ccab38e528790 100644
--- a/libc/test/src/math/
diff erential_testing/BinaryOpSingleOutputDiff.h
+++ b/libc/test/src/math/
diff erential_testing/BinaryOpSingleOutputDiff.h
@@ -7,8 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/FPUtil/FPBits.h"
-#include "utils/testutils/StreamWrapper.h"
-#include "utils/testutils/Timer.h"
+#include "test/src/math/
diff erential_testing/Timer.h"
+
+#include <fstream>
 
 namespace __llvm_libc {
 namespace testing {
@@ -24,8 +25,7 @@ template <typename T> class BinaryOpSingleOutputDiff {
 
   static uint64_t run_
diff _in_range(Func myFunc, Func otherFunc,
                                     UIntType startingBit, UIntType endingBit,
-                                    UIntType N,
-                                    testutils::OutputFileStream &log) {
+                                    UIntType N, std::ofstream &log) {
     uint64_t result = 0;
     if (endingBit < startingBit) {
       return result;
@@ -58,7 +58,7 @@ template <typename T> class BinaryOpSingleOutputDiff {
 
   static void run_perf_in_range(Func myFunc, Func otherFunc,
                                 UIntType startingBit, UIntType endingBit,
-                                UIntType N, testutils::OutputFileStream &log) {
+                                UIntType N, std::ofstream &log) {
     auto runner = [=](Func func) {
       volatile T result;
       if (endingBit < startingBit) {
@@ -105,7 +105,7 @@ template <typename T> class BinaryOpSingleOutputDiff {
   }
 
   static void run_perf(Func myFunc, Func otherFunc, const char *logFile) {
-    testutils::OutputFileStream log(logFile);
+    std::ofstream log(logFile);
     log << " Performance tests with inputs in denormal range:\n";
     run_perf_in_range(myFunc, otherFunc, /* startingBit= */ UIntType(0),
                       /* endingBit= */ FPBits::MAX_SUBNORMAL, 1'000'001, log);
@@ -121,7 +121,7 @@ template <typename T> class BinaryOpSingleOutputDiff {
 
   static void run_
diff (Func myFunc, Func otherFunc, const char *logFile) {
     uint64_t 
diff Count = 0;
-    testutils::OutputFileStream log(logFile);
+    std::ofstream log(logFile);
     log << " Diff tests with inputs in denormal range:\n";
     
diff Count += run_
diff _in_range(
         myFunc, otherFunc, /* startingBit= */ UIntType(0),

diff  --git a/libc/test/src/math/
diff erential_testing/CMakeLists.txt b/libc/test/src/math/
diff erential_testing/CMakeLists.txt
index a4ac9d5883522..f6522e89a6dc7 100644
--- a/libc/test/src/math/
diff erential_testing/CMakeLists.txt
+++ b/libc/test/src/math/
diff erential_testing/CMakeLists.txt
@@ -1,3 +1,11 @@
+add_library(
+  libc_
diff _test_utils
+  Timer.cpp
+  Timer.h
+)
+
+# A convenience target to build all 
diff erential tests.
+add_custom_target(libc-math-
diff erential-tests)
 
 function(add_
diff _binary target_name)
   cmake_parse_arguments(
@@ -39,8 +47,6 @@ function(add_
diff _binary target_name)
     ${fq_target_name}
     PRIVATE
       ${LIBC_SOURCE_DIR}
-      ${LIBC_BUILD_DIR}
-      ${LIBC_BUILD_DIR}/include
   )
   if(DIFF_COMPILE_OPTIONS)
     target_compile_options(
@@ -51,7 +57,7 @@ function(add_
diff _binary target_name)
 
   target_link_libraries(
       ${fq_target_name}
-      PRIVATE ${link_object_files} libc_test_utils)
+      PRIVATE ${link_object_files} libc_test_utils libc_
diff _test_utils)
 
   set_target_properties(${fq_target_name}
     PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
@@ -69,6 +75,7 @@ function(add_
diff _binary target_name)
     libc.src.__support.FPUtil.fp_bits
     ${fq_deps_list}
   )
+  add_dependencies(libc-math-
diff erential-tests ${fq_target_name})
 endfunction()
 
 add_header_library(

diff  --git a/libc/test/src/math/
diff erential_testing/SingleInputSingleOutputDiff.h b/libc/test/src/math/
diff erential_testing/SingleInputSingleOutputDiff.h
index 7cc7059db03a7..4805e1acac200 100644
--- a/libc/test/src/math/
diff erential_testing/SingleInputSingleOutputDiff.h
+++ b/libc/test/src/math/
diff erential_testing/SingleInputSingleOutputDiff.h
@@ -7,8 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/FPUtil/FPBits.h"
-#include "utils/testutils/StreamWrapper.h"
-#include "utils/testutils/Timer.h"
+#include "test/src/math/
diff erential_testing/Timer.h"
+
+#include <fstream>
 
 namespace __llvm_libc {
 namespace testing {
@@ -24,7 +25,7 @@ template <typename T> class SingleInputSingleOutputDiff {
 
   static void runDiff(Func myFunc, Func otherFunc, const char *logFile) {
     UIntType 
diff Count = 0;
-    testutils::OutputFileStream log(logFile);
+    std::ofstream log(logFile);
     log << "Starting 
diff  for values from 0 to " << UIntMax << '\n'
         << "Only 
diff ering results will be logged.\n\n";
     for (UIntType bits = 0;; ++bits) {
@@ -47,8 +48,7 @@ template <typename T> class SingleInputSingleOutputDiff {
   }
 
   static void runPerfInRange(Func myFunc, Func otherFunc, UIntType startingBit,
-                             UIntType endingBit,
-                             testutils::OutputFileStream &log) {
+                             UIntType endingBit, std::ofstream &log) {
     auto runner = [=](Func func) {
       volatile T result;
       for (UIntType bits = startingBit;; ++bits) {
@@ -89,7 +89,7 @@ template <typename T> class SingleInputSingleOutputDiff {
   }
 
   static void runPerf(Func myFunc, Func otherFunc, const char *logFile) {
-    testutils::OutputFileStream log(logFile);
+    std::ofstream log(logFile);
     log << " Performance tests with inputs in denormal range:\n";
     runPerfInRange(myFunc, otherFunc, /* startingBit= */ UIntType(0),
                    /* endingBit= */ FPBits::MAX_SUBNORMAL, log);

diff  --git a/libc/utils/testutils/Timer.cpp b/libc/test/src/math/
diff erential_testing/Timer.cpp
similarity index 100%
rename from libc/utils/testutils/Timer.cpp
rename to libc/test/src/math/
diff erential_testing/Timer.cpp

diff  --git a/libc/utils/testutils/Timer.h b/libc/test/src/math/
diff erential_testing/Timer.h
similarity index 100%
rename from libc/utils/testutils/Timer.h
rename to libc/test/src/math/
diff erential_testing/Timer.h

diff  --git a/libc/utils/testutils/CMakeLists.txt b/libc/utils/testutils/CMakeLists.txt
index 616a01f44de2a..2d36ae5816739 100644
--- a/libc/utils/testutils/CMakeLists.txt
+++ b/libc/utils/testutils/CMakeLists.txt
@@ -13,7 +13,5 @@ add_library(
   ExecuteFunction.h
   ${FDReaderFile}
   FDReader.h
-  Timer.h
-  Timer.cpp
   RoundingModeUtils.cpp
 )


        


More information about the libc-commits mailing list