Logo AND Algorithmique Numérique Distribuée

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