remove some codes for scheduling
[IRC.git] / Robust / src / Runtime / DSTM / interface / tests / testd-3.c
1 #include<stdio.h>
2 #include<pthread.h>
3 #include "dstm.h"
4 #include "llookup.h"
5 #include "ip.h"
6
7 #define LISTEN_PORT 2156
8
9 extern objstr_t *mainobjstore;
10
11 int classsize[]={sizeof(int),sizeof(char),sizeof(short), sizeof(void *)};       
12
13 int main() 
14 {
15 //      test2();
16 //      test3();
17 //      test4();
18         test5();
19 //      test5a();
20 //      test2a();
21 //      test2b();
22 //      test7();
23
24 }
25
26 int test1(void) {
27
28         transrecord_t *record;
29         objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
30
31         dstmInit();
32         record = transStart();
33         printf("DEBUG -> Init done\n");
34         h1 = transRead(record, 1);
35         printf("oid = %d\tsize = %d\n", OID(h1),classsize[h1->type]);
36         h3 = transRead(record, 3);
37         printf("oid = %d\tsize = %d\n", OID(h3),classsize[h3->type]);
38         h4 = transRead(record, 4);
39         printf("oid = %d\tsize = %d\n", OID(h4),classsize[h4->type]);
40         h2 = transRead(record, 2);
41         printf("oid = %d\tsize = %d\n", OID(h2),classsize[h2->type]);
42         h4 = transRead(record, 4);
43         printf("oid = %d\tsize = %d\n", OID(h4),classsize[h4->type]);
44         h3 = transRead(record, 3);
45         printf("oid = %d\tsize = %d\n", OID(h3),classsize[h3->type]);
46         h5 = transRead(record, 5);
47         printf("oid = %d\tsize = %d\n", OID(h5),classsize[h5->type]);
48 }
49
50 int test2(void) {
51
52         transrecord_t *record;
53         objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
54
55         dstmInit();
56         record = transStart();
57
58         lhashInsert(1,1);
59         lhashInsert(2,1);
60         lhashInsert(3,1);
61         lhashInsert(4,1);
62         lhashInsert(5,1);
63         lhashInsert(6,1);
64         printf("DEBUG -> Init done\n");
65         h1 = transRead(record, 1);
66         lhashInsert(OID(h1), 1);
67         h2 = transRead(record, 2);
68         lhashInsert(OID(h2), 1);
69         h3 = transRead(record, 3);
70         lhashInsert(OID(h3), 1);
71         h4 = transRead(record, 4);
72         lhashInsert(OID(h4), 1);
73         h5 = transRead(record, 5);
74         lhashInsert(OID(h5), 1);
75         h6 = transRead(record, 6);
76         lhashInsert(OID(h6), 1);
77         
78         transCommit(record);
79
80         return 0;
81 }
82
83 //Read objects when objects are found in remote location
84 int test2a(void) {
85          unsigned int val, mid;
86          transrecord_t *myTrans;
87          unsigned int size;
88          objheader_t *header, *h1, *h2;
89          pthread_t thread_Listen;
90          pthread_attr_t attr;
91
92          dstmInit();
93          pthread_attr_init(&attr);
94          pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
95
96          //Create and Insert Oid 20
97          size = sizeof(objheader_t) + classsize[2] ;
98          header = (objheader_t *) objstrAlloc(mainobjstore, size);
99          OID(header) = 20;
100          header->type = 2;
101          header->version = 1;
102          header->rcount = 0; //? not sure how to handle this yet
103          header->status = 0;
104          header->status |= NEW;
105          mhashInsert(OID(header), header);
106          mid = iptoMid("128.200.9.29");
107          lhashInsert(OID(header), mid);
108
109          //Create and Insert Oid 21
110          size = sizeof(objheader_t) + classsize[1] ;
111          header = (objheader_t *) objstrAlloc(mainobjstore, size);
112          OID(header) = 21;
113          header->type = 1;
114          header->version = 1;
115          header->rcount = 0; //? not sure how to handle this yet
116          header->status = 0;
117          header->status |= NEW;
118          mhashInsert(OID(header), header);
119          mid = iptoMid("128.200.9.29");
120          lhashInsert(OID(header), mid);
121
122          //Create and Insert Oid 22
123          size = sizeof(objheader_t) + classsize[3] ;
124          header = (objheader_t *) objstrAlloc(mainobjstore, size);
125          OID(header) = 22;
126          header->type = 3;
127          header->version = 1;
128          header->rcount = 0; //? not sure how to handle this yet
129          header->status = 0;
130          header->status |= NEW;
131          mhashInsert(OID(header), header);
132          mid = iptoMid("128.200.9.29");
133          lhashInsert(OID(header), mid);
134
135          //Inserting into lhashtable
136          mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
137          lhashInsert(31, mid);
138          lhashInsert(32, mid);
139
140          mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
141          //Inserting into lhashtable
142          lhashInsert(1, mid);
143          lhashInsert(2, mid);
144          lhashInsert(3, mid);
145          lhashInsert(4, mid);
146
147          pthread_create(&thread_Listen, &attr, dstmListen, NULL);
148
149          //Check if machine demsky is up and running
150          checkServer(mid, "128.200.9.10");
151          mid = iptoMid("128.195.175.69");
152          //Check if machine dw-1 is up and running
153          checkServer(mid, "128.195.175.69");
154
155          // Start Transaction    
156          myTrans = transStart();
157
158          //read object 1
159          if((h1 = transRead(myTrans, 1)) == NULL){
160                  printf("Object not found\n");
161          }
162          //read object 2
163          if((h2 = transRead(myTrans, 2)) == NULL) {
164                  printf("Object not found\n");
165          }
166
167          pthread_join(thread_Listen, NULL);
168          return 0;
169 }
170
171 //Read objects that are both remote and local and are available on machines
172 int test2b(void) {
173
174         unsigned int val, mid;
175         transrecord_t *myTrans;
176         unsigned int size;
177         objheader_t *header, *h1, *h2, *h3, *h4;
178         pthread_t thread_Listen;
179         pthread_attr_t attr;
180
181         dstmInit();
182         pthread_attr_init(&attr);
183         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
184
185         //Create and Insert Oid 20
186         size = sizeof(objheader_t) + classsize[2] ;
187         header = (objheader_t *) objstrAlloc(mainobjstore, size);
188         OID(header) = 20;
189         header->type = 2;
190         header->version = 1;
191         header->rcount = 0; //? not sure how to handle this yet
192         header->status = 0;
193         header->status |= NEW;
194         mhashInsert(OID(header), header);
195         mid = iptoMid("128.200.9.29");
196         lhashInsert(OID(header), mid);
197
198         //Create and Insert Oid 21
199         size = sizeof(objheader_t) + classsize[1] ;
200         header = (objheader_t *) objstrAlloc(mainobjstore, size);
201         OID(header) = 21;
202         header->type = 1;
203         header->version = 1;
204         header->rcount = 0; //? not sure how to handle this yet
205         header->status = 0;
206         header->status |= NEW;
207         mhashInsert(OID(header), header);
208         mid = iptoMid("128.200.9.29");
209         lhashInsert(OID(header), mid);
210
211         //Create and Insert Oid 22
212         size = sizeof(objheader_t) + classsize[3] ;
213         header = (objheader_t *) objstrAlloc(mainobjstore, size);
214         OID(header) = 22;
215         header->type = 3;
216         header->version = 1;
217         header->rcount = 0; //? not sure how to handle this yet
218         header->status = 0;
219         header->status |= NEW;
220         mhashInsert(OID(header), header);
221         mid = iptoMid("128.200.9.29");
222         lhashInsert(OID(header), mid);
223
224         //Inserting into lhashtable
225         mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
226         lhashInsert(31, mid);
227         lhashInsert(32, mid);
228         lhashInsert(33, mid);
229
230         mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
231         //Inserting into lhashtable
232         lhashInsert(1, mid);
233         lhashInsert(2, mid);
234         lhashInsert(3, mid);
235         lhashInsert(4, mid);
236
237         pthread_create(&thread_Listen, &attr, dstmListen, NULL);
238
239         //Check if machine demsky is up and running
240         checkServer(mid, "128.200.9.10");
241         mid = iptoMid("128.195.175.69");
242         //Check if machine dw-1 is up and running
243         checkServer(mid, "128.195.175.69");
244
245         // Start Transaction    
246         myTrans = transStart();
247
248         //read object 1 (found on demksy)
249         if((h1 = transRead(myTrans, 1)) == NULL){
250                 printf("Object not found\n");
251         }
252         //read object 2 (found on demsky)
253         if((h2 = transRead(myTrans, 2)) == NULL) {
254                 printf("Object not found\n");
255         }
256         
257         //read object 21 (found on local)
258         if((h3 = transRead(myTrans, 21)) == NULL) {
259                 printf("Object not found\n");
260         }
261         
262         //read object 32 (found on dw-1)
263         if((h4 = transRead(myTrans, 32)) == NULL) {
264                 printf("Object not found\n");
265         }
266
267         pthread_join(thread_Listen, NULL);
268         return 0;
269
270 }
271
272
273 //Read objects when objects are not found in  any participant 
274 int test3(void){
275         transrecord_t *record;
276         objheader_t *h1,*h2;
277
278         dstmInit();
279         record = transStart();
280         printf("DEBUG -> Init done\n");
281         //read object 11
282         if((h1 = transRead(record, 11)) == NULL){
283                 printf("Object not found\n");
284         }
285         //read object 12
286         if((h2 = transRead(record, 12)) == NULL) {
287                 printf("Object not found\n");
288         }
289         transCommit(record);
290
291         return 0;
292 }
293
294 //Read objects when some objects are found and other objects not found in  any participant 
295 int test4(void) {
296         transrecord_t *record;
297         objheader_t *h1,*h2, *h3, *h4;
298
299         dstmInit();
300         record = transStart();
301         printf("DEBUG -> Init done\n");
302         //read object 1
303         if((h1 = transRead(record, 1)) == NULL){
304                 printf("Object not found\n");
305         }
306         //read object 2
307         if((h2 = transRead(record, 2)) == NULL) {
308                 printf("Object not found\n");
309         }
310         //read object 11
311         if((h3 = transRead(record, 11)) == NULL) {
312                 printf("Object not found\n");
313         }
314         //read object 13
315         if((h4 = transRead(record, 13)) == NULL) {
316                 printf("Object not found\n");
317         }
318         if((h1 != NULL) && (h2 != NULL) && (h3 != NULL) && h4 !=NULL) { 
319                 transCommit(record);
320         }else {
321                 printf("Cannot complete this transaction\n");
322         }
323
324         return 0;
325 }
326
327 //Commit for transaction objects when the objs are part of other 
328 //transactions running simultaneously
329 int test5(void) {
330         unsigned int val, mid;
331         transrecord_t *myTrans;
332         unsigned int size;
333         objheader_t *header, *h1, *h2, *h3, *h4, *h5, *h6;
334         pthread_t thread_Listen;
335         pthread_attr_t attr;
336
337         dstmInit();
338         pthread_attr_init(&attr);
339         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
340
341         //Create and Insert Oid 20
342         size = sizeof(objheader_t) + classsize[2] ;
343         header = (objheader_t *) objstrAlloc(mainobjstore, size);
344         OID(header) = 20;
345         header->type = 2;
346         header->version = 1;
347         header->rcount = 0; //? not sure how to handle this yet
348         header->status = 0;
349         header->status |= NEW;
350         mhashInsert(OID(header), header);
351         mid = iptoMid("128.200.9.29");
352         lhashInsert(OID(header), mid);
353
354         //Create and Insert Oid 21
355         size = sizeof(objheader_t) + classsize[1] ;
356         header = (objheader_t *) objstrAlloc(mainobjstore, size);
357         OID(header) = 21;
358         header->type = 1;
359         header->version = 1;
360         header->rcount = 0; //? not sure how to handle this yet
361         header->status = 0;
362         header->status |= NEW;
363         mhashInsert(OID(header), header);
364         mid = iptoMid("128.200.9.29");
365         lhashInsert(OID(header), mid);
366
367         //Create and Insert Oid 22
368         size = sizeof(objheader_t) + classsize[3] ;
369         header = (objheader_t *) objstrAlloc(mainobjstore, size);
370         OID(header) = 22;
371         header->type = 3;
372         header->version = 1;
373         header->rcount = 0; //? not sure how to handle this yet
374         header->status = 0;
375         header->status |= NEW;
376         mhashInsert(OID(header), header);
377         mid = iptoMid("128.200.9.29");
378         lhashInsert(OID(header), mid);
379
380         //Inserting into lhashtable
381         mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
382         lhashInsert(31, mid);
383         lhashInsert(32, mid);
384         lhashInsert(33, mid);
385
386         mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
387         //Inserting into lhashtable
388         lhashInsert(1, mid);
389         lhashInsert(2, mid);
390         lhashInsert(3, mid);
391         lhashInsert(4, mid);
392
393         pthread_create(&thread_Listen, &attr, dstmListen, NULL);
394         //Check if machine demsky is up and running
395         checkServer(mid, "128.200.9.10");
396         mid = iptoMid("128.195.175.69");
397         //Check if machine dw-1 is up and running
398         checkServer(mid, "128.195.175.69");
399
400         // Start Transaction    
401         myTrans = transStart();
402
403         //read object 1 (found on demksy)
404         if((h1 = transRead(myTrans, 1)) == NULL){
405                 printf("Object not found\n");
406         }
407         //read object 2 (found on demksy)
408         if((h2 = transRead(myTrans,2)) == NULL){
409                 printf("Object not found\n");
410         }
411         //read object 22 (found locally )
412         if((h3 = transRead(myTrans, 22)) == NULL) {
413                 printf("Object not found\n");
414         }
415         
416         //Commit transaction
417         transCommit(myTrans);
418         
419         pthread_join(thread_Listen, NULL);
420         return 0;
421 }
422 int test5a(void) {
423         unsigned int val, mid;
424         transrecord_t *myTrans;
425         unsigned int size;
426         objheader_t *header, *h1, *h2, *h3;
427         pthread_t thread_Listen;
428         pthread_attr_t attr;
429
430         dstmInit();
431         pthread_attr_init(&attr);
432         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
433
434         //Create and Insert Oid 20
435         size = sizeof(objheader_t) + classsize[2] ;
436         header = (objheader_t *) objstrAlloc(mainobjstore, size);
437         OID(header) = 20;
438         header->type = 2;
439         header->version = 1;
440         header->rcount = 0; //? not sure how to handle this yet
441         header->status = 0;
442         header->status |= NEW;
443         mhashInsert(OID(header), header);
444         mid = iptoMid("128.200.9.29");
445         lhashInsert(OID(header), mid);
446
447         //Create and Insert Oid 21
448         size = sizeof(objheader_t) + classsize[1] ;
449         header = (objheader_t *) objstrAlloc(mainobjstore, size);
450         OID(header) = 21;
451         header->type = 1;
452         //read object 31 (found on dw-1)
453         if((h2 = transRead(myTrans, 31)) == NULL) {
454                 printf("Object not found\n");
455         }
456         
457         //Commit transaction
458         transCommit(myTrans);
459         
460         pthread_join(thread_Listen, NULL);
461         return 0;
462 }
463 int test5b(void) {
464         unsigned int val, mid;
465         transrecord_t *myTrans;
466         unsigned int size;
467         objheader_t *header, *h1, *h2, *h3;
468         pthread_t thread_Listen;
469         pthread_attr_t attr;
470
471         dstmInit();
472         pthread_attr_init(&attr);
473         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
474
475         //Create and Insert Oid 20
476         size = sizeof(objheader_t) + classsize[2] ;
477         header = (objheader_t *) objstrAlloc(mainobjstore, size);
478         OID(header) = 20;
479         header->type = 2;
480         header->version = 1;
481         header->rcount = 0; //? not sure how to handle this yet
482         header->status = 0;
483         header->status |= NEW;
484         mhashInsert(OID(header), header);
485         mid = iptoMid("128.200.9.29");
486         lhashInsert(OID(header), mid);
487
488         //Create and Insert Oid 21
489         size = sizeof(objheader_t) + classsize[1] ;
490         header = (objheader_t *) objstrAlloc(mainobjstore, size);
491         OID(header) = 21;
492         header->type = 1;
493         header->version = 1;
494         header->rcount = 0; //? not sure how to handle this yet
495         header->status = 0;
496         header->status |= NEW;
497         mhashInsert(OID(header), header);
498         mid = iptoMid("128.200.9.29");
499         lhashInsert(OID(header), mid);
500
501         //Create and Insert Oid 22
502         size = sizeof(objheader_t) + classsize[3] ;
503         header = (objheader_t *) objstrAlloc(mainobjstore, size);
504         OID(header) = 22;
505         header->type = 3;
506         header->version = 1;
507         header->rcount = 0; //? not sure how to handle this yet
508         header->status = 0;
509         header->status |= NEW;
510         mhashInsert(OID(header), header);
511         mid = iptoMid("128.200.9.29");
512         lhashInsert(OID(header), mid);
513
514         //Inserting into lhashtable
515         mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
516         lhashInsert(31, mid);
517         lhashInsert(32, mid);
518         lhashInsert(33, mid);
519
520         mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
521         //Inserting into lhashtable
522         lhashInsert(1, mid);
523         lhashInsert(2, mid);
524         lhashInsert(3, mid);
525         lhashInsert(4, mid);
526
527         pthread_create(&thread_Listen, &attr, dstmListen, NULL);
528
529         //Check if machine demsky is up and running
530         checkServer(mid, "128.200.9.10");
531         mid = iptoMid("128.195.175.69");
532         //Check if machine dw-1 is up and running
533         checkServer(mid, "128.195.175.69");
534
535         // Start Transaction    
536         myTrans = transStart();
537
538         //read object 1 (found on demksy)
539         if((h1 = transRead(myTrans, 1)) == NULL){
540                 printf("Object not found\n");
541         }
542         //read object 31 (found on dw-1)
543         if((h2 = transRead(myTrans, 31)) == NULL) {
544                 printf("Object not found\n");
545         }
546         
547         //read object 22 (found locally)
548         if((h3 = transRead(myTrans, 22)) == NULL) {
549                 printf("Object not found\n");
550         }
551         
552         //Commit transaction
553         if((h1 != NULL) && (h2 != NULL) && (h3 != NULL))
554                 transCommit(myTrans);
555         else
556                 printf("Cannot complete this transaction \n");
557
558         pthread_join(thread_Listen, NULL);
559         return 0;
560 }
561 //Commit transactions on local and remote objects that are NOT a part of 
562 //any other transaction
563 int test7(void) {
564         unsigned int val, mid;
565         transrecord_t *myTrans;
566         unsigned int size;
567         objheader_t *header, *h1, *h2, *h3;
568         pthread_t thread_Listen;
569         pthread_attr_t attr;
570
571         dstmInit();
572         pthread_attr_init(&attr);
573         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
574
575         //Create and Insert Oid 20
576         size = sizeof(objheader_t) + classsize[2] ;
577         header = (objheader_t *) objstrAlloc(mainobjstore, size);
578         OID(header) = 20;
579         header->type = 2;
580         header->version = 1;
581         header->rcount = 0; //? not sure how to handle this yet
582         header->status = 0;
583         header->status |= NEW;
584         mhashInsert(OID(header), header);
585         mid = iptoMid("128.200.9.29");
586         lhashInsert(OID(header), mid);
587
588         //Create and Insert Oid 21
589         size = sizeof(objheader_t) + classsize[1] ;
590         header = (objheader_t *) objstrAlloc(mainobjstore, size);
591         OID(header) = 21;
592         header->type = 1;
593         header->version = 1;
594         header->rcount = 0; //? not sure how to handle this yet
595         header->status = 0;
596         header->status |= NEW;
597         mhashInsert(OID(header), header);
598         mid = iptoMid("128.200.9.29");
599         lhashInsert(OID(header), mid);
600
601         //Create and Insert Oid 22
602         size = sizeof(objheader_t) + classsize[3] ;
603         header = (objheader_t *) objstrAlloc(mainobjstore, size);
604         OID(header) = 22;
605         header->type = 3;
606         header->version = 1;
607         header->rcount = 0; //? not sure how to handle this yet
608         header->status = 0;
609         header->status |= NEW;
610         mhashInsert(OID(header), header);
611         mid = iptoMid("128.200.9.29");
612         lhashInsert(OID(header), mid);
613
614         //Inserting into lhashtable
615         mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
616         lhashInsert(31, mid);
617         lhashInsert(32, mid);
618         lhashInsert(33, mid);
619
620         mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
621         //Inserting into lhashtable
622         lhashInsert(1, mid);
623         lhashInsert(2, mid);
624         lhashInsert(3, mid);
625         lhashInsert(4, mid);
626
627         pthread_create(&thread_Listen, &attr, dstmListen, NULL);
628
629         //Check if machine demsky is up and running
630         checkServer(mid, "128.200.9.10");
631         mid = iptoMid("128.195.175.69");
632         //Check if machine dw-1 is up and running
633         checkServer(mid, "128.195.175.69");
634
635         // Start Transaction    
636         myTrans = transStart();
637
638         //read object 3 (found on demksy)
639         if((h1 = transRead(myTrans, 3)) == NULL){
640                 printf("Object not found\n");
641         }
642         //read object 32 (found on dw-1)
643         if((h2 = transRead(myTrans, 32)) == NULL) {
644                 printf("Object not found\n");
645         }
646         
647         //read object 22 (found locally)
648         if((h3 = transRead(myTrans, 22)) == NULL) {
649                 printf("Object not found\n");
650         }
651         
652         //Commit transaction
653         transCommit(myTrans);
654
655         pthread_join(thread_Listen, NULL);
656         return 0;
657 }