Skip to content

Commit

Permalink
check condition
Browse files Browse the repository at this point in the history
  • Loading branch information
osalyk committed Jul 19, 2024
1 parent d287953 commit 5be3af9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 54 deletions.
26 changes: 16 additions & 10 deletions src/tests/ras/unsafe_shutdown/local_move_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,7 @@ std::ostream& operator<<(std::ostream& stream, move_param const& m) {
return stream;
}

/* 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);
}
}
bool pmem;

std::vector<move_param> GetMoveParams() {
std::vector<move_param> ret_vec;
Expand All @@ -60,6 +53,7 @@ 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.pmem = true;
} else {
tc.enough_dimms = false;
}
Expand All @@ -74,6 +68,7 @@ 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.pmem = false;
} else {
tc.enough_dimms = false;
}
Expand All @@ -84,6 +79,7 @@ std::vector<move_param> GetMoveParams() {
{
move_param tc;
tc.description = "from unsafely shutdown DIMM to safely shutdown DIMM";
tc.pmem = true;
if (unsafe_dn.size() >= 1 && safe_dn.size() >= 1) {
tc.enough_dimms = true;
tc.src_pool_dir = unsafe_dn[0].GetTestDir();
Expand All @@ -98,6 +94,7 @@ std::vector<move_param> GetMoveParams() {
{
move_param tc;
tc.description = "from unsafely shutdown DIMM to unsafely shutdown DIMM";
tc.pmem = true;
if (unsafe_dn.size() >= 2) {
tc.enough_dimms = true;
tc.src_pool_dir = unsafe_dn[1].GetTestDir();
Expand All @@ -112,6 +109,7 @@ std::vector<move_param> GetMoveParams() {
{
move_param tc;
tc.description = "From safely shutdown DIMM to non-pmem";
tc.pmem = true;
if (safe_dn.size() >= 1) {
tc.enough_dimms = true;
tc.src_pool_dir = safe_dn[0].GetTestDir();
Expand All @@ -126,6 +124,7 @@ std::vector<move_param> GetMoveParams() {
{
move_param tc;
tc.description = "From non-pmem to safely shutdown DIMM";
tc.pmem = false;
if (safe_dn.size() >= 1) {
tc.enough_dimms = true;
tc.src_pool_dir = test_phase.GetTestDir();
Expand All @@ -145,6 +144,7 @@ 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;
}

/**
Expand All @@ -165,12 +165,14 @@ void MovePoolClean::SetUp() {
*/
TEST_P(MovePoolClean, TC_MOVE_POOL_CLEAN_phase_1) {
/* Step1 */
set_sds_at_create_func(false);
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();
set_sds_at_create_func(true);
if (pmem == false)
set_sds_at_create_func(true);

/* Step2 */
ObjData<int> pd{pop_};
Expand Down Expand Up @@ -227,9 +229,13 @@ 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
3 changes: 2 additions & 1 deletion src/tests/ras/unsafe_shutdown/local_move_tests.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018, Intel Corporation
* Copyright 2018-2024, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -40,6 +40,7 @@ struct move_param {
std::string src_pool_dir;
std::string dest_pool_dir;
bool enough_dimms;
bool pmem;
};

std::ostream& operator<<(std::ostream& stream, move_param const& m);
Expand Down
60 changes: 17 additions & 43 deletions src/tests/ras/unsafe_shutdown/local_replicas_tests.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023, Intel Corporation
* Copyright 2018-2024, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -37,10 +37,13 @@ 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;
}

/**
Expand Down Expand Up @@ -71,10 +74,14 @@ 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 @@ -135,6 +142,7 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
tc.description =
"Master replica on unsafely shutdown DIMM, secondary replica "
"on safely shutdown DIMM.";
tc.pmem = true;
if (unsafe_dn.size() > 0 && safe_dn.size() > 0) {
tc.enough_dimms = true;
tc.poolset = Poolset{
Expand All @@ -152,29 +160,9 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
ret_vec.emplace_back(tc);
}

/* Not needed */
/* Master replica on unsafely shutdown DIMM, healthy secondary replica on
* non-pmem device. */
{
sync_local_replica_tc tc;
tc.description =
"Master replica on unsafely shutdown DIMM, healthy secondary replica "
"on non-pmem device.";
if (unsafe_dn.size() > 0) {
tc.enough_dimms = true;
tc.poolset = Poolset{
unsafe_dn[0].GetTestDir(),
"pool_tc2.set",
{{"PMEMPOOLSET",
"9MB " + unsafe_dn[0].GetTestDir() + "tc2_master.part0",
"9MB " + unsafe_dn[0].GetTestDir() + "tc2_master.part1"},
{"REPLICA", "9MB " + test_phase.GetTestDir() + "tc2_replica.part0",
"9MB " + test_phase.GetTestDir() + "tc2_replica.part1"}}};
tc.is_syncable = true;
} else {
tc.enough_dimms = false;
}
ret_vec.emplace_back(tc);
}

/* Two local secodary replicas, one partially on unsafely shutdown DIMM, other
* on safely shutdown DIMM.
Expand All @@ -184,6 +172,7 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
tc.description =
"Healthy secondary replica on safely shutdown DIMM; replica partially "
"on unsafely shutdown DIMM ";
tc.pmem = true;
if (unsafe_dn.size() > 0 && safe_dn.size() > 0) {
tc.enough_dimms = true;
tc.poolset = Poolset{
Expand All @@ -209,6 +198,7 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
sync_local_replica_tc tc;
tc.description =
"Master and secondary replicas on same unsafely shutdown DIMM.";
tc.pmem = false;
if (unsafe_dn.size() > 0) {
tc.enough_dimms = true;
tc.poolset = Poolset{
Expand All @@ -233,6 +223,7 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
tc.description =
"Master and secondary replica partially interleaved on unsafely and "
"safely shutdown DIMMs.";
tc.pmem = false;
if (unsafe_dn.size() > 0 && safe_dn.size() > 0) {
tc.enough_dimms = true;
tc.poolset = Poolset{
Expand All @@ -255,6 +246,7 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
sync_local_replica_tc tc;
tc.description =
"Master and secondary replica on different unsafely shutdown DIMMs.";
tc.pmem = false;
if (unsafe_dn.size() > 1) {
tc.enough_dimms = true;
tc.poolset = Poolset{
Expand All @@ -280,6 +272,7 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
tc.description =
"Master and secondary replica partially on two unsafely shutdown "
"dimms.";
tc.pmem = false;
if (unsafe_dn.size() >= 2) {
tc.enough_dimms = true;
tc.poolset = Poolset{
Expand All @@ -297,29 +290,9 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
ret_vec.emplace_back(tc);
}

/* Not needed */
/* Master replica and secondary replica partially on non-pmem,
* partially on two us-dimms. */
{
sync_local_replica_tc tc;
tc.description =
"Master and secondary replica partially on non-pmem, partially on two "
"unsafely shutdown dimms.";
if (unsafe_dn.size() >= 2) {
tc.enough_dimms = true;
tc.poolset = Poolset{
unsafe_dn[0].GetTestDir(),
"pool5.set",
{{"PMEMPOOLSET", "9MB " + unsafe_dn[0].GetTestDir() + "master5.part0",
"9MB " + test_phase.GetTestDir() + "master5.part1",
"9MB " + unsafe_dn[0].GetTestDir() + "master5.part2"},
{"REPLICA", "9MB " + unsafe_dn[1].GetTestDir() + "replica5.part0",
"18MB " + test_phase.GetTestDir() + "replica5.part1"}}};
tc.is_syncable = false;
} else {
tc.enough_dimms = false;
}
ret_vec.emplace_back(tc);
}

/* Master and two secondary replicas on unsafely shutdown DIMMs */
{
Expand All @@ -328,6 +301,7 @@ std::vector<sync_local_replica_tc> GetSyncLocalReplicaParams() {
"Master replica on unsafely shutdown DIMM 1, secondary replica on "
"unsafely shutdown DIMM 1, secondary replica on unsafely shutdown DIMM "
"2";
tc.pmem = false;
if (unsafe_dn.size() >= 2) {
tc.enough_dimms = true;
tc.poolset = Poolset{
Expand Down
1 change: 1 addition & 0 deletions src/tests/ras/unsafe_shutdown/local_replicas_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct sync_local_replica_tc {
Poolset poolset;
bool enough_dimms;
bool is_syncable;
bool pmem;
};

class SyncLocalReplica
Expand Down
9 changes: 9 additions & 0 deletions src/tests/ras/unsafe_shutdown/unsafe_shutdown.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,12 @@ 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);
}
}
2 changes: 2 additions & 0 deletions src/tests/ras/unsafe_shutdown/unsafe_shutdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ class UnsafeShutdown : public ::testing::Test {
void StampPassedResult() const;
};

void set_sds_at_create_func(bool state);

#endif // UNSAFE_SHUTDOWN_H

0 comments on commit 5be3af9

Please sign in to comment.