1 /* Copyright (c) 2007-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid/msg.h"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
10 const int FAIL_ON_ERROR = 0;
11 const int flop_amount = 100000000;
14 static int computation_fun(int argc, char* argv[])
16 int *size = MSG_process_get_data(MSG_process_self());
17 msg_task_t task = MSG_task_create("Task", *size, 0, NULL);
19 double begin = MSG_get_clock();
20 MSG_task_execute(task);
21 double end = MSG_get_clock();
23 if (0.1 - (end - begin) > 0.001) {
24 xbt_assert(! FAIL_ON_ERROR, "%s with %.4g load (%dflops) took %.4fs instead of 0.1s",
25 MSG_process_get_name(MSG_process_self()), ((double)*size/flop_amount),*size, (end-begin));
26 XBT_INFO("FAILED TEST: %s with %.4g load (%dflops) took %.4fs instead of 0.1s",
27 MSG_process_get_name(MSG_process_self()),((double)*size/flop_amount), *size, (end-begin));
30 XBT_INFO("Passed: %s with %.4g load (%dflops) took 0.1s as expected",
31 MSG_process_get_name(MSG_process_self()), ((double)*size/flop_amount), *size);
34 MSG_task_destroy(task);
40 static void run_test(const char *name, msg_host_t location, int size) {
41 int* data = xbt_new(int, 1);
43 MSG_process_create(name, computation_fun, data, location);
46 static int master_main(int argc, char* argv[])
49 XBT_INFO("# TEST ON SINGLE-CORE PMs");
51 msg_host_t pm0 = MSG_host_by_name("node-0.1core.org");
52 msg_host_t pm1 = MSG_host_by_name("node-1.1core.org");
54 xbt_assert(pm0, "Host node-0.1core.org does not seem to exist");
56 // syntax of the process name:
57 // "( )1" means PM with one core; "( )2" means PM with 2 cores
58 // "( [ ]2 )4" means a VM with 2 cores, on a PM with 4 cores.
59 // "o" means another process is there
60 // "X" means the process which holds this name
62 XBT_INFO("## Test 1 (started): check computation on normal PMs");
64 XBT_INFO("### Put a task on a PM");
65 run_test("(X)1", pm0, flop_amount);
68 XBT_INFO("### Put two tasks on a PM");
69 run_test("(Xo)1", pm0, flop_amount/2);
70 run_test("(oX)1", pm0, flop_amount/2);
73 XBT_INFO("### Put a task on each PM");
74 run_test("(X)1 (o)1", pm0, flop_amount);
75 run_test("(o)1 (X)1", pm1, flop_amount);
78 XBT_INFO("## Test 1 (ended)");
79 XBT_INFO("# TEST ON SINGLE-CORE PMs AND SINGLE-CORE VMs");
81 XBT_INFO("## Test 2 (started): check impact of running tasks inside a VM (there is no degradation for the moment)");
83 XBT_INFO("### Put a VM on a PM, and put a task to the VM");
84 vm0 = MSG_vm_create_core(pm0, "VM0");
86 run_test("( [X]1 )1", vm0, flop_amount);
90 XBT_INFO("### Put a VM on a PM, and put two task to the VM");
91 vm0 = MSG_vm_create_core(pm0, "VM0");
93 run_test("( [Xo]1 )1", vm0, flop_amount/2);
94 run_test("( [oX]1 )1", vm0, flop_amount/2);
98 XBT_INFO("## Test 2 (ended)");
100 XBT_INFO("## Test 3 (started): check impact of running tasks collocated with VMs (there is no VM noise for the moment)");
102 XBT_INFO("### Put a task on a PM collocated with an empty VM");
104 vm0 = MSG_vm_create_core(pm0, "VM0");
106 run_test("( [ ]1 X )1", pm0, flop_amount);
107 MSG_process_sleep(2);
110 XBT_INFO("### Put a VM on a PM, put a task to the PM and a task to the VM");
112 vm0 = MSG_vm_create_core(pm0, "VM0");
114 run_test("( [X]1 o )1", vm0, flop_amount/2);
115 run_test("( [o]1 X )1", pm0, flop_amount/2);
116 MSG_process_sleep(2);
119 XBT_INFO("### Put a VM on a PM, put a task to the PM and two tasks to the VM");
121 vm0 = MSG_vm_create_core(pm0, "VM0");
123 run_test("( [Xo]1 o )1", vm0, flop_amount/4);
124 run_test("( [oX]1 o )1", vm0, flop_amount/4);
125 run_test("( [oo]1 X )1", pm0, flop_amount/2);
126 MSG_process_sleep(2);
128 XBT_INFO("## Test 3 (ended)");
130 XBT_INFO("# TEST ON TWO-CORE PMs");
132 msg_host_t pm2 = MSG_host_by_name("node-0.2cores.org"); // 2 cores
133 xbt_assert(pm2, "Host node-0.2cores.org does not seem to exist");
135 XBT_INFO("## Test 4 (started): check computation on 2 cores PMs");
137 XBT_INFO("### Put a task on a PM");
138 run_test("(X)2", pm2, flop_amount);
139 MSG_process_sleep(2);
141 XBT_INFO("### Put two tasks on a PM");
142 run_test("(Xx)2", pm2, flop_amount);
143 run_test("(xX)2", pm2, flop_amount);
144 MSG_process_sleep(2);
146 XBT_INFO("### Put three tasks on a PM");
147 run_test("(Xxx)2", pm2, flop_amount*2/3);
148 run_test("(xXx)2", pm2, flop_amount*2/3);
149 run_test("(xxX)2", pm2, flop_amount*2/3);
150 MSG_process_sleep(2);
152 XBT_INFO("## Test 4 (ended)");
154 XBT_INFO("# TEST ON TWO-CORE PMs AND SINGLE-CORE VMs");
156 XBT_INFO("## Test 5 (started): check impact of a single VM (there is no degradation for the moment)");
158 XBT_INFO("### Put a VM on a PM, and put a task to the VM");
159 vm0 = MSG_vm_create_core(pm2, "VM0");
161 run_test("( [X]1 )2", vm0, flop_amount);
162 MSG_process_sleep(2);
165 XBT_INFO("### Put a VM on a PM, and put two tasks to the VM");
166 vm0 = MSG_vm_create_core(pm2, "VM0");
168 run_test("( [Xx]1 )2", vm0, flop_amount/2);
169 run_test("( [xX]1 )2", vm0, flop_amount/2);
170 MSG_process_sleep(2);
173 XBT_INFO("### Put a VM on a PM, and put a task to the PM");
174 vm0 = MSG_vm_create_core(pm2, "VM0");
176 run_test("( [ ]1 X )2", pm2, flop_amount);
177 MSG_process_sleep(2);
180 XBT_INFO("### Put a VM on a PM, put a task to the PM and a task to the VM");
181 vm0 = MSG_vm_create_core(pm2, "VM0");
183 run_test("( [X]1 x )2", vm0, flop_amount);
184 run_test("( [x]1 X )2", pm2, flop_amount);
185 MSG_process_sleep(2);
188 XBT_INFO("## Test 5 (ended)");
190 XBT_INFO("## Test 6 (started): check impact of a several VMs (there is no degradation for the moment)");
192 XBT_INFO("### Put two VMs on a PM, and put a task to one VM");
193 vm0 = MSG_vm_create_core(pm2, "VM0");
194 msg_vm_t vm1 = MSG_vm_create_core(pm2, "VM1");
197 run_test("( [X]1 [ ]1 )2", vm0, flop_amount);
198 MSG_process_sleep(2);
202 XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
203 vm0 = MSG_vm_create_core(pm2, "VM0");
204 vm1 = MSG_vm_create_core(pm2, "VM1");
207 run_test("( [X]1 [x]1 )2", vm0, flop_amount);
208 run_test("( [x]1 [X]1 )2", vm1, flop_amount);
209 MSG_process_sleep(2);
213 XBT_INFO("### Put three VMs on a PM, and put a task to two VMs");
214 vm0 = MSG_vm_create_core(pm2, "VM0");
215 vm1 = MSG_vm_create_core(pm2, "VM1");
216 msg_vm_t vm2 = MSG_vm_create_core(pm2, "VM2");
220 run_test("( [X]1 [x]1 [ ]1 )2", vm0, flop_amount);
221 run_test("( [x]1 [X]1 [ ]1 )2", vm1, flop_amount);
222 MSG_process_sleep(2);
227 XBT_INFO("### Put three VMs on a PM, and put a task to each VM");
228 vm0 = MSG_vm_create_core(pm2, "VM0");
229 vm1 = MSG_vm_create_core(pm2, "VM1");
230 vm2 = MSG_vm_create_core(pm2, "VM2");
234 run_test("( [X]1 [o]1 [o]1 )2", vm0, flop_amount*2/3);
235 run_test("( [o]1 [X]1 [o]1 )2", vm1, flop_amount*2/3);
236 run_test("( [o]1 [o]1 [X]1 )2", vm2, flop_amount*2/3);
237 MSG_process_sleep(2);
242 XBT_INFO("## Test 6 (ended)");
244 XBT_INFO("# TEST ON TWO-CORE PMs AND TWO-CORE VMs");
246 XBT_INFO("## Test 7 (started): check impact of a single VM (there is no degradation for the moment)");
248 XBT_INFO("### Put a VM on a PM, and put a task to the VM");
249 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
251 run_test("( [X]2 )2", vm0, flop_amount);
252 MSG_process_sleep(2);
255 XBT_INFO("### Put a VM on a PM, and put two tasks to the VM");
256 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
258 run_test("( [Xo]2 )2", vm0, flop_amount);
259 run_test("( [oX]2 )2", vm0, flop_amount);
260 MSG_process_sleep(2);
263 XBT_INFO("### Put a VM on a PM, and put three tasks to the VM");
264 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
266 run_test("( [Xoo]2 )2", vm0, flop_amount*2/3);
267 run_test("( [oXo]2 )2", vm0, flop_amount*2/3);
268 run_test("( [ooX]2 )2", vm0, flop_amount*2/3);
269 MSG_process_sleep(2);
272 XBT_INFO("## Test 7 (ended)");
274 XBT_INFO("## Test 8 (started): check impact of a single VM collocated with a task (there is no degradation for the moment)");
276 XBT_INFO("### Put a VM on a PM, and put a task to the PM");
277 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
279 run_test("( [ ]2 X )2", pm2, flop_amount);
280 MSG_process_sleep(2);
283 XBT_INFO("### Put a VM on a PM, put one task to the PM and one task to the VM");
284 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
286 run_test("( [o]2 X )2", pm2, flop_amount);
287 run_test("( [X]2 o )2", vm0, flop_amount);
288 MSG_process_sleep(2);
291 XBT_INFO("### Put a VM on a PM, put one task to the PM and two tasks to the VM");
292 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
294 run_test("( [oo]2 X )2", pm2, flop_amount*2/3);
295 run_test("( [Xo]2 o )2", vm0, flop_amount*2/3);
296 run_test("( [oX]2 o )2", vm0, flop_amount*2/3);
297 MSG_process_sleep(2);
300 XBT_INFO("### Put a VM on a PM, put one task to the PM and three tasks to the VM");
301 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
303 run_test("( [ooo]2 X )2", pm2, flop_amount*2/3);
304 run_test("( [Xoo]2 o )2", vm0, flop_amount*2/9);
305 run_test("( [oXo]2 o )2", vm0, flop_amount*2/9);
306 run_test("( [ooX]2 o )2", vm0, flop_amount*2/9);
307 MSG_process_sleep(2);
310 XBT_INFO("### Put a VM on a PM, and put two tasks to the PM");
311 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
313 run_test("( [ ]2 Xo )2", pm2, flop_amount);
314 run_test("( [ ]2 oX )2", pm2, flop_amount);
315 MSG_process_sleep(2);
318 XBT_INFO("### Put a VM on a PM, put one task to the PM and one task to the VM");
319 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
321 run_test("( [o]2 Xo )2", pm2, flop_amount*2/3);
322 run_test("( [o]2 oX )2", pm2, flop_amount*2/3);
323 run_test("( [X]2 oo )2", vm0, flop_amount*2/3);
324 MSG_process_sleep(2);
327 XBT_INFO("### Put a VM on a PM, put one task to the PM and two tasks to the VM");
328 vm0 = MSG_vm_create_multicore(pm2, "VM0",2);
330 run_test("( [oo]2 Xo )2", pm2, flop_amount/2);
331 run_test("( [oo]2 oX )2", pm2, flop_amount/2);
332 run_test("( [Xo]2 oo )2", vm0, flop_amount/2);
333 run_test("( [oX]2 oo )2", vm0, flop_amount/2);
334 MSG_process_sleep(2);
337 XBT_INFO("### Put a VM on a PM, put one task to the PM and three tasks to the VM");
338 vm0 = MSG_vm_create_multicore(pm2, "VM0", 2);
340 run_test("( [ooo]2 Xo )2", pm2, flop_amount*2/4);
341 run_test("( [ooo]2 oX )2", pm2, flop_amount*2/4);
342 run_test("( [Xoo]2 oo )2", vm0, flop_amount/3);
343 run_test("( [oXo]2 oo )2", vm0, flop_amount/3);
344 run_test("( [ooX]2 oo )2", vm0, flop_amount/3);
345 MSG_process_sleep(2);
348 XBT_INFO("## Test 8 (ended)");
350 XBT_INFO("# TEST ON FOUR-CORE PMs AND TWO-CORE VMs");
352 msg_host_t pm4 = MSG_host_by_name("node-0.4cores.org");
353 xbt_assert(pm4, "Host node-0.4cores.org does not seem to exist");
355 XBT_INFO("## Test 9 (started): check impact of a single VM");
357 XBT_INFO("### Put a VM on a PM, and put a task to the VM");
358 vm0 = MSG_vm_create_multicore(pm4, "VM0", 2);
360 run_test("( [X]2 )4", vm0, flop_amount);
361 MSG_process_sleep(2);
364 XBT_INFO("### Put a VM on a PM, and put two tasks to the VM");
365 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
367 run_test("( [Xo]2 )4", vm0, flop_amount);
368 run_test("( [oX]2 )4", vm0, flop_amount);
369 MSG_process_sleep(2);
372 XBT_INFO("### ( [ooo]2 )4: Put a VM on a PM, and put three tasks to the VM");
373 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
375 run_test("( [Xoo]2 )4", vm0, flop_amount*2/3);
376 run_test("( [oXo]2 )4", vm0, flop_amount*2/3);
377 run_test("( [ooX]2 )4", vm0, flop_amount*2/3);
378 MSG_process_sleep(2);
381 XBT_INFO("## Test 9 (ended)");
383 XBT_INFO("## Test 10 (started): check impact of a single emtpy VM collocated with tasks");
385 XBT_INFO("### Put a VM on a PM, and put a task to the PM");
386 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
388 run_test("( [ ]2 X )4", pm4, flop_amount);
389 MSG_process_sleep(2);
392 XBT_INFO("### Put a VM on a PM, and put two tasks to the PM");
393 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
395 run_test("( [ ]2 Xo )4", pm4, flop_amount);
396 run_test("( [ ]2 oX )4", pm4, flop_amount);
397 MSG_process_sleep(2);
400 XBT_INFO("### Put a VM on a PM, and put three tasks to the PM");
401 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
403 run_test("( [ ]2 Xoo )4", pm4, flop_amount);
404 run_test("( [ ]2 oXo )4", pm4, flop_amount);
405 run_test("( [ ]2 ooX )4", pm4, flop_amount);
406 MSG_process_sleep(2);
409 XBT_INFO("### Put a VM on a PM, and put four tasks to the PM");
410 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
412 run_test("( [ ]2 Xooo )4", pm4, flop_amount);
413 run_test("( [ ]2 oXoo )4", pm4, flop_amount);
414 run_test("( [ ]2 ooXo )4", pm4, flop_amount);
415 run_test("( [ ]2 oooX )4", pm4, flop_amount);
416 MSG_process_sleep(2);
419 XBT_INFO("## Test 10 (ended)");
421 XBT_INFO("## Test 11 (started): check impact of a single working VM collocated with tasks");
423 XBT_INFO("### Put a VM on a PM, and put one task to the PM and one task to the VM");
424 vm0 = MSG_vm_create_multicore(pm4, "VM0", 2);
426 run_test("( [X]2 o )4", vm0, flop_amount);
427 run_test("( [o]2 X )4", pm4, flop_amount);
428 MSG_process_sleep(2);
431 XBT_INFO("### Put a VM on a PM, and put two tasks to the PM and one task to the VM");
432 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
434 run_test("( [X]2 oo )4", vm0, flop_amount);
435 run_test("( [o]2 Xo )4", pm4, flop_amount);
436 run_test("( [o]2 oX )4", pm4, flop_amount);
437 MSG_process_sleep(2);
440 XBT_INFO("### Put a VM on a PM, and put two tasks to the PM and two tasks to the VM");
441 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
443 run_test("( [Xo]2 oo )4", vm0, flop_amount);
444 run_test("( [oX]2 oo )4", vm0, flop_amount);
445 run_test("( [oo]2 Xo )4", pm4, flop_amount);
446 run_test("( [oo]2 oX )4", pm4, flop_amount);
447 MSG_process_sleep(2);
450 XBT_INFO("### Put a VM on a PM, and put three tasks to the PM and one tasks to the VM");
451 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
453 run_test("( [X]2 ooo )4", vm0, flop_amount);
454 run_test("( [o]2 Xoo )4", pm4, flop_amount);
455 run_test("( [o]2 oXo )4", pm4, flop_amount);
456 run_test("( [o]2 ooX )4", pm4, flop_amount);
457 MSG_process_sleep(2);
460 XBT_INFO("### Put a VM on a PM, and put three tasks to the PM and two tasks to the VM");
461 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
463 run_test("( [Xo]2 ooo )4", vm0, flop_amount*4/5);
464 run_test("( [oX]2 ooo )4", vm0, flop_amount*4/5);
465 run_test("( [oo]2 Xoo )4", pm4, flop_amount*4/5);
466 run_test("( [oo]2 oXo )4", pm4, flop_amount*4/5);
467 run_test("( [oo]2 ooX )4", pm4, flop_amount*4/5);
468 MSG_process_sleep(2);
471 XBT_INFO("### Put a VM on a PM, and put three tasks to the PM and three tasks to the VM");
472 vm0 = MSG_vm_create_multicore(pm4, "VM0",2);
474 run_test("( [Xoo]2 ooo )4", vm0, flop_amount*(8/5) * 1/3); // The VM has 8/5 of the PM
475 run_test("( [oXo]2 ooo )4", vm0, flop_amount*(8/5) * 1/3);
476 run_test("( [ooX]2 ooo )4", vm0, flop_amount*(8/5) * 1/3);
478 run_test("( [ooo]2 Xoo )4", pm4, flop_amount*4/5);
479 run_test("( [ooo]2 oXo )4", pm4, flop_amount*4/5);
480 run_test("( [ooo]2 ooX )4", pm4, flop_amount*4/5);
481 MSG_process_sleep(2);
484 XBT_INFO("## Test 11 (ended)");
488 XBT_INFO("## %d test failed", failed_test);
493 int main(int argc, char* argv[])
495 /* Get the arguments */
496 MSG_init(&argc, argv);
498 /* load the platform file */
499 const char* platform = "../../../platforms/cloud-sharing.xml";
502 MSG_create_environment(platform);
504 msg_host_t pm0 = MSG_host_by_name("node-0.1core.org");
505 xbt_assert(pm0, "Host 'node-0.1core.org' not found");
506 MSG_process_create("master", master_main, NULL, pm0);
508 return MSG_main() != MSG_OK || failed_test;