X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=test%2Fjunction_parallel_driver.cpp;h=8dadf63bd30e3b337997a6c4f5c05f17d3924fc2;hb=8377b966404bf0978a08b9d745ab22113e93d19f;hp=b6f74f6fb2213d327ae68250ae7ba58e93778290;hpb=a5c4f9abb37cd877dbb7be486657e9dca281274d;p=junction.git diff --git a/test/junction_parallel_driver.cpp b/test/junction_parallel_driver.cpp index b6f74f6..8dadf63 100644 --- a/test/junction_parallel_driver.cpp +++ b/test/junction_parallel_driver.cpp @@ -1,26 +1,9 @@ -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include +#include "test.h" namespace junction_test { class JunctionMapInsDelFindTest_Parallel : public cds_test::stress_fixture { protected: - typedef junction::ConcurrentMap_Grampa GrampaMap; - typedef junction::ConcurrentMap_Linear LinearMap; - typedef junction::ConcurrentMap_Leapfrog LeapfrogMap; - typedef junction::ConcurrentMap_Crude CrudeMap; - static unsigned s_nInsertPercentage; static unsigned s_nDeletePercentage; static size_t s_nGCFrequency; // Run GC after "s_nGCFrequency" operations. @@ -63,7 +46,9 @@ protected: GetConfigNonZeroExpected(DeletePercentage, 5); GetConfigNonZeroExpected(ThreadCount, 4); GetConfigNonZeroExpected(MapKeyRange, 20000); - GetConfigNonZeroExpected(CrudeMapCapacity, s_nMapKeyRange * 64); + // CrudeMap may need a big enough capacity in case may insertion operations + // got jammed up. + GetConfigNonZeroExpected(CrudeMapCapacity, s_nMapKeyRange * 1024); GetConfigNonZeroExpected(GCFrequency, 1500); GetConfigNonZeroExpected(CrudePassCount, 1500000000); GetConfigNonZeroExpected(GrampaPassCount, 650000000); @@ -71,65 +56,9 @@ protected: GetConfigNonZeroExpected(LeapfrogPassCount, 850000000); } - template - static bool map_insert(Map* map, Key key, Value value) { - auto iter = map->insertOrFind(key); - if (!iter.getValue() || iter.getValue() != value) { - // Insert/update the pair - iter.assignValue(value); - return true; - } else { - return false; - } - } - - template - static bool map_delete(Map* map, Key key) { - auto iter = map->find(key); - if (iter.getValue()) { - iter.eraseValue(); - return true; - } else { - return false; - } - } - - template - static bool map_find(Map* map, Key key) { - auto iter = map->find(key); - if (iter.getValue()) { - return true; - } else { - return false; - } - } - - // Specialization for CrudeMap - template - static bool map_insert(CrudeMap* map, Key key, Value value) { - auto old_val = map->get(key); - if (!old_val || old_val != value) { - map->assign(key, value); - return true; - } else { - return false; - } - } - - template static bool map_delete(CrudeMap* map, Key key) { - if (!map->get(key)) { - map->assign(key, ((Key)0)); - return true; - } else { - return false; - } - } - - template static bool map_find(CrudeMap* map, Key key) { - return map->get(key) != ((Key)0); - } - - template static void run_test(Map* map, size_t pass_count) { + template + static void run_test(Map* map, size_t pass_count, size_t* inserted_num, + size_t* deleted_num) { auto qsbrContext = junction::DefaultQSBR.createContext(); std::random_device rd; @@ -138,6 +67,7 @@ protected: unsigned action_index = 0; size_t nInsertedNum = 0; + size_t nDeletedNum = 0; size_t nFindSuccess = 0; size_t nOperations = 0; @@ -153,7 +83,9 @@ protected: break; } case do_delete: { - map_delete(map, key); + if (map_delete(map, key)) { + nDeletedNum++; + } break; } case do_find: { @@ -174,6 +106,27 @@ protected: } junction::DefaultQSBR.update(qsbrContext); junction::DefaultQSBR.destroyContext(qsbrContext); + *inserted_num = nInsertedNum; + *deleted_num = nDeletedNum; + } + + template + void JunctionThreading(Map* map, size_t pass_count) { + std::unique_ptr threads(new std::thread[s_nThreadCount]); + std::unique_ptr inserted_nums(new size_t[s_nThreadCount]); + std::unique_ptr deleted_nums(new size_t[s_nThreadCount]); + for (size_t i = 0; i < s_nThreadCount; i++) { + threads[i] = std::thread(run_test, map, pass_count, + &inserted_nums[i], &deleted_nums[i]); + } + size_t inserted_sum = 0; + size_t deleted_sum = 0; + for (size_t i = 0; i < s_nThreadCount; i++) { + threads[i].join(); + inserted_sum += inserted_nums[i]; + deleted_sum += deleted_nums[i]; + } + EXPECT_LE(deleted_sum, inserted_sum); } }; @@ -191,43 +144,24 @@ size_t JunctionMapInsDelFindTest_Parallel::s_nGrampaPassCount; size_t JunctionMapInsDelFindTest_Parallel::s_nLinearPassCount; size_t JunctionMapInsDelFindTest_Parallel::s_nLeapfrogPassCount; -#define JunctionThreading(map_type, pass_count) \ - std::unique_ptr threads(new std::thread[s_nThreadCount]); \ - for (size_t i = 0; i < s_nThreadCount; i++) { \ - threads[i] = std::thread(run_test, map.get(), pass_count); \ - } \ - for (size_t i = 0; i < s_nThreadCount; i++) { \ - threads[i].join(); \ - } - TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapCrude) { std::unique_ptr map(new CrudeMap(s_nCrudeMapCapacity)); - JunctionThreading(CrudeMap, s_nCrudePassCount); + JunctionThreading(map.get(), s_nCrudePassCount); } TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapLeapfrog) { std::unique_ptr map(new LeapfrogMap()); - JunctionThreading(LeapfrogMap, s_nLeapfrogPassCount); + JunctionThreading(map.get(), s_nLeapfrogPassCount); } TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapLinear) { std::unique_ptr map(new LinearMap()); - JunctionThreading(LinearMap, s_nLinearPassCount); + JunctionThreading(map.get(), s_nLinearPassCount); } TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapGrampa) { std::unique_ptr map(new GrampaMap()); - JunctionThreading(GrampaMap, s_nGrampaPassCount); + JunctionThreading(map.get(), s_nGrampaPassCount); } } // namespace junction_test - -int main(int argc, char** argv) { - // Read test config file - cds_test::init_config(argc, argv); - - // Init Google test - ::testing::InitGoogleTest(&argc, argv); - int result = RUN_ALL_TESTS(); - return result; -}