From 8c3cc1fe798afef50589651b016317b4d5abb74a Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 26 Feb 2016 21:48:10 +0100 Subject: [PATCH] simplify some msg examples test_all is from another age --- examples/msg/properties/msg_prop.c | 95 ++++++--------------- examples/msg/start_kill_time/sk_time.c | 37 ++------ examples/msg/suspend/CMakeLists.txt | 4 - examples/msg/suspend/deployment_suspend.xml | 5 -- examples/msg/suspend/suspend.c | 51 +++-------- examples/msg/suspend/suspend.tesh | 2 +- examples/msg/token_ring/ring_call.c | 44 ++++------ 7 files changed, 68 insertions(+), 170 deletions(-) delete mode 100644 examples/msg/suspend/deployment_suspend.xml diff --git a/examples/msg/properties/msg_prop.c b/examples/msg/properties/msg_prop.c index 15d2ee042b..8e057056a3 100644 --- a/examples/msg/properties/msg_prop.c +++ b/examples/msg/properties/msg_prop.c @@ -4,37 +4,18 @@ /* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ -#include "xbt/sysdep.h" /* calloc, printf */ - -/* Create a log channel to have nice outputs. */ -#include "xbt/log.h" -#include "xbt/asserts.h" - -#include -#include +#include "simgrid/msg.h" /** @addtogroup MSG_examples * - * - properties/msg_prop.c Attaching arbitrary informations to - * host, processes and such, and retrieving them with @ref - * MSG_host_get_properties, @ref MSG_host_get_property_value, @ref - * MSG_process_get_properties and @ref - * MSG_process_get_property_value. Also make sure to read the - * platform and deployment XML files to see how to declare these - * data. - * + * - properties/msg_prop.c Attaching arbitrary informations to host, processes and such, and retrieving them + * with @ref MSG_host_get_properties, @ref MSG_host_get_property_value, @ref MSG_process_get_properties and + * @ref MSG_process_get_property_value. Also make sure to read the platform and deployment XML files to see how to + * declare these data. */ XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test"); -int alice(int argc, char *argv[]); -int bob(int argc, char *argv[]); -int carole(int argc, char *argv[]); -int david(int argc, char *argv[]); -msg_error_t test_all(const char *platform_file, - const char *application_file); - static void test_host(const char*hostname) { msg_host_t thehost = MSG_host_by_name(hostname); @@ -47,7 +28,7 @@ static void test_host(const char*hostname) XBT_INFO("== Print the properties of the host '%s'", hostname); xbt_dict_foreach(props, cursor, key, data) - XBT_INFO(" Host property: '%s' -> '%s'", key, data); + XBT_INFO(" Host property: '%s' -> '%s'", key, data); XBT_INFO("== Try to get a host property that does not exist"); value = MSG_host_get_property_value(thehost, noexist); @@ -55,11 +36,8 @@ static void test_host(const char*hostname) XBT_INFO("== Try to get a host property that does exist"); value = MSG_host_get_property_value(thehost, exist); - xbt_assert(value, "\tProperty %s is undefined (where it should)", - exist); - xbt_assert(!strcmp(value, "180"), - "\tValue of property %s is defined to %s (where it should be 180)", - exist, value); + xbt_assert(value, "\tProperty %s is undefined (where it should)", exist); + xbt_assert(!strcmp(value, "180"), "\tValue of property %s is defined to %s (where it should be 180)", exist, value); XBT_INFO(" Property: %s old value: %s", exist, value); XBT_INFO("== Trying to modify a host property"); @@ -68,31 +46,31 @@ static void test_host(const char*hostname) /* Test if we have changed the value */ value = MSG_host_get_property_value(thehost, exist); xbt_assert(value, "Property %s is undefined (where it should)", exist); - xbt_assert(!strcmp(value, "250"), - "Value of property %s is defined to %s (where it should be 250)", - exist, value); + xbt_assert(!strcmp(value, "250"), "Value of property %s is defined to %s (where it should be 250)", exist, value); XBT_INFO(" Property: %s old value: %s", exist, value); /* Restore the value for the next test */ MSG_host_set_property_value(thehost, exist, xbt_strdup("180"), xbt_free_f); } -int alice(int argc, char *argv[]) { /* Dump what we have on the current host */ +static int alice(int argc, char *argv[]) { /* Dump what we have on the current host */ test_host("host1"); return 0; } -int carole(int argc, char *argv[]) {/* Dump what we have on a remote host */ + +static int carole(int argc, char *argv[]) {/* Dump what we have on a remote host */ MSG_process_sleep(1); // Wait for alice to be done with its experiment test_host("host1"); return 0; } -int david(int argc, char *argv[]) {/* Dump what we have on a remote host */ + +static int david(int argc, char *argv[]) {/* Dump what we have on a remote host */ MSG_process_sleep(2); // Wait for alice and carole to be done with its experiment test_host("node-0.acme.org"); return 0; } -int bob(int argc, char *argv[]) +static int bob(int argc, char *argv[]) { /* Get the property list of current bob process */ xbt_dict_t props = MSG_process_get_properties(MSG_process_self()); @@ -103,7 +81,7 @@ int bob(int argc, char *argv[]) XBT_INFO("== Print the properties of the process"); xbt_dict_foreach(props, cursor, key, data) - XBT_INFO(" Process property: %s -> %s", key, data); + XBT_INFO(" Process property: %s -> %s", key, data); XBT_INFO("== Try to get a process property that does not exist"); @@ -113,54 +91,37 @@ int bob(int argc, char *argv[]) return 0; } -/** Test function */ -msg_error_t test_all(const char *platform_file, - const char *application_file) +int main(int argc, char *argv[]) { - int host_number; + msg_error_t res = MSG_OK; unsigned int i; xbt_dynar_t hosts; msg_host_t host; - msg_error_t ret; + + MSG_init(&argc, argv); + xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" + "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]); MSG_function_register("alice", alice); MSG_function_register("bob", bob); MSG_function_register("carole", carole); MSG_function_register("david", david); - MSG_create_environment(platform_file); + MSG_create_environment(argv[1]); - host_number = MSG_get_host_number(); - XBT_INFO("There are %d hosts in the environment", host_number); + XBT_INFO("There are %d hosts in the environment", MSG_get_host_number()); hosts = MSG_hosts_as_dynar(); xbt_dynar_foreach(hosts, i, host){ - XBT_INFO("Host '%s' runs at %.0f flops/s",MSG_host_get_name(host), - MSG_get_host_speed(host)); + XBT_INFO("Host '%s' runs at %.0f flops/s",MSG_host_get_name(host), MSG_get_host_speed(host)); } - MSG_launch_application(application_file); + MSG_launch_application(argv[2]); - ret = MSG_main(); + res = MSG_main(); xbt_dynar_free(&hosts); - return ret; -} /* end_of_test_all */ - - -/** Main function */ -int main(int argc, char *argv[]) -{ - msg_error_t res = MSG_OK; - - MSG_init(&argc, argv); - xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" - "\tExample: %s msg_platform.xml msg_deployment.xml\n", - argv[0], argv[0]); - - res = test_all(argv[1], argv[2]); - - return res != MSG_OK; + return res!=MSG_OK; } diff --git a/examples/msg/start_kill_time/sk_time.c b/examples/msg/start_kill_time/sk_time.c index 8442325d5c..820cc7efd2 100644 --- a/examples/msg/start_kill_time/sk_time.c +++ b/examples/msg/start_kill_time/sk_time.c @@ -4,13 +4,9 @@ /* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ -#include "xbt/sysdep.h" /* calloc */ +#include "simgrid/msg.h" -/* Create a log channel to have nice outputs. */ -#include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, - "Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); static int my_onexit(void* ignored1, void *ignored2) { XBT_INFO("Exiting now (done sleeping or got killed)."); @@ -27,34 +23,19 @@ static int sleeper(int argc, char *argv[]) return 0; } -/** Test function */ -static msg_error_t test_all(const char *platform_file, - const char *application_file) +int main(int argc, char *argv[]) { msg_error_t res = MSG_OK; - MSG_create_environment(platform_file); + MSG_init(&argc, argv); + xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" + "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]); + + MSG_create_environment(argv[1]); MSG_function_register("sleeper", sleeper); - MSG_launch_application(application_file); + MSG_launch_application(argv[2]); res = MSG_main(); - XBT_INFO("Simulation time %g", MSG_get_clock()); - return res; -} /* end_of_test_all */ - - -/** Main function */ -int main(int argc, char *argv[]) -{ - msg_error_t res = MSG_OK; - - MSG_init(&argc, argv); - xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" - "\tExample: %s msg_platform.xml msg_deployment.xml\n", - argv[0], argv[0]); - - test_all(argv[1], argv[2]); - return res != MSG_OK; } diff --git a/examples/msg/suspend/CMakeLists.txt b/examples/msg/suspend/CMakeLists.txt index 119df72d8d..f34c90a24a 100644 --- a/examples/msg/suspend/CMakeLists.txt +++ b/examples/msg/suspend/CMakeLists.txt @@ -5,10 +5,6 @@ set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/suspend.tesh PARENT_SCOPE) -set(xml_files - ${xml_files} - ${CMAKE_CURRENT_SOURCE_DIR}/deployment_suspend.xml - PARENT_SCOPE) set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/suspend.c diff --git a/examples/msg/suspend/deployment_suspend.xml b/examples/msg/suspend/deployment_suspend.xml deleted file mode 100644 index 07fc5673e2..0000000000 --- a/examples/msg/suspend/deployment_suspend.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/examples/msg/suspend/suspend.c b/examples/msg/suspend/suspend.c index a36254ae65..13db39fea6 100644 --- a/examples/msg/suspend/suspend.c +++ b/examples/msg/suspend/suspend.c @@ -4,23 +4,18 @@ /* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ -#include "xbt/sysdep.h" /* calloc */ +#include "simgrid/msg.h" -/* Create a log channel to have nice outputs. */ -#include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, - "Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); #define SLEEP(duration) \ if (MSG_process_sleep(duration) != MSG_OK) \ - xbt_die("What's going on??? I failed to sleep!"); \ - else \ - (void)0 + xbt_die("What's going on??? I failed to sleep!"); /** @addtogroup MSG_examples * - * - suspend/suspend.c: Demonstrates how to suspend and resume processes using @ref MSG_process_suspend and @ref MSG_process_resume. + * - suspend/suspend.c: Demonstrates how to suspend and resume processes using + * @ref MSG_process_suspend and @ref MSG_process_resume. */ /** Lazy guy function. This process suspends itself asap. */ @@ -42,8 +37,7 @@ static int lazy_guy(int argc, char *argv[]) return 0; } /* end_of_lazy_guy */ -/** Dream master function. This process creates a lazy_guy process and - resumes it 10 seconds later. */ +/** Dream master function. This process creates a lazy_guy process and resumes it 10 seconds later. */ static int dream_master(int argc, char *argv[]) { msg_process_t lazy = NULL; @@ -73,39 +67,20 @@ static int dream_master(int argc, char *argv[]) XBT_INFO("OK, goodbye now."); return 0; -} /* end_of_dram_master */ +} /* end_of_dream_master */ -/** Test function */ -static msg_error_t test_all(const char *platform_file, - const char *application_file) -{ - msg_error_t res = MSG_OK; - - { /* Simulation setting */ - MSG_create_environment(platform_file); - } - { /* Application deployment */ - MSG_function_register("dream_master", dream_master); - MSG_launch_application(application_file); - } - res = MSG_main(); - - XBT_INFO("Simulation time %g", MSG_get_clock()); - return res; -} /* end_of_test_all */ - - -/** Main function */ int main(int argc, char *argv[]) { msg_error_t res = MSG_OK; MSG_init(&argc, argv); - xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" - "\tExample: %s msg_platform.xml msg_deployment_suspend.xml\n", - argv[0], argv[0]); + xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); - test_all(argv[1], argv[2]); + MSG_create_environment(argv[1]); + MSG_function_register("dream_master", dream_master); + MSG_process_create("dream_master", dream_master, NULL, xbt_dynar_getfirst_as(MSG_hosts_as_dynar(), msg_host_t)); + res = MSG_main(); + XBT_INFO("Simulation time %g", MSG_get_clock()); return res != MSG_OK; } diff --git a/examples/msg/suspend/suspend.tesh b/examples/msg/suspend/suspend.tesh index 22766aaa03..72b817851c 100644 --- a/examples/msg/suspend/suspend.tesh +++ b/examples/msg/suspend/suspend.tesh @@ -3,7 +3,7 @@ p Testing the suspend/resume feature of MSG ! output sort 19 -$ $SG_TEST_EXENV suspend/suspend ${srcdir:=.}/../platforms/platform.xml ${srcdir:=.}/suspend/deployment_suspend.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +$ $SG_TEST_EXENV suspend/suspend ${srcdir:=.}/../platforms/platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (1:dream_master@Jacquelin) Let's create a lazy guy. > [ 0.000000] (1:dream_master@Jacquelin) Let's wait a little bit... > [ 0.000000] (2:Lazy@Jacquelin) Nobody's watching me ? Let's go to sleep. diff --git a/examples/msg/token_ring/ring_call.c b/examples/msg/token_ring/ring_call.c index 06a46488bb..bc270cd1ac 100644 --- a/examples/msg/token_ring/ring_call.c +++ b/examples/msg/token_ring/ring_call.c @@ -4,32 +4,24 @@ /* 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" -int host(int argc, char *argv[]); -unsigned int task_comp_size = 50000000; -unsigned int task_comm_size = 1000000; - -int nb_hosts; /* All declared hosts */ - -XBT_LOG_NEW_DEFAULT_CATEGORY(ring, - "Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(ring, "Messages specific for this msg example"); /** @addtogroup MSG_examples * * @section MSG_ex_apps Examples of full applications * - * - token_ring/ring_call.c: Classical token ring - * communication, where a token is exchanged along a ring to reach - * every participant. - * + * - token_ring/ring_call.c: Classical token ring communication, where a token is exchanged along a ring to + * reach every participant. */ -int host(int argc, char *argv[]) +static int host(int argc, char *argv[]) { - int host_number = xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Process name must be an integer but is: %s"); + unsigned int task_comp_size = 50000000; + unsigned int task_comm_size = 1000000; + int host_number = + xbt_str_parse_int(MSG_process_get_name(MSG_process_self()), "Process name must be an integer but is: %s"); char mailbox[256]; msg_task_t task = NULL; XBT_ATTRIB_UNUSED int res; @@ -43,13 +35,12 @@ int host(int argc, char *argv[]) xbt_assert(res == MSG_OK, "MSG_task_get failed"); XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task)); MSG_task_destroy(task); - } - else{ //slave receive then send + } else{ //slave receive then send res = MSG_task_receive(&(task), MSG_process_get_name(MSG_process_self())); xbt_assert(res == MSG_OK, "MSG_task_get failed"); XBT_INFO("Host \"%d\" received \"%s\"",host_number, MSG_task_get_name(task)); - if(host_number+1 == nb_hosts) + if(host_number+1 == MSG_get_host_number()) sprintf(mailbox, "0"); else sprintf(mailbox, "%d", host_number+1); @@ -61,23 +52,22 @@ int host(int argc, char *argv[]) int main(int argc, char **argv) { - int i,res; + unsigned int i; MSG_init(&argc, argv); MSG_create_environment(argv[1]); xbt_dynar_t hosts = MSG_hosts_as_dynar(); - nb_hosts = xbt_dynar_length(hosts); + msg_host_t h; MSG_function_register("host", host); - XBT_INFO("Number of host '%d'",nb_hosts); - for(i = 0 ; i