1 /* A few basic tests for the surf library */
3 /* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "simgrid/host.h"
9 #include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object
10 #include "simgrid/s4u/Engine.hpp"
11 #include "simgrid/zone.h"
12 #include "src/kernel/EngineImpl.hpp"
13 #include "src/kernel/resource/CpuImpl.hpp"
14 #include "src/kernel/resource/LinkImpl.hpp"
15 #include "xbt/config.hpp"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
19 static const char* string_action(simgrid::kernel::resource::Action::State state)
22 case simgrid::kernel::resource::Action::State::INITED:
23 return "SURF_ACTION_INITED";
24 case simgrid::kernel::resource::Action::State::STARTED:
25 return "SURF_ACTION_RUNNING";
26 case simgrid::kernel::resource::Action::State::FAILED:
27 return "SURF_ACTION_FAILED";
28 case simgrid::kernel::resource::Action::State::FINISHED:
29 return "SURF_ACTION_DONE";
30 case simgrid::kernel::resource::Action::State::IGNORED:
31 return "SURF_ACTION_IGNORED";
33 return "INVALID STATE";
37 int main(int argc, char** argv)
39 simgrid::s4u::Engine e(&argc, argv);
40 simgrid::s4u::Engine::set_config("cpu/model:Cas01");
41 simgrid::s4u::Engine::set_config("network/model:CM02");
43 xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
44 e.load_platform(argv[1]);
46 const_sg_netzone_t as_zone = e.netzone_by_name_or_null("AS0");
47 auto net_model = as_zone->get_impl()->get_network_model();
48 auto cpu_model_pm = as_zone->get_impl()->get_cpu_pm_model();
50 XBT_DEBUG("CPU model: %p", cpu_model_pm.get());
51 XBT_DEBUG("Network model: %p", net_model.get());
52 simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
53 simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
55 /* Let's do something on it */
56 const simgrid::kernel::resource::Action* actionA = hostA->get_cpu()->execution_start(1000.0, -1);
57 const simgrid::kernel::resource::Action* actionB = hostB->get_cpu()->execution_start(1000.0, -1);
58 const simgrid::kernel::resource::Action* actionC = hostB->get_cpu()->sleep(7.32);
60 simgrid::kernel::resource::Action::State stateActionA = actionA->get_state();
61 simgrid::kernel::resource::Action::State stateActionB = actionB->get_state();
62 simgrid::kernel::resource::Action::State stateActionC = actionC->get_state();
64 /* And just look at the state of these tasks */
65 XBT_INFO("actionA state: %s", string_action(stateActionA));
66 XBT_INFO("actionB state: %s", string_action(stateActionB));
67 XBT_INFO("actionC state: %s", string_action(stateActionC));
69 /* Let's do something on it */
70 net_model->communicate(hostA, hostB, 150.0, -1.0);
72 e.get_impl()->solve(-1.0);
74 XBT_INFO("Next Event : %g", simgrid::s4u::Engine::get_clock());
75 XBT_DEBUG("\t CPU actions");
77 simgrid::kernel::resource::Action::StateSet* action_list = cpu_model_pm->get_failed_action_set();
78 while (not action_list->empty()) {
79 simgrid::kernel::resource::Action& action = action_list->front();
80 XBT_INFO(" CPU Failed action");
81 XBT_DEBUG("\t * Failed : %p", &action);
85 action_list = cpu_model_pm->get_finished_action_set();
86 while (not action_list->empty()) {
87 simgrid::kernel::resource::Action& action = action_list->front();
88 XBT_INFO(" CPU Done action");
89 XBT_DEBUG("\t * Done : %p", &action);
93 action_list = net_model->get_failed_action_set();
94 while (not action_list->empty()) {
95 simgrid::kernel::resource::Action& action = action_list->front();
96 XBT_INFO(" Network Failed action");
97 XBT_DEBUG("\t * Failed : %p", &action);
101 action_list = net_model->get_finished_action_set();
102 while (not action_list->empty()) {
103 simgrid::kernel::resource::Action& action = action_list->front();
104 XBT_INFO(" Network Done action");
105 XBT_DEBUG("\t * Done : %p", &action);
108 } while ((net_model->get_started_action_set()->size() || cpu_model_pm->get_started_action_set()->size()) &&
109 e.get_impl()->solve(-1.0) >= 0.0);
111 XBT_DEBUG("Simulation Terminated");