1 /* A few basic tests for the surf library */
3 /* Copyright (c) 2004-2017. 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"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
14 int main(int argc, char **argv)
18 surf_init(&argc, argv); /* Initialize some common structures */
20 xbt_cfg_set_parse("network/model:CM02");
21 xbt_cfg_set_parse("cpu/model:Cas01");
23 xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]);
24 parse_platform_file(argv[1]);
26 /*********************** HOST ***********************************/
27 simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
28 simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
30 /* Let's do something on it */
31 hostA->pimpl_cpu->execution_start(1000.0);
32 hostB->pimpl_cpu->execution_start(1000.0);
33 hostB->pimpl_cpu->sleep(7.32);
35 surf_network_model->communicate(hostA, hostB, 150.0, -1.0);
37 surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */
39 surf_action_t action = nullptr;
42 double now = surf_get_clock();
43 XBT_INFO("Next Event : %g", now);
45 for (auto const& model : *all_existing_models) {
46 if (surf_model_running_action_set_size(model)) {
47 XBT_DEBUG("\t Running that model");
51 action = surf_model_extract_failed_action_set(model);
52 while (action != nullptr) {
53 XBT_INFO(" * Done Action");
54 XBT_DEBUG("\t * Failed Action: %p", action);
56 action = surf_model_extract_failed_action_set(model);
59 action = surf_model_extract_done_action_set(model);
60 while (action != nullptr){
61 XBT_INFO(" * Done Action");
62 XBT_DEBUG("\t * Done Action: %p", action);
64 action = surf_model_extract_done_action_set(model);
67 } while (running && surf_solve(-1.0) >= 0.0);
69 XBT_INFO("Simulation Terminated");