Logo AND Algorithmique Numérique Distribuée

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