Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cleanup in log categories
[simgrid.git] / teshsuite / models / cloud-sharing / cloud-sharing.cpp
1 /* Copyright (c) 2007-2022. 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/plugins/energy.h"
8 #include "simgrid/s4u.hpp"
9 #include "simgrid/s4u/VirtualMachine.hpp"
10 #include <cmath>
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this test");
13
14 const int FAIL_ON_ERROR = 0;
15 const int flop_amount   = 100000000; // 100Mf, so that computing this on a 1Gf core takes exactly 0.1s
16 int failed_test         = 0;
17
18 static int computation_fun(std::vector<std::string> argv)
19 {
20   int size = std::stoi(argv[0]);
21
22   double begin = simgrid::s4u::Engine::get_clock();
23   simgrid::s4u::this_actor::execute(size);
24   double end = simgrid::s4u::Engine::get_clock();
25
26   if (0.1 - (end - begin) > 0.001) {
27     xbt_assert(not FAIL_ON_ERROR, "%s with %.4g load (%dflops) took %.4fs instead of 0.1s",
28                simgrid::s4u::this_actor::get_name().c_str(), ((double)size / flop_amount), size, (end - begin));
29     XBT_INFO("FAILED TEST: %s with %.4g load (%dflops) took %.4fs instead of 0.1s",
30              simgrid::s4u::this_actor::get_name().c_str(), ((double)size / flop_amount), size, (end - begin));
31     failed_test++;
32   } else {
33     XBT_INFO("Passed: %s with %.4g load (%dflops) took 0.1s as expected", simgrid::s4u::this_actor::get_name().c_str(),
34              ((double)size / flop_amount), size);
35   }
36
37   return 0;
38 }
39
40 static void run_test_process(const std::string& name, simgrid::s4u::Host* location, int size)
41 {
42   std::vector<std::string> arg = {std::to_string(size)};
43   simgrid::s4u::Actor::create(name, location, computation_fun, arg);
44 }
45
46 static void test_energy_consumption(const std::string& name, int nb_cores)
47 {
48   static double current_energy = 0;
49   double new_energy = 0;
50
51   for (simgrid::s4u::Host* pm : simgrid::s4u::Engine::get_instance()->get_all_hosts()) {
52     if (not dynamic_cast<simgrid::s4u::VirtualMachine*>(pm))
53       new_energy += sg_host_get_consumed_energy(pm);
54   }
55
56   double expected_consumption = 0.1 * nb_cores;
57   double actual_consumption   = new_energy - current_energy;
58
59   current_energy = new_energy;
60
61   if (std::abs(expected_consumption - actual_consumption) > 0.001) {
62     XBT_INFO("FAILED TEST: %s consumed %f instead of %f J (i.e. %i cores should have been used)", name.c_str(),
63              actual_consumption, expected_consumption, nb_cores);
64     failed_test++;
65   } else {
66     XBT_INFO("Passed: %s consumed %f J (i.e. %i cores used)", name.c_str(), actual_consumption, nb_cores);
67   }
68 }
69
70 static void run_test(const std::string& chooser)
71 {
72   simgrid::s4u::Host* pm0 = simgrid::s4u::Host::by_name("node-0.1core.org");
73   simgrid::s4u::Host* pm1 = simgrid::s4u::Host::by_name("node-1.1core.org");
74   simgrid::s4u::Host* pm2 = simgrid::s4u::Host::by_name("node-0.2cores.org"); // 2 cores
75   simgrid::s4u::Host* pm4 = simgrid::s4u::Host::by_name("node-0.4cores.org");
76
77   simgrid::s4u::VirtualMachine* vm0;
78   xbt_assert(pm0, "Host node-0.1core.org does not seem to exist");
79   xbt_assert(pm2, "Host node-0.2cores.org does not seem to exist");
80   xbt_assert(pm4, "Host node-0.4cores.org does not seem to exist");
81
82   // syntax of the process name:
83   // "( )1" means PM with one core; "( )2" means PM with 2 cores
84   // "(  [  ]2  )4" means a VM with 2 cores, on a PM with 4 cores.
85   // "o" means another process is there
86   // "X" means the process which holds this name
87
88   if (chooser == "(o)1") {
89     XBT_INFO("### Test '%s'. A task on a regular PM", chooser.c_str());
90     run_test_process("(X)1", pm0, flop_amount);
91     simgrid::s4u::this_actor::sleep_for(2);
92     test_energy_consumption(chooser, 1);
93
94   } else if (chooser == "(oo)1") {
95     XBT_INFO("### Test '%s'. 2 tasks on a regular PM", chooser.c_str());
96     run_test_process("(Xo)1", pm0, flop_amount / 2);
97     run_test_process("(oX)1", pm0, flop_amount / 2);
98     simgrid::s4u::this_actor::sleep_for(2);
99     test_energy_consumption(chooser, 1);
100
101   } else if (chooser == "(o)1 (o)1") {
102     XBT_INFO("### Test '%s'. 2 regular PMs, with a task each.", chooser.c_str());
103     run_test_process("(X)1 (o)1", pm0, flop_amount);
104     run_test_process("(o)1 (X)1", pm1, flop_amount);
105     simgrid::s4u::this_actor::sleep_for(2);
106     test_energy_consumption(chooser, 2);
107
108   } else if (chooser == "( [o]1 )1") {
109     XBT_INFO("### Test '%s'. A task in a VM on a PM.", chooser.c_str());
110     vm0 = pm0->create_vm("VM0", 1);
111     run_test_process("( [X]1 )1", vm0, flop_amount);
112     simgrid::s4u::this_actor::sleep_for(2);
113     test_energy_consumption(chooser, 1);
114     vm0->destroy();
115
116   } else if (chooser == "( [oo]1 )1") {
117     XBT_INFO("### Test '%s'. 2 tasks co-located in a VM on a PM.", chooser.c_str());
118     vm0 = pm0->create_vm("VM0", 1);
119     run_test_process("( [Xo]1 )1", vm0, flop_amount / 2);
120     run_test_process("( [oX]1 )1", vm0, flop_amount / 2);
121     simgrid::s4u::this_actor::sleep_for(2);
122     test_energy_consumption(chooser, 1);
123     vm0->destroy();
124
125   } else if (chooser == "( [ ]1 o )1") {
126     XBT_INFO("### Test '%s'. 1 task collocated with an empty VM", chooser.c_str());
127     vm0 = pm0->create_vm("VM0", 1);
128     run_test_process("( [ ]1 X )1", pm0, flop_amount);
129     simgrid::s4u::this_actor::sleep_for(2);
130     test_energy_consumption(chooser, 1);
131     vm0->destroy();
132
133   } else if (chooser == "( [o]1 o )1") {
134     XBT_INFO("### Test '%s'. A task in a VM, plus a task", chooser.c_str());
135     vm0 = pm0->create_vm("VM0", 1);
136     run_test_process("( [X]1 o )1", vm0, flop_amount / 2);
137     run_test_process("( [o]1 X )1", pm0, flop_amount / 2);
138     simgrid::s4u::this_actor::sleep_for(2);
139     test_energy_consumption(chooser, 1);
140     vm0->destroy();
141
142   } else if (chooser == "( [oo]1 o )1") {
143     XBT_INFO("### Test '%s'. 2 tasks in a VM, plus a task", chooser.c_str());
144     vm0 = pm0->create_vm("VM0", 1);
145     run_test_process("( [Xo]1 o )1", vm0, flop_amount / 4);
146     run_test_process("( [oX]1 o )1", vm0, flop_amount / 4);
147     run_test_process("( [oo]1 X )1", pm0, flop_amount / 2);
148     simgrid::s4u::this_actor::sleep_for(2);
149     test_energy_consumption(chooser, 1);
150     vm0->destroy();
151
152   } else if (chooser == "( o )2") {
153     XBT_INFO("### Test '%s'. A task on bicore PM", chooser.c_str());
154     run_test_process("(X)2", pm2, flop_amount);
155     simgrid::s4u::this_actor::sleep_for(2);
156     test_energy_consumption(chooser, 1);
157
158   } else if (chooser == "( oo )2") {
159     XBT_INFO("### Test '%s'. 2 tasks on a bicore PM", chooser.c_str());
160     run_test_process("(Xx)2", pm2, flop_amount);
161     run_test_process("(xX)2", pm2, flop_amount);
162     simgrid::s4u::this_actor::sleep_for(2);
163     test_energy_consumption(chooser, 2);
164
165   } else if (chooser == "( ooo )2") {
166     XBT_INFO("### Test '%s'. 3 tasks on a bicore PM", chooser.c_str());
167     run_test_process("(Xxx)2", pm2, flop_amount * 2 / 3);
168     run_test_process("(xXx)2", pm2, flop_amount * 2 / 3);
169     run_test_process("(xxX)2", pm2, flop_amount * 2 / 3);
170     simgrid::s4u::this_actor::sleep_for(2);
171     test_energy_consumption(chooser, 2);
172
173   } else if (chooser == "( [o]1 )2") {
174     XBT_INFO("### Test '%s'. A task in a VM on a bicore PM", chooser.c_str());
175     vm0 = pm2->create_vm("VM0", 1);
176     run_test_process("( [X]1 )2", vm0, flop_amount);
177     simgrid::s4u::this_actor::sleep_for(2);
178     test_energy_consumption(chooser, 1);
179     vm0->destroy();
180
181   } else if (chooser == "( [oo]1 )2") {
182     XBT_INFO("### Test '%s'. 2 tasks in a VM on a bicore PM", chooser.c_str());
183     vm0 = pm2->create_vm("VM0", 1);
184     run_test_process("( [Xx]1 )2", vm0, flop_amount / 2);
185     run_test_process("( [xX]1 )2", vm0, flop_amount / 2);
186     simgrid::s4u::this_actor::sleep_for(2);
187     test_energy_consumption(chooser, 1);
188     vm0->destroy();
189
190   } else if (chooser == "( [ ]1 o )2") {
191     XBT_INFO("### Put a VM on a PM, and put a task to the PM");
192     vm0 = pm2->create_vm("VM0", 1);
193     run_test_process("( [ ]1 X )2", pm2, flop_amount);
194     simgrid::s4u::this_actor::sleep_for(2);
195     test_energy_consumption(chooser, 1);
196     vm0->destroy();
197
198   } else if (chooser == "( [o]1 o )2") {
199     XBT_INFO("### Put a VM on a PM, put a task to the PM and a task to the VM");
200     vm0 = pm2->create_vm("VM0", 1);
201     run_test_process("( [X]1 x )2", vm0, flop_amount);
202     run_test_process("( [x]1 X )2", pm2, flop_amount);
203     simgrid::s4u::this_actor::sleep_for(2);
204     test_energy_consumption(chooser, 2);
205     vm0->destroy();
206
207   } else if (chooser == "( [o]1 [ ]1 )2") {
208     XBT_INFO("### Put two VMs on a PM, and put a task to one VM");
209     vm0       = pm2->create_vm("VM0", 1);
210     auto* vm1 = pm2->create_vm("VM1", 1);
211     run_test_process("( [X]1 [ ]1 )2", vm0, flop_amount);
212     simgrid::s4u::this_actor::sleep_for(2);
213     test_energy_consumption(chooser, 1);
214     vm0->destroy();
215     vm1->destroy();
216
217   } else if (chooser == "( [o]1 [o]1 )2") {
218     XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
219     vm0       = pm2->create_vm("VM0", 1);
220     auto* vm1 = pm2->create_vm("VM1", 1);
221     run_test_process("( [X]1 [x]1 )2", vm0, flop_amount);
222     run_test_process("( [x]1 [X]1 )2", vm1, flop_amount);
223     simgrid::s4u::this_actor::sleep_for(2);
224     test_energy_consumption(chooser, 2);
225     vm0->destroy();
226     vm1->destroy();
227
228   } else if (chooser == "( [o]1 [o]1 [ ]1 )2") {
229     XBT_INFO("### Put three VMs on a PM, and put a task to two VMs");
230     vm0       = pm2->create_vm("VM0", 1);
231     auto* vm1 = pm2->create_vm("VM1", 1);
232     auto* vm2 = pm2->create_vm("VM2", 1);
233     run_test_process("( [X]1 [x]1 [ ]1 )2", vm0, flop_amount);
234     run_test_process("( [x]1 [X]1 [ ]1 )2", vm1, flop_amount);
235     simgrid::s4u::this_actor::sleep_for(2);
236     test_energy_consumption(chooser, 2);
237     vm0->destroy();
238     vm1->destroy();
239     vm2->destroy();
240
241   } else if (chooser == "( [o]1 [o]1 [o]1 )2") {
242     XBT_INFO("### Put three VMs on a PM, and put a task to each VM");
243     vm0       = pm2->create_vm("VM0", 1);
244     auto* vm1 = pm2->create_vm("VM1", 1);
245     auto* vm2 = pm2->create_vm("VM2", 1);
246     run_test_process("( [X]1 [o]1 [o]1 )2", vm0, flop_amount * 2 / 3);
247     run_test_process("( [o]1 [X]1 [o]1 )2", vm1, flop_amount * 2 / 3);
248     run_test_process("( [o]1 [o]1 [X]1 )2", vm2, flop_amount * 2 / 3);
249     simgrid::s4u::this_actor::sleep_for(2);
250     test_energy_consumption(chooser, 2);
251     vm0->destroy();
252     vm1->destroy();
253     vm2->destroy();
254
255   } else if (chooser == "( [o]2 )2") {
256     XBT_INFO("### Put a VM on a PM, and put a task to the VM");
257     vm0 = pm2->create_vm("VM0", 2);
258     run_test_process("( [X]2 )2", vm0, flop_amount);
259     simgrid::s4u::this_actor::sleep_for(2);
260     test_energy_consumption(chooser, 1);
261     vm0->destroy();
262
263   } else if (chooser == "( [oo]2 )2") {
264     XBT_INFO("### Put a VM on a PM, and put two tasks to the VM");
265     vm0 = pm2->create_vm("VM0", 2);
266     run_test_process("( [Xo]2 )2", vm0, flop_amount);
267     run_test_process("( [oX]2 )2", vm0, flop_amount);
268     simgrid::s4u::this_actor::sleep_for(2);
269     test_energy_consumption(chooser, 2);
270     vm0->destroy();
271
272   } else if (chooser == "( [ooo]2 )2") {
273     XBT_INFO("### Put a VM on a PM, and put three tasks to the VM");
274     vm0 = pm2->create_vm("VM0", 2);
275     run_test_process("( [Xoo]2 )2", vm0, flop_amount * 2 / 3);
276     run_test_process("( [oXo]2 )2", vm0, flop_amount * 2 / 3);
277     run_test_process("( [ooX]2 )2", vm0, flop_amount * 2 / 3);
278     simgrid::s4u::this_actor::sleep_for(2);
279     test_energy_consumption(chooser, 2);
280     vm0->destroy();
281
282   } else if (chooser == "( [ ]2 o )2") {
283     XBT_INFO("### Put a VM on a PM, and put a task to the PM");
284     vm0 = pm2->create_vm("VM0", 2);
285     run_test_process("( [ ]2 X )2", pm2, flop_amount);
286     simgrid::s4u::this_actor::sleep_for(2);
287     test_energy_consumption(chooser, 1);
288     vm0->destroy();
289
290   } else if (chooser == "( [o]2 o )2") {
291     XBT_INFO("### Put a VM on a PM, put one task to the PM and one task to the VM");
292     vm0 = pm2->create_vm("VM0", 2);
293     run_test_process("( [o]2 X )2", pm2, flop_amount);
294     run_test_process("( [X]2 o )2", vm0, flop_amount);
295     simgrid::s4u::this_actor::sleep_for(2);
296     test_energy_consumption(chooser, 2);
297     vm0->destroy();
298
299   } else if (chooser == "( [oo]2 o )2") {
300     XBT_INFO("### Put a VM on a PM, put one task to the PM and two tasks to the VM");
301     vm0 = pm2->create_vm("VM0", 2);
302     run_test_process("( [oo]2 X )2", pm2, flop_amount * 2 / 3);
303     run_test_process("( [Xo]2 o )2", vm0, flop_amount * 2 / 3);
304     run_test_process("( [oX]2 o )2", vm0, flop_amount * 2 / 3);
305     simgrid::s4u::this_actor::sleep_for(2);
306     test_energy_consumption(chooser, 2);
307     vm0->destroy();
308
309   } else if (chooser == "( [ooo]2 o )2") {
310     XBT_INFO("### Put a VM on a PM, put one task to the PM and three tasks to the VM");
311     vm0 = pm2->create_vm("VM0", 2);
312     run_test_process("( [ooo]2 X )2", pm2, flop_amount * 2 / 3);
313     run_test_process("( [Xoo]2 o )2", vm0, (flop_amount * 4 / 3) / 3); // VM_share/3
314     run_test_process("( [oXo]2 o )2", vm0, (flop_amount * 4 / 3) / 3); // VM_share/3
315     run_test_process("( [ooX]2 o )2", vm0, (flop_amount * 4 / 3) / 3); // VM_share/3
316     simgrid::s4u::this_actor::sleep_for(2);
317     test_energy_consumption(chooser, 2);
318     vm0->destroy();
319
320   } else if (chooser == "( [ ]2 oo )2") {
321     XBT_INFO("### Put a VM on a PM, and put two tasks to the PM");
322     vm0 = pm2->create_vm("VM0", 2);
323     run_test_process("( [ ]2 Xo )2", pm2, flop_amount);
324     run_test_process("( [ ]2 oX )2", pm2, flop_amount);
325     simgrid::s4u::this_actor::sleep_for(2);
326     test_energy_consumption(chooser, 2);
327     vm0->destroy();
328
329   } else if (chooser == "( [o]2 oo )2") {
330     XBT_INFO("### Put a VM on a PM, put one task to the PM and one task to the VM");
331     vm0 = pm2->create_vm("VM0", 2);
332     run_test_process("( [o]2 Xo )2", pm2, flop_amount * 2 / 3);
333     run_test_process("( [o]2 oX )2", pm2, flop_amount * 2 / 3);
334     run_test_process("( [X]2 oo )2", vm0, flop_amount * 2 / 3);
335     simgrid::s4u::this_actor::sleep_for(2);
336     test_energy_consumption(chooser, 2);
337     vm0->destroy();
338
339   } else if (chooser == "( [oo]2 oo )2") {
340     XBT_INFO("### Put a VM on a PM, put one task to the PM and two tasks to the VM");
341     vm0 = pm2->create_vm("VM0", 2);
342     run_test_process("( [oo]2 Xo )2", pm2, flop_amount / 2);
343     run_test_process("( [oo]2 oX )2", pm2, flop_amount / 2);
344     run_test_process("( [Xo]2 oo )2", vm0, flop_amount / 2);
345     run_test_process("( [oX]2 oo )2", vm0, flop_amount / 2);
346     simgrid::s4u::this_actor::sleep_for(2);
347     test_energy_consumption(chooser, 2);
348     vm0->destroy();
349
350   } else if (chooser == "( [ooo]2 oo )2") {
351     XBT_INFO("### Put a VM on a PM, put one task to the PM and three tasks to the VM");
352     vm0 = pm2->create_vm("VM0", 2);
353     run_test_process("( [ooo]2 Xo )2", pm2, flop_amount * 2 / 4);
354     run_test_process("( [ooo]2 oX )2", pm2, flop_amount * 2 / 4);
355     run_test_process("( [Xoo]2 oo )2", vm0, flop_amount / 3);
356     run_test_process("( [oXo]2 oo )2", vm0, flop_amount / 3);
357     run_test_process("( [ooX]2 oo )2", vm0, flop_amount / 3);
358     simgrid::s4u::this_actor::sleep_for(2);
359     test_energy_consumption(chooser, 2);
360     vm0->destroy();
361
362   } else if (chooser == "( [o]2 )4") {
363     XBT_INFO("### Put a VM on a PM, and put a task to the VM");
364     vm0 = pm4->create_vm("VM0", 2);
365     run_test_process("( [X]2 )4", vm0, flop_amount);
366     simgrid::s4u::this_actor::sleep_for(2);
367     test_energy_consumption(chooser, 1);
368     vm0->destroy();
369
370   } else if (chooser == "( [oo]2 )4") {
371     XBT_INFO("### Put a VM on a PM, and put two tasks to the VM");
372     vm0 = pm4->create_vm("VM0", 2);
373     run_test_process("( [Xo]2 )4", vm0, flop_amount);
374     run_test_process("( [oX]2 )4", vm0, flop_amount);
375     simgrid::s4u::this_actor::sleep_for(2);
376     test_energy_consumption(chooser, 2);
377     vm0->destroy();
378
379   } else if (chooser == "( [ooo]2 )4") {
380     XBT_INFO("### ( [ooo]2 )4: Put a VM on a PM, and put three tasks to the VM");
381     vm0 = pm4->create_vm("VM0", 2);
382     run_test_process("( [Xoo]2 )4", vm0, flop_amount * 2 / 3);
383     run_test_process("( [oXo]2 )4", vm0, flop_amount * 2 / 3);
384     run_test_process("( [ooX]2 )4", vm0, flop_amount * 2 / 3);
385     simgrid::s4u::this_actor::sleep_for(2);
386     test_energy_consumption(chooser, 2);
387     vm0->destroy();
388
389   } else if (chooser == "( [ ]2 o )4") {
390     XBT_INFO("### Put a VM on a PM, and put a task to the PM");
391     vm0 = pm4->create_vm("VM0", 2);
392     run_test_process("( [ ]2 X )4", pm4, flop_amount);
393     simgrid::s4u::this_actor::sleep_for(2);
394     test_energy_consumption(chooser, 1);
395     vm0->destroy();
396
397   } else if (chooser == "( [ ]2 oo )4") {
398     XBT_INFO("### Put a VM on a PM, and put two tasks to the PM");
399     vm0 = pm4->create_vm("VM0", 2);
400     run_test_process("( [ ]2 Xo )4", pm4, flop_amount);
401     run_test_process("( [ ]2 oX )4", pm4, flop_amount);
402     simgrid::s4u::this_actor::sleep_for(2);
403     test_energy_consumption(chooser, 2);
404     vm0->destroy();
405
406   } else if (chooser == "( [ ]2 ooo )4") {
407     XBT_INFO("### Put a VM on a PM, and put three tasks to the PM");
408     vm0 = pm4->create_vm("VM0", 2);
409     run_test_process("( [ ]2 Xoo )4", pm4, flop_amount);
410     run_test_process("( [ ]2 oXo )4", pm4, flop_amount);
411     run_test_process("( [ ]2 ooX )4", pm4, flop_amount);
412     simgrid::s4u::this_actor::sleep_for(2);
413     test_energy_consumption(chooser, 3);
414     vm0->destroy();
415
416   } else if (chooser == "( [ ]2 oooo )4") {
417     XBT_INFO("### Put a VM on a PM, and put four tasks to the PM");
418     vm0 = pm4->create_vm("VM0", 2);
419     run_test_process("( [ ]2 Xooo )4", pm4, flop_amount);
420     run_test_process("( [ ]2 oXoo )4", pm4, flop_amount);
421     run_test_process("( [ ]2 ooXo )4", pm4, flop_amount);
422     run_test_process("( [ ]2 oooX )4", pm4, flop_amount);
423     simgrid::s4u::this_actor::sleep_for(2);
424     test_energy_consumption(chooser, 4);
425     vm0->destroy();
426
427   } else if (chooser == "( [o]2 o )4") {
428     XBT_INFO("### Put a VM on a PM, and put one task to the PM and one task to the VM");
429     vm0 = pm4->create_vm("VM0", 2);
430     run_test_process("( [X]2 o )4", vm0, flop_amount);
431     run_test_process("( [o]2 X )4", pm4, flop_amount);
432     simgrid::s4u::this_actor::sleep_for(2);
433     test_energy_consumption(chooser, 2);
434     vm0->destroy();
435
436   } else if (chooser == "( [o]2 oo )4") {
437     XBT_INFO("### Put a VM on a PM, and put two tasks to the PM and one task to the VM");
438     vm0 = pm4->create_vm("VM0", 2);
439     run_test_process("( [X]2 oo )4", vm0, flop_amount);
440     run_test_process("( [o]2 Xo )4", pm4, flop_amount);
441     run_test_process("( [o]2 oX )4", pm4, flop_amount);
442     simgrid::s4u::this_actor::sleep_for(2);
443     test_energy_consumption(chooser, 3);
444     vm0->destroy();
445
446   } else if (chooser == "( [oo]2 oo )4") {
447     XBT_INFO("### Put a VM on a PM, and put two tasks to the PM and two tasks to the VM");
448     vm0 = pm4->create_vm("VM0", 2);
449     run_test_process("( [Xo]2 oo )4", vm0, flop_amount);
450     run_test_process("( [oX]2 oo )4", vm0, flop_amount);
451     run_test_process("( [oo]2 Xo )4", pm4, flop_amount);
452     run_test_process("( [oo]2 oX )4", pm4, flop_amount);
453     simgrid::s4u::this_actor::sleep_for(2);
454     test_energy_consumption(chooser, 4);
455     vm0->destroy();
456
457   } else if (chooser == "( [o]2 ooo )4") {
458     XBT_INFO("### Put a VM on a PM, and put three tasks to the PM and one tasks to the VM");
459     vm0 = pm4->create_vm("VM0", 2);
460     run_test_process("( [X]2 ooo )4", vm0, flop_amount);
461     run_test_process("( [o]2 Xoo )4", pm4, flop_amount);
462     run_test_process("( [o]2 oXo )4", pm4, flop_amount);
463     run_test_process("( [o]2 ooX )4", pm4, flop_amount);
464     simgrid::s4u::this_actor::sleep_for(2);
465     test_energy_consumption(chooser, 4);
466     vm0->destroy();
467
468   } else if (chooser == "( [oo]2 ooo )4") {
469     XBT_INFO("### Put a VM on a PM, and put three tasks to the PM and two tasks to the VM");
470     vm0 = pm4->create_vm("VM0", 2);
471     run_test_process("( [Xo]2 ooo )4", vm0, flop_amount * 4 / 5);
472     run_test_process("( [oX]2 ooo )4", vm0, flop_amount * 4 / 5);
473     run_test_process("( [oo]2 Xoo )4", pm4, flop_amount * 4 / 5);
474     run_test_process("( [oo]2 oXo )4", pm4, flop_amount * 4 / 5);
475     run_test_process("( [oo]2 ooX )4", pm4, flop_amount * 4 / 5);
476     simgrid::s4u::this_actor::sleep_for(2);
477     test_energy_consumption(chooser, 4);
478     vm0->destroy();
479
480   } else if (chooser == "( [ooo]2 ooo )4") {
481     XBT_INFO("### Put a VM on a PM, and put three tasks to the PM and three tasks to the VM");
482     vm0 = pm4->create_vm("VM0", 2);
483     run_test_process("( [Xoo]2 ooo )4", vm0, (flop_amount * 8 / 5) / 3); // The VM has 8/5 of the PM
484     run_test_process("( [oXo]2 ooo )4", vm0, (flop_amount * 8 / 5) / 3);
485     run_test_process("( [ooX]2 ooo )4", vm0, (flop_amount * 8 / 5) / 3);
486
487     run_test_process("( [ooo]2 Xoo )4", pm4, flop_amount * 4 / 5);
488     run_test_process("( [ooo]2 oXo )4", pm4, flop_amount * 4 / 5);
489     run_test_process("( [ooo]2 ooX )4", pm4, flop_amount * 4 / 5);
490     simgrid::s4u::this_actor::sleep_for(2);
491     test_energy_consumption(chooser, 4);
492     vm0->destroy();
493
494   } else {
495     xbt_die("Unknown chooser: %s", chooser.c_str());
496   }
497 }
498 static int master_main()
499 {
500   XBT_INFO("# TEST ON SINGLE-CORE PMs");
501   XBT_INFO("## Check computation on regular PMs");
502   run_test("(o)1");
503   run_test("(oo)1");
504   run_test("(o)1 (o)1");
505   XBT_INFO("# TEST ON SINGLE-CORE PMs AND SINGLE-CORE VMs");
506
507   XBT_INFO("## Check the impact of running tasks inside a VM (no degradation for the moment)");
508   run_test("( [o]1 )1");
509   run_test("( [oo]1 )1");
510
511   XBT_INFO("## Check impact of running tasks collocated with VMs (no VM noise for the moment)");
512   run_test("( [ ]1 o )1");
513   run_test("( [o]1 o )1");
514   run_test("( [oo]1 o )1");
515
516   XBT_INFO("# TEST ON TWO-CORE PMs");
517   XBT_INFO("## Check computation on 2 cores PMs");
518   run_test("( o )2");
519   run_test("( oo )2");
520   run_test("( ooo )2");
521
522   XBT_INFO("# TEST ON TWO-CORE PMs AND SINGLE-CORE VMs");
523   XBT_INFO("## Check impact of a single VM (no degradation for the moment)");
524   run_test("( [o]1 )2");
525   run_test("( [oo]1 )2");
526   run_test("( [ ]1 o )2");
527   run_test("( [o]1 o )2");
528
529   XBT_INFO("## Check impact of a several VMs (there is no degradation for the moment)");
530   run_test("( [o]1 [ ]1 )2");
531   run_test("( [o]1 [o]1 )2");
532   run_test("( [o]1 [o]1 [ ]1 )2");
533   run_test("( [o]1 [o]1 [o]1 )2");
534
535   XBT_INFO("# TEST ON TWO-CORE PMs AND TWO-CORE VMs");
536
537   XBT_INFO("## Check impact of a single VM (there is no degradation for the moment)");
538   run_test("( [o]2 )2");
539   run_test("( [oo]2 )2");
540   run_test("( [ooo]2 )2");
541
542   XBT_INFO("## Check impact of a single VM collocated with a task (there is no degradation for the moment)");
543   run_test("( [ ]2 o )2");
544   run_test("( [o]2 o )2");
545   run_test("( [oo]2 o )2");
546   run_test("( [ooo]2 o )2");
547   run_test("( [ ]2 oo )2");
548   run_test("( [o]2 oo )2");
549   run_test("( [oo]2 oo )2");
550   run_test("( [ooo]2 oo )2");
551
552   XBT_INFO("# TEST ON FOUR-CORE PMs AND TWO-CORE VMs");
553
554   XBT_INFO("## Check impact of a single VM");
555   run_test("( [o]2 )4");
556   run_test("( [oo]2 )4");
557   run_test("( [ooo]2 )4");
558
559   XBT_INFO("## Check impact of a single empty VM collocated with tasks");
560   run_test("( [ ]2 o )4");
561   run_test("( [ ]2 oo )4");
562   run_test("( [ ]2 ooo )4");
563   run_test("( [ ]2 oooo )4");
564
565   XBT_INFO("## Check impact of a single working VM collocated with tasks");
566   run_test("( [o]2 o )4");
567   run_test("( [o]2 oo )4");
568   run_test("( [oo]2 oo )4");
569   run_test("( [o]2 ooo )4");
570   run_test("( [oo]2 ooo )4");
571   run_test("( [ooo]2 ooo )4");
572
573   XBT_INFO(".");
574   XBT_INFO("## %d test failed", failed_test);
575   XBT_INFO(".");
576   return 0;
577 }
578 int main(int argc, char* argv[])
579 {
580   /* Get the arguments */
581   simgrid::s4u::Engine e(&argc, argv);
582   sg_host_energy_plugin_init();
583
584   /* load the platform file */
585   const char* platform = "../../../platforms/cloud-sharing.xml";
586   if (argc == 2)
587     platform = argv[1];
588   e.load_platform(platform);
589
590   simgrid::s4u::Host* pm0 = e.host_by_name("node-0.1core.org");
591   xbt_assert(pm0, "Host 'node-0.1core.org' not found");
592   simgrid::s4u::Actor::create("master", pm0, master_main);
593
594   e.run();
595
596   return failed_test;
597 }