Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
document this test as broken
[simgrid.git] / teshsuite / msg / host_on_off_processes / host_on_off_processes.c
1 /* Copyright (c) 2010-2014. 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 <stdio.h>
8 #include "simgrid/msg.h"            /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
9 #include "xbt/sysdep.h"         /* calloc, printf */
10
11 /* Create a log channel to have nice outputs. */
12 #include "xbt/log.h"
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
15                              "Messages specific for this msg example");
16
17 int test_launcher(int argc, char *argv[]);
18 int process_daemon(int argc, char *argv[]);
19 int process_sleep(int argc, char *argv[]);
20 int commRX(int argc, char *argv[]);
21 int commTX(int argc, char *argv[]);
22
23 xbt_dynar_t tests;
24
25 int test_launcher(int argc, char *argv[])
26 {
27   int test = 0;
28   char **argvF;
29   argvF = xbt_new(char*, 2);
30   argvF[0] = xbt_strdup("process_daemon");
31   msg_host_t jupiter = MSG_get_host_by_name("Jupiter");
32
33   test = 1;
34   // Create a process running a simple task on a host and turn the host off during the execution of the process.
35   if (xbt_dynar_search_or_negative(tests, &test)!=-1){
36     XBT_INFO("Test 1:");
37     XBT_INFO("  Create a process on Jupiter");
38     argvF = xbt_new(char*, 2);
39     argvF[0] = xbt_strdup("process_daemon");
40     MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, jupiter, 1, argvF);
41     MSG_process_sleep(3);
42     XBT_INFO("  Turn off Jupiter");
43     MSG_host_off(jupiter);
44     MSG_process_sleep(10);
45     XBT_INFO("Test 1 seems ok, cool !(number of Process : %d, it should be 1 (i.e. the Test one))", MSG_process_get_number());
46   }
47
48   test = 2;
49   // Create a process that on a host that is turned off (this should not be possible)
50   if (xbt_dynar_search_or_negative(tests, &test)!=-1){
51     XBT_INFO("Test 2:");
52     XBT_INFO("  Turn off Jupiter");
53     // adsein: Jupiter is already, hence nothing should happen
54     // adsein: This can be one additional test, to check that you cannot shutdown twice a host
55     MSG_host_off(jupiter);
56     argvF = xbt_new(char*, 2);
57     argvF[0] = xbt_strdup("process_daemon");
58     MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, jupiter, 1, argvF);
59     MSG_process_sleep(10);
60     XBT_INFO("  Test 2 does not crash, WTF ?!(number of Process : %d, it should be 1)", MSG_process_get_number());
61     XBT_INFO("  Ok so let's turn on/off the node to see whether the process is correctly bound to Jupiter");
62     MSG_host_on(jupiter);
63     XBT_INFO("  Turn off");
64     MSG_host_off(jupiter);
65     XBT_INFO("  sleep");
66     MSG_process_sleep(10);
67     XBT_INFO("number of Process : %d it should be 1. The daemon that has been created for test2 has been correctly destroyed....ok at least it looks rigorous, cool ! You just have to disallow the possibility to create a new process on a node when the node is off.)", MSG_process_get_number());
68   }
69
70    test = 3;
71   // Create a process running sucessive sleeps on a host and turn the host off during the execution of the process.
72   if (xbt_dynar_search_or_negative(tests, &test)!=-1){
73     XBT_INFO("Test 3:");
74     MSG_host_on(jupiter);
75     argvF = xbt_new(char*, 2);
76     argvF[0] = xbt_strdup("process_sleep");
77     MSG_process_create_with_arguments("process_sleep", process_sleep, NULL, jupiter, 1, argvF);
78     MSG_process_sleep(100);
79     XBT_INFO("  Turn off");
80     MSG_host_off(jupiter);
81     XBT_INFO("  sleep for 10 seconds");
82     MSG_process_sleep(10000);
83     XBT_INFO("number of Process : %d it should be 1 (i.e. the Test one))", MSG_process_get_number());
84   }
85
86   test = 4;
87   if (xbt_dynar_search_or_negative(tests, &test)!=-1){
88     XBT_INFO("Test 4 (turn off src during a communication) : Create a Process/task to make a communication between Jupiter and Tremblay and turn off Jupiter during the communication");
89     MSG_host_on(jupiter);
90     MSG_process_sleep(10);
91     argvF = xbt_new(char*, 2);
92     argvF[0] = xbt_strdup("commRX");
93     MSG_process_create_with_arguments("commRX", commRX, NULL, MSG_get_host_by_name("Tremblay"), 1, argvF);
94     argvF = xbt_new(char*, 2);
95     argvF[0] = xbt_strdup("commTX");
96     MSG_process_create_with_arguments("commTX", commTX, NULL, jupiter, 1, argvF);
97     XBT_INFO("  number of processes: %d", MSG_process_get_number());
98     MSG_process_sleep(10);
99     XBT_INFO("  Turn Jupiter off");
100     MSG_host_off(jupiter);
101     XBT_INFO("Test 4 seems ok  (number of Process : %d, it should be 1 or 2 if RX has not been satisfied) cool, you can now turn off a node that has a process paused by a sleep call", MSG_process_get_number());
102   }
103
104   test = 5;
105   if (xbt_dynar_search_or_negative(tests, &test)!=-1){
106     XBT_INFO("Test 5 (turn off dest during a communication : Create a Process/task to make a communication between Tremblay and Jupiter and turn off Jupiter during the communication");
107     XBT_INFO("Warning! I think this test is completely broken and it was revealed by exception/exception test.");
108     XBT_INFO("At time 20, Jupiter should wake up with a HOST_FAILURE and it gets a TRANSFERT_FAILURE. This is because when turning off Jupiter, its processes are killed, which cancels/destroys the corresponding surf communication instead of canceling a src_ or dst_timeout.");
109     MSG_host_on(jupiter);
110     MSG_process_sleep(10);
111     argvF = xbt_new(char*, 2);
112     argvF[0] = xbt_strdup("commRX");
113     MSG_process_create_with_arguments("commRX", commRX, NULL, jupiter, 1, argvF);
114     argvF = xbt_new(char*, 2);
115     argvF[0] = xbt_strdup("commTX");
116     MSG_process_create_with_arguments("commTX", commTX, NULL, MSG_get_host_by_name("Tremblay"), 1, argvF);
117     XBT_INFO("  number of processes: %d", MSG_process_get_number());
118     MSG_process_sleep(10);
119     XBT_INFO("  Turn Jupiter off");
120     MSG_host_off(jupiter);
121     XBT_INFO("Test 5 seems ok, cool !(number of Process : %d, it should be 2", MSG_process_get_number());
122   }
123
124   test =6;
125   if (xbt_dynar_search_or_negative(tests, &test)!=-1){
126     XBT_INFO("Test 6: Turn on Jupiter, assign a VM on Jupiter, launch a process inside the VM, and turn off the node");
127
128     // Create VM0
129     int dpRate = 70;
130     msg_vm_t vm0;
131     msg_process_t daemon;
132
133     vm0 = MSG_vm_create (jupiter, "vm0", 1, 2048, 125, NULL, -1, 125, dpRate);
134     MSG_vm_start(vm0);
135
136     argvF = xbt_new(char*, 2);
137     argvF[0] = xbt_strdup("process_daemon");
138     daemon = MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, vm0, 1, argvF);
139
140     argvF = xbt_new(char*, 2);
141     argvF[0] = xbt_strdup("process_daemonJUPI");
142     MSG_process_create_with_arguments("process_daemonJUPI", process_daemon, NULL, jupiter, 1, argvF);
143
144     MSG_process_suspend(daemon);
145     MSG_vm_set_bound(vm0, 90);
146     MSG_process_resume(daemon);
147
148     MSG_process_sleep(10);
149
150     XBT_INFO("  Turn Jupiter off");
151     MSG_host_off(jupiter);
152     XBT_INFO("  Shutdown vm0");
153     MSG_vm_shutdown(vm0);
154     XBT_INFO("  Destroy vm0");
155     MSG_vm_destroy(vm0);
156     XBT_INFO("Test 6 is also weird: when the node Jupiter is turned off once again, the VM and its daemon are not killed. However, the issue regarding the shutdown of hosted VMs can be seen a feature not a bug ;)");
157   }
158
159   test = 7;
160   if (xbt_dynar_search_or_negative(tests, &test)!=-1){
161
162   }
163
164   test = 8;
165   if (xbt_dynar_search_or_negative(tests, &test)!=-1){
166
167   }
168
169   test = 9;
170   if (xbt_dynar_search_or_negative(tests, &test)!=-1){
171
172   }
173   XBT_INFO("  Test done. See you!");
174   return 0;
175 }
176
177 // adsein: Is this really a daemon ? it ran only one task ? I just added a stupid loop
178 int process_daemon(int argc, char *argv[])
179 {
180   msg_task_t task = NULL;
181   XBT_INFO("  Start daemon on %s (%f)",  MSG_host_get_name(MSG_host_self()), MSG_get_host_speed(MSG_host_self()));
182   for(;;){
183     task = MSG_task_create("deamon", MSG_get_host_speed(MSG_host_self()), 0, NULL);
184     XBT_INFO("  Execute deamon");
185     MSG_task_execute(task);
186     MSG_task_destroy(task);
187   }
188   XBT_INFO("  Deamon done. See you!");
189   return 0;
190 }
191
192 int process_sleep(int argc, char *argv[])
193 {
194   for(;;){
195     XBT_INFO("  I'm alive but I should sleep");
196     MSG_process_sleep(10);
197   }
198   XBT_INFO("  I'm done. See you!");
199   return 0;
200 }
201
202 int commTX(int argc, char *argv[])
203 {
204   msg_task_t task = NULL;
205   char mailbox[80];
206   sprintf(mailbox, "comm");
207   XBT_INFO("  Start TX");
208   task = MSG_task_create("COMM", 0, 100000000, NULL);
209   MSG_task_isend(task, mailbox);
210   // We should wait a bit (if not the process will end before the communication, leading to an exception at the other side).
211   MSG_process_sleep(30);
212   XBT_INFO("  TX done");
213   return 0;
214 }
215
216 int commRX(int argc, char *argv[])
217 {
218   msg_task_t task = NULL;
219   char mailbox[80];
220   sprintf(mailbox, "comm");
221   XBT_INFO("  Start RX");
222   msg_error_t error = MSG_task_receive(&(task), mailbox);
223   if (error==MSG_OK) {
224     XBT_INFO("  Receive message: %s", task->name);
225   } else if (error==MSG_HOST_FAILURE) {
226     XBT_INFO("  Receive message: HOST_FAILURE");
227   } else if (error==MSG_TRANSFER_FAILURE) {
228     XBT_INFO("  Receive message: TRANSFERT_FAILURE");
229   } else {
230     XBT_INFO("  Receive message: %d", error);
231   }
232   XBT_INFO("  RX Done");
233   return 0;
234 }
235
236 /** Main function */
237 int main(int argc, char *argv[])
238 {
239   msg_error_t res;
240   const char *platform_file;
241   const char *application_file;
242
243   MSG_init(&argc, argv);
244   if (argc != 4) {
245     printf("Usage: %s platform_file deployment_file test_number\n", argv[0]);
246     printf("example: %s msg_platform.xml msg_deployment.xml 1\n", argv[0]);
247     exit(1);
248   }
249
250   unsigned int iter;
251   char *groups;
252   xbt_dynar_t s_tests = xbt_str_split(argv[3], ",");
253   int tmp_test = 0;
254   tests = xbt_dynar_new(sizeof(int), NULL);
255   xbt_dynar_foreach(s_tests, iter, groups) {
256      sscanf(xbt_dynar_get_as(s_tests, iter, char *), "%d", &tmp_test);
257      xbt_dynar_set_as(tests, iter, int, tmp_test);
258   }
259
260   platform_file = argv[1];
261   application_file = argv[2];
262
263   /* MSG_config("workstation/model","KCCFLN05"); */
264   {                             /*  Simulation setting */
265     MSG_create_environment(platform_file);
266   }
267   {                             /*   Application deployment */
268     MSG_function_register("test_launcher", test_launcher);
269     MSG_function_register("process_daemon", process_daemon);
270     MSG_function_register("process_sleep", process_sleep);
271
272     MSG_launch_application(application_file);
273   }
274   res = MSG_main();
275
276   XBT_INFO("Simulation time %g", MSG_get_clock());
277
278   if (res == MSG_OK)
279     return 0;
280   else
281     return 1;
282 }                               /* end_of_main */