1 /* A few basic tests for the surf library */
3 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. 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. */
13 #include "surf/surf.h"
14 #include "surf/surfxml_parse.h" // for reset callback
17 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
18 "Messages specific for surf example");
20 const char *string_action(e_surf_action_state_t state);
21 const char *string_action(e_surf_action_state_t state)
24 case (SURF_ACTION_READY):
25 return "SURF_ACTION_READY";
26 case (SURF_ACTION_RUNNING):
27 return "SURF_ACTION_RUNNING";
28 case (SURF_ACTION_FAILED):
29 return "SURF_ACTION_FAILED";
30 case (SURF_ACTION_DONE):
31 return "SURF_ACTION_DONE";
32 case (SURF_ACTION_NOT_IN_THE_SYSTEM):
33 return "SURF_ACTION_NOT_IN_THE_SYSTEM";
35 return "INVALID STATE";
40 void test(char *platform);
41 void test(char *platform)
43 void *workstationA = NULL;
44 void *workstationB = NULL;
49 find_model_description(surf_workstation_model_description, "CLM03");
50 surf_parse_reset_callbacks();
51 surf_workstation_model_description[workstation_id].
52 model_init_preparse(platform);
53 parse_platform_file(platform);
54 if (surf_workstation_model_description[workstation_id].
56 surf_workstation_model_description[workstation_id].
57 model_init_postparse();
59 /*********************** WORKSTATION ***********************************/
61 surf_workstation_resource_by_name("Cpu A");
63 surf_workstation_resource_by_name("Cpu B");
65 /* Let's check that those two processors exist */
66 XBT_DEBUG("%s : %p", surf_resource_name(workstationA), workstationA);
67 XBT_DEBUG("%s : %p", surf_resource_name(workstationB), workstationB);
69 /* Let's do something on it */
70 surf_workstation_model->extension.workstation.execute(workstationA, 1000.0);
71 surf_workstation_model->extension.workstation.execute(workstationB, 1000.0);
72 surf_workstation_model->extension.workstation.sleep(workstationB, 7.32);
74 surf_workstation_model->extension.workstation.
75 communicate(workstationA, workstationB, 150.0, -1.0);
77 surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */
79 surf_action_t action = NULL;
81 surf_model_t model = NULL;
84 now = surf_get_clock();
85 XBT_DEBUG("Next Event : %g", now);
87 xbt_dynar_foreach(model_list, iter, model) {
88 XBT_DEBUG("\t %s actions", model->name);
89 while ((action = xbt_swag_extract(model->states.failed_action_set))) {
90 XBT_DEBUG("\t * Failed : %p", action);
91 model->action_unref(action);
93 while ((action = xbt_swag_extract(model->states.done_action_set))) {
94 XBT_DEBUG("\t * Done : %p", action);
95 model->action_unref(action);
97 if (xbt_swag_size(model->states.running_action_set)) {
98 XBT_DEBUG("running %s", model->name);
102 } while (running && surf_solve(-1.0) >= 0.0);
104 XBT_DEBUG("Simulation Terminated");
112 int main(int argc, char **argv)
114 surf_init(&argc, argv); /* Initialize some common structures */
116 fprintf(stderr, "Usage : %s platform.txt\n", argv[0]);