3 /* A few basic tests for the surf library */
5 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
14 #include "surf/surf.h"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
19 const char *string_action(e_surf_action_state_t state);
20 const char *string_action(e_surf_action_state_t state)
23 case (SURF_ACTION_READY):
24 return "SURF_ACTION_READY";
25 case (SURF_ACTION_RUNNING):
26 return "SURF_ACTION_RUNNING";
27 case (SURF_ACTION_FAILED):
28 return "SURF_ACTION_FAILED";
29 case (SURF_ACTION_DONE):
30 return "SURF_ACTION_DONE";
31 case (SURF_ACTION_NOT_IN_THE_SYSTEM):
32 return "SURF_ACTION_NOT_IN_THE_SYSTEM";
34 return "INVALID STATE";
39 void test(char *platform);
40 void test(char *platform)
42 void *workstationA = NULL;
43 void *workstationB = NULL;
44 surf_action_t actionA = NULL;
45 surf_action_t actionB = NULL;
46 surf_action_t actionC = NULL;
47 surf_action_t commAB = NULL;
51 find_model_description(surf_workstation_model_description, "CLM03");
53 surf_workstation_model_description[workstation_id].model_init(platform);
54 parse_platform_file(platform);
55 if (surf_workstation_model_description[workstation_id].create_ws)
56 surf_workstation_model_description[workstation_id].create_ws();
58 /*********************** WORKSTATION ***********************************/
59 workstationA = surf_workstation_model->common_public->name_service("Cpu A");
60 workstationB = surf_workstation_model->common_public->name_service("Cpu B");
62 /* Let's check that those two processors exist */
64 surf_workstation_model->common_public->
65 get_resource_name(workstationA), workstationA);
67 surf_workstation_model->common_public->
68 get_resource_name(workstationB), workstationB);
70 /* Let's do something on it */
72 surf_workstation_model->extension_public->execute(workstationA, 1000.0);
74 surf_workstation_model->extension_public->execute(workstationB, 1000.0);
76 surf_workstation_model->extension_public->sleep(workstationB, 7.32);
79 surf_workstation_model->extension_public->communicate(workstationA,
83 surf_solve(); /* Takes traces into account. Returns 0.0 */
85 surf_action_t action = NULL;
87 surf_model_t model = NULL;
89 now = surf_get_clock();
90 DEBUG1("Next Event : %g", now);
92 xbt_dynar_foreach(model_list, iter, model) {
93 DEBUG1("\t %s actions", model->common_public->name);
95 xbt_swag_extract(model->common_public->states.
96 failed_action_set))) {
97 DEBUG1("\t * Failed : %p", action);
98 model->common_public->action_free(action);
101 xbt_swag_extract(model->common_public->states.
103 DEBUG1("\t * Done : %p", action);
104 model->common_public->action_free(action);
107 } while (surf_solve() >= 0.0);
109 DEBUG0("Simulation Terminated");
117 int main(int argc, char **argv)
119 surf_init(&argc, argv); /* Initialize some common structures */
121 fprintf(stderr, "Usage : %s platform.txt\n", argv[0]);