From e62bba7ea511413feb10d9de5c306061a8560c54 Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 18 May 2009 08:32:48 +0000 Subject: [PATCH 1/1] Add regression tests for the lastly fixed bugs in GRAS dadadesc git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6286 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- ChangeLog | 4 +- src/gras/DataDesc/ddt_exchange.c | 23 +- teshsuite/gras/datadesc/datadesc.little32_4 | Bin 125661 -> 125895 bytes teshsuite/gras/datadesc/datadesc_mem.tesh | 3 + .../gras/datadesc/datadesc_r_little32_4.tesh | 3 + teshsuite/gras/datadesc/datadesc_rw.tesh | 6 + teshsuite/gras/datadesc/datadesc_usage.c | 1095 +++++++++-------- 7 files changed, 621 insertions(+), 513 deletions(-) diff --git a/ChangeLog b/ChangeLog index d38785df8b..3d62e0a84c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ SimGrid (3.4-svn) unstable; urgency=high GRAS: * fix a bug on struct sizeof computation, which prevented the exchange of arrays of structs in some conditions + - added a regression test about this in datadesc_usage * Allow the exchange of 0-long dynamic vectors. - for that, use -1 as indicator of dynamic size instead of 0 - This implied to change any size from unsigned long to long, @@ -11,7 +12,8 @@ SimGrid (3.4-svn) unstable; urgency=high - This also induce a protocol change, thus bumping network protocol version from 0 to 1 (if we have external users, we have to get clean on that point too ;) - + - added two regression tests about this in datadesc_usage + MSG: * Allow to control the simulation from a trace file. New functions MSG_action_register() and MSG_action_trace_run() diff --git a/src/gras/DataDesc/ddt_exchange.c b/src/gras/DataDesc/ddt_exchange.c index 90454a5a03..a35b2de110 100644 --- a/src/gras/DataDesc/ddt_exchange.c +++ b/src/gras/DataDesc/ddt_exchange.c @@ -808,12 +808,14 @@ gras_datadesc_recv_rec(gras_socket_t sock, subsub_type = array_data.type; - - gras_dd_alloc_ref(refs, - subsub_type->size[GRAS_THISARCH] * subsubcount, - r_ref,pointer_type->size[r_arch], - (char**)&l_referenced, - detect_cycle); + if (subsubcount != 0) + gras_dd_alloc_ref(refs, + subsub_type->size[GRAS_THISARCH] * subsubcount, + r_ref,pointer_type->size[r_arch], + (char**)&l_referenced, + detect_cycle); + else + l_referenced = NULL; } else { gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH], r_ref,pointer_type->size[r_arch], @@ -821,10 +823,11 @@ gras_datadesc_recv_rec(gras_socket_t sock, detect_cycle); } - gras_datadesc_recv_rec(sock,state,refs, sub_type, - r_arch,r_ref,pointer_type->size[r_arch], - (char*)l_referenced, subsubcount, - detect_cycle || sub_type->cycle); + if (l_referenced != NULL) + gras_datadesc_recv_rec(sock,state,refs, sub_type, + r_arch,r_ref,pointer_type->size[r_arch], + (char*)l_referenced, subsubcount, + detect_cycle || sub_type->cycle); *(void**)l_data=l_referenced; VERB3("'%s' remotely referenced at %p locally at %p", diff --git a/teshsuite/gras/datadesc/datadesc.little32_4 b/teshsuite/gras/datadesc/datadesc.little32_4 index 5648314d2b172e519d876734ea2ac41f8be51dea..f291d4d54acc146863252d41f0832d428509c295 100644 GIT binary patch delta 2547 zcmaKuT}&KR6vxlAzzxbX=a6a1e$bJ(RZPD19#{hxd8 z|C~E>XRrTe|LzZa=(z!zjVy;K{fnVB>$|DO4;q>sDMsTX{X-{} zdKdmZGCUY@_V&bkWXaI|hPDsF_=$K|@5E5gNY`+*i*2ocV`%3f1o6jK^*;@bnJ*jB zl`31YjZOS-0yEr9Ak25GtXRM-AdHK~C(cY-<4e!V_$ZIhk_eqX5&Bth-23a!j%b;q zhBp6dK?OHy@dfZ)L8a=_i!vw5bK=YTicDEWnA)3gFH4;pwuALw_*z6xcAN4j+nc7G zzhsvP@CPAhP>+fNgVXfrM83m?<01~IX(P9;+hnc26L1_VtYY`UVQ{Q)KXXdwN(!rv zgJW7Qa{$?HTgDH>K)TK=l-7ez%Yl)9%GmqhKb)W+M5f9>Fs zb~zUk5`tY-3Gz4AF()cER;hRH?dk_+L-pZcq=eXssgDcyWb3M&|+$Qr;-flpC ziOI_nff9Ek^2=QK1g*SQT*K|2`4qfUtXjXwTw7A}1jeU6GqXh5XFRR1uANZZ9G7c8Ri>Sph#_ zuVm{}I4R~Ix2s3D`zP=*yNX%(5q#F<<*&e(?KO=Y|GT+LZy2lazSQBJ+w)#JuOa%D zy`~z`p;|*LLzR8QgTpw?#=bn3s-3scT28}-rIyD2Dcn0*!Ea*%dXy6^tYlUS`arCq z#{AU51*hDG804)hNQ`$nePHTcL$_TnCE9fEG zFxPOSEdTCA2M;SpsWd)mv@IrtJfyt&-RhSP z+w^;A` S&7<|!oAY0hoSEMazW)od0md%? delta 2462 zcmZ{mU1(cn7{{N}CMQQN+K$zwcC$sSYp23VPCij-%Y+q~7&eulj5H>xiDYSMGD+u0 zs=Kg*snvo6MCgSVy%8o}wBjx%YR!${)M7x2SQT?;*;N>W_MmM}fl*y+TsYeAH2zn4Klqw`d6^?zY8#=zu73b3x z{9d0@!WQyBNF4E@UgA4o>5&?+{exW^RZfucfX|4V-BMSf`B0)K5WtU3n#nk*%^cinLn8J^+y8f=u5G+0#(HBFSR}&_Z zZMD8kCPUSwi?1om`CA+>i}+>mmf)Eb<(&@0Yu*XtSNQ?jMYAmh%$dP28He z+3D1rp?=+Gw>dK>^vagG%|lo3U@0r4d+Zkq4>qF!)8!u!!$J3Vy?m&j!FBdxnMQs$~}_ zig_2X9nQS{QI;^Tl$?2|CRjszq~>l=>~U7H%Tjf3v@xmFwXpZzF?eWBb2|Da)7_oh zcoJ?Gyu%L(x2NpP)57g>c|zQsnt2MTpL>VIg8ff}Z+M3%z^!L^82ogHxjm6+)u28i zM%G1p9@AypT1oIZeMDYHu(--|V)Dv$bK7ZE{R~TJm6V)Twa>AJR!Pm>s_V0?!kSdw zwytKBTFc;4NZGy@&b8PtZ~-(=X1JSY6j{Zwlj^~P*DTo?S+Oc1j^XAwD;q6Kd6Kdj zEUl|M%S*h<~sGsV9k)nF!?rDfzNIg0q%=z{-hgy z*n#}~`FT8h7czJiO`OuN45EQgbb9O4PUl$Rc1Jx>>p!dXTqWmDFHi1il)H4}F8hf* z+M}&Db>nUnE+H?Mt zQj^i57GsF2_!}dKg=vK`LUqO{Z7{}Yi?J4`hT@<}O~wGV7=zSiw8(hRo+B6{KVz82 z86y;9jM5BajFOCT$}6-?YQuX?IJN?0s5z`4`57%5XG9+v!!*Mfp(JCJ@{BR6zHhs< z;>VTajuBg@FoLaP#MUw5q~Od6ml2CT+xFlpcW+MpU->W2 qrJcUboj$E`c?1`6_HW$~IVX$h3+3DiStvG0)JDP0YaeNUJ^LR~YAIa+ diff --git a/teshsuite/gras/datadesc/datadesc_mem.tesh b/teshsuite/gras/datadesc/datadesc_mem.tesh index 089a5f78aa..dad96113f2 100644 --- a/teshsuite/gras/datadesc/datadesc_mem.tesh +++ b/teshsuite/gras/datadesc/datadesc_mem.tesh @@ -9,13 +9,16 @@ $ gras/datadesc/datadesc_usage --copy --log=root.fmt:%m%n > ---- Test on a reference to an integer ---- > ---- Test on string (ref to dynamic array) ---- > ---- Test on dynar containing integers ---- +> ---- Test on empty dynar of integers ---- > ---- Test on all possible struct having 3 fields (49 structs) ---- > ---- Test on homogeneous structure ---- > ---- Test on heterogeneous structure ---- > ---- Test on nested structures ---- +> ---- Test on heterogeneous structure arrays ---- > ---- Test on chained list ---- > ---- Test on graph (cyclique chained list of 3 items) ---- > ---- Test on dynar containing integers ---- > ---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ---- > ---- Test on struct containing dynamic array and its size (cbps test) ---- +> ---- Test on struct containing dynamic array and its size when size=0 (cbps test) ---- > Exiting GRAS diff --git a/teshsuite/gras/datadesc/datadesc_r_little32_4.tesh b/teshsuite/gras/datadesc/datadesc_r_little32_4.tesh index 2cb01ea81f..c516f1316c 100644 --- a/teshsuite/gras/datadesc/datadesc_r_little32_4.tesh +++ b/teshsuite/gras/datadesc/datadesc_r_little32_4.tesh @@ -9,13 +9,16 @@ $ gras/datadesc/datadesc_usage --read ${srcdir:=.}/gras/datadesc/datadesc.little > ---- Test on a reference to an integer ---- > ---- Test on string (ref to dynamic array) ---- > ---- Test on dynar containing integers ---- +> ---- Test on empty dynar of integers ---- > ---- Test on all possible struct having 3 fields (49 structs) ---- > ---- Test on homogeneous structure ---- > ---- Test on heterogeneous structure ---- > ---- Test on nested structures ---- +> ---- Test on heterogeneous structure arrays ---- > ---- Test on chained list ---- > ---- Test on graph (cyclique chained list of 3 items) ---- > ---- Test on dynar containing integers ---- > ---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ---- > ---- Test on struct containing dynamic array and its size (cbps test) ---- +> ---- Test on struct containing dynamic array and its size when size=0 (cbps test) ---- > Exiting GRAS diff --git a/teshsuite/gras/datadesc/datadesc_rw.tesh b/teshsuite/gras/datadesc/datadesc_rw.tesh index 2f73d9c25f..16db2efcd7 100644 --- a/teshsuite/gras/datadesc/datadesc_rw.tesh +++ b/teshsuite/gras/datadesc/datadesc_rw.tesh @@ -11,15 +11,18 @@ $ gras/datadesc/datadesc_usage --write --log=root.fmt:%m%n > ---- Test on a reference to an integer ---- > ---- Test on string (ref to dynamic array) ---- > ---- Test on dynar containing integers ---- +> ---- Test on empty dynar of integers ---- > ---- Test on all possible struct having 3 fields (49 structs) ---- > ---- Test on homogeneous structure ---- > ---- Test on heterogeneous structure ---- > ---- Test on nested structures ---- +> ---- Test on heterogeneous structure arrays ---- > ---- Test on chained list ---- > ---- Test on graph (cyclique chained list of 3 items) ---- > ---- Test on dynar containing integers ---- > ---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ---- > ---- Test on struct containing dynamic array and its size (cbps test) ---- +> ---- Test on struct containing dynamic array and its size when size=0 (cbps test) ---- > Exiting GRAS $ gras/datadesc/datadesc_usage --read --log=root.fmt:%m%n @@ -31,13 +34,16 @@ $ gras/datadesc/datadesc_usage --read --log=root.fmt:%m%n > ---- Test on a reference to an integer ---- > ---- Test on string (ref to dynamic array) ---- > ---- Test on dynar containing integers ---- +> ---- Test on empty dynar of integers ---- > ---- Test on all possible struct having 3 fields (49 structs) ---- > ---- Test on homogeneous structure ---- > ---- Test on heterogeneous structure ---- > ---- Test on nested structures ---- +> ---- Test on heterogeneous structure arrays ---- > ---- Test on chained list ---- > ---- Test on graph (cyclique chained list of 3 items) ---- > ---- Test on dynar containing integers ---- > ---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ---- > ---- Test on struct containing dynamic array and its size (cbps test) ---- +> ---- Test on struct containing dynamic array and its size when size=0 (cbps test) ---- > Exiting GRAS diff --git a/teshsuite/gras/datadesc/datadesc_usage.c b/teshsuite/gras/datadesc/datadesc_usage.c index a95d4cb08c..51df175fbf 100644 --- a/teshsuite/gras/datadesc/datadesc_usage.c +++ b/teshsuite/gras/datadesc/datadesc_usage.c @@ -6,7 +6,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ - + #ifdef __BORLANDC__ #pragma hdrstop #endif @@ -21,550 +21,622 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); #define WRITE 1 #define COPY 2 -const char *filename = "datadesc_usage.out"; +const char *filename = "datadesc_usage.out"; void -write_read(const char* msgtype,void *src, void *dst, - gras_socket_t sock, int direction); +write_read(const char* msgtype,void *src, void *dst, + gras_socket_t sock, int direction); void -write_read(const char* msgtype,void *src, void *dst, - gras_socket_t sock, int direction) { - - switch (direction) { - case READ: - gras_msg_wait(15, msgtype, NULL, dst); - break; - - case WRITE: - gras_msg_send(sock, msgtype, src); - break; - - case COPY: - gras_datadesc_memcpy(gras_datadesc_by_name(msgtype), src, dst); - break; - } +write_read(const char* msgtype,void *src, void *dst, + gras_socket_t sock, int direction) { + + switch (direction) { + case READ: + gras_msg_wait(15, msgtype, NULL, dst); + break; + + case WRITE: + gras_msg_send(sock, msgtype, src); + break; + + case COPY: + gras_datadesc_memcpy(gras_datadesc_by_name(msgtype), src, dst); + break; + } } /* defined in datadesc_structures.c, which in perl generated */ void register_structures(void); -void test_structures(gras_socket_t sock, int direction); +void test_structures(gras_socket_t sock, int direction); /************************ * Each and every tests * ************************/ static void test_int(gras_socket_t sock, int direction) { - int i=5,j; - - INFO0("---- Test on integer ----"); - write_read("int", &i,&j, sock,direction); - if (direction == READ || direction == COPY) - xbt_assert(i == j); + int i=5,j; + + INFO0("---- Test on integer ----"); + write_read("int", &i,&j, sock,direction); + if (direction == READ || direction == COPY) + xbt_assert(i == j); } static void test_float(gras_socket_t sock, int direction) { - float i=5.0,j; - - INFO0("---- Test on float ----"); - write_read("float", &i,&j, sock,direction); - if (direction == READ || direction == COPY) - xbt_assert2(i == j,"%f != %f",i,j); + float i=5.0,j; + + INFO0("---- Test on float ----"); + write_read("float", &i,&j, sock,direction); + if (direction == READ || direction == COPY) + xbt_assert2(i == j,"%f != %f",i,j); } static void test_double(gras_socket_t sock, int direction) { - double i=-3252355.1234,j; - - INFO0("---- Test on double ----"); - write_read("double", &i,&j, sock,direction); - if (direction == READ || direction == COPY) - xbt_assert2(i == j,"%f != %f",i,j); + double i=-3252355.1234,j; + + INFO0("---- Test on double ----"); + write_read("double", &i,&j, sock,direction); + if (direction == READ || direction == COPY) + xbt_assert2(i == j,"%f != %f",i,j); } #define FIXED_ARRAY_SIZE 5 typedef int array[FIXED_ARRAY_SIZE]; static void test_array(gras_socket_t sock, int direction) { - array i = { 35212,-6226,74337,11414,7733}; - array j; - int cpt; - - INFO0("---- Test on fixed array ----"); - - write_read("fixed int array", &i,&j, sock,direction); - if (direction == READ || direction == COPY) { - for (cpt=0; cpta = 2235; i->b = 433425; - i->c = -23423; i->d = -235235; - - write_read("homostruct*", &i,&j, sock,direction); - if (direction == READ || 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); - xbt_assert(i->d == j->d); - free(j); - } - free(i); + homostruct *i, *j; + + INFO0("---- Test on homogeneous structure ----"); + /* init a value, exchange it and check its validity*/ + i=xbt_new(homostruct,1); + i->a = 2235; i->b = 433425; + i->c = -23423; i->d = -235235; + + write_read("homostruct*", &i,&j, sock,direction); + if (direction == READ || 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); + xbt_assert(i->d == j->d); + free(j); + } + free(i); } /*** *** heterogeneous struct - ***/ + ***/ typedef struct { - unsigned char c1; - unsigned long int l1; - unsigned char c2; - unsigned long int l2; + unsigned char c1; + unsigned long int l1; + unsigned char c2; + unsigned long int l2; } hetestruct; static void test_hetestruct(gras_socket_t sock, int direction) { - hetestruct *i, *j; - - INFO0("---- Test on heterogeneous structure ----"); - /* init a value, exchange it and check its validity*/ - i=xbt_new(hetestruct,1); - i->c1 = 's'; i->l1 = 123455; - i->c2 = 'e'; i->l2 = 774531; - - write_read("hetestruct*", &i,&j, sock,direction); - if (direction == READ || 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); - xbt_assert(i->l2 == j->l2); - free(j); - } - free(i); + hetestruct *i, *j; + + INFO0("---- Test on heterogeneous structure ----"); + /* init a value, exchange it and check its validity*/ + i=xbt_new(hetestruct,1); + i->c1 = 's'; i->l1 = 123455; + i->c2 = 'e'; i->l2 = 774531; + + write_read("hetestruct*", &i,&j, sock,direction); + if (direction == READ || 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); + xbt_assert(i->l2 == j->l2); + free(j); + } + free(i); } +static void test_hetestruct_array(gras_socket_t sock, int direction) { + hetestruct *i, *j, *p,*q; + int cpt; + + INFO0("---- Test on heterogeneous structure arrays ----"); + /* init a value, exchange it and check its validity*/ + i=xbt_malloc(sizeof(hetestruct)*10); + for (cpt=0,p=i;cpt<10;cpt++,p++) { + p->c1 = 's'+cpt; p->l1 = 123455+cpt; + p->c2 = 'e'+cpt; p->l2 = 774531+cpt; + } + + write_read("hetestruct[10]*", &i,&j, sock,direction); + if (direction == READ || direction == COPY) { + for (cpt=0,p=i,q=j; + cpt<10; + cpt++,p++,q++) { + xbt_assert(p->c1 == q->c1); + xbt_assert(p->c2 == q->c2); + xbt_assert3(p->l1 == p->l1, + "for cpt=%d i->l1(=%ld) != j->l1(=%ld)",cpt,p->l1,q->l1); + xbt_assert(q->l2 == p->l2); + } + free(j); + } + free(i); +} /*** *** nested struct - ***/ + ***/ typedef struct { - hetestruct hete; - homostruct homo; + hetestruct hete; + homostruct homo; } nestedstruct; static void test_nestedstruct(gras_socket_t sock, int direction) { - nestedstruct *i, *j; - - INFO0("---- Test on nested structures ----"); - /* init a value, exchange it and check its validity*/ - i=xbt_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; - i->hete.c2 = 'e'; i->hete.l2 = 774531; - - write_read("nestedstruct*", &i,&j, sock,direction); - if (direction == READ || 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); - xbt_assert(i->homo.d == j->homo.d); - xbt_assert(i->hete.c1 == j->hete.c1); - xbt_assert(i->hete.c2 == j->hete.c2); - xbt_assert(i->hete.l1 == j->hete.l1); - xbt_assert(i->hete.l2 == j->hete.l2); - free(j); - } - free(i); + nestedstruct *i, *j; + + INFO0("---- Test on nested structures ----"); + /* init a value, exchange it and check its validity*/ + i=xbt_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; + i->hete.c2 = 'e'; i->hete.l2 = 774531; + + write_read("nestedstruct*", &i,&j, sock,direction); + if (direction == READ || 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); + xbt_assert(i->homo.d == j->homo.d); + xbt_assert(i->hete.c1 == j->hete.c1); + xbt_assert(i->hete.c2 == j->hete.c2); + xbt_assert(i->hete.l1 == j->hete.l1); + xbt_assert(i->hete.l2 == j->hete.l2); + free(j); + } + free(i); } /*** *** chained list - ***/ + ***/ typedef struct s_chained_list chained_list_t; struct s_chained_list { - int v; - chained_list_t *l; + int v; + chained_list_t *l; }; 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); chained_list_t * cons(int v, chained_list_t *l) { - chained_list_t *nl = xbt_new(chained_list_t,1); - - nl->v = v; - nl->l = l; - - return nl; + chained_list_t *nl = xbt_new(chained_list_t,1); + + nl->v = v; + nl->l = l; + + return nl; } void list_free(chained_list_t*l) { - if (l) { - list_free(l->l); - free(l); - } + if (l) { + list_free(l->l); + free(l); + } } int list_eq(chained_list_t*i,chained_list_t*j) { - if (!i || !j) return i == j; - if (i->v != j->v) - return 0; - return list_eq(i->l, j->l); + if (!i || !j) return i == j; + if (i->v != j->v) + return 0; + return list_eq(i->l, j->l); } static void test_chain_list(gras_socket_t sock, int direction) { - chained_list_t *i, *j; + chained_list_t *i, *j; - INFO0("---- Test on chained list ----"); + INFO0("---- Test on chained list ----"); - /* init a value, exchange it and check its validity*/ - i = cons( 12355, cons( 246264 , cons( 23263, NULL))); - j = NULL; + /* init a value, exchange it and check its validity*/ + i = cons( 12355, cons( 246264 , cons( 23263, NULL))); + j = NULL; - write_read("chained_list_t*", &i,&j, sock,direction); - if (direction == READ || direction == COPY) { - xbt_assert(list_eq(i,j)); - list_free(j); - } + write_read("chained_list_t*", &i,&j, sock,direction); + if (direction == READ || direction == COPY) { + xbt_assert(list_eq(i,j)); + list_free(j); + } - list_free(i); + list_free(i); } /*** *** graph ***/ static void test_graph(gras_socket_t sock, int direction) { - chained_list_t *i, *j; - - 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; - - write_read("chained_list_t*", &i,&j, sock,direction); - if (direction == READ || direction == COPY) { - - 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); - xbt_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; - xbt_assert(list_eq(i,j)); - - list_free(j); - } - i->l->l->l = NULL; /* do this even in WRITE mode */ - list_free(i); + chained_list_t *i, *j; + + 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; + + write_read("chained_list_t*", &i,&j, sock,direction); + if (direction == READ || direction == COPY) { + + 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); + xbt_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; + xbt_assert(list_eq(i,j)); + + list_free(j); + } + i->l->l->l = NULL; /* do this even in WRITE mode */ + list_free(i); } /*** Dynar of references ***/ static void free_string(void *d){ /* used to free the data in dynar */ - free(*(void**)d); + free(*(void**)d); } static void test_dynar_ref(gras_socket_t sock, int direction){ - xbt_dynar_t i,j; - char buf[1024]; - char *s1,*s2; - int cpt; - - INFO0("---- Test on dynar containing integers ----"); - - i=xbt_dynar_new(sizeof(char*),&free_string); - for (cpt=0; cpt< 64; cpt++) { - sprintf(buf,"%d",cpt); - s1=strdup(buf); - xbt_dynar_push(i,&s1); - } - - write_read("xbt_dynar_of_string", &i,&j, sock, direction); - if (direction == READ || direction == COPY) { - for (cpt=0; cpt< 64; cpt++) { - sprintf(buf,"%d",cpt); - xbt_dynar_shift(j,&s2); - xbt_assert2 (!strcmp(buf,s2), - "The retrieved value is not the same than the injected one (%s!=%s)", - buf,s2); - free(s2); - } - xbt_dynar_free(&j); - } - xbt_dynar_free(&i); + xbt_dynar_t i,j; + char buf[1024]; + char *s1,*s2; + int cpt; + + INFO0("---- Test on dynar containing integers ----"); + + i=xbt_dynar_new(sizeof(char*),&free_string); + for (cpt=0; cpt< 64; cpt++) { + sprintf(buf,"%d",cpt); + s1=strdup(buf); + xbt_dynar_push(i,&s1); + } + + write_read("xbt_dynar_of_string", &i,&j, sock, direction); + if (direction == READ || direction == COPY) { + for (cpt=0; cpt< 64; cpt++) { + sprintf(buf,"%d",cpt); + xbt_dynar_shift(j,&s2); + xbt_assert2 (!strcmp(buf,s2), + "The retrieved value is not the same than the injected one (%s!=%s)", + buf,s2); + free(s2); + } + xbt_dynar_free(&j); + } + xbt_dynar_free(&i); } /**** PBIO *****/ 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]; - int Cnshr; - int Cnpt; - double Cdtime; - double Ctime[2]; - int Cntens; - double Cdfgrd0[373][3]; - double Cdfgrd1[3][3]; - double Cstress[106]; - double Cddsdde[106][106]; + struct s_pbio{ /* structure presented in the IEEE article */ + int Cnstatv; + double Cstatev[12]; + int Cnprops; + double Cprops[110]; + int Cndi[4]; + int Cnshr; + int Cnpt; + 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; static void test_pbio(gras_socket_t sock, int direction) { - int cpt; - int cpt2; - gras_datadesc_type_t pbio_type; - pbio_t i, j; - - INFO0("---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ----"); - pbio_type = gras_datadesc_by_symbol(s_pbio); - - /* 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); - } - write_read("s_pbio", &i,&j, sock,direction); - if (direction == READ || direction == COPY) { - /* Check that the data match */ - xbt_assert(i.Cnstatv == j.Cnstatv); - for (cpt=0; cpt<12; cpt++) - xbt_assert4(i.Cstatev[cpt] == j.Cstatev[cpt], - "i.Cstatev[%d] (=%f) != j.Cstatev[%d] (=%f)", - cpt,i.Cstatev[cpt],cpt,j.Cstatev[cpt]); - xbt_assert(i.Cnprops == j.Cnprops); - for (cpt=0; cpt<110; cpt++) - xbt_assert(i.Cprops[cpt] == j.Cprops[cpt]); - for (cpt=0; cpt<4; cpt++) - xbt_assert(i.Cndi[cpt] == j.Cndi[cpt]); - xbt_assert(i.Cnshr == j.Cnshr); - xbt_assert(i.Cnpt == j.Cnpt); - xbt_assert(i.Cdtime == j.Cdtime); - xbt_assert(i.Ctime[0] == j.Ctime[0]); - xbt_assert(i.Ctime[1] == j.Ctime[1]); - xbt_assert(i.Cntens == j.Cntens); - for (cpt=0; cpt<3; cpt++) { - for (cpt2=0; cpt2<373; cpt2++) - xbt_assert(i.Cdfgrd0[cpt2][cpt] == j.Cdfgrd0[cpt2][cpt]); - for (cpt2=0; cpt2<3; cpt2++) - xbt_assert(i.Cdfgrd1[cpt][cpt2] == j.Cdfgrd1[cpt][cpt2]); - } - for (cpt=0; cpt<106; cpt++) { - xbt_assert(i.Cstress[cpt] == j.Cstress[cpt]); - for (cpt2=0; cpt2<106; cpt2++) - xbt_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]); - } - } + int cpt; + int cpt2; + gras_datadesc_type_t pbio_type; + pbio_t i, j; + + INFO0("---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ----"); + pbio_type = gras_datadesc_by_symbol(s_pbio); + + /* 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); + } + write_read("s_pbio", &i,&j, sock,direction); + if (direction == READ || direction == COPY) { + /* Check that the data match */ + xbt_assert(i.Cnstatv == j.Cnstatv); + for (cpt=0; cpt<12; cpt++) + xbt_assert4(i.Cstatev[cpt] == j.Cstatev[cpt], + "i.Cstatev[%d] (=%f) != j.Cstatev[%d] (=%f)", + cpt,i.Cstatev[cpt],cpt,j.Cstatev[cpt]); + xbt_assert(i.Cnprops == j.Cnprops); + for (cpt=0; cpt<110; cpt++) + xbt_assert(i.Cprops[cpt] == j.Cprops[cpt]); + for (cpt=0; cpt<4; cpt++) + xbt_assert(i.Cndi[cpt] == j.Cndi[cpt]); + xbt_assert(i.Cnshr == j.Cnshr); + xbt_assert(i.Cnpt == j.Cnpt); + xbt_assert(i.Cdtime == j.Cdtime); + xbt_assert(i.Ctime[0] == j.Ctime[0]); + xbt_assert(i.Ctime[1] == j.Ctime[1]); + xbt_assert(i.Cntens == j.Cntens); + for (cpt=0; cpt<3; cpt++) { + for (cpt2=0; cpt2<373; cpt2++) + xbt_assert(i.Cdfgrd0[cpt2][cpt] == j.Cdfgrd0[cpt2][cpt]); + for (cpt2=0; cpt2<3; cpt2++) + xbt_assert(i.Cdfgrd1[cpt][cpt2] == j.Cdfgrd1[cpt][cpt2]); + } + for (cpt=0; cpt<106; cpt++) { + xbt_assert(i.Cstress[cpt] == j.Cstress[cpt]); + for (cpt2=0; cpt2<106; cpt2++) + xbt_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_DEFINE_TYPE(s_clause, -struct s_clause { - int num_lits; - int *literals GRAS_ANNOTE(size,num_lits); /* Tells GRAS where to find the size */ + 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; static void test_clause(gras_socket_t sock, int direction) { - Clause *i,*j; - int cpt; - - INFO0("---- Test on struct containing dynamic array and its size (cbps test) ----"); - - /* create and fill the struct */ - i=xbt_new(Clause,1); - - i->num_lits = 5432; - i->literals = xbt_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); - - write_read("Clause*", &i,&j, sock,direction); - if (direction == READ || direction == COPY) { - xbt_assert(i->num_lits == j->num_lits); - for (cpt=0; cptnum_lits; cpt++) - xbt_assert(i->literals[cpt] == j->literals[cpt]); - - free(j->literals); - free(j); - } - free(i->literals); - free(i); + Clause *i,*j; + int cpt; + + INFO0("---- Test on struct containing dynamic array and its size (cbps test) ----"); + + /* create and fill the struct */ + i=xbt_new(Clause,1); + + i->num_lits = 5432; + i->literals = xbt_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); + + write_read("Clause*", &i,&j, sock,direction); + if (direction == READ || direction == COPY) { + xbt_assert(i->num_lits == j->num_lits); + for (cpt=0; cptnum_lits; cpt++) + xbt_assert(i->literals[cpt] == j->literals[cpt]); + + free(j->literals); + free(j); + } + free(i->literals); + free(i); +} + +static void test_clause_empty(gras_socket_t sock, int direction) { + Clause *i,*j; + + INFO0("---- Test on struct containing dynamic array and its size when size=0 (cbps test) ----"); + + /* create and fill the struct */ + i=xbt_new(Clause,1); + + i->num_lits = 0; + i->literals = xbt_new(int, 0); + DEBUG3("created data=%p (within %p @%p)",&(i->num_lits),i,&i); + DEBUG1("created count=%d",i->num_lits); + + write_read("Clause*", &i,&j, sock,direction); + if (direction == READ || direction == COPY) { + xbt_assert(i->num_lits == j->num_lits); + + free(j->literals); + free(j); + } + free(i->literals); + free(i); } static void register_types(void) { - gras_datadesc_type_t my_type,ref_my_type; - - gras_msgtype_declare("char",gras_datadesc_by_name("char")); - gras_msgtype_declare("int",gras_datadesc_by_name("int")); - gras_msgtype_declare("float",gras_datadesc_by_name("float")); - gras_msgtype_declare("double",gras_datadesc_by_name("double")); - - my_type=gras_datadesc_array_fixed("fixed int array", - gras_datadesc_by_name("int"), - FIXED_ARRAY_SIZE); - gras_msgtype_declare("fixed int array",my_type); - - my_type = gras_datadesc_dynar(gras_datadesc_by_name("int"),NULL); - gras_msgtype_declare("xbt_dynar_of_int",my_type); - - my_type = gras_datadesc_ref("int*",gras_datadesc_by_name("int")); - gras_msgtype_declare("int*",my_type); - - gras_msgtype_declare("string",gras_datadesc_by_name("string")); - - 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")); - gras_msgtype_declare("homostruct*",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")); - gras_msgtype_declare("hetestruct*",my_type); - - my_type=gras_datadesc_struct("nestedstruct"); - 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")); - gras_msgtype_declare("nestedstruct*",my_type); - - my_type=gras_datadesc_struct("chained_list_t"); - ref_my_type=gras_datadesc_ref("chained_list_t*",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); - gras_datadesc_cycle_set(gras_datadesc_by_name("chained_list_t*")); - gras_msgtype_declare("chained_list_t",my_type); - gras_msgtype_declare("chained_list_t*",ref_my_type); - - my_type = gras_datadesc_dynar(gras_datadesc_by_name("string"),&free_string); - gras_msgtype_declare("xbt_dynar_of_string",my_type); - - my_type = gras_datadesc_by_symbol(s_pbio); - gras_msgtype_declare("s_pbio",my_type); - - my_type = gras_datadesc_by_symbol(s_clause); - my_type = gras_datadesc_ref("Clause*",my_type); - gras_msgtype_declare("Clause*",my_type); + gras_datadesc_type_t my_type,ref_my_type; + + gras_msgtype_declare("char",gras_datadesc_by_name("char")); + gras_msgtype_declare("int",gras_datadesc_by_name("int")); + gras_msgtype_declare("float",gras_datadesc_by_name("float")); + gras_msgtype_declare("double",gras_datadesc_by_name("double")); + + my_type=gras_datadesc_array_fixed("fixed int array", + gras_datadesc_by_name("int"), + FIXED_ARRAY_SIZE); + gras_msgtype_declare("fixed int array",my_type); + + my_type = gras_datadesc_dynar(gras_datadesc_by_name("int"),NULL); + gras_msgtype_declare("xbt_dynar_of_int",my_type); + + my_type = gras_datadesc_ref("int*",gras_datadesc_by_name("int")); + gras_msgtype_declare("int*",my_type); + + gras_msgtype_declare("string",gras_datadesc_by_name("string")); + + 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")); + gras_msgtype_declare("homostruct*",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")); + gras_msgtype_declare("hetestruct*",my_type); + + my_type = gras_datadesc_array_fixed("hetestruct[10]",gras_datadesc_by_name("hetestruct"),10); + my_type = gras_datadesc_ref("hetestruct[10]*", my_type); + gras_msgtype_declare("hetestruct[10]*",my_type); + + my_type=gras_datadesc_struct("nestedstruct"); + 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")); + gras_msgtype_declare("nestedstruct*",my_type); + + my_type=gras_datadesc_struct("chained_list_t"); + ref_my_type=gras_datadesc_ref("chained_list_t*",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); + gras_datadesc_cycle_set(gras_datadesc_by_name("chained_list_t*")); + gras_msgtype_declare("chained_list_t",my_type); + gras_msgtype_declare("chained_list_t*",ref_my_type); + + my_type = gras_datadesc_dynar(gras_datadesc_by_name("string"),&free_string); + gras_msgtype_declare("xbt_dynar_of_string",my_type); + + my_type = gras_datadesc_by_symbol(s_pbio); + gras_msgtype_declare("s_pbio",my_type); + + my_type = gras_datadesc_by_symbol(s_clause); + my_type = gras_datadesc_ref("Clause*",my_type); + gras_msgtype_declare("Clause*",my_type); } @@ -573,73 +645,92 @@ static void register_types(void) { #endif int main(int argc,char *argv[]) { - gras_socket_t sock=NULL; - int direction = WRITE; - int cpt; - char local_arch, remote_arch; - - gras_init(&argc,argv); - register_types(); - register_structures(); - - for (cpt=1; cpt