From: Peizhao Ou Date: Thu, 8 Feb 2018 21:00:18 +0000 (-0800) Subject: Adds parallel test case organization in CMakefile (no actual parallel test cases... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=junction.git;a=commitdiff_plain;h=176b53dafc01aa30b9128db59fd3a234fff1198d Adds parallel test case organization in CMakefile (no actual parallel test cases yet) --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5deccde..fe8a11e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,15 +1,13 @@ cmake_minimum_required(VERSION 2.8.5) +set(CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Build configs") + include_directories( /scratch/googletest/googletest/include/ ) -set(PACKAGE_NAME stress-sequential-junction) -set(JUNCTION_TEST_SOURCES - junction_driver.cpp -) - -set(CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Build configs") +set(SEQUENTIAL_DRIVER stress-sequential-junction) +set(PARALLEL_DRIVER stress-parallel-junction) set(JUNCTION_LIB junction @@ -20,5 +18,8 @@ set(JUNCTION_LIB #/scratch/googletest/libgtest.a ) -add_executable(${PACKAGE_NAME} ${JUNCTION_TEST_SOURCES}) -target_link_libraries(${PACKAGE_NAME} ${JUNCTION_LIB}) +add_executable(${SEQUENTIAL_DRIVER} junction_sequential_driver.cpp) +target_link_libraries(${SEQUENTIAL_DRIVER} ${JUNCTION_LIB}) + +add_executable(${PARALLEL_DRIVER} junction_parallel_driver.cpp) +target_link_libraries(${PARALLEL_DRIVER} ${JUNCTION_LIB}) diff --git a/test/junction_driver.cpp b/test/junction_driver.cpp deleted file mode 100644 index d016438..0000000 --- a/test/junction_driver.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace junction_test { - -class JunctionMapInsDelFindTest : public ::testing::Test { -protected: - typedef junction::ConcurrentMap_Grampa GrampaMap; - typedef junction::ConcurrentMap_Linear LinearMap; - typedef junction::ConcurrentMap_Leapfrog LeapfrogMap; - typedef junction::ConcurrentMap_Crude CrudeMap; - - static const unsigned s_nInsertPercentage = 10; - // Run GC after "kGCFrequency" operations. - static const size_t kGCFrequency = 3000; - static const size_t kLeapfrogGCFrequency = 1500; - - static const size_t kCrudeMapSize = 10000; - static const size_t kCrudePassCount = 400000; - - static const size_t kGrampaMapSize = 20000; - static const size_t kGrampaPassCount = 60000; - - static const size_t kLinearMapSize = 20000; - static const size_t kLinearPassCount = 70000; - - static const size_t kLeapfrogMapSize = 20000; - static const size_t kLeapfrogPassCount = 75000; - - static void SetUpTestCase() {} - - template - static void run_test(size_t map_size, size_t pass_count, - size_t gc_frequency) { - size_t nInsertedNum = 0; - size_t nFindSuccess = 0; - size_t nOperations = 0; - std::unique_ptr map(new Map()); - auto qsbrContext = junction::DefaultQSBR.createContext(); - for (size_t count = 0; count < pass_count; count++) { - for (size_t i = 0; i < map_size; ++i) { - // The number to operate on the map. - size_t n = map_size + i; - // Insert - if (i % s_nInsertPercentage == 1) { - auto iter = map->insertOrFind(i); - if (!iter.getValue()) { - iter.assignValue(n); - nInsertedNum++; - // std::cout << "Inserted" << i << "\n"; - } - } - // Find - { - auto iter = map->find(i); - if (iter.getValue()) { - ++nFindSuccess; - // std::cout << "Found" << i << "\n"; - } - } - // Delete - if (i % s_nInsertPercentage == 1) { - auto iter = map->find(i); - if (iter.getValue()) { - iter.eraseValue(); - // std::cout << "Erased" << i << "\n"; - } - } - if (++nOperations > gc_frequency) { - junction::DefaultQSBR.update(qsbrContext); - nOperations = 0; - } - } - } - junction::DefaultQSBR.update(qsbrContext); - junction::DefaultQSBR.destroyContext(qsbrContext); - EXPECT_EQ(nFindSuccess, nInsertedNum); - } - - template - void run_crude_map(size_t map_size, size_t pass_count, size_t gc_frequency) { - size_t nInsertedNum = 0; - size_t nFindSuccess = 0; - size_t nOperations = 0; - // Seems like the crude map won't resize, so better have a large enough - // capacity. - std::unique_ptr map(new Map(map_size * 32)); - auto qsbrContext = junction::DefaultQSBR.createContext(); - for (size_t count = 0; count < pass_count; count++) { - for (size_t i = 0; i < map_size; ++i) { - // The number to operate on the map. - size_t n = map_size + i; - // Insert - if (i % s_nInsertPercentage == 1) { - map->assign(i, n); - nInsertedNum++; - // std::cout << "Inserted" << i << "\n"; - } - // Find - { - if (map->get(i)) { - ++nFindSuccess; - // std::cout << "Found" << i << "\n"; - } - } - // Delete - if (i % s_nInsertPercentage == 1) { - if (map->get(i)) { - map->assign(n, 0); - // std::cout << "Erased" << i << "\n"; - } - } - if (++nOperations > gc_frequency) { - junction::DefaultQSBR.update(qsbrContext); - nOperations = 0; - } - } - } - junction::DefaultQSBR.update(qsbrContext); - junction::DefaultQSBR.destroyContext(qsbrContext); - - EXPECT_EQ(nFindSuccess, nInsertedNum); - } -}; - -TEST_F(JunctionMapInsDelFindTest, JunctionMapCrude) { - run_crude_map(kCrudeMapSize, kCrudePassCount, kGCFrequency); -} - -TEST_F(JunctionMapInsDelFindTest, JunctionMapLeapfrog) { - run_test(kLeapfrogMapSize, kLeapfrogPassCount, - kLeapfrogGCFrequency); -} - -TEST_F(JunctionMapInsDelFindTest, JunctionMapLinear) { - run_test(kLinearMapSize, kLinearPassCount, kGCFrequency); -} - -TEST_F(JunctionMapInsDelFindTest, JunctionMapGrampa) { - run_test(kGrampaMapSize, kGrampaPassCount, kGCFrequency); -} - -} // namespace junction_test - -int main(int argc, char** argv) { - // Init Google test - ::testing::InitGoogleTest(&argc, argv); - int result = RUN_ALL_TESTS(); - return 0; -} diff --git a/test/junction_parallel_driver.cpp b/test/junction_parallel_driver.cpp new file mode 100644 index 0000000..d016438 --- /dev/null +++ b/test/junction_parallel_driver.cpp @@ -0,0 +1,158 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace junction_test { + +class JunctionMapInsDelFindTest : public ::testing::Test { +protected: + typedef junction::ConcurrentMap_Grampa GrampaMap; + typedef junction::ConcurrentMap_Linear LinearMap; + typedef junction::ConcurrentMap_Leapfrog LeapfrogMap; + typedef junction::ConcurrentMap_Crude CrudeMap; + + static const unsigned s_nInsertPercentage = 10; + // Run GC after "kGCFrequency" operations. + static const size_t kGCFrequency = 3000; + static const size_t kLeapfrogGCFrequency = 1500; + + static const size_t kCrudeMapSize = 10000; + static const size_t kCrudePassCount = 400000; + + static const size_t kGrampaMapSize = 20000; + static const size_t kGrampaPassCount = 60000; + + static const size_t kLinearMapSize = 20000; + static const size_t kLinearPassCount = 70000; + + static const size_t kLeapfrogMapSize = 20000; + static const size_t kLeapfrogPassCount = 75000; + + static void SetUpTestCase() {} + + template + static void run_test(size_t map_size, size_t pass_count, + size_t gc_frequency) { + size_t nInsertedNum = 0; + size_t nFindSuccess = 0; + size_t nOperations = 0; + std::unique_ptr map(new Map()); + auto qsbrContext = junction::DefaultQSBR.createContext(); + for (size_t count = 0; count < pass_count; count++) { + for (size_t i = 0; i < map_size; ++i) { + // The number to operate on the map. + size_t n = map_size + i; + // Insert + if (i % s_nInsertPercentage == 1) { + auto iter = map->insertOrFind(i); + if (!iter.getValue()) { + iter.assignValue(n); + nInsertedNum++; + // std::cout << "Inserted" << i << "\n"; + } + } + // Find + { + auto iter = map->find(i); + if (iter.getValue()) { + ++nFindSuccess; + // std::cout << "Found" << i << "\n"; + } + } + // Delete + if (i % s_nInsertPercentage == 1) { + auto iter = map->find(i); + if (iter.getValue()) { + iter.eraseValue(); + // std::cout << "Erased" << i << "\n"; + } + } + if (++nOperations > gc_frequency) { + junction::DefaultQSBR.update(qsbrContext); + nOperations = 0; + } + } + } + junction::DefaultQSBR.update(qsbrContext); + junction::DefaultQSBR.destroyContext(qsbrContext); + EXPECT_EQ(nFindSuccess, nInsertedNum); + } + + template + void run_crude_map(size_t map_size, size_t pass_count, size_t gc_frequency) { + size_t nInsertedNum = 0; + size_t nFindSuccess = 0; + size_t nOperations = 0; + // Seems like the crude map won't resize, so better have a large enough + // capacity. + std::unique_ptr map(new Map(map_size * 32)); + auto qsbrContext = junction::DefaultQSBR.createContext(); + for (size_t count = 0; count < pass_count; count++) { + for (size_t i = 0; i < map_size; ++i) { + // The number to operate on the map. + size_t n = map_size + i; + // Insert + if (i % s_nInsertPercentage == 1) { + map->assign(i, n); + nInsertedNum++; + // std::cout << "Inserted" << i << "\n"; + } + // Find + { + if (map->get(i)) { + ++nFindSuccess; + // std::cout << "Found" << i << "\n"; + } + } + // Delete + if (i % s_nInsertPercentage == 1) { + if (map->get(i)) { + map->assign(n, 0); + // std::cout << "Erased" << i << "\n"; + } + } + if (++nOperations > gc_frequency) { + junction::DefaultQSBR.update(qsbrContext); + nOperations = 0; + } + } + } + junction::DefaultQSBR.update(qsbrContext); + junction::DefaultQSBR.destroyContext(qsbrContext); + + EXPECT_EQ(nFindSuccess, nInsertedNum); + } +}; + +TEST_F(JunctionMapInsDelFindTest, JunctionMapCrude) { + run_crude_map(kCrudeMapSize, kCrudePassCount, kGCFrequency); +} + +TEST_F(JunctionMapInsDelFindTest, JunctionMapLeapfrog) { + run_test(kLeapfrogMapSize, kLeapfrogPassCount, + kLeapfrogGCFrequency); +} + +TEST_F(JunctionMapInsDelFindTest, JunctionMapLinear) { + run_test(kLinearMapSize, kLinearPassCount, kGCFrequency); +} + +TEST_F(JunctionMapInsDelFindTest, JunctionMapGrampa) { + run_test(kGrampaMapSize, kGrampaPassCount, kGCFrequency); +} + +} // namespace junction_test + +int main(int argc, char** argv) { + // Init Google test + ::testing::InitGoogleTest(&argc, argv); + int result = RUN_ALL_TESTS(); + return 0; +} diff --git a/test/junction_sequential_driver.cpp b/test/junction_sequential_driver.cpp new file mode 100644 index 0000000..d016438 --- /dev/null +++ b/test/junction_sequential_driver.cpp @@ -0,0 +1,158 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace junction_test { + +class JunctionMapInsDelFindTest : public ::testing::Test { +protected: + typedef junction::ConcurrentMap_Grampa GrampaMap; + typedef junction::ConcurrentMap_Linear LinearMap; + typedef junction::ConcurrentMap_Leapfrog LeapfrogMap; + typedef junction::ConcurrentMap_Crude CrudeMap; + + static const unsigned s_nInsertPercentage = 10; + // Run GC after "kGCFrequency" operations. + static const size_t kGCFrequency = 3000; + static const size_t kLeapfrogGCFrequency = 1500; + + static const size_t kCrudeMapSize = 10000; + static const size_t kCrudePassCount = 400000; + + static const size_t kGrampaMapSize = 20000; + static const size_t kGrampaPassCount = 60000; + + static const size_t kLinearMapSize = 20000; + static const size_t kLinearPassCount = 70000; + + static const size_t kLeapfrogMapSize = 20000; + static const size_t kLeapfrogPassCount = 75000; + + static void SetUpTestCase() {} + + template + static void run_test(size_t map_size, size_t pass_count, + size_t gc_frequency) { + size_t nInsertedNum = 0; + size_t nFindSuccess = 0; + size_t nOperations = 0; + std::unique_ptr map(new Map()); + auto qsbrContext = junction::DefaultQSBR.createContext(); + for (size_t count = 0; count < pass_count; count++) { + for (size_t i = 0; i < map_size; ++i) { + // The number to operate on the map. + size_t n = map_size + i; + // Insert + if (i % s_nInsertPercentage == 1) { + auto iter = map->insertOrFind(i); + if (!iter.getValue()) { + iter.assignValue(n); + nInsertedNum++; + // std::cout << "Inserted" << i << "\n"; + } + } + // Find + { + auto iter = map->find(i); + if (iter.getValue()) { + ++nFindSuccess; + // std::cout << "Found" << i << "\n"; + } + } + // Delete + if (i % s_nInsertPercentage == 1) { + auto iter = map->find(i); + if (iter.getValue()) { + iter.eraseValue(); + // std::cout << "Erased" << i << "\n"; + } + } + if (++nOperations > gc_frequency) { + junction::DefaultQSBR.update(qsbrContext); + nOperations = 0; + } + } + } + junction::DefaultQSBR.update(qsbrContext); + junction::DefaultQSBR.destroyContext(qsbrContext); + EXPECT_EQ(nFindSuccess, nInsertedNum); + } + + template + void run_crude_map(size_t map_size, size_t pass_count, size_t gc_frequency) { + size_t nInsertedNum = 0; + size_t nFindSuccess = 0; + size_t nOperations = 0; + // Seems like the crude map won't resize, so better have a large enough + // capacity. + std::unique_ptr map(new Map(map_size * 32)); + auto qsbrContext = junction::DefaultQSBR.createContext(); + for (size_t count = 0; count < pass_count; count++) { + for (size_t i = 0; i < map_size; ++i) { + // The number to operate on the map. + size_t n = map_size + i; + // Insert + if (i % s_nInsertPercentage == 1) { + map->assign(i, n); + nInsertedNum++; + // std::cout << "Inserted" << i << "\n"; + } + // Find + { + if (map->get(i)) { + ++nFindSuccess; + // std::cout << "Found" << i << "\n"; + } + } + // Delete + if (i % s_nInsertPercentage == 1) { + if (map->get(i)) { + map->assign(n, 0); + // std::cout << "Erased" << i << "\n"; + } + } + if (++nOperations > gc_frequency) { + junction::DefaultQSBR.update(qsbrContext); + nOperations = 0; + } + } + } + junction::DefaultQSBR.update(qsbrContext); + junction::DefaultQSBR.destroyContext(qsbrContext); + + EXPECT_EQ(nFindSuccess, nInsertedNum); + } +}; + +TEST_F(JunctionMapInsDelFindTest, JunctionMapCrude) { + run_crude_map(kCrudeMapSize, kCrudePassCount, kGCFrequency); +} + +TEST_F(JunctionMapInsDelFindTest, JunctionMapLeapfrog) { + run_test(kLeapfrogMapSize, kLeapfrogPassCount, + kLeapfrogGCFrequency); +} + +TEST_F(JunctionMapInsDelFindTest, JunctionMapLinear) { + run_test(kLinearMapSize, kLinearPassCount, kGCFrequency); +} + +TEST_F(JunctionMapInsDelFindTest, JunctionMapGrampa) { + run_test(kGrampaMapSize, kGrampaPassCount, kGCFrequency); +} + +} // namespace junction_test + +int main(int argc, char** argv) { + // Init Google test + ::testing::InitGoogleTest(&argc, argv); + int result = RUN_ALL_TESTS(); + return 0; +}