Skip to content

Commit

Permalink
a new way to switch sds
Browse files Browse the repository at this point in the history
  • Loading branch information
osalyk committed Jul 22, 2024
1 parent d1aade3 commit 70a22cb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 43 deletions.
27 changes: 10 additions & 17 deletions src/tests/ras/unsafe_shutdown/local_move_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ std::ostream& operator<<(std::ostream& stream, move_param const& m) {
return stream;
}

bool pmem;

std::vector<move_param> GetMoveParams() {
std::vector<move_param> ret_vec;
LocalTestPhase& test_phase = LocalTestPhase::GetInstance();
Expand All @@ -53,10 +51,10 @@ std::vector<move_param> 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);
}

Expand All @@ -68,10 +66,10 @@ std::vector<move_param> 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);
}

Expand All @@ -83,10 +81,10 @@ std::vector<move_param> 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);
}

Expand All @@ -98,10 +96,10 @@ std::vector<move_param> 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);
}

Expand All @@ -113,10 +111,10 @@ std::vector<move_param> 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);
}

Expand All @@ -128,10 +126,10 @@ std::vector<move_param> 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;
Expand All @@ -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();
}

/**
Expand All @@ -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<int> pd{pop_};
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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<int> pd{pop_};
Expand Down
2 changes: 1 addition & 1 deletion src/tests/ras/unsafe_shutdown/local_move_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 1 addition & 14 deletions src/tests/ras/unsafe_shutdown/local_replicas_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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<int> pd{pop_};
Expand Down Expand Up @@ -156,7 +150,6 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
} else {
tc.enough_dimms = false;
}
tc.pmem = true;
ret_vec.emplace_back(tc);
}

Expand Down Expand Up @@ -190,7 +183,6 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
} else {
tc.enough_dimms = false;
}
tc.pmem = true;
ret_vec.emplace_back(tc);
}

Expand All @@ -213,7 +205,6 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
} else {
tc.enough_dimms = false;
}
tc.pmem = false;
ret_vec.emplace_back(tc);
}

Expand All @@ -237,7 +228,6 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
} else {
tc.enough_dimms = false;
}
tc.pmem = false;
ret_vec.emplace_back(tc);
}

Expand All @@ -261,7 +251,6 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
} else {
tc.enough_dimms = false;
}
tc.pmem = false;
ret_vec.emplace_back(tc);
}

Expand All @@ -287,7 +276,6 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
} else {
tc.enough_dimms = false;
}
tc.pmem = false;
ret_vec.emplace_back(tc);
}

Expand Down Expand Up @@ -319,7 +307,6 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
} else {
tc.enough_dimms = false;
}
tc.pmem = false;
ret_vec.emplace_back(tc);
}
return ret_vec;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/ras/unsafe_shutdown/local_replicas_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct sync_local_replica_tc {
Poolset poolset;
bool enough_dimms;
bool is_syncable;
bool pmem;
bool is_pmem;
};

class SyncLocalReplica
Expand Down
27 changes: 19 additions & 8 deletions src/tests/ras/unsafe_shutdown/unsafe_shutdown.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
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);
}
}
8 changes: 6 additions & 2 deletions src/tests/ras/unsafe_shutdown/unsafe_shutdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand All @@ -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 {
Expand All @@ -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

0 comments on commit 70a22cb

Please sign in to comment.