Browse Source

feat: fixture test helper

legacy
Dnomd343 3 months ago
parent
commit
c7845e4a4f
  1. 3
      src/core_test/cases/all_cases.cc
  2. 3
      src/core_test/cases/basic_ranges.cc
  3. 24
      src/core_test/cases/helper/cases.h
  4. 32
      src/core_test/helper/fixture.h

3
src/core_test/cases/all_cases.cc

@ -2,6 +2,7 @@
#include "helper/hash.h" #include "helper/hash.h"
#include "helper/cases.h" #include "helper/cases.h"
#include "helper/fixture.h"
#include "utility/exposer.h" #include "utility/exposer.h"
#include "short_code/short_code.h" #include "short_code/short_code.h"
@ -28,7 +29,7 @@ constexpr auto ALL_CASES_XXH3 = std::to_array<uint64_t>({
0x2cdf6c14a7ce3e9a, 0xb9dd04a315583f5c, 0x19046e49c44ae90d, 0x2d06800538d394c2, 0x2cdf6c14a7ce3e9a, 0xb9dd04a315583f5c, 0x19046e49c44ae90d, 0x2d06800538d394c2,
}); });
class AllCasesTest : public testing::Test, public Concurrent { class AllCasesTest : public testing::Test, public helper::Concurrent {
protected: protected:
void SetUp() override { void SetUp() override {
Reset(); Reset();

3
src/core_test/cases/basic_ranges.cc

@ -3,6 +3,7 @@
#include "group/group.h" #include "group/group.h"
#include "helper/hash.h" #include "helper/hash.h"
#include "helper/cases.h" #include "helper/cases.h"
#include "helper/fixture.h"
#include "utility/exposer.h" #include "utility/exposer.h"
using klotski::array_sum; using klotski::array_sum;
@ -18,7 +19,7 @@ EXPOSE_VAR(BasicRanges, bool, available_)
constexpr uint64_t BASIC_RANGES_XXH3 = 0x34fce9da6a052533; constexpr uint64_t BASIC_RANGES_XXH3 = 0x34fce9da6a052533;
class BasicRangesTest : public testing::Test, public Concurrent { class BasicRangesTest : public testing::Test, public helper::Concurrent {
protected: protected:
void SetUp() override { void SetUp() override {
Reset(); Reset();

24
src/core_test/cases/helper/cases.h

@ -29,30 +29,6 @@ constexpr auto Heads = std::to_array({
// ----------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------- //
/// Test fixture wrapper with concurrency tools.
class Concurrent {
protected:
// Execute same task concurrently.
helper::Racer racer_ {};
// Execute assigned tasks one by one.
helper::Executor serial_ {1};
// Execute assigned tasks on all cores.
helper::Executor executor_ {0};
// Atomic helpers for multi-thread testing.
std::atomic<int> counter_ {0};
std::atomic_flag condition_ {false};
};
/// Test fixture macro with custom test suite name.
#define TEST_FF(test_suite_name, test_name) \
GTEST_TEST_(test_suite_name, test_name, test_suite_name##Test, \
::testing::internal::GetTypeId<test_suite_name##Test>())
// ----------------------------------------------------------------------------------------- //
/// Assert that Ranges are sorted and unique. /// Assert that Ranges are sorted and unique.
#define EXPECT_SORTED_AND_UNIQUE(R) \ #define EXPECT_SORTED_AND_UNIQUE(R) \
EXPECT_TRUE(std::ranges::is_sorted(R.begin(), R.end())); \ EXPECT_TRUE(std::ranges::is_sorted(R.begin(), R.end())); \

32
src/core_test/helper/fixture.h

@ -0,0 +1,32 @@
#pragma once
#include <atomic>
#include <gtest/gtest.h>
#include "helper/concurrent.h"
namespace helper {
/// Test fixture wrapper with concurrency tools.
class Concurrent {
protected:
// Execute same task concurrently.
Racer racer_ {};
// Execute assigned tasks one by one.
Executor serial_ {1};
// Execute assigned tasks on all cores.
Executor executor_ {0};
// Atomic helpers for multi-thread testing.
std::atomic<int> counter_ {0};
std::atomic_flag condition_ {false};
};
/// Test fixture macro with custom test suite name.
#define TEST_FF(test_suite_name, test_name) \
GTEST_TEST_(test_suite_name, test_name, test_suite_name##Test, \
::testing::internal::GetTypeId<test_suite_name##Test>())
} // namespace helper
Loading…
Cancel
Save