1 /* Copyright (c) 2016-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
8 import org.simgrid.msg.Host;
9 import org.simgrid.msg.HostFailureException;
10 import org.simgrid.msg.HostNotFoundException;
11 import org.simgrid.msg.Msg;
12 import org.simgrid.msg.Process;
13 import org.simgrid.msg.Task;
14 import org.simgrid.msg.TaskCancelledException;
15 import org.simgrid.msg.VM;
17 /* This class is a process in charge of running the test. It creates and starts the VMs, and fork processes within VMs */
18 public class EnergyVMRunner extends Process {
20 public class DummyProcess extends Process {
21 public DummyProcess (Host host, String name) {
26 public void main(String[] strings) {
27 Task task = new Task(this.getHost().getName()+"-task", 300E6 , 0);
30 } catch (HostFailureException | TaskCancelledException e) {
31 Msg.error(e.getMessage());
34 Msg.info("This worker is done.");
38 EnergyVMRunner(Host host, String name, String[] args) throws HostNotFoundException {
39 super(host, name, args);
43 public void main(String[] strings) throws HostNotFoundException, HostFailureException {
45 Host host1 = Host.getByName("MyHost1");
46 Host host2 = Host.getByName("MyHost2");
47 Host host3 = Host.getByName("MyHost3");
49 Msg.info("Creating and starting two VMs");
50 VM vmHost1 = new VM(host1, "vmHost1");
53 VM vmHost2 = new VM(host2, "vmHost3");
56 Msg.info("Create two tasks on Host1: one inside a VM, the other directly on the host");
57 new DummyProcess (vmHost1, "p11").start();
58 new DummyProcess (vmHost1, "p12").start();
60 Msg.info("Create two tasks on Host2: both directly on the host");
61 new DummyProcess (vmHost2, "p21").start();
62 new DummyProcess (host2, "p22").start();
64 Msg.info("Create two tasks on Host3: both inside a VM");
65 new DummyProcess (host3, "p31").start();
66 new DummyProcess (host3, "p312").start();
68 Msg.info("Wait 5 seconds. The tasks are still running (they run for 3 seconds, but 2 tasks are co-located, "
69 + "so they run for 6 seconds)");
71 Msg.info("Wait another 5 seconds. The tasks stop at some point in between");