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. */
11 #include "surf/surf.h"
13 const char *string_action(e_surf_action_state_t state);
14 const char *string_action(e_surf_action_state_t state)
17 case (SURF_ACTION_READY):
18 return "SURF_ACTION_READY";
19 case (SURF_ACTION_RUNNING):
20 return "SURF_ACTION_RUNNING";
21 case (SURF_ACTION_FAILED):
22 return "SURF_ACTION_FAILED";
23 case (SURF_ACTION_DONE):
24 return "SURF_ACTION_DONE";
25 case (SURF_ACTION_NOT_IN_THE_SYSTEM):
26 return "SURF_ACTION_NOT_IN_THE_SYSTEM";
28 return "INVALID STATE";
40 surf_action_t actionA = NULL;
41 surf_action_t actionB = NULL;
42 surf_action_t commAB = NULL;
43 e_surf_action_state_t stateActionA;
44 e_surf_action_state_t stateActionB;
45 xbt_maxmin_float_t now = -1.0;
47 surf_cpu_resource_init("platform.txt"); /* Now it is possible to use CPUs */
48 surf_network_resource_init("platform.txt"); /* Now it is possible to use eth0 */
50 /*********************** CPU ***********************************/
51 printf("%p \n", surf_cpu_resource);
52 cpuA = surf_cpu_resource->common_public->name_service("Cpu A");
53 cpuB = surf_cpu_resource->common_public->name_service("Cpu B");
55 /* Let's check that those two processors exist */
56 printf("%s : %p\n", surf_cpu_resource->common_public->get_resource_name(cpuA), cpuA);
57 printf("%s : %p\n", surf_cpu_resource->common_public->get_resource_name(cpuB), cpuB);
59 /* Let's do something on it */
60 actionA = surf_cpu_resource->extension_public->execute(cpuA, 1000.0);
61 actionB = surf_cpu_resource->extension_public->execute(cpuB, 1000.0);
63 /* Use whatever calling style you want... */
64 stateActionA = surf_cpu_resource->common_public->action_get_state(actionA); /* When you know actionA resource type */
65 stateActionB = actionB->resource_type->common_public->action_get_state(actionB); /* If you're unsure about it's resource type */
67 /* And just look at the stat of these tasks */
68 printf("actionA : %p (%s)\n", actionA, string_action(stateActionA));
69 printf("actionB : %p (%s)\n", actionB, string_action(stateActionB));
71 /*********************** Network *******************************/
72 printf("%p \n", surf_network_resource);
73 cardA = surf_network_resource->common_public->name_service("Cpu A");
74 cardB = surf_network_resource->common_public->name_service("Cpu B");
76 /* Let's check that those two processors exist */
77 printf("%s : %p\n", surf_network_resource->common_public->get_resource_name(cardA), cardA);
78 printf("%s : %p\n", surf_network_resource->common_public->get_resource_name(cardB), cardB);
80 /* Let's do something on it */
81 commAB = surf_network_resource->extension_public->communicate(cardA, cardB, 150.0);
83 surf_solve(); /* Takes traces into account. Returns 0.0 */
85 surf_action_t action = NULL;
86 now = surf_get_clock();
87 printf("Next Event : " XBT_HEAP_FLOAT_T "\n", now);
88 printf("\t CPU actions\n");
89 while(action=xbt_swag_extract(surf_cpu_resource->common_public->states.failed_action_set)) {
90 printf("\t * Failed : %p\n", action);
91 action->resource_type->common_public->action_free(action);
93 while(action=xbt_swag_extract(surf_cpu_resource->common_public->states.done_action_set)) {
94 printf("\t * Done : %p\n", action);
95 action->resource_type->common_public->action_free(action);
97 printf("\t Network actions\n");
98 while(action=xbt_swag_extract(surf_network_resource->common_public->states.failed_action_set)) {
99 printf("\t * Failed : %p\n", action);
100 action->resource_type->common_public->action_free(action);
102 while(action=xbt_swag_extract(surf_network_resource->common_public->states.done_action_set)) {
103 printf("\t * Done : %p\n", action);
104 action->resource_type->common_public->action_free(action);
107 } while(surf_solve());
109 printf("Simulation Terminated\n");
115 int main(int argc, char **argv)
117 surf_init(&argc, argv); /* Initialize some common structures */