X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1bbfe6dff09cff639aaab8fd2898678a5a630c2b..36950885fdb8e3294c2f1b4bde08dc84743714a7:/testsuite/gras/datadesc_usage.c diff --git a/testsuite/gras/datadesc_usage.c b/testsuite/gras/datadesc_usage.c index 2a6507bf26..45884e8c57 100644 --- a/testsuite/gras/datadesc_usage.c +++ b/testsuite/gras/datadesc_usage.c @@ -14,128 +14,142 @@ #include "../DataDesc/datadesc_interface.h" GRAS_LOG_NEW_DEFAULT_CATEGORY(test); +#define READ 0 +#define WRITE 1 +#define RW 2 + 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("datadesc_usage.out",&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("datadesc_usage.out",&sock)); + + if (direction == READ || direction == RW) + TRY(gras_datadesc_recv(sock, type, gras_arch_selfid(), 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_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_int(gras_socket_t *sock, int direction) { gras_error_t errcode; - gras_datadesc_type_t *type; - int i=5,*j=NULL; + int i=5,j; INFO0("==== Test on integer ===="); - TRY(gras_datadesc_by_name("int", &type)); - TRY(write_read(type, (void*)&i,(void**) &j)); - gras_assert(i == *j); - free(j); + 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(void) { +gras_error_t test_float(gras_socket_t *sock, int direction) { gras_error_t errcode; - gras_datadesc_type_t *type; - float i=5.0,*j=NULL; + float i=5.0,j; INFO0("==== Test on float ===="); - TRY(gras_datadesc_by_name("float", &type)); - TRY(write_read(type, (void*)&i,(void**) &j)); - gras_assert(i == *j); - free(j); + TRY(write_read(gras_datadesc_by_name("float"), &i,&j, sock,direction)); + if (direction == READ || direction == RW) { + gras_assert(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 *int_type; gras_datadesc_type_t *my_type; - array i,*j; - long int code; + array i,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); + 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; } @@ -188,36 +207,41 @@ 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; - long int my_code; hetestruct *i, *j; INFO0("==== Test on heterogeneous structure ===="); /* create descriptor */ - TRY(gras_datadesc_declare_struct("hetestruct",&my_code)); - TRY(gras_datadesc_declare_struct_add_name(my_code,"c1","unsigned char")); - TRY(gras_datadesc_declare_struct_add_name(my_code,"l1","unsigned long int")); - TRY(gras_datadesc_declare_struct_add_name(my_code,"c2","unsigned char")); - TRY(gras_datadesc_declare_struct_add_name(my_code,"l2","unsigned long int")); - TRY(gras_datadesc_by_code(my_code, &my_type)); + 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)); /* 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_assert(i->l1 == j->l1); + gras_assert(i->l2 == j->l2); + free(j); + } free(i); - free(j); return no_error; } @@ -228,18 +252,22 @@ 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; - long int my_code; nestedstruct *i, *j; INFO0("==== Test on nested structures ===="); /* create descriptor */ - TRY(gras_datadesc_declare_struct("nestedstruct",&my_code)); - TRY(gras_datadesc_declare_struct_add_name(my_code,"hete","hetestruct")); - TRY(gras_datadesc_declare_struct_add_name(my_code,"homo","homostruct")); - TRY(gras_datadesc_by_code(my_code, &my_type)); + 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))) ) @@ -248,20 +276,20 @@ gras_error_t test_nestedstruct(void) { i->homo.c = rand(); i->homo.d = rand(); 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; } @@ -273,9 +301,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)); @@ -296,68 +340,64 @@ 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; - long int my_code; - long int ref_my_code; chained_list_t *i, *j; INFO0("==== Test on chained list ===="); - /* create descriptor */ - TRY(gras_datadesc_declare_struct("chained_list_t",&my_code)); - TRY(gras_datadesc_by_code(my_code, &my_type)); - - TRY(gras_datadesc_declare_ref("chained_list_t*",my_type,&ref_my_code)); - - TRY(gras_datadesc_declare_struct_add_name(my_code,"v","int")); - TRY(gras_datadesc_declare_struct_add_code(my_code,"l",ref_my_code)); - TRY(gras_datadesc_by_code(ref_my_code, &ref_my_type)); - /* init a value, exchange it and check its validity*/ i = cons( rand(), cons( rand() , cons( rand(), 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) ===="); - TRY(gras_datadesc_by_name("chained_list_t*", &my_type)); - /* init a value, exchange it and check its validity*/ i = cons( rand(), cons( rand() , cons( rand(), NULL))); - i->l->l->l = i->l; + 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); + i->l->l->l = NULL; + j->l->l->l = NULL; + gras_assert(list_eq(i,j)); + + list_free(j); + } list_free(i); - list_free(j); return no_error; } @@ -375,26 +415,43 @@ 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, + gras_init_defaultlog(&argc,argv, "DataDesc.thresh=verbose" " test.thresh=debug" - // " set.thresh=debug" + //" set.thresh=debug" ); + if (argc >= 2) { + if (!strcmp(argv[1], "--read")) + direction = READ; + if (!strcmp(argv[1], "--write")) + direction = WRITE; + } + + 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)); + + 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_int()); - TRYFAIL(test_float()); - TRYFAIL(test_array()); - TRYFAIL(test_intref()); - TRYFAIL(test_string()); + TRYFAIL(test_homostruct(sock,direction)); + TRYFAIL(test_hetestruct(sock,direction)); + TRYFAIL(test_nestedstruct(sock,direction)); - TRYFAIL(test_homostruct()); - TRYFAIL(test_hetestruct()); - TRYFAIL(test_nestedstruct()); - */ - TRYFAIL(test_chain_list()); - TRYFAIL(test_graph()); + TRYFAIL(declare_chained_list_type()); + TRYFAIL(test_chain_list(sock,direction)); + TRYFAIL(test_graph(sock,direction)); + if (direction != RW) + gras_socket_close(sock); + gras_exit(); return 0; }