X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0b7358668fffbf7153bfb9b0a1b8aac6123f9f16..c102403bfd59375027b5865880814bd2257531c0:/testsuite/gras/datadesc_usage.c diff --git a/testsuite/gras/datadesc_usage.c b/testsuite/gras/datadesc_usage.c index 88dc74dcd8..d8111415dc 100644 --- a/testsuite/gras/datadesc_usage.c +++ b/testsuite/gras/datadesc_usage.c @@ -15,103 +15,93 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); #define READ 0 #define WRITE 1 -#define RW 2 +#define COPY 2 +#define RW 3 int r_arch; const char *filename = "datadesc_usage.out"; -xbt_error_t +void write_read(gras_datadesc_type_t type,void *src, void *dst, gras_socket_t sock, int direction); -xbt_error_t +void write_read(gras_datadesc_type_t type,void *src, void *dst, gras_socket_t sock, int direction) { - xbt_error_t errcode; /* write */ if (direction == RW) - TRY(gras_socket_client_from_file(filename,&sock)); + sock = gras_socket_client_from_file(filename); if (direction == WRITE || direction == RW) - TRY(gras_datadesc_send(sock, type, src)); -/* TRY(gras_datadesc_gen_send(sock, type, src));*/ + gras_datadesc_send(sock, type, src); if (direction == RW) gras_socket_close(sock); /* read */ if (direction == RW) - TRY(gras_socket_server_from_file(filename,&sock)); + sock = gras_socket_server_from_file(filename); if (direction == READ || direction == RW) - TRY(gras_datadesc_recv(sock, type, r_arch, dst)); + gras_datadesc_recv(sock, type, r_arch, dst); if (direction == RW) gras_socket_close(sock); - - return no_error; + + if (direction == COPY) + gras_datadesc_copy(type, src, dst); } -xbt_error_t test_int(gras_socket_t sock, int direction); -xbt_error_t test_float(gras_socket_t sock, int direction); -xbt_error_t test_double(gras_socket_t sock, int direction); -xbt_error_t test_array(gras_socket_t sock, int direction); -xbt_error_t test_dynar_scal(gras_socket_t sock, int direction); -xbt_error_t test_intref(gras_socket_t sock, int direction); -xbt_error_t test_string(gras_socket_t sock, int direction); +void test_int(gras_socket_t sock, int direction); +void test_float(gras_socket_t sock, int direction); +void test_double(gras_socket_t sock, int direction); +void test_array(gras_socket_t sock, int direction); +void test_dynar_scal(gras_socket_t sock, int direction); +void test_intref(gras_socket_t sock, int direction); +void test_string(gras_socket_t sock, int direction); -xbt_error_t test_homostruct(gras_socket_t sock, int direction); -xbt_error_t test_hetestruct(gras_socket_t sock, int direction); -xbt_error_t test_nestedstruct(gras_socket_t sock, int direction); -xbt_error_t test_chain_list(gras_socket_t sock, int direction); -xbt_error_t test_graph(gras_socket_t sock, int direction); -xbt_error_t test_dynar_ref(gras_socket_t sock, int direction); +void test_homostruct(gras_socket_t sock, int direction); +void test_hetestruct(gras_socket_t sock, int direction); +void test_nestedstruct(gras_socket_t sock, int direction); +void test_chain_list(gras_socket_t sock, int direction); +void test_graph(gras_socket_t sock, int direction); +void test_dynar_ref(gras_socket_t sock, int direction); -xbt_error_t test_pbio(gras_socket_t sock, int direction); -xbt_error_t test_clause(gras_socket_t sock, int direction); +void test_pbio(gras_socket_t sock, int direction); +void test_clause(gras_socket_t sock, int direction); /* defined in datadesc_structures.c, which in perl generated */ -xbt_error_t test_structures(gras_socket_t sock, int direction); +void test_structures(gras_socket_t sock, int direction); -xbt_error_t test_int(gras_socket_t sock, int direction) { - xbt_error_t errcode; +void test_int(gras_socket_t sock, int direction) { 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) { + write_read(gras_datadesc_by_name("int"), &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) xbt_assert(i == j); - } - return no_error; } -xbt_error_t test_float(gras_socket_t sock, int direction) { - xbt_error_t errcode; +void test_float(gras_socket_t sock, int direction) { float i=5.0,j; INFO0("---- Test on float ----"); - TRY(write_read(gras_datadesc_by_name("float"), &i,&j, sock,direction)); - if (direction == READ || direction == RW) { + write_read(gras_datadesc_by_name("float"), &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) xbt_assert2(i == j,"%f != %f",i,j); - } - return no_error; } -xbt_error_t test_double(gras_socket_t sock, int direction) { - xbt_error_t errcode; +void test_double(gras_socket_t sock, int direction) { double i=-3252355.1234,j; INFO0("---- Test on double ----"); - TRY(write_read(gras_datadesc_by_name("double"), &i,&j, sock,direction)); - if (direction == READ || direction == RW) { + write_read(gras_datadesc_by_name("double"), &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) xbt_assert2(i == j,"%f != %f",i,j); - } - return no_error; } #define SIZE 5 typedef int array[SIZE]; -xbt_error_t test_array(gras_socket_t sock, int direction) { - xbt_error_t errcode; +void test_array(gras_socket_t sock, int direction) { gras_datadesc_type_t my_type; array i = { 35212,-6226,74337,11414,7733}; @@ -124,20 +114,18 @@ xbt_error_t test_array(gras_socket_t sock, int direction) { gras_datadesc_by_name("int"), SIZE); - TRY(write_read(my_type, &i,&j, sock,direction)); - if (direction == READ || direction == RW) { + write_read(my_type, &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) { for (cpt=0; cpta = 2235; i->b = 433425; i->c = -23423; i->d = -235235; - TRY(write_read(my_type, &i,&j, sock,direction)); - if (direction == READ || direction == RW) { + write_read(my_type, &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) { xbt_assert2(i->a == j->a,"i->a=%d != j->a=%d",i->a,j->a); xbt_assert(i->b == j->b); xbt_assert(i->c == j->c); @@ -251,7 +232,6 @@ xbt_error_t test_homostruct(gras_socket_t sock, int direction) { free(j); } free(i); - return no_error; } /*** @@ -263,8 +243,7 @@ typedef struct { unsigned char c2; unsigned long int l2; } hetestruct; -xbt_error_t test_hetestruct(gras_socket_t sock, int direction) { - xbt_error_t errcode; +void test_hetestruct(gras_socket_t sock, int direction) { gras_datadesc_type_t my_type; hetestruct *i, *j; @@ -288,8 +267,8 @@ xbt_error_t test_hetestruct(gras_socket_t sock, int direction) { i->c1 = 's'; i->l1 = 123455; i->c2 = 'e'; i->l2 = 774531; - TRY(write_read(my_type, &i,&j, sock,direction)); - if (direction == READ || direction == RW) { + write_read(my_type, &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) { xbt_assert(i->c1 == j->c1); xbt_assert(i->c2 == j->c2); xbt_assert2(i->l1 == j->l1,"i->l1(=%ld) != j->l1(=%ld)",i->l1,j->l1); @@ -297,7 +276,6 @@ xbt_error_t test_hetestruct(gras_socket_t sock, int direction) { free(j); } free(i); - return no_error; } /*** @@ -307,8 +285,7 @@ typedef struct { hetestruct hete; homostruct homo; } nestedstruct; -xbt_error_t test_nestedstruct(gras_socket_t sock, int direction) { - xbt_error_t errcode; +void test_nestedstruct(gras_socket_t sock, int direction) { gras_datadesc_type_t my_type; nestedstruct *i, *j; @@ -330,8 +307,8 @@ xbt_error_t test_nestedstruct(gras_socket_t sock, int direction) { i->hete.c1 = 's'; i->hete.l1 = 123455; i->hete.c2 = 'e'; i->hete.l2 = 774531; - TRY(write_read(my_type, &i,&j, sock,direction)); - if (direction == READ || direction == RW) { + write_read(my_type, &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) { xbt_assert(i->homo.a == j->homo.a); xbt_assert(i->homo.b == j->homo.b); xbt_assert(i->homo.c == j->homo.c); @@ -343,7 +320,6 @@ xbt_error_t test_nestedstruct(gras_socket_t sock, int direction) { free(j); } free(i); - return no_error; } /*** @@ -354,13 +330,12 @@ struct s_chained_list { int v; chained_list_t *l; }; -xbt_error_t declare_chained_list_type(void); +void 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); -xbt_error_t declare_chained_list_type(void) { - xbt_error_t errcode; +void declare_chained_list_type(void) { gras_datadesc_type_t my_type,ref_my_type; my_type=gras_datadesc_struct("chained_list_t"); @@ -369,8 +344,6 @@ xbt_error_t declare_chained_list_type(void) { 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) { @@ -393,8 +366,7 @@ int list_eq(chained_list_t*i,chained_list_t*j) { return 0; return list_eq(i->l, j->l); } -xbt_error_t test_chain_list(gras_socket_t sock, int direction) { - xbt_error_t errcode; +void test_chain_list(gras_socket_t sock, int direction) { chained_list_t *i, *j; INFO0("---- Test on chained list ----"); @@ -403,34 +375,31 @@ xbt_error_t test_chain_list(gras_socket_t sock, int direction) { i = cons( 12355, cons( 246264 , cons( 23263, NULL))); j = NULL; - TRY(write_read(gras_datadesc_by_name("chained_list_t*"), - &i,&j, - sock,direction)); - if (direction == READ || direction == RW) { + write_read(gras_datadesc_by_name("chained_list_t*"), + &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) { xbt_assert(list_eq(i,j)); list_free(j); } list_free(i); - return no_error; } /*** *** graph ***/ -xbt_error_t test_graph(gras_socket_t sock, int direction) { - xbt_error_t errcode; +void test_graph(gras_socket_t sock, int direction) { chained_list_t *i, *j; - INFO0("---- Test on graph (cyclique chained list) ----"); + INFO0("---- Test on graph (cyclique chained list of 3 items) ----"); /* init a value, exchange it and check its validity*/ i = cons( 1151515, cons( -232362 , cons( 222552, NULL))); 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) { + write_read(gras_datadesc_by_name("chained_list_t*"), + &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) { DEBUG1("i=%p" ,i); DEBUG1("i->l=%p" ,i->l); @@ -453,7 +422,6 @@ xbt_error_t test_graph(gras_socket_t sock, int direction) { } i->l->l->l = NULL; /* do this even in WRITE mode */ list_free(i); - return no_error; } @@ -461,8 +429,7 @@ xbt_error_t test_graph(gras_socket_t sock, int direction) { static void free_string(void *d){ /* used to free the data in dynar */ free(*(void**)d); } -xbt_error_t test_dynar_ref(gras_socket_t sock, int direction){ - xbt_error_t errcode; +void test_dynar_ref(gras_socket_t sock, int direction){ gras_datadesc_type_t my_type; xbt_dynar_t i,j; char buf[1024]; @@ -479,8 +446,8 @@ xbt_error_t test_dynar_ref(gras_socket_t sock, int direction){ xbt_dynar_push(i,&s1); } - TRY(write_read(my_type, &i,&j, sock, direction)); - if (direction == READ || direction == RW) { + write_read(my_type, &i,&j, sock, direction); + if (direction == READ || direction == RW || direction == COPY) { for (cpt=0; cpt< 64; cpt++) { sprintf(buf,"%d",cpt); xbt_dynar_shift(j,&s2); @@ -492,8 +459,6 @@ xbt_error_t test_dynar_ref(gras_socket_t sock, int direction){ xbt_dynar_free(&j); } xbt_dynar_free(&i); - - return no_error; } @@ -518,8 +483,7 @@ struct s_pbio{ /* structure presented in the IEEE article */ ) typedef struct s_pbio pbio_t; -xbt_error_t test_pbio(gras_socket_t sock, int direction) { - xbt_error_t errcode; +void test_pbio(gras_socket_t sock, int direction) { int cpt; int cpt2; gras_datadesc_type_t pbio_type; @@ -555,9 +519,9 @@ xbt_error_t test_pbio(gras_socket_t sock, int direction) { 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) { + write_read(gras_datadesc_by_symbol(s_pbio), + &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) { /* Check that the data match */ xbt_assert(i.Cnstatv == j.Cnstatv); for (cpt=0; cpt<12; cpt++) @@ -589,8 +553,6 @@ xbt_error_t test_pbio(gras_socket_t sock, int direction) { i.Cddsdde[cpt][cpt2],cpt,cpt2,j.Cddsdde[cpt][cpt2]); } } - - return no_error; } GRAS_DEFINE_TYPE(s_clause, @@ -600,9 +562,8 @@ struct s_clause { };) typedef struct s_clause Clause; -xbt_error_t test_clause(gras_socket_t sock, int direction) { - xbt_error_t errcode; - gras_datadesc_type_t ddt,array_t; +void test_clause(gras_socket_t sock, int direction) { + gras_datadesc_type_t ddt; Clause *i,*j; int cpt; @@ -624,8 +585,8 @@ xbt_error_t test_clause(gras_socket_t sock, int direction) { ddt=gras_datadesc_ref("Clause*",ddt); - TRY(write_read(ddt, &i,&j, sock,direction)); - if (direction == READ || direction == RW) { + write_read(ddt, &i,&j, sock,direction); + if (direction == READ || direction == RW || direction == COPY) { xbt_assert(i->num_lits == j->num_lits); for (cpt=0; cptnum_lits; cpt++) xbt_assert(i->literals[cpt] == j->literals[cpt]); @@ -635,12 +596,10 @@ xbt_error_t test_clause(gras_socket_t sock, int direction) { } free(i->literals); free(i); - return no_error; } int main(int argc,char *argv[]) { - xbt_error_t errcode; - gras_socket_t sock; + gras_socket_t sock=NULL; int direction = RW; int cpt; char r_arch_char = gras_arch_selfid(); @@ -652,51 +611,53 @@ int main(int argc,char *argv[]) { direction = READ; } else if (!strcmp(argv[cpt], "--write")) { direction = WRITE; + } else if (!strcmp(argv[cpt], "--copy")) { + direction = COPY; } else { filename=argv[cpt]; } } if (direction == WRITE) { - TRYFAIL(gras_socket_client_from_file(filename,&sock)); - TRY(gras_datadesc_send(sock, gras_datadesc_by_name("char"), - &r_arch_char)); + sock = gras_socket_client_from_file(filename); + gras_datadesc_send(sock, gras_datadesc_by_name("char"), + &r_arch_char); } if (direction == READ) { - TRYFAIL(gras_socket_server_from_file(filename,&sock)); - TRY(gras_datadesc_recv(sock, gras_datadesc_by_name("char"), - gras_arch_selfid(), &r_arch_char)); + sock = gras_socket_server_from_file(filename); + gras_datadesc_recv(sock, gras_datadesc_by_name("char"), + gras_arch_selfid(), &r_arch_char); INFO3("This datafile was generated on %s (%d), I'm %s.", gras_datadesc_arch_name(r_arch_char),(int)r_arch_char, gras_datadesc_arch_name(gras_arch_selfid())); } r_arch = (int)r_arch_char; - TRYFAIL(test_int(sock,direction)); - TRYFAIL(test_float(sock,direction)); - TRYFAIL(test_double(sock,direction)); - TRYFAIL(test_array(sock,direction)); - TRYFAIL(test_dynar_scal(sock,direction)); - TRYFAIL(test_intref(sock,direction)); - - TRYFAIL(test_string(sock,direction)); + test_int(sock,direction); + test_float(sock,direction); + test_double(sock,direction); + test_array(sock,direction); + test_intref(sock,direction); + + test_string(sock,direction); + test_dynar_scal(sock,direction); - TRYFAIL(test_structures(sock,direction)); + test_structures(sock,direction); - TRYFAIL(test_homostruct(sock,direction)); - TRYFAIL(test_hetestruct(sock,direction)); - TRYFAIL(test_nestedstruct(sock,direction)); + test_homostruct(sock,direction); + test_hetestruct(sock,direction); + test_nestedstruct(sock,direction); - TRYFAIL(declare_chained_list_type()); - TRYFAIL(test_chain_list(sock,direction)); - TRYFAIL(test_graph(sock,direction)); - TRYFAIL(test_dynar_ref(sock,direction)); + declare_chained_list_type(); + test_chain_list(sock,direction); + test_graph(sock,direction); + test_dynar_ref(sock,direction); - TRYFAIL(test_pbio(sock,direction)); + test_pbio(sock,direction); - TRYFAIL(test_clause(sock,direction)); + test_clause(sock,direction); - if (direction != RW) + if (direction != RW && direction != COPY) gras_socket_close(sock); gras_exit(); return 0;