1 /* A few basic tests for the surf library */
3 /* Copyright (c) 2004-2018. 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 "src/surf/cpu_interface.hpp"
10 #include "src/surf/network_interface.hpp"
11 #include "surf/surf.hpp"
12 #include "xbt/config.hpp"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
16 static const char* string_action(simgrid::kernel::resource::Action::State state)
19 case simgrid::kernel::resource::Action::State::INITED:
20 return "SURF_ACTION_INITED";
21 case simgrid::kernel::resource::Action::State::STARTED:
22 return "SURF_ACTION_RUNNING";
23 case simgrid::kernel::resource::Action::State::FAILED:
24 return "SURF_ACTION_FAILED";
25 case simgrid::kernel::resource::Action::State::FINISHED:
26 return "SURF_ACTION_DONE";
27 case simgrid::kernel::resource::Action::State::IGNORED:
28 return "SURF_ACTION_IGNORED";
30 return "INVALID STATE";
34 int main(int argc, char **argv)
36 surf_init(&argc, argv); /* Initialize some common structures */
37 simgrid::config::set_parse("cpu/model:Cas01");
38 simgrid::config::set_parse("network/model:CM02");
40 xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
41 parse_platform_file(argv[1]);
43 XBT_DEBUG("CPU model: %p", surf_cpu_model_pm);
44 XBT_DEBUG("Network model: %p", surf_network_model);
45 simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
46 simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
48 /* Let's do something on it */
49 simgrid::kernel::resource::Action* actionA = hostA->pimpl_cpu->execution_start(1000.0);
50 simgrid::kernel::resource::Action* actionB = hostB->pimpl_cpu->execution_start(1000.0);
51 simgrid::kernel::resource::Action* actionC = hostB->pimpl_cpu->sleep(7.32);
53 simgrid::kernel::resource::Action::State stateActionA = actionA->get_state();
54 simgrid::kernel::resource::Action::State stateActionB = actionB->get_state();
55 simgrid::kernel::resource::Action::State stateActionC = actionC->get_state();
57 /* And just look at the state of these tasks */
58 XBT_INFO("actionA state: %s", string_action(stateActionA));
59 XBT_INFO("actionB state: %s", string_action(stateActionB));
60 XBT_INFO("actionC state: %s", string_action(stateActionC));
63 /* Let's do something on it */
64 surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
68 XBT_INFO("Next Event : %g", surf_get_clock());
69 XBT_DEBUG("\t CPU actions");
71 simgrid::kernel::resource::Action::StateSet* action_list = surf_cpu_model_pm->get_failed_action_set();
72 while (not action_list->empty()) {
73 simgrid::kernel::resource::Action& action = action_list->front();
74 XBT_INFO(" CPU Failed action");
75 XBT_DEBUG("\t * Failed : %p", &action);
79 action_list = surf_cpu_model_pm->get_finished_action_set();
80 while (not action_list->empty()) {
81 simgrid::kernel::resource::Action& action = action_list->front();
82 XBT_INFO(" CPU Done action");
83 XBT_DEBUG("\t * Done : %p", &action);
87 action_list = surf_network_model->get_failed_action_set();
88 while (not action_list->empty()) {
89 simgrid::kernel::resource::Action& action = action_list->front();
90 XBT_INFO(" Network Failed action");
91 XBT_DEBUG("\t * Failed : %p", &action);
95 action_list = surf_network_model->get_finished_action_set();
96 while (not action_list->empty()) {
97 simgrid::kernel::resource::Action& action = action_list->front();
98 XBT_INFO(" Network Done action");
99 XBT_DEBUG("\t * Done : %p", &action);
104 (surf_network_model->get_started_action_set()->size() || surf_cpu_model_pm->get_started_action_set()->size()) &&
105 surf_solve(-1.0) >= 0.0);
107 XBT_DEBUG("Simulation Terminated");