[libc][NFC] Remove use of StreamWrapper from math differential tests.
authorSiva Chandra Reddy <sivachandra@google.com>
Sun, 16 Apr 2023 05:40:07 +0000 (05:40 +0000)
committerSiva Chandra Reddy <sivachandra@google.com>
Mon, 17 Apr 2023 05:20:53 +0000 (05:20 +0000)
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

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/test/src/math/differential_testing/Timer.cpp [moved from libc/utils/testutils/Timer.cpp with 100% similarity]
libc/test/src/math/differential_testing/Timer.h [moved from libc/utils/testutils/Timer.h with 100% similarity]
libc/utils/testutils/CMakeLists.txt

index 62f9e7f..ccab38e 100644 (file)
@@ -7,8 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/FPUtil/FPBits.h"
-#include "utils/testutils/StreamWrapper.h"
-#include "utils/testutils/Timer.h"
+#include "test/src/math/differential_testing/Timer.h"
+
+#include <fstream>
 
 namespace __llvm_libc {
 namespace testing {
@@ -24,8 +25,7 @@ public:
 
   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 @@ public:
 
   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 @@ public:
   }
 
   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 @@ public:
 
   static void run_diff(Func myFunc, Func otherFunc, const char *logFile) {
     uint64_t diffCount = 0;
-    testutils::OutputFileStream log(logFile);
+    std::ofstream log(logFile);
     log << " Diff tests with inputs in denormal range:\n";
     diffCount += run_diff_in_range(
         myFunc, otherFunc, /* startingBit= */ UIntType(0),
index a4ac9d5..f6522e8 100644 (file)
@@ -1,3 +1,11 @@
+add_library(
+  libc_diff_test_utils
+  Timer.cpp
+  Timer.h
+)
+
+# A convenience target to build all differential tests.
+add_custom_target(libc-math-differential-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-differential-tests ${fq_target_name})
 endfunction()
 
 add_header_library(
index 7cc7059..4805e1a 100644 (file)
@@ -7,8 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/FPUtil/FPBits.h"
-#include "utils/testutils/StreamWrapper.h"
-#include "utils/testutils/Timer.h"
+#include "test/src/math/differential_testing/Timer.h"
+
+#include <fstream>
 
 namespace __llvm_libc {
 namespace testing {
@@ -24,7 +25,7 @@ public:
 
   static void runDiff(Func myFunc, Func otherFunc, const char *logFile) {
     UIntType diffCount = 0;
-    testutils::OutputFileStream log(logFile);
+    std::ofstream log(logFile);
     log << "Starting diff for values from 0 to " << UIntMax << '\n'
         << "Only differing results will be logged.\n\n";
     for (UIntType bits = 0;; ++bits) {
@@ -47,8 +48,7 @@ public:
   }
 
   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 @@ public:
   }
 
   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);
index 616a01f..2d36ae5 100644 (file)
@@ -13,7 +13,5 @@ add_library(
   ExecuteFunction.h
   ${FDReaderFile}
   FDReader.h
-  Timer.h
-  Timer.cpp
   RoundingModeUtils.cpp
 )