Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
get rid of useless spaces and tabs
[simgrid.git] / teshsuite / simdag / network / test_reinit_costs.c
1 /* Computation tests                                                        */
2
3 /* Copyright (c) 2007, 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
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 #include "simdag/simdag.h"
13
14 /*
15  * This test checks if the reinitialization of
16  * surf works properly. 
17  * 1 test: empty task, reinit, empty task
18  * 2 test: comm cost task, reinit, empty task
19  * 
20  * output should be:
21  * 0
22  * 1.5
23  */
24
25 static SD_task_t create_empty_cost_root()
26 {
27   double no_cost[] = { 0.0 };
28   SD_task_t root;
29
30   root = SD_task_create("Root", NULL, 1.0);
31   SD_task_schedule(root, 1, SD_workstation_get_list(), no_cost, no_cost,
32                    -1.0);
33
34   return root;
35 }
36
37 static void zero_cost_test(int *argc, char *argv[])
38 {
39   double time;
40   SD_task_t task;
41   xbt_dynar_t ret;
42
43   SD_init(argc, argv);
44   SD_create_environment(argv[1]);
45
46   task = create_empty_cost_root();
47   ret = SD_simulate(-1.0);
48   xbt_dynar_free(&ret);
49   SD_task_destroy(task);
50
51   SD_application_reinit();
52
53   task = create_empty_cost_root();
54   ret = SD_simulate(-1.0);
55   xbt_dynar_free(&ret);
56   SD_task_destroy(task);
57
58   ret = SD_simulate(-1.0);
59   xbt_dynar_free(&ret);
60
61   time = SD_get_clock();
62   printf("%g\n", time);
63   fflush(stdout);
64
65   SD_exit();
66 }
67
68 static SD_task_t create_root_with_costs()
69 {
70   double comp_cost[] = { 0.0, 0.0 };
71   double comm_cost[] = { 0.0, 1.0, 0.0, 0.0 };
72   SD_task_t root;
73
74   root = SD_task_create("Root", NULL, 1.0);
75   SD_task_schedule(root, 2, SD_workstation_get_list(), comp_cost,
76                    comm_cost, -1.0);
77
78   return root;
79 }
80
81 static void zero_cost_test2(int *argc, char *argv[])
82 {
83   double time;
84   SD_task_t task;
85   xbt_dynar_t ret;
86
87   SD_init(argc, argv);
88   SD_create_environment(argv[1]);
89
90   task = create_root_with_costs();
91   ret = SD_simulate(-1.0);
92   xbt_dynar_free(&ret);
93   SD_task_destroy(task);
94
95   SD_application_reinit();
96
97   task = create_empty_cost_root();
98   ret =  SD_simulate(-1.0);
99   xbt_dynar_free(&ret);
100   SD_task_destroy(task);
101
102   ret = SD_simulate(-1.0);
103   xbt_dynar_free(&ret);
104
105   time = SD_get_clock();
106   printf("%g\n", time);
107   fflush(stdout);
108
109   SD_exit();
110 }
111
112 int main(int argc, char **argv)
113 {
114
115   zero_cost_test(&argc, argv);
116
117   zero_cost_test2(&argc, argv);
118
119   return 0;
120 }