1 /* A few basic tests for the surf library */
3 /* Authors: Arnaud Legrand */
5 /* This program is free software; you can redistribute it and/or modify it
6 under the terms of the license (GNU LGPL) which comes with this package. */
11 const char *string_action(e_surf_action_state_t state);
12 const char *string_action(e_surf_action_state_t state)
15 case (SURF_ACTION_READY):
16 return "SURF_ACTION_READY";
17 case (SURF_ACTION_RUNNING):
18 return "SURF_ACTION_RUNNING";
19 case (SURF_ACTION_FAILED):
20 return "SURF_ACTION_FAILED";
21 case (SURF_ACTION_DONE):
22 return "SURF_ACTION_DONE";
23 case (SURF_ACTION_NOT_IN_THE_SYSTEM):
24 return "SURF_ACTION_NOT_IN_THE_SYSTEM";
26 return "INVALID STATE";
38 surf_action_t actionA = NULL;
39 surf_action_t actionB = NULL;
40 surf_action_t commAB = NULL;
41 e_surf_action_state_t stateActionA;
42 e_surf_action_state_t stateActionB;
43 xbt_maxmin_float_t now = -1.0;
45 surf_init(); /* Initialize some common structures */
46 surf_cpu_resource_init("platform.txt"); /* Now it is possible to use CPUs */
47 surf_network_resource_init("platform.txt"); /* Now it is possible to use eth0 */
49 /*********************** CPU ***********************************/
50 printf("%p \n", surf_cpu_resource);
51 cpuA = surf_cpu_resource->common_public->name_service("Cpu A");
52 cpuB = surf_cpu_resource->common_public->name_service("Cpu B");
54 /* Let's check that those two processors exist */
55 printf("%s : %p\n", surf_cpu_resource->common_public->get_resource_name(cpuA), cpuA);
56 printf("%s : %p\n", surf_cpu_resource->common_public->get_resource_name(cpuB), cpuB);
58 /* Let's do something on it */
59 actionA = surf_cpu_resource->extension_public->execute(cpuA, 1000.0);
60 actionB = surf_cpu_resource->extension_public->execute(cpuB, 1000.0);
62 /* Use whatever calling style you want... */
63 stateActionA = surf_cpu_resource->common_public->action_get_state(actionA); /* When you know actionA resource type */
64 stateActionB = actionB->resource_type->common_public->action_get_state(actionB); /* If you're unsure about it's resource type */
66 /* And just look at the stat of these tasks */
67 printf("actionA : %p (%s)\n", actionA, string_action(stateActionA));
68 printf("actionB : %p (%s)\n", actionB, string_action(stateActionB));
70 /*********************** Network *******************************/
71 printf("%p \n", surf_network_resource);
72 cardA = surf_network_resource->common_public->name_service("Cpu A");
73 cardB = surf_network_resource->common_public->name_service("Cpu B");
75 /* Let's check that those two processors exist */
76 printf("%s : %p\n", surf_network_resource->common_public->get_resource_name(cardA), cardA);
77 printf("%s : %p\n", surf_network_resource->common_public->get_resource_name(cardB), cardB);
79 /* Let's do something on it */
80 commAB = surf_network_rescpource->extension_public->communicate(cardA, cardB, 132.0);
82 surf_solve(); /* Takes traces into account. Returns 0.0 */
84 surf_action_t action = NULL;
85 now = surf_get_clock();
86 printf("Next Event : " XBT_HEAP_FLOAT_T "\n", now);
87 printf("\t CPU actions\n");
88 while(action=xbt_swag_extract(surf_cpu_resource->common_public->states.failed_action_set)) {
89 printf("\t * Failed : %p\n", action);
90 action->resource_type->common_public->action_free(action);
92 while(action=xbt_swag_extract(surf_cpu_resource->common_public->states.done_action_set)) {
93 printf("\t * Done : %p\n", action);
94 action->resource_type->common_public->action_free(action);
96 printf("\t Network actions\n");
97 while(action=xbt_swag_extract(surf_network_resource->common_public->states.failed_action_set)) {
98 printf("\t * Failed : %p\n", action);
99 action->resource_type->common_public->action_free(action);
101 while(action=xbt_swag_extract(surf_network_resource->common_public->states.done_action_set)) {
102 printf("\t * Done : %p\n", action);
103 action->resource_type->common_public->action_free(action);
106 } while(surf_solve());
108 printf("Simulation Terminated\n");
114 int main(int argc, char **argv)