From c2513f4e813d441952d9f1440e83ad3c4c60d247 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Tue, 13 Aug 2024 11:24:39 +0200 Subject: [PATCH] test: add env variable to allow skipping slow tests in CI --- .docker/build-linux.sh | 5 +++++ test/block_cache_test.cpp | 4 +++- test/block_merger_test.cpp | 23 +++++++++++++++++------ test/dwarfs_test.cpp | 5 ++++- test/filesystem_test.cpp | 2 ++ test/test_helpers.cpp | 5 +++++ test/test_helpers.h | 12 ++++++++++++ test/tool_main_test.cpp | 11 +++++++++-- test/tools_test.cpp | 11 +++++++---- 9 files changed, 64 insertions(+), 14 deletions(-) diff --git a/.docker/build-linux.sh b/.docker/build-linux.sh index 8b052f09..3b88ce22 100755 --- a/.docker/build-linux.sh +++ b/.docker/build-linux.sh @@ -34,6 +34,11 @@ if [[ "$BUILD_TYPE" != "clang-release-ninja-static" ]]; then export DWARFS_LOCAL_REPO_PATH="$LOCAL_REPO_PATH" fi +if [[ "-$BUILD_TYPE-" == *-debug-* ]] && [[ "-$BUILD_TYPE-" != *-coverage-* ]] && + [[ "-$BUILD_TYPE-" != *-[at]san-* ]] && [[ "-$BUILD_TYPE-" != *-ubsan-* ]]; then + export DWARFS_SKIP_SLOW_TESTS=1 +fi + cd "$HOME" rm -rf dwarfs dwarfs-* diff --git a/test/block_cache_test.cpp b/test/block_cache_test.cpp index dfd8ffd1..cf758a2b 100644 --- a/test/block_cache_test.cpp +++ b/test/block_cache_test.cpp @@ -133,7 +133,9 @@ TEST(block_range, compressed) { ::testing::HasSubstr("block_range: size out of range (101 > 100)"))); } -class options_test : public ::testing::TestWithParam {}; +class options_test : public ::testing::TestWithParam { + DWARFS_SLOW_FIXTURE +}; TEST_P(options_test, cache_stress) { static constexpr size_t num_threads{8}; diff --git a/test/block_merger_test.cpp b/test/block_merger_test.cpp index 0d321c90..ef3c77d7 100644 --- a/test/block_merger_test.cpp +++ b/test/block_merger_test.cpp @@ -38,6 +38,9 @@ #include +#include "test_helpers.h" + +using namespace dwarfs::test; using namespace dwarfs::writer; namespace { @@ -46,6 +49,8 @@ constexpr int const debuglevel{0}; constexpr size_t const max_runs_regular{250}; constexpr size_t const max_runs_partial{50}; +constexpr size_t const max_runs_regular_quick{25}; +constexpr size_t const max_runs_partial_quick{5}; constexpr size_t const num_runner_threads{16}; constexpr size_t const num_repetitions{4}; @@ -469,9 +474,11 @@ block_merger_test(size_t const max_runs) { TEST(block_merger, random) { using merger_type = internal::multi_queue_block_merger; - auto [passes, fails] = block_merger_test(max_runs_regular); + auto max_runs = skip_slow_tests() ? max_runs_regular_quick : max_runs_regular; - EXPECT_EQ(max_runs_regular * num_repetitions, passes); + auto [passes, fails] = block_merger_test(max_runs); + + EXPECT_EQ(max_runs * num_repetitions, passes); EXPECT_TRUE(fails.empty()) << folly::join(", ", fails); } @@ -480,9 +487,11 @@ TEST(block_merger, random_sized) { internal::multi_queue_block_merger; - auto [passes, fails] = block_merger_test(max_runs_regular); + auto max_runs = skip_slow_tests() ? max_runs_regular_quick : max_runs_regular; - EXPECT_EQ(max_runs_regular * num_repetitions, passes); + auto [passes, fails] = block_merger_test(max_runs); + + EXPECT_EQ(max_runs * num_repetitions, passes); EXPECT_TRUE(fails.empty()) << folly::join(", ", fails); } @@ -491,8 +500,10 @@ TEST(block_merger, random_sized_partial) { internal::multi_queue_block_merger; - auto [passes, fails] = block_merger_test(max_runs_partial); + auto max_runs = skip_slow_tests() ? max_runs_partial_quick : max_runs_partial; - EXPECT_EQ(max_runs_partial * num_repetitions, passes); + auto [passes, fails] = block_merger_test(max_runs); + + EXPECT_EQ(max_runs * num_repetitions, passes); EXPECT_TRUE(fails.empty()) << folly::join(", ", fails); } diff --git a/test/dwarfs_test.cpp b/test/dwarfs_test.cpp index 02f50495..83976b2f 100644 --- a/test/dwarfs_test.cpp +++ b/test/dwarfs_test.cpp @@ -576,6 +576,7 @@ std::vector const compressions{ class compression_test : public testing::TestWithParam>> { + DWARFS_SLOW_FIXTURE }; class scanner_test : public testing::TestWithParam< @@ -857,7 +858,9 @@ INSTANTIATE_TEST_SUITE_P(dwarfs, compression_regression, class file_scanner : public testing::TestWithParam< - std::tuple>> {}; + std::tuple>> { + DWARFS_SLOW_FIXTURE +}; TEST_P(file_scanner, inode_ordering) { auto [order_mode, file_hash_algo] = GetParam(); diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 56e16875..b0885411 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -214,6 +214,8 @@ std::string valid_v2_header(uint32_t section_number = 0) { } // namespace TEST(filesystem, find_image_offset) { + DWARFS_SLOW_TEST(); + test::test_logger lgr; test::os_access_mock os; diff --git a/test/test_helpers.cpp b/test/test_helpers.cpp index 67f86cf1..eb8338e6 100644 --- a/test/test_helpers.cpp +++ b/test/test_helpers.cpp @@ -583,4 +583,9 @@ std::string create_random_string(size_t size, size_t seed) { return create_random_string(size, tmprng); } +bool skip_slow_tests() { + static bool skip = getenv_is_enabled("DWARFS_SKIP_SLOW_TESTS"); + return skip; +} + } // namespace dwarfs::test diff --git a/test/test_helpers.h b/test/test_helpers.h index 4fb4b8a8..720e2768 100644 --- a/test/test_helpers.h +++ b/test/test_helpers.h @@ -365,4 +365,16 @@ std::string create_random_string(size_t size, uint8_t min, uint8_t max, std::string create_random_string(size_t size, std::mt19937_64& gen); std::string create_random_string(size_t size, size_t seed = 0); +bool skip_slow_tests(); + +#define DWARFS_SLOW_TEST() \ + do { \ + if (::dwarfs::test::skip_slow_tests()) { \ + GTEST_SKIP() << "skipping slow test"; \ + } \ + } while (0) + +#define DWARFS_SLOW_FIXTURE \ + void SetUp() override { DWARFS_SLOW_TEST(); } + } // namespace dwarfs::test diff --git a/test/tool_main_test.cpp b/test/tool_main_test.cpp index ba2a15d5..608a36f6 100644 --- a/test/tool_main_test.cpp +++ b/test/tool_main_test.cpp @@ -1478,7 +1478,9 @@ INSTANTIATE_TEST_SUITE_P(dwarfs, mkdwarfs_recompress_test, ::testing::ValuesIn(source_fs_compression)); class mkdwarfs_build_options_test - : public testing::TestWithParam {}; + : public testing::TestWithParam { + DWARFS_SLOW_FIXTURE +}; TEST_P(mkdwarfs_build_options_test, basic) { auto opts = GetParam(); @@ -1669,6 +1671,8 @@ constexpr std::array const pack_mode_names = { } TEST(mkdwarfs_test, pack_modes_random) { + DWARFS_SLOW_TEST(); + std::mt19937_64 rng{42}; std::uniform_int_distribution<> dist{1, pack_mode_names.size()}; @@ -1848,7 +1852,9 @@ TEST(mkdwarfs_test, compression_cannot_be_used_for_category) { } #endif -class mkdwarfs_progress_test : public testing::TestWithParam {}; +class mkdwarfs_progress_test : public testing::TestWithParam { + DWARFS_SLOW_FIXTURE +}; TEST_P(mkdwarfs_progress_test, basic) { std::string mode{GetParam()}; @@ -2471,6 +2477,7 @@ TEST(mkdwarfs_test, filesystem_read_error) { } class segmenter_repeating_sequence_test : public testing::TestWithParam { + DWARFS_SLOW_FIXTURE }; TEST_P(segmenter_repeating_sequence_test, github161) { diff --git a/test/tools_test.cpp b/test/tools_test.cpp index 5318f9dc..a919e79e 100644 --- a/test/tools_test.cpp +++ b/test/tools_test.cpp @@ -1055,12 +1055,15 @@ TEST_P(tools_test, end_to_end) { "-oenable_nlink", "-oreadonly", #endif - "-omlock=try", - "-ono_cache_image", - "-ocache_files", - "-otidy_strategy=time", }; + if (!dwarfs::test::skip_slow_tests()) { + all_options.push_back("-omlock=try"); + all_options.push_back("-ono_cache_image"); + all_options.push_back("-ocache_files"); + all_options.push_back("-otidy_strategy=time"); + } + unsigned const combinations = 1 << all_options.size(); for (unsigned bitmask = 0; bitmask < combinations; ++bitmask) {