Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add java teshsuite for sleep_host_off
[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 "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/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_member(tests, &test)){
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     XBT_INFO("  Turn off Jupiter");
42     MSG_host_off(jupiter);
43     MSG_process_sleep(10);
44     XBT_INFO("Test 1 seems ok, cool !(number of Process : %d, it should be 1 (i.e. the Test one))", MSG_process_get_number());
45   }
46
47   test = 2;
48   // Create a process that on a host that is turned off (this should not be possible)
49   if (xbt_dynar_member(tests, &test)){
50     XBT_INFO("Test 2:");
51     XBT_INFO("  Turn off Jupiter");
52     // adsein: Jupiter is already, hence nothing should happen
53     // adsein: This can be one additional test, to check that you cannot shutdown twice a host
54     MSG_host_off(jupiter);
55     argvF = xbt_new(char*, 2);
56     argvF[0] = xbt_strdup("process_daemon");
57     MSG_process_create_with_arguments("process_daemon", process_daemon, NULL, jupiter, 1, argvF);
58     MSG_process_sleep(10);
59     XBT_INFO("  Test 2 does not crash, WTF ?!(number of Process : %d, it should be 1)", MSG_process_get_number());
60     XBT_INFO("  Ok so let's turn on/off the node to see whether the process is correctly bound to Jupiter");
61     MSG_host_on(jupiter);
62     XBT_INFO("  Turn off");
63     MSG_host_off(jupiter);
64     XBT_INFO("  sleep");
65     MSG_process_sleep(10);
66     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());
67   }
68
69    test = 3;
70   // Create a process running sucessive sleeps on a host and turn the host off during the execution of the process.
71   if (xbt_dynar_member(tests, &test)){
72     XBT_INFO("Test 3:");
73     MSG_host_on(jupiter);
74     argvF = xbt_new(char*, 2);
75     argvF[0] = xbt_strdup("process_sleep");
76     MSG_process_create_with_arguments("process_sleep", process_sleep, NULL, jupiter, 1, argvF);
77     MSG_process_sleep(100);
78     XBT_INFO("  Turn off");
79     MSG_host_off(jupiter);
80     XBT_INFO("  sleep for 10 seconds");
81     MSG_process_sleep(10000);
82     XBT_INFO("number of Process : %d it should be 1 (i.e. the Test one))", MSG_process_get_number());
83   }
84
85   test = 4;
86   if (xbt_dynar_member(tests, &test)){
87     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");
88     MSG_host_on(jupiter);
89     MSG_process_sleep(10);
90     argvF = xbt_new(char*, 2);
91     argvF[0] = xbt_strdup("commRX");
92     MSG_process_create_with_arguments("commRX", commRX, NULL, MSG_get_host_by_name("Tremblay"), 1, argvF);
93     argvF = xbt_new(char*, 2);
94     argvF[0] = xbt_strdup("commTX");
95     MSG_process_create_with_arguments("commTX", commTX, NULL, jupiter, 1, argvF);
96     XBT_INFO("  number of processes: %d", MSG_process_get_number());
97     MSG_process_sleep(10);
98     XBT_INFO("  Turn Jupiter off");
99     MSG_host_off(jupiter);
100     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());
101   }
102
103   test = 5;
104   if (xbt_dynar_member(tests, &test)){
105     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");
106     MSG_host_on(jupiter);
107     MSG_process_sleep(10);
108     argvF = xbt_new(char*, 2);
109     argvF[0] = xbt_strdup("commRX");
110     MSG_process_create_with_arguments("commRX", commRX, NULL, jupiter, 1, argvF);
111     argvF = xbt_new(char*, 2);
112     argvF[0] = xbt_strdup("commTX");
113     MSG_process_create_with_arguments("commTX", commTX, NULL, MSG_get_host_by_name("Tremblay"), 1, argvF);
114     XBT_INFO("  number of processes: %d", MSG_process_get_number());
115     MSG_process_sleep(10);
116     XBT_INFO("  Turn Jupiter off");
117     MSG_host_off(jupiter);
118     XBT_INFO("Test 4 seems ok, cool !(number of Process : %d, it should be 2", MSG_process_get_number());
119   }
120
121   test =6;
122   if (xbt_dynar_member(tests, &test)){
123     /*XBT_INFO("Test 5: Turn on Jupiter, assign a VM on Jupiter, launch a process inside the VM, and turn off the node");
124
125     // Create VM0
126     int dpRate = 70;
127     msg_vm_t vm0;
128 MSG_vm_create (msg_host_t ind_pm, const char *name, int ncpus, int ramsize, int net_cap, char *disk_path, int disksize, int mig_netspeed, int dp_intensity)
129   vm0 = MSG_vm_create_core(jupiter, "vm0");
130   params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes
131   MSG_host_set_params(vm0, &params);
132   MSG_vm_start(vm0);
133     XVM vm0 = null;
134         vm0 = new XVM(
135                 host1,
136                 "vm0",
137                 1, // Nb of vcpu
138                 2048, // Ramsize,
139                 125, // Net Bandwidth
140                 null, //VM disk image
141                 -1,   //size of disk image,
142                 125, // Net bandwidth,
143                 dpRate // Memory intensity
144         );
145         vm0.start();
146         vm0.setLoad(90);
147
148         host1.off();
149         Msg.info("Test 5 is also weird: when the node host1 is turned off once again, the VM and its daemon are not killed." +
150                 " However, the issue regarding the shutdown of hosted VMs can be seen a feature not a bug ;)\n");*/
151   }
152
153   test = 7;
154   if (xbt_dynar_member(tests, &test)){
155
156   }
157
158   test = 8;
159   if (xbt_dynar_member(tests, &test)){
160
161   }
162
163   test = 9;
164   if (xbt_dynar_member(tests, &test)){
165
166   }
167   XBT_INFO("  Test done. See you!");
168   return 0;
169 }
170
171 // adsein: Is this really a daemon ? it ran only one task ? I just added a stupid loop
172 int process_daemon(int argc, char *argv[])
173 {
174   msg_task_t task = NULL;
175   for(;;){
176     task = MSG_task_create("deamon", 100*MSG_get_host_speed(MSG_host_self()), 0, NULL);
177     XBT_INFO("  Execute deamon");
178     MSG_task_destroy(task);
179   }
180   MSG_task_execute(task);
181   XBT_INFO("  Deamon done. See you!");
182   return 0;
183 }
184
185 int process_sleep(int argc, char *argv[])
186 {
187   for(;;){
188     XBT_INFO("  I'm alive but I should sleep");
189     MSG_process_sleep(10);
190   }
191   XBT_INFO("  I'm done. See you!");
192   return 0;
193 }
194
195 int commTX(int argc, char *argv[])
196 {
197   msg_task_t task = NULL;
198   char mailbox[80];
199   sprintf(mailbox, "comm");
200   XBT_INFO("  Start TX");
201   task = MSG_task_create("COMM", 0, 100000000, NULL);
202   MSG_task_isend(task, mailbox);
203   // We should wait a bit (if not the process will end before the communication, leading to an exception at the other side).
204   MSG_process_sleep(30);
205   XBT_INFO("  TX done");
206   return 0;
207 }
208
209 int commRX(int argc, char *argv[])
210 {
211   msg_task_t task = NULL;
212   char mailbox[80];
213   sprintf(mailbox, "comm");
214   XBT_INFO("  Start RX");
215   msg_error_t error = MSG_task_receive(&(task), mailbox);
216   if (error==MSG_OK) {
217     XBT_INFO("  Receive message: %s", task->name);
218   } else if (error==MSG_HOST_FAILURE) {
219     XBT_INFO("  Receive message: HOST_FAILURE");
220   } else if (error==MSG_TRANSFER_FAILURE) {
221     XBT_INFO("  Receive message: TRANSFERT_FAILURE");
222   } else {
223     XBT_INFO("  Receive message: %d", error);
224   }
225   XBT_INFO("  RX Done");
226   return 0;
227 }
228
229 /** Main function */
230 int main(int argc, char *argv[])
231 {
232   msg_error_t res;
233   const char *platform_file;
234   const char *application_file;
235
236   MSG_init(&argc, argv);
237   if (argc != 4) {
238     printf("Usage: %s platform_file deployment_file test_number\n", argv[0]);
239     printf("example: %s msg_platform.xml msg_deployment.xml 1\n", argv[0]);
240     exit(1);
241   }
242
243   unsigned int iter;
244   char *groups;
245   xbt_dynar_t s_tests = xbt_str_split(argv[3], ",");
246   int tmp_test = 0;
247   tests = xbt_dynar_new(sizeof(int), NULL);
248   xbt_dynar_foreach(s_tests, iter, groups) {
249      sscanf(xbt_dynar_get_as(s_tests, iter, char *), "%d", &tmp_test);
250      xbt_dynar_set_as(tests, iter, int, tmp_test);
251   }
252
253   platform_file = argv[1];
254   application_file = argv[2];
255
256   /* MSG_config("workstation/model","KCCFLN05"); */
257   {                             /*  Simulation setting */
258     MSG_create_environment(platform_file);
259   }
260   {                             /*   Application deployment */
261     MSG_function_register("test_launcher", test_launcher);
262     MSG_function_register("process_daemon", process_daemon);
263     MSG_function_register("process_sleep", process_sleep);
264
265     MSG_launch_application(application_file);
266   }
267   res = MSG_main();
268
269   XBT_INFO("Simulation time %g", MSG_get_clock());
270
271   if (res == MSG_OK)
272     return 0;
273   else
274     return 1;
275 }                               /* end_of_main */