X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e2577d0360f31128b87c748dc9a3253b2ed87727..483072928e0c397b39cb35eff642fdb8d2cad245:/testsuite/gras/datadesc_usage.c diff --git a/testsuite/gras/datadesc_usage.c b/testsuite/gras/datadesc_usage.c index 144e17f73d..45a09ba59e 100644 --- a/testsuite/gras/datadesc_usage.c +++ b/testsuite/gras/datadesc_usage.c @@ -14,116 +14,159 @@ #include "../DataDesc/datadesc_interface.h" GRAS_LOG_NEW_DEFAULT_CATEGORY(test); +#define READ 0 +#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); +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) { +write_read(gras_datadesc_type_t *type,void *src, void *dst, + gras_socket_t *sock, int direction) { gras_error_t errcode; - gras_socket_t *sock; /* write */ - TRY(gras_socket_client_from_file("datadesc_usage.out",&sock)); - TRY(gras_datadesc_send(sock, type, src)); - gras_socket_close(&sock); + if (direction == RW) + 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); /* read */ - TRY(gras_socket_server_from_file("datadesc_usage.out",&sock)); - TRY(gras_datadesc_recv(sock, type, gras_arch_selfid(), dst)); - gras_socket_close(&sock); + if (direction == RW) + TRY(gras_socket_server_from_file(filename,&sock)); + + if (direction == READ || direction == RW) + TRY(gras_datadesc_recv(sock, type, r_arch, dst)); + + if (direction == RW) + gras_socket_close(sock); return no_error; } -gras_error_t test_int(void); -gras_error_t test_float(void); -gras_error_t test_array(void); -gras_error_t test_intref(void); -gras_error_t test_string(void); +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(void); -gras_error_t test_hetestruct(void); -gras_error_t test_nestedstruct(void); -gras_error_t test_chain_list(void); -gras_error_t test_graph(void); +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_int(void) { +gras_error_t test_pbio(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; + + INFO0("---- Test on integer ----"); + TRY(write_read(gras_datadesc_by_name("int"), &i,&j, sock,direction)); + if (direction == READ || direction == RW) { + gras_assert(i == j); + } + return no_error; +} +gras_error_t test_float(gras_socket_t *sock, int direction) { gras_error_t errcode; - int i=5,*j=NULL; + float i=5.0,j; - INFO0("==== Test on integer ===="); - TRY(write_read(gras_datadesc_by_name("int"), (void*)&i,(void**) &j)); - gras_assert(i == *j); - free(j); + INFO0("---- Test on float ----"); + TRY(write_read(gras_datadesc_by_name("float"), &i,&j, sock,direction)); + if (direction == READ || direction == RW) { + gras_assert2(i == j,"%f != %f",i,j); + } return no_error; } -gras_error_t test_float(void) { +gras_error_t test_double(gras_socket_t *sock, int direction) { gras_error_t errcode; - float i=5.0,*j=NULL; + double i=-3252355.1234,j; - INFO0("==== Test on float ===="); - TRY(write_read(gras_datadesc_by_name("float"), (void*)&i,(void**) &j)); - gras_assert(i == *j); - free(j); + INFO0("---- Test on double ----"); + TRY(write_read(gras_datadesc_by_name("double"), &i,&j, sock,direction)); + if (direction == READ || direction == RW) { + gras_assert2(i == j,"%f != %f",i,j); + } return no_error; } #define SIZE 5 typedef int array[SIZE]; -gras_error_t test_array(void) { +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; cpta = rand(); i->b = rand(); - i->c = rand(); i->d = rand(); - j = NULL; - - TRY(write_read(my_type, (void*)i, (void**)&j)); - gras_assert(i->a == j->a); - gras_assert(i->b == j->b); - gras_assert(i->c == j->c); - gras_assert(i->d == j->d); - + 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_assert(i->b == j->b); + gras_assert(i->c == j->c); + gras_assert(i->d == j->d); + free(j); + } free(i); - free(j); return no_error; } @@ -178,12 +224,12 @@ typedef struct { unsigned char c2; unsigned long int l2; } hetestruct; -gras_error_t test_hetestruct(void) { +gras_error_t test_hetestruct(gras_socket_t *sock, int direction) { gras_error_t errcode; gras_datadesc_type_t *my_type; hetestruct *i, *j; - INFO0("==== Test on heterogeneous structure ===="); + INFO0("---- Test on heterogeneous structure ----"); /* create descriptor */ TRY(gras_datadesc_declare_struct("hetestruct",&my_type)); TRY(gras_datadesc_declare_struct_append(my_type,"c1", @@ -194,22 +240,25 @@ gras_error_t test_hetestruct(void) { 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)); /* init a value, exchange it and check its validity*/ if (! (i=malloc(sizeof(hetestruct))) ) RAISE_MALLOC; i->c1 = 's'; i->l1 = 123455; i->c2 = 'e'; i->l2 = 774531; - j = NULL; - - TRY(write_read(my_type, (void*)i, (void**)&j)); - gras_assert(i->c1 == j->c1); - gras_assert(i->c2 == j->c2); - gras_assert(i->l1 == j->l1); - gras_assert(i->l2 == j->l2); + TRY(write_read(my_type, &i,&j, sock,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_assert(i->l2 == j->l2); + free(j); + } free(i); - free(j); return no_error; } @@ -220,40 +269,44 @@ typedef struct { hetestruct hete; homostruct homo; } nestedstruct; -gras_error_t test_nestedstruct(void) { +gras_error_t test_nestedstruct(gras_socket_t *sock, int direction) { gras_error_t errcode; gras_datadesc_type_t *my_type; nestedstruct *i, *j; - INFO0("==== Test on nested structures ===="); + INFO0("---- Test on nested structures ----"); /* create descriptor */ TRY(gras_datadesc_declare_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"))); + TRY(gras_datadesc_declare_ref("nestedstruct*", + gras_datadesc_by_name("nestedstruct"), + &my_type)); /* 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; - j = NULL; - - TRY(write_read(my_type, (void*)i, (void**)&j)); - gras_assert(i->homo.a == j->homo.a); - gras_assert(i->homo.b == j->homo.b); - gras_assert(i->homo.c == j->homo.c); - gras_assert(i->homo.d == j->homo.d); - gras_assert(i->hete.c1 == j->hete.c1); - gras_assert(i->hete.c2 == j->hete.c2); - gras_assert(i->hete.l1 == j->hete.l1); - gras_assert(i->hete.l2 == j->hete.l2); + TRY(write_read(my_type, &i,&j, sock,direction)); + if (direction == READ || direction == RW) { + gras_assert(i->homo.a == j->homo.a); + gras_assert(i->homo.b == j->homo.b); + gras_assert(i->homo.c == j->homo.c); + gras_assert(i->homo.d == j->homo.d); + gras_assert(i->hete.c1 == j->hete.c1); + gras_assert(i->hete.c2 == j->hete.c2); + gras_assert(i->hete.l1 == j->hete.l1); + gras_assert(i->hete.l2 == j->hete.l2); + free(j); + } free(i); - free(j); return no_error; } @@ -265,9 +318,25 @@ struct s_chained_list { int v; chained_list_t *l; }; +gras_error_t declare_chained_list_type(void); chained_list_t *cons(int v, chained_list_t *l); void list_free(chained_list_t *l); 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; + + 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_declare_struct_append(my_type,"v", + gras_datadesc_by_name("int"))); + TRY(gras_datadesc_declare_struct_append(my_type,"l",ref_my_type)); + + return no_error; +} + chained_list_t * cons(int v, chained_list_t *l) { chained_list_t *nl = malloc(sizeof (chained_list_t)); @@ -288,105 +357,223 @@ 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(void) { +gras_error_t test_chain_list(gras_socket_t *sock, int direction) { gras_error_t errcode; - gras_datadesc_type_t *my_type,*ref_my_type; chained_list_t *i, *j; - INFO0("==== Test on chained list ===="); - /* create descriptor */ - 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_declare_struct_append(my_type,"v", - gras_datadesc_by_name("int"))); - TRY(gras_datadesc_declare_struct_append(my_type,"l",ref_my_type)); + 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(my_type, (void*)i, (void**)&j)); - gras_assert(list_eq(i,j)); + TRY(write_read(gras_datadesc_by_name("chained_list_t*"), + &i,&j, + sock,direction)); + if (direction == READ || direction == RW) { + gras_assert(list_eq(i,j)); + list_free(j); + } list_free(i); - list_free(j); return no_error; } /*** *** graph ***/ -gras_error_t test_graph(void) { +gras_error_t test_graph(gras_socket_t *sock, int direction) { gras_error_t errcode; - gras_datadesc_type_t *my_type; chained_list_t *i, *j; - INFO0("==== Test on graph (cyclique chained list) ===="); - my_type = gras_datadesc_by_name("chained_list_t*"); - gras_assert(my_type); - + 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->l->l->l = i->l; + i = cons( 1151515, cons( -232362 , cons( 222552, NULL))); + i->l->l->l = i; j = NULL; - TRY(write_read(my_type, (void*)&i, (void**)&j)); - INFO1("j=%p" ,j); - INFO1("j->l=%p" ,j->l); - INFO1("j->l->l=%p" ,j->l->l); - INFO1("j->l->l->l=%p",j->l->l->l); - gras_assert4(j->l->l->l == j->l, - "Received list is not cyclic. j->l=%p != j->l->l->l=%p\n" - "j=%p; &j=%p", - j->l,j->l->l->l, - j ,&j); - i->l->l->l = NULL; - j->l->l->l = NULL; - gras_assert(list_eq(i,j)); - + TRY(write_read(gras_datadesc_by_name("chained_list_t*"), + &i,&j, sock,direction)); + if (direction == READ || direction == RW) { + + DEBUG1("i=%p" ,i); + DEBUG1("i->l=%p" ,i->l); + DEBUG1("i->l->l=%p" ,i->l->l); + DEBUG1("i->l->l->l=%p",i->l->l->l); + DEBUG1("j=%p" ,j); + DEBUG1("j->l=%p" ,j->l); + DEBUG1("j->l->l=%p" ,j->l->l); + DEBUG1("j->l->l->l=%p",j->l->l->l); + gras_assert4(j->l->l->l == j, + "Received list is not cyclic. j=%p != j->l->l->l=%p\n" + "j=%p; &j=%p", + j,j->l->l->l, + j ,&j); + 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 WRITE mode */ list_free(i); - list_free(j); return no_error; } /**** PBIO *****/ -typedef struct { /* structure presented in the IEEE article */ +GRAS_DEFINE_TYPE(s_pbio, +struct s_pbio{ /* structure presented in the IEEE article */ int Cnstatv; double Cstatev[12]; int Cnprops; double Cprops[110]; - int Cndi[4], Cnshr, Cnpt; - double Cdtime, Ctime[2]; + int Cndi[4]; + int Cnshr; + int Cnpt; + double Cdtime; + double Ctime[2]; int Cntens; - double Cdfgrd0[3][373], Cdfgrd1[3][3], Cstress[106], Cddsdde[106][106]; -} KSdata1; + /* + double Cdfgrd0[373][3]; + double Cdfgrd1[3][3]; + double Cstress[106]; + double Cddsdde[106][106]; + */ +}; + ) +typedef struct s_pbio pbio_t; -int main(int argc,char *argv[]) { +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; + + 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++) + i.Cstatev[cpt] = ((double) cpt) * -2361.11; + i.Cnprops = -37373; + for (cpt=0; cpt<110; cpt++) + i.Cprops[cpt] = cpt * 100.0; + for (cpt=0; cpt<4; cpt++) + 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++) + i.Cdfgrd0[cpt2][cpt] = ((double)cpt) * ((double)cpt2); + for (cpt2=0; cpt2<3; cpt2++) + i.Cdfgrd1[cpt][cpt2] = -((double)cpt) * ((double)cpt2); + } + for (cpt=0; cpt<106; cpt++) { + 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) { + /* Check that the data match */ + gras_assert(i.Cnstatv == j.Cnstatv); + for (cpt=0; cpt<12; cpt++) + gras_assert(i.Cstatev[cpt] == j.Cstatev[cpt]); + gras_assert(i.Cnprops == j.Cnprops); + for (cpt=0; cpt<110; cpt++) + gras_assert(i.Cprops[cpt] == j.Cprops[cpt]); + for (cpt=0; cpt<4; cpt++) + gras_assert(i.Cndi[cpt] == j.Cndi[cpt]); + gras_assert(i.Cnshr == j.Cnshr); + gras_assert(i.Cnpt == j.Cnpt); + gras_assert(i.Cdtime == j.Cdtime); + 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]); + for (cpt2=0; cpt2<3; cpt2++) + gras_assert(i.Cdfgrd1[cpt][cpt2] == j.Cdfgrd1[cpt][cpt2]); + } + for (cpt=0; cpt<106; cpt++) { + gras_assert(i.Cstress[cpt] == j.Cstress[cpt]); + for (cpt2=0; cpt2<106; cpt2++) + 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]); + }*/ + } - gras_init_defaultlog(&argc,argv, - "DataDesc.thresh=verbose" - " test.thresh=debug" - // " set.thresh=debug" - ); + return no_error; +} +int main(int argc,char *argv[]) { + gras_error_t errcode; + gras_socket_t *sock; + int direction = RW; + int cpt; + char r_arch_char = gras_arch_selfid(); + + gras_init_defaultlog(&argc,argv,NULL); + + for (cpt=1; cpt