Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
no more printf (using DEBUG)
[simgrid.git] / testsuite / surf / surf_usage2.c
1 /*      $Id$     */
2
3 /* A few basic tests for the surf library                                   */
4
5 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
6
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. */
9
10 #include <stdio.h>
11 #include "surf/surf.h"
12
13 #include "xbt/log.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
15
16 const char *string_action(e_surf_action_state_t state);
17 const char *string_action(e_surf_action_state_t state)
18 {
19   switch (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";
30   default:
31     return "INVALID STATE";
32   }
33 }
34
35
36 void test(char *platform);
37 void test(char *platform)
38 {
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;
45   e_surf_action_state_t stateActionA;
46   e_surf_action_state_t stateActionB;
47   e_surf_action_state_t stateActionC;
48   double now = -1.0;
49
50   surf_workstation_resource_init_CLM03(platform);
51
52   /*********************** WORKSTATION ***********************************/
53   workstationA =
54       surf_workstation_resource->common_public->name_service("Cpu A");
55   workstationB =
56       surf_workstation_resource->common_public->name_service("Cpu B");
57
58   /* Let's check that those two processors exist */
59   DEBUG2("%s : %p\n",
60          surf_workstation_resource->common_public->
61          get_resource_name(workstationA), workstationA);
62   DEBUG2("%s : %p\n",
63          surf_workstation_resource->common_public->
64          get_resource_name(workstationB), workstationB);
65
66   /* Let's do something on it */
67   actionA =
68       surf_workstation_resource->extension_public->execute(workstationA,
69                                                            1000.0);
70   actionB =
71       surf_workstation_resource->extension_public->execute(workstationB,
72                                                            1000.0);
73   actionC =
74       surf_workstation_resource->extension_public->sleep(workstationB,
75                                                          7.32);
76
77   commAB =
78       surf_workstation_resource->extension_public->
79       communicate(workstationA, workstationB, 150.0, -1.0);
80
81   surf_solve();                 /* Takes traces into account. Returns 0.0 */
82   do {
83     surf_action_t action = NULL;
84     int i;
85     surf_resource_t resource = NULL;
86
87     now = surf_get_clock();
88     DEBUG1("Next Event : " "%lg" "\n", now);
89
90     xbt_dynar_foreach(resource_list, i, resource) {
91       DEBUG1("\t %s actions\n", resource->common_public->name);
92       while ((action =
93              xbt_swag_extract(resource->common_public->states.
94                               failed_action_set))) {
95         DEBUG1("\t * Failed : %p\n", action);
96         resource->common_public->action_free(action);
97       }
98       while ((action =
99              xbt_swag_extract(resource->common_public->states.
100                               done_action_set))) {
101         DEBUG1("\t * Done : %p\n", action);
102         resource->common_public->action_free(action);
103       }
104     }
105   } while (surf_solve()>=0.0);
106
107   DEBUG0("Simulation Terminated\n");
108
109   surf_finalize();
110 }
111
112 int main(int argc, char **argv)
113 {
114   surf_init(&argc, argv);       /* Initialize some common structures */
115   if(argc==1) {
116      fprintf(stderr,"Usage : %s platform.txt\n",argv[0]);
117      return 1;
118   }
119   test(argv[1]);
120   return 0;
121 }