Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : tests for snapshot comparison
[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   MC_UNSET_RAW_MEM;
25
26   int res = snapshot_compare(snapshot1, snapshot2);
27   xbt_assert(res == 0);
28
29   fprintf(stderr, "\n**************** END TEST 1 ****************\n");
30
31   MC_SET_RAW_MEM;
32   
33   MC_free_snapshot(snapshot1);
34   MC_free_snapshot(snapshot2);
35
36   MC_UNSET_RAW_MEM;
37 }
38
39 static void test2()
40 {
41
42   fprintf(stderr, "\n**************** TEST 2 ****************\n\n");
43
44   MC_SET_RAW_MEM;
45
46   /* Save first snapshot */
47   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
48   MC_take_snapshot_liveness(snapshot1);
49
50   MC_UNSET_RAW_MEM;
51
52   char* 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   int res = snapshot_compare(snapshot1, snapshot2);
61   xbt_assert(res != 0);
62
63   MC_UNSET_RAW_MEM;
64   
65   fprintf(stderr, "\n**************** END TEST 2 ****************\n");
66
67   free(t);
68
69   MC_SET_RAW_MEM;
70
71   MC_free_snapshot(snapshot1);
72   MC_free_snapshot(snapshot2);
73
74   MC_UNSET_RAW_MEM;
75 }
76
77 static void test3()
78 {
79
80   fprintf(stderr, "\n**************** TEST 3 ****************\n\n");
81
82   MC_SET_RAW_MEM;
83
84   /* Save first snapshot */
85   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
86   MC_take_snapshot_liveness(snapshot1);
87
88   MC_UNSET_RAW_MEM;
89
90   char *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   int res = snapshot_compare(snapshot1, snapshot2);
100   xbt_assert(res == 0);
101   
102   MC_UNSET_RAW_MEM;
103   
104   fprintf(stderr, "\n**************** END TEST 3 ****************\n");
105
106   MC_SET_RAW_MEM;
107
108   MC_free_snapshot(snapshot1);
109   MC_free_snapshot(snapshot2);
110
111   MC_UNSET_RAW_MEM;
112 }
113
114 static void test4()
115 {
116
117   fprintf(stderr, "\n**************** TEST 4 ****************\n\n");
118
119   char *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   int res = snapshot_compare(snapshot1, snapshot2);
138   xbt_assert(res != 0);
139   
140   MC_UNSET_RAW_MEM;
141   
142   fprintf(stderr, "\n**************** END TEST 4 ****************\n");
143   
144   MC_SET_RAW_MEM;
145
146   MC_free_snapshot(snapshot1);
147   MC_free_snapshot(snapshot2);
148
149   MC_UNSET_RAW_MEM;
150 }
151
152
153 static void test5()
154 {
155
156   fprintf(stderr, "\n**************** TEST 5 ****************\n\n");
157
158   char *ptr1 = malloc(sizeof(char *));
159
160   MC_SET_RAW_MEM;
161
162   /* Save first snapshot */
163   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
164   MC_take_snapshot_liveness(snapshot1);
165
166   MC_UNSET_RAW_MEM;
167
168   *ptr1 = *ptr1 + 1;
169
170   MC_SET_RAW_MEM;
171
172   /* Save second snapshot */
173   mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
174   MC_take_snapshot_liveness(snapshot2);
175
176   int res = snapshot_compare(snapshot1, snapshot2);
177   xbt_assert(res != 0);
178   
179   MC_UNSET_RAW_MEM;
180   
181   fprintf(stderr, "\n**************** END TEST 5 ****************\n");
182
183   MC_SET_RAW_MEM;
184
185   MC_free_snapshot(snapshot1);
186   MC_free_snapshot(snapshot2);
187
188   MC_UNSET_RAW_MEM;
189 }
190
191 static void test6()
192 {
193
194   fprintf(stderr, "\n**************** TEST 6 ****************\n\n");
195
196   char *ptr1 = malloc(sizeof(char *));
197
198   MC_SET_RAW_MEM;
199
200   /* Save first snapshot */
201   mc_snapshot_t snapshot1 = xbt_new0(s_mc_snapshot_t, 1);
202   MC_take_snapshot_liveness(snapshot1);
203
204   MC_UNSET_RAW_MEM;
205
206   *ptr1 = *ptr1 + 1;
207   *ptr1 = *ptr1 - 1;
208
209   MC_SET_RAW_MEM;
210
211   /* Save second snapshot */
212   mc_snapshot_t snapshot2 = xbt_new0(s_mc_snapshot_t, 1);
213   MC_take_snapshot_liveness(snapshot2);
214
215   int res = snapshot_compare(snapshot1, snapshot2);
216   xbt_assert(res == 0);
217   
218   MC_UNSET_RAW_MEM;
219   
220   fprintf(stderr, "\n**************** END TEST 6 ****************\n");
221
222   MC_SET_RAW_MEM;
223
224   MC_free_snapshot(snapshot1);
225   MC_free_snapshot(snapshot2);
226
227   MC_UNSET_RAW_MEM;
228 }
229
230
231 void MC_test_snapshot_comparison(){
232
233   MC_memory_init();
234
235   MC_SET_RAW_MEM;
236   mc_snapshot_t initial = xbt_new0(s_mc_snapshot_t, 1);
237   MC_take_snapshot_liveness(initial); 
238   MC_UNSET_RAW_MEM;
239
240   test1();
241   
242   test2();
243   
244   MC_restore_snapshot(initial);
245   MC_UNSET_RAW_MEM;
246
247   test3();
248
249   MC_restore_snapshot(initial);
250   MC_UNSET_RAW_MEM;
251
252   test4();
253
254   MC_restore_snapshot(initial);
255   MC_UNSET_RAW_MEM;
256   
257   test5();
258
259   MC_restore_snapshot(initial);
260   MC_UNSET_RAW_MEM;
261   
262   test6();
263 }