From: Arnaud Giersch Date: Thu, 13 Feb 2020 08:35:02 +0000 (+0100) Subject: Update tests. X-Git-Tag: v3.26~965 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a69ed874a1a5e699e354f52f2ebc1dd60bf7c89f Update tests. Code factorization, more debug messages, prepare for other kinds of activities. --- diff --git a/.gitignore b/.gitignore index 70c6b5fbd0..a1774bfc3c 100644 --- a/.gitignore +++ b/.gitignore @@ -280,6 +280,7 @@ teshsuite/s4u/actor/actor teshsuite/s4u/actor-autorestart/actor-autorestart teshsuite/s4u/actor-migration/actor-migration teshsuite/s4u/activity-lifecycle/activity-lifecycle +teshsuite/s4u/activity-test-wait/activity-test-wait teshsuite/s4u/cloud-interrupt-migration/cloud-interrupt-migration teshsuite/s4u/cloud-sharing/cloud-sharing teshsuite/s4u/comm-pt2pt/comm-pt2pt diff --git a/teshsuite/s4u/activity-test-wait/activity-test-wait.cpp b/teshsuite/s4u/activity-test-wait/activity-test-wait.cpp index 66c61db4a5..05a5f8954d 100644 --- a/teshsuite/s4u/activity-test-wait/activity-test-wait.cpp +++ b/teshsuite/s4u/activity-test-wait/activity-test-wait.cpp @@ -9,6 +9,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); +// FIXME: fix failing tests, and remove this macro +#define FAILING if (false) + std::vector all_hosts; /* Helper function easing the testing of actor's ending condition */ @@ -49,22 +52,40 @@ static void run_test(const char* test_name, const std::function& test) ** Each tests **/ +//========== Creators: create an async activity + +// Create a new async execution with given duration +static simgrid::s4u::ActivityPtr create_exec(double duration) +{ + double speed = simgrid::s4u::this_actor::get_host()->get_speed(); + return simgrid::s4u::this_actor::exec_async(speed * duration); +} + +// TODO: check other kinds of activities too (Io, Comm, ...) + +using creator_type = decltype(create_exec); + +//========== Testers: test the completion of an activity + // Calls exec->test() and returns its result -static bool tester_test(simgrid::s4u::ExecPtr& exec) +static bool tester_test(const simgrid::s4u::ActivityPtr& exec) { return exec->test(); } // Calls exec->wait_for(Duration * 0.0125) and returns true when exec is terminated, just like test() -template bool tester_wait(simgrid::s4u::ExecPtr& exec) +template bool tester_wait(const simgrid::s4u::ActivityPtr& exec) { bool ret; try { exec->wait_for(Duration * 0.0125); + XBT_DEBUG("wait_for() returned normally"); ret = true; - } catch (const simgrid::TimeoutException&) { + } catch (const simgrid::TimeoutException& e) { + XBT_DEBUG("wait_for() timed out (%s)", e.what()); ret = false; - } catch (const simgrid::Exception&) { + } catch (const simgrid::Exception& e) { + XBT_DEBUG("wait_for() threw an exception: %s", e.what()); ret = true; } return ret; @@ -72,148 +93,135 @@ template bool tester_wait(simgrid::s4u::ExecPtr& exec) using tester_type = decltype(tester_test); -template void test_trivial() +//========== Waiters: wait for the completion of an activity + +// Wait for 6s +static void waiter_sleep6(const simgrid::s4u::ActivityPtr&) { - XBT_INFO("%s: Launch a execute(5s), and let it proceed before test", __func__); + simgrid::s4u::this_actor::sleep_for(6.0); + XBT_DEBUG("wake up after 6s sleep"); +} + +// Wait for completion of exec +static void waiter_wait(const simgrid::s4u::ActivityPtr& exec) +{ + exec->wait(); + XBT_DEBUG("end of wait()"); +} + +using waiter_type = decltype(waiter_wait); + +//========== Finally, the test templates + +template void test_trivial() +{ + XBT_INFO("%s: Launch an activity for 5s, and let it proceed before test", __func__); simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], []() { assert_exit(false, 6.); - auto exec = simgrid::s4u::this_actor::exec_async(500000000); + simgrid::s4u::ActivityPtr activity = Create(5.0); simgrid::s4u::this_actor::sleep_for(6.0); - xbt_assert(Test(exec), "exec should be terminated now"); + xbt_assert(Test(activity), "activity should be terminated now"); }); exec5->join(); } -template void test_basic() +template void test_basic() { - XBT_INFO("%s: Launch a execute(5s), and test while it proceeds", __func__); + XBT_INFO("%s: Launch an activity for 5s, and test while it proceeds", __func__); simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], []() { assert_exit(false, 6.); - auto exec = simgrid::s4u::this_actor::exec_async(500000000); + simgrid::s4u::ActivityPtr activity = Create(5.0); for (int i = 0; i < 3; i++) { - xbt_assert(not Test(exec), "exec finished too soon (i = %d)!?", i); + xbt_assert(not Test(activity), "activity finished too soon (i = %d)!?", i); simgrid::s4u::this_actor::sleep_for(2.0); } - xbt_assert(Test(exec), "exec should be terminated now"); + xbt_assert(Test(activity), "activity should be terminated now"); }); exec5->join(); } -template void test_cancel() +template void test_cancel() { - XBT_INFO("%s: Launch a execute(5s), and cancel it after 2s", __func__); + XBT_INFO("%s: Launch an activity for 5s, and cancel it after 2s", __func__); simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], []() { assert_exit(false, 2.); - auto exec = simgrid::s4u::this_actor::exec_async(500000000); + simgrid::s4u::ActivityPtr activity = Create(5.0); simgrid::s4u::this_actor::sleep_for(2.0); - exec->cancel(); - xbt_assert(Test(exec), "exec should be terminated now"); + activity->cancel(); + xbt_assert(Test(activity), "activity should be terminated now"); }); exec5->join(); } -template void test_failure_actor_sleep() +template void test_failure_actor() { - XBT_INFO("%s: Launch a execute(5s), and kill running actor after 2s (sleep during exec)", __func__); + XBT_INFO("%s: Launch an activity for 5s, and kill running actor after 2s", __func__); - simgrid::s4u::ExecPtr exec; - simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], [&exec]() { + simgrid::s4u::ActivityPtr activity; + simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], [&activity]() { assert_exit(true, 2.); - exec = simgrid::s4u::this_actor::exec_async(500000000); - simgrid::s4u::this_actor::sleep_for(6.0); - XBT_ERROR("should not be here!"); + activity = Create(5.0); + Wait(activity); + xbt_die("should not be here!"); }); simgrid::s4u::this_actor::sleep_for(2.0); - xbt_assert(not Test(exec), "exec finished too soon!?"); + xbt_assert(not Test(activity), "activity finished too soon!?"); exec5->kill(); - xbt_assert(Test(exec), "exec should be terminated now"); + xbt_assert(Test(activity), "activity should be terminated now"); } -template void test_failure_host_sleep() +template void test_failure_host() { - XBT_INFO("%s: Launch a execute(5s), and shutdown host 2s (sleep during exec)", __func__); + XBT_INFO("%s: Launch an activity for 5s, and shutdown host 2s", __func__); - simgrid::s4u::ExecPtr exec; - simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], [&exec]() { + simgrid::s4u::ActivityPtr activity; + simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], [&activity]() { assert_exit(true, 2.); - exec = simgrid::s4u::this_actor::exec_async(500000000); - simgrid::s4u::this_actor::sleep_for(6.0); - XBT_ERROR("should not be here!"); + activity = Create(5.0); + Wait(activity); + xbt_die("should not be here!"); }); simgrid::s4u::this_actor::sleep_for(2.0); - xbt_assert(not Test(exec), "exec finished too soon!?"); + xbt_assert(not Test(activity), "activity finished too soon!?"); exec5->get_host()->turn_off(); exec5->get_host()->turn_on(); - xbt_assert(Test(exec), "exec should be terminated now"); -} - -template void test_failure_actor_wait() -{ - XBT_INFO("%s: Launch a execute(5s), and kill running actor after 2s (wait for exec)", __func__); - - simgrid::s4u::ExecPtr exec; - simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], [&exec]() { - assert_exit(true, 2.); - exec = simgrid::s4u::this_actor::exec_async(500000000); - exec->wait(); - XBT_ERROR("should not be here!"); - }); - simgrid::s4u::this_actor::sleep_for(2.0); - xbt_assert(not Test(exec), "exec finished too soon!?"); - exec5->kill(); - xbt_assert(Test(exec), "exec should be terminated now"); + xbt_assert(Test(activity), "activity should be terminated now"); } -template void test_failure_host_wait() -{ - XBT_INFO("%s: Launch a execute(5s), and shutdown host 2s (wait for exec)", __func__); - - simgrid::s4u::ExecPtr exec; - simgrid::s4u::ActorPtr exec5 = simgrid::s4u::Actor::create("exec5", all_hosts[1], [&exec]() { - assert_exit(true, 2.); - exec = simgrid::s4u::this_actor::exec_async(500000000); - exec->wait(); - XBT_ERROR("should not be here!"); - }); - simgrid::s4u::this_actor::sleep_for(2.0); - xbt_assert(not Test(exec), "exec finished too soon!?"); - exec5->get_host()->turn_off(); - exec5->get_host()->turn_on(); - xbt_assert(Test(exec), "exec should be terminated now"); -} +//========== /* We need an extra actor here, so that it can sleep until the end of each test */ static void main_dispatcher() { XBT_INFO("***** Using *****"); - run_test("exec and test once", test_trivial); - run_test("exec and test many", test_basic); - run_test("cancel and test", test_cancel); - // run_test("actor failure and test / sleep", test_failure_actor_sleep); - // run_test("host failure and test / sleep", test_failure_host_sleep); - run_test("actor failure and test / wait", test_failure_actor_wait); - run_test("host failure and test / wait", test_failure_host_wait); + run_test("exec: run and test once", test_trivial); + run_test("exec: run and test many", test_basic); + run_test("exec: cancel and test", test_cancel); + FAILING run_test("exec: actor failure and test / sleep", test_failure_actor); + FAILING run_test("exec: host failure and test / sleep", test_failure_host); + run_test("exec: actor failure and test / wait", test_failure_actor); + run_test("exec: host failure and test / wait", test_failure_host); XBT_INFO("***** Using > *****"); - run_test("exec and wait<0> once", test_trivial>); - // run_test("exec and wait<0> many", test_basic>); - run_test("cancel and wait<0>", test_cancel>); - // run_test("actor failure and wait<0> / sleep", test_failure_actor_sleep>); - // run_test("host failure and wait<0> / sleep", test_failure_host_sleep>); - // run_test("actor failure and wait<0> / wait", test_failure_actor_wait>); - // run_test("host failure and wait<0> / wait", test_failure_host_wait>); + run_test("exec: run and wait<0> once", test_trivial>); + FAILING run_test("exec: run and wait<0> many", test_basic>); + run_test("exec: cancel and wait<0>", test_cancel>); + FAILING run_test("exec: actor failure and wait<0> / sleep", test_failure_actor, waiter_sleep6>); + FAILING run_test("exec: host failure and wait<0> / sleep", test_failure_host, waiter_sleep6>); + FAILING run_test("exec: actor failure and wait<0> / wait", test_failure_actor, waiter_wait>); + FAILING run_test("exec: host failure and wait<0> / wait", test_failure_host, waiter_wait>); XBT_INFO("***** Using > *****"); - run_test("exec and wait<1> once", test_trivial>); - // run_test("exec and wait<1> many", test_basic>); - run_test("cancel and wait<1>", test_cancel>); - // run_test("actor failure and wait<1> / sleep", test_failure_actor_sleep>); - // run_test("host failure and wait<1> / sleep", test_failure_host_sleep>); - // run_test("actor failure and wait<1> / wait", test_failure_actor_wait>); - // run_test("host failure and wait<1> / wait", test_failure_host_wait>); + run_test("exec: run and wait<1> once", test_trivial>); + FAILING run_test("exec: run and wait<1> many", test_basic>); + run_test("exec: cancel and wait<1>", test_cancel>); + FAILING run_test("exec: actor failure and wait<1> / sleep", test_failure_actor, waiter_sleep6>); + FAILING run_test("exec: host failure and wait<1> / sleep", test_failure_host, waiter_sleep6>); + FAILING run_test("exec: actor failure and wait<1> / wait", test_failure_actor, waiter_wait>); + FAILING run_test("exec: host failure and wait<1> / wait", test_failure_host, waiter_wait>); } int main(int argc, char* argv[])