Various bug fixes
[IRC.git] / Robust / src / Runtime / DSTM / interface / testserver.c
1 #include <pthread.h>
2 #include "dstm.h"
3 #include <sys/socket.h>
4 #include <netinet/in.h>
5 #include <arpa/inet.h>
6
7 extern objstr_t *mainobjstore;
8 int classsize[]={sizeof(int),sizeof(char),sizeof(short), sizeof(void *)};
9
10 int test1(void);
11 int test2(void);
12
13 unsigned int createObjects(transrecord_t *record, unsigned short type) {
14         objheader_t *header, *tmp;
15         struct sockaddr_in antelope;
16         unsigned int size, mid;
17         size = sizeof(objheader_t) + classsize[type] ;
18         header = transCreateObj(record, type);
19         tmp = (objheader_t *) objstrAlloc(mainobjstore, size);
20         memcpy(tmp, header, size);
21         mhashInsert(tmp->oid, tmp);
22         mid = iptoMid("128.200.9.10");
23         lhashInsert(tmp->oid, mid);
24         //Lock oid 3 object
25 //      if(tmp->oid == 3)
26 //              tmp->status |= LOCK;
27         return 0;
28 }
29
30 int main()
31 {
32         test2();
33 }
34
35 int test1()
36 {
37         unsigned int val;
38         transrecord_t *myTrans;
39         pthread_t thread_Listen;
40
41         dstmInit();     
42         pthread_create(&thread_Listen, NULL, dstmListen, NULL);
43         // Start Transaction    
44         myTrans = transStart();
45
46         printf("Creating Transaction\n");
47         //Create Object1
48         if((val = createObjects(myTrans, 0)) != 0) {
49                 printf("Error transCreateObj1");
50         }
51         //Create Object2
52         if((val = createObjects(myTrans, 1)) != 0) {
53                 printf("Error transCreateObj2");
54         }
55         //Create Object3
56         if((val = createObjects(myTrans, 2)) != 0) {
57                 printf("Error transCreateObj3");
58         }
59         //Create Object4
60         if((val = createObjects(myTrans, 3)) != 0) {
61                 printf("Error transCreateObj4");
62         }
63         //Create Object5
64         if((val = createObjects(myTrans, 0)) != 0) {
65                 printf("Error transCreateObj5");
66         }
67         //Create Object6
68         if((val = createObjects(myTrans, 1)) != 0) {
69                 printf("Error transCreateObj6");
70         }
71         pthread_join(thread_Listen, NULL);
72         return 0;
73 }
74
75 int test2() {
76         
77         unsigned int val, mid;
78         transrecord_t *myTrans;
79         pthread_t thread_Listen;
80
81         dstmInit();     
82         mid = iptoMid("128.200.9.27");
83         //Inserting into lhashtable
84         lhashInsert(20, mid);
85         lhashInsert(21, mid);
86         lhashInsert(22, mid);
87         lhashInsert(23, mid);
88         lhashInsert(30, mid);
89         lhashInsert(28, mid);
90         lhashInsert(29, mid);
91         pthread_create(&thread_Listen, NULL, dstmListen, NULL);
92         // Start Transaction    
93         myTrans = transStart();
94
95         printf("Creating Transaction\n");
96         //Create Object1
97         if((val = createObjects(myTrans, 0)) != 0) {
98                 printf("Error transCreateObj1");
99         }
100         //Create Object2
101         if((val = createObjects(myTrans, 1)) != 0) {
102                 printf("Error transCreateObj2");
103         }
104         //Create Object3
105         if((val = createObjects(myTrans, 2)) != 0) {
106                 printf("Error transCreateObj3");
107         }
108         //Create Object4
109         if((val = createObjects(myTrans, 3)) != 0) {
110                 printf("Error transCreateObj4");
111         }
112         //Create Object5
113         if((val = createObjects(myTrans, 0)) != 0) {
114                 printf("Error transCreateObj5");
115         }
116         //Create Object6
117         if((val = createObjects(myTrans, 1)) != 0) {
118                 printf("Error transCreateObj6");
119         }
120         pthread_join(thread_Listen, NULL);
121 }