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. */
11 #include "surf/surf.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
16 const char *string_action(e_surf_action_state_t state);
17 const char *string_action(e_surf_action_state_t state)
20 case (SURF_ACTION_READY):
21 return "SURF_ACTION_READY";
22 case (SURF_ACTION_RUNNING):
23 return "SURF_ACTION_RUNNING";
24 case (SURF_ACTION_FAILED):
25 return "SURF_ACTION_FAILED";
26 case (SURF_ACTION_DONE):
27 return "SURF_ACTION_DONE";
28 case (SURF_ACTION_NOT_IN_THE_SYSTEM):
29 return "SURF_ACTION_NOT_IN_THE_SYSTEM";
31 return "INVALID STATE";
36 void test(char *platform);
37 void test(char *platform)
39 void *workstationA = NULL;
40 void *workstationB = NULL;
41 surf_action_t actionA = NULL;
42 surf_action_t actionB = NULL;
43 surf_action_t actionC = NULL;
44 surf_action_t commAB = NULL;
47 surf_workstation_resource_init_CLM03(platform);
49 /*********************** WORKSTATION ***********************************/
51 surf_workstation_resource->common_public->name_service("Cpu A");
53 surf_workstation_resource->common_public->name_service("Cpu B");
55 /* Let's check that those two processors exist */
57 surf_workstation_resource->common_public->
58 get_resource_name(workstationA), workstationA);
60 surf_workstation_resource->common_public->
61 get_resource_name(workstationB), workstationB);
63 /* Let's do something on it */
65 surf_workstation_resource->extension_public->execute(workstationA,
68 surf_workstation_resource->extension_public->execute(workstationB,
71 surf_workstation_resource->extension_public->sleep(workstationB,
75 surf_workstation_resource->extension_public->
76 communicate(workstationA, workstationB, 150.0, -1.0);
78 surf_solve(); /* Takes traces into account. Returns 0.0 */
80 surf_action_t action = NULL;
82 surf_resource_t resource = NULL;
84 now = surf_get_clock();
85 DEBUG1("Next Event : " "%g" "\n", now);
87 xbt_dynar_foreach(resource_list, i, resource) {
88 DEBUG1("\t %s actions\n", resource->common_public->name);
90 xbt_swag_extract(resource->common_public->states.
91 failed_action_set))) {
92 DEBUG1("\t * Failed : %p\n", action);
93 resource->common_public->action_free(action);
96 xbt_swag_extract(resource->common_public->states.
98 DEBUG1("\t * Done : %p\n", action);
99 resource->common_public->action_free(action);
102 } while (surf_solve()>=0.0);
104 DEBUG0("Simulation Terminated\n");
108 int main(int argc, char **argv)
110 surf_init(&argc, argv); /* Initialize some common structures */
112 fprintf(stderr,"Usage : %s platform.txt\n",argv[0]);