From 7d70d8d6e2d5b11b9c4e9ab3908d19a87b2d17d2 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Sun, 27 Nov 2016 22:02:48 -0800 Subject: [PATCH] Canonicalize some aspects of the folly/experimental/hazptr test Summary: [Folly] Canonicalize some aspects of the `folly/experimental/hazptr` test. * Remove the custom `main()` and use the provided weak symbol, either from `folly/test/common/TestMain.cpp` or from `gtest` depending on the build. * Extract some common setup/teardown (just debug logging in this case) to a test fixture. Reviewed By: Orvid Differential Revision: D4234154 fbshipit-source-id: 25613cba0ad6c9147714d98150e013fba1a64d46 --- folly/experimental/hazptr/test/HazptrTest.cpp | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/folly/experimental/hazptr/test/HazptrTest.cpp b/folly/experimental/hazptr/test/HazptrTest.cpp index ddd06421..47d6d061 100644 --- a/folly/experimental/hazptr/test/HazptrTest.cpp +++ b/folly/experimental/hazptr/test/HazptrTest.cpp @@ -32,8 +32,17 @@ DEFINE_int64(num_ops, 10, "Number of ops or pairs of ops per rep"); using namespace folly::hazptr; -TEST(Hazptr, Test1) { - DEBUG_PRINT("========== start of scope"); +class HazptrTest : public testing::Test { + public: + HazptrTest() : Test() { + DEBUG_PRINT("========== start of test scope"); + } + ~HazptrTest() override { + DEBUG_PRINT("========== end of test scope"); + } +}; + +TEST_F(HazptrTest, Test1) { DEBUG_PRINT(""); Node1* node0 = (Node1*)malloc(sizeof(Node1)); DEBUG_PRINT("=== new node0 " << node0 << " " << sizeof(*node0)); @@ -94,12 +103,9 @@ TEST(Hazptr, Test1) { n2->retire(myDomain0); DEBUG_PRINT("=== retire n3 " << n3); n3->retire(myDomain1); - - DEBUG_PRINT("========== end of scope"); } -TEST(Hazptr, Test2) { - DEBUG_PRINT("========== start of scope"); +TEST_F(HazptrTest, Test2) { Node2* node0 = new Node2; DEBUG_PRINT("=== new node0 " << node0 << " " << sizeof(*node0)); Node2* node1 = (Node2*)malloc(sizeof(Node2)); @@ -159,13 +165,10 @@ TEST(Hazptr, Test2) { n2->retire(mineDomain0, &mineReclaimFnFree); DEBUG_PRINT("=== retire n3 " << n3); n3->retire(mineDomain1, &mineReclaimFnFree); - - DEBUG_PRINT("========== end of scope"); } -TEST(Hazptr, LIFO) { +TEST_F(HazptrTest, LIFO) { using T = uint32_t; - DEBUG_PRINT("========== start of test scope"); CHECK_GT(FLAGS_num_threads, 0); for (int i = 0; i < FLAGS_num_reps; ++i) { DEBUG_PRINT("========== start of rep scope"); @@ -185,12 +188,10 @@ TEST(Hazptr, LIFO) { } DEBUG_PRINT("========== end of rep scope"); } - DEBUG_PRINT("========== end of test scope"); } -TEST(Hazptr, SWMRLIST) { +TEST_F(HazptrTest, SWMRLIST) { using T = uint64_t; - DEBUG_PRINT("========== start of test scope"); hazptr_domain custom_domain; CHECK_GT(FLAGS_num_threads, 0); @@ -216,12 +217,9 @@ TEST(Hazptr, SWMRLIST) { } DEBUG_PRINT("========== end of rep scope"); } - DEBUG_PRINT("========== end of test scope"); } -TEST(Hazptr, WIDECAS) { - DEBUG_PRINT("========== start of test scope"); - +TEST_F(HazptrTest, WIDECAS) { WideCAS s; std::string u = ""; std::string v = "11112222"; @@ -239,15 +237,4 @@ TEST(Hazptr, WIDECAS) { v = "333344445555"; ret = s.cas(u, v); CHECK(ret); - - DEBUG_PRINT("========== end of test scope"); -} - -int main(int argc, char** argv) { - DEBUG_PRINT("================================================= start main"); - testing::InitGoogleTest(&argc, argv); - google::ParseCommandLineFlags(&argc, &argv, true); - auto ret = RUN_ALL_TESTS(); - DEBUG_PRINT("================================================= end main"); - return ret; } -- 2.34.1