1 /* A few basic tests for the surf library */
3 /* Copyright (c) 2004-2015. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "simgrid/sg_config.h"
11 #include "surf/surf.h"
12 #include "surf/surfxml_parse.h" // for reset callback
15 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
16 "Messages specific for surf example");
18 const char *string_action(e_surf_action_state_t state);
19 const char *string_action(e_surf_action_state_t state)
22 case (SURF_ACTION_READY):
23 return "SURF_ACTION_READY";
24 case (SURF_ACTION_RUNNING):
25 return "SURF_ACTION_RUNNING";
26 case (SURF_ACTION_FAILED):
27 return "SURF_ACTION_FAILED";
28 case (SURF_ACTION_DONE):
29 return "SURF_ACTION_DONE";
30 case (SURF_ACTION_NOT_IN_THE_SYSTEM):
31 return "SURF_ACTION_NOT_IN_THE_SYSTEM";
33 return "INVALID STATE";
37 void test(char *platform);
38 void test(char *platform)
40 sg_host_t cpuA = NULL;
41 sg_host_t cpuB = NULL;
42 surf_action_t actionA = NULL;
43 surf_action_t actionB = NULL;
44 surf_action_t actionC = NULL;
45 e_surf_action_state_t stateActionA;
46 e_surf_action_state_t stateActionB;
47 e_surf_action_state_t stateActionC;
49 xbt_cfg_set_parse(_sg_cfg_set, "cpu/model:Cas01");
50 xbt_cfg_set_parse(_sg_cfg_set, "network/model:CM02");
51 parse_platform_file(platform);
53 /*********************** CPU ***********************************/
54 XBT_DEBUG("%p", surf_cpu_model_pm);
55 cpuA = sg_host_by_name("Cpu A");
56 cpuB = sg_host_by_name("Cpu B");
58 /* Let's check that those two processors exist */
59 XBT_DEBUG("%s : %p", surf_cpu_name(sg_host_surfcpu(cpuA)), cpuA);
60 XBT_DEBUG("%s : %p", surf_cpu_name(sg_host_surfcpu(cpuB)), cpuB);
62 /* Let's do something on it */
63 actionA = surf_cpu_execute(cpuA, 1000.0);
64 actionB = surf_cpu_execute(cpuB, 1000.0);
65 actionC = surf_cpu_sleep(cpuB, 7.32);
67 /* Use whatever calling style you want... */
68 stateActionA = surf_action_get_state(actionA); /* When you know actionA model type */
69 stateActionB = surf_action_get_state(actionB); /* If you're unsure about it's model type */
70 stateActionC = surf_action_get_state(actionC); /* When you know actionA model type */
72 /* And just look at the state of these tasks */
73 XBT_DEBUG("actionA : %p (%s)", actionA, string_action(stateActionA));
74 XBT_DEBUG("actionB : %p (%s)", actionB, string_action(stateActionB));
75 XBT_DEBUG("actionC : %p (%s)", actionB, string_action(stateActionC));
77 /*********************** Network *******************************/
78 XBT_DEBUG("%p", surf_network_model);
80 /* Let's do something on it */
81 surf_network_model_communicate(surf_network_model, cpuA, cpuB, 150.0, -1.0);
83 surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */
85 surf_action_t action = NULL;
86 now = surf_get_clock();
87 XBT_DEBUG("Next Event : %g", now);
88 XBT_DEBUG("\t CPU actions");
90 surf_model_extract_failed_action_set((surf_model_t)surf_cpu_model_pm))) {
91 XBT_DEBUG("\t * Failed : %p", action);
92 surf_action_unref(action);
95 surf_model_extract_done_action_set((surf_model_t)surf_cpu_model_pm))) {
96 XBT_DEBUG("\t * Done : %p", action);
97 surf_action_unref(action);
99 XBT_DEBUG("\t Network actions");
101 surf_model_extract_failed_action_set((surf_model_t)surf_network_model))) {
102 XBT_DEBUG("\t * Failed : %p", action);
103 surf_action_unref(action);
106 surf_model_extract_done_action_set((surf_model_t)surf_network_model))) {
107 XBT_DEBUG("\t * Done : %p", action);
108 surf_action_unref(action);
111 } while ((surf_model_running_action_set_size((surf_model_t)surf_network_model) ||
112 surf_model_running_action_set_size((surf_model_t)surf_cpu_model_pm)) &&
113 surf_solve(-1.0) >= 0.0);
115 XBT_DEBUG("Simulation Terminated");
118 int main(int argc, char **argv)
120 surf_init(&argc, argv); /* Initialize some common structures */
122 fprintf(stderr, "Usage : %s platform.xml\n", argv[0]);