X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b1acf7fe2f1886e9adcb4313f53548c9995a906c..a7e99df0a1386a5ae5ba510ee949aecb76fc6204:/testsuite/gras/datadesc_usage.c diff --git a/testsuite/gras/datadesc_usage.c b/testsuite/gras/datadesc_usage.c index 8acb2d073a..e25b677fd7 100644 --- a/testsuite/gras/datadesc_usage.c +++ b/testsuite/gras/datadesc_usage.c @@ -14,125 +14,145 @@ #include "../DataDesc/datadesc_interface.h" GRAS_LOG_NEW_DEFAULT_CATEGORY(test); +#define READ 0 +#define WRITE 1 +#define RW 2 + +int r_arch; + + 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, 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_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; + 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; } @@ -183,7 +210,7 @@ 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; @@ -191,26 +218,33 @@ gras_error_t test_hetestruct(void) { INFO0("==== Test on heterogeneous structure ===="); /* create descriptor */ TRY(gras_datadesc_declare_struct("hetestruct",&my_type)); - TRY(gras_datadesc_declare_struct_append_name(my_type,"c1","unsigned char")); - TRY(gras_datadesc_declare_struct_append_name(my_type,"l1","unsigned long int")); - TRY(gras_datadesc_declare_struct_append_name(my_type,"c2","unsigned char")); - TRY(gras_datadesc_declare_struct_append_name(my_type,"l2","unsigned long int")); + 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; } @@ -221,7 +255,7 @@ 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; @@ -229,8 +263,14 @@ gras_error_t test_nestedstruct(void) { INFO0("==== Test on nested structures ===="); /* create descriptor */ TRY(gras_datadesc_declare_struct("nestedstruct",&my_type)); - TRY(gras_datadesc_declare_struct_append_name(my_type,"hete","hetestruct")); - TRY(gras_datadesc_declare_struct_append_name(my_type,"homo","homostruct")); + + 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))) ) @@ -239,20 +279,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; } @@ -264,9 +304,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)); @@ -287,62 +343,65 @@ 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_name(my_type,"v","int")); - TRY(gras_datadesc_declare_struct_append(my_type,"l",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); + 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 READ mode */ list_free(i); - list_free(j); return no_error; } @@ -360,30 +419,54 @@ 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; + char r_arch_char = gras_arch_selfid(); 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)); + TRY(gras_datadesc_send(sock, gras_datadesc_by_name("char"), + &r_arch_char)); + } + if (direction == READ) { + TRYFAIL(gras_socket_server_from_file("datadesc_usage.out",&sock)); + TRY(gras_datadesc_recv(sock, gras_datadesc_by_name("char"), + gras_arch_selfid(), &r_arch_char)); + INFO1("This datafile was generated on %s", + gras_datadesc_arch_name(r_arch_char)); + } + r_arch = (int)r_arch_char; + + 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_homostruct(sock,direction)); + TRYFAIL(test_hetestruct(sock,direction)); + TRYFAIL(test_nestedstruct(sock,direction)); - TRYFAIL(test_int()); - TRYFAIL(test_float()); - TRYFAIL(test_array()); - TRYFAIL(test_intref()); - TRYFAIL(test_string()); - - TRYFAIL(test_homostruct()); - TRYFAIL(test_hetestruct()); - TRYFAIL(test_nestedstruct()); - - TRYFAIL(test_chain_list()); + TRYFAIL(declare_chained_list_type()); + TRYFAIL(test_chain_list(sock,direction)); + TRYFAIL(test_graph(sock,direction)); - CRITICAL0("Not even test graphs: it dies with awfully scaring messages"); - gras_abort(); - // TRYFAIL(test_graph()); - + if (direction != RW) + gras_socket_close(sock); gras_exit(); return 0; } +