From 542371d56278e9b8ef892343d32c132b26ec4aeb Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 17 Jul 2024 15:48:32 -0700 Subject: [PATCH] Build TestDriver for perf testing too --- CMakeLists.txt | 5 +++++ Internal.h | 40 +++++++++++++++++++++++++--------------- TestDriver.cpp | 7 ++++++- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bfd604..05bb11b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -353,6 +353,11 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND BUILD_TESTING) add_executable(real_data_bench RealDataBench.cpp) target_link_libraries(real_data_bench PRIVATE ${PROJECT_NAME}) set_target_properties(real_data_bench PROPERTIES SKIP_BUILD_RPATH ON) + + # fuzzer-based perf + add_executable(driver_perf TestDriver.cpp) + target_compile_definitions(driver_perf PRIVATE PERF_TEST=1) + target_link_libraries(driver_perf PRIVATE ${PROJECT_NAME}) endif() # packaging diff --git a/Internal.h b/Internal.h index 0f2e01d..ac54e62 100644 --- a/Internal.h +++ b/Internal.h @@ -578,7 +578,8 @@ inline const char *resultToStr(ConflictSet::Result r) { namespace { -template struct TestDriver { +template +struct TestDriver { Arbitrary arbitrary; explicit TestDriver(const uint8_t *data, size_t size) : arbitrary({data, size}) {} @@ -724,10 +725,14 @@ template struct TestDriver { cs.addWrites(writes, numPointWrites + numRangeWrites, v); CALLGRIND_STOP_INSTRUMENTATION; - refImpl.addWrites(writes, numPointWrites + numRangeWrites, v); + if constexpr (kEnableAssertions) { + refImpl.addWrites(writes, numPointWrites + numRangeWrites, v); + } cs.setOldestVersion(oldestVersion); - refImpl.setOldestVersion(oldestVersion); + if constexpr (kEnableAssertions) { + refImpl.setOldestVersion(oldestVersion); + } #ifdef THREAD_TEST thread2.join(); @@ -821,16 +826,18 @@ template struct TestDriver { cs.check(reads, results1, numPointReads + numRangeReads); CALLGRIND_STOP_INSTRUMENTATION; - // Call remaining const methods - cs.getBytes(); - ConflictSet::MetricsV1 *m; - int count; - cs.getMetricsV1(&m, &count); - for (int i = 0; i < count; ++i) { - m[i].getValue(); - } + if constexpr (kEnableAssertions) { + // Call remaining const methods + cs.getBytes(); + ConflictSet::MetricsV1 *m; + int count; + cs.getMetricsV1(&m, &count); + for (int i = 0; i < count; ++i) { + m[i].getValue(); + } - refImpl.check(reads, results2, numPointReads + numRangeReads); + refImpl.check(reads, results2, numPointReads + numRangeReads); + } auto compareResults = [reads](ConflictSet::Result *results1, ConflictSet::Result *results2, int count) { @@ -857,9 +864,12 @@ template struct TestDriver { return true; }; - if (!compareResults(results1, results2, numPointReads + numRangeReads)) { - ok = false; - return true; + if constexpr (kEnableAssertions) { + if (!compareResults(results1, results2, + numPointReads + numRangeReads)) { + ok = false; + return true; + } } #ifdef THREAD_TEST diff --git a/TestDriver.cpp b/TestDriver.cpp index 1529afe..e1d24b3 100644 --- a/TestDriver.cpp +++ b/TestDriver.cpp @@ -3,13 +3,18 @@ #include #include +#ifndef PERF_TEST +#define PERF_TEST 0 +#endif + int main(int argc, char **argv) { for (int i = 1; i < argc; ++i) { std::ifstream t(argv[i], std::ios::binary); std::stringstream buffer; buffer << t.rdbuf(); auto str = buffer.str(); - TestDriver driver{(const uint8_t *)str.data(), str.size()}; + TestDriver driver{(const uint8_t *)str.data(), + str.size()}; while (!driver.next()) ; if (!driver.ok) {