From 046665be8080c68d81f9febe0410cdae00aac16c Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 16 Jun 2021 16:40:01 +0200 Subject: [PATCH] Tests: add test_templates using PitySwarm --- test/test_template_swarm_multi.cc | 65 ++++++++++++++++++++++++++++++ test/test_template_swarm_single.cc | 55 +++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 test/test_template_swarm_multi.cc create mode 100644 test/test_template_swarm_single.cc diff --git a/test/test_template_swarm_multi.cc b/test/test_template_swarm_multi.cc new file mode 100644 index 0000000..4aec53a --- /dev/null +++ b/test/test_template_swarm_multi.cc @@ -0,0 +1,65 @@ +#include "pitytest11/src/PityUnit.hh" +#include "pitytest11/src/PityModel.hh" +#include "pitytest11/src/PitySwarm.hh" +#include "pitytest11/src/PityPerspective.hh" +#include "../src/utils.hh" +#include "framework/framework.hh" +#include "framework/utils.hh" + +#include +#include +#include +#include +#include +#include +#include + +using namespace pEp; +using namespace pEp::Adapter; +using namespace pEp::Test::Utils; +using namespace pEp::PityTest11; + +// Test template for 3 nodes (processes) running the same 2 tests each in their own environment in parallel + +// This is the 1st test unit +void test_func1(PityUnit &pity, PityPerspective *ctx) +{ + pity.log(ctx->name); + pity.log("getName: " + pity.getName()); + pity.log("getPath: " +pity.getPath()); + pity.log("getPathShort: " +pity.getPathShort()); + pity.log("transportDir: " +pity.transportDir()); + pity.log("processDir: " +pity.processDir()); + pity.log("getGlobalRootDir: " +pity.getGlobalRootDir()); + pity.log("to_string: " +pity.to_string()); + + PTASSERT(true); +} + +// This is the 2nd test unit +void test_func2(PityUnit &pity, PityPerspective *ctx) +{ + pity.log(ctx->name); + PTASSERT(false); +} + + +int main(int argc, char *argv[]) +{ + int nodecount = 3; + PityModel model{ "templ_swarm_multi", nodecount }; + PitySwarm swarm{ model }; + + // 1. Create the swarm process TestUnit + // 2. Append a PityUnit to process 1 unit + auto unit1 = swarm.addTestUnit(0, "unit1", test_func1); + auto unit1_1 = PityUnit(unit1,"unit1_1", test_func2); + + auto unit2 = swarm.addTestUnit(1, "unit2", test_func1); + auto unit2_1 = PityUnit(unit2,"unit2_1", test_func2); + + auto unit3 = swarm.addTestUnit(2, "unit3", test_func1); + auto unit3_1 = PityUnit(unit3,"unit3_1", test_func2); + + swarm.run(); +} \ No newline at end of file diff --git a/test/test_template_swarm_single.cc b/test/test_template_swarm_single.cc new file mode 100644 index 0000000..f546be2 --- /dev/null +++ b/test/test_template_swarm_single.cc @@ -0,0 +1,55 @@ +#include "pitytest11/src/PityUnit.hh" +#include "pitytest11/src/PityModel.hh" +#include "pitytest11/src/PitySwarm.hh" +#include "pitytest11/src/PityPerspective.hh" +#include "../src/utils.hh" +#include "framework/framework.hh" +#include "framework/utils.hh" + +#include +#include +#include +#include +#include +#include +#include + +using namespace pEp; +using namespace pEp::Adapter; +using namespace pEp::Test::Utils; +using namespace pEp::PityTest11; + +// Test template for a single process with 2 test units that run in sequence + +// This is the 1st test unit +void test_func1(PityUnit &pity, PityPerspective *ctx) +{ + // here some example values from the PityUnit + pity.log("getName: " + pity.getName()); + pity.log("getPath: " + pity.getPath()); + pity.log("getPathShort: " + pity.getPathShort()); + pity.log("transportDir: " + pity.transportDir()); + pity.log("processDir: " + pity.processDir()); + pity.log("getGlobalRootDir: " + pity.getGlobalRootDir()); + pity.log("to_string: " + pity.to_string(false)); + PTASSERT(true); +} + +// This is the 2nd test unit +void test_func2(PityUnit &pity, PityPerspective *ctx) +{ + pity.log(ctx->name); + PTASSERT(false); +} + + +int main(int argc, char *argv[]) +{ + PityModel model{ "templ_swarm_single", 1 }; + PitySwarm swarm{ model }; + + auto unit1 = swarm.addTestUnit(0, "unit1", test_func1); + auto unit1_1 = PityUnit(unit1, "unit1_1", test_func2); + + swarm.run(); +} \ No newline at end of file