Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the tests that my cleanups in the config variable broke
[simgrid.git] / testsuite / surf / surf_usage2.c
1 /* A few basic tests for the surf library                                   */
2
3 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8 #ifdef __BORLANDC__
9 #pragma hdrstop
10 #endif
11
12 #include <stdio.h>
13 #include "surf/surf.h"
14 #include "surf/surf_resource.h"
15 #include "surf/surfxml_parse.h" // for reset callback
16
17 #include "xbt/log.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
19                              "Messages specific for surf example");
20
21 const char *string_action(e_surf_action_state_t state);
22 const char *string_action(e_surf_action_state_t state)
23 {
24   switch (state) {
25   case (SURF_ACTION_READY):
26     return "SURF_ACTION_READY";
27   case (SURF_ACTION_RUNNING):
28     return "SURF_ACTION_RUNNING";
29   case (SURF_ACTION_FAILED):
30     return "SURF_ACTION_FAILED";
31   case (SURF_ACTION_DONE):
32     return "SURF_ACTION_DONE";
33   case (SURF_ACTION_NOT_IN_THE_SYSTEM):
34     return "SURF_ACTION_NOT_IN_THE_SYSTEM";
35   default:
36     return "INVALID STATE";
37   }
38 }
39
40
41 void test(char *platform);
42 void test(char *platform)
43 {
44   void *workstationA = NULL;
45   void *workstationB = NULL;
46   double now = -1.0;
47   int running;
48
49   xbt_cfg_set_parse(_surf_cfg_set, "network/model:CM02");
50   xbt_cfg_set_parse(_surf_cfg_set, "cpu/model:Cas01");
51   parse_platform_file(platform);
52
53   /*********************** WORKSTATION ***********************************/
54   workstationA =
55       surf_workstation_resource_by_name("Cpu A");
56   workstationB =
57       surf_workstation_resource_by_name("Cpu B");
58
59   /* Let's check that those two processors exist */
60   XBT_DEBUG("%s : %p", surf_resource_name(workstationA), workstationA);
61   XBT_DEBUG("%s : %p", surf_resource_name(workstationB), workstationB);
62
63   /* Let's do something on it */
64   surf_workstation_model->extension.workstation.execute(workstationA, 1000.0);
65   surf_workstation_model->extension.workstation.execute(workstationB, 1000.0);
66       surf_workstation_model->extension.workstation.sleep(workstationB, 7.32);
67
68   surf_workstation_model->extension.workstation.
69       communicate(workstationA, workstationB, 150.0, -1.0);
70
71   surf_solve(-1.0);                 /* Takes traces into account. Returns 0.0 */
72   do {
73     surf_action_t action = NULL;
74     unsigned int iter;
75     surf_model_t model = NULL;
76     running = 0;
77
78     now = surf_get_clock();
79     XBT_DEBUG("Next Event : %g", now);
80
81     xbt_dynar_foreach(model_list, iter, model) {
82       XBT_DEBUG("\t %s actions", model->name);
83       while ((action = xbt_swag_extract(model->states.failed_action_set))) {
84         XBT_DEBUG("\t * Failed : %p", action);
85         model->action_unref(action);
86       }
87       while ((action = xbt_swag_extract(model->states.done_action_set))) {
88         XBT_DEBUG("\t * Done : %p", action);
89         model->action_unref(action);
90       }
91       if (xbt_swag_size(model->states.running_action_set)) {
92         XBT_DEBUG("running %s", model->name);
93         running = 1;
94       }
95     }
96   } while (running && surf_solve(-1.0) >= 0.0);
97
98   XBT_DEBUG("Simulation Terminated");
99
100 }
101
102 #ifdef __BORLANDC__
103 #pragma argsused
104 #endif
105
106 int main(int argc, char **argv)
107 {
108   surf_init(&argc, argv);       /* Initialize some common structures */
109   if (argc == 1) {
110     fprintf(stderr, "Usage : %s platform.txt\n", argv[0]);
111     surf_exit();
112     return 1;
113   }
114   test(argv[1]);
115
116   surf_exit();
117   return 0;
118 }