diff --git a/src/tests/ras/unsafe_shutdown/local_move_tests.cc b/src/tests/ras/unsafe_shutdown/local_move_tests.cc index 5db0a2c..61936a5 100644 --- a/src/tests/ras/unsafe_shutdown/local_move_tests.cc +++ b/src/tests/ras/unsafe_shutdown/local_move_tests.cc @@ -37,8 +37,6 @@ std::ostream& operator<<(std::ostream& stream, move_param const& m) { return stream; } -bool pmem; - std::vector GetMoveParams() { std::vector ret_vec; LocalTestPhase& test_phase = LocalTestPhase::GetInstance(); @@ -53,10 +51,10 @@ std::vector GetMoveParams() { tc.enough_dimms = true; tc.src_pool_dir = unsafe_dn[0].GetTestDir(); tc.dest_pool_dir = test_phase.GetTestDir(); + tc.src_pool_dir_is_pmem = true; } else { tc.enough_dimms = false; } - tc.pmem = true; ret_vec.emplace_back(tc); } @@ -68,10 +66,10 @@ std::vector GetMoveParams() { tc.enough_dimms = true; tc.src_pool_dir = test_phase.GetTestDir(); tc.dest_pool_dir = unsafe_dn[0].GetTestDir(); + tc.src_pool_dir_is_pmem = false; } else { tc.enough_dimms = false; } - tc.pmem = false; ret_vec.emplace_back(tc); } @@ -83,10 +81,10 @@ std::vector GetMoveParams() { tc.enough_dimms = true; tc.src_pool_dir = unsafe_dn[0].GetTestDir(); tc.dest_pool_dir = safe_dn[0].GetTestDir(); + tc.src_pool_dir_is_pmem = true; } else { tc.enough_dimms = false; } - tc.pmem = true; ret_vec.emplace_back(tc); } @@ -98,10 +96,10 @@ std::vector GetMoveParams() { tc.enough_dimms = true; tc.src_pool_dir = unsafe_dn[1].GetTestDir(); tc.dest_pool_dir = unsafe_dn[0].GetTestDir(); + tc.src_pool_dir_is_pmem = true; } else { tc.enough_dimms = false; } - tc.pmem = true; ret_vec.emplace_back(tc); } @@ -113,10 +111,10 @@ std::vector GetMoveParams() { tc.enough_dimms = true; tc.src_pool_dir = safe_dn[0].GetTestDir(); tc.dest_pool_dir = test_phase.GetTestDir(); + tc.src_pool_dir_is_pmem = true; } else { tc.enough_dimms = false; } - tc.pmem = true; ret_vec.emplace_back(tc); } @@ -128,10 +126,10 @@ std::vector GetMoveParams() { tc.enough_dimms = true; tc.src_pool_dir = test_phase.GetTestDir(); tc.dest_pool_dir = safe_dn[0].GetTestDir(); + tc.src_pool_dir_is_pmem = false; } else { tc.enough_dimms = false; } - tc.pmem = false; ret_vec.emplace_back(tc); } return ret_vec; @@ -144,7 +142,8 @@ void MovePoolClean::SetUp() { << "Insufficient number of DIMMs to run this test"; src_pool_path_ = param.src_pool_dir + GetNormalizedTestName() + "_pool"; dest_pool_path_ = param.dest_pool_dir + GetNormalizedTestName() + "_pool"; - pmem = param.pmem; + create_on_pmem = param.src_pool_dir_is_pmem; + UnsafeShutdown::SetUp(); } /** @@ -165,14 +164,10 @@ void MovePoolClean::SetUp() { */ TEST_P(MovePoolClean, TC_MOVE_POOL_CLEAN_phase_1) { /* Step1 */ - if (pmem == false) - set_sds_at_create_func(false); pop_ = pmemobj_create(src_pool_path_.c_str(), nullptr, PMEMOBJ_MIN_POOL, 0644); ASSERT_TRUE(pop_ != nullptr) << "Pool creating failed. Errno: " << errno << std::endl << pmemobj_errormsg(); - if (pmem == false) - set_sds_at_create_func(true); /* Step2 */ ObjData pd{pop_}; @@ -209,6 +204,8 @@ void MovePoolDirty::SetUp() { << "Insufficient number of DIMMs to run this test"; src_pool_path_ = param.src_pool_dir + GetNormalizedTestName() + "_pool"; dest_pool_path_ = param.dest_pool_dir + GetNormalizedTestName() + "_pool"; + create_on_pmem = param.src_pool_dir_is_pmem; + UnsafeShutdown::SetUp(); } /** @@ -229,13 +226,9 @@ void MovePoolDirty::SetUp() { */ TEST_P(MovePoolDirty, TC_MOVE_POOL_DIRTY_phase_1) { /* Step1 */ - if (pmem == false) - set_sds_at_create_func(false); pop_ = pmemobj_create(src_pool_path_.c_str(), nullptr, PMEMOBJ_MIN_POOL, 0644); ASSERT_TRUE(pop_ != nullptr) << "Pool creating failed" << std::endl << pmemobj_errormsg(); - if (pmem == false) - set_sds_at_create_func(true); /* Step2 */ ObjData pd{pop_}; diff --git a/src/tests/ras/unsafe_shutdown/local_move_tests.h b/src/tests/ras/unsafe_shutdown/local_move_tests.h index 60ef437..00b14fc 100644 --- a/src/tests/ras/unsafe_shutdown/local_move_tests.h +++ b/src/tests/ras/unsafe_shutdown/local_move_tests.h @@ -40,7 +40,7 @@ struct move_param { std::string src_pool_dir; std::string dest_pool_dir; bool enough_dimms; - bool pmem; + bool src_pool_dir_is_pmem; }; std::ostream& operator<<(std::ostream& stream, move_param const& m); diff --git a/src/tests/ras/unsafe_shutdown/local_replicas_tests.cc b/src/tests/ras/unsafe_shutdown/local_replicas_tests.cc index 8153fff..fd478f4 100644 --- a/src/tests/ras/unsafe_shutdown/local_replicas_tests.cc +++ b/src/tests/ras/unsafe_shutdown/local_replicas_tests.cc @@ -37,13 +37,11 @@ std::ostream& operator<<(std::ostream& stream, sync_local_replica_tc const& p) { return stream; } -bool is_pmem; - void SyncLocalReplica::SetUp() { sync_local_replica_tc param = GetParam(); ASSERT_TRUE(param.enough_dimms) << "Insufficient number of DIMMs to run this test"; - is_pmem = param.pmem; + UnsafeShutdown::SetUp(); } /** @@ -74,14 +72,10 @@ TEST_P(SyncLocalReplica, TC_SYNC_LOCAL_REPLICA_phase_1) { ASSERT_TRUE(p_mgmt.PoolsetFileExists(ps)) << "Poolset file " << ps.GetFullPath() << " does not exist"; - if (is_pmem == false) - set_sds_at_create_func(true); pop_ = pmemobj_create(ps.GetFullPath().c_str(), nullptr, 0, 0644); ASSERT_TRUE(pop_ != nullptr) << "Error while creating the pool. Errno:" << errno << std::endl << pmemobj_errormsg(); - if (is_pmem == false) - set_sds_at_create_func(false); /* Step2 */ ObjData pd{pop_}; @@ -156,7 +150,6 @@ std::vector GetSyncLocalReplicaParams() { } else { tc.enough_dimms = false; } - tc.pmem = true; ret_vec.emplace_back(tc); } @@ -190,7 +183,6 @@ std::vector GetSyncLocalReplicaParams() { } else { tc.enough_dimms = false; } - tc.pmem = true; ret_vec.emplace_back(tc); } @@ -213,7 +205,6 @@ std::vector GetSyncLocalReplicaParams() { } else { tc.enough_dimms = false; } - tc.pmem = false; ret_vec.emplace_back(tc); } @@ -237,7 +228,6 @@ std::vector GetSyncLocalReplicaParams() { } else { tc.enough_dimms = false; } - tc.pmem = false; ret_vec.emplace_back(tc); } @@ -261,7 +251,6 @@ std::vector GetSyncLocalReplicaParams() { } else { tc.enough_dimms = false; } - tc.pmem = false; ret_vec.emplace_back(tc); } @@ -287,7 +276,6 @@ std::vector GetSyncLocalReplicaParams() { } else { tc.enough_dimms = false; } - tc.pmem = false; ret_vec.emplace_back(tc); } @@ -319,7 +307,6 @@ std::vector GetSyncLocalReplicaParams() { } else { tc.enough_dimms = false; } - tc.pmem = false; ret_vec.emplace_back(tc); } return ret_vec; diff --git a/src/tests/ras/unsafe_shutdown/local_replicas_tests.h b/src/tests/ras/unsafe_shutdown/local_replicas_tests.h index fb6f683..2757955 100644 --- a/src/tests/ras/unsafe_shutdown/local_replicas_tests.h +++ b/src/tests/ras/unsafe_shutdown/local_replicas_tests.h @@ -40,7 +40,7 @@ struct sync_local_replica_tc { Poolset poolset; bool enough_dimms; bool is_syncable; - bool pmem; + bool is_pmem; }; class SyncLocalReplica diff --git a/src/tests/ras/unsafe_shutdown/unsafe_shutdown.cc b/src/tests/ras/unsafe_shutdown/unsafe_shutdown.cc index 3343fa2..a598624 100644 --- a/src/tests/ras/unsafe_shutdown/unsafe_shutdown.cc +++ b/src/tests/ras/unsafe_shutdown/unsafe_shutdown.cc @@ -48,7 +48,7 @@ void UnsafeShutdown::StampPassedResult() const { } } -bool UnsafeShutdown::PassedOnPreviousPhase() const { +bool UnsafeShutdown:: PassedOnPreviousPhase() const { bool ret = ApiC::RegularFileExists(GetPassedStamp()); if (ret) { ApiC::RemoveFile(GetPassedStamp()); @@ -87,11 +87,22 @@ int UnsafeShutdown::PmempoolRepair(std::string pool_file_path) const { return pmempool_check_end(ppc); } -/* Change the status of the shutdown state */ -void set_sds_at_create_func(bool state) { - int ret = pmemobj_ctl_set(NULL, "sds.at_create", &state); - if (ret) { - std::cerr << "Failed to set sds.at_create: " << pmemobj_errormsg() << std::endl; - exit(1); - } +void UnsafeShutdown::SetSdsAtCreate(bool state) const { + int ret = pmemobj_ctl_set(NULL, "sds.at_create", &state); + if (ret) { + std::cerr << "Failed to set sds.at_create: " << pmemobj_errormsg() << std::endl; + exit(1); + } +} + +void UnsafeShutdown::SetUp() { + if (!create_on_pmem) { + SetSdsAtCreate(false); + } +} + +void UnsafeShutdown::TearDown() { + if (!create_on_pmem) { + SetSdsAtCreate(true); + } } diff --git a/src/tests/ras/unsafe_shutdown/unsafe_shutdown.h b/src/tests/ras/unsafe_shutdown/unsafe_shutdown.h index 75c8a8a..e6863e8 100644 --- a/src/tests/ras/unsafe_shutdown/unsafe_shutdown.h +++ b/src/tests/ras/unsafe_shutdown/unsafe_shutdown.h @@ -58,6 +58,10 @@ class UnsafeShutdown : public ::testing::Test { std::string GetNormalizedTestName() const; int PmempoolRepair(std::string pool_file_path) const; + + void SetUp() override; + void TearDown() override; + ~UnsafeShutdown() { StampPassedResult(); if (close_pools_at_end_) { @@ -69,6 +73,7 @@ class UnsafeShutdown : public ::testing::Test { protected: bool close_pools_at_end_ = true; + bool create_on_pmem = true; private: const ::testing::TestInfo& GetTestInfo() const { @@ -78,8 +83,7 @@ class UnsafeShutdown : public ::testing::Test { return test_phase_.GetTestDir() + GetNormalizedTestName() + "_passed"; } void StampPassedResult() const; + void SetSdsAtCreate(bool state) const; }; -void set_sds_at_create_func(bool state); - #endif // UNSAFE_SHUTDOWN_H