From: Peizhao Ou Date: Thu, 8 Feb 2018 19:06:39 +0000 (-0800) Subject: Refactors test cases to use gtest framework X-Git-Url: http://plrg.eecs.uci.edu/git/?p=junction.git;a=commitdiff_plain;h=dce136ff897929eb6dafeeba678ba136c860e90f Refactors test cases to use gtest framework --- diff --git a/test/.clang-format b/test/.clang-format new file mode 100644 index 0000000..f5e68f4 --- /dev/null +++ b/test/.clang-format @@ -0,0 +1,90 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IndentCaseLabels: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c7b7493..5deccde 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 2.8.5) +include_directories( + /scratch/googletest/googletest/include/ +) + set(PACKAGE_NAME stress-sequential-junction) set(JUNCTION_TEST_SOURCES junction_driver.cpp @@ -10,6 +14,10 @@ set(CMAKE_CONFIGURATION_TYPES "Release" CACHE INTERNAL "Build configs") set(JUNCTION_LIB junction turf + # AArch64 lib + /scratch/googletest/googletest/libgtest.a + # x86 lib + #/scratch/googletest/libgtest.a ) add_executable(${PACKAGE_NAME} ${JUNCTION_TEST_SOURCES}) diff --git a/test/junction_driver.cpp b/test/junction_driver.cpp index a8ba4c5..d016438 100644 --- a/test/junction_driver.cpp +++ b/test/junction_driver.cpp @@ -1,176 +1,158 @@ +#include +#include +#include +#include #include -#include #include -#include -#include +#include #include -#include -#include -namespace { +#include -const unsigned s_nInsertPercentage = 10; -const char* kTestName = "InsDelFind"; -// Run GC after "kGCFrequency" operations. -const size_t kGCFrequency = 3000; -const size_t kLeapfrogGCFrequency = 1500; +namespace junction_test { -const size_t kCrudeMapSize = 10000; -const size_t kCrudePassCount = 400000; -const char* kCrudeBenchmarkName = "JunctionMapCrude"; +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; -const size_t kGrampaMapSize = 20000; -const size_t kGrampaPassCount = 60000; -const char* kGrampaBenchmarkName = "JunctionMapGrampa"; + static const unsigned s_nInsertPercentage = 10; + // Run GC after "kGCFrequency" operations. + static const size_t kGCFrequency = 3000; + static const size_t kLeapfrogGCFrequency = 1500; -const size_t kLinearMapSize = 20000; -const size_t kLinearPassCount = 70000; -const char* kLinearBenchmarkName = "JunctionMapLinear"; + static const size_t kCrudeMapSize = 10000; + static const size_t kCrudePassCount = 400000; -const size_t kLeapfrogMapSize = 20000; -const size_t kLeapfrogPassCount = 75000; -const char* kLeapfrogBenchmarkName = "JunctionMapLeapfrog"; + static const size_t kGrampaMapSize = 20000; + static const size_t kGrampaPassCount = 60000; -} // namespace + static const size_t kLinearMapSize = 20000; + static const size_t kLinearPassCount = 70000; -typedef junction::ConcurrentMap_Grampa GrampaMap; -typedef junction::ConcurrentMap_Linear LinearMap; -typedef junction::ConcurrentMap_Leapfrog LeapfrogMap; -typedef junction::ConcurrentMap_Crude CrudeMap; + static const size_t kLeapfrogMapSize = 20000; + static const size_t kLeapfrogPassCount = 75000; -template -void run_crude_map(size_t map_size, size_t pass_count, const char* bench_name, - size_t gc_frequency) { - std::cout << "[ RUN ] " << kTestName << "." << bench_name << std::endl; - auto start_time = std::chrono::system_clock::now(); + 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; - // Seems like the crude map won't resize, so better have a large enough - // capacity. - std::unique_ptr map(new Map(map_size * 32)); + 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) { - 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; - } + 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 ); - auto finish_time = std::chrono::system_clock::now(); - auto dur = finish_time - start_time; - auto milisecs = std::chrono::duration_cast(dur); - - if (nFindSuccess != nInsertedNum) { - std::cout << "nFindSuccess=" << nFindSuccess << ", nInsertedNum=" - << nInsertedNum << std::endl; - std::cout << "[ FAILED ] " << kTestName << "." << bench_name - << " (" << milisecs.count() << " ms)" << std::endl; - assert(false && "ConcurrentMap ERROR"); - } else { - std::cout << "[ OK ] " << kTestName << "." << bench_name - << " (" << milisecs.count() << " ms)" << std::endl; - } -} - -template -void run_test(size_t map_size, size_t pass_count, const char* bench_name, - size_t gc_frequency) { - std::cout << "[ RUN ] " << kTestName << "." << bench_name << std::endl; - auto start_time = std::chrono::system_clock::now(); + 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; - std::unique_ptr map(new Map()); + // 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) { - 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; - } + 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 ); - auto finish_time = std::chrono::system_clock::now(); - auto dur = finish_time - start_time; - auto milisecs = std::chrono::duration_cast(dur); - - if (nFindSuccess != nInsertedNum) { - std::cout << "nFindSuccess=" << nFindSuccess << ", nInsertedNum=" - << nInsertedNum << std::endl; - std::cout << "[ FAILED ] " << kTestName << "." << bench_name - << " (" << milisecs.count() << " ms)" << std::endl; - assert(false && "ConcurrentMap ERROR"); - } else { - std::cout << "[ OK ] " << kTestName << "." << bench_name - << " (" << milisecs.count() << " ms)" << std::endl; - } + junction::DefaultQSBR.destroyContext(qsbrContext); + + EXPECT_EQ(nFindSuccess, nInsertedNum); + } +}; + +TEST_F(JunctionMapInsDelFindTest, JunctionMapCrude) { + run_crude_map(kCrudeMapSize, kCrudePassCount, kGCFrequency); } -int main() { - run_crude_map(kCrudeMapSize, kCrudePassCount, kCrudeBenchmarkName, - kGCFrequency); - run_test(kLeapfrogMapSize, kLeapfrogPassCount, - kLeapfrogBenchmarkName, kLeapfrogGCFrequency ); - run_test(kLinearMapSize, kLinearPassCount, kLinearBenchmarkName, - kGCFrequency); - run_test(kGrampaMapSize, kGrampaPassCount, kGrampaBenchmarkName, - kGCFrequency); - return 0; +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; }