Generalize definition of SumExpr a little...Lets sum all elements of
[repair.git] / Repair / RepairInterpreter / test.cc
1 /* Defines interfaces for the applications and exports function calls that  
2    the applications should use instead of the standard ones. */
3
4 #include <stdlib.h>
5 #include <sys/time.h>
6 #include "classlist.h"
7 #include "model.h"
8 #include "dmodel.h"
9 extern "C" {
10 #include "test.h"
11 }
12 #include <stdio.h>
13 #include "element.h"
14 #include "Hashtable.h"
15 #include "tmap.h"
16
17
18
19 model * exportmodel;
20
21 void initializeanalysis() 
22 {
23   exportmodel=new model("testabstract", "testmodel", "testspace", "teststruct", "testconcrete", "testrange");
24 }
25
26
27
28
29 void doanalysis() 
30 {
31   struct timeval begin,end;
32   unsigned long t;
33   gettimeofday(&begin,NULL);
34   exportmodel->doabstraction();
35   exportmodel->getdomainrelation()->fixstuff();
36   bool found = exportmodel->docheck();
37   exportmodel->doconcrete();
38   gettimeofday(&end,NULL);
39   t=(end.tv_sec-begin.tv_sec)*1000000+end.tv_usec-begin.tv_usec;
40
41 #ifdef DEBUGMANYMESSAGES
42
43 #endif
44   exportmodel->getdomainrelation()->print();
45   printf("Time used for analysis(us): %ld\n",t);
46 }
47
48
49 /* This procedure invokes the tool.
50    If the model hasn't been initialized, it simply returns. 
51    If a bug was constraint violation was found, displays a message
52    and terminates the program. */
53 void doanalysisfordebugging(char* msg)
54
55   if (exportmodel == NULL) {
56     printf("Initialize tool first...\n");
57     return;
58   }
59
60   printf("%s\n", msg);
61   exportmodel->doabstraction(); 
62   
63   //exportmodel->getdomainrelation()->fixstuff();
64   //bool found = exportmodel->docheck();  
65   
66   bool found = exportmodel->getdomainrelation()->fixstuff() || exportmodel->docheck(); 
67
68 #ifdef DEBUGMANYMESSAGES
69   exportmodel->getdomainrelation()->print();
70 #endif
71
72   if (found)
73     exit(1);
74
75   resetanalysis();
76   printf("\n");  
77 }
78
79
80
81 // returns true if a violated constraint was found
82 unsigned long benchmark() 
83 {
84   struct timeval begin,end;
85   unsigned long t;
86   gettimeofday(&begin,NULL);
87   exportmodel->doabstraction();
88   exportmodel->getdomainrelation()->fixstuff();  
89   bool found = exportmodel->docheck();
90   exportmodel->doconcrete();
91   gettimeofday(&end,NULL);
92   t=(end.tv_sec-begin.tv_sec)*1000000+end.tv_usec-begin.tv_usec;
93   return t;
94 }
95
96
97 // insert errors that break the specs
98 void doanalysis2() 
99 {
100   struct timeval begin,end;
101   unsigned long t;
102   gettimeofday(&begin,NULL);
103   exportmodel->doabstraction();
104   exportmodel->getdomainrelation()->fixstuff();
105
106
107   exportmodel->breakspec();
108 #ifdef DEBUGMESSAGES
109   printf("\n\nSpecs BROKEN \n\n");
110   fflush(NULL);
111 #endif
112   
113   exportmodel->docheck();
114   exportmodel->doconcrete();
115   gettimeofday(&end,NULL);
116   t=(end.tv_sec-begin.tv_sec)*1000000+end.tv_usec-begin.tv_usec;
117
118   printf("Time used for analysis(us): %ld\n",t);
119 }
120
121
122 // insert errors that do not break the specs
123 void doanalysis3() 
124 {
125   struct timeval begin,end;
126   unsigned long t;
127   gettimeofday(&begin,NULL);
128   exportmodel->doabstraction();
129   exportmodel->getdomainrelation()->fixstuff();
130
131   exportmodel->inserterrors();
132
133 #ifdef DEBUGMESSAGES
134   printf("\n\nErrors INSERTED \n\n");
135   fflush(NULL);
136 #endif
137   
138   exportmodel->docheck();
139   exportmodel->doconcrete();
140   gettimeofday(&end,NULL);
141   t=(end.tv_sec-begin.tv_sec)*1000000+end.tv_usec-begin.tv_usec;
142
143   printf("Time used for analysis(us): %ld\n",t);
144 }
145
146
147
148 void resetanalysis() {
149   exportmodel->reset();
150 }
151
152 void addmapping(char *key, void * address, char *type) {
153   Hashtable *env=exportmodel->gethashtable();
154   env->put(key,new Element(address,exportmodel->getstructure(type)));//should be of badstruct
155 }
156
157 void addintmapping(char *key, int value) {
158   Hashtable *env=exportmodel->gethashtable();
159   env->put(key,new Element(value)); //should be of badstruct
160 }
161
162 void *ourcalloc(size_t nmemb, size_t size) {
163   typemap *tm=exportmodel->gettypemap();
164   void *oc=calloc(nmemb,size);
165   tm->allocate(oc,size*nmemb);
166   return oc;
167 }
168
169 void *ourmalloc(size_t size) {
170   typemap *tm=exportmodel->gettypemap();
171   void *oc=malloc(size);
172   tm->allocate(oc,size);
173   return oc;
174 }
175
176 void ourfree(void *ptr) {
177   typemap *tm=exportmodel->gettypemap();
178   tm->deallocate(ptr);
179   free(ptr);
180 }
181
182 void *ourrealloc(void *ptr, size_t size) {
183   typemap *tm=exportmodel->gettypemap();
184   void *orr=realloc(ptr,size);
185   if (size==0) {
186     tm->deallocate(ptr);
187     return orr;
188   }
189   if (orr==NULL) {
190     return orr;
191   }
192   tm->deallocate(ptr);
193   tm->allocate(ptr,size);
194 }
195
196 void alloc(void *ptr,int size) {
197   typemap *tm=exportmodel->gettypemap();
198   tm->allocate(ptr,size);
199 }
200
201 void dealloc(void *ptr) {
202   typemap *tm=exportmodel->gettypemap();
203   tm->deallocate(ptr);
204 }