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. */
15 #include "surf/surf.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,"Messages specific for surf example");
20 const char *string_action(e_surf_action_state_t state);
21 const char *string_action(e_surf_action_state_t 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";
35 return "INVALID STATE";
39 void test(char *platform);
40 void test(char *platform)
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;
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 */
58 /*********************** CPU ***********************************/
59 DEBUG1("%p \n", surf_cpu_model);
60 cpuA = surf_cpu_model->common_public->name_service("Cpu A");
61 cpuB = surf_cpu_model->common_public->name_service("Cpu B");
63 /* Let's check that those two processors exist */
65 surf_cpu_model->common_public->get_resource_name(cpuA), cpuA);
67 surf_cpu_model->common_public->get_resource_name(cpuB), cpuB);
69 /* Let's do something on it */
70 actionA = surf_cpu_model->extension_public->execute(cpuA, 1000.0);
71 actionB = surf_cpu_model->extension_public->execute(cpuB, 1000.0);
72 actionC = surf_cpu_model->extension_public->sleep(cpuB, 7.32);
74 /* Use whatever calling style you want... */
75 stateActionA = surf_cpu_model->common_public->action_get_state(actionA); /* When you know actionA model type */
76 stateActionB = actionB->model_type->common_public->action_get_state(actionB); /* If you're unsure about it's model type */
77 stateActionC = surf_cpu_model->common_public->action_get_state(actionC); /* When you know actionA model type */
79 /* And just look at the state of these tasks */
80 DEBUG2("actionA : %p (%s)\n", actionA, string_action(stateActionA));
81 DEBUG2("actionB : %p (%s)\n", actionB, string_action(stateActionB));
82 DEBUG2("actionC : %p (%s)\n", actionB, string_action(stateActionC));
84 /*********************** Network *******************************/
85 DEBUG1("%p \n", surf_network_model);
86 cardA = surf_network_model->common_public->name_service("Cpu A");
87 cardB = surf_network_model->common_public->name_service("Cpu B");
89 /* Let's check that those two processors exist */
91 surf_network_model->common_public->get_resource_name(cardA),
94 surf_network_model->common_public->get_resource_name(cardB),
97 /* Let's do something on it */
99 surf_network_model->extension_public->communicate(cardA, cardB,
102 surf_solve(); /* Takes traces into account. Returns 0.0 */
104 surf_action_t action = NULL;
105 now = surf_get_clock();
106 DEBUG1("Next Event : " "%g" "\n", now);
107 DEBUG0("\t CPU actions\n");
109 xbt_swag_extract(surf_cpu_model->common_public->states.
110 failed_action_set))) {
111 DEBUG1("\t * Failed : %p\n", action);
112 action->model_type->common_public->action_free(action);
115 xbt_swag_extract(surf_cpu_model->common_public->states.
117 DEBUG1("\t * Done : %p\n", action);
118 action->model_type->common_public->action_free(action);
120 DEBUG0("\t Network actions\n");
122 xbt_swag_extract(surf_network_model->common_public->states.
123 failed_action_set))) {
124 DEBUG1("\t * Failed : %p\n", action);
125 action->model_type->common_public->action_free(action);
128 xbt_swag_extract(surf_network_model->common_public->states.
130 DEBUG1("\t * Done : %p\n", action);
131 action->model_type->common_public->action_free(action);
134 } while (surf_solve()>=0.0);
136 DEBUG0("Simulation Terminated\n");
143 int main(int argc, char **argv)
145 surf_init(&argc, argv); /* Initialize some common structures */
147 fprintf(stderr,"Usage : %s platform.txt\n",argv[0]);