Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Help running properly after last XML parsing/DTD changes.
[simgrid.git] / testsuite / surf / surf_usage.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 #ifdef __BORLANDC__
11 #pragma hdrstop
12 #endif
13
14 #include <stdio.h>
15 #include "surf/surf.h"
16
17 #include "xbt/log.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
19
20 const char *string_action(e_surf_action_state_t state);
21 const char *string_action(e_surf_action_state_t state)
22 {
23   switch (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";
34   default:
35     return "INVALID STATE";
36   }
37 }
38
39 void test(char *platform);
40 void test(char *platform)
41 {
42   void *cpuA = NULL;
43   void *cpuB = NULL;
44   void *cardA = NULL;
45   void *cardB = NULL;
46   surf_action_t actionA = NULL;
47   surf_action_t actionB = NULL;
48   surf_action_t actionC = NULL;
49   surf_action_t commAB = NULL;
50   e_surf_action_state_t stateActionA;
51   e_surf_action_state_t stateActionB;
52   e_surf_action_state_t stateActionC;
53   double now = -1.0;
54
55   surf_cpu_model_init_Cas01(platform);  /* Now it is possible to use CPUs */
56   surf_network_model_init_CM02(platform);       /* Now it is possible to use eth0 */
57
58   parse_platform_file(platform);
59
60   /*********************** CPU ***********************************/
61   DEBUG1("%p \n", surf_cpu_model);
62   cpuA = surf_cpu_model->common_public->name_service("Cpu A");
63   cpuB = surf_cpu_model->common_public->name_service("Cpu B");
64
65   /* Let's check that those two processors exist */
66   DEBUG2("%s : %p\n",
67          surf_cpu_model->common_public->get_resource_name(cpuA), cpuA);
68   DEBUG2("%s : %p\n",
69          surf_cpu_model->common_public->get_resource_name(cpuB), cpuB);
70
71   /* Let's do something on it */
72   actionA = surf_cpu_model->extension_public->execute(cpuA, 1000.0);
73   actionB = surf_cpu_model->extension_public->execute(cpuB, 1000.0);
74   actionC = surf_cpu_model->extension_public->sleep(cpuB, 7.32);
75
76   /* Use whatever calling style you want... */
77   stateActionA = surf_cpu_model->common_public->action_get_state(actionA);      /* When you know actionA model type */
78   stateActionB = actionB->model_type->common_public->action_get_state(actionB); /* If you're unsure about it's model type */
79   stateActionC = surf_cpu_model->common_public->action_get_state(actionC);      /* When you know actionA model type */
80
81   /* And just look at the state of these tasks */
82   DEBUG2("actionA : %p (%s)\n", actionA, string_action(stateActionA));
83   DEBUG2("actionB : %p (%s)\n", actionB, string_action(stateActionB));
84   DEBUG2("actionC : %p (%s)\n", actionB, string_action(stateActionC));
85
86   /*********************** Network *******************************/
87   DEBUG1("%p \n", surf_network_model);
88   cardA = surf_network_model->common_public->name_service("Cpu A");
89   cardB = surf_network_model->common_public->name_service("Cpu B");
90
91   /* Let's check that those two processors exist */
92   DEBUG2("%s : %p\n",
93          surf_network_model->common_public->get_resource_name(cardA),
94          cardA);
95   DEBUG2("%s : %p\n",
96          surf_network_model->common_public->get_resource_name(cardB),
97          cardB);
98
99   /* Let's do something on it */
100   commAB =
101       surf_network_model->extension_public->communicate(cardA, cardB,
102                                                            150.0,-1.0);
103
104   surf_solve();                 /* Takes traces into account. Returns 0.0 */
105   do {
106     surf_action_t action = NULL;
107     now = surf_get_clock();
108     DEBUG1("Next Event : " "%g" "\n", now);
109     DEBUG0("\t CPU actions\n");
110     while ((action =
111             xbt_swag_extract(surf_cpu_model->common_public->states.
112                              failed_action_set))) {
113       DEBUG1("\t * Failed : %p\n", action);
114       action->model_type->common_public->action_free(action);
115     }
116     while ((action =
117             xbt_swag_extract(surf_cpu_model->common_public->states.
118                              done_action_set))) {
119       DEBUG1("\t * Done : %p\n", action);
120       action->model_type->common_public->action_free(action);
121     }
122     DEBUG0("\t Network actions\n");
123     while ((action =
124             xbt_swag_extract(surf_network_model->common_public->states.
125                              failed_action_set))) {
126       DEBUG1("\t * Failed : %p\n", action);
127       action->model_type->common_public->action_free(action);
128     }
129     while ((action =
130             xbt_swag_extract(surf_network_model->common_public->states.
131                              done_action_set))) {
132       DEBUG1("\t * Done : %p\n", action);
133       action->model_type->common_public->action_free(action);
134     }
135
136   } while (surf_solve()>=0.0);
137
138   DEBUG0("Simulation Terminated\n");
139 }
140
141 #ifdef __BORLANDC__
142 #pragma argsused
143 #endif
144
145 int main(int argc, char **argv)
146 {
147   surf_init(&argc, argv);       /* Initialize some common structures */
148   if(argc==1) {
149      fprintf(stderr,"Usage : %s platform.xml\n",argv[0]);
150      return 1;
151   }
152   test(argv[1]);
153
154   surf_exit();
155   return 0;
156 }