Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : process can be NULL
[simgrid.git] / src / mc / test / heap_comparison.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 ****************\nNo modification (successive snapshot)\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 ****************\nMalloc after first snapshot\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 ****************\nMalloc and free after first snapshot\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 ****************\nMalloc before first snapshot and free after first snapshot\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 ****************\nMalloc before first snapshot and increment pointer after first snapshot\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 ****************\nMalloc before first snapshot and increment then decrement pointer after first snapshot\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_heap_comparison(){
229
230   MC_memory_init();
231
232   MC_SET_RAW_MEM;
233
234   mc_snapshot_t initial = xbt_new0(s_mc_snapshot_t, 1);
235   MC_take_snapshot_liveness(initial); 
236
237   MC_UNSET_RAW_MEM;
238
239   /* Get .plt section (start and end addresses) for data libsimgrid and data program comparison */
240   get_libsimgrid_plt_section();
241   get_binary_plt_section();
242
243   test1();
244
245   MC_restore_snapshot(initial);
246   MC_UNSET_RAW_MEM;
247   
248   test2();
249   
250   MC_restore_snapshot(initial);
251   MC_UNSET_RAW_MEM;
252
253   test3();
254
255   MC_restore_snapshot(initial);
256   MC_UNSET_RAW_MEM;
257
258   test4();
259
260   MC_restore_snapshot(initial);
261   MC_UNSET_RAW_MEM;
262   
263   test5();
264
265   MC_restore_snapshot(initial);
266   MC_UNSET_RAW_MEM;
267   
268   test6();
269
270   MC_restore_snapshot(initial);
271   MC_UNSET_RAW_MEM;
272 }