Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More explicit error message on failures
[simgrid.git] / testsuite / gras / datadesc_usage.c
index f09b5d9..4b84efc 100644 (file)
@@ -18,6 +18,9 @@ GRAS_LOG_NEW_DEFAULT_CATEGORY(test);
 #define WRITE 1
 #define RW    2
 
+int r_arch;
+const char *filename = "datadesc_usage.out";  
+
 gras_error_t
 write_read(gras_datadesc_type_t *type,void *src, void *dst, 
           gras_socket_t *sock, int direction);
@@ -29,21 +32,21 @@ write_read(gras_datadesc_type_t *type,void *src, void *dst,
    
   /* write */
   if (direction == RW) 
-    TRY(gras_socket_client_from_file("datadesc_usage.out",&sock));
+    TRY(gras_socket_client_from_file(filename,&sock));
   if (direction == WRITE || direction == RW)
     TRY(gras_datadesc_send(sock, type, src));
   if (direction == RW) 
-    gras_socket_close(&sock);
+    gras_socket_close(sock);
    
   /* read */
   if (direction == RW) 
-    TRY(gras_socket_server_from_file("datadesc_usage.out",&sock));
+    TRY(gras_socket_server_from_file(filename,&sock));
 
   if (direction == READ || direction == RW)
-    TRY(gras_datadesc_recv(sock, type, gras_arch_selfid(), dst));
+    TRY(gras_datadesc_recv(sock, type, r_arch, dst));
 
   if (direction == RW) 
-    gras_socket_close(&sock);
+    gras_socket_close(sock);
   
   return no_error;
 }
@@ -78,7 +81,7 @@ gras_error_t test_float(gras_socket_t *sock, int direction) {
   INFO0("==== Test on float ====");
   TRY(write_read(gras_datadesc_by_name("float"), &i,&j, sock,direction));
   if (direction == READ || direction == RW) {
-    gras_assert(i == j);
+    gras_assert2(i == j,"%f != %f",i,j);
   }
   return no_error;
 }
@@ -89,13 +92,11 @@ gras_error_t test_array(gras_socket_t *sock, int direction) {
   gras_error_t errcode;
   gras_datadesc_type_t *my_type;
   
-  array i,j;
+  array i = { 35212,-6226,74337,11414,7733};
+  array j;
   int cpt;
 
   INFO0("==== Test on fixed array ====");
-  for (cpt=0; cpt<SIZE; cpt++) {
-    i[cpt] = rand();
-  }
 
   TRY(gras_datadesc_declare_array_fixed("fixed int array", 
                                        gras_datadesc_by_name("int"),
@@ -103,9 +104,11 @@ gras_error_t test_array(gras_socket_t *sock, int direction) {
 
   TRY(write_read(my_type, &i,&j, sock,direction));
   if (direction == READ || direction == RW) {
-    for (cpt=0; cpt<SIZE; cpt++)
+    for (cpt=0; cpt<SIZE; cpt++) {
+      DEBUG1("Test spot %d",cpt);
       gras_assert4(i[cpt] == j[cpt],"i[%d]=%d  !=  j[%d]=%d",
                   cpt,i[cpt],cpt,j[cpt]);
+    }
   }
   return no_error;
 }
@@ -136,20 +139,14 @@ gras_error_t test_intref(gras_socket_t *sock, int direction) {
  ***/ 
 gras_error_t test_string(gras_socket_t *sock, int direction) {
   gras_error_t errcode;
-  gras_datadesc_type_t *my_type;
   char *i=strdup("Some data"), *j=NULL;
   int cpt;
   
-  INFO0("==== Test on string (dynamic array) ====");
-  TRY(gras_datadesc_declare_ref("string*",
-                               gras_datadesc_by_name("string"),
-                               &my_type));
-
-  TRY(write_read(gras_datadesc_by_name("string*"), &i,&j,
+  INFO0("==== Test on string (ref to dynamic array) ====");
+  TRY(write_read(gras_datadesc_by_name("string"), &i,&j,
                 sock,direction));
   if (direction == READ || direction == RW) {
     for (cpt=0; cpt<strlen(i); cpt++) {
-      fprintf(stderr,"%d ", cpt);
       gras_assert4(i[cpt] == j[cpt],"i[%d]=%c  !=  j[%d]=%c",
                   cpt,i[cpt],cpt,j[cpt]);
     } 
@@ -189,8 +186,8 @@ gras_error_t test_homostruct(gras_socket_t *sock, int direction) {
   /* init a value, exchange it and check its validity*/
   if (! (i=malloc(sizeof(homostruct))) )
     RAISE_MALLOC;
-  i->a = rand();  i->b = rand();
-  i->c = rand();  i->d = rand();
+  i->a = 2235;    i->b = 433425;
+  i->c = -23423;  i->d = -235235;
 
   TRY(write_read(my_type, &i,&j, sock,direction));
   if (direction == READ || direction == RW) {
@@ -243,7 +240,7 @@ gras_error_t test_hetestruct(gras_socket_t *sock, int direction) {
   if (direction == READ || direction == RW) {
     gras_assert(i->c1 == j->c1);
     gras_assert(i->c2 == j->c2);
-    gras_assert(i->l1 == j->l1);
+    gras_assert2(i->l1 == j->l1,"i->l1(=%d)  !=  j->l1(=%d)",i->l1,j->l1);
     gras_assert(i->l2 == j->l2);
     free(j);
   }
@@ -278,8 +275,8 @@ gras_error_t test_nestedstruct(gras_socket_t *sock, int direction) {
   /* init a value, exchange it and check its validity*/
   if (! (i=malloc(sizeof(nestedstruct))) )
     RAISE_MALLOC;
-  i->homo.a = rand();  i->homo.b = rand();
-  i->homo.c = rand();  i->homo.d = rand();
+  i->homo.a = 235231;  i->homo.b = -124151;
+  i->homo.c = 211551;  i->homo.d = -664222;
   i->hete.c1 = 's'; i->hete.l1 = 123455;
   i->hete.c2 = 'e'; i->hete.l2 = 774531;
 
@@ -353,7 +350,7 @@ gras_error_t test_chain_list(gras_socket_t *sock, int direction) {
   INFO0("==== Test on chained list ====");
 
   /* init a value, exchange it and check its validity*/
-  i = cons( rand(), cons( rand() , cons( rand(), NULL)));
+  i = cons( 12355, cons( 246264 , cons( 23263, NULL)));
   j = NULL;
 
   TRY(write_read(gras_datadesc_by_name("chained_list_t*"),
@@ -376,7 +373,7 @@ gras_error_t test_graph(gras_socket_t *sock, int direction) {
 
   INFO0("==== Test on graph (cyclique chained list) ====");
   /* init a value, exchange it and check its validity*/
-  i = cons( rand(), cons( rand() , cons( rand(), NULL)));
+  i = cons( 1151515, cons( -232362 , cons( 222552, NULL)));
   i->l->l->l = i;
   j = NULL;
 
@@ -397,12 +394,13 @@ gras_error_t test_graph(gras_socket_t *sock, int direction) {
                 "j=%p; &j=%p",
                 j,j->l->l->l, 
                 j ,&j);
-    i->l->l->l = NULL;
     j->l->l->l = NULL;
+    i->l->l->l = NULL;
     gras_assert(list_eq(i,j));
 
     list_free(j);
   }
+  i->l->l->l = NULL; /* do this even in READ mode */
   list_free(i);
   return no_error;
 }
@@ -422,30 +420,42 @@ typedef struct { /* structure presented in the IEEE article */
 int main(int argc,char *argv[]) {
   gras_error_t errcode;
   gras_socket_t *sock;
-  int direction = RW; // READ; // WRITE
-
-  gras_init_defaultlog(&argc,argv,
-                      "DataDesc.thresh=verbose"
-                      " test.thresh=debug"
-                      //" set.thresh=debug"
-                      );
-  if (argc >= 2) {
-    if (!strcmp(argv[1], "--read"))
+  int direction = RW;
+  int cpt;
+  char r_arch_char = gras_arch_selfid();
+
+  gras_init_defaultlog(&argc,argv,NULL);
+
+  for (cpt=1; cpt<argc; cpt++) {
+    if (!strcmp(argv[cpt], "--read")) {
       direction = READ;
-    if (!strcmp(argv[1], "--write"))
+    } else if (!strcmp(argv[cpt], "--write")) {
       direction = WRITE;
+    } else {
+       filename=argv[cpt];
+    }
   }
     
-  if (direction == WRITE) 
-    TRYFAIL(gras_socket_client_from_file("datadesc_usage.out",&sock));
-  if (direction == READ) 
-    TRYFAIL(gras_socket_server_from_file("datadesc_usage.out",&sock));
-
+  if (direction == WRITE) {
+    TRYFAIL(gras_socket_client_from_file(filename,&sock));
+    TRY(gras_datadesc_send(sock, gras_datadesc_by_name("char"),
+                          &r_arch_char));
+  }
+  if (direction == READ) {
+    TRYFAIL(gras_socket_server_from_file(filename,&sock));
+    TRY(gras_datadesc_recv(sock, gras_datadesc_by_name("char"),
+                          gras_arch_selfid(), &r_arch_char));
+    INFO3("This datafile was generated on %s (%d), I'm %s.",
+         gras_datadesc_arch_name(r_arch_char),(int)r_arch_char,
+         gras_datadesc_arch_name(gras_arch_selfid()));
+  }
+  r_arch = (int)r_arch_char;
+  
   TRYFAIL(test_int(sock,direction));    
   TRYFAIL(test_float(sock,direction));  
   TRYFAIL(test_array(sock,direction));  
   TRYFAIL(test_intref(sock,direction)); 
-
+  
   TRYFAIL(test_string(sock,direction)); 
 
   TRYFAIL(test_homostruct(sock,direction));
@@ -457,7 +467,8 @@ int main(int argc,char *argv[]) {
   TRYFAIL(test_graph(sock,direction));
 
   if (direction != RW) 
-    gras_socket_close(&sock);
+    gras_socket_close(sock);
   gras_exit();
   return 0;
 }
+