From 6ea1c1d09019f252214c02677f0d550fb180cfca Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 16 Feb 2016 00:13:27 +0100 Subject: [PATCH] add a test for this example --- examples/msg/semaphores/synchro.c | 21 +++----- examples/msg/semaphores/synchro.tesh | 76 ++++++++++++++++++++++++++++ tools/cmake/Tests.cmake | 1 + 3 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 examples/msg/semaphores/synchro.tesh diff --git a/examples/msg/semaphores/synchro.c b/examples/msg/semaphores/synchro.c index 5919698b26..7fab442c3f 100644 --- a/examples/msg/semaphores/synchro.c +++ b/examples/msg/semaphores/synchro.c @@ -4,20 +4,16 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include #include #include "simgrid/msg.h" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_semaphore_example, - "Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_semaphore_example, "Messages specific for this msg example"); msg_sem_t sem; static int peer(int argc, char* argv[]){ - int i = 0; - while(i < argc) { double wait_time = xbt_str_parse_double(argv[i++],"Invalid wait time: %s"); MSG_process_sleep(wait_time); @@ -37,11 +33,11 @@ static int peer(int argc, char* argv[]){ return 0; } -int main(int argc, char* argv[]) { - +int main(int argc, char* argv[]) +{ MSG_init(&argc, argv); MSG_create_environment(argv[1]); - + xbt_dynar_t hosts = MSG_hosts_as_dynar(); msg_host_t h = xbt_dynar_get_as(hosts,0,msg_host_t); @@ -69,14 +65,11 @@ int main(int argc, char* argv[]) { bobTimes[nbBob++] = xbt_strdup("0"); bobTimes[nbBob++] = xbt_strdup("5"); bobTimes[nbBob++] = NULL; - - MSG_process_create_with_arguments(xbt_strdup("Alice"), peer, NULL, - h, 8, aliceTimes); - MSG_process_create_with_arguments(xbt_strdup("Bob"), peer, NULL, - h, 8, bobTimes); + MSG_process_create_with_arguments(xbt_strdup("Alice"), peer, NULL, h, 8, aliceTimes); + MSG_process_create_with_arguments(xbt_strdup("Bob"), peer, NULL, h, 8, bobTimes); msg_error_t res = MSG_main(); - printf("Finished\n"); + XBT_INFO("Finished\n"); return (res != MSG_OK); } diff --git a/examples/msg/semaphores/synchro.tesh b/examples/msg/semaphores/synchro.tesh new file mode 100644 index 0000000000..e0b97dab25 --- /dev/null +++ b/examples/msg/semaphores/synchro.tesh @@ -0,0 +1,76 @@ +#! ./tesh + +p Testing synchronization with semaphores + +! output sort 19 +$ $SG_TEST_EXENV semaphores/synchro ${srcdir:=.}/../platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:Alice@Fafard) Trying to acquire 1 +> [ 0.000000] (1:Alice@Fafard) Acquired 1 +> [ 0.900000] (2:Bob@Fafard) Trying to acquire 1 +> [ 1.000000] (1:Alice@Fafard) Releasing 2 +> [ 1.000000] (2:Bob@Fafard) Acquired 1 +> [ 1.000000] (1:Alice@Fafard) Released 2 +> [ 2.000000] (2:Bob@Fafard) Releasing 2 +> [ 2.000000] (2:Bob@Fafard) Released 2 +> [ 3.000000] (2:Bob@Fafard) Trying to acquire 3 +> [ 3.000000] (2:Bob@Fafard) Acquired 3 +> [ 4.000000] (1:Alice@Fafard) Trying to acquire 3 +> [ 5.000000] (2:Bob@Fafard) Releasing 4 +> [ 5.000000] (1:Alice@Fafard) Acquired 3 +> [ 5.000000] (2:Bob@Fafard) Released 4 +> [ 7.000000] (2:Bob@Fafard) Trying to acquire 5 +> [ 10.000000] (1:Alice@Fafard) Releasing 4 +> [ 10.000000] (2:Bob@Fafard) Acquired 5 +> [ 10.000000] (1:Alice@Fafard) Released 4 +> [ 10.000000] (2:Bob@Fafard) Releasing 6 +> [ 10.000000] (2:Bob@Fafard) Released 6 +> [ 10.000000] (2:Bob@Fafard) Trying to acquire 7 +> [ 10.000000] (2:Bob@Fafard) Acquired 7 +> [ 11.000000] (1:Alice@Fafard) Trying to acquire 5 +> [ 15.000000] (2:Bob@Fafard) Releasing 8 +> [ 15.000000] (1:Alice@Fafard) Acquired 5 +> [ 15.000000] (2:Bob@Fafard) Released 8 +> [ 17.000000] (1:Alice@Fafard) Releasing 6 +> [ 17.000000] (1:Alice@Fafard) Released 6 +> [ 22.000000] (1:Alice@Fafard) Trying to acquire 7 +> [ 22.000000] (1:Alice@Fafard) Acquired 7 +> [ 22.000000] (1:Alice@Fafard) Releasing 8 +> [ 22.000000] (1:Alice@Fafard) Released 8 +> [ 65.000000] (2:Bob@Fafard) Done +> [ 72.000000] (1:Alice@Fafard) Done +> [ 72.000000] (0:maestro@) Finished + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index 08c54191bd..7d582cd123 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -242,6 +242,7 @@ IF(NOT enable_memcheck) ADD_TESH_FACTORIES(msg-ptask "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/parallel_task/parallel_task.tesh) ADD_TESH_FACTORIES(msg-priority "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/priority/priority.tesh) ADD_TESH_FACTORIES(msg-properties "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/properties/msg_prop.tesh) + ADD_TESH_FACTORIES(msg-semaphores "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/semaphores/synchro.tesh) ADD_TESH_FACTORIES(msg-icomms "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg/icomms --cd ${CMAKE_BINARY_DIR}/examples/msg/icomms ${CMAKE_HOME_DIRECTORY}/examples/msg/icomms/peer.tesh) ADD_TESH_FACTORIES(msg-actions "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/actions --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/actions actions.tesh) ADD_TESH_FACTORIES(msg-chord-no-crosstraffic "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/chord --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/chord chord.tesh) -- 2.20.1