Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : forget to remove unused variables
[simgrid.git] / src / mc / test / compare_snapshot.c
1 #include "../mc_private.h"
2
3 static void test1(void);
4 static void test2(void);
5 static void test2(void);
6 static void test4(void);
7 static void test5(void);
8 static void test6(void);
9
10 static void test1()
11 {
12
13   fprintf(stderr, "\n**************** TEST 1 ****************\n\n");
14   MC_SET_RAW_MEM;
15
16   /* Save first snapshot */
17   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
18   MC_take_snapshot_liveness(snapshot1);
19
20   /* Save second snapshot */
21   mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
22   MC_take_snapshot_liveness(snapshot2);
23
24   xbt_assert(snapshot_compare(snapshot1, snapshot2) == 0);
25
26   MC_UNSET_RAW_MEM;
27
28   fprintf(stderr, "\n**************** END TEST 1 ****************\n");
29
30   MC_SET_RAW_MEM;
31   
32   MC_free_snapshot(snapshot1);
33   MC_free_snapshot(snapshot2);
34
35   MC_UNSET_RAW_MEM;
36 }
37
38 static void test2()
39 {
40
41   fprintf(stderr, "\n**************** TEST 2 ****************\n\n");
42
43   MC_SET_RAW_MEM;
44
45   /* Save first snapshot */
46   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
47   MC_take_snapshot_liveness(snapshot1);
48
49   MC_UNSET_RAW_MEM;
50
51   char* t = malloc(50);
52   t = strdup("toto");
53  
54   MC_SET_RAW_MEM;
55
56   /* Save second snapshot */
57   mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
58   MC_take_snapshot_liveness(snapshot2);
59
60   xbt_assert(snapshot_compare(snapshot1, snapshot2) != 0);
61
62   MC_UNSET_RAW_MEM;
63   
64   fprintf(stderr, "\n**************** END TEST 2 ****************\n");
65
66   free(t);
67
68   MC_SET_RAW_MEM;
69
70   MC_free_snapshot(snapshot1);
71   MC_free_snapshot(snapshot2);
72
73   MC_UNSET_RAW_MEM;
74 }
75
76 static void test3()
77 {
78
79   fprintf(stderr, "\n**************** TEST 3 ****************\n\n");
80
81   MC_SET_RAW_MEM;
82
83   /* Save first snapshot */
84   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
85   MC_take_snapshot_liveness(snapshot1);
86
87   MC_UNSET_RAW_MEM;
88
89   char *t = malloc(5);
90   t = strdup("toto");
91   free(t);
92
93   MC_SET_RAW_MEM;
94
95   /* Save second snapshot */
96   mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
97   MC_take_snapshot_liveness(snapshot2);
98
99   xbt_assert(snapshot_compare(snapshot1, snapshot2) == 0);
100   
101   MC_UNSET_RAW_MEM;
102   
103   fprintf(stderr, "\n**************** END TEST 3 ****************\n");
104
105   MC_SET_RAW_MEM;
106
107   MC_free_snapshot(snapshot1);
108   MC_free_snapshot(snapshot2);
109
110   MC_UNSET_RAW_MEM;
111 }
112
113 static void test4()
114 {
115
116   fprintf(stderr, "\n**************** TEST 4 ****************\n\n");
117
118   char *t = malloc(5);
119   t = strdup("toto");
120
121   MC_SET_RAW_MEM;
122
123   /* Save first snapshot */
124   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
125   MC_take_snapshot_liveness(snapshot1);
126
127   MC_UNSET_RAW_MEM;
128
129   free(t);
130
131   MC_SET_RAW_MEM;
132
133   /* Save second snapshot */
134   mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
135   MC_take_snapshot_liveness(snapshot2);
136
137   xbt_assert(snapshot_compare(snapshot1, snapshot2) != 0);
138   
139   MC_UNSET_RAW_MEM;
140   
141   fprintf(stderr, "\n**************** END TEST 4 ****************\n");
142   
143   MC_SET_RAW_MEM;
144
145   MC_free_snapshot(snapshot1);
146   MC_free_snapshot(snapshot2);
147
148   MC_UNSET_RAW_MEM;
149 }
150
151
152 static void test5()
153 {
154
155   fprintf(stderr, "\n**************** TEST 5 ****************\n\n");
156
157   char *ptr1 = malloc(sizeof(char *));
158
159   MC_SET_RAW_MEM;
160
161   /* Save first snapshot */
162   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
163   MC_take_snapshot_liveness(snapshot1);
164
165   MC_UNSET_RAW_MEM;
166
167   *ptr1 = *ptr1 + 1;
168
169   MC_SET_RAW_MEM;
170
171   /* Save second snapshot */
172   mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
173   MC_take_snapshot_liveness(snapshot2);
174
175   xbt_assert(snapshot_compare(snapshot1, snapshot2) != 0);
176   
177   MC_UNSET_RAW_MEM;
178   
179   fprintf(stderr, "\n**************** END TEST 5 ****************\n");
180
181   MC_SET_RAW_MEM;
182
183   MC_free_snapshot(snapshot1);
184   MC_free_snapshot(snapshot2);
185
186   MC_UNSET_RAW_MEM;
187 }
188
189 static void test6()
190 {
191
192   fprintf(stderr, "\n**************** TEST 6 ****************\n\n");
193
194   char *ptr1 = malloc(sizeof(char *));
195
196   MC_SET_RAW_MEM;
197
198   /* Save first snapshot */
199   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
200   MC_take_snapshot_liveness(snapshot1);
201
202   MC_UNSET_RAW_MEM;
203
204   *ptr1 = *ptr1 + 1;
205   *ptr1 = *ptr1 - 1;
206
207   MC_SET_RAW_MEM;
208
209   /* Save second snapshot */
210   mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
211   MC_take_snapshot_liveness(snapshot2);
212
213   xbt_assert(snapshot_compare(snapshot1, snapshot2) == 0);
214   
215   MC_UNSET_RAW_MEM;
216   
217   fprintf(stderr, "\n**************** END TEST 6 ****************\n");
218
219   MC_SET_RAW_MEM;
220
221   MC_free_snapshot(snapshot1);
222   MC_free_snapshot(snapshot2);
223
224   MC_UNSET_RAW_MEM;
225 }
226
227
228 void MC_test_snapshot_comparison(){
229
230   MC_memory_init();
231
232   MC_SET_RAW_MEM;
233   mc_snapshot_t initial = xbt_new0(s_mc_snapshot_t, 1);
234   MC_take_snapshot_liveness(initial); 
235   MC_UNSET_RAW_MEM;
236
237   /* Get .plt section (start and end addresses) for data libsimgrid comparison */
238   get_plt_section();
239
240   test1();
241
242   MC_restore_snapshot(initial);
243   MC_UNSET_RAW_MEM;
244   
245   test2();
246   
247   MC_restore_snapshot(initial);
248   MC_UNSET_RAW_MEM;
249
250   test3();
251
252   MC_restore_snapshot(initial);
253   MC_UNSET_RAW_MEM;
254
255   test4();
256
257   MC_restore_snapshot(initial);
258   MC_UNSET_RAW_MEM;
259   
260   test5();
261
262   MC_restore_snapshot(initial);
263   MC_UNSET_RAW_MEM;
264   
265   test6();
266
267   MC_restore_snapshot(initial);
268   MC_UNSET_RAW_MEM;
269 }