Logo AND Algorithmique Numérique Distribuée

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