Logo AND Algorithmique Numérique Distribuée

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