Skip to content

Commit

Permalink
[libc][NFC] Remove use of StreamWrapper from math differential tests.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Siva Chandra Reddy committed Apr 17, 2023
1 parent 06387f9 commit df8c78c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -121,7 +121,7 @@ template <typename T> class BinaryOpSingleOutputDiff {

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),
Expand Down
13 changes: 10 additions & 3 deletions libc/test/src/math/differential_testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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})
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -24,7 +25,7 @@ template <typename T> class SingleInputSingleOutputDiff {

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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions libc/utils/testutils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ add_library(
ExecuteFunction.h
${FDReaderFile}
FDReader.h
Timer.h
Timer.cpp
RoundingModeUtils.cpp
)

0 comments on commit df8c78c

Please sign in to comment.