Browse Source

Test: PityTest - test_execmodes use model /prettify

LIB-11
heck 4 years ago
parent
commit
8816b1e65e
  1. 63
      test/pitytest11/test/test_execmodes.cc

63
test/pitytest11/test/test_execmodes.cc

@ -7,59 +7,58 @@ using namespace std;
using namespace pEp; using namespace pEp;
using namespace pEp::PityTest11; using namespace pEp::PityTest11;
void do_some_work(PityUnit<>& myself, int sleepmilis, int rep_count)
struct CTXExecmodes {
int sleepmilis;
int rep_count;
};
using TestContext = CTXExecmodes;
using TestUnit = PityUnit<TestContext>;
int do_some_work(TestUnit& pity, TestContext* ctx)
{ {
int i = 0; int i = 0;
while (i < rep_count) { while (i < ctx->rep_count) {
myself.log(myself.getName() + " - " + to_string(i)); pity.log(pity.getName() + " - " + to_string(i));
Utils::sleep_millis(sleepmilis); Utils::sleep_millis(ctx->sleepmilis);
i++; i++;
} }
return 0;
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
{
// DEBUG Logging of PityTestUnit itself // DEBUG Logging of PityTestUnit itself
PityUnit<>::debug_log_enabled = false; TestUnit::debug_log_enabled = false;
CTXExecmodes ctxe;
ctxe.sleepmilis = 100;
ctxe.rep_count = 3;
// The RootNode is the // The RootNode is the
PityUnit<> root = PityUnit<>{ nullptr, "Test Execution Model" }; TestUnit root = TestUnit{ nullptr, "Test Execution Model" };
// Subprocess 1 // Subprocess 1
PityUnit<> test1 = PityUnit<>{ &root, TestUnit test1 = TestUnit{ &root,
"node1", "node1",
[](PityUnit<>& unit, void* ctx) { do_some_work,
do_some_work(unit, 200, 10); &ctxe,
}, TestUnit::ExecutionMode::PROCESS_PARALLEL };
nullptr,
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL };
PityUnit<> test1_1 = PityUnit<>{ &test1, "test1.1", [](PityUnit<>& unit, void* ctx) { TestUnit test1_1 = TestUnit{ &test1, "test1.1", do_some_work };
do_some_work(unit, 200, 10);
} };
PityUnit<> test1_2 = PityUnit<>{ &test1, "test1.2", [](PityUnit<>& unit, void* ctx) { TestUnit test1_2 = TestUnit{ &test1, "test1.2", do_some_work };
do_some_work(unit, 200, 10);
} };
// Subprocess 2 // Subprocess 2
PityUnit<> test2 = PityUnit<>{ &root, TestUnit test2 = TestUnit{ &root,
"node2", "node2",
[](PityUnit<>& unit, void* ctx) { do_some_work,
do_some_work(unit, 200, 10); &ctxe,
}, TestUnit::ExecutionMode::PROCESS_PARALLEL };
nullptr,
pEp::PityTest11::PityUnit<>::ExecutionMode::PROCESS_PARALLEL };
PityUnit<> test2_1 = PityUnit<>{ &test2, "test2.1", [](PityUnit<>& unit, void* ctx) { TestUnit test2_1 = TestUnit{ &test2, "test2.1", do_some_work };
do_some_work(unit, 200, 10);
} };
PityUnit<> test2_2 = PityUnit<>{ &test2, "test2.2", [](PityUnit<>& unit, void* ctx) { TestUnit test2_2 = TestUnit{ &test2, "test2.2", do_some_work };
do_some_work(unit, 200, 10);
} };
root.run(); root.run();
}
} }
Loading…
Cancel
Save