Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2bf85580296aad2f7295f988722fd6395cb92333
[simgrid.git] / teshsuite / msg / host_on_off / host_on_off_wait.c
1 /* Copyright (c) 2010-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "simgrid/msg.h"            /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
10
11 static int master(int argc, char *argv[])
12 {
13   xbt_ex_t e;
14   TRY {
15     msg_host_t jupiter = MSG_host_by_name("Jupiter");
16     XBT_INFO("Master waiting");
17     MSG_process_sleep(1);
18
19     XBT_INFO("Turning off the slave host");
20     MSG_host_off(jupiter);
21     XBT_INFO("Master has finished");
22   }
23   CATCH(e) {
24     xbt_die("Exception caught in the master");
25     return 1;
26   }
27   return 0;
28 }
29
30 static int slave(int argc, char *argv[])
31 {
32   xbt_ex_t e;
33   TRY {
34     XBT_INFO("Slave waiting");
35     // TODO, This should really be MSG_HOST_FAILURE
36     MSG_process_sleep(5);
37     XBT_ERROR("Slave should be off already.");
38     return 1;
39   }
40   CATCH(e) {
41     XBT_ERROR("Exception caught in the slave");
42     return 1;
43   }
44   return 0;
45 }
46
47 int main(int argc, char *argv[])
48 {
49   msg_error_t res;
50
51   MSG_init(&argc, argv);
52   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
53              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
54
55   MSG_create_environment(argv[1]);
56
57   MSG_function_register("master", master);
58   MSG_function_register("slave", slave);
59   MSG_launch_application(argv[2]);
60
61   res = MSG_main();
62
63   XBT_INFO("Simulation time %g", MSG_get_clock());
64
65   return res != MSG_OK;
66 }