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"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "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";
38 void test(char *platform);
39 void test(char *platform)
41 void *workstationA = NULL;
42 void *workstationB = NULL;
43 surf_action_t actionA = NULL;
44 surf_action_t actionB = NULL;
45 surf_action_t actionC = NULL;
46 surf_action_t commAB = NULL;
51 find_model_description(surf_workstation_model_description, "CLM03");
53 surf_workstation_model_description[workstation_id].model_init_preparse(platform);
54 parse_platform_file(platform);
55 if (surf_workstation_model_description[workstation_id].model_init_postparse)
56 surf_workstation_model_description[workstation_id].model_init_postparse();
58 /*********************** WORKSTATION ***********************************/
59 workstationA = surf_model_resource_by_name(surf_workstation_model,"Cpu A");
60 workstationB = surf_model_resource_by_name(surf_workstation_model,"Cpu B");
62 /* Let's check that those two processors exist */
63 DEBUG2("%s : %p", surf_resource_name(workstationA), workstationA);
64 DEBUG2("%s : %p", surf_resource_name(workstationB), workstationB);
66 /* Let's do something on it */
68 surf_workstation_model->extension.workstation.execute(workstationA, 1000.0);
70 surf_workstation_model->extension.workstation.execute(workstationB, 1000.0);
72 surf_workstation_model->extension.workstation.sleep(workstationB, 7.32);
75 surf_workstation_model->extension.workstation.communicate(workstationA,
79 surf_solve(); /* Takes traces into account. Returns 0.0 */
81 surf_action_t action = NULL;
83 surf_model_t model = NULL;
86 now = surf_get_clock();
87 DEBUG1("Next Event : %g", now);
89 xbt_dynar_foreach(model_list, iter, model) {
90 DEBUG1("\t %s actions", model->name);
92 xbt_swag_extract(model->states.failed_action_set))) {
93 DEBUG1("\t * Failed : %p", action);
94 model->action_unref(action);
97 xbt_swag_extract(model->states.done_action_set))) {
98 DEBUG1("\t * Done : %p", action);
99 model->action_unref(action);
101 if (xbt_swag_size(model->states.running_action_set)) {
102 DEBUG1("running %s", model->name);
106 } while (running && surf_solve() >= 0.0);
108 DEBUG0("Simulation Terminated");
116 int main(int argc, char **argv)
118 surf_init(&argc, argv); /* Initialize some common structures */
120 fprintf(stderr, "Usage : %s platform.txt\n", argv[0]);