Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not allow malloc(0) since that's not portable
[simgrid.git] / teshsuite / gras / datadesc / datadesc_usage.c
1 /* $Id$ */
2
3 /* datadesc: test of data description (using file transport).               */
4
5 /* Copyright (c) 2004-2007 Martin Quinson. All rights reserved.             */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #ifdef __BORLANDC__
11 #pragma hdrstop
12 #endif
13
14 #include <stdio.h>
15 #include "gras.h"
16
17 #include "gras/DataDesc/datadesc_interface.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
19
20 #define READ  0
21 #define WRITE 1
22 #define COPY  2
23
24 const char *filename = "datadesc_usage.out";
25
26 void
27 write_read(const char* msgtype,void *src, void *dst,
28                 gras_socket_t sock, int direction);
29
30 void
31 write_read(const char* msgtype,void *src, void *dst,
32                 gras_socket_t sock, int direction) {
33
34         switch (direction) {
35         case READ:
36                 gras_msg_wait(15, msgtype, NULL, dst);
37                 break;
38
39         case WRITE:
40                 gras_msg_send(sock, msgtype, src);
41                 break;
42
43         case COPY:
44                 gras_datadesc_memcpy(gras_datadesc_by_name(msgtype), src, dst);
45                 break;
46         }
47 }
48
49
50 /* defined in datadesc_structures.c, which in perl generated */
51 void register_structures(void);
52 void test_structures(gras_socket_t sock, int direction);
53
54 /************************
55  * Each and every tests *
56  ************************/
57
58 static void test_int(gras_socket_t sock, int direction) {
59         int i=5,j;
60
61         INFO0("---- Test on integer ----");
62         write_read("int", &i,&j, sock,direction);
63         if (direction == READ || direction == COPY)
64                 xbt_assert(i == j);
65 }
66 static void test_float(gras_socket_t sock, int direction) {
67         float i=5.0,j;
68
69         INFO0("---- Test on float ----");
70         write_read("float", &i,&j, sock,direction);
71         if (direction == READ || direction == COPY)
72                 xbt_assert2(i == j,"%f != %f",i,j);
73 }
74 static void test_double(gras_socket_t sock, int direction) {
75         double i=-3252355.1234,j;
76
77         INFO0("---- Test on double ----");
78         write_read("double", &i,&j, sock,direction);
79         if (direction == READ || direction == COPY)
80                 xbt_assert2(i == j,"%f != %f",i,j);
81 }
82
83 #define FIXED_ARRAY_SIZE 5
84 typedef int array[FIXED_ARRAY_SIZE];
85 static void test_array(gras_socket_t sock, int direction) {
86         array i = { 35212,-6226,74337,11414,7733};
87         array j;
88         int cpt;
89
90         INFO0("---- Test on fixed array ----");
91
92         write_read("fixed int array", &i,&j, sock,direction);
93         if (direction == READ || direction == COPY) {
94                 for (cpt=0; cpt<FIXED_ARRAY_SIZE; cpt++) {
95                         DEBUG1("Test spot %d",cpt);
96                         xbt_assert4(i[cpt] == j[cpt],"i[%d]=%d  !=  j[%d]=%d",
97                                         cpt,i[cpt],cpt,j[cpt]);
98                 }
99         }
100 }
101 /*** Dynar of scalar ***/
102
103 static void test_dynar_scal(gras_socket_t sock, int direction){
104         xbt_dynar_t i,j;
105         int cpt;
106
107         INFO0("---- Test on dynar containing integers ----");
108         i = xbt_dynar_new(sizeof(int),NULL);
109         for (cpt=0; cpt<64; cpt++) {
110                 xbt_dynar_push_as(i,int,cpt);
111                 DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(i));
112         }
113         /*  xbt_dynar_dump(i);*/
114         write_read("xbt_dynar_of_int", &i,&j, sock, direction);
115         /*  xbt_dynar_dump(j);*/
116         if (direction == READ || direction == COPY) {
117                 for (cpt=0; cpt<64; cpt++){
118                         int ret=xbt_dynar_get_as(j,cpt,int);
119                         if (cpt != ret) {
120                                 CRITICAL3("The retrieved value for cpt=%d is not the same than the injected one (%d!=%d)",
121                                                 cpt,ret,cpt);
122                                 xbt_abort();
123                         }
124                 }
125                 xbt_dynar_free(&j);
126         }
127         xbt_dynar_free(&i);
128 }
129
130 /*** Empty dynar ***/
131
132 static void test_dynar_empty(gras_socket_t sock, int direction){
133         xbt_dynar_t i,j;
134
135         INFO0("---- Test on empty dynar of integers ----");
136         i = xbt_dynar_new(sizeof(int),NULL);
137         write_read("xbt_dynar_of_int", &i,&j, sock, direction);
138         /*  xbt_dynar_dump(j);*/
139         if (direction == READ || direction == COPY) {
140                 xbt_assert(xbt_dynar_length(j) == 0);
141                 xbt_dynar_free(&j);
142         }
143         xbt_dynar_free(&i);
144 }
145
146 static void test_intref(gras_socket_t sock, int direction) {
147         int *i,*j;
148
149         i=xbt_new(int,1);
150         *i=12345;
151
152         INFO0("---- Test on a reference to an integer ----");
153
154         write_read("int*", &i,&j, sock,direction);
155         if (direction == READ || direction == COPY) {
156                 xbt_assert2(*i == *j,"*i != *j (%d != %d)",*i,*j);
157                 free(j);
158         }
159         free(i);
160 }
161
162 /***
163  *** string (dynamic array)
164  ***/
165 static void test_string(gras_socket_t sock, int direction) {
166         char *i=xbt_strdup("Some data"), *j=NULL;
167         int cpt;
168
169         INFO0("---- Test on string (ref to dynamic array) ----");
170         write_read("string", &i,&j, sock,direction);
171         if (direction == READ || direction == COPY) {
172                 for (cpt=0; cpt<strlen(i); cpt++) {
173                         xbt_assert4(i[cpt] == j[cpt],"i[%d]=%c  !=  j[%d]=%c",
174                                         cpt,i[cpt],cpt,j[cpt]);
175                 }
176                 free(j);
177         }
178         free(i);
179 }
180
181
182 /***
183  *** homogeneous struct
184  ***/
185 typedef struct {
186         int a,b,c,d;
187 } homostruct;
188 static void test_homostruct(gras_socket_t sock, int direction) {
189         homostruct *i, *j;
190
191         INFO0("---- Test on homogeneous structure ----");
192         /* init a value, exchange it and check its validity*/
193         i=xbt_new(homostruct,1);
194         i->a = 2235;    i->b = 433425;
195         i->c = -23423;  i->d = -235235;
196
197         write_read("homostruct*", &i,&j, sock,direction);
198         if (direction == READ || direction == COPY) {
199                 xbt_assert2(i->a == j->a,"i->a=%d != j->a=%d",i->a,j->a);
200                 xbt_assert(i->b == j->b);
201                 xbt_assert(i->c == j->c);
202                 xbt_assert(i->d == j->d);
203                 free(j);
204         }
205         free(i);
206 }
207
208 /***
209  *** heterogeneous struct
210  ***/
211 typedef struct {
212         unsigned char c1;
213         unsigned long int l1;
214         unsigned char c2;
215         unsigned long int l2;
216 } hetestruct;
217 static void test_hetestruct(gras_socket_t sock, int direction) {
218         hetestruct *i, *j;
219
220         INFO0("---- Test on heterogeneous structure ----");
221         /* init a value, exchange it and check its validity*/
222         i=xbt_new(hetestruct,1);
223         i->c1 = 's'; i->l1 = 123455;
224         i->c2 = 'e'; i->l2 = 774531;
225
226         write_read("hetestruct*", &i,&j, sock,direction);
227         if (direction == READ || direction == COPY) {
228                 xbt_assert(i->c1 == j->c1);
229                 xbt_assert(i->c2 == j->c2);
230                 xbt_assert2(i->l1 == j->l1,"i->l1(=%ld)  !=  j->l1(=%ld)",i->l1,j->l1);
231                 xbt_assert(i->l2 == j->l2);
232                 free(j);
233         }
234         free(i);
235 }
236
237 static void test_hetestruct_array(gras_socket_t sock, int direction) {
238         hetestruct *i, *j, *p,*q;
239         int cpt;
240
241         INFO0("---- Test on heterogeneous structure arrays ----");
242         /* init a value, exchange it and check its validity*/
243         i=xbt_malloc(sizeof(hetestruct)*10);
244         for (cpt=0,p=i;cpt<10;cpt++,p++) {
245                 p->c1 = 's'+cpt; p->l1 = 123455+cpt;
246                 p->c2 = 'e'+cpt; p->l2 = 774531+cpt;
247         }
248
249         write_read("hetestruct[10]*", &i,&j, sock,direction);
250         if (direction == READ || direction == COPY) {
251                 for (cpt=0,p=i,q=j;
252                          cpt<10;
253                          cpt++,p++,q++) {
254                         xbt_assert(p->c1 == q->c1);
255                         xbt_assert(p->c2 == q->c2);
256                         xbt_assert3(p->l1 == p->l1,
257                                         "for cpt=%d i->l1(=%ld)  !=  j->l1(=%ld)",cpt,p->l1,q->l1);
258                         xbt_assert(q->l2 == p->l2);
259                 }
260                 free(j);
261         }
262         free(i);
263 }
264 /***
265  *** nested struct
266  ***/
267 typedef struct {
268         hetestruct hete;
269         homostruct homo;
270 } nestedstruct;
271 static void test_nestedstruct(gras_socket_t sock, int direction) {
272         nestedstruct *i, *j;
273
274         INFO0("---- Test on nested structures ----");
275         /* init a value, exchange it and check its validity*/
276         i=xbt_new(nestedstruct,1);
277         i->homo.a = 235231;  i->homo.b = -124151;
278         i->homo.c = 211551;  i->homo.d = -664222;
279         i->hete.c1 = 's'; i->hete.l1 = 123455;
280         i->hete.c2 = 'e'; i->hete.l2 = 774531;
281
282         write_read("nestedstruct*", &i,&j, sock,direction);
283         if (direction == READ || direction == COPY) {
284                 xbt_assert(i->homo.a == j->homo.a);
285                 xbt_assert(i->homo.b == j->homo.b);
286                 xbt_assert(i->homo.c == j->homo.c);
287                 xbt_assert(i->homo.d == j->homo.d);
288                 xbt_assert(i->hete.c1 == j->hete.c1);
289                 xbt_assert(i->hete.c2 == j->hete.c2);
290                 xbt_assert(i->hete.l1 == j->hete.l1);
291                 xbt_assert(i->hete.l2 == j->hete.l2);
292                 free(j);
293         }
294         free(i);
295 }
296
297 /***
298  *** chained list
299  ***/
300 typedef struct s_chained_list chained_list_t;
301 struct s_chained_list {
302         int          v;
303         chained_list_t *l;
304 };
305 chained_list_t *cons(int v, chained_list_t *l);
306 void list_free(chained_list_t *l);
307 int list_eq(chained_list_t*i,chained_list_t*j);
308
309 chained_list_t * cons(int v, chained_list_t *l) {
310         chained_list_t *nl = xbt_new(chained_list_t,1);
311
312         nl->v = v;
313         nl->l = l;
314
315         return nl;
316 }
317 void list_free(chained_list_t*l) {
318         if (l) {
319                 list_free(l->l);
320                 free(l);
321         }
322 }
323 int list_eq(chained_list_t*i,chained_list_t*j) {
324         if (!i || !j) return i == j;
325         if (i->v != j->v)
326                 return 0;
327         return list_eq(i->l, j->l);
328 }
329 static void test_chain_list(gras_socket_t sock, int direction) {
330         chained_list_t *i, *j;
331
332         INFO0("---- Test on chained list ----");
333
334         /* init a value, exchange it and check its validity*/
335         i = cons( 12355, cons( 246264 , cons( 23263, NULL)));
336         j = NULL;
337
338         write_read("chained_list_t*", &i,&j,  sock,direction);
339         if (direction == READ || direction == COPY) {
340                 xbt_assert(list_eq(i,j));
341                 list_free(j);
342         }
343
344         list_free(i);
345 }
346 /***
347  *** graph
348  ***/
349 static void test_graph(gras_socket_t sock, int direction) {
350         chained_list_t *i, *j;
351
352         INFO0("---- Test on graph (cyclique chained list of 3 items) ----");
353         /* init a value, exchange it and check its validity*/
354         i = cons( 1151515, cons( -232362 , cons( 222552, NULL)));
355         i->l->l->l = i;
356         j = NULL;
357
358         write_read("chained_list_t*", &i,&j, sock,direction);
359         if (direction == READ || direction == COPY) {
360
361                 DEBUG1("i=%p"         ,i);
362                 DEBUG1("i->l=%p"      ,i->l);
363                 DEBUG1("i->l->l=%p"   ,i->l->l);
364                 DEBUG1("i->l->l->l=%p",i->l->l->l);
365                 DEBUG1("j=%p"         ,j);
366                 DEBUG1("j->l=%p"      ,j->l);
367                 DEBUG1("j->l->l=%p"   ,j->l->l);
368                 DEBUG1("j->l->l->l=%p",j->l->l->l);
369                 xbt_assert4(j->l->l->l == j,
370                                 "Received list is not cyclic. j=%p != j->l->l->l=%p\n"
371                                 "j=%p; &j=%p",
372                                 j,j->l->l->l,
373                                 j ,&j);
374                 j->l->l->l = NULL;
375                 i->l->l->l = NULL;
376                 xbt_assert(list_eq(i,j));
377
378                 list_free(j);
379         }
380         i->l->l->l = NULL; /* do this even in WRITE mode */
381         list_free(i);
382 }
383
384
385 /*** Dynar of references ***/
386 static void free_string(void *d){ /* used to free the data in dynar */
387         free(*(void**)d);
388 }
389 static void test_dynar_ref(gras_socket_t sock, int direction){
390         xbt_dynar_t i,j;
391         char buf[1024];
392         char *s1,*s2;
393         int cpt;
394
395         INFO0("---- Test on dynar containing integers ----");
396
397         i=xbt_dynar_new(sizeof(char*),&free_string);
398         for (cpt=0; cpt< 64; cpt++) {
399                 sprintf(buf,"%d",cpt);
400                 s1=strdup(buf);
401                 xbt_dynar_push(i,&s1);
402         }
403
404         write_read("xbt_dynar_of_string", &i,&j, sock, direction);
405         if (direction == READ || direction == COPY) {
406                 for (cpt=0; cpt< 64; cpt++) {
407                         sprintf(buf,"%d",cpt);
408                         xbt_dynar_shift(j,&s2);
409                         xbt_assert2 (!strcmp(buf,s2),
410                                         "The retrieved value is not the same than the injected one (%s!=%s)",
411                                         buf,s2);
412                         free(s2);
413                 }
414                 xbt_dynar_free(&j);
415         }
416         xbt_dynar_free(&i);
417 }
418
419
420 /**** PBIO *****/
421 GRAS_DEFINE_TYPE(s_pbio,
422                 struct s_pbio{ /* structure presented in the IEEE article */
423         int Cnstatv;
424         double Cstatev[12];
425         int Cnprops;
426         double Cprops[110];
427         int Cndi[4];
428         int Cnshr;
429         int Cnpt;
430         double Cdtime;
431         double Ctime[2];
432         int Cntens;
433         double Cdfgrd0[373][3];
434         double Cdfgrd1[3][3];
435         double Cstress[106];
436         double Cddsdde[106][106];
437 };
438 )
439 typedef struct s_pbio pbio_t;
440
441 static void test_pbio(gras_socket_t sock, int direction) {
442         int cpt;
443         int cpt2;
444         gras_datadesc_type_t pbio_type;
445         pbio_t i, j;
446
447         INFO0("---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ----");
448         pbio_type = gras_datadesc_by_symbol(s_pbio);
449
450         /* Fill in that damn struct */
451         i.Cnstatv = 325115;
452         for (cpt=0; cpt<12; cpt++)
453                 i.Cstatev[cpt] = ((double) cpt) * -2361.11;
454         i.Cnprops = -37373;
455         for (cpt=0; cpt<110; cpt++)
456                 i.Cprops[cpt] = cpt * 100.0;
457         for (cpt=0; cpt<4; cpt++)
458                 i.Cndi[cpt] = cpt * 23262;
459         i.Cnshr = -4634;
460         i.Cnpt = 114142;
461         i.Cdtime = -11515.662;
462         i.Ctime[0] = 332523.226;
463         i.Ctime[1] = -26216.113;
464         i.Cntens = 235211411;
465
466         for (cpt=0; cpt<3; cpt++) {
467                 for (cpt2=0; cpt2<373; cpt2++)
468                         i.Cdfgrd0[cpt2][cpt] = ((double)cpt) * ((double)cpt2);
469                 for (cpt2=0; cpt2<3; cpt2++)
470                         i.Cdfgrd1[cpt][cpt2] = -((double)cpt) * ((double)cpt2);
471         }
472         for (cpt=0; cpt<106; cpt++) {
473                 i.Cstress[cpt]=(double)cpt * 22.113;
474                 for (cpt2=0; cpt2<106; cpt2++)
475                         i.Cddsdde[cpt][cpt2] = ((double)cpt) * ((double)cpt2);
476         }
477         write_read("s_pbio", &i,&j, sock,direction);
478         if (direction == READ || direction == COPY) {
479                 /* Check that the data match */
480                 xbt_assert(i.Cnstatv == j.Cnstatv);
481                 for (cpt=0; cpt<12; cpt++)
482                         xbt_assert4(i.Cstatev[cpt] == j.Cstatev[cpt],
483                                         "i.Cstatev[%d] (=%f) != j.Cstatev[%d] (=%f)",
484                                         cpt,i.Cstatev[cpt],cpt,j.Cstatev[cpt]);
485                 xbt_assert(i.Cnprops == j.Cnprops);
486                 for (cpt=0; cpt<110; cpt++)
487                         xbt_assert(i.Cprops[cpt] == j.Cprops[cpt]);
488                 for (cpt=0; cpt<4; cpt++)
489                         xbt_assert(i.Cndi[cpt] == j.Cndi[cpt]);
490                 xbt_assert(i.Cnshr == j.Cnshr);
491                 xbt_assert(i.Cnpt == j.Cnpt);
492                 xbt_assert(i.Cdtime == j.Cdtime);
493                 xbt_assert(i.Ctime[0] == j.Ctime[0]);
494                 xbt_assert(i.Ctime[1] == j.Ctime[1]);
495                 xbt_assert(i.Cntens == j.Cntens);
496                 for (cpt=0; cpt<3; cpt++) {
497                         for (cpt2=0; cpt2<373; cpt2++)
498                                 xbt_assert(i.Cdfgrd0[cpt2][cpt] == j.Cdfgrd0[cpt2][cpt]);
499                         for (cpt2=0; cpt2<3; cpt2++)
500                                 xbt_assert(i.Cdfgrd1[cpt][cpt2] == j.Cdfgrd1[cpt][cpt2]);
501                 }
502                 for (cpt=0; cpt<106; cpt++) {
503                         xbt_assert(i.Cstress[cpt] == j.Cstress[cpt]);
504                         for (cpt2=0; cpt2<106; cpt2++)
505                                 xbt_assert4(i.Cddsdde[cpt][cpt2] == j.Cddsdde[cpt][cpt2],
506                                                 "%f=i.Cddsdde[%d][%d] != j.Cddsdde[cpt][cpt2]=%f",
507                                                 i.Cddsdde[cpt][cpt2],cpt,cpt2,j.Cddsdde[cpt][cpt2]);
508                 }
509         }
510 }
511
512 GRAS_DEFINE_TYPE(s_clause,
513                 struct s_clause {
514         int num_lits;
515         int *literals GRAS_ANNOTE(size,num_lits); /* Tells GRAS where to find the size */
516 };)
517 typedef struct s_clause Clause;
518
519 static void test_clause(gras_socket_t sock, int direction) {
520         Clause *i,*j;
521         int cpt;
522
523         INFO0("---- Test on struct containing dynamic array and its size (cbps test) ----");
524
525         /* create and fill the struct */
526         i=xbt_new(Clause,1);
527
528         i->num_lits = 5432;
529         i->literals = xbt_new(int, i->num_lits);
530         for (cpt=0; cpt<i->num_lits; cpt++)
531                 i->literals[cpt] = cpt * cpt - ((cpt * cpt) / 2);
532         DEBUG3("created data=%p (within %p @%p)",&(i->num_lits),i,&i);
533         DEBUG1("created count=%d",i->num_lits);
534
535         write_read("Clause*", &i,&j, sock,direction);
536         if (direction == READ || direction == COPY) {
537                 xbt_assert(i->num_lits == j->num_lits);
538                 for (cpt=0; cpt<i->num_lits; cpt++)
539                         xbt_assert(i->literals[cpt] == j->literals[cpt]);
540
541                 free(j->literals);
542                 free(j);
543         }
544         free(i->literals);
545         free(i);
546 }
547
548 static void test_clause_empty(gras_socket_t sock, int direction) {
549         Clause *i,*j;
550
551         INFO0("---- Test on struct containing dynamic array and its size when size=0 (cbps test) ----");
552
553         /* create and fill the struct */
554         i=xbt_new(Clause,1);
555
556         i->num_lits = 0;
557         i->literals = NULL;
558         DEBUG3("created data=%p (within %p @%p)",&(i->num_lits),i,&i);
559         DEBUG1("created count=%d",i->num_lits);
560
561         write_read("Clause*", &i,&j, sock,direction);
562         if (direction == READ || direction == COPY) {
563                 xbt_assert(i->num_lits == j->num_lits);
564
565                 free(j->literals);
566                 free(j);
567         }
568         free(i->literals);
569         free(i);
570 }
571
572 static void register_types(void) {
573         gras_datadesc_type_t my_type,ref_my_type;
574
575         gras_msgtype_declare("char",gras_datadesc_by_name("char"));
576         gras_msgtype_declare("int",gras_datadesc_by_name("int"));
577         gras_msgtype_declare("float",gras_datadesc_by_name("float"));
578         gras_msgtype_declare("double",gras_datadesc_by_name("double"));
579
580         my_type=gras_datadesc_array_fixed("fixed int array",
581                         gras_datadesc_by_name("int"),
582                         FIXED_ARRAY_SIZE);
583         gras_msgtype_declare("fixed int array",my_type);
584
585         my_type = gras_datadesc_dynar(gras_datadesc_by_name("int"),NULL);
586         gras_msgtype_declare("xbt_dynar_of_int",my_type);
587
588         my_type = gras_datadesc_ref("int*",gras_datadesc_by_name("int"));
589         gras_msgtype_declare("int*",my_type);
590
591         gras_msgtype_declare("string",gras_datadesc_by_name("string"));
592
593         my_type=gras_datadesc_struct("homostruct");
594         gras_datadesc_struct_append(my_type,"a",gras_datadesc_by_name("signed int"));
595         gras_datadesc_struct_append(my_type,"b",gras_datadesc_by_name("int"));
596         gras_datadesc_struct_append(my_type,"c",gras_datadesc_by_name("int"));
597         gras_datadesc_struct_append(my_type,"d",gras_datadesc_by_name("int"));
598         gras_datadesc_struct_close(my_type);
599         my_type=gras_datadesc_ref("homostruct*",gras_datadesc_by_name("homostruct"));
600         gras_msgtype_declare("homostruct*",my_type);
601
602         my_type=gras_datadesc_struct("hetestruct");
603         gras_datadesc_struct_append(my_type,"c1", gras_datadesc_by_name("unsigned char"));
604         gras_datadesc_struct_append(my_type,"l1", gras_datadesc_by_name("unsigned long int"));
605         gras_datadesc_struct_append(my_type,"c2", gras_datadesc_by_name("unsigned char"));
606         gras_datadesc_struct_append(my_type,"l2", gras_datadesc_by_name("unsigned long int"));
607         gras_datadesc_struct_close(my_type);
608         my_type=gras_datadesc_ref("hetestruct*", gras_datadesc_by_name("hetestruct"));
609         gras_msgtype_declare("hetestruct*",my_type);
610
611         my_type = gras_datadesc_array_fixed("hetestruct[10]",gras_datadesc_by_name("hetestruct"),10);
612         my_type = gras_datadesc_ref("hetestruct[10]*", my_type);
613         gras_msgtype_declare("hetestruct[10]*",my_type);
614
615         my_type=gras_datadesc_struct("nestedstruct");
616         gras_datadesc_struct_append(my_type,"hete",gras_datadesc_by_name("hetestruct"));
617         gras_datadesc_struct_append(my_type,"homo",gras_datadesc_by_name("homostruct"));
618         gras_datadesc_struct_close(my_type);
619         my_type=gras_datadesc_ref("nestedstruct*", gras_datadesc_by_name("nestedstruct"));
620         gras_msgtype_declare("nestedstruct*",my_type);
621
622         my_type=gras_datadesc_struct("chained_list_t");
623         ref_my_type=gras_datadesc_ref("chained_list_t*",my_type);
624         gras_datadesc_struct_append(my_type,"v", gras_datadesc_by_name("int"));
625         gras_datadesc_struct_append(my_type,"l", ref_my_type);
626         gras_datadesc_struct_close(my_type);
627         gras_datadesc_cycle_set(gras_datadesc_by_name("chained_list_t*"));
628         gras_msgtype_declare("chained_list_t",my_type);
629         gras_msgtype_declare("chained_list_t*",ref_my_type);
630
631         my_type = gras_datadesc_dynar(gras_datadesc_by_name("string"),&free_string);
632         gras_msgtype_declare("xbt_dynar_of_string",my_type);
633
634         my_type = gras_datadesc_by_symbol(s_pbio);
635         gras_msgtype_declare("s_pbio",my_type);
636
637         my_type = gras_datadesc_by_symbol(s_clause);
638         my_type = gras_datadesc_ref("Clause*",my_type);
639         gras_msgtype_declare("Clause*",my_type);
640
641 }
642
643 #ifdef __BORLANDC__
644 #pragma argsused
645 #endif
646
647 int main(int argc,char *argv[]) {
648         gras_socket_t sock=NULL;
649         int direction = WRITE;
650         int cpt;
651         char local_arch, remote_arch;
652
653         gras_init(&argc,argv);
654         register_types();
655         register_structures();
656
657         for (cpt=1; cpt<argc; cpt++) {
658                 if (!strcmp(argv[cpt], "--arch")) {
659                         INFO2("We are on %s (#%d)",
660                                         gras_datadesc_arch_name(gras_arch_selfid()),(int)gras_arch_selfid());
661                         exit(0);
662                 } else if (!strcmp(argv[cpt], "--help")) {
663                         printf("Usage: datadesc_usage [option] [filename]\n");
664                         printf(" --arch: display the current architecture and quit.\n");
665                         printf(" --read file: reads the description from the given file\n");
666                         printf(" --write file: writes the description to the given file\n");
667                         printf(" --copy: copy the description in memory\n");
668                         printf(" --regen: write the description to the file of the current architecture\n");
669                         printf(" --help: displays this message\n");
670                         exit(0);
671                 } else if (!strcmp(argv[cpt], "--regen")) {
672                         direction = WRITE;
673                         filename = bprintf("datadesc.%s",gras_datadesc_arch_name(gras_arch_selfid()));
674                 } else if (!strcmp(argv[cpt], "--read")) {
675                         direction = READ;
676                 } else if (!strcmp(argv[cpt], "--write")) {
677                         direction = WRITE;
678                 } else if (!strcmp(argv[cpt], "--copy")) {
679                         direction = COPY;
680                 } else {
681                         filename=argv[cpt];
682                 }
683         }
684
685         if (direction == WRITE) {
686                 INFO1("Write to file %s",filename);
687                 sock = gras_socket_client_from_file(filename);
688         }
689         if (direction == READ) {
690                 INFO1("Read from file %s",filename);
691                 sock = gras_socket_server_from_file(filename);
692         }
693         if (direction == COPY) {
694                 INFO0("Memory copy");
695         }
696
697         local_arch = gras_arch_selfid();
698         write_read("char", &local_arch,&remote_arch, sock,direction);
699         if (direction == READ)
700                 VERB2("This file was generated on %s (%d)",
701                                 gras_datadesc_arch_name(remote_arch),(int)remote_arch);
702
703
704         test_int(sock,direction);
705         test_float(sock,direction);
706         test_double(sock,direction);
707         test_array(sock,direction);
708         test_intref(sock,direction);
709
710         test_string(sock,direction);
711         test_dynar_scal(sock,direction);
712         test_dynar_empty(sock,direction);
713
714         test_structures(sock,direction);
715
716         test_homostruct(sock,direction);
717         test_hetestruct(sock,direction);
718         test_nestedstruct(sock,direction);
719         test_hetestruct_array(sock,direction);
720
721         test_chain_list(sock,direction);
722         test_graph(sock,direction);
723         test_dynar_ref(sock,direction);
724
725         test_pbio(sock,direction);
726
727         test_clause(sock,direction);
728         test_clause_empty(sock,direction);
729
730         if (direction != COPY)
731                 gras_socket_close(sock);
732
733         gras_exit();
734         return 0;
735 }
736