Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to exchange dynars
[simgrid.git] / testsuite / gras / datadesc_usage.c
index 5ff53f0..bf5d90d 100644 (file)
@@ -55,6 +55,7 @@ xbt_error_t test_int(gras_socket_t sock, int direction);
 xbt_error_t test_float(gras_socket_t sock, int direction);
 xbt_error_t test_double(gras_socket_t sock, int direction);
 xbt_error_t test_array(gras_socket_t sock, int direction);
+xbt_error_t test_dynar_scal(gras_socket_t sock, int direction);
 xbt_error_t test_intref(gras_socket_t sock, int direction);
 xbt_error_t test_string(gras_socket_t sock, int direction);
 
@@ -63,6 +64,7 @@ xbt_error_t test_hetestruct(gras_socket_t sock, int direction);
 xbt_error_t test_nestedstruct(gras_socket_t sock, int direction);
 xbt_error_t test_chain_list(gras_socket_t sock, int direction);
 xbt_error_t test_graph(gras_socket_t sock, int direction);
+xbt_error_t test_dynar_ref(gras_socket_t sock, int direction);
 
 xbt_error_t test_pbio(gras_socket_t sock, int direction);
 xbt_error_t test_clause(gras_socket_t sock, int direction);
@@ -132,6 +134,39 @@ xbt_error_t test_array(gras_socket_t sock, int direction) {
   }
   return no_error;
 }
+/*** Dynar of scalar ***/
+
+xbt_error_t test_dynar_scal(gras_socket_t sock, int direction){
+  xbt_error_t errcode;
+  gras_datadesc_type_t my_type;
+  xbt_dynar_t i,j;
+  int cpt;
+   
+  INFO0("---- Test on dynar containing integers ----");
+  my_type = gras_datadesc_dynar(gras_datadesc_by_name("int"),NULL);
+  i = xbt_dynar_new(sizeof(int),NULL);
+  for (cpt=0; cpt<64; cpt++) {
+    xbt_dynar_push_as(i,int,cpt); 
+    DEBUG2("Push %d, length=%lu",cpt, xbt_dynar_length(i));
+  }
+/*  xbt_dynar_dump(i);*/
+  TRY(write_read(my_type, &i,&j, sock, direction));
+/*  xbt_dynar_dump(j);*/
+  if (direction == READ || direction == RW) {
+     for (cpt=0; cpt<64; cpt++){
+       int ret=xbt_dynar_get_as(j,cpt,int);
+       if (cpt != ret) {
+          CRITICAL3("The retrieved value for cpt=%d is not the same than the injected one (%d!=%d)",
+                    cpt,ret,cpt);
+          xbt_abort();
+       }
+     }
+     xbt_dynar_free(&j);
+  }
+  xbt_dynar_free(&i);
+
+  return no_error;
+}
 xbt_error_t test_intref(gras_socket_t sock, int direction) {
   xbt_error_t errcode;
   gras_datadesc_type_t my_type;
@@ -421,6 +456,47 @@ xbt_error_t test_graph(gras_socket_t sock, int direction) {
   return no_error;
 }
 
+
+/*** Dynar of references ***/
+static void free_string(void *d){ /* used to free the data in dynar */
+     free(*(void**)d);
+}
+xbt_error_t test_dynar_ref(gras_socket_t sock, int direction){
+  xbt_error_t errcode;
+  gras_datadesc_type_t my_type;
+  xbt_dynar_t i,j;
+  char buf[1024];
+  char *s1,*s2;
+  int cpt;
+   
+  INFO0("---- Test on dynar containing integers ----");
+  my_type = gras_datadesc_dynar(gras_datadesc_by_name("string"),&free_string);
+
+  i=xbt_dynar_new(sizeof(char*),&free_string);   
+  for (cpt=0; cpt< 64; cpt++) {
+    sprintf(buf,"%d",cpt);
+    s1=strdup(buf);
+    xbt_dynar_push(i,&s1);
+  }
+
+  TRY(write_read(my_type, &i,&j, sock, direction));
+  if (direction == READ || direction == RW) {
+     for (cpt=0; cpt< 64; cpt++) {
+       sprintf(buf,"%d",cpt);
+       xbt_dynar_shift(j,&s2);
+       xbt_assert2 (!strcmp(buf,s2),
+                    "The retrieved value is not the same than the injected one (%s!=%s)",
+                    buf,s2);
+       free(s2);
+     }
+     xbt_dynar_free(&j);
+  }
+  xbt_dynar_free(&i);
+
+  return no_error;
+}
+
+
 /**** PBIO *****/
 GRAS_DEFINE_TYPE(s_pbio,
 struct s_pbio{ /* structure presented in the IEEE article */
@@ -441,76 +517,76 @@ struct s_pbio{ /* structure presented in the IEEE article */
 };
                 )
 typedef struct s_pbio pbio_t;
-pbio_t pbio_i, pbio_j;
 
 xbt_error_t test_pbio(gras_socket_t sock, int direction) {
   xbt_error_t errcode;
   int cpt;
   int cpt2;
   gras_datadesc_type_t pbio_type;
+  pbio_t i, j;
 
   INFO0("---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ----");
   pbio_type = gras_datadesc_by_symbol(s_pbio);
 
   /* Fill in that damn struct */
-  pbio_i.Cnstatv = 325115;
+  i.Cnstatv = 325115;
   for (cpt=0; cpt<12; cpt++) 
-    pbio_i.Cstatev[cpt] = ((double) cpt) * -2361.11;
-  pbio_i.Cnprops = -37373;
+    i.Cstatev[cpt] = ((double) cpt) * -2361.11;
+  i.Cnprops = -37373;
   for (cpt=0; cpt<110; cpt++)
-    pbio_i.Cprops[cpt] = cpt * 100.0;
+    i.Cprops[cpt] = cpt * 100.0;
   for (cpt=0; cpt<4; cpt++)
-    pbio_i.Cndi[cpt] = cpt * 23262;
-  pbio_i.Cnshr = -4634;
-  pbio_i.Cnpt = 114142;
-  pbio_i.Cdtime = -11515.662;
-  pbio_i.Ctime[0] = 332523.226;
-  pbio_i.Ctime[1] = -26216.113;
-  pbio_i.Cntens = 235211411;
+    i.Cndi[cpt] = cpt * 23262;
+  i.Cnshr = -4634;
+  i.Cnpt = 114142;
+  i.Cdtime = -11515.662;
+  i.Ctime[0] = 332523.226;
+  i.Ctime[1] = -26216.113;
+  i.Cntens = 235211411;
   
   for (cpt=0; cpt<3; cpt++) {
     for (cpt2=0; cpt2<373; cpt2++)
-      pbio_i.Cdfgrd0[cpt2][cpt] = ((double)cpt) * ((double)cpt2);
+      i.Cdfgrd0[cpt2][cpt] = ((double)cpt) * ((double)cpt2);
     for (cpt2=0; cpt2<3; cpt2++)
-      pbio_i.Cdfgrd1[cpt][cpt2] = -((double)cpt) * ((double)cpt2);
+      i.Cdfgrd1[cpt][cpt2] = -((double)cpt) * ((double)cpt2);
   }
   for (cpt=0; cpt<106; cpt++) {
-    pbio_i.Cstress[cpt]=(double)cpt * 22.113;
+    i.Cstress[cpt]=(double)cpt * 22.113;
     for (cpt2=0; cpt2<106; cpt2++) 
-      pbio_i.Cddsdde[cpt][cpt2] = ((double)cpt) * ((double)cpt2);
+      i.Cddsdde[cpt][cpt2] = ((double)cpt) * ((double)cpt2);
   }
   TRY(write_read(gras_datadesc_by_symbol(s_pbio),
-                &pbio_i,&pbio_j, sock,direction));
+                &i,&j, sock,direction));
   if (direction == READ || direction == RW) {
     /* Check that the data match */
-    xbt_assert(pbio_i.Cnstatv == pbio_j.Cnstatv);
+    xbt_assert(i.Cnstatv == j.Cnstatv);
     for (cpt=0; cpt<12; cpt++)
-      xbt_assert4(pbio_i.Cstatev[cpt] == pbio_j.Cstatev[cpt],
+      xbt_assert4(i.Cstatev[cpt] == j.Cstatev[cpt],
                  "i.Cstatev[%d] (=%f) != j.Cstatev[%d] (=%f)",
-                 cpt,pbio_i.Cstatev[cpt],cpt,pbio_j.Cstatev[cpt]);
-    xbt_assert(pbio_i.Cnprops == pbio_j.Cnprops);
+                 cpt,i.Cstatev[cpt],cpt,j.Cstatev[cpt]);
+    xbt_assert(i.Cnprops == j.Cnprops);
     for (cpt=0; cpt<110; cpt++)
-      xbt_assert(pbio_i.Cprops[cpt] == pbio_j.Cprops[cpt]);
+      xbt_assert(i.Cprops[cpt] == j.Cprops[cpt]);
     for (cpt=0; cpt<4; cpt++) 
-      xbt_assert(pbio_i.Cndi[cpt] == pbio_j.Cndi[cpt]);
-    xbt_assert(pbio_i.Cnshr == pbio_j.Cnshr);
-    xbt_assert(pbio_i.Cnpt == pbio_j.Cnpt);
-    xbt_assert(pbio_i.Cdtime == pbio_j.Cdtime);
-    xbt_assert(pbio_i.Ctime[0] == pbio_j.Ctime[0]);
-    xbt_assert(pbio_i.Ctime[1] == pbio_j.Ctime[1]);
-    xbt_assert(pbio_i.Cntens == pbio_j.Cntens);
+      xbt_assert(i.Cndi[cpt] == j.Cndi[cpt]);
+    xbt_assert(i.Cnshr == j.Cnshr);
+    xbt_assert(i.Cnpt == j.Cnpt);
+    xbt_assert(i.Cdtime == j.Cdtime);
+    xbt_assert(i.Ctime[0] == j.Ctime[0]);
+    xbt_assert(i.Ctime[1] == j.Ctime[1]);
+    xbt_assert(i.Cntens == j.Cntens);
     for (cpt=0; cpt<3; cpt++) {
       for (cpt2=0; cpt2<373; cpt2++)
-       xbt_assert(pbio_i.Cdfgrd0[cpt2][cpt] == pbio_j.Cdfgrd0[cpt2][cpt]);
+       xbt_assert(i.Cdfgrd0[cpt2][cpt] == j.Cdfgrd0[cpt2][cpt]);
       for (cpt2=0; cpt2<3; cpt2++)
-       xbt_assert(pbio_i.Cdfgrd1[cpt][cpt2] == pbio_j.Cdfgrd1[cpt][cpt2]);
+       xbt_assert(i.Cdfgrd1[cpt][cpt2] == j.Cdfgrd1[cpt][cpt2]);
     }
     for (cpt=0; cpt<106; cpt++) {
-      xbt_assert(pbio_i.Cstress[cpt] == pbio_j.Cstress[cpt]);
+      xbt_assert(i.Cstress[cpt] == j.Cstress[cpt]);
       for (cpt2=0; cpt2<106; cpt2++) 
-       xbt_assert4(pbio_i.Cddsdde[cpt][cpt2] == pbio_j.Cddsdde[cpt][cpt2],
+       xbt_assert4(i.Cddsdde[cpt][cpt2] == j.Cddsdde[cpt][cpt2],
                     "%f=i.Cddsdde[%d][%d] != j.Cddsdde[cpt][cpt2]=%f",
-                    pbio_i.Cddsdde[cpt][cpt2],cpt,cpt2,pbio_j.Cddsdde[cpt][cpt2]);
+                    i.Cddsdde[cpt][cpt2],cpt,cpt2,j.Cddsdde[cpt][cpt2]);
     }
   }
 
@@ -595,16 +671,17 @@ int main(int argc,char *argv[]) {
          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_double(sock,direction));  
-  TRYFAIL(test_array(sock,direction));  
+  TRYFAIL(test_array(sock,direction));
+  TRYFAIL(test_dynar_scal(sock,direction));  
   TRYFAIL(test_intref(sock,direction)); 
   
   TRYFAIL(test_string(sock,direction)); 
 
-     TRYFAIL(test_structures(sock,direction));
+  TRYFAIL(test_structures(sock,direction));
 
   TRYFAIL(test_homostruct(sock,direction));
   TRYFAIL(test_hetestruct(sock,direction));
@@ -613,6 +690,7 @@ int main(int argc,char *argv[]) {
   TRYFAIL(declare_chained_list_type());
   TRYFAIL(test_chain_list(sock,direction));
   TRYFAIL(test_graph(sock,direction)); 
+  TRYFAIL(test_dynar_ref(sock,direction));  
 
   TRYFAIL(test_pbio(sock,direction));