Skip to content

Commit

Permalink
Make some unit tests cheaper in DEBUG mode (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
joka921 authored Sep 6, 2022
1 parent 8e2238b commit b50aabe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/native-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=$(pwd)/toolchains/${{matrix.compiler}}.cmake -DADDITIONAL_COMPILER_FLAGS="${{matrix.warnings}}" -DUSE_PARALLEL=true
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=$(pwd)/toolchains/${{matrix.compiler}}.cmake -DADDITIONAL_COMPILER_FLAGS="${{matrix.warnings}}" -DUSE_PARALLEL=true -DRUN_EXPENSIVE_TESTS=true

- name: Build
# Build your program with the given configuration
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ if (USE_TREE_BASED_CACHE)
add_definitions("-D_QLEVER_USE_TREE_BASED_CACHE")
endif()

if (RUN_EXPENSIVE_TESTS)
message(STATUS "Running expensive unit tests. This is only recommended in release builds")
add_definitions("-DQLEVER_RUN_EXPENSIVE_TESTS")
endif()

################################
# STXXL
################################
Expand Down
13 changes: 10 additions & 3 deletions test/ValueIdTestHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
#include "../src/global/ValueId.h"
#include "../src/util/Random.h"

// Enabling cheaper unit tests when building in Debug mode
#ifdef QLEVER_RUN_EXPENSIVE_TESTS
static constexpr size_t numElements = 10'000;
#else
static constexpr size_t numElements = 10;
#endif

inline auto positiveRepresentableDoubleGenerator = RandomDoubleGenerator(
ValueId::minPositiveDouble, std::numeric_limits<double>::max());
inline auto negativeRepresentableDoubleGenerator = RandomDoubleGenerator(
Expand Down Expand Up @@ -49,7 +56,7 @@ inline uint64_t getTextRecordIndex(ValueId id) {
inline auto addIdsFromGenerator = [](auto& generator, auto makeIds,
std::vector<ValueId>& ids) {
SlowRandomIntGenerator<uint8_t> numRepetitionGenerator(1, 4);
for (size_t i = 0; i < 10'000; ++i) {
for (size_t i = 0; i < numElements; ++i) {
auto randomValue = generator();
auto numRepetitions = numRepetitionGenerator();
for (size_t j = 0; j < numRepetitions; ++j) {
Expand All @@ -64,7 +71,7 @@ inline auto makeRandomDoubleIds = []() {
addIdsFromGenerator(negativeRepresentableDoubleGenerator,
&ValueId::makeFromDouble, ids);

for (size_t i = 0; i < 1000; ++i) {
for (size_t i = 0; i < numElements; ++i) {
ids.push_back(ValueId::makeFromDouble(0.0));
ids.push_back(ValueId::makeFromDouble(-0.0));
auto inf = std::numeric_limits<double>::infinity();
Expand All @@ -91,7 +98,7 @@ inline auto makeRandomIds = []() {
addIdsFromGenerator(overflowingNBitGenerator, &ValueId::makeFromInt, ids);
addIdsFromGenerator(underflowingNBitGenerator, &ValueId::makeFromInt, ids);

for (size_t i = 0; i < 10'000; ++i) {
for (size_t i = 0; i < numElements; ++i) {
ids.push_back(ValueId::makeUndefined());
}

Expand Down

0 comments on commit b50aabe

Please sign in to comment.