Build TestDriver for perf testing too

This commit is contained in:
2024-07-17 15:48:32 -07:00
parent 958a4e2d0e
commit 542371d562
3 changed files with 36 additions and 16 deletions

View File

@@ -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

View File

@@ -578,7 +578,8 @@ inline const char *resultToStr(ConflictSet::Result r) {
namespace {
template <class ConflictSetImpl> struct TestDriver {
template <class ConflictSetImpl, bool kEnableAssertions = true>
struct TestDriver {
Arbitrary arbitrary;
explicit TestDriver(const uint8_t *data, size_t size)
: arbitrary({data, size}) {}
@@ -724,10 +725,14 @@ template <class ConflictSetImpl> struct TestDriver {
cs.addWrites(writes, numPointWrites + numRangeWrites, v);
CALLGRIND_STOP_INSTRUMENTATION;
if constexpr (kEnableAssertions) {
refImpl.addWrites(writes, numPointWrites + numRangeWrites, v);
}
cs.setOldestVersion(oldestVersion);
if constexpr (kEnableAssertions) {
refImpl.setOldestVersion(oldestVersion);
}
#ifdef THREAD_TEST
thread2.join();
@@ -821,6 +826,7 @@ template <class ConflictSetImpl> struct TestDriver {
cs.check(reads, results1, numPointReads + numRangeReads);
CALLGRIND_STOP_INSTRUMENTATION;
if constexpr (kEnableAssertions) {
// Call remaining const methods
cs.getBytes();
ConflictSet::MetricsV1 *m;
@@ -831,6 +837,7 @@ template <class ConflictSetImpl> struct TestDriver {
}
refImpl.check(reads, results2, numPointReads + numRangeReads);
}
auto compareResults = [reads](ConflictSet::Result *results1,
ConflictSet::Result *results2, int count) {
@@ -857,10 +864,13 @@ template <class ConflictSetImpl> struct TestDriver {
return true;
};
if (!compareResults(results1, results2, numPointReads + numRangeReads)) {
if constexpr (kEnableAssertions) {
if (!compareResults(results1, results2,
numPointReads + numRangeReads)) {
ok = false;
return true;
}
}
#ifdef THREAD_TEST
thread2.join();

View File

@@ -3,13 +3,18 @@
#include <fstream>
#include <sstream>
#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<ConflictSet> driver{(const uint8_t *)str.data(), str.size()};
TestDriver<ConflictSet, !PERF_TEST> driver{(const uint8_t *)str.data(),
str.size()};
while (!driver.next())
;
if (!driver.ok) {