Browse Source

test: add mutex check for BasicRanges and AllCases

master
Dnomd343 2 years ago
parent
commit
3c21061728
  1. 24
      test/CMakeLists.txt
  2. 31
      test/all_cases.cc
  3. 3
      test/common_code.cc

24
test/CMakeLists.txt

@ -14,16 +14,26 @@ add_library(md5 STATIC ../third_party/md5/md5.cpp)
################################################################
include_directories(../src/klotski_core/utils)
add_executable(test_utils utils.cc)
target_link_libraries(test_utils PUBLIC ${TEST_DEPS})
add_test(NAME utils COMMAND test_utils)
#include_directories(../src/klotski_core/utils)
#add_executable(test_utils utils.cc)
#target_link_libraries(test_utils PUBLIC ${TEST_DEPS})
#add_test(NAME utils COMMAND test_utils)
################################################################
#include_directories(../src/klotski_core/all_cases)
#add_executable(test_all_cases all_cases.cc)
#target_link_libraries(test_all_cases PUBLIC ${TEST_DEPS} md5)
#add_test(NAME all_cases COMMAND test_all_cases)
################################################################
include_directories(../src/klotski_core/utils)
include_directories(../src/klotski_core/all_cases)
add_executable(test_all_cases all_cases.cc)
target_link_libraries(test_all_cases PUBLIC ${TEST_DEPS} md5)
add_test(NAME all_cases COMMAND test_all_cases)
add_executable(test_basic utils.cc all_cases.cc common_code.cc)
target_link_libraries(test_basic PUBLIC ${TEST_DEPS} md5)
add_test(NAME basic COMMAND test_basic)
################################################################

31
test/all_cases.cc

@ -1,3 +1,4 @@
#include <thread>
#include <cstdint>
#include "md5.h"
#include "all_cases.h"
@ -9,12 +10,28 @@ using klotski::ALL_CASES_SIZE;
using klotski::BASIC_RANGES_SIZE;
using klotski::ALL_CASES_SIZE_SUM;
const int TEST_THREAD_NUM = 8;
/// basic ranges constants
const char BASIC_RANGES_MD5[] = "6f385dc171e201089ff96bb010b47212";
/// all cases constants
const char ALL_CASES_MD5[] = "3888e9fab8d3cbb50908b12b147cfb23";
/// basic ranges mutex check
TEST(AllCases, basic_ranges_mutex) {
std::thread threads[TEST_THREAD_NUM];
EXPECT_EQ(BasicRanges::status(), BasicRanges::NO_INIT);
for (auto &t : threads) {
t = std::thread(BasicRanges::build);
}
EXPECT_EQ(BasicRanges::status(), BasicRanges::BUILDING);
for (auto &t : threads) {
t.join();
}
EXPECT_EQ(BasicRanges::status(), BasicRanges::AVAILABLE);
}
/// basic ranges size check
TEST(AllCases, basic_ranges_size) {
auto &basic_ranges = BasicRanges::fetch();
@ -33,6 +50,20 @@ TEST(AllCases, basic_ranges_data) {
EXPECT_STREQ(basic_ranges_md5.c_str(), BASIC_RANGES_MD5);
}
/// basic ranges mutex check
TEST(AllCases, all_cases_mutex) {
std::thread threads[TEST_THREAD_NUM];
EXPECT_EQ(AllCases::status(), AllCases::NO_INIT);
for (auto &t : threads) {
t = std::thread(AllCases::build);
}
EXPECT_EQ(AllCases::status(), AllCases::BUILDING);
for (auto &t : threads) {
t.join();
}
EXPECT_EQ(AllCases::status(), AllCases::AVAILABLE);
}
/// all cases size check
TEST(AllCases, all_cases_size) {
auto &all_cases = AllCases::fetch();

3
test/common_code.cc

@ -0,0 +1,3 @@
#include "gtest/gtest.h"
Loading…
Cancel
Save