1 /* A few basic tests for the surf library */
3 /* Copyright (c) 2004-2014. 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. */
14 #include "simgrid/sg_config.h"
15 #include "surf/surf.h"
16 #include "surf/surf_resource.h"
17 #include "surf/surfxml_parse.h" // for reset callback
20 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
21 "Messages specific for surf example");
23 const char *string_action(e_surf_action_state_t state);
24 const char *string_action(e_surf_action_state_t state)
27 case (SURF_ACTION_READY):
28 return "SURF_ACTION_READY";
29 case (SURF_ACTION_RUNNING):
30 return "SURF_ACTION_RUNNING";
31 case (SURF_ACTION_FAILED):
32 return "SURF_ACTION_FAILED";
33 case (SURF_ACTION_DONE):
34 return "SURF_ACTION_DONE";
35 case (SURF_ACTION_NOT_IN_THE_SYSTEM):
36 return "SURF_ACTION_NOT_IN_THE_SYSTEM";
38 return "INVALID STATE";
43 void test(char *platform);
44 void test(char *platform)
46 void *workstationA = NULL;
47 void *workstationB = NULL;
51 xbt_cfg_set_parse(_sg_cfg_set, "network/model:CM02");
52 xbt_cfg_set_parse(_sg_cfg_set, "cpu/model:Cas01");
53 parse_platform_file(platform);
55 /*********************** WORKSTATION ***********************************/
57 surf_workstation_resource_by_name("Cpu A");
59 surf_workstation_resource_by_name("Cpu B");
61 /* Let's check that those two processors exist */
62 XBT_DEBUG("%s : %p", surf_resource_name(workstationA), workstationA);
63 XBT_DEBUG("%s : %p", surf_resource_name(workstationB), workstationB);
65 /* Let's do something on it */
66 surf_workstation_execute(workstationA, 1000.0);
67 surf_workstation_execute(workstationB, 1000.0);
68 surf_workstation_sleep(workstationB, 7.32);
70 surf_workstation_model_communicate(surf_workstation_model, workstationA, workstationB, 150.0, -1.0);
72 surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */
74 surf_action_t action = NULL;
76 surf_model_t model = NULL;
79 now = surf_get_clock();
80 XBT_DEBUG("Next Event : %g", now);
82 xbt_dynar_foreach(model_list, iter, model) {
83 XBT_DEBUG("\t %s actions", surf_model_name(model));
84 while ((action = surf_model_extract_failed_action_set((surf_model_t)model))) {
85 XBT_DEBUG("\t * Failed : %p", action);
86 surf_action_unref(action);
88 while ((action = surf_model_extract_done_action_set((surf_model_t)model))) {
89 XBT_DEBUG("\t * Done : %p", action);
90 surf_action_unref(action);
92 if (surf_model_running_action_set_size((surf_model_t)model)) {
93 XBT_DEBUG("running %s", surf_model_name(model));
97 } while (running && surf_solve(-1.0) >= 0.0);
99 XBT_DEBUG("Simulation Terminated");
107 int main(int argc, char **argv)
109 surf_init(&argc, argv); /* Initialize some common structures */
111 fprintf(stderr, "Usage : %s platform.txt\n", argv[0]);