Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use template parameter for ActivityPtr in testing_test-wait.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 12 Feb 2021 10:24:49 +0000 (11:24 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 12 Feb 2021 11:37:03 +0000 (12:37 +0100)
teshsuite/s4u/activity-lifecycle/testing_test-wait.cpp

index 52d79a5..d88a11a 100644 (file)
@@ -7,6 +7,8 @@
 
 //========== Creators: create an async activity
 
+template <typename Activity> using creator_type = Activity (*)(double);
+
 // Create a new async execution with given duration
 static simgrid::s4u::ActivityPtr create_exec(double duration)
 {
@@ -16,10 +18,10 @@ static simgrid::s4u::ActivityPtr create_exec(double duration)
 
 // TODO: check other kinds of activities too (Io, Comm, ...)
 
-using creator_type = decltype(create_exec);
-
 //========== Testers: test the completion of an activity
 
+template <typename Activity> using tester_type = bool (*)(const Activity&);
+
 // Calls activity->test() and returns its result
 static bool tester_test(const simgrid::s4u::ActivityPtr& activity)
 {
@@ -51,10 +53,10 @@ template <int Duration> bool tester_wait(const simgrid::s4u::ActivityPtr& activi
   return ret;
 }
 
-using tester_type = decltype(tester_test);
-
 //========== Waiters: wait for the completion of an activity
 
+template <typename Activity> using waiter_type = void (*)(const Activity&);
+
 // Wait for 6s
 static void waiter_sleep6(const simgrid::s4u::ActivityPtr&)
 {
@@ -69,17 +71,15 @@ static void waiter_wait(const simgrid::s4u::ActivityPtr& activity)
   XBT_DEBUG("end of wait()");
 }
 
-using waiter_type = decltype(waiter_wait);
-
 //========== Finally, the test templates
 
-template <creator_type Create, tester_type Test> void test_trivial()
+template <typename Activity, creator_type<Activity> Create, tester_type<Activity> Test> void test_trivial()
 {
   XBT_INFO("Launch an activity for 5s, and let it proceed before test");
 
   simgrid::s4u::ActorPtr actor = simgrid::s4u::Actor::create("actor", all_hosts[1], []() {
     assert_exit(true, 6.);
-    simgrid::s4u::ActivityPtr activity = Create(5.0);
+    Activity activity = Create(5.0);
     simgrid::s4u::this_actor::sleep_for(6.0);
     INFO("activity should be terminated now");
     REQUIRE(Test(activity));
@@ -87,13 +87,13 @@ template <creator_type Create, tester_type Test> void test_trivial()
   actor->join();
 }
 
-template <creator_type Create, tester_type Test> void test_basic()
+template <typename Activity, creator_type<Activity> Create, tester_type<Activity> Test> void test_basic()
 {
   XBT_INFO("Launch an activity for 5s, and test while it proceeds");
 
   simgrid::s4u::ActorPtr actor = simgrid::s4u::Actor::create("actor", all_hosts[1], []() {
     assert_exit(true, 6.);
-    simgrid::s4u::ActivityPtr activity = Create(5.0);
+    Activity activity = Create(5.0);
     for (int i = 0; i < 3; i++) {
       const double timestep = simgrid::s4u::Engine::get_clock() + 2.0;
       INFO("activity should be still running (i = " << i << ")");
@@ -106,13 +106,13 @@ template <creator_type Create, tester_type Test> void test_basic()
   actor->join();
 }
 
-template <creator_type Create, tester_type Test> void test_cancel()
+template <typename Activity, creator_type<Activity> Create, tester_type<Activity> Test> void test_cancel()
 {
   XBT_INFO("Launch an activity for 5s, and cancel it after 2s");
 
   simgrid::s4u::ActorPtr actor = simgrid::s4u::Actor::create("actor", all_hosts[1], []() {
     assert_exit(true, 2.);
-    simgrid::s4u::ActivityPtr activity = Create(5.0);
+    Activity activity = Create(5.0);
     simgrid::s4u::this_actor::sleep_for(2.0);
     activity->cancel();
     INFO("activity should be terminated now");
@@ -121,11 +121,12 @@ template <creator_type Create, tester_type Test> void test_cancel()
   actor->join();
 }
 
-template <creator_type Create, tester_type Test, waiter_type Wait> void test_failure_actor()
+template <typename Activity, creator_type<Activity> Create, tester_type<Activity> Test, waiter_type<Activity> Wait>
+void test_failure_actor()
 {
   XBT_INFO("Launch an activity for 5s, and kill running actor after 2s");
 
-  simgrid::s4u::ActivityPtr activity;
+  Activity activity;
   simgrid::s4u::ActorPtr actor = simgrid::s4u::Actor::create("actor", all_hosts[1], [&activity]() {
     assert_exit(false, 2.);
     activity = Create(5.0);
@@ -142,11 +143,12 @@ template <creator_type Create, tester_type Test, waiter_type Wait> void test_fai
   REQUIRE(Test(activity));
 }
 
-template <creator_type Create, tester_type Test, waiter_type Wait> void test_failure_host()
+template <typename Activity, creator_type<Activity> Create, tester_type<Activity> Test, waiter_type<Activity> Wait>
+void test_failure_host()
 {
   XBT_INFO("Launch an activity for 5s, and shutdown host 2s");
 
-  simgrid::s4u::ActivityPtr activity;
+  Activity activity;
   simgrid::s4u::ActorPtr actor = simgrid::s4u::Actor::create("actor", all_hosts[1], [&activity]() {
     assert_exit(false, 2.);
     activity = Create(5.0);
@@ -166,17 +168,23 @@ template <creator_type Create, tester_type Test, waiter_type Wait> void test_fai
 
 //==========
 
+using simgrid::s4u::ActivityPtr;
+
 TEST_CASE("Activity test/wait: using <tester_test>")
 {
   XBT_INFO("#####[ launch next test ]#####");
 
-  RUN_SECTION("exec: run and test once", test_trivial<create_exec, tester_test>);
-  RUN_SECTION("exec: run and test many", test_basic<create_exec, tester_test>);
-  RUN_SECTION("exec: cancel and test", test_cancel<create_exec, tester_test>);
-  RUN_SECTION("exec: actor failure and test / sleep", test_failure_actor<create_exec, tester_test, waiter_sleep6>);
-  RUN_SECTION("exec: host failure and test / sleep", test_failure_host<create_exec, tester_test, waiter_sleep6>);
-  RUN_SECTION("exec: actor failure and test / wait", test_failure_actor<create_exec, tester_test, waiter_wait>);
-  RUN_SECTION("exec: host failure and test / wait", test_failure_host<create_exec, tester_test, waiter_wait>);
+  RUN_SECTION("exec: run and test once", test_trivial<ActivityPtr, create_exec, tester_test>);
+  RUN_SECTION("exec: run and test many", test_basic<ActivityPtr, create_exec, tester_test>);
+  RUN_SECTION("exec: cancel and test", test_cancel<ActivityPtr, create_exec, tester_test>);
+  RUN_SECTION("exec: actor failure and test / sleep",
+              test_failure_actor<ActivityPtr, create_exec, tester_test, waiter_sleep6>);
+  RUN_SECTION("exec: host failure and test / sleep",
+              test_failure_host<ActivityPtr, create_exec, tester_test, waiter_sleep6>);
+  RUN_SECTION("exec: actor failure and test / wait",
+              test_failure_actor<ActivityPtr, create_exec, tester_test, waiter_wait>);
+  RUN_SECTION("exec: host failure and test / wait",
+              test_failure_host<ActivityPtr, create_exec, tester_test, waiter_wait>);
 
   simgrid::s4u::this_actor::sleep_for(10);
   assert_cleanup();
@@ -186,9 +194,9 @@ TEST_CASE("Activity test/wait: using <tester_wait<0>>")
 {
   XBT_INFO("#####[ launch next test ]#####");
 
-  RUN_SECTION("exec: run and wait<0> once", test_trivial<create_exec, tester_wait<0>>);
+  RUN_SECTION("exec: run and wait<0> once", test_trivial<ActivityPtr, create_exec, tester_wait<0>>);
   // exec: run and wait<0> many
-  RUN_SECTION("exec: cancel and wait<0>", test_cancel<create_exec, tester_wait<0>>);
+  RUN_SECTION("exec: cancel and wait<0>", test_cancel<ActivityPtr, create_exec, tester_wait<0>>);
   // exec: actor failure and wait<0> / sleep
   // exec: host failure and wait<0> / sleep
   // exec: actor failure and wait<0> / wait
@@ -202,9 +210,9 @@ TEST_CASE("Activity test/wait: using <tester_wait<1>>")
 {
   XBT_INFO("#####[ launch next test ]#####");
 
-  RUN_SECTION("exec: run and wait<1> once", test_trivial<create_exec, tester_wait<1>>);
+  RUN_SECTION("exec: run and wait<1> once", test_trivial<ActivityPtr, create_exec, tester_wait<1>>);
   // exec: run and wait<1> many
-  RUN_SECTION("exec: cancel and wait<1>", test_cancel<create_exec, tester_wait<1>>);
+  RUN_SECTION("exec: cancel and wait<1>", test_cancel<ActivityPtr, create_exec, tester_wait<1>>);
   // exec: actor failure and wait<1> / sleep
   // exec: host failure and wait<1> / sleep
   // exec: actor failure and wait<1> / wait
@@ -221,18 +229,26 @@ TEST_CASE("Activity test/wait: tests currently failing", "[.][failing]")
   XBT_INFO("#####[ launch next failing test ]#####");
 
   // with tester_wait<0>
-  RUN_SECTION("exec: run and wait<0> many", test_basic<create_exec, tester_wait<0>>);
-  RUN_SECTION("exec: actor failure and wait<0> / sleep", test_failure_actor<create_exec, tester_wait<0>, waiter_sleep6>);
-  RUN_SECTION("exec: host failure and wait<0> / sleep", test_failure_host<create_exec, tester_wait<0>, waiter_sleep6>);
-  RUN_SECTION("exec: actor failure and wait<0> / wait", test_failure_actor<create_exec, tester_wait<0>, waiter_wait>);
-  RUN_SECTION("exec: host failure and wait<0> / wait", test_failure_host<create_exec, tester_wait<0>, waiter_wait>);
-
-  // with tester_test<1>
-  RUN_SECTION("exec: run and wait<1> many", test_basic<create_exec, tester_wait<1>>);
-  RUN_SECTION("exec: actor failure and wait<1> / sleep", test_failure_actor<create_exec, tester_wait<1>, waiter_sleep6>);
-  RUN_SECTION("exec: host failure and wait<1> / sleep", test_failure_host<create_exec, tester_wait<1>, waiter_sleep6>);
-  RUN_SECTION("exec: actor failure and wait<1> / wait", test_failure_actor<create_exec, tester_wait<1>, waiter_wait>);
-  RUN_SECTION("exec: host failure and wait<1> / wait", test_failure_host<create_exec, tester_wait<1>, waiter_wait>);
+  RUN_SECTION("exec: run and wait<0> many", test_basic<ActivityPtr, create_exec, tester_wait<0>>);
+  RUN_SECTION("exec: actor failure and wait<0> / sleep",
+              test_failure_actor<ActivityPtr, create_exec, tester_wait<0>, waiter_sleep6>);
+  RUN_SECTION("exec: host failure and wait<0> / sleep",
+              test_failure_host<ActivityPtr, create_exec, tester_wait<0>, waiter_sleep6>);
+  RUN_SECTION("exec: actor failure and wait<0> / wait",
+              test_failure_actor<ActivityPtr, create_exec, tester_wait<0>, waiter_wait>);
+  RUN_SECTION("exec: host failure and wait<0> / wait",
+              test_failure_host<ActivityPtr, create_exec, tester_wait<0>, waiter_wait>);
+
+  // with tester_wait<1>
+  RUN_SECTION("exec: run and wait<1> many", test_basic<ActivityPtr, create_exec, tester_wait<1>>);
+  RUN_SECTION("exec: actor failure and wait<1> / sleep",
+              test_failure_actor<ActivityPtr, create_exec, tester_wait<1>, waiter_sleep6>);
+  RUN_SECTION("exec: host failure and wait<1> / sleep",
+              test_failure_host<ActivityPtr, create_exec, tester_wait<1>, waiter_sleep6>);
+  RUN_SECTION("exec: actor failure and wait<1> / wait",
+              test_failure_actor<ActivityPtr, create_exec, tester_wait<1>, waiter_wait>);
+  RUN_SECTION("exec: host failure and wait<1> / wait",
+              test_failure_host<ActivityPtr, create_exec, tester_wait<1>, waiter_wait>);
 
   simgrid::s4u::this_actor::sleep_for(10);
   assert_cleanup();