X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/483072928e0c397b39cb35eff642fdb8d2cad245..01021da3b27c6a5704bfa08cd0ce07be6b925e8b:/testsuite/gras/datadesc_usage.c?ds=sidebyside diff --git a/testsuite/gras/datadesc_usage.c b/testsuite/gras/datadesc_usage.c index 45a09ba59e..b6ee2ad6c0 100644 --- a/testsuite/gras/datadesc_usage.c +++ b/testsuite/gras/datadesc_usage.c @@ -11,8 +11,8 @@ #include #include -#include "../DataDesc/datadesc_interface.h" -GRAS_LOG_NEW_DEFAULT_CATEGORY(test); +#include "gras/DataDesc/datadesc_interface.h" +GRAS_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); #define READ 0 #define WRITE 1 @@ -22,12 +22,12 @@ 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); +write_read(gras_datadesc_type_t type,void *src, void *dst, + gras_socket_t sock, int direction); gras_error_t -write_read(gras_datadesc_type_t *type,void *src, void *dst, - gras_socket_t *sock, int direction) { +write_read(gras_datadesc_type_t type,void *src, void *dst, + gras_socket_t sock, int direction) { gras_error_t errcode; /* write */ @@ -51,22 +51,28 @@ write_read(gras_datadesc_type_t *type,void *src, void *dst, return no_error; } -gras_error_t test_int(gras_socket_t *sock, int direction); -gras_error_t test_float(gras_socket_t *sock, int direction); -gras_error_t test_double(gras_socket_t *sock, int direction); -gras_error_t test_array(gras_socket_t *sock, int direction); -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 test_int(gras_socket_t sock, int direction); +gras_error_t test_float(gras_socket_t sock, int direction); +gras_error_t test_double(gras_socket_t sock, int direction); +gras_error_t test_array(gras_socket_t sock, int direction); +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 test_homostruct(gras_socket_t *sock, int direction); -gras_error_t test_hetestruct(gras_socket_t *sock, int direction); -gras_error_t test_nestedstruct(gras_socket_t *sock, int direction); -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_homostruct(gras_socket_t sock, int direction); +gras_error_t test_hetestruct(gras_socket_t sock, int direction); +gras_error_t test_nestedstruct(gras_socket_t sock, int direction); +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_pbio(gras_socket_t sock, int direction); +gras_error_t test_clause(gras_socket_t sock, int direction); -gras_error_t test_int(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); + + + +gras_error_t test_int(gras_socket_t sock, int direction) { gras_error_t errcode; int i=5,j; @@ -77,7 +83,7 @@ gras_error_t test_int(gras_socket_t *sock, int direction) { } return no_error; } -gras_error_t test_float(gras_socket_t *sock, int direction) { +gras_error_t test_float(gras_socket_t sock, int direction) { gras_error_t errcode; float i=5.0,j; @@ -88,7 +94,7 @@ gras_error_t test_float(gras_socket_t *sock, int direction) { } return no_error; } -gras_error_t test_double(gras_socket_t *sock, int direction) { +gras_error_t test_double(gras_socket_t sock, int direction) { gras_error_t errcode; double i=-3252355.1234,j; @@ -102,9 +108,9 @@ gras_error_t test_double(gras_socket_t *sock, int direction) { #define SIZE 5 typedef int array[SIZE]; -gras_error_t test_array(gras_socket_t *sock, int direction) { +gras_error_t test_array(gras_socket_t sock, int direction) { gras_error_t errcode; - gras_datadesc_type_t *my_type; + gras_datadesc_type_t my_type; array i = { 35212,-6226,74337,11414,7733}; array j; @@ -112,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)); + my_type=gras_datadesc_array_fixed("fixed int array", + gras_datadesc_by_name("int"), + SIZE); TRY(write_read(my_type, &i,&j, sock,direction)); if (direction == READ || direction == RW) { @@ -126,18 +132,17 @@ gras_error_t test_array(gras_socket_t *sock, int direction) { } return no_error; } -gras_error_t test_intref(gras_socket_t *sock, int direction) { +gras_error_t test_intref(gras_socket_t sock, int direction) { gras_error_t errcode; - gras_datadesc_type_t *my_type; + gras_datadesc_type_t my_type; int *i,*j; - if (! (i=malloc(sizeof(int))) ) - RAISE_MALLOC; + i=gras_new(int,1); *i=12345; INFO1("---- Test on a reference to an integer (%p) ----",i); - TRY(gras_datadesc_declare_ref("int*",gras_datadesc_by_name("int"),&my_type)); + my_type = gras_datadesc_ref("int*",gras_datadesc_by_name("int")); TRY(write_read(my_type, &i,&j, sock,direction)); if (direction == READ || direction == RW) { @@ -151,9 +156,9 @@ gras_error_t test_intref(gras_socket_t *sock, int direction) { /*** *** string (dynamic array) ***/ -gras_error_t test_string(gras_socket_t *sock, int direction) { +gras_error_t test_string(gras_socket_t sock, int direction) { gras_error_t errcode; - char *i=strdup("Some data"), *j=NULL; + char *i=gras_strdup("Some data"), *j=NULL; int cpt; INFO0("---- Test on string (ref to dynamic array) ----"); @@ -177,35 +182,34 @@ gras_error_t test_string(gras_socket_t *sock, int direction) { typedef struct { int a,b,c,d; } homostruct; -gras_error_t test_homostruct(gras_socket_t *sock, int direction) { +gras_error_t test_homostruct(gras_socket_t sock, int direction) { gras_error_t errcode; - gras_datadesc_type_t *my_type; + gras_datadesc_type_t my_type; homostruct *i, *j; 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"))); - TRY(gras_datadesc_declare_ref("homostruct*", - gras_datadesc_by_name("homostruct"), - &my_type)); + my_type=gras_datadesc_struct("homostruct"); + gras_datadesc_struct_append(my_type,"a", + gras_datadesc_by_name("signed int")); + gras_datadesc_struct_append(my_type,"b", + gras_datadesc_by_name("int")); + gras_datadesc_struct_append(my_type,"c", + gras_datadesc_by_name("int")); + gras_datadesc_struct_append(my_type,"d", + gras_datadesc_by_name("int")); + gras_datadesc_struct_close(my_type); + my_type=gras_datadesc_ref("homostruct*", + gras_datadesc_by_name("homostruct")); /* init a value, exchange it and check its validity*/ - if (! (i=malloc(sizeof(homostruct))) ) - RAISE_MALLOC; + i=gras_new(homostruct,1); 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) { - gras_assert(i->a == j->a); + gras_assert2(i->a == j->a,"i->a=%d != j->a=%d",i->a,j->a); gras_assert(i->b == j->b); gras_assert(i->c == j->c); gras_assert(i->d == j->d); @@ -224,29 +228,28 @@ typedef struct { unsigned char c2; unsigned long int l2; } hetestruct; -gras_error_t test_hetestruct(gras_socket_t *sock, int direction) { +gras_error_t test_hetestruct(gras_socket_t sock, int direction) { gras_error_t errcode; - gras_datadesc_type_t *my_type; + gras_datadesc_type_t my_type; hetestruct *i, *j; 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"))); - TRY(gras_datadesc_declare_ref("hetestruct*", - gras_datadesc_by_name("hetestruct"), - &my_type)); + my_type=gras_datadesc_struct("hetestruct"); + gras_datadesc_struct_append(my_type,"c1", + gras_datadesc_by_name("unsigned char")); + gras_datadesc_struct_append(my_type,"l1", + gras_datadesc_by_name("unsigned long int")); + gras_datadesc_struct_append(my_type,"c2", + gras_datadesc_by_name("unsigned char")); + gras_datadesc_struct_append(my_type,"l2", + gras_datadesc_by_name("unsigned long int")); + gras_datadesc_struct_close(my_type); + my_type=gras_datadesc_ref("hetestruct*", gras_datadesc_by_name("hetestruct")); + /* init a value, exchange it and check its validity*/ - if (! (i=malloc(sizeof(hetestruct))) ) - RAISE_MALLOC; + i=gras_new(hetestruct,1); i->c1 = 's'; i->l1 = 123455; i->c2 = 'e'; i->l2 = 774531; @@ -254,7 +257,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); } @@ -269,26 +272,24 @@ typedef struct { hetestruct hete; homostruct homo; } nestedstruct; -gras_error_t test_nestedstruct(gras_socket_t *sock, int direction) { +gras_error_t test_nestedstruct(gras_socket_t sock, int direction) { gras_error_t errcode; - gras_datadesc_type_t *my_type; + gras_datadesc_type_t my_type; nestedstruct *i, *j; INFO0("---- Test on nested structures ----"); /* create descriptor */ - TRY(gras_datadesc_declare_struct("nestedstruct",&my_type)); + my_type=gras_datadesc_struct("nestedstruct"); - 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"))); - TRY(gras_datadesc_declare_ref("nestedstruct*", - gras_datadesc_by_name("nestedstruct"), - &my_type)); + gras_datadesc_struct_append(my_type,"hete", + gras_datadesc_by_name("hetestruct")); + gras_datadesc_struct_append(my_type,"homo", + gras_datadesc_by_name("homostruct")); + gras_datadesc_struct_close(my_type); + my_type=gras_datadesc_ref("nestedstruct*", gras_datadesc_by_name("nestedstruct")); /* init a value, exchange it and check its validity*/ - if (! (i=malloc(sizeof(nestedstruct))) ) - RAISE_MALLOC; + i=gras_new(nestedstruct,1); i->homo.a = 235231; i->homo.b = -124151; i->homo.c = 211551; i->homo.d = -664222; i->hete.c1 = 's'; i->hete.l1 = 123455; @@ -325,20 +326,20 @@ int list_eq(chained_list_t*i,chained_list_t*j); gras_error_t declare_chained_list_type(void) { gras_error_t errcode; - gras_datadesc_type_t *my_type,*ref_my_type; + 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)); + my_type=gras_datadesc_struct("chained_list_t"); + ref_my_type=gras_datadesc_ref("chained_list_t*",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_struct_append(my_type,"v", gras_datadesc_by_name("int")); + gras_datadesc_struct_append(my_type,"l", ref_my_type); + gras_datadesc_struct_close(my_type); return no_error; } chained_list_t * cons(int v, chained_list_t *l) { - chained_list_t *nl = malloc(sizeof (chained_list_t)); + chained_list_t *nl = gras_new(chained_list_t,1); nl->v = v; nl->l = l; @@ -357,7 +358,7 @@ int list_eq(chained_list_t*i,chained_list_t*j) { return 0; return list_eq(i->l, j->l); } -gras_error_t test_chain_list(gras_socket_t *sock, int direction) { +gras_error_t test_chain_list(gras_socket_t sock, int direction) { gras_error_t errcode; chained_list_t *i, *j; @@ -381,7 +382,7 @@ gras_error_t test_chain_list(gras_socket_t *sock, int direction) { /*** *** graph ***/ -gras_error_t test_graph(gras_socket_t *sock, int direction) { +gras_error_t test_graph(gras_socket_t sock, int direction) { gras_error_t errcode; chained_list_t *i, *j; @@ -391,6 +392,7 @@ gras_error_t test_graph(gras_socket_t *sock, int direction) { i->l->l->l = i; j = NULL; + gras_datadesc_cycle_set(gras_datadesc_by_name("chained_list_t*")); TRY(write_read(gras_datadesc_by_name("chained_list_t*"), &i,&j, sock,direction)); if (direction == READ || direction == RW) { @@ -432,28 +434,24 @@ struct s_pbio{ /* structure presented in the IEEE article */ double Cdtime; double Ctime[2]; int Cntens; - /* double Cdfgrd0[373][3]; double Cdfgrd1[3][3]; double Cstress[106]; double Cddsdde[106][106]; - */ }; ) typedef struct s_pbio pbio_t; -gras_error_t test_pbio(gras_socket_t *sock, int direction) { +gras_error_t test_pbio(gras_socket_t sock, int direction) { gras_error_t errcode; pbio_t i,j; int cpt; - // int cpt2; - gras_datadesc_type_t *pbio_type; + int cpt2; + gras_datadesc_type_t pbio_type; INFO0("---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ----"); pbio_type = gras_datadesc_by_symbol(s_pbio); - INFO1("sizof(s_pbio)=%d",sizeof(struct s_pbio)); - gras_datadesc_type_dump(gras_datadesc_by_name("double[373]")); - gras_datadesc_type_dump(pbio_type); + /* Fill in that damn struct */ i.Cnstatv = 325115; for (cpt=0; cpt<12; cpt++) @@ -469,7 +467,7 @@ gras_error_t test_pbio(gras_socket_t *sock, int direction) { 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++) i.Cdfgrd0[cpt2][cpt] = ((double)cpt) * ((double)cpt2); @@ -480,7 +478,7 @@ gras_error_t test_pbio(gras_socket_t *sock, int direction) { i.Cstress[cpt]=(double)cpt * 22.113; for (cpt2=0; cpt2<106; cpt2++) i.Cddsdde[cpt][cpt2] = ((double)cpt) * ((double)cpt2); - }*/ + } TRY(write_read(gras_datadesc_by_symbol(s_pbio), &i,&j, sock,direction)); if (direction == READ || direction == RW) { @@ -499,7 +497,6 @@ gras_error_t test_pbio(gras_socket_t *sock, int direction) { gras_assert(i.Ctime[0] == j.Ctime[0]); gras_assert(i.Ctime[1] == j.Ctime[1]); gras_assert(i.Cntens == j.Cntens); - /* for (cpt=0; cpt<3; cpt++) { for (cpt2=0; cpt2<373; cpt2++) gras_assert(i.Cdfgrd0[cpt2][cpt] == j.Cdfgrd0[cpt2][cpt]); @@ -512,15 +509,60 @@ gras_error_t test_pbio(gras_socket_t *sock, int direction) { gras_assert4(i.Cddsdde[cpt][cpt2] == j.Cddsdde[cpt][cpt2], "%f=i.Cddsdde[%d][%d] != j.Cddsdde[cpt][cpt2]=%f", i.Cddsdde[cpt][cpt2],cpt,cpt2,j.Cddsdde[cpt][cpt2]); - }*/ + } } return no_error; } +GRAS_DEFINE_TYPE(s_clause, +struct s_clause { + int num_lits; + int *literals GRAS_ANNOTE(size,num_lits); /* Tells GRAS where to find the size */ +};) +typedef struct s_clause Clause; + +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 */ + i=gras_new(Clause,1); + + i->num_lits = 5432; + i->literals = gras_new(int, i->num_lits); + for (cpt=0; cptnum_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 */ + ddt = gras_datadesc_by_symbol(s_clause); +/* gras_datadesc_type_dump(ddt); */ + + ddt=gras_datadesc_ref("Clause*",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; cptnum_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; + gras_socket_t sock; int direction = RW; int cpt; char r_arch_char = gras_arch_selfid(); @@ -552,7 +594,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)); @@ -561,16 +602,20 @@ int main(int argc,char *argv[]) { TRYFAIL(test_string(sock,direction)); + TRYFAIL(test_structures(sock,direction)); + TRYFAIL(test_homostruct(sock,direction)); TRYFAIL(test_hetestruct(sock,direction)); TRYFAIL(test_nestedstruct(sock,direction)); 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();