Logo AND Algorithmique Numérique Distribuée

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