Logo AND Algorithmique Numérique Distribuée

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