Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Version 0.5 (protocol not changed; ABI changed)
[simgrid.git] / testsuite / gras / datadesc_usage.c
index 253b03e..45058ae 100644 (file)
@@ -65,6 +65,7 @@ gras_error_t test_chain_list(gras_socket_t *sock, int direction);
 gras_error_t test_graph(gras_socket_t *sock, int direction);
 
 gras_error_t test_pbio(gras_socket_t *sock, int direction);
+gras_error_t test_clause(gras_socket_t *sock, int direction);
 
 /* defined in datadesc_structures.c, which in perl generated */
 gras_error_t test_structures(gras_socket_t *sock, int direction); 
@@ -117,9 +118,9 @@ gras_error_t test_array(gras_socket_t *sock, int direction) {
 
   INFO0("---- Test on fixed array ----");
 
-  TRY(gras_datadesc_declare_array_fixed("fixed int array", 
-                                       gras_datadesc_by_name("int"),
-                                       SIZE, &my_type));
+  TRY(gras_datadesc_array_fixed("fixed int array", 
+                               gras_datadesc_by_name("int"),
+                               SIZE, &my_type));
 
   TRY(write_read(my_type, &i,&j, sock,direction));
   if (direction == READ || direction == RW) {
@@ -142,7 +143,7 @@ gras_error_t test_intref(gras_socket_t *sock, int direction) {
 
   INFO1("---- Test on a reference to an integer (%p) ----",i);
 
-  TRY(gras_datadesc_declare_ref("int*",gras_datadesc_by_name("int"),&my_type));
+  TRY(gras_datadesc_ref("int*",gras_datadesc_by_name("int"),&my_type));
 
   TRY(write_read(my_type, &i,&j, sock,direction));
   if (direction == READ || direction == RW) {
@@ -189,19 +190,19 @@ gras_error_t test_homostruct(gras_socket_t *sock, int direction) {
 
   INFO0("---- Test on homogeneous structure ----");
   /* create descriptor */
-  TRY(gras_datadesc_declare_struct("homostruct",&my_type));
-  TRY(gras_datadesc_declare_struct_append(my_type,"a",
-                                         gras_datadesc_by_name("signed int")));
-  TRY(gras_datadesc_declare_struct_append(my_type,"b",
-                                         gras_datadesc_by_name("int")));
-  TRY(gras_datadesc_declare_struct_append(my_type,"c",
-                                         gras_datadesc_by_name("int")));
-  TRY(gras_datadesc_declare_struct_append(my_type,"d",
-                                         gras_datadesc_by_name("int")));
-  gras_datadesc_declare_struct_close(my_type);
-  TRY(gras_datadesc_declare_ref("homostruct*",
-                               gras_datadesc_by_name("homostruct"),
-                               &my_type));
+  TRY(gras_datadesc_struct("homostruct",&my_type));
+  TRY(gras_datadesc_struct_append(my_type,"a",
+                                 gras_datadesc_by_name("signed int")));
+  TRY(gras_datadesc_struct_append(my_type,"b",
+                                 gras_datadesc_by_name("int")));
+  TRY(gras_datadesc_struct_append(my_type,"c",
+                                 gras_datadesc_by_name("int")));
+  TRY(gras_datadesc_struct_append(my_type,"d",
+                                 gras_datadesc_by_name("int")));
+  gras_datadesc_struct_close(my_type);
+  TRY(gras_datadesc_ref("homostruct*",
+                       gras_datadesc_by_name("homostruct"),
+                       &my_type));
 
   /* init a value, exchange it and check its validity*/
   if (! (i=malloc(sizeof(homostruct))) )
@@ -237,19 +238,18 @@ gras_error_t test_hetestruct(gras_socket_t *sock, int direction) {
 
   INFO0("---- Test on heterogeneous structure ----");
   /* create descriptor */
-  TRY(gras_datadesc_declare_struct("hetestruct",&my_type));
-  TRY(gras_datadesc_declare_struct_append(my_type,"c1",
-                                         gras_datadesc_by_name("unsigned char")));
-  TRY(gras_datadesc_declare_struct_append(my_type,"l1",
-                                         gras_datadesc_by_name("unsigned long int")));
-  TRY(gras_datadesc_declare_struct_append(my_type,"c2",
-                                         gras_datadesc_by_name("unsigned char")));
-  TRY(gras_datadesc_declare_struct_append(my_type,"l2",
-                                         gras_datadesc_by_name("unsigned long int")));
-  gras_datadesc_declare_struct_close(my_type);
-  TRY(gras_datadesc_declare_ref("hetestruct*",
-                               gras_datadesc_by_name("hetestruct"),
-                               &my_type));
+  TRY(gras_datadesc_struct("hetestruct",&my_type));
+  TRY(gras_datadesc_struct_append(my_type,"c1",
+                                 gras_datadesc_by_name("unsigned char")));
+  TRY(gras_datadesc_struct_append(my_type,"l1",
+                                 gras_datadesc_by_name("unsigned long int")));
+  TRY(gras_datadesc_struct_append(my_type,"c2",
+                                 gras_datadesc_by_name("unsigned char")));
+  TRY(gras_datadesc_struct_append(my_type,"l2",
+                                 gras_datadesc_by_name("unsigned long int")));
+  gras_datadesc_struct_close(my_type);
+  TRY(gras_datadesc_ref("hetestruct*", gras_datadesc_by_name("hetestruct"),
+                       &my_type));
 
   /* init a value, exchange it and check its validity*/
   if (! (i=malloc(sizeof(hetestruct))) )
@@ -261,7 +261,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_assert2(i->l1 == j->l1,"i->l1(=%d)  !=  j->l1(=%d)",i->l1,j->l1);
+    gras_assert2(i->l1 == j->l1,"i->l1(=%ld)  !=  j->l1(=%ld)",i->l1,j->l1);
     gras_assert(i->l2 == j->l2);
     free(j);
   }
@@ -283,16 +283,15 @@ gras_error_t test_nestedstruct(gras_socket_t *sock, int direction) {
 
   INFO0("---- Test on nested structures ----");
   /* create descriptor */
-  TRY(gras_datadesc_declare_struct("nestedstruct",&my_type));
+  TRY(gras_datadesc_struct("nestedstruct",&my_type));
 
-  TRY(gras_datadesc_declare_struct_append(my_type,"hete",
-                                         gras_datadesc_by_name("hetestruct")));
-  TRY(gras_datadesc_declare_struct_append(my_type,"homo",
-                                         gras_datadesc_by_name("homostruct")));
-  gras_datadesc_declare_struct_close(my_type);
-  TRY(gras_datadesc_declare_ref("nestedstruct*",
-                               gras_datadesc_by_name("nestedstruct"),
-                               &my_type));
+  TRY(gras_datadesc_struct_append(my_type,"hete",
+                                 gras_datadesc_by_name("hetestruct")));
+  TRY(gras_datadesc_struct_append(my_type,"homo",
+                                 gras_datadesc_by_name("homostruct")));
+  gras_datadesc_struct_close(my_type);
+  TRY(gras_datadesc_ref("nestedstruct*", gras_datadesc_by_name("nestedstruct"),
+                       &my_type));
 
   /* init a value, exchange it and check its validity*/
   if (! (i=malloc(sizeof(nestedstruct))) )
@@ -335,13 +334,12 @@ gras_error_t declare_chained_list_type(void) {
   gras_error_t errcode;
   gras_datadesc_type_t *my_type,*ref_my_type;
 
-  TRY(gras_datadesc_declare_struct("chained_list_t",&my_type));
-  TRY(gras_datadesc_declare_ref("chained_list_t*",my_type,&ref_my_type));
+  TRY(gras_datadesc_struct("chained_list_t",&my_type));
+  TRY(gras_datadesc_ref("chained_list_t*",my_type,&ref_my_type));
 
-  TRY(gras_datadesc_declare_struct_append(my_type,"v",
-                                         gras_datadesc_by_name("int")));
-  TRY(gras_datadesc_declare_struct_append(my_type,"l",ref_my_type));
-  gras_datadesc_declare_struct_close(my_type);
+  TRY(gras_datadesc_struct_append(my_type,"v", gras_datadesc_by_name("int")));
+  TRY(gras_datadesc_struct_append(my_type,"l", ref_my_type));
+  gras_datadesc_struct_close(my_type);
 
   return no_error;
 }
@@ -522,6 +520,64 @@ gras_error_t test_pbio(gras_socket_t *sock, int direction) {
   return no_error;
 }
 
+typedef struct {
+   int num_lits; /* size of next array */
+   int* literals;
+} Clause;
+
+void Clause_pre_cb  (gras_cbps_t *vars,void *data);
+
+void Clause_pre_cb(gras_cbps_t *vars, void *data) {
+  gras_cbps_i_push(vars, (long int) ((Clause*)data)->num_lits);
+}
+
+gras_error_t test_clause(gras_socket_t *sock, int direction) {
+  gras_error_t errcode;
+  gras_datadesc_type_t *ddt,*array_t;
+  Clause *i,*j;
+  int cpt;
+  
+  INFO0("---- Test on struct containing dynamic array and its size (cbps test) ----");
+
+  /* create and fill the struct */
+  if (! (i=malloc(sizeof(Clause))) )
+    RAISE_MALLOC;
+
+  i->num_lits = 5432;
+  if (! (i->literals = malloc(sizeof(int) * i->num_lits)) )
+    RAISE_MALLOC;
+  for (cpt=0; cpt<i->num_lits; cpt++)
+    i->literals[cpt] = cpt * cpt - ((cpt * cpt) / 2);
+  DEBUG3("created data=%p (within %p @%p)",&(i->num_lits),i,&i);
+  DEBUG1("created count=%d",i->num_lits);
+
+  /* create the damn type descriptor */
+  TRYFAIL(gras_datadesc_struct("Clause",&ddt));
+
+  gras_datadesc_cb_send(ddt,Clause_pre_cb); /* push the size of the arrray */
+  
+  TRYFAIL(gras_datadesc_struct_append(ddt,"num_lits", 
+                                     gras_datadesc_by_name("int")));
+
+  TRYFAIL(gras_datadesc_ref_pop_arr(gras_datadesc_by_name("int"), &array_t));
+  TRYFAIL(gras_datadesc_struct_append(ddt,"literals",array_t));
+  gras_datadesc_struct_close(ddt);
+  TRYFAIL(gras_datadesc_ref("Clause*",ddt,&ddt));
+
+  TRY(write_read(ddt, &i,&j, sock,direction));
+  if (direction == READ || direction == RW) {
+    gras_assert(i->num_lits == j->num_lits);
+    for (cpt=0; cpt<i->num_lits; cpt++)
+      gras_assert(i->literals[cpt] == j->literals[cpt]);
+    
+    free(j->literals);
+    free(j);
+  }
+  free(i->literals);
+  free(i);
+  return no_error;
+}
+
 int main(int argc,char *argv[]) {
   gras_error_t errcode;
   gras_socket_t *sock;
@@ -556,7 +612,6 @@ int main(int argc,char *argv[]) {
   }
   r_arch = (int)r_arch_char;
   
-  
   TRYFAIL(test_int(sock,direction));    
   TRYFAIL(test_float(sock,direction));  
   TRYFAIL(test_double(sock,direction));  
@@ -573,10 +628,12 @@ int main(int argc,char *argv[]) {
 
   TRYFAIL(declare_chained_list_type());
   TRYFAIL(test_chain_list(sock,direction));
-  TRYFAIL(test_graph(sock,direction));
+  //  TRYFAIL(test_graph(sock,direction));
 
   TRYFAIL(test_pbio(sock,direction));
 
+  TRYFAIL(test_clause(sock,direction));
+
   if (direction != RW) 
     gras_socket_close(sock);
   gras_exit();