start of new file
[IRC.git] / Robust / src / Runtime / DSTM / interface / tests / testd-4.c
1 #include <pthread.h>
2 #include "dstm.h"
3
4 extern objstr_t *mainobjstore;
5 int classsize[]={sizeof(int),sizeof(char),sizeof(short), sizeof(void *)};
6
7 int main()
8 {
9         test1();
10 //      test2();
11 //      test3();
12 //      test4();
13 }
14
15 void init_obj(objheader_t *h, unsigned int oid, unsigned short type, \
16                 unsigned short version,\
17                 unsigned short rcount, char status) {
18         h->oid = oid;
19         h->type = type;
20         h->version = version;
21         h->rcount = rcount;
22         h->status |= status;
23         return;
24 }
25
26 //Test case to create objects and do nothing else
27 int test1() {
28         unsigned int val, mid;
29         unsigned int size;
30         transrecord_t *myTrans;
31         objheader_t *header;
32         pthread_t thread_Listen;
33         pthread_attr_t attr;
34
35         dstmInit();
36         pthread_attr_init(&attr);
37         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
38
39         //Create and Insert Oid 31
40         size = sizeof(objheader_t) + classsize[2] ;
41         header = (objheader_t *) objstrAlloc(mainobjstore, size);
42         init_obj(header, 31, 2, 1, 0, NEW);
43         mhashInsert(header->oid, header);
44         mid = iptoMid("128.195.175.69");
45         lhashInsert(header->oid, mid);
46
47         //Create and Insert Oid 32
48         size = sizeof(objheader_t) + classsize[1] ;
49         header = (objheader_t *) objstrAlloc(mainobjstore, size);
50         init_obj(header, 32, 1, 1, 0, NEW);
51         mhashInsert(header->oid, header);
52         mid = iptoMid("128.195.175.69");
53         lhashInsert(header->oid, mid);
54
55         //Create and Insert Oid 33
56         size = sizeof(objheader_t) + classsize[0] ;
57         header = (objheader_t *) objstrAlloc(mainobjstore, size);
58         init_obj(header, 33, 0, 1, 0, NEW);
59         mhashInsert(header->oid, header);
60         mid = iptoMid("128.195.175.69");
61         lhashInsert(header->oid, mid);
62
63         //Inserting into lhashtable into d-3.eecs
64         mid = iptoMid("128.200.9.29"); //d-3.eecs.uci.edu
65         lhashInsert(20, mid);
66         lhashInsert(21, mid);
67         lhashInsert(22, mid);
68
69         mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
70         //Inserting into lhashtable of demsky.eecs
71         lhashInsert(1, mid);
72         lhashInsert(2, mid);
73         lhashInsert(3, mid);
74         lhashInsert(4, mid);
75         
76         pthread_create(&thread_Listen, &attr, dstmListen, NULL);
77         //Check if machine demsky is up and running
78         checkServer(mid, "128.200.9.10");
79         mid = iptoMid("128.200.9.29");
80         //Check if machine d-3 is up and running
81         checkServer(mid, "128.200.9.29");
82
83         pthread_join(thread_Listen, NULL);
84
85         return 0;
86 }
87
88 //Read objects from remote and local machines ; NOTE objects are all available
89 int test2() {
90
91         unsigned int val, mid;
92         unsigned int size;
93         transrecord_t *myTrans;
94         objheader_t *header, *h1, *h2, *h3, *h4;
95         pthread_t thread_Listen;
96         pthread_attr_t attr;
97
98         dstmInit();
99         pthread_attr_init(&attr);
100         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
101
102         //Create and Insert Oid 31
103         size = sizeof(objheader_t) + classsize[2] ;
104         header = (objheader_t *) objstrAlloc(mainobjstore, size);
105         init_obj(header, 31, 2, 1, 0, NEW);
106         mhashInsert(header->oid, header);
107         mid = iptoMid("128.195.175.69");
108         lhashInsert(header->oid, mid);
109
110         //Create and Insert Oid 32
111         size = sizeof(objheader_t) + classsize[1] ;
112         header = (objheader_t *) objstrAlloc(mainobjstore, size);
113         init_obj(header, 32, 1, 1, 0, NEW);
114         mhashInsert(header->oid, header);
115         mid = iptoMid("128.195.175.69");
116         lhashInsert(header->oid, mid);
117
118         //Create and Insert Oid 33
119         size = sizeof(objheader_t) + classsize[0] ;
120         header = (objheader_t *) objstrAlloc(mainobjstore, size);
121         init_obj(header, 33, 0, 1, 0, NEW);
122         mhashInsert(header->oid, header);
123         mid = iptoMid("128.195.175.69");
124         lhashInsert(header->oid, mid);
125
126         //Inserting into lhashtable into d-3.eecs
127         mid = iptoMid("128.200.9.29"); //d-3.eecs.uci.edu
128         lhashInsert(20, mid);
129         lhashInsert(21, mid);
130         lhashInsert(22, mid);
131
132         mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
133         //Inserting into lhashtable of demsky.eecs
134         lhashInsert(1, mid);
135         lhashInsert(2, mid);
136         lhashInsert(3, mid);
137         lhashInsert(4, mid);
138         
139         pthread_create(&thread_Listen, &attr, dstmListen, NULL);
140
141         //Check if machine demsky is up and running
142         checkServer(mid, "128.200.9.10");
143         mid = iptoMid("128.200.9.29");
144         //Check if machine d-2 is up and running
145         checkServer(mid, "128.200.9.29");
146
147         // Start Transaction
148         myTrans = transStart();
149
150         //read object 1 (found on demksy)
151         if((h1 = transRead(myTrans, 1)) == NULL){
152                 printf("Object not found\n");
153         }
154         
155         //read object 33 (found on local)
156         if((h2 = transRead(myTrans, 33)) == NULL){
157                 printf("Object not found\n");
158         }
159
160         //read object 21 (found on d-3)
161         if((h3 = transRead(myTrans, 21)) == NULL){
162                 printf("Object not found\n");
163         }
164
165         //read object 32 (found on local)
166         if((h4 = transRead(myTrans, 32)) == NULL){
167                 printf("Object not found\n");
168         }
169
170         pthread_join(thread_Listen, NULL);
171
172         return 0;
173 }
174
175 int test3() {
176
177         unsigned int val, mid;
178         unsigned int size;
179         transrecord_t *myTrans;
180         objheader_t *header, *h1, *h2, *h3;
181         pthread_t thread_Listen;
182         pthread_attr_t attr;
183
184         dstmInit();
185         pthread_attr_init(&attr);
186         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
187
188         //Create and Insert Oid 31
189         size = sizeof(objheader_t) + classsize[2] ;
190         header = (objheader_t *) objstrAlloc(mainobjstore, size);
191         init_obj(header, 31, 2, 1, 0, NEW);
192         mhashInsert(header->oid, header);
193         mid = iptoMid("128.195.175.69");
194         lhashInsert(header->oid, mid);
195
196         //Create and Insert Oid 32
197         size = sizeof(objheader_t) + classsize[1] ;
198         header = (objheader_t *) objstrAlloc(mainobjstore, size);
199         init_obj(header, 32, 1, 1, 0, NEW);
200         mhashInsert(header->oid, header);
201         mid = iptoMid("128.195.175.69");
202         lhashInsert(header->oid, mid);
203
204         //Create and Insert Oid 33
205         size = sizeof(objheader_t) + classsize[0] ;
206         header = (objheader_t *) objstrAlloc(mainobjstore, size);
207         init_obj(header, 33, 0, 1, 0, NEW);
208         mhashInsert(header->oid, header);
209         mid = iptoMid("128.195.175.69");
210         lhashInsert(header->oid, mid);
211
212         //Inserting into lhashtable into d-3.eecs
213         mid = iptoMid("128.200.9.29"); //d-3.eecs.uci.edu
214         lhashInsert(20, mid);
215         lhashInsert(21, mid);
216         lhashInsert(22, mid);
217
218         mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
219         //Inserting into lhashtable of demsky.eecs
220         lhashInsert(1, mid);
221         lhashInsert(2, mid);
222         lhashInsert(3, mid);
223         lhashInsert(4, mid);
224         
225         pthread_create(&thread_Listen, &attr, dstmListen, NULL);
226
227         //Check if machine demsky is up and running
228         checkServer(mid, "128.200.9.10");
229         mid = iptoMid("128.200.9.29");
230         //Check if machine d-3 is up and running
231         checkServer(mid, "128.200.9.29");
232
233         // Start Transaction
234         myTrans = transStart();
235
236         //read object 4 (found on demksy)
237         if((h1 = transRead(myTrans, 4)) == NULL){
238                 printf("Object not found\n");
239         }
240         //read object 33 (found on local)
241         if((h2 = transRead(myTrans, 33)) == NULL){
242                 printf("Object not found\n");
243         }
244         //read object 20 (found on d-3)
245         if((h3 = transRead(myTrans, 20)) == NULL){
246                 printf("Object not found\n");
247         }
248
249         //Commit transaction
250         transCommit(myTrans);
251
252         pthread_join(thread_Listen, NULL);
253
254         return 0;
255 }
256 //Commit transaction for some objects that are available and some that are
257 //not available anywhere
258 int test4() {
259         unsigned int val, mid;
260         unsigned int size;
261         transrecord_t *myTrans;
262         objheader_t *header, *h1, *h2, *h3, *h4;
263         pthread_t thread_Listen;
264         pthread_attr_t attr;
265
266         dstmInit();
267         pthread_attr_init(&attr);
268         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
269
270         //Create and Insert Oid 31
271         size = sizeof(objheader_t) + classsize[2] ;
272         header = (objheader_t *) objstrAlloc(mainobjstore, size);
273         init_obj(header, 31, 2, 1, 0, NEW);
274         mhashInsert(header->oid, header);
275         mid = iptoMid("128.195.175.69");
276         lhashInsert(header->oid, mid);
277
278         //Create and Insert Oid 32
279         size = sizeof(objheader_t) + classsize[1] ;
280         header = (objheader_t *) objstrAlloc(mainobjstore, size);
281         init_obj(header, 32, 1, 1, 0, NEW);
282         mhashInsert(header->oid, header);
283         mid = iptoMid("128.195.175.69");
284         lhashInsert(header->oid, mid);
285
286         //Create and Insert Oid 33
287         size = sizeof(objheader_t) + classsize[0] ;
288         header = (objheader_t *) objstrAlloc(mainobjstore, size);
289         init_obj(header, 33, 0, 1, 0, NEW);
290         mhashInsert(header->oid, header);
291         mid = iptoMid("128.195.175.69");
292         lhashInsert(header->oid, mid);
293
294         //Inserting into lhashtable into d-3.eecs
295         mid = iptoMid("128.200.9.29"); //d-3.eecs.uci.edu
296         lhashInsert(20, mid);
297         lhashInsert(21, mid);
298         lhashInsert(22, mid);
299
300         mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
301         //Inserting into lhashtable of demsky.eecs
302         lhashInsert(1, mid);
303         lhashInsert(2, mid);
304         lhashInsert(3, mid);
305         lhashInsert(4, mid);
306         
307         pthread_create(&thread_Listen, &attr, dstmListen, NULL);
308
309         //Check if machine demsky is up and running
310         checkServer(mid, "128.200.9.10");
311         mid = iptoMid("128.200.9.29");
312         //Check if machine d-2 is up and running
313         checkServer(mid, "128.200.9.29");
314
315         // Start Transaction
316         myTrans = transStart();
317
318         //read object 4 (found on demksy)
319         if((h1 = transRead(myTrans, 4)) == NULL){
320                 printf("Object not found\n");
321         }
322         //read object 33 (found on local)
323         if((h2 = transRead(myTrans, 33)) == NULL){
324                 printf("Object not found\n");
325         }
326         //read object 24 (found nowhere)
327         if((h3 = transRead(myTrans, 24)) == NULL){
328                 printf("Object not found\n");
329         }
330         //read object 50 (found nowhere)
331         if((h4 = transRead(myTrans, 50)) == NULL){
332                 printf("Object not found\n");
333         }
334
335         //Commit transaction
336         if((h1 != NULL) && (h2 != NULL) && (h3 != NULL) && (h4 !=NULL)) 
337                 transCommit(myTrans);
338         else
339                 printf("Cannot complete this transaction\n");
340
341         pthread_join(thread_Listen, NULL);
342         return 0;
343
344 }