From: alegrand Date: Mon, 11 Oct 2010 09:49:00 +0000 (+0000) Subject: Indent the rest of the code (examples, buildtools, doc...) except for examples/SMPI... X-Git-Tag: v3_5~429 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cc01c6a871dbbfd0cc84e26eb9f94aeb539e613e?hp=0f5e8daaa6e9f74521068aa75837200bcd182ea6 Indent the rest of the code (examples, buildtools, doc...) except for examples/SMPI/NAS... git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8395 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c b/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c index 2fc26ed4ce..59d5289ab1 100644 --- a/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c +++ b/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c @@ -8,10 +8,10 @@ #include #ifdef _XBT_WIN32 - #include "win32_ucontext.h" - #include "win32_ucontext.c" +#include "win32_ucontext.h" +#include "win32_ucontext.c" #else - #include +#include #endif void child(void); @@ -23,43 +23,43 @@ ucontext_t uc_main; void child(void) { - if (swapcontext(&uc_child, &uc_main) != 0) - exit(2); + if (swapcontext(&uc_child, &uc_main) != 0) + exit(2); } int main(int argc, char *argv[]) { - FILE *fp; - void *stack; + FILE *fp; + void *stack; - /* the default is that it fails */ - if ((fp = fopen("conftestval", "w")) == NULL) - exit(3); - fprintf(fp, "no\n"); - fclose(fp); + /* the default is that it fails */ + if ((fp = fopen("conftestval", "w")) == NULL) + exit(3); + fprintf(fp, "no\n"); + fclose(fp); - /* configure a child user-space context */ - if ((stack = malloc(64*1024)) == NULL) - exit(4); - if (getcontext(&uc_child) != 0) - exit(5); - uc_child.uc_link = NULL; - uc_child.uc_stack.ss_sp = (char *)stack+(32*1024); - uc_child.uc_stack.ss_size = 32*1024; - uc_child.uc_stack.ss_flags = 0; - makecontext(&uc_child, child, 0); + /* configure a child user-space context */ + if ((stack = malloc(64 * 1024)) == NULL) + exit(4); + if (getcontext(&uc_child) != 0) + exit(5); + uc_child.uc_link = NULL; + uc_child.uc_stack.ss_sp = (char *) stack + (32 * 1024); + uc_child.uc_stack.ss_size = 32 * 1024; + uc_child.uc_stack.ss_flags = 0; + makecontext(&uc_child, child, 0); - /* switch into the user context */ - if (swapcontext(&uc_main, &uc_child) != 0) - exit(6); + /* switch into the user context */ + if (swapcontext(&uc_main, &uc_child) != 0) + exit(6); - /* Fine, child came home */ - if ((fp = fopen("conftestval", "w")) == NULL) - exit(7); - fprintf(fp, "yes\n"); - fclose(fp); + /* Fine, child came home */ + if ((fp = fopen("conftestval", "w")) == NULL) + exit(7); + fprintf(fp, "yes\n"); + fclose(fp); - /* die successfully */ - exit(0); - return 1; + /* die successfully */ + exit(0); + return 1; } diff --git a/buildtools/Cmake/test_prog/prog_GRAS_ARCH.c b/buildtools/Cmake/test_prog/prog_GRAS_ARCH.c index 52b03afab2..00b6dffcbc 100644 --- a/buildtools/Cmake/test_prog/prog_GRAS_ARCH.c +++ b/buildtools/Cmake/test_prog/prog_GRAS_ARCH.c @@ -9,49 +9,72 @@ #include #include -int main (void) +int main(void) { - int c = sizeof(char); - int si = sizeof(short int); - int i = sizeof(int); - int li = sizeof(long int); - int lli = sizeof(long long int); - int f = sizeof(float); - int v = sizeof(void *); - int vv = sizeof(void (*) (void)); - /*printf("char : %d\n",c); - printf("short int : %d\n",si); - printf("int : %d\n",i); - printf("long int : %d\n",li); - printf("long long int : %d\n",lli); - printf("float : %d\n",f); - printf("void * : %d\n",v); - printf("void (*) (void) : %d\n",vv);*/ + int c = sizeof(char); + int si = sizeof(short int); + int i = sizeof(int); + int li = sizeof(long int); + int lli = sizeof(long long int); + int f = sizeof(float); + int v = sizeof(void *); + int vv = sizeof(void (*)(void)); + /*printf("char : %d\n",c); + printf("short int : %d\n",si); + printf("int : %d\n",i); + printf("long int : %d\n",li); + printf("long long int : %d\n",lli); + printf("float : %d\n",f); + printf("void * : %d\n",v); + printf("void (*) (void) : %d\n",vv); */ - struct s0 {char c0; char i0;}; - struct s1 {char c1; short int i1;}; - struct s2 {char c2; int i2;}; - struct s3 {char c3; long int i3;}; - struct s4 {char c4; long long int i4;}; - struct s5 {char c5; double i5;}; - struct s6 {char c6; void * i6;}; - int res0=sizeof(struct s0)-sizeof(char); - int res1=sizeof(struct s1)-sizeof(short int); - int res2=sizeof(struct s2)-sizeof(int); - int res3=sizeof(struct s3)-sizeof(long int); - int res4=sizeof(struct s4)-sizeof(long long int); - int res5=sizeof(struct s5)-sizeof(double); - int res6=sizeof(struct s6)-sizeof(void *); - /*printf("struct-char : %d\n",res0); - printf("struct-short int : %d\n",res1); - printf("struct-int : %d\n",res2); - printf("struct-long int : %d\n",res3); - printf("struct-long long int : %d\n",res4); - printf("struct-double : %d\n",res5); - printf("struct-void * : %d\n",res6);*/ + struct s0 { + char c0; + char i0; + }; + struct s1 { + char c1; + short int i1; + }; + struct s2 { + char c2; + int i2; + }; + struct s3 { + char c3; + long int i3; + }; + struct s4 { + char c4; + long long int i4; + }; + struct s5 { + char c5; + double i5; + }; + struct s6 { + char c6; + void *i6; + }; + int res0 = sizeof(struct s0) - sizeof(char); + int res1 = sizeof(struct s1) - sizeof(short int); + int res2 = sizeof(struct s2) - sizeof(int); + int res3 = sizeof(struct s3) - sizeof(long int); + int res4 = sizeof(struct s4) - sizeof(long long int); + int res5 = sizeof(struct s5) - sizeof(double); + int res6 = sizeof(struct s6) - sizeof(void *); + /*printf("struct-char : %d\n",res0); + printf("struct-short int : %d\n",res1); + printf("struct-int : %d\n",res2); + printf("struct-long int : %d\n",res3); + printf("struct-long long int : %d\n",res4); + printf("struct-double : %d\n",res5); + printf("struct-void * : %d\n",res6); */ - printf("_C:%d/%d:_I:%d/%d:%d/%d:%d/%d:%d/%d:_P:%d/%d:%d/%d:_D:4/%d:8/%d:",c,res0,si,res1,i,res2,li,res3,lli,res4,v,res6,vv,res6,f,res5); - return 1; + printf + ("_C:%d/%d:_I:%d/%d:%d/%d:%d/%d:%d/%d:_P:%d/%d:%d/%d:_D:4/%d:8/%d:", + c, res0, si, res1, i, res2, li, res3, lli, res4, v, res6, vv, res6, + f, res5); + return 1; } - diff --git a/buildtools/Cmake/test_prog/prog_GRAS_CHECK_STRUCT_COMPACTION.c b/buildtools/Cmake/test_prog/prog_GRAS_CHECK_STRUCT_COMPACTION.c index 059941d8e3..865eeafc8c 100644 --- a/buildtools/Cmake/test_prog/prog_GRAS_CHECK_STRUCT_COMPACTION.c +++ b/buildtools/Cmake/test_prog/prog_GRAS_CHECK_STRUCT_COMPACTION.c @@ -5,62 +5,68 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include -#include /* offsetof() */ +#include /* offsetof() */ #include -int main (void) +int main(void) { -struct s0 {char c0; double d0;}; -struct s1 {double d1; int i1; char c1;}; -struct s2 {double d2; int i2; char c2[6];}; -struct s3 {double d3; int a3; int b3;}; + struct s0 { + char c0; + double d0; + }; + struct s1 { + double d1; + int i1; + char c1; + }; + struct s2 { + double d2; + int i2; + char c2[6]; + }; + struct s3 { + double d3; + int a3; + int b3; + }; -int gras_struct_packed; -int gras_struct_compact; -int gras_array_straddle_struct; -int gras_compact_struct; + int gras_struct_packed; + int gras_struct_compact; + int gras_array_straddle_struct; + int gras_compact_struct; - if (sizeof(struct s0) == sizeof(double)+sizeof(char)) - { - gras_struct_packed=1; - } - else - { - gras_struct_packed=0; - } - if (offsetof(struct s1,c1) == sizeof(double)+sizeof(int)) - { - gras_struct_compact=1; - } - else - { - gras_struct_compact=0; - } - if (offsetof(struct s2,c2) == sizeof(double)+sizeof(int)) - { - gras_array_straddle_struct=1; - } - else - { - gras_array_straddle_struct=0; - } - if (offsetof(struct s3,b3) == sizeof(double)+sizeof(int)) - { - gras_compact_struct=1; - } - else - { - gras_compact_struct=0; - } + if (sizeof(struct s0) == sizeof(double) + sizeof(char)) { + gras_struct_packed = 1; + } else { + gras_struct_packed = 0; + } + if (offsetof(struct s1, c1) == sizeof(double) + sizeof(int)) { + gras_struct_compact = 1; + } else { + gras_struct_compact = 0; + } + if (offsetof(struct s2, c2) == sizeof(double) + sizeof(int)) { + gras_array_straddle_struct = 1; + } else { + gras_array_straddle_struct = 0; + } + if (offsetof(struct s3, b3) == sizeof(double) + sizeof(int)) { + gras_compact_struct = 1; + } else { + gras_compact_struct = 0; + } - if(gras_struct_packed == 0 && gras_struct_compact == 1) printf("GRAS_STRUCT_COMPACT "); + if (gras_struct_packed == 0 && gras_struct_compact == 1) + printf("GRAS_STRUCT_COMPACT "); - if(gras_array_straddle_struct == 1) printf("GRAS_ARRAY_STRADDLE_STRUCT "); + if (gras_array_straddle_struct == 1) + printf("GRAS_ARRAY_STRADDLE_STRUCT "); - if(gras_compact_struct == 1) printf("GRAS_COMPACT_STRUCT "); + if (gras_compact_struct == 1) + printf("GRAS_COMPACT_STRUCT "); -return 1; + return 1; } diff --git a/buildtools/Cmake/test_prog/prog_getline.c b/buildtools/Cmake/test_prog/prog_getline.c index 81a257f4ad..0c4780c37c 100644 --- a/buildtools/Cmake/test_prog/prog_getline.c +++ b/buildtools/Cmake/test_prog/prog_getline.c @@ -6,9 +6,10 @@ #define _GNU_SOURCE #include -int main(void){ - FILE * fp; - char * line = NULL; - size_t len = 0; - getline(&line, &len, fp); +int main(void) +{ + FILE *fp; + char *line = NULL; + size_t len = 0; + getline(&line, &len, fp); } diff --git a/buildtools/Cmake/test_prog/prog_max_size.c b/buildtools/Cmake/test_prog/prog_max_size.c index d89e76d37d..021c5d5f18 100644 --- a/buildtools/Cmake/test_prog/prog_max_size.c +++ b/buildtools/Cmake/test_prog/prog_max_size.c @@ -10,27 +10,26 @@ #include #include -int main (void) +int main(void) { - int c = sizeof(char); - int si = sizeof(short int); - int i = sizeof(int); - int li = sizeof(long int); - int lli = sizeof(long long int); - int f = sizeof(float); - int v = sizeof(void *); - int vv = sizeof(void (*) (void)); - int t[8] = {c,si,i,li,lli,f,v,vv}; - - int max = t[0]; - - for (i = 1; i < 8; i++) - { - if (t[i] > max) max = t[i]; - - } - printf("%d",max); - return 1; + int c = sizeof(char); + int si = sizeof(short int); + int i = sizeof(int); + int li = sizeof(long int); + int lli = sizeof(long long int); + int f = sizeof(float); + int v = sizeof(void *); + int vv = sizeof(void (*)(void)); + int t[8] = { c, si, i, li, lli, f, v, vv }; + + int max = t[0]; + + for (i = 1; i < 8; i++) { + if (t[i] > max) + max = t[i]; + + } + printf("%d", max); + return 1; } - diff --git a/buildtools/Cmake/test_prog/prog_mutex_timedlock.c b/buildtools/Cmake/test_prog/prog_mutex_timedlock.c index c3eb72d34e..1b0664a4a3 100644 --- a/buildtools/Cmake/test_prog/prog_mutex_timedlock.c +++ b/buildtools/Cmake/test_prog/prog_mutex_timedlock.c @@ -6,9 +6,9 @@ #include -void main (void) +void main(void) { - pthread_mutex_t s; - const struct timespec t; - sem_timedlock(&s, &t); + pthread_mutex_t s; + const struct timespec t; + sem_timedlock(&s, &t); } diff --git a/buildtools/Cmake/test_prog/prog_printf_null.c b/buildtools/Cmake/test_prog/prog_printf_null.c index 473d6c58c6..00277d405a 100644 --- a/buildtools/Cmake/test_prog/prog_printf_null.c +++ b/buildtools/Cmake/test_prog/prog_printf_null.c @@ -5,4 +5,4 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include -printf("%s",NULL); +printf("%s", NULL); diff --git a/buildtools/Cmake/test_prog/prog_sem_init.c b/buildtools/Cmake/test_prog/prog_sem_init.c index f4d303852d..0fe001f76a 100644 --- a/buildtools/Cmake/test_prog/prog_sem_init.c +++ b/buildtools/Cmake/test_prog/prog_sem_init.c @@ -8,6 +8,6 @@ void main(void) { - sem_t s; - sem_init(&s); + sem_t s; + sem_init(&s); } diff --git a/buildtools/Cmake/test_prog/prog_sem_timedwait.c b/buildtools/Cmake/test_prog/prog_sem_timedwait.c index 58876f671f..994d9ad818 100644 --- a/buildtools/Cmake/test_prog/prog_sem_timedwait.c +++ b/buildtools/Cmake/test_prog/prog_sem_timedwait.c @@ -8,7 +8,7 @@ int main() { - sem_t *s; - const struct timespec * t; - sem_timedwait(s, t); + sem_t *s; + const struct timespec *t; + sem_timedwait(s, t); } diff --git a/buildtools/Cmake/test_prog/prog_snprintf.c b/buildtools/Cmake/test_prog/prog_snprintf.c index a33c8467fb..60f24037b3 100644 --- a/buildtools/Cmake/test_prog/prog_snprintf.c +++ b/buildtools/Cmake/test_prog/prog_snprintf.c @@ -8,14 +8,18 @@ int main(void) { - char bufs[5] = { 'x', 'x', 'x', '\0', '\0' }; - char bufd[5] = { 'x', 'x', 'x', '\0', '\0' }; - int i; - i = snprintf (bufs, 2, "%s", "111"); - if (strcmp (bufs, "1")) exit (1); - if (i != 3) exit (1); - i = snprintf (bufd, 2, "%d", 111); - if (strcmp (bufd, "1")) exit (1); - if (i != 3) exit (1); - exit(0); + char bufs[5] = { 'x', 'x', 'x', '\0', '\0' }; + char bufd[5] = { 'x', 'x', 'x', '\0', '\0' }; + int i; + i = snprintf(bufs, 2, "%s", "111"); + if (strcmp(bufs, "1")) + exit(1); + if (i != 3) + exit(1); + i = snprintf(bufd, 2, "%d", 111); + if (strcmp(bufd, "1")) + exit(1); + if (i != 3) + exit(1); + exit(0); } diff --git a/buildtools/Cmake/test_prog/prog_stackgrowth.c b/buildtools/Cmake/test_prog/prog_stackgrowth.c index c1a9e7804f..f0f2f1a4ac 100644 --- a/buildtools/Cmake/test_prog/prog_stackgrowth.c +++ b/buildtools/Cmake/test_prog/prog_stackgrowth.c @@ -9,22 +9,23 @@ static int iterate = 10; static int growsdown(int *x) { - auto int y; - y = (x > &y); - if (--iterate > 0) - y = growsdown(&y); - if (y != (x > &y)) - exit(1); - return y; + auto int y; + y = (x > &y); + if (--iterate > 0) + y = growsdown(&y); + if (y != (x > &y)) + exit(1); + return y; } + int main(int argc, char *argv[]) { - FILE *f; - auto int x; - if ((f = fopen("conftestval", "w")) == NULL) - exit(1); - fprintf(f, "%s\n", growsdown(&x) ? "down" : "up");; - fclose(f); - exit(0); - return 1; + FILE *f; + auto int x; + if ((f = fopen("conftestval", "w")) == NULL) + exit(1); + fprintf(f, "%s\n", growsdown(&x) ? "down" : "up");; + fclose(f); + exit(0); + return 1; } diff --git a/buildtools/Cmake/test_prog/prog_stacksetup.c b/buildtools/Cmake/test_prog/prog_stacksetup.c index 8bffd64f21..66dcba0157 100644 --- a/buildtools/Cmake/test_prog/prog_stacksetup.c +++ b/buildtools/Cmake/test_prog/prog_stacksetup.c @@ -9,8 +9,8 @@ #endif #ifdef _XBT_WIN32 - #include "win32_ucontext.h" - #include "win32_ucontext.c" +#include "win32_ucontext.h" +#include "win32_ucontext.c" #endif #include @@ -24,32 +24,32 @@ #if defined(TEST_makecontext) #ifdef _XBT_WIN32 - #include "win32_ucontext.h" +#include "win32_ucontext.h" #else - #include +#include #endif #endif union alltypes { - long l; - double d; - void *vp; - void (*fp)(void); - char *cp; + long l; + double d; + void *vp; + void (*fp) (void); + char *cp; }; -static volatile char *handler_addr = (char *)0xDEAD; +static volatile char *handler_addr = (char *) 0xDEAD; #if defined(TEST_sigstack) || defined(TEST_sigaltstack) static volatile int handler_done = 0; void handler(int sig) { - char garbage[1024]; - int i; - auto int dummy; - for (i = 0; i < 1024; i++) - garbage[i] = 'X'; - handler_addr = (char *)&dummy; - handler_done = 1; - return; + char garbage[1024]; + int i; + auto int dummy; + for (i = 0; i < 1024; i++) + garbage[i] = 'X'; + handler_addr = (char *) &dummy; + handler_done = 1; + return; } #endif #if defined(TEST_makecontext) @@ -57,96 +57,95 @@ static ucontext_t uc_handler; static ucontext_t uc_main; void handler(void) { - char garbage[1024]; - int i; - auto int dummy; - for (i = 0; i < 1024; i++) - garbage[i] = 'X'; - handler_addr = (char *)&dummy; - swapcontext(&uc_handler, &uc_main); - return; + char garbage[1024]; + int i; + auto int dummy; + for (i = 0; i < 1024; i++) + garbage[i] = 'X'; + handler_addr = (char *) &dummy; + swapcontext(&uc_handler, &uc_main); + return; } #endif int main(int argc, char *argv[]) { - FILE *f; - char *skaddr; - char *skbuf; - int sksize; - char result[1024]; - int i; - sksize = 32768; - skbuf = (char *)malloc(sksize*2+2*sizeof(union alltypes)); - if (skbuf == NULL) - exit(1); - for (i = 0; i < sksize*2+2*sizeof(union alltypes); i++) - skbuf[i] = 'A'; - skaddr = skbuf+sizeof(union alltypes); + FILE *f; + char *skaddr; + char *skbuf; + int sksize; + char result[1024]; + int i; + sksize = 32768; + skbuf = (char *) malloc(sksize * 2 + 2 * sizeof(union alltypes)); + if (skbuf == NULL) + exit(1); + for (i = 0; i < sksize * 2 + 2 * sizeof(union alltypes); i++) + skbuf[i] = 'A'; + skaddr = skbuf + sizeof(union alltypes); #if defined(TEST_sigstack) || defined(TEST_sigaltstack) - { - struct sigaction sa; + { + struct sigaction sa; #if defined(TEST_sigstack) - struct sigstack ss; + struct sigstack ss; #elif defined(TEST_sigaltstack) && defined(HAVE_STACK_T) - stack_t ss; + stack_t ss; #else - struct sigaltstack ss; + struct sigaltstack ss; #endif #if defined(TEST_sigstack) - ss.ss_sp = (void *)(skaddr + sksize); - ss.ss_onstack = 0; - if (sigstack(&ss, NULL) < 0) - exit(1); + ss.ss_sp = (void *) (skaddr + sksize); + ss.ss_onstack = 0; + if (sigstack(&ss, NULL) < 0) + exit(1); #elif defined(TEST_sigaltstack) - ss.ss_sp = (void *)(skaddr + sksize); - ss.ss_size = sksize; - ss.ss_flags = 0; - if (sigaltstack(&ss, NULL) < 0) - exit(1); + ss.ss_sp = (void *) (skaddr + sksize); + ss.ss_size = sksize; + ss.ss_flags = 0; + if (sigaltstack(&ss, NULL) < 0) + exit(1); #endif - memset((void *)&sa, 0, sizeof(struct sigaction)); - sa.sa_handler = handler; - sa.sa_flags = SA_ONSTACK; - sigemptyset(&sa.sa_mask); - sigaction(SIGUSR1, &sa, NULL); - kill(getpid(), SIGUSR1); - while (!handler_done) - /*nop*/; - } + memset((void *) &sa, 0, sizeof(struct sigaction)); + sa.sa_handler = handler; + sa.sa_flags = SA_ONSTACK; + sigemptyset(&sa.sa_mask); + sigaction(SIGUSR1, &sa, NULL); + kill(getpid(), SIGUSR1); + while (!handler_done) + /*nop */ ; + } #endif #if defined(TEST_makecontext) - { - if (getcontext(&uc_handler) != 0) - exit(1); - uc_handler.uc_link = NULL; - uc_handler.uc_stack.ss_sp = (void *)(skaddr + sksize); - uc_handler.uc_stack.ss_size = sksize; - uc_handler.uc_stack.ss_flags = 0; - makecontext(&uc_handler, handler, 0); - swapcontext(&uc_main, &uc_handler); - } + { + if (getcontext(&uc_handler) != 0) + exit(1); + uc_handler.uc_link = NULL; + uc_handler.uc_stack.ss_sp = (void *) (skaddr + sksize); + uc_handler.uc_stack.ss_size = sksize; + uc_handler.uc_stack.ss_flags = 0; + makecontext(&uc_handler, handler, 0); + swapcontext(&uc_main, &uc_handler); + } #endif - if (handler_addr == (char *)0xDEAD) - exit(1); - if (handler_addr < skaddr+sksize) { - /* stack was placed into lower area */ - if (*(skaddr+sksize) != 'A') - sprintf(result, "(skaddr)+(sksize)-%d,(sksize)-%d", - sizeof(union alltypes), sizeof(union alltypes)); - else - strcpy(result, "(skaddr)+(sksize),(sksize)"); - } - else { - /* stack was placed into higher area */ - if (*(skaddr+sksize*2) != 'A') - sprintf(result, "(skaddr),(sksize)-%d", sizeof(union alltypes)); - else - strcpy(result, "(skaddr),(sksize)"); - } - if ((f = fopen("conftestval", "w")) == NULL) - exit(1); - fprintf(f, "%s\n", result); - fclose(f); - exit(0); - return 1; + if (handler_addr == (char *) 0xDEAD) + exit(1); + if (handler_addr < skaddr + sksize) { + /* stack was placed into lower area */ + if (*(skaddr + sksize) != 'A') + sprintf(result, "(skaddr)+(sksize)-%d,(sksize)-%d", + sizeof(union alltypes), sizeof(union alltypes)); + else + strcpy(result, "(skaddr)+(sksize),(sksize)"); + } else { + /* stack was placed into higher area */ + if (*(skaddr + sksize * 2) != 'A') + sprintf(result, "(skaddr),(sksize)-%d", sizeof(union alltypes)); + else + strcpy(result, "(skaddr),(sksize)"); + } + if ((f = fopen("conftestval", "w")) == NULL) + exit(1); + fprintf(f, "%s\n", result); + fclose(f); + exit(0); + return 1; } diff --git a/buildtools/Cmake/test_prog/prog_vsnprintf.c b/buildtools/Cmake/test_prog/prog_vsnprintf.c index 30f4a9d22b..26e1db922b 100644 --- a/buildtools/Cmake/test_prog/prog_vsnprintf.c +++ b/buildtools/Cmake/test_prog/prog_vsnprintf.c @@ -7,26 +7,30 @@ #include #include -int my_vsnprintf (char *buf, const char *tmpl, ...) +int my_vsnprintf(char *buf, const char *tmpl, ...) { - int i; - va_list args; - va_start (args, tmpl); - i = vsnprintf (buf, 2, tmpl, args); - va_end (args); - return i; + int i; + va_list args; + va_start(args, tmpl); + i = vsnprintf(buf, 2, tmpl, args); + va_end(args); + return i; } int main(void) { - char bufs[5] = { 'x', 'x', 'x', '\0', '\0' }; - char bufd[5] = { 'x', 'x', 'x', '\0', '\0' }; - int i; - i = my_vsnprintf (bufs, "%s", "111"); - if (strcmp (bufs, "1")) exit (1); - if (i != 3) exit (1); - i = my_vsnprintf (bufd, "%d", 111); - if (strcmp (bufd, "1")) exit (1); - if (i != 3) exit (1); - exit(0); + char bufs[5] = { 'x', 'x', 'x', '\0', '\0' }; + char bufd[5] = { 'x', 'x', 'x', '\0', '\0' }; + int i; + i = my_vsnprintf(bufs, "%s", "111"); + if (strcmp(bufs, "1")) + exit(1); + if (i != 3) + exit(1); + i = my_vsnprintf(bufd, "%d", 111); + if (strcmp(bufd, "1")) + exit(1); + if (i != 3) + exit(1); + exit(0); } diff --git a/buildtools/builder6/libgras/libgras.c b/buildtools/builder6/libgras/libgras.c index cf253eeff3..dcf146c528 100644 --- a/buildtools/builder6/libgras/libgras.c +++ b/buildtools/builder6/libgras/libgras.c @@ -23,8 +23,10 @@ //--------------------------------------------------------------------------- #pragma argsused -int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) +int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, + void *lpReserved) { - return 1; + return 1; } + //--------------------------------------------------------------------------- diff --git a/buildtools/builder6/simgrid/simgrid.c b/buildtools/builder6/simgrid/simgrid.c index 16c8e2a98b..dcf146c528 100644 --- a/buildtools/builder6/simgrid/simgrid.c +++ b/buildtools/builder6/simgrid/simgrid.c @@ -23,9 +23,10 @@ //--------------------------------------------------------------------------- #pragma argsused -int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) +int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, + void *lpReserved) { - return 1; + return 1; } + //--------------------------------------------------------------------------- - \ No newline at end of file diff --git a/buildtools/vc7/cxx/SimGridX.c b/buildtools/vc7/cxx/SimGridX.c index 7f50312cbc..41e4702cc1 100644 --- a/buildtools/vc7/cxx/SimGridX.c +++ b/buildtools/vc7/cxx/SimGridX.c @@ -1,11 +1,11 @@ #include #include - -/* logs */ + +/* logs */ // XBT_LOG_NEW_DEFAULT_CATEGORY(SimGridX,"SimGrid for cxx"); - -int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) -{ - return 1; -} \ No newline at end of file + int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, + void *lpReserved) +{ + return 1; + } diff --git a/buildtools/vc7/simgrid/simgrid.c b/buildtools/vc7/simgrid/simgrid.c index c2a6fe57e0..b896056c98 100644 --- a/buildtools/vc7/simgrid/simgrid.c +++ b/buildtools/vc7/simgrid/simgrid.c @@ -1,7 +1,6 @@ #include - - -int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) -{ - return 1; -} \ No newline at end of file + int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, + void *lpReserved) +{ + return 1; + } diff --git a/buildtools/vc7/simgrid4java/libSimgrid4java.c b/buildtools/vc7/simgrid4java/libSimgrid4java.c index c2a6fe57e0..b896056c98 100644 --- a/buildtools/vc7/simgrid4java/libSimgrid4java.c +++ b/buildtools/vc7/simgrid4java/libSimgrid4java.c @@ -1,7 +1,6 @@ #include - - -int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) -{ - return 1; -} \ No newline at end of file + int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, + void *lpReserved) +{ + return 1; + } diff --git a/doc/gtut-files/01-bones.c b/doc/gtut-files/01-bones.c index ea9a3c0bf2..97fea9378b 100644 --- a/doc/gtut-files/01-bones.c +++ b/doc/gtut-files/01-bones.c @@ -6,20 +6,22 @@ #include -int client(int argc, char *argv[]) { - gras_init(&argc,argv); +int client(int argc, char *argv[]) +{ + gras_init(&argc, argv); /* Your own code for the client process */ - + gras_exit(); return 0; } -int server(int argc, char *argv[]) { - gras_init(&argc,argv); +int server(int argc, char *argv[]) +{ + gras_init(&argc, argv); /* Your own code for the server process */ - + gras_exit(); return 0; } diff --git a/doc/gtut-files/02-simple.c b/doc/gtut-files/02-simple.c index ded8811cd9..269414cb48 100644 --- a/doc/gtut-files/02-simple.c +++ b/doc/gtut-files/02-simple.c @@ -7,39 +7,44 @@ #include #include -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toclient; /* socket used to write to the client */ - - gras_init(&argc,argv); +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toclient; /* socket used to write to the client */ + + gras_init(&argc, argv); gras_msgtype_declare("hello", NULL); mysock = gras_socket_server(12345); - gras_msg_wait(60, "hello", &toclient, NULL /* no payload */); - - fprintf(stderr,"Cool, we received the message from %s:%d.\n", - gras_socket_peer_name(toclient), gras_socket_peer_port(toclient)); - + gras_msg_wait(60, "hello", &toclient, NULL /* no payload */ ); + + fprintf(stderr, "Cool, we received the message from %s:%d.\n", + gras_socket_peer_name(toclient), + gras_socket_peer_port(toclient)); + gras_exit(); return 0; } -int client(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toserver; /* socket used to write to the server */ - gras_init(&argc,argv); +int client(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ + + gras_init(&argc, argv); gras_msgtype_declare("hello", NULL); mysock = gras_socket_server_range(1024, 10000, 0, 0); - - fprintf(stderr,"Client ready; listening on %d\n", gras_socket_my_port(mysock)); - - gras_os_sleep(1.5); /* sleep 1 second and half */ + + fprintf(stderr, "Client ready; listening on %d\n", + gras_socket_my_port(mysock)); + + gras_os_sleep(1.5); /* sleep 1 second and half */ toserver = gras_socket_client("Jacquelin", 12345); - - gras_msg_send(toserver,"hello", NULL); - fprintf(stderr,"That's it, we sent the data to the server\n"); + + gras_msg_send(toserver, "hello", NULL); + fprintf(stderr, "That's it, we sent the data to the server\n"); gras_exit(); return 0; diff --git a/doc/gtut-files/03-args.c b/doc/gtut-files/03-args.c index 19070e7c33..06d6f1a166 100644 --- a/doc/gtut-files/03-args.c +++ b/doc/gtut-files/03-args.c @@ -7,39 +7,45 @@ #include #include -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toclient; /* socket used to write to the client */ - - gras_init(&argc,argv); +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toclient; /* socket used to write to the client */ + + gras_init(&argc, argv); gras_msgtype_declare("hello", NULL); mysock = gras_socket_server(atoi(argv[1])); - gras_msg_wait(60, "hello", &toclient, NULL /* no payload */); - - fprintf(stderr,"Cool, we received the message from %s:%d.\n", - gras_socket_peer_name(toclient), gras_socket_peer_port(toclient)); - + gras_msg_wait(60, "hello", &toclient, NULL /* no payload */ ); + + fprintf(stderr, "Cool, we received the message from %s:%d.\n", + gras_socket_peer_name(toclient), + gras_socket_peer_port(toclient)); + gras_exit(); return 0; } -int client(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toserver; /* socket used to write to the server */ - gras_init(&argc,argv); +int client(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ + + gras_init(&argc, argv); gras_msgtype_declare("hello", NULL); mysock = gras_socket_server_range(1024, 10000, 0, 0); - - fprintf(stderr,"Client ready; listening on %d\n", gras_socket_my_port(mysock)); - - gras_os_sleep(1.5); /* sleep 1 second and half */ + + fprintf(stderr, "Client ready; listening on %d\n", + gras_socket_my_port(mysock)); + + gras_os_sleep(1.5); /* sleep 1 second and half */ toserver = gras_socket_client(argv[1], atoi(argv[2])); - - gras_msg_send(toserver,"hello", NULL); - fprintf(stderr,"That's it, we sent the data to the server on %s\n", gras_socket_peer_name(toserver)); + + gras_msg_send(toserver, "hello", NULL); + fprintf(stderr, "That's it, we sent the data to the server on %s\n", + gras_socket_peer_name(toserver)); gras_exit(); return 0; diff --git a/doc/gtut-files/04-callback.c b/doc/gtut-files/04-callback.c index 956f6b5847..1e4c45f1bc 100644 --- a/doc/gtut-files/04-callback.c +++ b/doc/gtut-files/04-callback.c @@ -7,46 +7,51 @@ #include #include -int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) { +int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ gras_socket_t client = gras_msg_cb_ctx_from(ctx); - fprintf(stderr,"Cool, we received the message from %s:%d.\n", - gras_socket_peer_name(client), gras_socket_peer_port(client)); - + fprintf(stderr, "Cool, we received the message from %s:%d.\n", + gras_socket_peer_name(client), gras_socket_peer_port(client)); + return 0; -} /* end_of_callback */ +} /* end_of_callback */ + +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - - gras_init(&argc,argv); + gras_init(&argc, argv); gras_msgtype_declare("hello", NULL); mysock = gras_socket_server(atoi(argv[1])); - - gras_cb_register("hello",&server_hello_cb); + + gras_cb_register("hello", &server_hello_cb); gras_msg_handle(60); - + gras_exit(); return 0; } -int client(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toserver; /* socket used to write to the server */ +int client(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ - gras_init(&argc,argv); + gras_init(&argc, argv); gras_msgtype_declare("hello", NULL); mysock = gras_socket_server_range(1024, 10000, 0, 0); - - fprintf(stderr,"Client ready; listening on %d\n", gras_socket_my_port(mysock)); - - gras_os_sleep(1.5); /* sleep 1 second and half */ + + fprintf(stderr, "Client ready; listening on %d\n", + gras_socket_my_port(mysock)); + + gras_os_sleep(1.5); /* sleep 1 second and half */ toserver = gras_socket_client(argv[1], atoi(argv[2])); - - gras_msg_send(toserver,"hello", NULL); - fprintf(stderr,"That's it, we sent the data to the server on %s\n", gras_socket_peer_name(toserver)); + + gras_msg_send(toserver, "hello", NULL); + fprintf(stderr, "That's it, we sent the data to the server on %s\n", + gras_socket_peer_name(toserver)); gras_exit(); return 0; diff --git a/doc/gtut-files/05-globals.c b/doc/gtut-files/05-globals.c index a21233d432..4751176698 100644 --- a/doc/gtut-files/05-globals.c +++ b/doc/gtut-files/05-globals.c @@ -8,77 +8,84 @@ #include typedef struct { - int killed; + int killed; } server_data_t; - -int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) { + +int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ gras_socket_t client = gras_msg_cb_ctx_from(ctx); - server_data_t *globals=(server_data_t*)gras_userdata_get(); - - fprintf(stderr,"Argh, killed by %s:%d! Bye folks...\n", - gras_socket_peer_name(client), gras_socket_peer_port(client)); - + server_data_t *globals = (server_data_t *) gras_userdata_get(); + + fprintf(stderr, "Argh, killed by %s:%d! Bye folks...\n", + gras_socket_peer_name(client), gras_socket_peer_port(client)); + globals->killed = 1; - + return 0; -} /* end_of_kill_callback */ +} /* end_of_kill_callback */ -int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) { +int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ gras_socket_t client = gras_msg_cb_ctx_from(ctx); - fprintf(stderr,"Cool, we received the message from %s:%d.\n", - gras_socket_peer_name(client), gras_socket_peer_port(client)); - + fprintf(stderr, "Cool, we received the message from %s:%d.\n", + gras_socket_peer_name(client), gras_socket_peer_port(client)); + return 0; -} /* end_of_hello_callback */ +} /* end_of_hello_callback */ -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ server_data_t *globals; - - gras_init(&argc,argv); - globals=gras_userdata_new(server_data_t); - globals->killed=0; + gras_init(&argc, argv); + + globals = gras_userdata_new(server_data_t); + globals->killed = 0; gras_msgtype_declare("hello", NULL); gras_msgtype_declare("kill", NULL); mysock = gras_socket_server(atoi(argv[1])); - - gras_cb_register("hello",&server_hello_cb); - gras_cb_register("kill",&server_kill_cb); + + gras_cb_register("hello", &server_hello_cb); + gras_cb_register("kill", &server_kill_cb); while (!globals->killed) { - gras_msg_handle(-1); /* blocking */ + gras_msg_handle(-1); /* blocking */ } - + gras_exit(); return 0; } -int client(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toserver; /* socket used to write to the server */ +int client(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ - gras_init(&argc,argv); + gras_init(&argc, argv); gras_msgtype_declare("hello", NULL); gras_msgtype_declare("kill", NULL); mysock = gras_socket_server_range(1024, 10000, 0, 0); - - fprintf(stderr,"Client ready; listening on %d\n", gras_socket_my_port(mysock)); - - gras_os_sleep(1.5); /* sleep 1 second and half */ + + fprintf(stderr, "Client ready; listening on %d\n", + gras_socket_my_port(mysock)); + + gras_os_sleep(1.5); /* sleep 1 second and half */ toserver = gras_socket_client(argv[1], atoi(argv[2])); - - gras_msg_send(toserver,"hello", NULL); - fprintf(stderr,"we sent the data to the server on %s. Let's do it again for fun\n", gras_socket_peer_name(toserver)); - gras_msg_send(toserver,"hello", NULL); - - fprintf(stderr,"Ok. Enough. Have a rest, and then kill the server\n"); - gras_os_sleep(5); /* sleep 1 second and half */ - gras_msg_send(toserver,"kill", NULL); + + gras_msg_send(toserver, "hello", NULL); + fprintf(stderr, + "we sent the data to the server on %s. Let's do it again for fun\n", + gras_socket_peer_name(toserver)); + gras_msg_send(toserver, "hello", NULL); + + fprintf(stderr, "Ok. Enough. Have a rest, and then kill the server\n"); + gras_os_sleep(5); /* sleep 1 second and half */ + gras_msg_send(toserver, "kill", NULL); gras_exit(); return 0; diff --git a/doc/gtut-files/06-logs.c b/doc/gtut-files/06-logs.c index f0acfb7cd1..9ab044353b 100644 --- a/doc/gtut-files/06-logs.c +++ b/doc/gtut-files/06-logs.c @@ -6,80 +6,85 @@ #include -XBT_LOG_NEW_DEFAULT_CATEGORY(test,"My little example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(test, "My little example"); typedef struct { - int killed; + int killed; } server_data_t; - -int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) { + +int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ gras_socket_t client = gras_msg_cb_ctx_from(ctx); - server_data_t *globals=(server_data_t*)gras_userdata_get(); - + server_data_t *globals = (server_data_t *) gras_userdata_get(); + CRITICAL2("Argh, killed by %s:%d! Bye folks...", - gras_socket_peer_name(client), gras_socket_peer_port(client)); - + gras_socket_peer_name(client), gras_socket_peer_port(client)); + globals->killed = 1; - + return 0; -} /* end_of_kill_callback */ +} /* end_of_kill_callback */ -int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) { +int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ gras_socket_t client = gras_msg_cb_ctx_from(ctx); INFO2("Cool, we received the message from %s:%d.", - gras_socket_peer_name(client), gras_socket_peer_port(client)); - + gras_socket_peer_name(client), gras_socket_peer_port(client)); + return 0; -} /* end_of_hello_callback */ +} /* end_of_hello_callback */ -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ server_data_t *globals; - - gras_init(&argc,argv); - globals=gras_userdata_new(server_data_t*); - globals->killed=0; + gras_init(&argc, argv); + + globals = gras_userdata_new(server_data_t *); + globals->killed = 0; gras_msgtype_declare("hello", NULL); gras_msgtype_declare("kill", NULL); mysock = gras_socket_server(atoi(argv[1])); - - gras_cb_register("hello",&server_hello_cb); - gras_cb_register("kill",&server_kill_cb); + + gras_cb_register("hello", &server_hello_cb); + gras_cb_register("kill", &server_kill_cb); while (!globals->killed) { - gras_msg_handle(-1); /* blocking */ + gras_msg_handle(-1); /* blocking */ } - + gras_exit(); return 0; } -int client(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toserver; /* socket used to write to the server */ +int client(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ - gras_init(&argc,argv); + gras_init(&argc, argv); gras_msgtype_declare("hello", NULL); gras_msgtype_declare("kill", NULL); mysock = gras_socket_server_range(1024, 10000, 0, 0); - + VERB1("Client ready; listening on %d", gras_socket_my_port(mysock)); - - gras_os_sleep(1.5); /* sleep 1 second and half */ + + gras_os_sleep(1.5); /* sleep 1 second and half */ toserver = gras_socket_client(argv[1], atoi(argv[2])); - - gras_msg_send(toserver,"hello", NULL); - INFO1("we sent the data to the server on %s. Let's do it again for fun", gras_socket_peer_name(toserver)); - gras_msg_send(toserver,"hello", NULL); - + + gras_msg_send(toserver, "hello", NULL); + INFO1("we sent the data to the server on %s. Let's do it again for fun", + gras_socket_peer_name(toserver)); + gras_msg_send(toserver, "hello", NULL); + INFO0("Ok. Enough. Have a rest, and then kill the server"); - gras_os_sleep(5); /* sleep 1 second and half */ - gras_msg_send(toserver,"kill", NULL); + gras_os_sleep(5); /* sleep 1 second and half */ + gras_msg_send(toserver, "kill", NULL); gras_exit(); return 0; diff --git a/doc/gtut-files/07-timers.c b/doc/gtut-files/07-timers.c index cb5ad513df..6ddb67dde3 100644 --- a/doc/gtut-files/07-timers.c +++ b/doc/gtut-files/07-timers.c @@ -6,54 +6,57 @@ #include -XBT_LOG_NEW_DEFAULT_CATEGORY(test,"My little example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(test, "My little example"); /* *********************** Server *********************** */ typedef struct { - int killed; -} server_data_t; + int killed; +} server_data_t; -int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) { +int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ gras_socket_t client = gras_msg_cb_ctx_from(ctx); - server_data_t *globals=(server_data_t*)gras_userdata_get(); - + server_data_t *globals = (server_data_t *) gras_userdata_get(); + CRITICAL2("Argh, killed by %s:%d! Bye folks...", - gras_socket_peer_name(client), gras_socket_peer_port(client)); - + gras_socket_peer_name(client), gras_socket_peer_port(client)); + globals->killed = 1; - + return 0; -} /* end_of_kill_callback */ +} /* end_of_kill_callback */ -int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) { +int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ gras_socket_t client = gras_msg_cb_ctx_from(ctx); INFO2("Cool, we received the message from %s:%d.", - gras_socket_peer_name(client), gras_socket_peer_port(client)); - + gras_socket_peer_name(client), gras_socket_peer_port(client)); + return 0; -} /* end_of_hello_callback */ +} /* end_of_hello_callback */ -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ server_data_t *globals; - - gras_init(&argc,argv); - globals=gras_userdata_new(server_data_t*); - globals->killed=0; + gras_init(&argc, argv); + + globals = gras_userdata_new(server_data_t *); + globals->killed = 0; gras_msgtype_declare("hello", NULL); gras_msgtype_declare("kill", NULL); mysock = gras_socket_server(atoi(argv[1])); - - gras_cb_register("hello",&server_hello_cb); - gras_cb_register("kill",&server_kill_cb); + + gras_cb_register("hello", &server_hello_cb); + gras_cb_register("kill", &server_kill_cb); while (!globals->killed) { - gras_msg_handle(60); + gras_msg_handle(60); } - + gras_exit(); return 0; } @@ -61,59 +64,61 @@ int server(int argc, char *argv[]) { /* *********************** Client *********************** */ /* client_data */ typedef struct { - gras_socket_t toserver; - int done; + gras_socket_t toserver; + int done; } client_data_t; - -void client_do_hello(void) { - client_data_t *globals=(client_data_t*)gras_userdata_get(); - - gras_msg_send(globals->toserver,"hello", NULL); + +void client_do_hello(void) +{ + client_data_t *globals = (client_data_t *) gras_userdata_get(); + + gras_msg_send(globals->toserver, "hello", NULL); INFO0("Hello sent to server"); -} /* end_of_client_do_hello */ +} /* end_of_client_do_hello */ + +void client_do_stop(void) +{ + client_data_t *globals = (client_data_t *) gras_userdata_get(); -void client_do_stop(void) { - client_data_t *globals=(client_data_t*)gras_userdata_get(); - - gras_msg_send(globals->toserver,"kill", NULL); + gras_msg_send(globals->toserver, "kill", NULL); INFO0("Kill sent to server"); - - gras_timer_cancel_repeat(0.5,client_do_hello); - + + gras_timer_cancel_repeat(0.5, client_do_hello); + globals->done = 1; INFO0("Break the client's while loop"); -} /* end_of_client_do_stop */ +} /* end_of_client_do_stop */ -int client(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ +int client(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ client_data_t *globals; - gras_init(&argc,argv); + gras_init(&argc, argv); gras_msgtype_declare("hello", NULL); gras_msgtype_declare("kill", NULL); mysock = gras_socket_server_range(1024, 10000, 0, 0); - + VERB1("Client ready; listening on %d", gras_socket_my_port(mysock)); - - globals=gras_userdata_new(client_data_t*); + + globals = gras_userdata_new(client_data_t *); globals->done = 0; - - gras_os_sleep(1.5); /* sleep 1 second and half */ + + gras_os_sleep(1.5); /* sleep 1 second and half */ globals->toserver = gras_socket_client(argv[1], atoi(argv[2])); - + INFO0("Programming the repetitive action with a frequency of 0.5 sec"); - gras_timer_repeat(0.5,client_do_hello); - + gras_timer_repeat(0.5, client_do_hello); + INFO0("Programming the delayed action in 5 secs"); - gras_timer_delay(5,client_do_stop); - + gras_timer_delay(5, client_do_stop); + while (!globals->done) { - gras_msg_handle(60); + gras_msg_handle(60); } gras_exit(); return 0; } - diff --git a/doc/gtut-files/08-exceptions.c b/doc/gtut-files/08-exceptions.c index 6b90168abe..19d663e50c 100644 --- a/doc/gtut-files/08-exceptions.c +++ b/doc/gtut-files/08-exceptions.c @@ -6,86 +6,93 @@ #include -XBT_LOG_NEW_DEFAULT_CATEGORY(test,"My little example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(test, "My little example"); typedef struct { - int killed; + int killed; } server_data_t; - -int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) { + +int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ gras_socket_t client = gras_msg_cb_ctx_from(ctx); - server_data_t *globals=(server_data_t*)gras_userdata_get(); - + server_data_t *globals = (server_data_t *) gras_userdata_get(); + CRITICAL2("Argh, killed by %s:%d! Bye folks, I'm out of here...", - gras_socket_peer_name(client), gras_socket_peer_port(client)); - + gras_socket_peer_name(client), gras_socket_peer_port(client)); + globals->killed = 1; - + return 0; -} /* end_of_kill_callback */ +} /* end_of_kill_callback */ -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ server_data_t *globals; - - gras_init(&argc,argv); - globals=gras_userdata_new(server_data_t*); - globals->killed=0; + gras_init(&argc, argv); + + globals = gras_userdata_new(server_data_t *); + globals->killed = 0; gras_msgtype_declare("kill", NULL); - gras_cb_register("kill",&server_kill_cb); - - if (argc>1 && !strcmp(argv[1],"--cheat")) { - mysock = gras_socket_server(9999); - INFO0("Hi! hi! I'm not in the search range, but in 9999..."); + gras_cb_register("kill", &server_kill_cb); + + if (argc > 1 && !strcmp(argv[1], "--cheat")) { + mysock = gras_socket_server(9999); + INFO0("Hi! hi! I'm not in the search range, but in 9999..."); } else { - mysock = gras_socket_server((rand() % 10) + 3000); - INFO1("Ok, I'm hidden on port %d. Hope for the best.", gras_socket_my_port(mysock)); - } - + mysock = gras_socket_server((rand() % 10) + 3000); + INFO1("Ok, I'm hidden on port %d. Hope for the best.", + gras_socket_my_port(mysock)); + } + while (!globals->killed) { - gras_msg_handle(-1); /* blocking */ + gras_msg_handle(-1); /* blocking */ } - + gras_exit(); return 0; } -int client(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toserver; /* socket used to write to the server */ - int found; /* whether we found peer */ - int port; /* where we think that the server is */ +int client(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ + int found; /* whether we found peer */ + int port; /* where we think that the server is */ xbt_ex_t e; - gras_init(&argc,argv); + gras_init(&argc, argv); gras_msgtype_declare("kill", NULL); mysock = gras_socket_server_range(1024, 10000, 0, 0); - + VERB0("Run little server, run. I'll get you. (sleep 1.5 sec)"); gras_os_sleep(1.5); - - for (port=3000, found=0; port<3010 && !found; port++) { - TRY { - toserver = gras_socket_client(argv[1], port); - gras_msg_send(toserver,"kill", NULL); - gras_socket_close(toserver); - found = 1; - INFO1("Yeah! I found the server on %d! It's eradicated by now.",port); - } CATCH(e) { - xbt_ex_free(e); - } - if (!found) - INFO1("Damn, the server is not on %d",port); - } /* end_of_loop */ - - if(!found) - THROW0(not_found_error, 0, "Damn, I failed to find the server! I cannot survive this humilliation."); - - + + for (port = 3000, found = 0; port < 3010 && !found; port++) { + TRY { + toserver = gras_socket_client(argv[1], port); + gras_msg_send(toserver, "kill", NULL); + gras_socket_close(toserver); + found = 1; + INFO1("Yeah! I found the server on %d! It's eradicated by now.", + port); + } + CATCH(e) { + xbt_ex_free(e); + } + if (!found) + INFO1("Damn, the server is not on %d", port); + } /* end_of_loop */ + + if (!found) + THROW0(not_found_error, 0, + "Damn, I failed to find the server! I cannot survive this humilliation."); + + gras_exit(); return 0; } diff --git a/doc/gtut-files/09-datatype-dump.c b/doc/gtut-files/09-datatype-dump.c index 3d871a3d39..8124064647 100644 --- a/doc/gtut-files/09-datatype-dump.c +++ b/doc/gtut-files/09-datatype-dump.c @@ -11,18 +11,19 @@ extern const char *_gras_procname; /* This is a private data of gras/Datadesc we want to explore */ -xbt_set_t gras_datadesc_set_local=NULL; +xbt_set_t gras_datadesc_set_local = NULL; -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ xbt_set_elm_t elm; xbt_set_cursor_t cursor; - gras_init(&argc,argv); - + gras_init(&argc, argv); + xbt_set_foreach(gras_datadesc_set_local, cursor, elm) { - printf("%s\n",elm->name); + printf("%s\n", elm->name); } - - + + gras_exit(); return 0; } diff --git a/doc/gtut-files/09-simpledata.c b/doc/gtut-files/09-simpledata.c index 7ba96df0e7..a170ee4a33 100644 --- a/doc/gtut-files/09-simpledata.c +++ b/doc/gtut-files/09-simpledata.c @@ -6,91 +6,97 @@ #include -XBT_LOG_NEW_DEFAULT_CATEGORY(test,"My little example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(test, "My little example"); typedef struct { - int killed; + int killed; } server_data_t; - -int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) { - double delay = *(double*)payload; + +int server_kill_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ + double delay = *(double *) payload; gras_socket_t client = gras_msg_cb_ctx_from(ctx); - server_data_t *globals=(server_data_t*)gras_userdata_get(); - + server_data_t *globals = (server_data_t *) gras_userdata_get(); + CRITICAL3("Argh, %s:%d gave me %.2f seconds before suicide!", - gras_socket_peer_name(client), gras_socket_peer_port(client),delay); + gras_socket_peer_name(client), gras_socket_peer_port(client), + delay); gras_os_sleep(delay); CRITICAL0("Bye folks..."); - - + + globals->killed = 1; - + return 0; -} /* end_of_kill_callback */ +} /* end_of_kill_callback */ -int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) { - char *msg=*(char**)payload; +int server_hello_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ + char *msg = *(char **) payload; gras_socket_t client = gras_msg_cb_ctx_from(ctx); INFO3("Cool, we received a message from %s:%d. Here it is: \"%s\"", - gras_socket_peer_name(client), gras_socket_peer_port(client), - msg); - + gras_socket_peer_name(client), gras_socket_peer_port(client), msg); + return 0; -} /* end_of_hello_callback */ +} /* end_of_hello_callback */ -void message_declaration(void) { +void message_declaration(void) +{ gras_msgtype_declare("kill", gras_datadesc_by_name("double")); gras_msgtype_declare("hello", gras_datadesc_by_name("string")); } -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ server_data_t *globals; - - gras_init(&argc,argv); - globals=gras_userdata_new(server_data_t*); - globals->killed=0; + gras_init(&argc, argv); + + globals = gras_userdata_new(server_data_t *); + globals->killed = 0; message_declaration(); mysock = gras_socket_server(atoi(argv[1])); - - gras_cb_register("hello",&server_hello_cb); - gras_cb_register("kill",&server_kill_cb); + + gras_cb_register("hello", &server_hello_cb); + gras_cb_register("kill", &server_kill_cb); while (!globals->killed) { - gras_msg_handle(-1); /* blocking */ + gras_msg_handle(-1); /* blocking */ } - + gras_exit(); return 0; } -int client(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toserver; /* socket used to write to the server */ +int client(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ - gras_init(&argc,argv); + gras_init(&argc, argv); message_declaration(); mysock = gras_socket_server_range(1024, 10000, 0, 0); - + VERB1("Client ready; listening on %d", gras_socket_my_port(mysock)); - - gras_os_sleep(1.5); /* sleep 1 second and half */ + + gras_os_sleep(1.5); /* sleep 1 second and half */ toserver = gras_socket_client(argv[1], atoi(argv[2])); - - char *hello_payload="Nice to meet you"; - gras_msg_send(toserver,"hello", &hello_payload); - INFO1("we sent the hello to the server on %s.", gras_socket_peer_name(toserver)); - - double kill_payload=0.5; - gras_msg_send(toserver,"kill", &kill_payload); + + char *hello_payload = "Nice to meet you"; + gras_msg_send(toserver, "hello", &hello_payload); + INFO1("we sent the hello to the server on %s.", + gras_socket_peer_name(toserver)); + + double kill_payload = 0.5; + gras_msg_send(toserver, "kill", &kill_payload); INFO0("Gave the server more 0.5 second to live"); - + gras_exit(); return 0; } diff --git a/doc/gtut-files/10-rpc.c b/doc/gtut-files/10-rpc.c index 1e8e64d9c0..9cc423a9f8 100644 --- a/doc/gtut-files/10-rpc.c +++ b/doc/gtut-files/10-rpc.c @@ -7,122 +7,139 @@ #include #include -XBT_LOG_NEW_DEFAULT_CATEGORY(test,"My little example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(test, "My little example"); typedef struct { - int done; + int done; } server_data_t; -int server_done_cb(gras_msg_cb_ctx_t ctx, void *payload) { - server_data_t *globals=(server_data_t*)gras_userdata_get(); +int server_done_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ + server_data_t *globals = (server_data_t *) gras_userdata_get(); globals->done = 1; INFO0("Server done"); - + return 0; -} /* end_of_done_callback */ +} /* end_of_done_callback */ + +void message_declaration(void) +{ + gras_msgtype_declare_rpc("convert a2i", gras_datadesc_by_name("string"), + gras_datadesc_by_name("long")); + gras_msgtype_declare_rpc("convert i2a", gras_datadesc_by_name("long"), + gras_datadesc_by_name("string")); -void message_declaration(void) { - gras_msgtype_declare_rpc("convert a2i", gras_datadesc_by_name("string"), gras_datadesc_by_name("long")); - gras_msgtype_declare_rpc("convert i2a", gras_datadesc_by_name("long"), gras_datadesc_by_name("string")); - /* the other message allowing the client to stop the server after use */ - gras_msgtype_declare("done", NULL); + gras_msgtype_declare("done", NULL); } -int server_convert_i2a_cb(gras_msg_cb_ctx_t ctx, void *payload) { - long data = *(long*)payload; +int server_convert_i2a_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ + long data = *(long *) payload; char *result; char *p; - INFO1("Convert %ld to string",data); - result = bprintf("%ld", data); - INFO2("%ld converted to string: %s",data,result); - - gras_msg_rpcreturn(60,ctx,&result); + INFO1("Convert %ld to string", data); + result = bprintf("%ld", data); + INFO2("%ld converted to string: %s", data, result); + + gras_msg_rpcreturn(60, ctx, &result); free(result); return 0; -} /* end_of_convert_callback */ +} /* end_of_convert_callback */ -int server_convert_a2i_cb(gras_msg_cb_ctx_t ctx, void *payload) { - char *string = *(char**)payload; +int server_convert_a2i_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ + char *string = *(char **) payload; long result; char *p; - INFO1("Convert %s to long",string); + INFO1("Convert %s to long", string); result = strtol(string, &p, 10); - + if (*p != '\0') - THROW2(arg_error,0,"Error while converting %s: this does not seem to be a valid number (problem at '%s')",string,p); - - gras_msg_rpcreturn(60,ctx,&result); + THROW2(arg_error, 0, + "Error while converting %s: this does not seem to be a valid number (problem at '%s')", + string, p); + + gras_msg_rpcreturn(60, ctx, &result); return 0; -} /* end_of_convert_callback */ +} /* end_of_convert_callback */ -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ server_data_t *globals; - - gras_init(&argc,argv); - globals=gras_userdata_new(server_data_t*); - globals->done=0; + gras_init(&argc, argv); + + globals = gras_userdata_new(server_data_t *); + globals->done = 0; message_declaration(); mysock = gras_socket_server(atoi(argv[1])); - - gras_cb_register("convert a2i",&server_convert_a2i_cb); - gras_cb_register("convert i2a",&server_convert_i2a_cb); - gras_cb_register("done",&server_done_cb); + + gras_cb_register("convert a2i", &server_convert_a2i_cb); + gras_cb_register("convert i2a", &server_convert_i2a_cb); + gras_cb_register("done", &server_done_cb); while (!globals->done) { - gras_msg_handle(-1); /* blocking */ + gras_msg_handle(-1); /* blocking */ } - + gras_exit(); return 0; } -int client(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toserver; /* socket used to write to the server */ +int client(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ - gras_init(&argc,argv); + gras_init(&argc, argv); message_declaration(); mysock = gras_socket_server_range(1024, 10000, 0, 0); - + VERB1("Client ready; listening on %d", gras_socket_my_port(mysock)); - - gras_os_sleep(1.5); /* sleep 1 second and half */ + + gras_os_sleep(1.5); /* sleep 1 second and half */ toserver = gras_socket_client(argv[1], atoi(argv[2])); - - long long_to_convert=4321; + + long long_to_convert = 4321; char *string_result; INFO1("Ask to convert %ld", long_to_convert); - gras_msg_rpccall(toserver, 60, "convert i2a", &long_to_convert, &string_result); - INFO2("The server says that %ld is equal to \"%s\".", long_to_convert, string_result); + gras_msg_rpccall(toserver, 60, "convert i2a", &long_to_convert, + &string_result); + INFO2("The server says that %ld is equal to \"%s\".", long_to_convert, + string_result); free(string_result); - - char *string_to_convert="1234"; + + char *string_to_convert = "1234"; long long_result; INFO1("Ask to convert %s", string_to_convert); - gras_msg_rpccall(toserver, 60, "convert a2i", &string_to_convert, &long_result); - INFO2("The server says that \"%s\" is equal to %d.", string_to_convert, long_result); - + gras_msg_rpccall(toserver, 60, "convert a2i", &string_to_convert, + &long_result); + INFO2("The server says that \"%s\" is equal to %d.", string_to_convert, + long_result); + xbt_ex_t e; string_to_convert = "azerty"; TRY { - gras_msg_rpccall(toserver, 60, "convert a2i", &string_to_convert, &long_result); + gras_msg_rpccall(toserver, 60, "convert a2i", &string_to_convert, + &long_result); } CATCH(e) { - INFO1("The server refuses to convert %s. Here is the received exception:",string_to_convert); - xbt_ex_display(&e); - xbt_ex_free(e); - INFO0("Again, previous exception was excepted"); - } - - gras_msg_send(toserver,"done", NULL); + INFO1 + ("The server refuses to convert %s. Here is the received exception:", + string_to_convert); + xbt_ex_display(&e); + xbt_ex_free(e); + INFO0("Again, previous exception was excepted"); + } + + gras_msg_send(toserver, "done", NULL); INFO0("Stopped the server"); - + gras_exit(); return 0; } diff --git a/doc/gtut-files/11-explicitwait.c b/doc/gtut-files/11-explicitwait.c index 05146d33e0..4923f8d244 100644 --- a/doc/gtut-files/11-explicitwait.c +++ b/doc/gtut-files/11-explicitwait.c @@ -7,104 +7,116 @@ #include #include -XBT_LOG_NEW_DEFAULT_CATEGORY(test,"My little example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(test, "My little example"); -void message_declaration(void) { +void message_declaration(void) +{ gras_msgtype_declare("request", NULL); gras_msgtype_declare("grant", NULL); gras_msgtype_declare("release", NULL); } typedef struct { - int process_in_CS; - xbt_dynar_t waiting_queue; + int process_in_CS; + xbt_dynar_t waiting_queue; } server_data_t; -int server_request_cb(gras_msg_cb_ctx_t ctx, void *payload) { - server_data_t *globals=(server_data_t*)gras_userdata_get(); +int server_request_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ + server_data_t *globals = (server_data_t *) gras_userdata_get(); gras_socket_t s = gras_msg_cb_ctx_from(ctx); - + if (globals->process_in_CS) { - xbt_dynar_push(globals->waiting_queue, &s); - INFO2("put %s:%d in waiting queue",gras_socket_peer_name(s),gras_socket_peer_port(s)); - } else { - globals->process_in_CS = 1; - INFO2("grant %s:%d since nobody wanted it",gras_socket_peer_name(s),gras_socket_peer_port(s)); - gras_msg_send(s, "grant", NULL); + xbt_dynar_push(globals->waiting_queue, &s); + INFO2("put %s:%d in waiting queue", gras_socket_peer_name(s), + gras_socket_peer_port(s)); + } else { + globals->process_in_CS = 1; + INFO2("grant %s:%d since nobody wanted it", gras_socket_peer_name(s), + gras_socket_peer_port(s)); + gras_msg_send(s, "grant", NULL); } return 0; -} /* end_of_request_callback */ +} /* end_of_request_callback */ + +int server_release_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ + server_data_t *globals = (server_data_t *) gras_userdata_get(); -int server_release_cb(gras_msg_cb_ctx_t ctx, void *payload) { - server_data_t *globals=(server_data_t*)gras_userdata_get(); - if (xbt_dynar_length(globals->waiting_queue)) { - gras_socket_t s; - xbt_dynar_pop(globals->waiting_queue, &s); - - INFO2("grant %s:%d since token released",gras_socket_peer_name(s),gras_socket_peer_port(s)); - gras_msg_send(s, "grant", NULL); + gras_socket_t s; + xbt_dynar_pop(globals->waiting_queue, &s); + + INFO2("grant %s:%d since token released", gras_socket_peer_name(s), + gras_socket_peer_port(s)); + gras_msg_send(s, "grant", NULL); } else { - globals->process_in_CS = 0; + globals->process_in_CS = 0; } - + return 0; -} /* end_of_release_callback */ +} /* end_of_release_callback */ -int server(int argc, char *argv[]) { - gras_socket_t mysock; /* socket on which I listen */ +int server(int argc, char *argv[]) +{ + gras_socket_t mysock; /* socket on which I listen */ server_data_t *globals; int i; - - gras_init(&argc,argv); + + gras_init(&argc, argv); mysock = gras_socket_server(atoi(argv[1])); - globals=gras_userdata_new(server_data_t); - globals->process_in_CS=0; - globals->waiting_queue=xbt_dynar_new( sizeof(gras_socket_t), NULL /* not closing sockets */); + globals = gras_userdata_new(server_data_t); + globals->process_in_CS = 0; + globals->waiting_queue = + xbt_dynar_new(sizeof(gras_socket_t), + NULL /* not closing sockets */ ); - message_declaration(); - gras_cb_register("request",&server_request_cb); - gras_cb_register("release",&server_release_cb); + message_declaration(); + gras_cb_register("request", &server_request_cb); + gras_cb_register("release", &server_release_cb); + + for (i = 0; i < 20; i++) /* 5 requests of each process, 2 processes, 2 messages per request */ + gras_msg_handle(-1); - for (i=0; i<20; i++) /* 5 requests of each process, 2 processes, 2 messages per request */ - gras_msg_handle(-1); - gras_exit(); return 0; -} /* end_of_server */ - -void lock(gras_socket_t toserver) { - gras_msg_send(toserver,"request",NULL); - gras_msg_wait(-1, "grant",NULL,NULL); - INFO0("Granted by server"); -} /* end_of_lock */ - -void unlock(gras_socket_t toserver) { - INFO0("Release the token"); - gras_msg_send(toserver,"release",NULL); -} /* end_of_unlock */ - -int client(int argc, char *argv[]) { +} /* end_of_server */ + +void lock(gras_socket_t toserver) +{ + gras_msg_send(toserver, "request", NULL); + gras_msg_wait(-1, "grant", NULL, NULL); + INFO0("Granted by server"); +} /* end_of_lock */ + +void unlock(gras_socket_t toserver) +{ + INFO0("Release the token"); + gras_msg_send(toserver, "release", NULL); +} /* end_of_unlock */ + +int client(int argc, char *argv[]) +{ int i; - gras_socket_t mysock; /* socket on which I listen */ - gras_socket_t toserver; /* socket used to write to the server */ + gras_socket_t mysock; /* socket on which I listen */ + gras_socket_t toserver; /* socket used to write to the server */ - gras_init(&argc,argv); + gras_init(&argc, argv); mysock = gras_socket_server_range(1024, 10000, 0, 0); - + VERB1("Client ready; listening on %d", gras_socket_my_port(mysock)); - - gras_os_sleep(1.5); /* sleep 1 second and half */ + + gras_os_sleep(1.5); /* sleep 1 second and half */ message_declaration(); toserver = gras_socket_client(argv[1], atoi(argv[2])); - for (i=0;i<5; i++) { - gras_os_sleep(0.1); - lock(toserver); - gras_os_sleep(0.1); - unlock(toserver); + for (i = 0; i < 5; i++) { + gras_os_sleep(0.1); + lock(toserver); + gras_os_sleep(0.1); + unlock(toserver); } gras_exit(); return 0; diff --git a/examples/amok/alnem/alnem.c b/examples/amok/alnem/alnem.c index 720318f3e5..9bcb87f682 100644 --- a/examples/amok/alnem/alnem.c +++ b/examples/amok/alnem/alnem.c @@ -14,7 +14,7 @@ #include -#include /* alvin's graph toolbox (+ reconstruction algorithm) */ +#include /* alvin's graph toolbox (+ reconstruction algorithm) */ /* ********************************************************************** * Sensor code @@ -26,14 +26,17 @@ typedef struct { } sensor_data_t; /* Function prototypes */ -int sensor (int argc,char *argv[]); +int sensor(int argc, char *argv[]); -int sensor (int argc,char *argv[]) { +int sensor(int argc, char *argv[]) +{ xbt_error_t errcode; - sensor_data_t *g=gras_userdata_new(sensor_data_t); + sensor_data_t *g = gras_userdata_new(sensor_data_t); - if ((errcode=gras_sock_server_open(4000,4000,&(g->sock)))) { - fprintf(stderr,"Sensor: Error %s encountered while opening the server socket\n",xbt_error_name(errcode)); + if ((errcode = gras_sock_server_open(4000, 4000, &(g->sock)))) { + fprintf(stderr, + "Sensor: Error %s encountered while opening the server socket\n", + xbt_error_name(errcode)); return 1; } @@ -43,13 +46,13 @@ int sensor (int argc,char *argv[]) { } while (1) { - if ((errcode=gras_msg_handle(3600.0)) && errcode != timeout_error) { - fprintf(stderr,"Sensor: Error '%s' while handling message\n", - xbt_error_name(errcode)); + if ((errcode = gras_msg_handle(3600.0)) && errcode != timeout_error) { + fprintf(stderr, "Sensor: Error '%s' while handling message\n", + xbt_error_name(errcode)); } } - gras_sleep(5,0); + gras_sleep(5, 0); return gras_sock_close(g->sock); } @@ -63,7 +66,7 @@ typedef struct { } maestro_data_t; /* Function prototypes */ -int maestro (int argc,char *argv[]); +int maestro(int argc, char *argv[]); #define MAXHOSTS 100 @@ -73,33 +76,38 @@ int maestro (int argc,char *argv[]); TBX_Graph_nodeSearch(graph,b),\ TBX_Graph_nodeSearch(graph,v)) -int maestro(int argc,char *argv[]) { - int bufSize=32 * 1024; - int expSize= 1024 * 1024; - int msgSize=expSize; - int satSize=msgSize * 100; - double dummy,beginSim; +int maestro(int argc, char *argv[]) +{ + int bufSize = 32 * 1024; + int expSize = 1024 * 1024; + int msgSize = expSize; + int satSize = msgSize * 100; + double dummy, beginSim; xbt_error_t errcode; - maestro_data_t *g=gras_userdata_new(maestro_data_t); + maestro_data_t *g = gras_userdata_new(maestro_data_t); double bw[MAXHOSTS][MAXHOSTS]; double bw_sat[MAXHOSTS][MAXHOSTS]; - int a,b,c,d,begin; + int a, b, c, d, begin; - TBX_Graph_t graph = TBX_Graph_newGraph("Essai",0,NULL); /* a dummy graph containing all hosts */ + TBX_Graph_t graph = TBX_Graph_newGraph("Essai", 0, NULL); /* a dummy graph containing all hosts */ TBX_FIFO_t host_fifo = TBX_FIFO_newFIFO(); - TBX_InterfTable_t interf = NULL; /* the measured interferences */ - TBX_Graph_t builded_graph = NULL; /* the graph builded from the interferences */ + TBX_InterfTable_t interf = NULL; /* the measured interferences */ + TBX_Graph_t builded_graph = NULL; /* the graph builded from the interferences */ /* basics setups */ - if (argc>MAXHOSTS) { - fprintf(stderr,"You gave more than %d sensors for this experiment. Increase the MAX HOSTS constant in alnem code to be bigger than this number.\n",argc); + if (argc > MAXHOSTS) { + fprintf(stderr, + "You gave more than %d sensors for this experiment. Increase the MAX HOSTS constant in alnem code to be bigger than this number.\n", + argc); return 1; } - if ((errcode=gras_sock_server_open(4000,5000,&(g->sock)))) { - fprintf(stderr,"MAESTRO: Error %s encountered while opening the server socket\n",xbt_error_name(errcode)); + if ((errcode = gras_sock_server_open(4000, 5000, &(g->sock)))) { + fprintf(stderr, + "MAESTRO: Error %s encountered while opening the server socket\n", + xbt_error_name(errcode)); return 1; } @@ -108,109 +116,125 @@ int maestro(int argc,char *argv[]) { return 1; } - for (a=1; a %f (%f vs %f)%s\n", - gras_time(), - argv[c],argv[d],argv[a],argv[b], - bw_sat[c][d]/bw[c][d],bw[c][d],bw_sat[c][d], - - (bw_sat[c][d]/bw[c][d] < 0.75) ? " THERE IS SOME INTERFERENCE !!!":""); - INTERF(graph,interf,argv[c],argv[d],argv[a],argv[b])= - (bw_sat[c][d]/bw[c][d] < 0.75) ? 1 : 0; - } + gras_sleep(1, 0); + + begin = time(NULL); + beginSim = gras_time(); + for (c = 1; c < argc; c++) { + if (a == c || b == c) + continue; + + for (d = 1; d < argc; d++) { + if (a == d || b == d || c == d) + continue; + + if ((errcode = + grasbw_request(argv[c], 4000, argv[d], 4000, bufSize, + expSize, msgSize, &dummy, + &(bw_sat[c][d])))) { + fprintf(stderr, "MAESTRO: Error %s encountered in test\n", + xbt_error_name(errcode)); + return 1; + } + fprintf(stderr, + "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n", + gras_time(), argv[c], argv[d], argv[a], argv[b], + bw_sat[c][d] / bw[c][d], bw[c][d], bw_sat[c][d], + (bw_sat[c][d] / bw[c][d] < + 0.75) ? " THERE IS SOME INTERFERENCE !!!" : ""); + INTERF(graph, interf, argv[c], argv[d], argv[a], argv[b]) = + (bw_sat[c][d] / bw[c][d] < 0.75) ? 1 : 0; + } } - if ((errcode=grasbw_saturate_stop(argv[a],4000,argv[b],4000))) { - fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n", - xbt_error_name(errcode)); - return -1; + if ((errcode = grasbw_saturate_stop(argv[a], 4000, argv[b], 4000))) { + fprintf(stderr, + "MAESTRO: Error %s encountered while stopping saturation\n", + xbt_error_name(errcode)); + return -1; } - fprintf(stderr,"Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n", - time(NULL)-begin, gras_time()-beginSim); + fprintf(stderr, + "Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n", + time(NULL) - begin, gras_time() - beginSim); } } /* reconstruct the graph */ TBX_Graph_interferenceTableDump(interf); - TBX_Graph_interferenceTableSave(interf,"interference.dat"); - begin=time(NULL); + TBX_Graph_interferenceTableSave(interf, "interference.dat"); + begin = time(NULL); fprintf(stderr, "MAESTRO: Reconstruct the graph... "); builded_graph = TBX_Graph_exploreInterference(interf); TBX_Graph_exportToGraphViz(builded_graph, "toto.dot"); - fprintf(stderr, "done (took %d sec)",(int)time(NULL)); + fprintf(stderr, "done (took %d sec)", (int) time(NULL)); /* end */ - TBX_Graph_freeGraph(graph,NULL,NULL,NULL); - TBX_Graph_freeGraph(builded_graph,NULL,NULL,NULL); + TBX_Graph_freeGraph(graph, NULL, NULL, NULL); + TBX_Graph_freeGraph(builded_graph, NULL, NULL, NULL); TBX_Graph_freeInterfTable(interf); - gras_sleep(5,0); - exit(0); /* FIXME: There is a bug in MSG preventing me from terminating this server properly */ + gras_sleep(5, 0); + exit(0); /* FIXME: There is a bug in MSG preventing me from terminating this server properly */ return gras_sock_close(g->sock); } diff --git a/examples/amok/alnem/alnem_builder.c b/examples/amok/alnem/alnem_builder.c index 8fa78e792b..26341f1c16 100644 --- a/examples/amok/alnem/alnem_builder.c +++ b/examples/amok/alnem/alnem_builder.c @@ -11,23 +11,25 @@ #include #include -#include /* alvin's graph toolbox (+ reconstruction algorithm) */ +#include /* alvin's graph toolbox (+ reconstruction algorithm) */ -int main(int argc,char *argv[]) { - TBX_Graph_t graph; /* a dummy graph containing all hosts */ +int main(int argc, char *argv[]) +{ + TBX_Graph_t graph; /* a dummy graph containing all hosts */ TBX_FIFO_t host_fifo; - TBX_InterfTable_t interf; /* the measured interferences */ - TBX_Graph_t builded_graph; /* the graph builded from the interferences */ + TBX_InterfTable_t interf; /* the measured interferences */ + TBX_Graph_t builded_graph; /* the graph builded from the interferences */ if (argc != 2) { - fprintf(stderr,"alnem_builder: USAGE:\n"); - fprintf(stderr," alnem_builder interference_file\n"); - exit (1); + fprintf(stderr, "alnem_builder: USAGE:\n"); + fprintf(stderr, " alnem_builder interference_file\n"); + exit(1); } - if (TBX_Graph_interferenceTableRead (argv[1],&graph,&interf,&host_fifo)) { - fprintf(stderr,"Can't read the interference data, aborting\n"); - exit (1); + if (TBX_Graph_interferenceTableRead + (argv[1], &graph, &interf, &host_fifo)) { + fprintf(stderr, "Can't read the interference data, aborting\n"); + exit(1); } builded_graph = TBX_Graph_exploreInterference(interf); diff --git a/examples/amok/bandwidth/bandwidth.c b/examples/amok/bandwidth/bandwidth.c index 1090b5f018..e5d5de9b2d 100644 --- a/examples/amok/bandwidth/bandwidth.c +++ b/examples/amok/bandwidth/bandwidth.c @@ -11,7 +11,8 @@ #include "amok/bandwidth.h" #include "amok/peermanagement.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(Bandwidth, "Messages specific to this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(Bandwidth, + "Messages specific to this example"); /* ********************************************************************** * Sensor code @@ -110,19 +111,21 @@ int maestro(int argc, char *argv[]) peer = gras_socket_client(h1->name, h1->port); INFO0("Test the BW between me and one of the sensors"); - amok_bw_test(peer, buf_size, msg_size, msg_amount, min_duration, &sec, &bw); + amok_bw_test(peer, buf_size, msg_size, msg_amount, min_duration, &sec, + &bw); INFO7 - ("Experience between me and %s:%d (initially %d msgs of %d bytes, maybe modified to fill the pipe at least %.1fs) took %f sec, achieving %f kb/s", - h1->name, h1->port, msg_amount, msg_size, min_duration, sec, - ((double) bw) / 1024.0); - - INFO4("Test the BW between %s:%d and %s:%d", h1->name, h1->port, h2->name, - h2->port); - amok_bw_request(h1->name, h1->port, h2->name, h2->port, buf_size, msg_size, - msg_amount, min_duration, &sec, &bw); + ("Experience between me and %s:%d (initially %d msgs of %d bytes, maybe modified to fill the pipe at least %.1fs) took %f sec, achieving %f kb/s", + h1->name, h1->port, msg_amount, msg_size, min_duration, sec, + ((double) bw) / 1024.0); + + INFO4("Test the BW between %s:%d and %s:%d", h1->name, h1->port, + h2->name, h2->port); + amok_bw_request(h1->name, h1->port, h2->name, h2->port, buf_size, + msg_size, msg_amount, min_duration, &sec, &bw); INFO6 - ("Experience between %s:%d and %s:%d took took %f sec, achieving %f kb/s", - h1->name, h1->port, h2->name, h2->port, sec, ((double) bw) / 1024.0); + ("Experience between %s:%d and %s:%d took took %f sec, achieving %f kb/s", + h1->name, h1->port, h2->name, h2->port, sec, + ((double) bw) / 1024.0); /* Game is over, friends */ amok_pm_group_shutdown("bandwidth"); diff --git a/examples/amok/saturate/env.c b/examples/amok/saturate/env.c index 45abca5ea7..9309cbaf42 100644 --- a/examples/amok/saturate/env.c +++ b/examples/amok/saturate/env.c @@ -15,12 +15,14 @@ #include "amok/bandwidth.h" #include "amok/hostmanagement.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(saturate,"Messages specific to this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(saturate, + "Messages specific to this example"); -static void env_hosttohost_bw(int argc, char*argv[]) { +static void env_hosttohost_bw(int argc, char *argv[]) +{ /* where are the sensors */ - xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host); + xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t), &free_host); int nb_hosts; /* results */ @@ -30,108 +32,114 @@ static void env_hosttohost_bw(int argc, char*argv[]) { int i; xbt_host_t h1; - gras_socket_t peer; /* socket to sensor */ + gras_socket_t peer; /* socket to sensor */ - /* wait to ensure that all server sockets are there before starting the experiment */ + /* wait to ensure that all server sockets are there before starting the experiment */ gras_os_sleep(0.5); /* Get the sensor location from argc/argv */ - for (i=1; iname=strdup(argv[i]); - host->port=atoi(argv[i+1]); - INFO2("New sensor: %s:%d",host->name,host->port); - xbt_dynar_push(hosts,&host); + for (i = 1; i < argc - 1; i += 2) { + xbt_host_t host = xbt_new(s_xbt_host_t, 1); + host->name = strdup(argv[i]); + host->port = atoi(argv[i + 1]); + INFO2("New sensor: %s:%d", host->name, host->port); + xbt_dynar_push(hosts, &host); } nb_hosts = xbt_dynar_length(hosts); INFO0(">>> start Test1: ENV end to end mesurements"); - xbt_dynar_foreach(hosts,i,h1) { - peer = gras_socket_client(h1->name,h1->port); - amok_bw_test(peer,buf_size,exp_size,msg_size,min_duration,&sec,&bw); - INFO6("Bandwidth between me and %s:%d (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s", - h1->name,h1->port, - exp_size,msg_size, - sec,((double)bw)/1024.0); + xbt_dynar_foreach(hosts, i, h1) { + peer = gras_socket_client(h1->name, h1->port); + amok_bw_test(peer, buf_size, exp_size, msg_size, min_duration, &sec, + &bw); + INFO6 + ("Bandwidth between me and %s:%d (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s", + h1->name, h1->port, exp_size, msg_size, sec, + ((double) bw) / 1024.0); } - xbt_dynar_map(hosts,kill_buddy_dynar); + xbt_dynar_map(hosts, kill_buddy_dynar); xbt_dynar_free(&hosts); } + /********************************************************************************************/ -static void env_Pairwisehost_bw(int argc, char*argv[]) { +static void env_Pairwisehost_bw(int argc, char *argv[]) +{ xbt_ex_t e; /* where are the sensors */ - xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t),&free_host); + xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t), &free_host); int nb_hosts; /* getting the name of maestro for the saturation and the concurrent bandwidth measurements */ - char* host_test=argv[0]; + char *host_test = argv[0]; /* results */ double sec, bw; /* iterators */ - int i,j; - xbt_host_t h1,h2; + int i, j; + xbt_host_t h1, h2; /* socket to sensor */ gras_socket_t peer; - /* wait to ensure that all server sockets are there before starting the experiment */ + /* wait to ensure that all server sockets are there before starting the experiment */ gras_os_sleep(0.5); - INFO1(">>>>>< le maestro est: %s ",argv[0]); + INFO1(">>>>>< le maestro est: %s ", argv[0]); /* Get the sensor location from argc/argv */ - for (i=1; iname=strdup(argv[i]); - host->port=atoi(argv[i+1]); - INFO2("New sensor: %s:%d",host->name,host->port); - xbt_dynar_push(hosts,&host); + for (i = 1; i < argc - 1; i += 2) { + xbt_host_t host = xbt_new(s_xbt_host_t, 1); + host->name = strdup(argv[i]); + host->port = atoi(argv[i + 1]); + INFO2("New sensor: %s:%d", host->name, host->port); + xbt_dynar_push(hosts, &host); } nb_hosts = xbt_dynar_length(hosts); INFO0(">>> start Test2: ENV pairwise host bandwidth mesurements"); - xbt_dynar_foreach(hosts,i,h1) { - - TRY { - amok_bw_saturate_start(h1->name,h1->port, - host_test,h1->port,//"Ginette" - msg_size,120); // sturation of the link with msg_size to compute a concurent bandwidth MA //MB - } CATCH(e) { - RETHROW0("Cannot ask hosts to saturate the link: %s"); - } - // gras_os_sleep(1.0); - - xbt_dynar_foreach(hosts,j,h2) { - if (i==j) continue; - - peer = gras_socket_client(h2->name,h2->port); - amok_bw_test(peer,buf_size,exp_size,msg_size,min_duration,&sec,&bw); - INFO6("Bandwidth between me and %s // measurement between me and %s (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s", - h2->name,h1->name, - exp_size,msg_size, - sec,((double)bw)/1024.0); - + xbt_dynar_foreach(hosts, i, h1) { + + TRY { + amok_bw_saturate_start(h1->name, h1->port, host_test, h1->port, //"Ginette" + msg_size, 120); // sturation of the link with msg_size to compute a concurent bandwidth MA //MB + } + CATCH(e) { + RETHROW0("Cannot ask hosts to saturate the link: %s"); + } + // gras_os_sleep(1.0); + + xbt_dynar_foreach(hosts, j, h2) { + if (i == j) + continue; + + peer = gras_socket_client(h2->name, h2->port); + amok_bw_test(peer, buf_size, exp_size, msg_size, min_duration, &sec, + &bw); + INFO6 + ("Bandwidth between me and %s // measurement between me and %s (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s", + h2->name, h1->name, exp_size, msg_size, sec, + ((double) bw) / 1024.0); + + } + amok_bw_saturate_stop(h1->name, h1->port, NULL, NULL); } - amok_bw_saturate_stop(h1->name,h1->port,NULL,NULL); -} - xbt_dynar_map(hosts,kill_buddy_dynar); + xbt_dynar_map(hosts, kill_buddy_dynar); xbt_dynar_free(&hosts); } -int maestro(int argc,char *argv[]) { +int maestro(int argc, char *argv[]) +{ - gras_init(&argc,argv); + gras_init(&argc, argv); amok_bw_init(); amok_hm_init(); - gras_socket_server(3333); /* only so that messages from the transport layer in gras identify us */ + gras_socket_server(3333); /* only so that messages from the transport layer in gras identify us */ //env_Pairwisehost_bw(argc,argv); //env_hosttohost_bw(argc,argv); diff --git a/examples/amok/saturate/saturate.c b/examples/amok/saturate/saturate.c index 8d4a5377a2..1b77417c68 100644 --- a/examples/amok/saturate/saturate.c +++ b/examples/amok/saturate/saturate.c @@ -16,7 +16,8 @@ #include "amok/bandwidth.h" #include "amok/peermanagement.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(saturate, "Messages specific to this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(saturate, + "Messages specific to this example"); /* ********************************************************************** * Sensor code @@ -83,8 +84,8 @@ static double XP(const char *bw1, const char *bw2, amok_bw_request(bw1, 4000, bw2, 4000, buf_size, msg_size, msg_amount, min_duration, &sec_sat, &bw_sat); - INFO6("BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s", bw1, bw2, sat1, sat2, - sec, bw / 1024.0 / 1024.0); + INFO6("BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s", bw1, bw2, sat1, + sat2, sec, bw / 1024.0 / 1024.0); amok_bw_saturate_stop(sat1, 4000, NULL, NULL); @@ -252,10 +253,12 @@ static void full_fledged_saturation(int argc, char *argv[]) amok_bw_saturate_stop(h1->name, h1->port, &time1, &bw1); INFO2 - ("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)", - (long int) (time(NULL) - begin), gras_os_time() - begin_simulated); - INFO2("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)", - time1, bw1); + ("Did an iteration on saturation pair in %ld sec (%.2f simulated sec)", + (long int) (time(NULL) - begin), + gras_os_time() - begin_simulated); + INFO2 + ("the duration of the experiment >>>>> %.3f sec (%.3f bandwidth)", + time1, bw1); } } free(bw_sat); diff --git a/examples/gras/all2all/all2all.c b/examples/gras/all2all/all2all.c index 4c58b72488..8e5d607729 100644 --- a/examples/gras/all2all/all2all.c +++ b/examples/gras/all2all/all2all.c @@ -57,8 +57,8 @@ int receiver(int argc, char *argv[]) free(data); INFO3("Got Data from %s:%d (still %d to go)", - gras_socket_peer_name(expeditor), gras_socket_peer_port(expeditor), - todo); + gras_socket_peer_name(expeditor), + gras_socket_peer_port(expeditor), todo); } @@ -86,7 +86,8 @@ int sender(int argc, char *argv[]) /* xbt_dynar for peers */ - xbt_dynar_t peers = xbt_dynar_new(sizeof(xbt_peer_t), &xbt_peer_free_voidp); + xbt_dynar_t peers = + xbt_dynar_new(sizeof(xbt_peer_t), &xbt_peer_free_voidp); /* Init the GRAS infrastructure and declare my globals */ gras_init(&argc, argv); diff --git a/examples/gras/chrono/chrono2.c b/examples/gras/chrono/chrono2.c index 7816fd2c1f..5a0e1fd44a 100644 --- a/examples/gras/chrono/chrono2.c +++ b/examples/gras/chrono/chrono2.c @@ -9,54 +9,54 @@ #include "gras.h" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(Chrono,"Messages specific to this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(Chrono, "Messages specific to this example"); #include void cblas_dgemm(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_TRANSPOSE TransB, const int M, - const int N, const int K, const double alpha, - const double *A, const int lda, const double *B, - const int ldb, const double beta, double *C, - const int ldc); + const enum CBLAS_TRANSPOSE TransA, + const enum CBLAS_TRANSPOSE TransB, const int M, + const int N, const int K, const double alpha, + const double *A, const int lda, const double *B, + const int ldb, const double beta, double *C, + const int ldc); /* Function prototypes */ static int mat_mult(int n) { - int i,j,k,l; - double *A,*B,*C; + int i, j, k, l; + double *A, *B, *C; double start = 0.0; double now = 0.0; - A = malloc(n*n*sizeof(double)); - B = malloc(n*n*sizeof(double)); - C = malloc(n*n*sizeof(double)); + A = malloc(n * n * sizeof(double)); + B = malloc(n * n * sizeof(double)); + C = malloc(n * n * sizeof(double)); - start=now=gras_os_time(); + start = now = gras_os_time(); - INFO1("Matrix size: %d",n); + INFO1("Matrix size: %d", n); /* INFO1("Before computation: %lg", start); */ - for(l=0; l<40; l++) { - now=gras_os_time(); + for (l = 0; l < 40; l++) { + now = gras_os_time(); GRAS_BENCH_ONCE_RUN_ONCE_BEGIN(); - for(i=0; i>>>>>>> Got message PING(%d) from %s:%d <<<<<<<<", msg, - gras_socket_peer_name(expeditor), gras_socket_peer_port(expeditor)); + gras_socket_peer_name(expeditor), + gras_socket_peer_port(expeditor)); /* 4. Change the value of the msg variable */ msg = 4321; @@ -93,7 +94,8 @@ int server(int argc, char *argv[]) /* 7. Housekeeping */ if (!globals->endcondition) - WARN0("An error occured, the endcondition was not set by the callback"); + WARN0 + ("An error occured, the endcondition was not set by the callback"); /* 8. Free the allocated resources, and shut GRAS down */ gras_socket_close(globals->sock); diff --git a/examples/gras/mmrpc/mmrpc.c b/examples/gras/mmrpc/mmrpc.c index d1d356510a..bfad502250 100644 --- a/examples/gras/mmrpc/mmrpc.c +++ b/examples/gras/mmrpc/mmrpc.c @@ -10,31 +10,34 @@ #include "xbt/matrix.h" #include "mmrpc.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(MatMult,"Messages specific to this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(MatMult, "Messages specific to this example"); /* register messages which may be sent and their payload (common to client and server) */ -void mmrpc_register_messages(void) { +void mmrpc_register_messages(void) +{ gras_datadesc_type_t matrix_type, request_type; - matrix_type=gras_datadesc_matrix(gras_datadesc_by_name("double"), - NULL); - request_type=gras_datadesc_array_fixed("s_matrix_t(double)[2]",matrix_type,2); - + matrix_type = gras_datadesc_matrix(gras_datadesc_by_name("double"), + NULL); + request_type = + gras_datadesc_array_fixed("s_matrix_t(double)[2]", matrix_type, 2); + gras_msgtype_declare("answer", matrix_type); gras_msgtype_declare("request", request_type); } typedef xbt_matrix_t request_t[2]; -static int server_cb_request_handler(gras_msg_cb_ctx_t ctx, - void *payload_data) { +static int server_cb_request_handler(gras_msg_cb_ctx_t ctx, + void *payload_data) +{ + + gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx); - gras_socket_t expeditor=gras_msg_cb_ctx_from(ctx); - /* 1. Get the payload into the data variable */ - xbt_matrix_t *request = (xbt_matrix_t*)payload_data; + xbt_matrix_t *request = (xbt_matrix_t *) payload_data; xbt_matrix_t result; - + /* 2. Do the computation */ result = xbt_matrix_double_new_mult(request[0], request[1]); @@ -46,124 +49,129 @@ static int server_cb_request_handler(gras_msg_cb_ctx_t ctx, xbt_matrix_free(request[1]); xbt_matrix_free(result); gras_socket_close(expeditor); - + return 0; -} /* end_of_server_cb_request_handler */ +} /* end_of_server_cb_request_handler */ -int server (int argc,char *argv[]) { - xbt_ex_t e; - gras_socket_t sock=NULL; +int server(int argc, char *argv[]) +{ + xbt_ex_t e; + gras_socket_t sock = NULL; int port = 4000; - + /* 1. Init the GRAS infrastructure */ - gras_init(&argc,argv); - + gras_init(&argc, argv); + /* 2. Get the port I should listen on from the command line, if specified */ if (argc == 2) { - port=atoi(argv[1]); + port = atoi(argv[1]); } /* 3. Create my master socket */ INFO1("Launch server (port=%d)", port); TRY { sock = gras_socket_server(port); - } CATCH(e) { + } + CATCH(e) { RETHROW0("Unable to establish a server socket: %s"); } /* 4. Register the known messages and payloads. */ mmrpc_register_messages(); - + /* 5. Register my callback */ - gras_cb_register("request",&server_cb_request_handler); + gras_cb_register("request", &server_cb_request_handler); /* 6. Wait up to 10 minutes for an incomming message to handle */ gras_msg_handle(600.0); - + /* 7. Free the allocated resources, and shut GRAS down */ gras_socket_close(sock); gras_exit(); - + INFO0("Done."); return 0; -} /* end_of_server */ +} /* end_of_server */ -int client(int argc,char *argv[]) { - xbt_ex_t e; - gras_socket_t toserver=NULL; /* peer */ +int client(int argc, char *argv[]) +{ + xbt_ex_t e; + gras_socket_t toserver = NULL; /* peer */ gras_socket_t from; xbt_matrix_t request[2], answer; - int i,j; + int i, j; const char *host = "127.0.0.1"; - int port = 4000; + int port = 4000; /* 1. Init the GRAS's infrastructure */ gras_init(&argc, argv); - + /* 2. Get the server's address. The command line override defaults when specified */ if (argc == 3) { - host=argv[1]; - port=atoi(argv[2]); - } + host = argv[1]; + port = atoi(argv[2]); + } + + INFO2("Launch client (server on %s:%d)", host, port); - INFO2("Launch client (server on %s:%d)",host,port); - /* 3. Wait for the server startup */ gras_os_sleep(1); - + /* 4. Create a socket to speak to the server */ TRY { - toserver=gras_socket_client(host,port); - } CATCH(e) { + toserver = gras_socket_client(host, port); + } + CATCH(e) { RETHROW0("Unable to connect to the server: %s"); } - INFO2("Connected to %s:%d.",host,port); + INFO2("Connected to %s:%d.", host, port); /* 5. Register the messages (before use) */ mmrpc_register_messages(); /* 6. Keep the user informed of what's going on */ - INFO2(">>>>>>>> Connected to server which is on %s:%d <<<<<<<<", - gras_socket_peer_name(toserver),gras_socket_peer_port(toserver)); + INFO2(">>>>>>>> Connected to server which is on %s:%d <<<<<<<<", + gras_socket_peer_name(toserver), gras_socket_peer_port(toserver)); /* 7. Prepare and send the request to the server */ - request[0] = xbt_matrix_double_new_id(MATSIZE,MATSIZE); - request[1] = xbt_matrix_double_new_rand(MATSIZE,MATSIZE); + request[0] = xbt_matrix_double_new_id(MATSIZE, MATSIZE); + request[1] = xbt_matrix_double_new_rand(MATSIZE, MATSIZE); /* - xbt_matrix_dump(request[0],"C:sent0",0,xbt_matrix_dump_display_double); - xbt_matrix_dump(request[1],"C:sent1",0,xbt_matrix_dump_display_double); - */ + xbt_matrix_dump(request[0],"C:sent0",0,xbt_matrix_dump_display_double); + xbt_matrix_dump(request[1],"C:sent1",0,xbt_matrix_dump_display_double); + */ gras_msg_send(toserver, "request", &request); xbt_matrix_free(request[0]); INFO2(">>>>>>>> Request sent to %s:%d <<<<<<<<", - gras_socket_peer_name(toserver),gras_socket_peer_port(toserver)); + gras_socket_peer_name(toserver), gras_socket_peer_port(toserver)); /* 8. Wait for the answer from the server, and deal with issues */ - gras_msg_wait(6000,"answer",&from,&answer); + gras_msg_wait(6000, "answer", &from, &answer); /* - xbt_matrix_dump(answer,"C:answer",0,xbt_matrix_dump_display_double); - */ - for (i=0; i>>>>>>> Got answer from %s:%d (values are right) <<<<<<<<", - gras_socket_peer_name(from),gras_socket_peer_port(from)); + INFO2(">>>>>>>> Got answer from %s:%d (values are right) <<<<<<<<", + gras_socket_peer_name(from), gras_socket_peer_port(from)); /* 10. Free the allocated resources, and shut GRAS down */ xbt_matrix_free(request[1]); @@ -172,4 +180,4 @@ int client(int argc,char *argv[]) { gras_exit(); INFO0("Done."); return 0; -} /* end_of_client */ +} /* end_of_client */ diff --git a/examples/gras/mmrpc/mmrpc.h b/examples/gras/mmrpc/mmrpc.h index 13f5e0f031..3f08bc80df 100644 --- a/examples/gras/mmrpc/mmrpc.h +++ b/examples/gras/mmrpc/mmrpc.h @@ -21,4 +21,4 @@ void mmrpc_register_messages(void); int server(int argc, char *argv[]); int client(int argc, char *argv[]); -#endif /* MMRPC_H */ +#endif /* MMRPC_H */ diff --git a/examples/gras/mmrpc/mmrpc_common.c b/examples/gras/mmrpc/mmrpc_common.c index 5b0beaf586..a4884702ef 100644 --- a/examples/gras/mmrpc/mmrpc_common.c +++ b/examples/gras/mmrpc/mmrpc_common.c @@ -16,9 +16,10 @@ void mmrpc_register_messages(void) { gras_datadesc_type_t matrix_type, request_type; - matrix_type = gras_datadesc_matrix(gras_datadesc_by_name("double"), NULL); + matrix_type = + gras_datadesc_matrix(gras_datadesc_by_name("double"), NULL); request_type = - gras_datadesc_array_fixed("s_matrix_t(double)[2]", matrix_type, 2); + gras_datadesc_array_fixed("s_matrix_t(double)[2]", matrix_type, 2); gras_msgtype_declare("answer", matrix_type); gras_msgtype_declare("request", request_type); diff --git a/examples/gras/p2p/can/can.c b/examples/gras/p2p/can/can.c index a9b91412fb..4c359f0e7b 100644 --- a/examples/gras/p2p/can/can.c +++ b/examples/gras/p2p/can/can.c @@ -10,307 +10,311 @@ #include "xbt/sysdep.h" #include "gras.h" -#include "can_tests.c" +#include "can_tests.c" //#include "types.h" // header alone containing the typedef struct of a node // include can_tests.c must be OFF. //XBT_LOG_NEW_DEFAULT_CATEGORY(can,"Messages specific to this example"); // include can_tests.c must be OFF. //extern char *_gras_this_type_symbol_does_not_exist__s_nuke; -int node_nuke_handler(gras_msg_cb_ctx_t ctx,void *payload_data); +int node_nuke_handler(gras_msg_cb_ctx_t ctx, void *payload_data); // struct of a "get_successor" message, when a node look after the area in which he want to be. -GRAS_DEFINE_TYPE(s_get_suc, - struct s_get_suc{ - int xId; - int yId; - char host[1024]; - int port; - }; -); +GRAS_DEFINE_TYPE(s_get_suc, struct s_get_suc { + int xId; int yId; char host[1024]; int port;};); + typedef struct s_get_suc get_suc_t; // struct of a "response_successor" message, hen a node receive the information of his new area. -GRAS_DEFINE_TYPE(s_rep_suc, - struct s_rep_suc{ - int x1; // Xmin - int x2; // Xmax - int y1; // Ymin - int y2; // Ymax - - char north_host[1024]; - int north_port; - char south_host[1024]; - int south_port; - char east_host[1024]; - int east_port; - char west_host[1024]; - int west_port; - }; -); +GRAS_DEFINE_TYPE(s_rep_suc, struct s_rep_suc { + int x1; // Xmin + int x2; // Xmax + int y1; // Ymin + int y2; // Ymax + char north_host[1024]; + int north_port; + char south_host[1024]; + int south_port; + char east_host[1024]; + int east_port; char west_host[1024]; int west_port;};); typedef struct s_rep_suc rep_suc_t; -int node(int argc,char **argv); +int node(int argc, char **argv); // registering messages types -static void register_messages(){ - gras_msgtype_declare("can_get_suc",gras_datadesc_by_symbol(s_get_suc)); - gras_msgtype_declare("can_rep_suc",gras_datadesc_by_symbol(s_rep_suc)); - gras_msgtype_declare("can_nuke",gras_datadesc_by_symbol(s_nuke));// can_test.c message // include can_tests.c must be ON. +static void register_messages() +{ + gras_msgtype_declare("can_get_suc", gras_datadesc_by_symbol(s_get_suc)); + gras_msgtype_declare("can_rep_suc", gras_datadesc_by_symbol(s_rep_suc)); + gras_msgtype_declare("can_nuke", gras_datadesc_by_symbol(s_nuke)); // can_test.c message // include can_tests.c must be ON. } // a forwarding function for a "get_suc" message. -static void forward_get_suc(get_suc_t msg, char host[1024], int port){ - gras_socket_t temp_sock=NULL; - xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. - //INFO2("Transmiting message to %s:%d",host,port); - TRY{ - temp_sock=gras_socket_client(host,port); - }CATCH(e){ - RETHROW0("Unable to connect!: %s"); - } - TRY{ - gras_msg_send(temp_sock,"can_get_suc",&msg); - }CATCH(e){ - RETHROW0("Unable to send!: %s"); - } - INFO3("Forwarding a get_successor message to %s for (%d;%d)",host,msg.xId,msg.yId); - gras_socket_close(temp_sock); +static void forward_get_suc(get_suc_t msg, char host[1024], int port) +{ + gras_socket_t temp_sock = NULL; + xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. + //INFO2("Transmiting message to %s:%d",host,port); + TRY { + temp_sock = gras_socket_client(host, port); + } CATCH(e) { + RETHROW0("Unable to connect!: %s"); + } + TRY { + gras_msg_send(temp_sock, "can_get_suc", &msg); + } CATCH(e) { + RETHROW0("Unable to send!: %s"); + } + INFO3("Forwarding a get_successor message to %s for (%d;%d)", host, + msg.xId, msg.yId); + gras_socket_close(temp_sock); } // the handling function of a "get_suc" message (what do a node when he receive a "get_suc" message. -static int node_get_suc_handler(gras_msg_cb_ctx_t ctx,void *payload_data){ - gras_socket_t expeditor=gras_msg_cb_ctx_from(ctx); - get_suc_t *incoming=(get_suc_t*)payload_data; - xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. - node_data_t *globals=(node_data_t*)gras_userdata_get(); - gras_socket_t temp_sock=NULL; - INFO3("Received a get_successor message from %s for (%d;%d)",gras_socket_peer_name(expeditor),incoming->xId,incoming->yId); - //INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2); - if(incoming->xIdx1) // test if the message must be forwarded to a neighbour. - forward_get_suc(*incoming, globals->west_host, globals->west_port); - else if(incoming->xId>globals->x2) - forward_get_suc(*incoming, globals->east_host, globals->east_port); - else if(incoming->yIdy1) - forward_get_suc(*incoming, globals->south_host, globals->south_port); - else if(incoming->yId>globals->y2) - forward_get_suc(*incoming, globals->north_host, globals->north_port); - else{ // if the message must not be forwarded, then the area is splitted in half and one half is assignated to the new node. - rep_suc_t outgoing; - int validate=0; - INFO4("Spliting my area between me (%d;%d) and the inserting node (%d;%d)!", - globals->xId,globals->yId,incoming->xId,incoming->yId); - if((globals->x2-globals->x1)>(globals->y2-globals->y1)){ // the height of the area is smaller than its width. - if(incoming->xIdxId){ // the new node is west from the actual node. - outgoing.x1=globals->x1; - outgoing.x2=(incoming->xId+globals->xId)/2; - outgoing.y1=globals->y1; - outgoing.y2=globals->y2; - strcpy(outgoing.north_host,globals->north_host); - outgoing.north_port=globals->north_port; - strcpy(outgoing.south_host,globals->south_host); - outgoing.south_port=globals->south_port; - strcpy(outgoing.east_host,globals->host); - outgoing.east_port=globals->port; - strcpy(outgoing.west_host,globals->west_host); - outgoing.west_port=globals->west_port; - - globals->x1=(incoming->xId+globals->xId)/2; - strcpy(globals->west_host,incoming->host); - globals->west_port=incoming->port; - validate=1; - } - else if(incoming->xId>globals->xId){ // the new node is east from the actual node. - outgoing.x1=(incoming->xId+globals->xId)/2; - outgoing.x2=globals->x2; - outgoing.y1=globals->y1; - outgoing.y2=globals->y2; - strcpy(outgoing.north_host,globals->north_host); - outgoing.north_port=globals->north_port; - strcpy(outgoing.south_host,globals->south_host); - outgoing.south_port=globals->south_port; - strcpy(outgoing.east_host,globals->east_host); - outgoing.east_port=globals->east_port; - strcpy(outgoing.west_host,globals->host); - outgoing.west_port=globals->port; - - globals->x2=(incoming->xId+globals->xId)/2; - strcpy(globals->east_host,incoming->host); - globals->east_port=incoming->port; - validate=1; - } - } - else{ - if(incoming->yIdyId){ // the new node is south from the actual node. - outgoing.y1=globals->y1; - outgoing.y2=(incoming->yId+globals->yId)/2; - outgoing.y1=globals->y1; - outgoing.x2=globals->x2; - strcpy(outgoing.east_host,globals->east_host); - outgoing.east_port=globals->east_port; - strcpy(outgoing.west_host,globals->west_host); - outgoing.west_port=globals->west_port; - strcpy(outgoing.north_host,globals->host); - outgoing.north_port=globals->port; - strcpy(outgoing.south_host,globals->south_host); - outgoing.south_port=globals->south_port; - - globals->y1=(incoming->yId+globals->yId)/2; - strcpy(globals->south_host,incoming->host); - globals->south_port=incoming->port; - validate=1; - } - else if(incoming->yId>globals->yId){ // the new node is north from the actual node. - outgoing.y1=(incoming->yId+globals->yId)/2; - outgoing.y2=globals->y2; - outgoing.x1=globals->x1; - outgoing.x2=globals->x2; - strcpy(outgoing.east_host,globals->east_host); - outgoing.east_port=globals->east_port; - strcpy(outgoing.west_host,globals->west_host); - outgoing.west_port=globals->west_port; - strcpy(outgoing.north_host,globals->north_host); - outgoing.north_port=globals->north_port; - strcpy(outgoing.south_host,globals->host); - outgoing.south_port=globals->port; - - globals->y2=(incoming->yId+globals->yId)/2; - strcpy(globals->north_host,incoming->host); - globals->north_port=incoming->port; - validate=1; - } - } - if(validate==1){ // the area for the new node has been defined, then send theses informations to the new node. - INFO2("Sending environment informations to node %s:%d",incoming->host,incoming->port); - - TRY{ - temp_sock=gras_socket_client(incoming->host,incoming->port); - }CATCH(e){ - RETHROW0("Unable to connect to the node wich has requested for an area!: %s"); - } - TRY{ - gras_msg_send(temp_sock,"can_rep_suc",&outgoing); - INFO0("Environment informations sent!"); - }CATCH(e){ - RETHROW2("%s:Timeout sending environment informations to %s: %s",globals->host,gras_socket_peer_name(expeditor)); - } - gras_socket_close(temp_sock); - } - else // we have a problem! - INFO0("An error occurded!!!!!!!!!!!!!"); - - } - gras_socket_close(expeditor); // spare - TRY{ - gras_msg_handle(10000.0); // wait a bit in case of someone want to ask me for something. - }CATCH(e){ - INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2); - //INFO0("Closing node, all has been done!"); - } - return 0; +static int node_get_suc_handler(gras_msg_cb_ctx_t ctx, void *payload_data) +{ + gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx); + get_suc_t *incoming = (get_suc_t *) payload_data; + xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. + node_data_t *globals = (node_data_t *) gras_userdata_get(); + gras_socket_t temp_sock = NULL; + INFO3("Received a get_successor message from %s for (%d;%d)", + gras_socket_peer_name(expeditor), incoming->xId, incoming->yId); + //INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2); + if (incoming->xId < globals->x1) // test if the message must be forwarded to a neighbour. + forward_get_suc(*incoming, globals->west_host, globals->west_port); + else if (incoming->xId > globals->x2) + forward_get_suc(*incoming, globals->east_host, globals->east_port); + else if (incoming->yId < globals->y1) + forward_get_suc(*incoming, globals->south_host, globals->south_port); + else if (incoming->yId > globals->y2) + forward_get_suc(*incoming, globals->north_host, globals->north_port); + else { // if the message must not be forwarded, then the area is splitted in half and one half is assignated to the new node. + rep_suc_t outgoing; + int validate = 0; + INFO4 + ("Spliting my area between me (%d;%d) and the inserting node (%d;%d)!", + globals->xId, globals->yId, incoming->xId, incoming->yId); + if ((globals->x2 - globals->x1) > (globals->y2 - globals->y1)) { // the height of the area is smaller than its width. + if (incoming->xId < globals->xId) { // the new node is west from the actual node. + outgoing.x1 = globals->x1; + outgoing.x2 = (incoming->xId + globals->xId) / 2; + outgoing.y1 = globals->y1; + outgoing.y2 = globals->y2; + strcpy(outgoing.north_host, globals->north_host); + outgoing.north_port = globals->north_port; + strcpy(outgoing.south_host, globals->south_host); + outgoing.south_port = globals->south_port; + strcpy(outgoing.east_host, globals->host); + outgoing.east_port = globals->port; + strcpy(outgoing.west_host, globals->west_host); + outgoing.west_port = globals->west_port; + + globals->x1 = (incoming->xId + globals->xId) / 2; + strcpy(globals->west_host, incoming->host); + globals->west_port = incoming->port; + validate = 1; + } else if (incoming->xId > globals->xId) { // the new node is east from the actual node. + outgoing.x1 = (incoming->xId + globals->xId) / 2; + outgoing.x2 = globals->x2; + outgoing.y1 = globals->y1; + outgoing.y2 = globals->y2; + strcpy(outgoing.north_host, globals->north_host); + outgoing.north_port = globals->north_port; + strcpy(outgoing.south_host, globals->south_host); + outgoing.south_port = globals->south_port; + strcpy(outgoing.east_host, globals->east_host); + outgoing.east_port = globals->east_port; + strcpy(outgoing.west_host, globals->host); + outgoing.west_port = globals->port; + + globals->x2 = (incoming->xId + globals->xId) / 2; + strcpy(globals->east_host, incoming->host); + globals->east_port = incoming->port; + validate = 1; + } + } else { + if (incoming->yId < globals->yId) { // the new node is south from the actual node. + outgoing.y1 = globals->y1; + outgoing.y2 = (incoming->yId + globals->yId) / 2; + outgoing.y1 = globals->y1; + outgoing.x2 = globals->x2; + strcpy(outgoing.east_host, globals->east_host); + outgoing.east_port = globals->east_port; + strcpy(outgoing.west_host, globals->west_host); + outgoing.west_port = globals->west_port; + strcpy(outgoing.north_host, globals->host); + outgoing.north_port = globals->port; + strcpy(outgoing.south_host, globals->south_host); + outgoing.south_port = globals->south_port; + + globals->y1 = (incoming->yId + globals->yId) / 2; + strcpy(globals->south_host, incoming->host); + globals->south_port = incoming->port; + validate = 1; + } else if (incoming->yId > globals->yId) { // the new node is north from the actual node. + outgoing.y1 = (incoming->yId + globals->yId) / 2; + outgoing.y2 = globals->y2; + outgoing.x1 = globals->x1; + outgoing.x2 = globals->x2; + strcpy(outgoing.east_host, globals->east_host); + outgoing.east_port = globals->east_port; + strcpy(outgoing.west_host, globals->west_host); + outgoing.west_port = globals->west_port; + strcpy(outgoing.north_host, globals->north_host); + outgoing.north_port = globals->north_port; + strcpy(outgoing.south_host, globals->host); + outgoing.south_port = globals->port; + + globals->y2 = (incoming->yId + globals->yId) / 2; + strcpy(globals->north_host, incoming->host); + globals->north_port = incoming->port; + validate = 1; + } + } + if (validate == 1) { // the area for the new node has been defined, then send theses informations to the new node. + INFO2("Sending environment informations to node %s:%d", + incoming->host, incoming->port); + + TRY { + temp_sock = gras_socket_client(incoming->host, incoming->port); + } + CATCH(e) { + RETHROW0 + ("Unable to connect to the node wich has requested for an area!: %s"); + } + TRY { + gras_msg_send(temp_sock, "can_rep_suc", &outgoing); + INFO0("Environment informations sent!"); + } + CATCH(e) { + RETHROW2("%s:Timeout sending environment informations to %s: %s", + globals->host, gras_socket_peer_name(expeditor)); + } + gras_socket_close(temp_sock); + } else // we have a problem! + INFO0("An error occurded!!!!!!!!!!!!!"); + + } + gras_socket_close(expeditor); // spare + TRY { + gras_msg_handle(10000.0); // wait a bit in case of someone want to ask me for something. + } + CATCH(e) { + INFO4("My area is [%d;%d;%d;%d]", globals->x1, globals->x2, + globals->y1, globals->y2); + //INFO0("Closing node, all has been done!"); + } + return 0; } -int node(int argc,char **argv){ - node_data_t *globals=NULL; - xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. - gras_socket_t temp_sock=NULL; - - rep_suc_t rep_suc_msg; - - get_suc_t get_suc_msg; // building the "get_suc" message. - gras_socket_t temp_sock2=NULL; - - INFO0("Starting"); - - /* 1. Init the GRAS infrastructure and declare my globals */ - gras_init(&argc,argv); - gras_os_sleep((15-gras_os_getpid())*20); // wait a bit. - - globals=gras_userdata_new(node_data_t); - - globals->xId=atoi(argv[1]); // x coordinate of the node. - globals->yId=atoi(argv[2]); // y coordinate of the node. - globals->port=atoi(argv[3]); // node port - globals->sock=gras_socket_server(globals->port); // node socket. - snprintf(globals->host,1024,gras_os_myname()); // node name. - globals->version=0; // node version (used for fun) - - /* 2. Inserting the Node */ - INFO2("Inserting node %s:%d",globals->host,globals->port); - if(argc==4){ // the node is a server, then he has the whole area. - globals->x1=0; - globals->x2=1000; - globals->y1=0; - globals->y2=1000; - }else{ // asking for an area. - INFO1("Contacting %s so as to request for an area",argv[4]); - - TRY{ - temp_sock=gras_socket_client(argv[4],atoi(argv[5])); - }CATCH(e){ - RETHROW0("Unable to connect known host to request for an area!: %s"); - } - - - get_suc_msg.xId=globals->xId; - get_suc_msg.yId=globals->yId; - strcpy(get_suc_msg.host,globals->host); - get_suc_msg.port=globals->port; - TRY{ // asking. - gras_msg_send(temp_sock,"can_get_suc",&get_suc_msg); - }CATCH(e){ - gras_socket_close(temp_sock); - RETHROW0("Unable to contact known host to get an area!: %s"); - } - gras_socket_close(temp_sock); - - - - TRY{ // waiting for a reply. - INFO0("Waiting for reply!"); - gras_msg_wait(6000,"can_rep_suc",&temp_sock2,&rep_suc_msg); - }CATCH(e){ - RETHROW1("%s: Error waiting for an area:%s",globals->host); - } - - // retreiving the data of the response. - globals->x1=rep_suc_msg.x1; - globals->x2=rep_suc_msg.x2; - globals->y1=rep_suc_msg.y1; - globals->y2=rep_suc_msg.y2; - strcpy(globals->north_host,rep_suc_msg.north_host); - globals->north_port=rep_suc_msg.north_port; - strcpy(globals->south_host,rep_suc_msg.south_host); - globals->south_port=rep_suc_msg.south_port; - strcpy(globals->east_host,rep_suc_msg.east_host); - globals->east_port=rep_suc_msg.east_port; - strcpy(globals->west_host,rep_suc_msg.west_host); - globals->west_port=rep_suc_msg.west_port; - - gras_socket_close(temp_sock); // spare - } - INFO2("Node %s:%d inserted",globals->host,globals->port); - - // associating messages to handlers. - register_messages(); - gras_cb_register("can_get_suc",&node_get_suc_handler); - gras_cb_register("can_nuke",&node_nuke_handler);// can_test.c handler // include can_tests.c must be ON. - - TRY{ - gras_msg_handle(10000.0); // waiting.. in case of someone has something to say. - }CATCH(e){ - INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2); - //INFO0("Closing node, all has been done!"); - } - - gras_socket_close(globals->sock); // spare. - free(globals); // spare. - //gras_exit(); - return(0); +int node(int argc, char **argv) +{ + node_data_t *globals = NULL; + xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. + gras_socket_t temp_sock = NULL; + + rep_suc_t rep_suc_msg; + + get_suc_t get_suc_msg; // building the "get_suc" message. + gras_socket_t temp_sock2 = NULL; + + INFO0("Starting"); + + /* 1. Init the GRAS infrastructure and declare my globals */ + gras_init(&argc, argv); + gras_os_sleep((15 - gras_os_getpid()) * 20); // wait a bit. + + globals = gras_userdata_new(node_data_t); + + globals->xId = atoi(argv[1]); // x coordinate of the node. + globals->yId = atoi(argv[2]); // y coordinate of the node. + globals->port = atoi(argv[3]); // node port + globals->sock = gras_socket_server(globals->port); // node socket. + snprintf(globals->host, 1024, gras_os_myname()); // node name. + globals->version = 0; // node version (used for fun) + + /* 2. Inserting the Node */ + INFO2("Inserting node %s:%d", globals->host, globals->port); + if (argc == 4) { // the node is a server, then he has the whole area. + globals->x1 = 0; + globals->x2 = 1000; + globals->y1 = 0; + globals->y2 = 1000; + } else { // asking for an area. + INFO1("Contacting %s so as to request for an area", argv[4]); + + TRY { + temp_sock = gras_socket_client(argv[4], atoi(argv[5])); + } + CATCH(e) { + RETHROW0("Unable to connect known host to request for an area!: %s"); + } + + + get_suc_msg.xId = globals->xId; + get_suc_msg.yId = globals->yId; + strcpy(get_suc_msg.host, globals->host); + get_suc_msg.port = globals->port; + TRY { // asking. + gras_msg_send(temp_sock, "can_get_suc", &get_suc_msg); + } + CATCH(e) { + gras_socket_close(temp_sock); + RETHROW0("Unable to contact known host to get an area!: %s"); + } + gras_socket_close(temp_sock); + + + + TRY { // waiting for a reply. + INFO0("Waiting for reply!"); + gras_msg_wait(6000, "can_rep_suc", &temp_sock2, &rep_suc_msg); + } + CATCH(e) { + RETHROW1("%s: Error waiting for an area:%s", globals->host); + } + + // retreiving the data of the response. + globals->x1 = rep_suc_msg.x1; + globals->x2 = rep_suc_msg.x2; + globals->y1 = rep_suc_msg.y1; + globals->y2 = rep_suc_msg.y2; + strcpy(globals->north_host, rep_suc_msg.north_host); + globals->north_port = rep_suc_msg.north_port; + strcpy(globals->south_host, rep_suc_msg.south_host); + globals->south_port = rep_suc_msg.south_port; + strcpy(globals->east_host, rep_suc_msg.east_host); + globals->east_port = rep_suc_msg.east_port; + strcpy(globals->west_host, rep_suc_msg.west_host); + globals->west_port = rep_suc_msg.west_port; + + gras_socket_close(temp_sock); // spare + } + INFO2("Node %s:%d inserted", globals->host, globals->port); + + // associating messages to handlers. + register_messages(); + gras_cb_register("can_get_suc", &node_get_suc_handler); + gras_cb_register("can_nuke", &node_nuke_handler); // can_test.c handler // include can_tests.c must be ON. + + TRY { + gras_msg_handle(10000.0); // waiting.. in case of someone has something to say. + } + CATCH(e) { + INFO4("My area is [%d;%d;%d;%d]", globals->x1, globals->x2, + globals->y1, globals->y2); + //INFO0("Closing node, all has been done!"); + } + + gras_socket_close(globals->sock); // spare. + free(globals); // spare. + //gras_exit(); + return (0); } // END diff --git a/examples/gras/p2p/can/can_tests.c b/examples/gras/p2p/can/can_tests.c index 80eca1947a..8742379b0a 100644 --- a/examples/gras/p2p/can/can_tests.c +++ b/examples/gras/p2p/can/can_tests.c @@ -1,5 +1,5 @@ /* Broken Peer-To-Peer CAN simulator */ - + /* Copyright (c) 2006, 2007, 2010. The SimGrid Team. * All rights reserved. */ @@ -8,203 +8,212 @@ #include //#include "gras.h" -#include "types.h" // header containing the typedef struct of a node +#include "types.h" // header containing the typedef struct of a node -XBT_LOG_NEW_DEFAULT_CATEGORY(can,"Messages specific to this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(can, "Messages specific to this example"); // struct of a "nuke" message, when a node send a nuke to (xId;yId). -GRAS_DEFINE_TYPE(s_nuke, - struct s_nuke{ - int xId; - int yId; - char host[1024]; // original expeditor.. - int port; // ..and his port. - - int version; // fun. - }; -); +GRAS_DEFINE_TYPE(s_nuke, struct s_nuke { + int xId; int yId; char host[1024]; // original expeditor.. + int port; // ..and his port. + int version; // fun. + };); + typedef struct s_nuke nuke_t; // the function that start the **** War of the Nodes **** -int start_war(int argc,char **argv); -int start_war(int argc,char **argv){ - gras_socket_t temp_sock=NULL; - nuke_t nuke_msg; - xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. +int start_war(int argc, char **argv); +int start_war(int argc, char **argv) +{ + gras_socket_t temp_sock = NULL; + nuke_t nuke_msg; + xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. //return 0; // in order to inhibit the War of the Nodes - gras_init(&argc,argv); - gras_os_sleep((15-gras_os_getpid())*20+200); // wait a bit. + gras_init(&argc, argv); + gras_os_sleep((15 - gras_os_getpid()) * 20 + 200); // wait a bit. + - - TRY{ // contacting the bad guy that will launch the War. - temp_sock=gras_socket_client(gras_os_myname(),atoi(argv[1])); - }CATCH(e){ + TRY { // contacting the bad guy that will launch the War. + temp_sock = gras_socket_client(gras_os_myname(), atoi(argv[1])); + } CATCH(e) { RETHROW0("Unable to connect known host so as to declare WAR!: %s"); } - - nuke_msg.xId=-1; - nuke_msg.yId=-1; - nuke_msg.version=atoi(argv[2]); - strcpy(nuke_msg.host,gras_os_myname()); - nuke_msg.port=atoi(argv[1]); - TRY{ - gras_msg_send(temp_sock,"can_nuke",&nuke_msg); - }CATCH(e){ + nuke_msg.xId = -1; + nuke_msg.yId = -1; + nuke_msg.version = atoi(argv[2]); + strcpy(nuke_msg.host, gras_os_myname()); + nuke_msg.port = atoi(argv[1]); + + TRY { + gras_msg_send(temp_sock, "can_nuke", &nuke_msg); + } CATCH(e) { gras_socket_close(temp_sock); - RETHROW0("Unable to contact known host so as to declare WAR!!!!!!!!!!!!!!!!!!!!!: %s"); + RETHROW0 + ("Unable to contact known host so as to declare WAR!!!!!!!!!!!!!!!!!!!!!: %s"); } gras_socket_close(temp_sock); // spare. - gras_exit(); // spare. + gras_exit(); // spare. return 0; } // the function thaht send the nuke "msg" on (xId;yId), if it's not on me :p. -static int send_nuke(nuke_t *msg, int xId, int yId){ - node_data_t *globals=(node_data_t*)gras_userdata_get(); - gras_socket_t temp_sock=NULL; - xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. - - if(xId>=globals->x1 && xId<=globals->x2 && yId>=globals->y1 && yId<=globals->y2){ +static int send_nuke(nuke_t * msg, int xId, int yId) +{ + node_data_t *globals = (node_data_t *) gras_userdata_get(); + gras_socket_t temp_sock = NULL; + xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. + + if (xId >= globals->x1 && xId <= globals->x2 && yId >= globals->y1 + && yId <= globals->y2) { INFO0("Nuclear launch missed"); return 0; - } - else{ + } else { char host[1024]; - int port=0; - - if(xIdx1){ - strcpy(host,globals->west_host); - port=globals->west_port;} - else if(xId>globals->x2){ - strcpy(host,globals->east_host); - port=globals->east_port;} - else if(yIdy1){ - strcpy(host,globals->south_host); - port=globals->south_port;} - else if(yId>globals->y2){ - strcpy(host,globals->north_host); - port=globals->north_port;} - - msg->xId=xId; - msg->yId=yId; - - - - TRY{ // sending the nuke. - temp_sock=gras_socket_client(host,port); - }CATCH(e){ + int port = 0; + + if (xId < globals->x1) { + strcpy(host, globals->west_host); + port = globals->west_port; + } else if (xId > globals->x2) { + strcpy(host, globals->east_host); + port = globals->east_port; + } else if (yId < globals->y1) { + strcpy(host, globals->south_host); + port = globals->south_port; + } else if (yId > globals->y2) { + strcpy(host, globals->north_host); + port = globals->north_port; + } + + msg->xId = xId; + msg->yId = yId; + + + + TRY { // sending the nuke. + temp_sock = gras_socket_client(host, port); + } + CATCH(e) { RETHROW0("Unable to connect the nuke!: %s"); } //INFO4("%s ON %s %d %d <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",globals->host,host,xId,yId); - TRY{ - gras_msg_send(temp_sock,"can_nuke",msg); - }CATCH(e){ + TRY { + gras_msg_send(temp_sock, "can_nuke", msg); + } + CATCH(e) { RETHROW0("Unable to send the nuke!: %s"); } gras_socket_close(temp_sock); - INFO4("Nuke launched by %s to %s for (%d;%d)",globals->host,host,msg->xId,msg->yId); + INFO4("Nuke launched by %s to %s for (%d;%d)", globals->host, host, + msg->xId, msg->yId); return 1; } } -static int node_nuke_handler(gras_msg_cb_ctx_t ctx,void *payload_data){ - gras_socket_t expeditor=gras_msg_cb_ctx_from(ctx); - nuke_t *incoming=(nuke_t*)payload_data; - node_data_t *globals=(node_data_t*)gras_userdata_get(); - - int x; - int y; - nuke_t nuke_msg; // writing my name one the nuke. - gras_socket_t temp_sock=NULL; - xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. - - - if(incoming->xId==-1){ // i must start the War - INFO2("%s:%d declare the WAR!!!!!!!!!!!!!!!!!",globals->host,globals->port); - srand((unsigned int)time((time_t *)NULL)); - - do{ - x=(int)(1000.0*rand()/(RAND_MAX+1.0)); - y=(int)(1000.0*rand()/(RAND_MAX+1.0)); +static int node_nuke_handler(gras_msg_cb_ctx_t ctx, void *payload_data) +{ + gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx); + nuke_t *incoming = (nuke_t *) payload_data; + node_data_t *globals = (node_data_t *) gras_userdata_get(); + + int x; + int y; + nuke_t nuke_msg; // writing my name one the nuke. + gras_socket_t temp_sock = NULL; + xbt_ex_t e; // the error variable used in TRY.. CATCH tokens. + + + if (incoming->xId == -1) { // i must start the War + INFO2("%s:%d declare the WAR!!!!!!!!!!!!!!!!!", globals->host, + globals->port); + srand((unsigned int) time((time_t *) NULL)); + + do { + x = (int) (1000.0 * rand() / (RAND_MAX + 1.0)); + y = (int) (1000.0 * rand() / (RAND_MAX + 1.0)); } - while(send_nuke(incoming,x,y)==0); - - } - else if(incoming->xId>=globals->x1 && incoming->xId<=globals->x2 && incoming->yId>=globals->y1 && incoming->yId<=globals->y2){ // the nuke crash on my area.. - if(globals->version==incoming->version) // ..but i'm dead. + while (send_nuke(incoming, x, y) == 0); + + } else if (incoming->xId >= globals->x1 && incoming->xId <= globals->x2 && incoming->yId >= globals->y1 && incoming->yId <= globals->y2) { // the nuke crash on my area.. + if (globals->version == incoming->version) // ..but i'm dead. INFO0("I'm already dead :p"); - else if((incoming->xId-globals->xId)/60==0 && (incoming->yId-globals->yId)/60==0){ // ..and it's on me, so i die :X. - globals->version=incoming->version; - INFO2("Euuuaarrrgghhhh... %s killed %s !!!!!!!!!!!!!!!!!",incoming->host,globals->host); - } - else{ // and it miss me, i angry and i send my own nuke! - INFO1("%s was missed, and counteract!",globals->host); + else if ((incoming->xId - globals->xId) / 60 == 0 && (incoming->yId - globals->yId) / 60 == 0) { // ..and it's on me, so i die :X. + globals->version = incoming->version; + INFO2("Euuuaarrrgghhhh... %s killed %s !!!!!!!!!!!!!!!!!", + incoming->host, globals->host); + } else { // and it miss me, i angry and i send my own nuke! + INFO1("%s was missed, and counteract!", globals->host); /*int x1=(int)(1000.0*rand()/(RAND_MAX+1.0)); - int y1=(int)(1000.0*rand()/(RAND_MAX+1.0)); - int x2=(int)(1000.0*rand()/(RAND_MAX+1.0)); - int y2=(int)(1000.0*rand()/(RAND_MAX+1.0)); - int x3=(int)(1000.0*rand()/(RAND_MAX+1.0)); - int y3=(int)(1000.0*rand()/(RAND_MAX+1.0)); - int x4=(int)(1000.0*rand()/(RAND_MAX+1.0)); - int y4=(int)(1000.0*rand()/(RAND_MAX+1.0));*/ - - - nuke_msg.version=incoming->version; - strcpy(nuke_msg.host,globals->host); - nuke_msg.port=globals->port; - - - do{ - x=(int)(1000.0*rand()/(RAND_MAX+1.0)); - y=(int)(1000.0*rand()/(RAND_MAX+1.0)); + int y1=(int)(1000.0*rand()/(RAND_MAX+1.0)); + int x2=(int)(1000.0*rand()/(RAND_MAX+1.0)); + int y2=(int)(1000.0*rand()/(RAND_MAX+1.0)); + int x3=(int)(1000.0*rand()/(RAND_MAX+1.0)); + int y3=(int)(1000.0*rand()/(RAND_MAX+1.0)); + int x4=(int)(1000.0*rand()/(RAND_MAX+1.0)); + int y4=(int)(1000.0*rand()/(RAND_MAX+1.0)); */ + + + nuke_msg.version = incoming->version; + strcpy(nuke_msg.host, globals->host); + nuke_msg.port = globals->port; + + + do { + x = (int) (1000.0 * rand() / (RAND_MAX + 1.0)); + y = (int) (1000.0 * rand() / (RAND_MAX + 1.0)); } - while(send_nuke(&nuke_msg,x,y)==0); // and sending if it's not on me. + while (send_nuke(&nuke_msg, x, y) == 0); // and sending if it's not on me. } - } - else{ // the nuke isn't for me, so i forward her. + } else { // the nuke isn't for me, so i forward her. char host[1024]; - int port=0; - - if(incoming->xIdx1){ - strcpy(host,globals->west_host); - port=globals->west_port;} - else if(incoming->xId>globals->x2){ - strcpy(host,globals->east_host); - port=globals->east_port;} - else if(incoming->yIdy1){ - strcpy(host,globals->south_host); - port=globals->south_port;} - else if(incoming->yId>globals->y2){ - strcpy(host,globals->north_host); - port=globals->north_port;} - - - - TRY{ - temp_sock=gras_socket_client(host,port); - }CATCH(e){ + int port = 0; + + if (incoming->xId < globals->x1) { + strcpy(host, globals->west_host); + port = globals->west_port; + } else if (incoming->xId > globals->x2) { + strcpy(host, globals->east_host); + port = globals->east_port; + } else if (incoming->yId < globals->y1) { + strcpy(host, globals->south_host); + port = globals->south_port; + } else if (incoming->yId > globals->y2) { + strcpy(host, globals->north_host); + port = globals->north_port; + } + + + + TRY { + temp_sock = gras_socket_client(host, port); + } + CATCH(e) { RETHROW0("Unable to connect the nuke!: %s"); } - TRY{ - gras_msg_send(temp_sock,"can_nuke",incoming); - }CATCH(e){ + TRY { + gras_msg_send(temp_sock, "can_nuke", incoming); + } + CATCH(e) { RETHROW0("Unable to send the nuke!: %s"); } - INFO4("Nuke re-aimed by %s to %s for (%d;%d)",globals->host,host,incoming->xId,incoming->yId); + INFO4("Nuke re-aimed by %s to %s for (%d;%d)", globals->host, host, + incoming->xId, incoming->yId); gras_socket_close(temp_sock); } gras_socket_close(expeditor); // spare. - TRY{ - gras_msg_handle(10000.0); // wait a bit, in case of.. - }CATCH(e){ - INFO4("My area is [%d;%d;%d;%d]",globals->x1,globals->x2,globals->y1,globals->y2); + TRY { + gras_msg_handle(10000.0); // wait a bit, in case of.. + } + CATCH(e) { + INFO4("My area is [%d;%d;%d;%d]", globals->x1, globals->x2, + globals->y1, globals->y2); //INFO0("Closing node, all has been done!"); - } - return 0; + } + return 0; } // END diff --git a/examples/gras/p2p/can/types.h b/examples/gras/p2p/can/types.h index 4e2f0d13c7..ddeb68f1e2 100644 --- a/examples/gras/p2p/can/types.h +++ b/examples/gras/p2p/can/types.h @@ -7,26 +7,26 @@ #include "gras.h" /* Global private data */ -typedef struct{ - gras_socket_t sock; /* server socket on which I'm listening */ - int xId; - int yId; - char host[1024]; /* my host name */ - int port; /* port on which I'm listening FIXME */ +typedef struct { + gras_socket_t sock; /* server socket on which I'm listening */ + int xId; + int yId; + char host[1024]; /* my host name */ + int port; /* port on which I'm listening FIXME */ - int x1; // Xmin - int x2; // Xmax - int y1; // Ymin - int y2; // Ymax + int x1; // Xmin + int x2; // Xmax + int y1; // Ymin + int y2; // Ymax - char north_host[1024]; - int north_port; - char south_host[1024]; - int south_port; - char east_host[1024]; - int east_port; - char west_host[1024]; - int west_port; + char north_host[1024]; + int north_port; + char south_host[1024]; + int south_port; + char east_host[1024]; + int east_port; + char west_host[1024]; + int west_port; - int version; -}node_data_t; + int version; +} node_data_t; diff --git a/examples/gras/p2p/chord/chord.c b/examples/gras/p2p/chord/chord.c index b6b9de1efb..debf98fbbe 100644 --- a/examples/gras/p2p/chord/chord.c +++ b/examples/gras/p2p/chord/chord.c @@ -11,9 +11,9 @@ static int closest_preceding_node(int id); static void check_predecessor(void); -XBT_LOG_NEW_DEFAULT_CATEGORY(chord,"Messages specific to this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(chord, "Messages specific to this example"); -typedef enum msg_typus{ +typedef enum msg_typus { PING, PONG, GET_PRE, @@ -21,7 +21,7 @@ typedef enum msg_typus{ GET_SUC, REP_SUC, STD, -}msg_typus; +} msg_typus; /*GRAS_DEFINE_TYPE(s_pbio, struct s_pbio{ @@ -33,76 +33,69 @@ typedef enum msg_typus{ typedef struct s_pbio pbio_t;*/ /*GRAS_DEFINE_TYPE(s_ping,*/ - struct s_ping{ - int id; - }; +struct s_ping { + int id; +}; /*);*/ typedef struct s_ping ping_t; /*GRAS_DEFINE_TYPE(s_pong,*/ - struct s_pong{ - int id; - int failed; - }; +struct s_pong { + int id; + int failed; +}; /*);*/ typedef struct s_pong pong_t; -GRAS_DEFINE_TYPE(s_notify, - struct s_notify{ - int id; - char host[1024]; - int port; - }; -); +GRAS_DEFINE_TYPE(s_notify, struct s_notify { + int id; char host[1024]; int port;};); + typedef struct s_notify notify_t; -GRAS_DEFINE_TYPE(s_get_suc, - struct s_get_suc{ - int id; - }; -); +GRAS_DEFINE_TYPE(s_get_suc, struct s_get_suc { + int id;};); + typedef struct s_get_suc get_suc_t; -GRAS_DEFINE_TYPE(s_rep_suc, - struct s_rep_suc{ - int id; - char host[1024]; - int port; - }; -); +GRAS_DEFINE_TYPE(s_rep_suc, struct s_rep_suc { + int id; char host[1024]; int port;};); + typedef struct s_rep_suc rep_suc_t; -typedef struct finger_elem{ +typedef struct finger_elem { int id; char host[1024]; int port; -}finger_elem; +} finger_elem; -static void register_messages(){ +static void register_messages() +{ /* gras_msgtype_declare("chord",gras_datadesc_by_symbol(s_pbio));*/ - gras_msgtype_declare("chord_get_suc",gras_datadesc_by_symbol(s_get_suc)); - gras_msgtype_declare("chord_rep_suc",gras_datadesc_by_symbol(s_rep_suc)); - gras_msgtype_declare("chord_notify",gras_datadesc_by_symbol(s_notify)); + gras_msgtype_declare("chord_get_suc", + gras_datadesc_by_symbol(s_get_suc)); + gras_msgtype_declare("chord_rep_suc", + gras_datadesc_by_symbol(s_rep_suc)); + gras_msgtype_declare("chord_notify", gras_datadesc_by_symbol(s_notify)); } /* Global private data */ -typedef struct{ - gras_socket_t sock; /* server socket on which I'm listening */ - int id; /* my id number */ - char host[1024]; /* my host name */ - int port; /* port on which I'm listening FIXME */ - int fingers; /* how many fingers */ - finger_elem *finger; /* finger table */ - int next_to_fix; /* next in the finger list to be checked */ - int pre_id; /* predecessor id */ - char pre_host[1024]; /* predecessor host */ - int pre_port; /* predecessor port */ -}node_data_t; - - -int node(int argc,char **argv); +typedef struct { + gras_socket_t sock; /* server socket on which I'm listening */ + int id; /* my id number */ + char host[1024]; /* my host name */ + int port; /* port on which I'm listening FIXME */ + int fingers; /* how many fingers */ + finger_elem *finger; /* finger table */ + int next_to_fix; /* next in the finger list to be checked */ + int pre_id; /* predecessor id */ + char pre_host[1024]; /* predecessor host */ + int pre_port; /* predecessor port */ +} node_data_t; + + +int node(int argc, char **argv); /*static int node_cb_chord_handler(gras_socket_t expeditor,void *payload_data){ xbt_ex_t e; @@ -116,151 +109,166 @@ int node(int argc,char **argv); }*/ -static int node_cb_get_suc_handler(gras_msg_cb_ctx_t ctx,void *payload_data){ - gras_socket_t expeditor=gras_msg_cb_ctx_from(ctx); +static int node_cb_get_suc_handler(gras_msg_cb_ctx_t ctx, + void *payload_data) +{ + gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx); xbt_ex_t e; - get_suc_t incoming=*(get_suc_t*)payload_data; + get_suc_t incoming = *(get_suc_t *) payload_data; rep_suc_t outgoing; - node_data_t *globals=(node_data_t*)gras_userdata_get(); + node_data_t *globals = (node_data_t *) gras_userdata_get(); INFO2("Received a get_successor message from %s for %d", - gras_socket_peer_name(expeditor),incoming.id); - if((globals->id==globals->finger[0].id)|| - (incoming.id>globals->id&&incoming.id<=globals->finger[0].id)){ - outgoing.id=globals->finger[0].id; - snprintf(outgoing.host,1024,globals->finger[0].host); - outgoing.port=globals->finger[0].port; + gras_socket_peer_name(expeditor), incoming.id); + if ((globals->id == globals->finger[0].id) || + (incoming.id > globals->id + && incoming.id <= globals->finger[0].id)) { + outgoing.id = globals->finger[0].id; + snprintf(outgoing.host, 1024, globals->finger[0].host); + outgoing.port = globals->finger[0].port; INFO0("My successor is his successor!"); - }else{ + } else { gras_socket_t temp_sock; - int contact=closest_preceding_node(incoming.id); - if(contact==-1){ - outgoing.id=globals->finger[0].id; - snprintf(outgoing.host,1024,globals->finger[0].host); - outgoing.port=globals->finger[0].port; + int contact = closest_preceding_node(incoming.id); + if (contact == -1) { + outgoing.id = globals->finger[0].id; + snprintf(outgoing.host, 1024, globals->finger[0].host); + outgoing.port = globals->finger[0].port; INFO0("My successor is his successor!"); - }else{ - get_suc_t asking;asking.id=incoming.id; - TRY{ - temp_sock=gras_socket_client(globals->finger[contact].host, - globals->finger[contact].port); - }CATCH(e){ + } else { + get_suc_t asking; + asking.id = incoming.id; + TRY { + temp_sock = gras_socket_client(globals->finger[contact].host, + globals->finger[contact].port); + } + CATCH(e) { RETHROW0("Unable to connect!: %s"); } - TRY{ - gras_msg_send(temp_sock,"chord_get_suc",&asking); - }CATCH(e){ + TRY { + gras_msg_send(temp_sock, "chord_get_suc", &asking); + } + CATCH(e) { RETHROW0("Unable to ask!: %s"); } - gras_msg_wait(10.,"chord_rep_suc",&temp_sock, &outgoing); + gras_msg_wait(10., "chord_rep_suc", &temp_sock, &outgoing); } } - - TRY{ - gras_msg_send(expeditor,"chord_rep_suc",&outgoing); + + TRY { + gras_msg_send(expeditor, "chord_rep_suc", &outgoing); INFO0("Successor information sent!"); - }CATCH(e){ + } + CATCH(e) { RETHROW2("%s:Timeout sending successor information to %s: %s", - globals->host,gras_socket_peer_name(expeditor)); + globals->host, gras_socket_peer_name(expeditor)); } gras_socket_close(expeditor); return 0; } -static int closest_preceding_node(int id){ - node_data_t *globals=(node_data_t*)gras_userdata_get(); +static int closest_preceding_node(int id) +{ + node_data_t *globals = (node_data_t *) gras_userdata_get(); int i; - for(i=globals->fingers-1;i>=0;i--){ - if(globals->finger[i].id>globals->id&&globals->finger[i].idfingers - 1; i >= 0; i--) { + if (globals->finger[i].id > globals->id && globals->finger[i].id < id) { + return (i); } } - + return i; } -static int node_cb_notify_handler(gras_msg_cb_ctx_t ctx,void *payload_data){ - gras_socket_t expeditor=gras_msg_cb_ctx_from(ctx); - /*xbt_ex_t e;*/ - notify_t incoming=*(notify_t*)payload_data; - node_data_t *globals=(node_data_t*)gras_userdata_get(); +static int node_cb_notify_handler(gras_msg_cb_ctx_t ctx, + void *payload_data) +{ + gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx); + /*xbt_ex_t e; */ + notify_t incoming = *(notify_t *) payload_data; + node_data_t *globals = (node_data_t *) gras_userdata_get(); INFO2("Received a notifying message from %s as %d", - gras_socket_peer_name(expeditor),incoming.id); - if(globals->pre_id==-1|| - (incoming.id>globals->pre_id&&incoming.idid)){ - globals->pre_id=incoming.id; - snprintf(globals->pre_host,1024,incoming.host); - globals->pre_port=incoming.port; + gras_socket_peer_name(expeditor), incoming.id); + if (globals->pre_id == -1 || + (incoming.id > globals->pre_id && incoming.id < globals->id)) { + globals->pre_id = incoming.id; + snprintf(globals->pre_host, 1024, incoming.host); + globals->pre_port = incoming.port; INFO0("Set as my new predecessor!"); } return 0; } -static void fix_fingers(){ - get_suc_t get_suc_msg; +static void fix_fingers() +{ + get_suc_t get_suc_msg; xbt_ex_t e; - gras_socket_t temp_sock=NULL; - gras_socket_t temp_sock2=NULL; + gras_socket_t temp_sock = NULL; + gras_socket_t temp_sock2 = NULL; rep_suc_t rep_suc_msg; - node_data_t *globals=(node_data_t*)gras_userdata_get(); + node_data_t *globals = (node_data_t *) gras_userdata_get(); - TRY{ - temp_sock=gras_socket_client(globals->host,globals->port); - }CATCH(e){ + TRY { + temp_sock = gras_socket_client(globals->host, globals->port); + } CATCH(e) { RETHROW0("Unable to contact known host: %s"); } - get_suc_msg.id=globals->id; - TRY{ - gras_msg_send(temp_sock,"chord_get_suc",&get_suc_msg); - }CATCH(e){ + get_suc_msg.id = globals->id; + TRY { + gras_msg_send(temp_sock, "chord_get_suc", &get_suc_msg); + } CATCH(e) { gras_socket_close(temp_sock); RETHROW0("Unable to contact known host to get successor!: %s"); } - TRY{ + TRY { INFO0("Waiting for reply!"); - gras_msg_wait(6000,"chord_rep_suc",&temp_sock2, &rep_suc_msg); - }CATCH(e){ - RETHROW1("%s: Error waiting for successor:%s",globals->host); + gras_msg_wait(6000, "chord_rep_suc", &temp_sock2, &rep_suc_msg); + } CATCH(e) { + RETHROW1("%s: Error waiting for successor:%s", globals->host); } - globals->finger[0].id=rep_suc_msg.id; - snprintf(globals->finger[0].host,1024,rep_suc_msg.host); - globals->finger[0].port=rep_suc_msg.port; - INFO1("→ Finger %d fixed!",globals->next_to_fix); + globals->finger[0].id = rep_suc_msg.id; + snprintf(globals->finger[0].host, 1024, rep_suc_msg.host); + globals->finger[0].port = rep_suc_msg.port; + INFO1("→ Finger %d fixed!", globals->next_to_fix); gras_socket_close(temp_sock); - - globals->next_to_fix=(++globals->next_to_fix==globals->fingers)? - 0:globals->next_to_fix; + + globals->next_to_fix = (++globals->next_to_fix == globals->fingers) ? + 0 : globals->next_to_fix; } -static void check_predecessor(){ - node_data_t *globals = (node_data_t*)gras_userdata_get(); +static void check_predecessor() +{ + node_data_t *globals = (node_data_t *) gras_userdata_get(); gras_socket_t temp_sock; - ping_t ping; + ping_t ping; pong_t pong; xbt_ex_t e; - if (globals->pre_id == -1){ + if (globals->pre_id == -1) { return; } - TRY{ - temp_sock = gras_socket_client( globals->pre_host, globals->pre_port ); - }CATCH(e){ + TRY { + temp_sock = gras_socket_client(globals->pre_host, globals->pre_port); + } + CATCH(e) { globals->pre_id = -1; globals->pre_host[0] = 0; globals->pre_port = 0; } ping.id = 0; - TRY{ - gras_msg_send( temp_sock, "chord_ping",&ping); - }CATCH(e){ + TRY { + gras_msg_send(temp_sock, "chord_ping", &ping); + } + CATCH(e) { globals->pre_id = -1; globals->pre_host[0] = 0; globals->pre_port = 0; } - TRY{ - gras_msg_wait( 60, "chord_pong", &temp_sock, &pong); - }CATCH(e){ + TRY { + gras_msg_wait(60, "chord_pong", &temp_sock, &pong); + } + CATCH(e) { globals->pre_id = -1; globals->pre_host[0] = 0; globals->pre_port = 0; @@ -268,120 +276,127 @@ static void check_predecessor(){ gras_socket_close(temp_sock); } -int node(int argc,char **argv){ - node_data_t *globals=NULL; - gras_socket_t temp_sock=NULL; - gras_socket_t temp_sock2=NULL; +int node(int argc, char **argv) +{ + node_data_t *globals = NULL; + gras_socket_t temp_sock = NULL; + gras_socket_t temp_sock2 = NULL; get_suc_t get_suc_msg; rep_suc_t rep_suc_msg; xbt_ex_t e; - int create=0; - int other_port=-1; + int create = 0; + int other_port = -1; char *other_host; notify_t notify_msg; int l; /* 1. Init the GRAS infrastructure and declare my globals */ - gras_init(&argc,argv); - - gras_os_sleep((15-gras_os_getpid())*20); - - globals=gras_userdata_new(node_data_t); - - globals->id=atoi(argv[1]); - globals->port=atoi(argv[2]); - globals->fingers=0; - globals->finger=NULL; - globals->pre_id=-1; - globals->pre_host[0]=0; - globals->pre_port=-1; - - snprintf(globals->host,1024,gras_os_myname()); - - if(argc==3){ - create=1; - }else{ - asprintf(&other_host,"%s",argv[3]); - other_port=atoi(argv[4]); + gras_init(&argc, argv); + + gras_os_sleep((15 - gras_os_getpid()) * 20); + + globals = gras_userdata_new(node_data_t); + + globals->id = atoi(argv[1]); + globals->port = atoi(argv[2]); + globals->fingers = 0; + globals->finger = NULL; + globals->pre_id = -1; + globals->pre_host[0] = 0; + globals->pre_port = -1; + + snprintf(globals->host, 1024, gras_os_myname()); + + if (argc == 3) { + create = 1; + } else { + asprintf(&other_host, "%s", argv[3]); + other_port = atoi(argv[4]); } - - globals->sock=gras_socket_server(globals->port); + + globals->sock = gras_socket_server(globals->port); gras_os_sleep(1.0); register_messages(); - globals->finger=(finger_elem*)calloc(1,sizeof(finger_elem)); - INFO2("Launching node %s:%d",globals->host,globals->port); - if(create){ + globals->finger = (finger_elem *) calloc(1, sizeof(finger_elem)); + INFO2("Launching node %s:%d", globals->host, globals->port); + if (create) { INFO0("→Creating ring"); - globals->finger[0].id=globals->id; - snprintf(globals->finger[0].host,1024,globals->host); - globals->finger[0].port=globals->port; - }else{ - INFO2("→Known node %s:%d",other_host,other_port); + globals->finger[0].id = globals->id; + snprintf(globals->finger[0].host, 1024, globals->host); + globals->finger[0].port = globals->port; + } else { + INFO2("→Known node %s:%d", other_host, other_port); INFO0("→Contacting to determine successor"); - TRY{ - temp_sock=gras_socket_client(other_host,other_port); - }CATCH(e){ + TRY { + temp_sock = gras_socket_client(other_host, other_port); + } + CATCH(e) { RETHROW0("Unable to contact known host: %s"); } - get_suc_msg.id=globals->id; - TRY{ - gras_msg_send(temp_sock,"chord_get_suc", &get_suc_msg); - }CATCH(e){ + get_suc_msg.id = globals->id; + TRY { + gras_msg_send(temp_sock, "chord_get_suc", &get_suc_msg); + } + CATCH(e) { gras_socket_close(temp_sock); RETHROW0("Unable to contact known host to get successor!: %s"); } - TRY{ + TRY { INFO0("Waiting for reply!"); - gras_msg_wait(10.,"chord_rep_suc",&temp_sock2, &rep_suc_msg); - }CATCH(e){ - RETHROW1("%s: Error waiting for successor:%s",globals->host); + gras_msg_wait(10., "chord_rep_suc", &temp_sock2, &rep_suc_msg); + } + CATCH(e) { + RETHROW1("%s: Error waiting for successor:%s", globals->host); } - globals->finger[0].id=rep_suc_msg.id; - snprintf(globals->finger[0].host,1024,rep_suc_msg.host); - globals->finger[0].port=rep_suc_msg.port; - INFO3("→Got successor : %d-%s:%d",globals->finger[0].id, - globals->finger[0].host,globals->finger[0].port); + globals->finger[0].id = rep_suc_msg.id; + snprintf(globals->finger[0].host, 1024, rep_suc_msg.host); + globals->finger[0].port = rep_suc_msg.port; + INFO3("→Got successor : %d-%s:%d", globals->finger[0].id, + globals->finger[0].host, globals->finger[0].port); gras_socket_close(temp_sock); - TRY{ - temp_sock=gras_socket_client(globals->finger[0].host, - globals->finger[0].port); - }CATCH(e){ + TRY { + temp_sock = gras_socket_client(globals->finger[0].host, + globals->finger[0].port); + } + CATCH(e) { RETHROW0("Unable to contact successor: %s"); } - notify_msg.id=globals->id; - snprintf(notify_msg.host,1024,globals->host); - notify_msg.port=globals->port; - TRY{ - gras_msg_send(temp_sock,"chord_notify",¬ify_msg); - }CATCH(e){ + notify_msg.id = globals->id; + snprintf(notify_msg.host, 1024, globals->host); + notify_msg.port = globals->port; + TRY { + gras_msg_send(temp_sock, "chord_notify", ¬ify_msg); + } + CATCH(e) { RETHROW0("Unable to notify successor! %s"); } } - + gras_cb_register("chord_get_suc", &node_cb_get_suc_handler); - gras_cb_register("chord_notify", &node_cb_notify_handler); - /*gras_cb_register("chord_ping",&node_cb_ping_handler);*/ - /* gras_timer_repeat(600.,fix_fingers);*/ - /*while(1){*/ + gras_cb_register("chord_notify", &node_cb_notify_handler); + /*gras_cb_register("chord_ping",&node_cb_ping_handler); */ + /* gras_timer_repeat(600.,fix_fingers); */ + /*while(1){ */ - for(l=0;l<50;l++){ - TRY{ + for (l = 0; l < 50; l++) { + TRY { gras_msg_handle(6000000.0); - }CATCH(e){ + } + CATCH(e) { } } - /*}*/ - + /*} */ + gras_socket_close(globals->sock); free(globals); gras_exit(); INFO0("Done"); - return(0); + return (0); } diff --git a/examples/gras/ping/ping_server.c b/examples/gras/ping/ping_server.c index 27597d9e67..d75975ae0d 100644 --- a/examples/gras/ping/ping_server.c +++ b/examples/gras/ping/ping_server.c @@ -33,7 +33,8 @@ static int server_cb_ping_handler(gras_msg_cb_ctx_t ctx, void *payload) /* 3. Log which client connected */ INFO3(">>>>>>>> Got message PING(%d) from %s:%d <<<<<<<<", msg, - gras_socket_peer_name(expeditor), gras_socket_peer_port(expeditor)); + gras_socket_peer_name(expeditor), + gras_socket_peer_port(expeditor)); /* 4. Change the value of the msg variable */ msg = 4321; @@ -93,7 +94,8 @@ int server(int argc, char *argv[]) /* 7. Housekeeping */ if (!globals->endcondition) - WARN0("An error occured, the endcondition was not set by the callback"); + WARN0 + ("An error occured, the endcondition was not set by the callback"); /* 8. Free the allocated resources, and shut GRAS down */ gras_socket_close(globals->sock); diff --git a/examples/gras/pmm/pmm.c b/examples/gras/pmm/pmm.c index 78778efc7c..0ad4e9884d 100755 --- a/examples/gras/pmm/pmm.c +++ b/examples/gras/pmm/pmm.c @@ -21,8 +21,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(pmm, "Parallel Matrix Multiplication"); /* struct for recovering results */ GRAS_DEFINE_TYPE(s_result, struct s_result { - int linepos; - int rowpos; xbt_matrix_t C GRAS_ANNOTE(subtype, double);}); + int linepos; int rowpos; + xbt_matrix_t C GRAS_ANNOTE(subtype, double); + }); typedef struct s_result result_t; @@ -33,7 +34,8 @@ GRAS_DEFINE_TYPE(s_pmm_assignment, struct s_pmm_assignment { xbt_peer_t line[NEIGHBOR_COUNT]; xbt_peer_t row[NEIGHBOR_COUNT]; xbt_matrix_t A GRAS_ANNOTE(subtype, double); - xbt_matrix_t B GRAS_ANNOTE(subtype, double);}); + xbt_matrix_t B GRAS_ANNOTE(subtype, double); + }); typedef struct s_pmm_assignment s_pmm_assignment_t; @@ -55,11 +57,11 @@ static void register_messages(void) /* send data between slaves */ gras_msgtype_declare("dataA", - gras_datadesc_matrix(gras_datadesc_by_name("double"), - NULL)); + gras_datadesc_matrix(gras_datadesc_by_name + ("double"), NULL)); gras_msgtype_declare("dataB", - gras_datadesc_matrix(gras_datadesc_by_name("double"), - NULL)); + gras_datadesc_matrix(gras_datadesc_by_name + ("double"), NULL)); /* synchronization message */ gras_msgtype_declare("pmm_sync", 0); @@ -113,8 +115,9 @@ int master(int argc, char *argv[]) /* friends, we're ready. Come and play */ INFO0("Wait for peers for 2 sec"); gras_msg_handleall(2); - while (xbt_dynar_length(peers)<9) { - INFO1("Got only %ld pals. Wait 2 more seconds", xbt_dynar_length(peers)); + while (xbt_dynar_length(peers) < 9) { + INFO1("Got only %ld pals. Wait 2 more seconds", + xbt_dynar_length(peers)); gras_msg_handleall(2); } INFO1("Good. Got %ld pals", xbt_dynar_length(peers)); @@ -167,8 +170,9 @@ int master(int argc, char *argv[]) submatrix_size * line, submatrix_size * row, NULL); assignment.B = - xbt_matrix_new_sub(B, submatrix_size, submatrix_size, - submatrix_size * line, submatrix_size * row, NULL); + xbt_matrix_new_sub(B, submatrix_size, submatrix_size, + submatrix_size * line, submatrix_size * row, + NULL); row++; if (row >= PROC_MATRIX_SIZE) { row = 0; @@ -181,18 +185,19 @@ int master(int argc, char *argv[]) } /* synchronize slaves */ - for (i = 0 ; i < PROC_MATRIX_SIZE ; i++) { + for (i = 0; i < PROC_MATRIX_SIZE; i++) { int j; - for (j = 0 ; j < SLAVE_COUNT ; j++) + for (j = 0; j < SLAVE_COUNT; j++) gras_msg_wait(600, "pmm_sync", NULL, NULL); - for (j = 0 ; j < SLAVE_COUNT ; j++) + for (j = 0; j < SLAVE_COUNT; j++) gras_msg_send(socket[j], "pmm_sync", NULL); } /* Retrieve the results */ for (i = 0; i < SLAVE_COUNT; i++) { gras_msg_wait(6000, "result", &from, &result); - VERB2("%d slaves are done already. Waiting for %d", i + 1, SLAVE_COUNT); + VERB2("%d slaves are done already. Waiting for %d", i + 1, + SLAVE_COUNT); xbt_matrix_copy_values(C, result.C, submatrix_size, submatrix_size, submatrix_size * result.linepos, submatrix_size * result.rowpos, 0, 0, NULL); @@ -204,13 +209,13 @@ int master(int argc, char *argv[]) INFO0("XXXXXXXXXXXXXXXXXXXXXX Ok, the result matches expectations"); else { WARN0("the result seems wrong"); - if (DATA_MATRIX_SIZE < 30) { - INFO0("The Result of Multiplication is :"); - xbt_matrix_dump(C, "C:res", 0, xbt_matrix_dump_display_double); - } else { - INFO1("Matrix size too big (%d>30) to be displayed here", - DATA_MATRIX_SIZE); - } + if (DATA_MATRIX_SIZE < 30) { + INFO0("The Result of Multiplication is :"); + xbt_matrix_dump(C, "C:res", 0, xbt_matrix_dump_display_double); + } else { + INFO1("Matrix size too big (%d>30) to be displayed here", + DATA_MATRIX_SIZE); + } } amok_pm_group_shutdown("pmm"); /* Ok, we're out of here */ @@ -246,7 +251,7 @@ static int pmm_worker_cb(gras_msg_cb_ctx_t ctx, void *payload) int myline, myrow; xbt_matrix_t mydataA, mydataB; xbt_matrix_t bC = - xbt_matrix_double_new_zeros(submatrix_size, submatrix_size); + xbt_matrix_double_new_zeros(submatrix_size, submatrix_size); result_t result; @@ -290,7 +295,8 @@ static int pmm_worker_cb(gras_msg_cb_ctx_t ctx, void *payload) /* a line brodcast */ if (myline == step) { - VERB2("LINE: step(%d) = Myline(%d). Broadcast my data.", step, myline); + VERB2("LINE: step(%d) = Myline(%d). Broadcast my data.", step, + myline); for (l = 0; l < PROC_MATRIX_SIZE - 1; l++) { VERB1("LINE: Send to %s", gras_socket_peer_name(socket_row[l])); gras_msg_send(socket_row[l], "dataB", &mydataB); @@ -316,7 +322,8 @@ static int pmm_worker_cb(gras_msg_cb_ctx_t ctx, void *payload) if (myrow == step) { VERB2("ROW: step(%d)=myrow(%d). Broadcast my data.", step, myrow); for (l = 1; l < PROC_MATRIX_SIZE; l++) { - VERB1("ROW: Send to %s", gras_socket_peer_name(socket_line[l - 1])); + VERB1("ROW: Send to %s", + gras_socket_peer_name(socket_line[l - 1])); gras_msg_send(socket_line[l - 1], "dataA", &mydataA); } xbt_matrix_free(bA); diff --git a/examples/gras/properties/properties.c b/examples/gras/properties/properties.c index 850b91d492..ce8372e50d 100644 --- a/examples/gras/properties/properties.c +++ b/examples/gras/properties/properties.c @@ -28,11 +28,11 @@ int alice(int argc, char *argv[]) INFO0("== Dump all the properties of current host"); xbt_dict_foreach(host_props, cursor, key, data) - INFO2(" Host property: '%s' has value: '%s'", key, data); + INFO2(" Host property: '%s' has value: '%s'", key, data); INFO0("== Dump all the properties of alice"); xbt_dict_foreach(process_props, cursor, key, data) - if (!strncmp(key, "SG_TEST_", 8)) + if (!strncmp(key, "SG_TEST_", 8)) INFO2(" Process property: '%s' has value: '%s'", key, data); INFO0("== Try to get a process property that does not exist"); @@ -68,20 +68,21 @@ int bob(int argc, char *argv[]) INFO0("== Dump all the properties of host1"); xbt_dict_foreach(host_props, cursor, key, data) - INFO2(" Host property: '%s' has value: '%s'", key, data); + INFO2(" Host property: '%s' has value: '%s'", key, data); INFO0("== Try to get a property that does not exist"); value = gras_os_host_property_value("non existing key"); xbt_assert1(value == NULL, - "The key 'non existing key' exists (with value '%s')!!", value); + "The key 'non existing key' exists (with value '%s')!!", + value); INFO0 - ("== Set a host property that alice will try to retrieve in SG (from bob->hello)"); + ("== Set a host property that alice will try to retrieve in SG (from bob->hello)"); xbt_dict_set(host_props, "from bob", xbt_strdup("hello"), xbt_free_f); INFO0("== Dump all the properties of host1 again to check the addition"); xbt_dict_foreach(host_props, cursor, key, data) - INFO2(" Host property: '%s' has value: '%s'", key, data); + INFO2(" Host property: '%s' has value: '%s'", key, data); gras_os_sleep(1); /* KILLME once bug on empty main is solved */ gras_exit(); diff --git a/examples/gras/replay/replay.c b/examples/gras/replay/replay.c index c29f566354..a0a42e9d51 100644 --- a/examples/gras/replay/replay.c +++ b/examples/gras/replay/replay.c @@ -21,30 +21,34 @@ #include "simix/simix.h" -int master(int argc,char *argv[]); -int worker(int argc,char *argv[]); +int master(int argc, char *argv[]); +int worker(int argc, char *argv[]); XBT_LOG_NEW_DEFAULT_CATEGORY(replay, "Messages specific to this example"); -static void declare_msg() { +static void declare_msg() +{ amok_pm_init(); xbt_workload_declare_datadesc(); - gras_msgtype_declare("go",NULL); + gras_msgtype_declare("go", NULL); gras_msgtype_declare("commands", - gras_datadesc_dynar( - gras_datadesc_by_name("xbt_workload_elm_t"),xbt_workload_elm_free_voidp)); - gras_msgtype_declare("chunk",gras_datadesc_by_name("xbt_workload_data_chunk_t")); + gras_datadesc_dynar(gras_datadesc_by_name + ("xbt_workload_elm_t"), + xbt_workload_elm_free_voidp)); + gras_msgtype_declare("chunk", + gras_datadesc_by_name("xbt_workload_data_chunk_t")); } -int master(int argc,char *argv[]) { +int master(int argc, char *argv[]) +{ - gras_init(&argc,argv); + gras_init(&argc, argv); declare_msg(); - xbt_assert0(argc==3,"usage: replay_master tracefile port"); - gras_socket_server(atoi(argv[2])); /* open my master socket, even if I don't use it */ - xbt_dynar_t peers = amok_pm_group_new("replay"); /* group of slaves */ + xbt_assert0(argc == 3, "usage: replay_master tracefile port"); + gras_socket_server(atoi(argv[2])); /* open my master socket, even if I don't use it */ + xbt_dynar_t peers = amok_pm_group_new("replay"); /* group of slaves */ xbt_peer_t peer; xbt_dynar_t cmds = xbt_workload_parse_file(argv[1]); xbt_workload_sort_who_date(cmds); @@ -54,28 +58,30 @@ int master(int argc,char *argv[]) { xbt_ex_t e; xbt_dict_cursor_t dict_cursor; - xbt_dict_t pals_int=xbt_dict_new(); - xbt_dynar_foreach(cmds,cursor,cmd) { - int *p = xbt_dict_get_or_null(pals_int,cmd->who); + xbt_dict_t pals_int = xbt_dict_new(); + xbt_dynar_foreach(cmds, cursor, cmd) { + int *p = xbt_dict_get_or_null(pals_int, cmd->who); if (!p) { - p=(int*)0xBEAF; - xbt_dict_set(pals_int,cmd->who,&p,NULL); + p = (int *) 0xBEAF; + xbt_dict_set(pals_int, cmd->who, &p, NULL); } } /* friends, we're ready. Come and play */ - INFO1("Wait for peers for a while. I need %d peers",xbt_dict_size(pals_int)); - while (xbt_dynar_length(peers)name); + } + CATCH(e) { + xbt_dynar_foreach(peers, cursor, peer) { + xbt_dict_remove(pals_int, peer->name); } char *peer_name; void *data; - xbt_dict_foreach(pals_int,dict_cursor,peer_name,data) { - INFO1("Peer %s didn't showed up",peer_name); + xbt_dict_foreach(pals_int, dict_cursor, peer_name, data) { + INFO1("Peer %s didn't showed up", peer_name); } RETHROW; } @@ -86,16 +92,16 @@ int master(int argc,char *argv[]) { /* Check who came */ xbt_dict_t pals = xbt_dict_new(); gras_socket_t pal; - xbt_dynar_foreach(peers,cursor, peer) { + xbt_dynar_foreach(peers, cursor, peer) { //INFO1("%s is here",peer->name); - gras_socket_t sock = gras_socket_client(peer->name,peer->port); - xbt_dict_set(pals,peer->name,sock,NULL); + gras_socket_t sock = gras_socket_client(peer->name, peer->port); + xbt_dict_set(pals, peer->name, sock, NULL); } /* check that we have a dude for every element of the trace */ - xbt_dynar_foreach(cmds,cursor,cmd) { - pal=xbt_dict_get_or_null(pals,cmd->who); + xbt_dynar_foreach(cmds, cursor, cmd) { + pal = xbt_dict_get_or_null(pals, cmd->who); if (!pal) { - CRITICAL1("Process %s didn't came! Abording!",cmd->who); + CRITICAL1("Process %s didn't came! Abording!", cmd->who); amok_pm_group_shutdown("replay"); xbt_dynar_free(&cmds); gras_exit(); @@ -104,18 +110,18 @@ int master(int argc,char *argv[]) { } /* Send the commands to every pal */ char *pal_name; - xbt_dict_foreach(pals,dict_cursor,pal_name,pal) { - gras_msg_send(pal,"commands",&cmds); + xbt_dict_foreach(pals, dict_cursor, pal_name, pal) { + gras_msg_send(pal, "commands", &cmds); } INFO0("Sent commands to every processes. Let them start now"); xbt_dict_cursor_t dict_it; - xbt_dict_foreach(pals,dict_it,pal_name,pal) { - gras_msg_send(pal,"go",NULL); + xbt_dict_foreach(pals, dict_it, pal_name, pal) { + gras_msg_send(pal, "go", NULL); } INFO0("They should be started by now. Wait for their completion."); - for (cursor=0;cursorpeers,peer); + gras_socket_t peer_sock = xbt_dict_get_or_null(g->peers, peer); if (!peer_sock) { - INFO1("Create a socket to %s",peer); - peer_sock = gras_socket_client(peer,4000); - xbt_dict_set(g->peers,peer,peer_sock,NULL);//gras_socket_close_voidp); + INFO1("Create a socket to %s", peer); + peer_sock = gras_socket_client(peer, 4000); + xbt_dict_set(g->peers, peer, peer_sock, NULL); //gras_socket_close_voidp); } return peer_sock; } -static int worker_commands_cb(gras_msg_cb_ctx_t ctx, void *payload) { + +static int worker_commands_cb(gras_msg_cb_ctx_t ctx, void *payload) +{ worker_data_t g = gras_userdata_get(); - g->commands = *(xbt_dynar_t*)payload; + g->commands = *(xbt_dynar_t *) payload; return 0; } -static void do_command(int rank, void*c) { + +static void do_command(int rank, void *c) +{ xbt_ex_t e; - xbt_workload_elm_t cmd = *(xbt_workload_elm_t*)c; + xbt_workload_elm_t cmd = *(xbt_workload_elm_t *) c; xbt_workload_data_chunk_t chunk; if (cmd->action == XBT_WORKLOAD_SEND) { gras_socket_t sock = get_peer_sock(cmd->str_arg); - chunk = xbt_workload_data_chunk_new((int)(cmd->d_arg)); - INFO4("Send %.f bytes to %s %s:%d",cmd->d_arg,cmd->str_arg, - gras_socket_peer_name(sock),gras_socket_peer_port(sock)); - gras_msg_send_(sock,gras_msgtype_by_name("chunk"),&chunk); - INFO2("Done sending %.f bytes to %s",cmd->d_arg,cmd->str_arg); + chunk = xbt_workload_data_chunk_new((int) (cmd->d_arg)); + INFO4("Send %.f bytes to %s %s:%d", cmd->d_arg, cmd->str_arg, + gras_socket_peer_name(sock), gras_socket_peer_port(sock)); + gras_msg_send_(sock, gras_msgtype_by_name("chunk"), &chunk); + INFO2("Done sending %.f bytes to %s", cmd->d_arg, cmd->str_arg); } else if (cmd->action == XBT_WORKLOAD_RECV) { - INFO2("Recv %.f bytes from %s",cmd->d_arg,cmd->str_arg); + INFO2("Recv %.f bytes from %s", cmd->d_arg, cmd->str_arg); TRY { - gras_msg_wait(1000000,"chunk",NULL,&chunk); - } CATCH(e) { + gras_msg_wait(1000000, "chunk", NULL, &chunk); + } + CATCH(e) { SIMIX_display_process_status(); RETHROW2("Exception while waiting for %f bytes from %s: %s", - cmd->d_arg,cmd->str_arg); + cmd->d_arg, cmd->str_arg); } xbt_workload_data_chunk_free(chunk); - INFO2("Done receiving %.f bytes from %s",cmd->d_arg,cmd->str_arg); + INFO2("Done receiving %.f bytes from %s", cmd->d_arg, cmd->str_arg); } else { - xbt_die(bprintf("unknown command: %s",xbt_workload_elm_to_string(cmd))); + xbt_die(bprintf + ("unknown command: %s", xbt_workload_elm_to_string(cmd))); } } -int worker(int argc,char *argv[]) { + +int worker(int argc, char *argv[]) +{ xbt_ex_t e; worker_data_t globals; - gras_init(&argc,argv); + gras_init(&argc, argv); declare_msg(); globals = gras_userdata_new(s_worker_data_t); /* Create the connexions */ - globals->mysock = gras_socket_server(4000); /* FIXME: shouldn't be hardcoded */ - gras_socket_t master=NULL; - int connected=0; + globals->mysock = gras_socket_server(4000); /* FIXME: shouldn't be hardcoded */ + gras_socket_t master = NULL; + int connected = 0; gras_cb_register("commands", worker_commands_cb); - globals->peers=xbt_dict_new(); + globals->peers = xbt_dict_new(); if (gras_if_RL()) - INFO2("Sensor %s starting. Connecting to master on %s", gras_os_myname(), argv[1]); + INFO2("Sensor %s starting. Connecting to master on %s", + gras_os_myname(), argv[1]); while (!connected) { xbt_ex_t e; TRY { @@ -208,57 +224,60 @@ int worker(int argc,char *argv[]) { } /* Join and run the group */ amok_pm_group_join(master, "replay", -1); - gras_msg_handle(60); // command message - gras_msg_wait(60,"go",NULL,NULL); + gras_msg_handle(60); // command message + gras_msg_wait(60, "go", NULL, NULL); { worker_data_t g = gras_userdata_get(); unsigned int cursor; xbt_workload_elm_t cmd; - const char *myname=gras_os_myname(); - xbt_dynar_t cmd_to_go = xbt_dynar_new(sizeof(xbt_workload_elm_t),NULL); + const char *myname = gras_os_myname(); + xbt_dynar_t cmd_to_go = + xbt_dynar_new(sizeof(xbt_workload_elm_t), NULL); - xbt_dynar_foreach(g->commands,cursor,cmd) { - if (!strcmp(cmd->who,myname)) { + xbt_dynar_foreach(g->commands, cursor, cmd) { + if (!strcmp(cmd->who, myname)) { char *c = xbt_workload_elm_to_string(cmd); - // INFO1("TODO: %s",c); + // INFO1("TODO: %s",c); free(c); switch (cmd->action) { case XBT_WORKLOAD_COMPUTE: /* If any communication were queued, do them in parallel */ - if (xbt_dynar_length(cmd_to_go)){ + if (xbt_dynar_length(cmd_to_go)) { TRY { - xbt_dynar_dopar(cmd_to_go,do_command); + xbt_dynar_dopar(cmd_to_go, do_command); xbt_dynar_reset(cmd_to_go); - } CATCH(e) { + } + CATCH(e) { SIMIX_display_process_status(); } INFO0("Communications all done"); xbt_dynar_reset(cmd_to_go); } - INFO1("Compute %.f flops",cmd->d_arg); + INFO1("Compute %.f flops", cmd->d_arg); gras_cpu_burn(cmd->d_arg); - INFO1("Done computing %.f flops",cmd->d_arg); + INFO1("Done computing %.f flops", cmd->d_arg); break; case XBT_WORKLOAD_SEND: /* Create the socket from main thread since it seems to fails when done from dopar thread */ get_peer_sock(cmd->str_arg); case XBT_WORKLOAD_RECV: /* queue communications for later realization in parallel */ - xbt_dynar_push(cmd_to_go,&cmd); + xbt_dynar_push(cmd_to_go, &cmd); break; } } } /* do in parallel any communication still queued */ - INFO1("Do %ld pending communications after end of TODO list",xbt_dynar_length(cmd_to_go)); - if (xbt_dynar_length(cmd_to_go)){ - xbt_dynar_dopar(cmd_to_go,do_command); + INFO1("Do %ld pending communications after end of TODO list", + xbt_dynar_length(cmd_to_go)); + if (xbt_dynar_length(cmd_to_go)) { + xbt_dynar_dopar(cmd_to_go, do_command); xbt_dynar_reset(cmd_to_go); } } - gras_msg_send(master,"go",NULL); + gras_msg_send(master, "go", NULL); // amok_pm_group_leave(master, "replay"); gras_socket_close(globals->mysock); diff --git a/examples/gras/replay/workload.h b/examples/gras/replay/workload.h index 46dcd8345f..2d4372d7a1 100644 --- a/examples/gras/replay/workload.h +++ b/examples/gras/replay/workload.h @@ -24,19 +24,20 @@ typedef struct { /* keep it in sync with function xbt_workload_declare_datadesc() */ - char *who; /* the slave who should do it */ - char *comment; /* a comment placed at the end of the line, if any */ - int action; /* 0: compute(darg flops); 1: send darg bytes to strarg; 2: recv darg bytes from strarg */ - double date; /* when it occured when the trace was captured */ - double d_arg; /* double argument, if any */ - char * str_arg; /* string argument, if any */ + char *who; /* the slave who should do it */ + char *comment; /* a comment placed at the end of the line, if any */ + int action; /* 0: compute(darg flops); 1: send darg bytes to strarg; 2: recv darg bytes from strarg */ + double date; /* when it occured when the trace was captured */ + double d_arg; /* double argument, if any */ + char *str_arg; /* string argument, if any */ } s_xbt_workload_elm_t, *xbt_workload_elm_t; XBT_PUBLIC(xbt_workload_elm_t) xbt_workload_elm_parse(char *line); XBT_PUBLIC(void) xbt_workload_elm_free(xbt_workload_elm_t cmd); -XBT_PUBLIC(void) xbt_workload_elm_free_voidp(void*cmd); -XBT_PUBLIC(char *)xbt_workload_elm_to_string(xbt_workload_elm_t cmd); -XBT_PUBLIC(int) xbt_workload_elm_cmp_who_date(const void* _c1, const void* _c2); +XBT_PUBLIC(void) xbt_workload_elm_free_voidp(void *cmd); +XBT_PUBLIC(char *) xbt_workload_elm_to_string(xbt_workload_elm_t cmd); +XBT_PUBLIC(int) xbt_workload_elm_cmp_who_date(const void *_c1, + const void *_c2); XBT_PUBLIC(void) xbt_workload_sort_who_date(xbt_dynar_t c); XBT_PUBLIC(xbt_dynar_t) xbt_workload_parse_file(char *filename); @@ -46,8 +47,9 @@ XBT_PUBLIC(void) xbt_workload_declare_datadesc(void); typedef struct { int size; char *chunk; -} s_xbt_workload_data_chunk_t,*xbt_workload_data_chunk_t; -XBT_PUBLIC(xbt_workload_data_chunk_t) xbt_workload_data_chunk_new(int size); +} s_xbt_workload_data_chunk_t, *xbt_workload_data_chunk_t; +XBT_PUBLIC(xbt_workload_data_chunk_t) xbt_workload_data_chunk_new(int + size); XBT_PUBLIC(void) xbt_workload_data_chunk_free(xbt_workload_data_chunk_t c); -#endif /* XBT_WORKLOAD_H_ */ +#endif /* XBT_WORKLOAD_H_ */ diff --git a/examples/gras/replay/xbt_workload.c b/examples/gras/replay/xbt_workload.c index 46a9e4bdb7..769d8b53a2 100644 --- a/examples/gras/replay/xbt_workload.c +++ b/examples/gras/replay/xbt_workload.c @@ -15,17 +15,19 @@ #include "workload.h" #include "gras/datadesc.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_workload,xbt, "Workload characterisation mecanisms"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_workload, xbt, + "Workload characterisation mecanisms"); -xbt_workload_elm_t xbt_workload_elm_parse(char *line) { - xbt_workload_elm_t res = xbt_new(s_xbt_workload_elm_t,1); - res->date=-1; - res->comment=NULL; /* it's not enough to memset for valgrind, apparently */ - res->who=NULL; - res->str_arg=NULL; +xbt_workload_elm_t xbt_workload_elm_parse(char *line) +{ + xbt_workload_elm_t res = xbt_new(s_xbt_workload_elm_t, 1); + res->date = -1; + res->comment = NULL; /* it's not enough to memset for valgrind, apparently */ + res->who = NULL; + res->str_arg = NULL; - xbt_dynar_t w = xbt_str_split(line," "); + xbt_dynar_t w = xbt_str_split(line, " "); if (xbt_dynar_length(w) == 0) { free(res); @@ -33,38 +35,40 @@ xbt_workload_elm_t xbt_workload_elm_parse(char *line) { return NULL; } - char **words = xbt_dynar_get_ptr(w,0); - int i=0; + char **words = xbt_dynar_get_ptr(w, 0); + int i = 0; if (words[i][0] == '[') { - sscanf(words[i]+1,"%lg",&(res->date)); + sscanf(words[i] + 1, "%lg", &(res->date)); i++; } res->who = xbt_strdup(words[i++]); - if (!strcmp(words[i],"recv")) { + if (!strcmp(words[i], "recv")) { res->action = XBT_WORKLOAD_RECV; res->str_arg = xbt_strdup(words[++i]); - sscanf(words[++i],"%lg",&(res->d_arg)); + sscanf(words[++i], "%lg", &(res->d_arg)); - } else if (!strcmp(words[i],"send")) { + } else if (!strcmp(words[i], "send")) { res->action = XBT_WORKLOAD_SEND; res->str_arg = xbt_strdup(words[++i]); - sscanf(words[++i],"%lg",&(res->d_arg)); + sscanf(words[++i], "%lg", &(res->d_arg)); - } else if (!strcmp(words[i],"compute")) { + } else if (!strcmp(words[i], "compute")) { res->action = XBT_WORKLOAD_COMPUTE; - sscanf(words[++i],"%lg",&(res->d_arg)); + sscanf(words[++i], "%lg", &(res->d_arg)); } else { - xbt_die(bprintf("Unparsable command: %s (in %s)",words[i],line)); + xbt_die(bprintf("Unparsable command: %s (in %s)", words[i], line)); } i++; if (words[i] && words[i][0] == '#') { - res->comment = xbt_strdup(strchr(line,'#')+1); + res->comment = xbt_strdup(strchr(line, '#') + 1); } xbt_dynar_free(&w); return res; } -void xbt_workload_elm_free(xbt_workload_elm_t cmd) { + +void xbt_workload_elm_free(xbt_workload_elm_t cmd) +{ if (!cmd) return; if (cmd->who) @@ -75,55 +79,65 @@ void xbt_workload_elm_free(xbt_workload_elm_t cmd) { free(cmd->str_arg); free(cmd); } -void xbt_workload_elm_free_voidp(void*cmd) { - xbt_workload_elm_free(*(xbt_workload_elm_t*)cmd); + +void xbt_workload_elm_free_voidp(void *cmd) +{ + xbt_workload_elm_free(*(xbt_workload_elm_t *) cmd); } -char *xbt_workload_elm_to_string(xbt_workload_elm_t cmd) { +char *xbt_workload_elm_to_string(xbt_workload_elm_t cmd) +{ char res[2048]; char *addon; - res[0]='\0'; - if (cmd==NULL) + res[0] = '\0'; + if (cmd == NULL) return xbt_strdup("(null command)"); if (cmd->date != -1) { - addon=bprintf("[%f] ",cmd->date); - strcat(res,addon); + addon = bprintf("[%f] ", cmd->date); + strcat(res, addon); free(addon); } - addon= bprintf("'%s' ",cmd->who); - strcat(res,addon);free(addon); + addon = bprintf("'%s' ", cmd->who); + strcat(res, addon); + free(addon); switch (cmd->action) { case XBT_WORKLOAD_COMPUTE: - addon=bprintf("computed %f flops",cmd->d_arg); - strcat(res,addon);free(addon); + addon = bprintf("computed %f flops", cmd->d_arg); + strcat(res, addon); + free(addon); break; case XBT_WORKLOAD_SEND: - addon=bprintf("sent %f bytes to '%s'",cmd->d_arg,cmd->str_arg); - strcat(res,addon);free(addon); + addon = bprintf("sent %f bytes to '%s'", cmd->d_arg, cmd->str_arg); + strcat(res, addon); + free(addon); break; case XBT_WORKLOAD_RECV: - addon=bprintf("received %f bytes from '%s'",cmd->d_arg,cmd->str_arg); - strcat(res,addon);free(addon); + addon = + bprintf("received %f bytes from '%s'", cmd->d_arg, cmd->str_arg); + strcat(res, addon); + free(addon); break; default: - xbt_die(bprintf("Unknown command %d in '%s...'",cmd->action,res)); + xbt_die(bprintf("Unknown command %d in '%s...'", cmd->action, res)); } if (cmd->comment) { - addon=bprintf(" (comment: %s)",cmd->comment); - strcat(res,addon);free(addon); + addon = bprintf(" (comment: %s)", cmd->comment); + strcat(res, addon); + free(addon); } return xbt_strdup(res); } -int xbt_workload_elm_cmp_who_date(const void* _c1, const void* _c2) { - xbt_workload_elm_t c1=*(xbt_workload_elm_t*)_c1; - xbt_workload_elm_t c2=*(xbt_workload_elm_t*)_c2; +int xbt_workload_elm_cmp_who_date(const void *_c1, const void *_c2) +{ + xbt_workload_elm_t c1 = *(xbt_workload_elm_t *) _c1; + xbt_workload_elm_t c2 = *(xbt_workload_elm_t *) _c2; if (!c1 || !c1->who) return -1; if (!c2 || !c2->who) return 1; - int r = strcmp(c1->who,c2->who); + int r = strcmp(c1->who, c2->who); if (r) return r; if (c1->date == c2->date) @@ -132,64 +146,81 @@ int xbt_workload_elm_cmp_who_date(const void* _c1, const void* _c2) { return -1; return 1; } -void xbt_workload_sort_who_date(xbt_dynar_t c) { - qsort(xbt_dynar_get_ptr(c,0),xbt_dynar_length(c),sizeof(xbt_workload_elm_t),xbt_workload_elm_cmp_who_date); + +void xbt_workload_sort_who_date(xbt_dynar_t c) +{ + qsort(xbt_dynar_get_ptr(c, 0), xbt_dynar_length(c), + sizeof(xbt_workload_elm_t), xbt_workload_elm_cmp_who_date); } -xbt_dynar_t xbt_workload_parse_file(char *filename) { + +xbt_dynar_t xbt_workload_parse_file(char *filename) +{ FILE *file_in; - file_in = fopen(filename,"r"); - xbt_assert1(file_in, "cannot open tracefile '%s'",filename); + file_in = fopen(filename, "r"); + xbt_assert1(file_in, "cannot open tracefile '%s'", filename); char *str_in = xbt_str_from_file(file_in); fclose(file_in); - xbt_dynar_t in = xbt_str_split(str_in,"\n"); + xbt_dynar_t in = xbt_str_split(str_in, "\n"); free(str_in); - xbt_dynar_t cmds=xbt_dynar_new(sizeof(xbt_workload_elm_t),xbt_workload_elm_free_voidp); + xbt_dynar_t cmds = + xbt_dynar_new(sizeof(xbt_workload_elm_t), + xbt_workload_elm_free_voidp); unsigned int cursor; char *line; - xbt_dynar_foreach(in,cursor,line) { + xbt_dynar_foreach(in, cursor, line) { xbt_workload_elm_t cmd = xbt_workload_elm_parse(line); if (cmd) - xbt_dynar_push(cmds,&cmd); + xbt_dynar_push(cmds, &cmd); } - xbt_dynar_shrink(cmds,0); + xbt_dynar_shrink(cmds, 0); xbt_dynar_free(&in); return cmds; } -void xbt_workload_declare_datadesc(void) { +void xbt_workload_declare_datadesc(void) +{ gras_datadesc_type_t ddt; ddt = gras_datadesc_struct("s_xbt_workload_elm_t"); - gras_datadesc_struct_append(ddt,"who",gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt,"comment",gras_datadesc_by_name("string")); - gras_datadesc_struct_append(ddt,"action",gras_datadesc_by_name("int")); - gras_datadesc_struct_append(ddt,"date",gras_datadesc_by_name("double")); - gras_datadesc_struct_append(ddt,"d_arg",gras_datadesc_by_name("double")); - gras_datadesc_struct_append(ddt,"str_arg",gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt, "who", gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt, "comment", + gras_datadesc_by_name("string")); + gras_datadesc_struct_append(ddt, "action", gras_datadesc_by_name("int")); + gras_datadesc_struct_append(ddt, "date", + gras_datadesc_by_name("double")); + gras_datadesc_struct_append(ddt, "d_arg", + gras_datadesc_by_name("double")); + gras_datadesc_struct_append(ddt, "str_arg", + gras_datadesc_by_name("string")); gras_datadesc_struct_close(ddt); - gras_datadesc_ref("xbt_workload_elm_t",ddt); + gras_datadesc_ref("xbt_workload_elm_t", ddt); ddt = gras_datadesc_struct("s_xbt_workload_data_chunk_t"); - gras_datadesc_struct_append(ddt,"size",gras_datadesc_by_name("int")); + gras_datadesc_struct_append(ddt, "size", gras_datadesc_by_name("int")); gras_datadesc_cb_field_push(ddt, "size"); - gras_datadesc_struct_append(ddt,"chunk",gras_datadesc_ref_pop_arr(gras_datadesc_by_name("char"))); + gras_datadesc_struct_append(ddt, "chunk", + gras_datadesc_ref_pop_arr + (gras_datadesc_by_name("char"))); gras_datadesc_struct_close(ddt); - gras_datadesc_ref("xbt_workload_data_chunk_t",ddt); + gras_datadesc_ref("xbt_workload_data_chunk_t", ddt); } -xbt_workload_data_chunk_t xbt_workload_data_chunk_new(int size) { - xbt_workload_data_chunk_t res = xbt_new0(s_xbt_workload_data_chunk_t,1); - res->size = size-sizeof(res)-sizeof(int); - res->chunk = xbt_new(char,res->size); +xbt_workload_data_chunk_t xbt_workload_data_chunk_new(int size) +{ + xbt_workload_data_chunk_t res = xbt_new0(s_xbt_workload_data_chunk_t, 1); + res->size = size - sizeof(res) - sizeof(int); + res->chunk = xbt_new(char, res->size); return res; } -void xbt_workload_data_chunk_free(xbt_workload_data_chunk_t c) { + +void xbt_workload_data_chunk_free(xbt_workload_data_chunk_t c) +{ free(c->chunk); free(c); } diff --git a/examples/gras/rpc/rpc.c b/examples/gras/rpc/rpc.c index f4ee78f76a..ae7f548145 100644 --- a/examples/gras/rpc/rpc.c +++ b/examples/gras/rpc/rpc.c @@ -145,7 +145,7 @@ int client(int argc, char *argv[]) xbt_assert1(!strncmp(e.msg, exception_msg, strlen(exception_msg)), "Got wrong message: %s", e.msg); INFO0 - ("Got the expected exception when calling the exception raising RPC"); + ("Got the expected exception when calling the exception raising RPC"); xbt_ex_free(e); } @@ -176,7 +176,8 @@ int client(int argc, char *argv[]) for (i = 0; i < 5; i++) { INFO1("Call the exception raising RPC on the forwarder (i=%d)", i); TRY { - gras_msg_rpccall(toforwarder, 6000.0, "forward exception", NULL, NULL); + gras_msg_rpccall(toforwarder, 6000.0, "forward exception", NULL, + NULL); } CATCH(e) { gotit = 1; @@ -191,7 +192,7 @@ int client(int argc, char *argv[]) "Got wrong category: %d (instead of %d)", e.category, unknown_error); INFO0 - ("Got the expected exception when calling the exception raising RPC"); + ("Got the expected exception when calling the exception raising RPC"); xbt_ex_free(e); exception_catching(); } @@ -231,7 +232,8 @@ static int forwarder_cb_kill(gras_msg_cb_ctx_t ctx, void *payload_data) return 0; } -static int forwarder_cb_forward_ex(gras_msg_cb_ctx_t ctx, void *payload_data) +static int forwarder_cb_forward_ex(gras_msg_cb_ctx_t ctx, + void *payload_data) { forward_data_t fdata = gras_userdata_get(); @@ -313,7 +315,8 @@ static int server_cb_ping(gras_msg_cb_ctx_t ctx, void *payload_data) /* 2. Log which client connected */ INFO3("Got message PING(%d) from %s:%d", msg, - gras_socket_peer_name(expeditor), gras_socket_peer_port(expeditor)); + gras_socket_peer_name(expeditor), + gras_socket_peer_port(expeditor)); /* 4. Change the value of the msg variable */ msg = 4321; diff --git a/examples/gras/spawn/spawn_child.c b/examples/gras/spawn/spawn_child.c index 3098ffd823..acc35238e8 100644 --- a/examples/gras/spawn/spawn_child.c +++ b/examples/gras/spawn/spawn_child.c @@ -62,7 +62,8 @@ int child(int argc, char *argv[]) gras_socket_close(dady); RETHROW0("Dad don't want to speak with me! : %s"); } - INFO2("Pinged dad with %d, he answered with %d; leaving now.", ping, pong); + INFO2("Pinged dad with %d, he answered with %d; leaving now.", ping, + pong); /* 7. Free the allocated resources, and shut GRAS down */ gras_socket_close(dady); diff --git a/examples/gras/spawn/spawn_father.c b/examples/gras/spawn/spawn_father.c index edf1fa2002..12cc6ae76a 100644 --- a/examples/gras/spawn/spawn_father.c +++ b/examples/gras/spawn/spawn_father.c @@ -46,7 +46,8 @@ static int father_cb_ping_handler(gras_msg_cb_ctx_t ctx, void *payload) RETHROW0("Unable to answer to my poor child: %s"); } INFO2("Answered to %s:%d's request", - gras_socket_peer_name(expeditor), gras_socket_peer_port(expeditor)); + gras_socket_peer_name(expeditor), + gras_socket_peer_port(expeditor)); /* 7. Tell GRAS that we consummed this message */ return 0; diff --git a/examples/gras/synchro/philosopher.c b/examples/gras/synchro/philosopher.c index 96a653fdc2..d4debb26d1 100644 --- a/examples/gras/synchro/philosopher.c +++ b/examples/gras/synchro/philosopher.c @@ -29,14 +29,14 @@ static void pickup(int id, int lunch) { INFO2("Thread %d gets hungry (lunch #%d)", id, lunch); xbt_mutex_acquire(mutex); - while (state[(id + (philosopher_amount - 1)) % philosopher_amount] == EATING - || state[(id + 1) % philosopher_amount] == EATING) { + while (state[(id + (philosopher_amount - 1)) % philosopher_amount] == + EATING || state[(id + 1) % philosopher_amount] == EATING) { xbt_cond_wait(forks[id], mutex); } state[id] = EATING; - xbt_assert1(state[(id + (philosopher_amount - 1)) % philosopher_amount] == - THINKING + xbt_assert1(state[(id + (philosopher_amount - 1)) % philosopher_amount] + == THINKING && state[(id + 1) % philosopher_amount] == THINKING, "Philosopher %d eats at the same time that one of its neighbors!!!", id); @@ -87,8 +87,8 @@ static void philo_thread(void *arg) /* Enter an endless loop to test the killing facilities */ INFO1 - ("Thread %d tries to enter the dead-end; hopefully, the master will cancel it", - id); + ("Thread %d tries to enter the dead-end; hopefully, the master will cancel it", + id); xbt_mutex_acquire(dead_end); INFO1("Oops, thread %d reached the dead-end. Cancelation failed", id); } @@ -129,7 +129,9 @@ int philosopher(int argc, char *argv[]) /* spawn threads */ for (i = 0; i < philosopher_amount; i++) { char *name = bprintf("thread %d", i); - philosophers[i] = xbt_thread_create(name, philo_thread, &id[i],0/*not joinable*/); + philosophers[i] = + xbt_thread_create(name, philo_thread, &id[i], + 0 /*not joinable */ ); free(name); } diff --git a/examples/gras/timer/timer.c b/examples/gras/timer/timer.c index 9c1aab5db7..18d52a1b22 100644 --- a/examples/gras/timer/timer.c +++ b/examples/gras/timer/timer.c @@ -35,8 +35,9 @@ static void repetitive_action(void) gras_timer_cancel_repeat(REPEAT_INTERVAL, repetitive_action); } - INFO1("repetitive_action decrementing globals->still_to_do. New value: %d", - globals->still_to_do - 1); + INFO1 + ("repetitive_action decrementing globals->still_to_do. New value: %d", + globals->still_to_do - 1); globals->still_to_do--; /* should be the last line of the action since value=0 stops the program */ } /* end_of_repetitive_action */ @@ -71,7 +72,8 @@ int client(int argc, char *argv[]) INFO0("Canceling the delayed_action."); gras_timer_cancel_delay(REPEAT_INTERVAL, delayed_action); - INFO1("Re-programming the delayed_action for after %f sec", DELAY_INTERVAL); + INFO1("Re-programming the delayed_action for after %f sec", + DELAY_INTERVAL); gras_timer_delay(REPEAT_INTERVAL, delayed_action); while (globals->still_to_do == -1 || /* Before delayed action runs */ diff --git a/examples/msg/actions/actions.c b/examples/msg/actions/actions.c index 02fcb18eac..5ab23f0759 100644 --- a/examples/msg/actions/actions.c +++ b/examples/msg/actions/actions.c @@ -12,23 +12,24 @@ #include "simgrid_config.h" /* getline */ XBT_LOG_NEW_DEFAULT_CATEGORY(actions, - "Messages specific for this msg example"); -int communicator_size=0; + "Messages specific for this msg example"); +int communicator_size = 0; -typedef struct coll_ctr_t{ +typedef struct coll_ctr_t { int bcast_counter; int reduce_counter; int allReduce_counter; } *coll_ctr; /* Helper function */ -static double parse_double(const char *string) { +static double parse_double(const char *string) +{ double value; char *endptr; - value=strtod(string, &endptr); + value = strtod(string, &endptr); if (*endptr != '\0') - THROW1(unknown_error, 0, "%s is not a double", string); + THROW1(unknown_error, 0, "%s is not a double", string); return value; } @@ -40,28 +41,28 @@ static void action_send(xbt_dynar_t action) char to[250]; char *size = xbt_dynar_get_as(action, 3, char *); double clock = MSG_get_clock(); - sprintf (to,"%s_%s", MSG_process_get_name(MSG_process_self()), - xbt_dynar_get_as(action, 2, char *)); + sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), + xbt_dynar_get_as(action, 2, char *)); // char *to = xbt_dynar_get_as(action, 2, char *); - if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(actions, xbt_log_priority_debug)) name = xbt_str_join(action, " "); DEBUG2("Entering Send: %s (size: %lg)", name, parse_double(size)); MSG_task_send(MSG_task_create(name, 0, parse_double(size), NULL), to); - DEBUG2("%s %f", name, MSG_get_clock()-clock); + DEBUG2("%s %f", name, MSG_get_clock() - clock); - if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(actions, xbt_log_priority_debug)) free(name); } static int spawned_send(int argc, char *argv[]) { - DEBUG3("%s: Sending %s on %s", MSG_process_get_name(MSG_process_self()), - argv[1],argv[0]); - MSG_task_send(MSG_task_create(argv[0], 0, parse_double(argv[1]), NULL), - argv[0]); + DEBUG3("%s: Sending %s on %s", MSG_process_get_name(MSG_process_self()), + argv[1], argv[0]); + MSG_task_send(MSG_task_create(argv[0], 0, parse_double(argv[1]), NULL), + argv[0]); return 0; } @@ -74,47 +75,47 @@ static void Isend(xbt_dynar_t action) char **myargv; m_process_t comm_helper; double clock = MSG_get_clock(); - DEBUG1("Isend on %s: spawn process ", - MSG_process_get_name(MSG_process_self())); + DEBUG1("Isend on %s: spawn process ", + MSG_process_get_name(MSG_process_self())); + + sprintf(to, "%s_%s", MSG_process_get_name(MSG_process_self()), + xbt_dynar_get_as(action, 2, char *)); + myargv = (char **) calloc(3, sizeof(char *)); - sprintf (to,"%s_%s", MSG_process_get_name(MSG_process_self()), - xbt_dynar_get_as(action, 2, char *)); - myargv = (char**) calloc (3, sizeof (char*)); - myargv[0] = xbt_strdup(to); myargv[1] = xbt_strdup(size); myargv[2] = NULL; // sprintf(spawn_name,"%s_wait",MSG_process_get_name(MSG_process_self())); - sprintf(spawn_name,"%s_wait",to); + sprintf(spawn_name, "%s_wait", to); comm_helper = - MSG_process_create_with_arguments(spawn_name, spawned_send, - NULL, MSG_host_self(), 2, myargv); - DEBUG2("%s %f",xbt_str_join(action, " "), MSG_get_clock()-clock); + MSG_process_create_with_arguments(spawn_name, spawned_send, + NULL, MSG_host_self(), 2, myargv); + DEBUG2("%s %f", xbt_str_join(action, " "), MSG_get_clock() - clock); } static void action_recv(xbt_dynar_t action) { char *name = NULL; - char mailbox_name[250]; + char mailbox_name[250]; m_task_t task = NULL; double clock = MSG_get_clock(); //FIXME: argument of action ignored so far; semantic not clear //char *from=xbt_dynar_get_as(action,2,char*); - sprintf (mailbox_name,"%s_%s", xbt_dynar_get_as(action, 2, char *), - MSG_process_get_name(MSG_process_self())); + sprintf(mailbox_name, "%s_%s", xbt_dynar_get_as(action, 2, char *), + MSG_process_get_name(MSG_process_self())); - if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(actions, xbt_log_priority_debug)) name = xbt_str_join(action, " "); DEBUG1("Receiving: %s", name); MSG_task_receive(&task, mailbox_name); // MSG_task_receive(&task, MSG_process_get_name(MSG_process_self())); - DEBUG2("%s %f", name, MSG_get_clock()-clock); + DEBUG2("%s %f", name, MSG_get_clock() - clock); MSG_task_destroy(task); - if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(actions, xbt_log_priority_debug)) free(name); } @@ -125,9 +126,9 @@ static int spawned_recv(int argc, char *argv[]) MSG_task_receive(&task, argv[0]); DEBUG1("Received %s", MSG_task_get_name(task)); DEBUG1("waiter on %s", MSG_process_get_name(MSG_process_self())); - MSG_task_send(MSG_task_create("waiter",0,0,NULL), - MSG_process_get_name(MSG_process_self())); - + MSG_task_send(MSG_task_create("waiter", 0, 0, NULL), + MSG_process_get_name(MSG_process_self())); + MSG_task_destroy(task); return 0; } @@ -140,23 +141,22 @@ static void Irecv(xbt_dynar_t action) char mailbox_name[250]; char **myargv; double clock = MSG_get_clock(); - DEBUG1("Irecv on %s: spawn process ", - MSG_process_get_name(MSG_process_self())); - - sprintf (mailbox_name,"%s_%s", xbt_dynar_get_as(action, 2, char *), - MSG_process_get_name(MSG_process_self())); - name = bprintf("%s_wait",MSG_process_get_name(MSG_process_self())); - myargv = (char**) calloc (2, sizeof (char*)); - + DEBUG1("Irecv on %s: spawn process ", + MSG_process_get_name(MSG_process_self())); + + sprintf(mailbox_name, "%s_%s", xbt_dynar_get_as(action, 2, char *), + MSG_process_get_name(MSG_process_self())); + name = bprintf("%s_wait", MSG_process_get_name(MSG_process_self())); + myargv = (char **) calloc(2, sizeof(char *)); + myargv[0] = xbt_strdup(mailbox_name); myargv[1] = NULL; - comm_helper = MSG_process_create_with_arguments(name,spawned_recv, - NULL, MSG_host_self(), - 1, myargv); + comm_helper = MSG_process_create_with_arguments(name, spawned_recv, + NULL, MSG_host_self(), + 1, myargv); + + DEBUG2("%s %f", xbt_str_join(action, " "), MSG_get_clock() - clock); - DEBUG2("%s %f", xbt_str_join(action, " "), - MSG_get_clock()-clock); - free(name); } @@ -167,44 +167,44 @@ static void action_wait(xbt_dynar_t action) char task_name[80]; m_task_t task = NULL; double clock = MSG_get_clock(); - - if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) + + if (XBT_LOG_ISENABLED(actions, xbt_log_priority_debug)) name = xbt_str_join(action, " "); DEBUG1("Entering %s", name); - sprintf(task_name,"%s_wait",MSG_process_get_name(MSG_process_self())); + sprintf(task_name, "%s_wait", MSG_process_get_name(MSG_process_self())); DEBUG1("wait: %s", task_name); - MSG_task_receive(&task,task_name); + MSG_task_receive(&task, task_name); MSG_task_destroy(task); - DEBUG2("%s %f", name, MSG_get_clock()-clock); - if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) + DEBUG2("%s %f", name, MSG_get_clock() - clock); + if (XBT_LOG_ISENABLED(actions, xbt_log_priority_debug)) free(name); } /* FIXME: that's a poor man's implementation: we should take the message exchanges into account */ -smx_sem_t barrier_semaphore=NULL; -static void barrier (xbt_dynar_t action) +smx_sem_t barrier_semaphore = NULL; +static void barrier(xbt_dynar_t action) { char *name = NULL; - if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(actions, xbt_log_priority_debug)) name = xbt_str_join(action, " "); DEBUG1("Entering barrier: %s", name); - if (barrier_semaphore == NULL) // first arriving on the barrier + if (barrier_semaphore == NULL) // first arriving on the barrier barrier_semaphore = SIMIX_sem_init(0); - if (SIMIX_sem_get_capacity(barrier_semaphore)==-communicator_size +1) { // last arriving + if (SIMIX_sem_get_capacity(barrier_semaphore) == -communicator_size + 1) { // last arriving SIMIX_sem_release_forever(barrier_semaphore); SIMIX_sem_destroy(barrier_semaphore); barrier_semaphore = NULL; - } else { // not last + } else { // not last SIMIX_sem_acquire(barrier_semaphore); } DEBUG1("Exiting barrier: %s", name); - if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) + if (XBT_LOG_ISENABLED(actions, xbt_log_priority_debug)) free(name); } @@ -218,129 +218,130 @@ static void reduce(xbt_dynar_t action) char **myargv; char *comm_size = xbt_dynar_get_as(action, 2, char *); char *comp_size = xbt_dynar_get_as(action, 3, char *); - m_process_t comm_helper=NULL; - m_task_t task=NULL, comp_task=NULL; - const char* process_name; + m_process_t comm_helper = NULL; + m_task_t task = NULL, comp_task = NULL; + const char *process_name; double clock = MSG_get_clock(); - - coll_ctr counters = (coll_ctr) MSG_process_get_data(MSG_process_self()); + + coll_ctr counters = (coll_ctr) MSG_process_get_data(MSG_process_self()); xbt_assert0(communicator_size, "Size of Communicator is not defined" - ", can't use collective operations"); + ", can't use collective operations"); process_name = MSG_process_get_name(MSG_process_self()); - if (!counters){ + if (!counters) { DEBUG0("Initialize the counters"); - counters = (coll_ctr) calloc (1, sizeof(struct coll_ctr_t)); + counters = (coll_ctr) calloc(1, sizeof(struct coll_ctr_t)); } name = bprintf("reduce_%d", counters->reduce_counter++); - if (!strcmp(process_name, "p0")){ - DEBUG2("%s: %s is the Root",name, process_name); - for(i=1;ibcast_counter++); - if (!strcmp(process_name, "p0")){ - DEBUG2("%s: %s is the Root",name, process_name); + if (!strcmp(process_name, "p0")) { + DEBUG2("%s: %s is the Root", name, process_name); - for(i=1;iallReduce_counter++); - if (!strcmp(process_name, "p0")){ - DEBUG2("%s: %s is the Root",name, process_name); - for(i=1;i -#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ -#include "xbt/sysdep.h" /* calloc, printf */ +#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ +#include "xbt/sysdep.h" /* calloc, printf */ /* Create a log channel to have nice outputs. */ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); typedef enum { @@ -22,218 +23,220 @@ typedef enum { int master(int argc, char *argv[]); int slave(int argc, char *argv[]); int forwarder(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); -#define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */ +#define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */ /** Emitter function */ int master(int argc, char *argv[]) { - int alias_count = 0; - char** aliases = NULL; - m_task_t *todo = NULL; - int number_of_tasks = 0; - double task_comp_size = 0; - double task_comm_size = 0; - - - int i; - - xbt_assert1(sscanf(argv[1],"%d", &number_of_tasks),"Invalid argument %s\n",argv[1]); - xbt_assert1(sscanf(argv[2],"%lg", &task_comp_size),"Invalid argument %s\n",argv[2]); - xbt_assert1(sscanf(argv[3],"%lg", &task_comm_size),"Invalid argument %s\n",argv[3]); - - { - /* Task creation */ - char sprintf_buffer[64]; - - todo = xbt_new0(m_task_t,number_of_tasks); - - for (i = 0; i < number_of_tasks; i++) - { - sprintf(sprintf_buffer, "Task_%d", i); - todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); - } - } - - { - /* Process organisation */ - alias_count = argc - 4; - aliases = xbt_new0(char*,alias_count); - - for(i = 4; i < argc; i++) - { - aliases[i-4] = strdup(argv[i]); - } - } - - INFO2("Got %d aliases and %d tasks to process", alias_count,number_of_tasks); - - for (i = 0; i < alias_count; i++) - DEBUG1("%s", aliases[i]); - - for (i = 0; i < number_of_tasks; i++) - { - INFO2("Sending \"%s\" to \"%s\"",todo[i]->name,aliases[i % alias_count]); - - if(!strcmp(MSG_host_get_name(MSG_host_self()), aliases[i % alias_count])) - { - INFO0("Hey ! It's me ! :)"); - } - - MSG_task_send(todo[i], aliases[i % alias_count]); - INFO0("Sent"); - } - - INFO0("All tasks have been dispatched. Let's tell everybody the computation is over."); - - for (i = 0; i < alias_count; i++) - MSG_task_send(MSG_task_create("finalize", 0, 0, FINALIZE),aliases[i]); - - INFO0("Goodbye now!"); - - for(i = 0; i < alias_count; i++) - free(aliases[i]); - - free(aliases); - free(todo); - return 0; -} /* end_of_master */ + int alias_count = 0; + char **aliases = NULL; + m_task_t *todo = NULL; + int number_of_tasks = 0; + double task_comp_size = 0; + double task_comm_size = 0; + + + int i; + + xbt_assert1(sscanf(argv[1], "%d", &number_of_tasks), + "Invalid argument %s\n", argv[1]); + xbt_assert1(sscanf(argv[2], "%lg", &task_comp_size), + "Invalid argument %s\n", argv[2]); + xbt_assert1(sscanf(argv[3], "%lg", &task_comm_size), + "Invalid argument %s\n", argv[3]); + + { + /* Task creation */ + char sprintf_buffer[64]; + + todo = xbt_new0(m_task_t, number_of_tasks); + + for (i = 0; i < number_of_tasks; i++) { + sprintf(sprintf_buffer, "Task_%d", i); + todo[i] = + MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, + NULL); + } + } + + { + /* Process organisation */ + alias_count = argc - 4; + aliases = xbt_new0(char *, alias_count); + + for (i = 4; i < argc; i++) { + aliases[i - 4] = strdup(argv[i]); + } + } + + INFO2("Got %d aliases and %d tasks to process", alias_count, + number_of_tasks); + + for (i = 0; i < alias_count; i++) + DEBUG1("%s", aliases[i]); + + for (i = 0; i < number_of_tasks; i++) { + INFO2("Sending \"%s\" to \"%s\"", todo[i]->name, + aliases[i % alias_count]); + + if (!strcmp + (MSG_host_get_name(MSG_host_self()), aliases[i % alias_count])) { + INFO0("Hey ! It's me ! :)"); + } + + MSG_task_send(todo[i], aliases[i % alias_count]); + INFO0("Sent"); + } + + INFO0 + ("All tasks have been dispatched. Let's tell everybody the computation is over."); + + for (i = 0; i < alias_count; i++) + MSG_task_send(MSG_task_create("finalize", 0, 0, FINALIZE), aliases[i]); + + INFO0("Goodbye now!"); + + for (i = 0; i < alias_count; i++) + free(aliases[i]); + + free(aliases); + free(todo); + return 0; +} /* end_of_master */ /** Receiver function */ int slave(int argc, char *argv[]) { - m_task_t task = NULL; - int res; - - while(1) - { - res = MSG_task_receive(&(task), MSG_host_get_name(MSG_host_self())); - xbt_assert0(res == MSG_OK, "MSG_task_receive failed"); - - INFO1("Received \"%s\"", MSG_task_get_name(task)); - - if (!strcmp(MSG_task_get_name(task),"finalize")) - { - MSG_task_destroy(task); - break; - } - - INFO1("Processing \"%s\"", MSG_task_get_name(task)); - MSG_task_execute(task); - INFO1("\"%s\" done", MSG_task_get_name(task)); - MSG_task_destroy(task); - task = NULL; - } - - INFO0("I'm done. See you!"); - return 0; -} /* end_of_slave */ + m_task_t task = NULL; + int res; + + while (1) { + res = MSG_task_receive(&(task), MSG_host_get_name(MSG_host_self())); + xbt_assert0(res == MSG_OK, "MSG_task_receive failed"); + + INFO1("Received \"%s\"", MSG_task_get_name(task)); + + if (!strcmp(MSG_task_get_name(task), "finalize")) { + MSG_task_destroy(task); + break; + } + + INFO1("Processing \"%s\"", MSG_task_get_name(task)); + MSG_task_execute(task); + INFO1("\"%s\" done", MSG_task_get_name(task)); + MSG_task_destroy(task); + task = NULL; + } + + INFO0("I'm done. See you!"); + return 0; +} /* end_of_slave */ /** Forwarder function */ int forwarder(int argc, char *argv[]) { - int i; - int alias_count; - char** aliases; - - { /* Process organisation */ - alias_count = argc - 1; - aliases = xbt_new0(char*,alias_count); - - for (i = 1; i < argc; i++) - aliases[i-1] =strdup(argv[i]); - } - - i=0; - - while(1) - { - m_task_t task = NULL; - int a; - - a = MSG_task_receive(&(task),MSG_host_get_name(MSG_host_self())); - - if (a == MSG_OK) - { - INFO1("Received \"%s\"", MSG_task_get_name(task)); - - if(MSG_task_get_data(task)==FINALIZE) - { - INFO0("All tasks have been dispatched. Let's tell everybody the computation is over."); - - for (i = 0; i < alias_count; i++) - MSG_task_send(MSG_task_create("finalize", 0, 0, FINALIZE),aliases[i]); - - MSG_task_destroy(task); - break; - } - - INFO2("Sending \"%s\" to \"%s\"",MSG_task_get_name(task),aliases[i% alias_count]); - MSG_task_send(task, aliases[i % alias_count]); - i++; - } - else - { - INFO0("Hey ?! What's up ? "); - xbt_assert0(0,"Unexpected behavior"); - } - } - - for(i = 0; i < alias_count; i++) - free(aliases[i]); - - INFO0("I'm done. See you!"); - return 0; - -} /* end_of_forwarder */ + int i; + int alias_count; + char **aliases; + + { /* Process organisation */ + alias_count = argc - 1; + aliases = xbt_new0(char *, alias_count); + + for (i = 1; i < argc; i++) + aliases[i - 1] = strdup(argv[i]); + } + + i = 0; + + while (1) { + m_task_t task = NULL; + int a; + + a = MSG_task_receive(&(task), MSG_host_get_name(MSG_host_self())); + + if (a == MSG_OK) { + INFO1("Received \"%s\"", MSG_task_get_name(task)); + + if (MSG_task_get_data(task) == FINALIZE) { + INFO0 + ("All tasks have been dispatched. Let's tell everybody the computation is over."); + + for (i = 0; i < alias_count; i++) + MSG_task_send(MSG_task_create("finalize", 0, 0, FINALIZE), + aliases[i]); + + MSG_task_destroy(task); + break; + } + + INFO2("Sending \"%s\" to \"%s\"", MSG_task_get_name(task), + aliases[i % alias_count]); + MSG_task_send(task, aliases[i % alias_count]); + i++; + } else { + INFO0("Hey ?! What's up ? "); + xbt_assert0(0, "Unexpected behavior"); + } + } + + for (i = 0; i < alias_count; i++) + free(aliases[i]); + + INFO0("I'm done. See you!"); + return 0; + +} /* end_of_forwarder */ /** Test function */ -MSG_error_t test_all(const char *platform_file,const char *application_file) +MSG_error_t test_all(const char *platform_file, + const char *application_file) { - MSG_error_t res = MSG_OK; - - { /* Simulation setting */ - MSG_set_channel_number(MAX_CHANNEL); - MSG_paje_output("msg_test.trace"); - MSG_create_environment(platform_file); - } - - { - /* Application deployment */ - MSG_function_register("master", master); - MSG_function_register("slave", slave); - MSG_function_register("forwarder", forwarder); - MSG_launch_application(application_file); - } - - res = MSG_main(); - - INFO1("Simulation time %g",MSG_get_clock()); - return res; -} /* end_of_test_all */ + MSG_error_t res = MSG_OK; + + { /* Simulation setting */ + MSG_set_channel_number(MAX_CHANNEL); + MSG_paje_output("msg_test.trace"); + MSG_create_environment(platform_file); + } + + { + /* Application deployment */ + MSG_function_register("master", master); + MSG_function_register("slave", slave); + MSG_function_register("forwarder", forwarder); + MSG_launch_application(application_file); + } + + res = MSG_main(); + + INFO1("Simulation time %g", MSG_get_clock()); + return res; +} /* end_of_test_all */ /** Main function */ int main(int argc, char *argv[]) { - MSG_error_t res = MSG_OK; - - MSG_global_init(&argc,argv); - - if (argc < 3) - { - printf ("Usage: %s platform_file deployment_file\n",argv[0]); - printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]); - exit(1); - } - - res = test_all(argv[1],argv[2]); - MSG_clean(); - - if(res==MSG_OK) - return 0; - else - return 1; -} /* end_of_main */ + MSG_error_t res = MSG_OK; + + MSG_global_init(&argc, argv); + + if (argc < 3) { + printf("Usage: %s platform_file deployment_file\n", argv[0]); + printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); + } + + res = test_all(argv[1], argv[2]); + MSG_clean(); + + if (res == MSG_OK) + return 0; + else + return 1; +} /* end_of_main */ diff --git a/examples/msg/gtnets/gtnets.c b/examples/msg/gtnets/gtnets.c index 22adcee44a..c2884844a6 100644 --- a/examples/msg/gtnets/gtnets.c +++ b/examples/msg/gtnets/gtnets.c @@ -15,7 +15,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, int master(int argc, char *argv[]); int slave(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); typedef enum { PORT_22 = 0, @@ -58,14 +59,14 @@ int master(int argc, char *argv[]) id = atoi(argv[3]); sprintf(id_alias, "flow_%d", id); slavenames[id] = slavename; - TRACE_category (id_alias); + TRACE_category(id_alias); masternames[id] = MSG_host_get_name(MSG_host_self()); { /* Task creation. */ char sprintf_buffer[64] = "Task_0"; todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL); - TRACE_msg_set_task_category(todo,id_alias); + TRACE_msg_set_task_category(todo, id_alias); //keep track of running tasks gl_task_array[id] = todo; gl_data_size[id] = task_comm_size; @@ -83,10 +84,12 @@ int master(int argc, char *argv[]) if (!bool_printed) { - INFO3("Send completed (to %s). Transfer time: %f\t Agregate bandwidth: %f", - slave->name, (end_time - start_time), - task_comm_size / (end_time - start_time)); - INFO2("Completed peer: %s time: %f", slave->name, (end_time - start_time)); + INFO3 + ("Send completed (to %s). Transfer time: %f\t Agregate bandwidth: %f", + slave->name, (end_time - start_time), + task_comm_size / (end_time - start_time)); + INFO2("Completed peer: %s time: %f", slave->name, + (end_time - start_time)); } return 0; } /* end_of_master */ @@ -99,7 +102,7 @@ int slave(int argc, char *argv[]) int a; int id = 0; #ifdef HAVE_LATENCY_BOUND_TRACKING - int limited_latency=0; + int limited_latency = 0; #endif double remaining = 0; char id_alias[10]; @@ -127,42 +130,44 @@ int slave(int argc, char *argv[]) if (gl_task_array[id] == NULL) { } else if (gl_task_array[id] == task) { #ifdef HAVE_LATENCY_BOUND_TRACKING - limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]); - if(limited_latency){ - INFO1("WARNING FLOW[%d] is limited by latency!!", id); - } + limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]); + if (limited_latency) { + INFO1("WARNING FLOW[%d] is limited by latency!!", id); + } #endif - INFO5 - ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f", - id, gl_data_size[id] / elapsed_time, masternames[id], - slavenames[id], 0.0); + INFO5 + ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f", + id, gl_data_size[id] / elapsed_time, masternames[id], + slavenames[id], 0.0); } else { - remaining = MSG_task_get_remaining_communication(gl_task_array[id]); + remaining = + MSG_task_get_remaining_communication(gl_task_array[id]); #ifdef HAVE_LATENCY_BOUND_TRACKING - limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]); + limited_latency = MSG_task_is_latency_bounded(gl_task_array[id]); - if(limited_latency){ - INFO1("WARNING FLOW[%d] is limited by latency!!", id); + if (limited_latency) { + INFO1("WARNING FLOW[%d] is limited by latency!!", id); } #endif INFO5 - ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f", - id, (gl_data_size[id] - remaining) / elapsed_time, masternames[id], - slavenames[id], remaining); + ("===> Estimated Bw of FLOW[%d] : %f ; message from %s to %s with remaining : %f", + id, (gl_data_size[id] - remaining) / elapsed_time, + masternames[id], slavenames[id], remaining); } } - } + } char mark[100]; - snprintf (mark, 100, "flow_%d_finished", trace_id); - TRACE_mark ("endmark", mark); + snprintf(mark, 100, "flow_%d_finished", trace_id); + TRACE_mark("endmark", mark); MSG_task_destroy(task); return 0; } /* end_of_slave */ /** Test function */ -MSG_error_t test_all(const char *platform_file, const char *application_file) +MSG_error_t test_all(const char *platform_file, + const char *application_file) { MSG_error_t res = MSG_OK; @@ -193,14 +198,14 @@ int main(int argc, char *argv[]) exit(1); } - TRACE_start (); - TRACE_declare_mark ("endmark"); + TRACE_start(); + TRACE_declare_mark("endmark"); res = test_all(argv[1], argv[2]); MSG_clean(); - TRACE_end (); + TRACE_end(); if (res == MSG_OK) return 0; diff --git a/examples/msg/icomms/peer.c b/examples/msg/icomms/peer.c index 0e2c21db29..ccf0ac425d 100755 --- a/examples/msg/icomms/peer.c +++ b/examples/msg/icomms/peer.c @@ -5,18 +5,20 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include -#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ -#include "xbt/sysdep.h" /* calloc, printf */ +#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ +#include "xbt/sysdep.h" /* calloc, printf */ /* Create a log channel to have nice outputs. */ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); int sender(int argc, char *argv[]); int receiver(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); /** Sender function */ int sender(int argc, char *argv[]) @@ -28,62 +30,57 @@ int sender(int argc, char *argv[]) double sleep_start_time = atof(argv[5]); double sleep_test_time = atof(argv[6]); - INFO2("sleep_start_time : %f , sleep_test_time : %f",sleep_start_time,sleep_test_time); + INFO2("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, + sleep_test_time); msg_comm_t comm = NULL; int i; m_task_t task = NULL; - MSG_process_sleep (sleep_start_time); - for (i = 0; i < number_of_tasks; i++) - { - char mailbox[256]; - char sprintf_buffer[256]; + MSG_process_sleep(sleep_start_time); + for (i = 0; i < number_of_tasks; i++) { + char mailbox[256]; + char sprintf_buffer[256]; - sprintf(mailbox,"receiver-%ld",i % receivers_count); + sprintf(mailbox, "receiver-%ld", i % receivers_count); sprintf(sprintf_buffer, "Task_%d", i); - task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); - comm=MSG_task_isend(task, mailbox); - INFO2("Send to receiver-%ld Task_%d",i % receivers_count,i); - - if(sleep_test_time == 0) - { - MSG_comm_wait(comm,-1); - } - else - { - while(MSG_comm_test(comm) == 0){ - MSG_process_sleep (sleep_test_time); - }; - MSG_comm_destroy(comm); + task = + MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, + NULL); + comm = MSG_task_isend(task, mailbox); + INFO2("Send to receiver-%ld Task_%d", i % receivers_count, i); + + if (sleep_test_time == 0) { + MSG_comm_wait(comm, -1); + } else { + while (MSG_comm_test(comm) == 0) { + MSG_process_sleep(sleep_test_time); + }; + MSG_comm_destroy(comm); } } - for (i = 0; i < receivers_count; i++) - { + for (i = 0; i < receivers_count; i++) { char mailbox[80]; - sprintf(mailbox,"receiver-%ld",i % receivers_count); - task = MSG_task_create ("finalize", 0, 0, 0); + sprintf(mailbox, "receiver-%ld", i % receivers_count); + task = MSG_task_create("finalize", 0, 0, 0); comm = MSG_task_isend(task, mailbox); - INFO1("Send to receiver-%ld finalize",i % receivers_count); - if(sleep_test_time == 0) - { - MSG_comm_wait(comm,-1); - } - else - { - while(MSG_comm_test(comm) == 0){ - MSG_process_sleep (sleep_test_time); - }; - MSG_comm_destroy(comm); + INFO1("Send to receiver-%ld finalize", i % receivers_count); + if (sleep_test_time == 0) { + MSG_comm_wait(comm, -1); + } else { + while (MSG_comm_test(comm) == 0) { + MSG_process_sleep(sleep_test_time); + }; + MSG_comm_destroy(comm); } } INFO0("Goodbye now!"); return 0; -} /* end_of_sender */ +} /* end_of_sender */ /** Receiver function */ int receiver(int argc, char *argv[]) @@ -95,35 +92,33 @@ int receiver(int argc, char *argv[]) msg_comm_t res_irecv; double sleep_start_time = atof(argv[2]); double sleep_test_time = atof(argv[3]); - INFO2("sleep_start_time : %f , sleep_test_time : %f",sleep_start_time,sleep_test_time); - - xbt_assert1(sscanf(argv[1],"%d", &id), - "Invalid argument %s\n",argv[1]); - - MSG_process_sleep (sleep_start_time); - - sprintf(mailbox,"receiver-%d",id); - while(1) { - res_irecv = MSG_task_irecv(&(task), mailbox); - INFO0("Wait to receive a task"); - - if(sleep_test_time == 0) - { - res = MSG_comm_wait(res_irecv,-1); - xbt_assert0(res == MSG_OK, "MSG_task_get failed"); - } - else - { - while(MSG_comm_test(res_irecv) == 0){ - MSG_process_sleep (sleep_test_time); - }; - MSG_comm_destroy(res_irecv); + INFO2("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time, + sleep_test_time); + + xbt_assert1(sscanf(argv[1], "%d", &id), + "Invalid argument %s\n", argv[1]); + + MSG_process_sleep(sleep_start_time); + + sprintf(mailbox, "receiver-%d", id); + while (1) { + res_irecv = MSG_task_irecv(&(task), mailbox); + INFO0("Wait to receive a task"); + + if (sleep_test_time == 0) { + res = MSG_comm_wait(res_irecv, -1); + xbt_assert0(res == MSG_OK, "MSG_task_get failed"); + } else { + while (MSG_comm_test(res_irecv) == 0) { + MSG_process_sleep(sleep_test_time); + }; + MSG_comm_destroy(res_irecv); } - INFO1("Received \"%s\"", MSG_task_get_name(task)); - if (!strcmp(MSG_task_get_name(task),"finalize")) { - MSG_task_destroy(task); - break; + INFO1("Received \"%s\"", MSG_task_get_name(task)); + if (!strcmp(MSG_task_get_name(task), "finalize")) { + MSG_task_destroy(task); + break; } INFO1("Processing \"%s\"", MSG_task_get_name(task)); @@ -134,29 +129,29 @@ int receiver(int argc, char *argv[]) } INFO0("I'm done. See you!"); return 0; -} /* end_of_receiver */ +} /* end_of_receiver */ /** Test function */ MSG_error_t test_all(const char *platform_file, - const char *application_file) + const char *application_file) { MSG_error_t res = MSG_OK; /* MSG_config("workstation/model","KCCFLN05"); */ - { /* Simulation setting */ + { /* Simulation setting */ MSG_set_channel_number(0); MSG_create_environment(platform_file); } - { /* Application deployment */ + { /* Application deployment */ MSG_function_register("sender", sender); MSG_function_register("receiver", receiver); MSG_launch_application(application_file); } res = MSG_main(); - - INFO1("Simulation time %g",MSG_get_clock()); + + INFO1("Simulation time %g", MSG_get_clock()); return res; -} /* end_of_test_all */ +} /* end_of_test_all */ /** Main function */ @@ -164,18 +159,18 @@ int main(int argc, char *argv[]) { MSG_error_t res = MSG_OK; - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); if (argc < 3) { - printf ("Usage: %s platform_file deployment_file\n",argv[0]); - printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]); - exit(1); + printf("Usage: %s platform_file deployment_file\n", argv[0]); + printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); } - res = test_all(argv[1],argv[2]); - SIMIX_message_sizes_output("toto.txt"); + res = test_all(argv[1], argv[2]); + SIMIX_message_sizes_output("toto.txt"); MSG_clean(); - if(res==MSG_OK) + if (res == MSG_OK) return 0; else return 1; -} /* end_of_main */ +} /* end_of_main */ diff --git a/examples/msg/icomms/peer2.c b/examples/msg/icomms/peer2.c index 0625a1551d..6a0d0fc1c4 100755 --- a/examples/msg/icomms/peer2.c +++ b/examples/msg/icomms/peer2.c @@ -5,18 +5,20 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include -#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ -#include "xbt/sysdep.h" /* calloc, printf */ +#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ +#include "xbt/sysdep.h" /* calloc, printf */ /* Create a log channel to have nice outputs. */ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); int sender(int argc, char *argv[]); int receiver(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); /** Sender function */ int sender(int argc, char *argv[]) @@ -26,34 +28,35 @@ int sender(int argc, char *argv[]) double task_comm_size = atof(argv[3]); long receivers_count = atol(argv[4]); - msg_comm_t *comm = malloc((number_of_tasks+receivers_count)*sizeof(msg_comm_t)); + msg_comm_t *comm = + malloc((number_of_tasks + receivers_count) * sizeof(msg_comm_t)); int i; m_task_t task = NULL; - for (i = 0; i < number_of_tasks; i++) - { - char mailbox[256]; - char sprintf_buffer[256]; - sprintf(mailbox,"receiver-%ld",i % receivers_count); + for (i = 0; i < number_of_tasks; i++) { + char mailbox[256]; + char sprintf_buffer[256]; + sprintf(mailbox, "receiver-%ld", i % receivers_count); sprintf(sprintf_buffer, "Task_%d", i); - task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); - comm[i]=MSG_task_isend(task, mailbox); - INFO2("Send to receiver-%ld Task_%d",i % receivers_count,i); + task = + MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, + NULL); + comm[i] = MSG_task_isend(task, mailbox); + INFO2("Send to receiver-%ld Task_%d", i % receivers_count, i); } - for (i = 0; i < receivers_count; i++) - { + for (i = 0; i < receivers_count; i++) { char mailbox[80]; - sprintf(mailbox,"receiver-%ld",i % receivers_count); - task = MSG_task_create ("finalize", 0, 0, 0); - comm[i+number_of_tasks]=MSG_task_isend(task, mailbox); - INFO1("Send to receiver-%ld finalize",i % receivers_count); + sprintf(mailbox, "receiver-%ld", i % receivers_count); + task = MSG_task_create("finalize", 0, 0, 0); + comm[i + number_of_tasks] = MSG_task_isend(task, mailbox); + INFO1("Send to receiver-%ld finalize", i % receivers_count); } - /* Here we are waiting for the completion of all communications*/ - MSG_comm_waitall(comm,(number_of_tasks+receivers_count),-1); + /* Here we are waiting for the completion of all communications */ + MSG_comm_waitall(comm, (number_of_tasks + receivers_count), -1); INFO0("Goodbye now!"); return 0; -} /* end_of_sender */ +} /* end_of_sender */ /** Receiver function */ int receiver(int argc, char *argv[]) @@ -63,19 +66,19 @@ int receiver(int argc, char *argv[]) int id = -1; char mailbox[80]; msg_comm_t res_irecv; - xbt_assert1(sscanf(argv[1],"%d", &id), - "Invalid argument %s\n",argv[1]); - MSG_process_sleep (10); - sprintf(mailbox,"receiver-%d",id); - while(1) { - res_irecv = MSG_task_irecv(&(task), mailbox); - INFO0("Wait to receive a task"); - res = MSG_comm_wait(res_irecv,-1); - xbt_assert0(res == MSG_OK, "MSG_task_get failed"); - INFO1("Received \"%s\"", MSG_task_get_name(task)); - if (!strcmp(MSG_task_get_name(task),"finalize")) { - MSG_task_destroy(task); - break; + xbt_assert1(sscanf(argv[1], "%d", &id), + "Invalid argument %s\n", argv[1]); + MSG_process_sleep(10); + sprintf(mailbox, "receiver-%d", id); + while (1) { + res_irecv = MSG_task_irecv(&(task), mailbox); + INFO0("Wait to receive a task"); + res = MSG_comm_wait(res_irecv, -1); + xbt_assert0(res == MSG_OK, "MSG_task_get failed"); + INFO1("Received \"%s\"", MSG_task_get_name(task)); + if (!strcmp(MSG_task_get_name(task), "finalize")) { + MSG_task_destroy(task); + break; } INFO1("Processing \"%s\"", MSG_task_get_name(task)); @@ -86,29 +89,29 @@ int receiver(int argc, char *argv[]) } INFO0("I'm done. See you!"); return 0; -} /* end_of_receiver */ +} /* end_of_receiver */ /** Test function */ MSG_error_t test_all(const char *platform_file, - const char *application_file) + const char *application_file) { MSG_error_t res = MSG_OK; /* MSG_config("workstation/model","KCCFLN05"); */ - { /* Simulation setting */ + { /* Simulation setting */ MSG_set_channel_number(0); MSG_create_environment(platform_file); } - { /* Application deployment */ + { /* Application deployment */ MSG_function_register("sender", sender); MSG_function_register("receiver", receiver); MSG_launch_application(application_file); } res = MSG_main(); - - INFO1("Simulation time %g",MSG_get_clock()); + + INFO1("Simulation time %g", MSG_get_clock()); return res; -} /* end_of_test_all */ +} /* end_of_test_all */ /** Main function */ @@ -116,18 +119,18 @@ int main(int argc, char *argv[]) { MSG_error_t res = MSG_OK; - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); if (argc < 3) { - printf ("Usage: %s platform_file deployment_file\n",argv[0]); - printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]); - exit(1); + printf("Usage: %s platform_file deployment_file\n", argv[0]); + printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); } - res = test_all(argv[1],argv[2]); - SIMIX_message_sizes_output("toto.txt"); + res = test_all(argv[1], argv[2]); + SIMIX_message_sizes_output("toto.txt"); MSG_clean(); - if(res==MSG_OK) + if (res == MSG_OK) return 0; else return 1; -} /* end_of_main */ +} /* end_of_main */ diff --git a/examples/msg/icomms/peer3.c b/examples/msg/icomms/peer3.c index 45b4f5636b..feba87dc94 100755 --- a/examples/msg/icomms/peer3.c +++ b/examples/msg/icomms/peer3.c @@ -5,18 +5,20 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include -#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ -#include "xbt/sysdep.h" /* calloc, printf */ +#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ +#include "xbt/sysdep.h" /* calloc, printf */ #include /* Create a log channel to have nice outputs. */ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); int sender(int argc, char *argv[]); int receiver(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); /** Sender function */ int sender(int argc, char *argv[]) @@ -26,53 +28,57 @@ int sender(int argc, char *argv[]) double task_comm_size = atof(argv[3]); long receivers_count = atol(argv[4]); int diff_com = atol(argv[5]); - double coef= 0; + double coef = 0; xbt_dynar_t d = NULL; int i; m_task_t task = NULL; char mailbox[256]; char sprintf_buffer[256]; d = xbt_dynar_new(sizeof(msg_comm_t), NULL); - msg_comm_t *comm = malloc((number_of_tasks+receivers_count)*sizeof(msg_comm_t)); + msg_comm_t *comm = + malloc((number_of_tasks + receivers_count) * sizeof(msg_comm_t)); msg_comm_t res_irecv = NULL; - for (i = 0; i < (number_of_tasks); i++) - { - task = NULL; - if(diff_com == 0) coef = 1; - else coef = (i+1); - - sprintf(mailbox,"receiver-%ld",(i % receivers_count)); + for (i = 0; i < (number_of_tasks); i++) { + task = NULL; + if (diff_com == 0) + coef = 1; + else + coef = (i + 1); + + sprintf(mailbox, "receiver-%ld", (i % receivers_count)); sprintf(sprintf_buffer, "Task_%d", i); - task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size/coef, NULL); + task = + MSG_task_create(sprintf_buffer, task_comp_size, + task_comm_size / coef, NULL); comm[i] = MSG_task_isend(task, mailbox); MSG_task_refcount_dec(task); xbt_dynar_push_as(d, msg_comm_t, comm[i]); - INFO3("Send to receiver-%ld %s comm_size %f",i % receivers_count,sprintf_buffer,task_comm_size/coef); + INFO3("Send to receiver-%ld %s comm_size %f", i % receivers_count, + sprintf_buffer, task_comm_size / coef); } - /* Here we are waiting for the completion of all communications*/ + /* Here we are waiting for the completion of all communications */ - while(d->used) - { + while (d->used) { xbt_dynar_remove_at(d, MSG_comm_waitany(d), &res_irecv); } xbt_dynar_free(&d); - /* Here we are waiting for the completion of all tasks*/ - sprintf(mailbox,"finalize"); + /* Here we are waiting for the completion of all tasks */ + sprintf(mailbox, "finalize"); - for(i=0; iused) - { - task_com = NULL; - res_irecv = NULL; - MSG_error_t err = MSG_OK; - int num = MSG_comm_waitany(comms); - xbt_dynar_remove_at(comms, num, &res_irecv); - task_com = MSG_comm_get_task(res_irecv); - INFO1("Processing \"%s\"", MSG_task_get_name(task_com) ); - MSG_task_execute(task_com); - INFO1("\"%s\" done", MSG_task_get_name(task_com)); - err = MSG_task_destroy(task_com); - xbt_assert0(err == MSG_OK, "MSG_task_destroy failed"); + /* Here we are waiting for the receiving of all communications */ + while (comms->used) { + task_com = NULL; + res_irecv = NULL; + MSG_error_t err = MSG_OK; + int num = MSG_comm_waitany(comms); + xbt_dynar_remove_at(comms, num, &res_irecv); + task_com = MSG_comm_get_task(res_irecv); + INFO1("Processing \"%s\"", MSG_task_get_name(task_com)); + MSG_task_execute(task_com); + INFO1("\"%s\" done", MSG_task_get_name(task_com)); + err = MSG_task_destroy(task_com); + xbt_assert0(err == MSG_OK, "MSG_task_destroy failed"); } xbt_dynar_free(&comms); - /* Here we tell to sender that all tasks are done*/ - sprintf(mailbox,"finalize"); + /* Here we tell to sender that all tasks are done */ + sprintf(mailbox, "finalize"); res_irecv = MSG_task_isend(MSG_task_create(NULL, 0, 0, NULL), mailbox); - MSG_comm_wait(res_irecv,-1); + MSG_comm_wait(res_irecv, -1); INFO0("I'm done. See you!"); return 0; -} /* end_of_receiver */ +} /* end_of_receiver */ /** Test function */ MSG_error_t test_all(const char *platform_file, - const char *application_file) + const char *application_file) { MSG_error_t res = MSG_OK; /* MSG_config("workstation/model","KCCFLN05"); */ - { /* Simulation setting */ + { /* Simulation setting */ MSG_set_channel_number(0); MSG_create_environment(platform_file); } - { /* Application deployment */ + { /* Application deployment */ MSG_function_register("sender", sender); MSG_function_register("receiver", receiver); MSG_launch_application(application_file); } res = MSG_main(); - - INFO1("Simulation time %g",MSG_get_clock()); + + INFO1("Simulation time %g", MSG_get_clock()); return res; -} /* end_of_test_all */ +} /* end_of_test_all */ /** Main function */ @@ -153,18 +157,18 @@ int main(int argc, char *argv[]) { MSG_error_t res = MSG_OK; - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); if (argc < 3) { - printf ("Usage: %s platform_file deployment_file\n",argv[0]); - printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]); - exit(1); + printf("Usage: %s platform_file deployment_file\n", argv[0]); + printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); } - res = test_all(argv[1],argv[2]); - SIMIX_message_sizes_output("toto.txt"); + res = test_all(argv[1], argv[2]); + SIMIX_message_sizes_output("toto.txt"); MSG_clean(); - if(res==MSG_OK) + if (res == MSG_OK) return 0; else return 1; -} /* end_of_main */ +} /* end_of_main */ diff --git a/examples/msg/masterslave/masterslave_bypass.c b/examples/msg/masterslave/masterslave_bypass.c index cd30465b74..f6d3e2892e 100644 --- a/examples/msg/masterslave/masterslave_bypass.c +++ b/examples/msg/masterslave/masterslave_bypass.c @@ -179,7 +179,8 @@ int master(int argc, char *argv[]) for (i = 0; i < number_of_tasks; i++) { sprintf(sprintf_buffer, "Task_%d", i); todo[i] = - MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); + MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, + NULL); } } @@ -216,7 +217,7 @@ int master(int argc, char *argv[]) } INFO0 - ("All tasks have been dispatched. Let's tell everybody the computation is over."); + ("All tasks have been dispatched. Let's tell everybody the computation is over."); for (i = 0; i < slaves_count; i++) MSG_task_put(MSG_task_create("finalize", 0, 0, FINALIZE), slaves[i], PORT_22); diff --git a/examples/msg/masterslave/masterslave_console.c b/examples/msg/masterslave/masterslave_console.c index fa5543b6c0..978bf70f5f 100644 --- a/examples/msg/masterslave/masterslave_console.c +++ b/examples/msg/masterslave/masterslave_console.c @@ -16,7 +16,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, int master(int argc, char *argv[]); int slave(int argc, char *argv[]); -MSG_error_t test_all(const char*); +MSG_error_t test_all(const char *); typedef enum { PORT_22 = 0, @@ -26,37 +26,42 @@ typedef enum { /** Emitter function */ int master(int argc, char *argv[]) { - long number_of_tasks = atol(argv[1]); - double task_comp_size = atof(argv[2]); - double task_comm_size = atof(argv[3]); - long slaves_count = atol(argv[4]); - int i; - - INFO2("Got %ld slaves and %ld tasks to process", slaves_count,number_of_tasks); - for (i = 0; i < number_of_tasks; i++) { - char mailbox[256]; - char sprintf_buffer[256]; - m_task_t task=NULL; - - sprintf(mailbox,"slave-%ld",i % slaves_count); - sprintf(sprintf_buffer, "Task_%d", i); - task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); - if (number_of_tasks<10000 || i%10000 == 0) - INFO3("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_tasks, mailbox); - MSG_task_send(task, mailbox); - } - - INFO0("All tasks have been dispatched. Let's tell everybody the computation is over."); - for (i = 0; i < slaves_count; i++) { - char mailbox[80]; - - sprintf(mailbox,"slave-%ld",i % slaves_count); - m_task_t finalize = MSG_task_create ("finalize", 0, 0, 0); - MSG_task_send(finalize, mailbox); - } - - INFO0("Goodbye now!"); - return 0; + long number_of_tasks = atol(argv[1]); + double task_comp_size = atof(argv[2]); + double task_comm_size = atof(argv[3]); + long slaves_count = atol(argv[4]); + int i; + + INFO2("Got %ld slaves and %ld tasks to process", slaves_count, + number_of_tasks); + for (i = 0; i < number_of_tasks; i++) { + char mailbox[256]; + char sprintf_buffer[256]; + m_task_t task = NULL; + + sprintf(mailbox, "slave-%ld", i % slaves_count); + sprintf(sprintf_buffer, "Task_%d", i); + task = + MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, + NULL); + if (number_of_tasks < 10000 || i % 10000 == 0) + INFO3("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, + number_of_tasks, mailbox); + MSG_task_send(task, mailbox); + } + + INFO0 + ("All tasks have been dispatched. Let's tell everybody the computation is over."); + for (i = 0; i < slaves_count; i++) { + char mailbox[80]; + + sprintf(mailbox, "slave-%ld", i % slaves_count); + m_task_t finalize = MSG_task_create("finalize", 0, 0, 0); + MSG_task_send(finalize, mailbox); + } + + INFO0("Goodbye now!"); + return 0; } /* end_of_master */ /** Receiver function */ @@ -67,19 +72,19 @@ int slave(int argc, char *argv[]) int id = -1; char mailbox[80]; - xbt_assert1(sscanf(argv[1],"%d", &id), - "Invalid argument %s\n",argv[1]); + xbt_assert1(sscanf(argv[1], "%d", &id), + "Invalid argument %s\n", argv[1]); - sprintf(mailbox,"slave-%d",id); + sprintf(mailbox, "slave-%d", id); - while(1) { + while (1) { res = MSG_task_receive(&(task), mailbox); xbt_assert0(res == MSG_OK, "MSG_task_get failed"); INFO1("Received \"%s\"", MSG_task_get_name(task)); - if (!strcmp(MSG_task_get_name(task),"finalize")) { - MSG_task_destroy(task); - break; + if (!strcmp(MSG_task_get_name(task), "finalize")) { + MSG_task_destroy(task); + break; } INFO1("Processing \"%s\"", MSG_task_get_name(task)); @@ -90,10 +95,10 @@ int slave(int argc, char *argv[]) } INFO0("I'm done. See you!"); return 0; -} /* end_of_slave */ +} /* end_of_slave */ /** Test function */ -MSG_error_t test_all(const char *file)//(void) +MSG_error_t test_all(const char *file) //(void) { MSG_error_t res = MSG_OK; /* Simulation setting */ @@ -116,9 +121,9 @@ int main(int argc, char *argv[]) MSG_global_init(&argc, argv); if (argc < 2) { - printf ("Usage: %s platform_script[.lua]\n",argv[0]); - printf ("example: %s platform_script.lua\n",argv[0]); - exit(1); + printf("Usage: %s platform_script[.lua]\n", argv[0]); + printf("example: %s platform_script.lua\n", argv[0]); + exit(1); } res = test_all(argv[1]); MSG_clean(); diff --git a/examples/msg/masterslave/masterslave_failure.c b/examples/msg/masterslave/masterslave_failure.c index 330250d868..1629a0a9c9 100644 --- a/examples/msg/masterslave/masterslave_failure.c +++ b/examples/msg/masterslave/masterslave_failure.c @@ -17,7 +17,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, int master(int argc, char *argv[]); int slave(int argc, char *argv[]); int forwarder(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); typedef enum { PORT_22 = 0, @@ -70,25 +71,24 @@ int master(int argc, char *argv[]) int a; *((double *) task->data) = MSG_get_clock(); - a = - MSG_task_put_with_timeout(task, slaves[i % slaves_count], PORT_22, - 10.0); + a = MSG_task_put_with_timeout(task, slaves[i % slaves_count], PORT_22, + 10.0); if (a == MSG_OK) { INFO0("Send completed"); } else if (a == MSG_HOST_FAILURE) { INFO0 - ("Gloups. The cpu on which I'm running just turned off!. See you!"); + ("Gloups. The cpu on which I'm running just turned off!. See you!"); free(slaves); return 0; } else if (a == MSG_TRANSFER_FAILURE) { INFO1 - ("Mmh. Something went wrong with '%s'. Nevermind. Let's keep going!", - slaves[i % slaves_count]->name); + ("Mmh. Something went wrong with '%s'. Nevermind. Let's keep going!", + slaves[i % slaves_count]->name); MSG_task_destroy(task); } else if (a == MSG_TIMEOUT) { INFO1 - ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", - slaves[i % slaves_count]->name); + ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", + slaves[i % slaves_count]->name); MSG_task_destroy(task); } else { INFO0("Hey ?! What's up ? "); @@ -97,7 +97,7 @@ int master(int argc, char *argv[]) } INFO0 - ("All tasks have been dispatched. Let's tell everybody the computation is over."); + ("All tasks have been dispatched. Let's tell everybody the computation is over."); for (i = 0; i < slaves_count; i++) { m_task_t task = MSG_task_create("finalize", 0, 0, FINALIZE); int a = MSG_task_put_with_timeout(task, slaves[i], PORT_22, 1.0); @@ -105,7 +105,7 @@ int master(int argc, char *argv[]) continue; if (a == MSG_HOST_FAILURE) { INFO0 - ("Gloups. The cpu on which I'm running just turned off!. See you!"); + ("Gloups. The cpu on which I'm running just turned off!. See you!"); return 0; } else if (a == MSG_TRANSFER_FAILURE) { INFO1("Mmh. Can't reach '%s'! Nevermind. Let's keep going!", @@ -113,12 +113,13 @@ int master(int argc, char *argv[]) MSG_task_destroy(task); } else if (a == MSG_TIMEOUT) { INFO1 - ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", - slaves[i % slaves_count]->name); + ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", + slaves[i % slaves_count]->name); MSG_task_destroy(task); } else { INFO0("Hey ?! What's up ? "); - xbt_assert2(0, "Unexpected behavior with '%s': %d", slaves[i]->name, a); + xbt_assert2(0, "Unexpected behavior with '%s': %d", slaves[i]->name, + a); } } @@ -155,7 +156,7 @@ int slave(int argc, char *argv[]) MSG_task_destroy(task); } else if (a == MSG_HOST_FAILURE) { INFO0 - ("Gloups. The cpu on which I'm running just turned off!. See you!"); + ("Gloups. The cpu on which I'm running just turned off!. See you!"); return 0; } else { INFO0("Hey ?! What's up ? "); @@ -163,7 +164,7 @@ int slave(int argc, char *argv[]) } } else if (a == MSG_HOST_FAILURE) { INFO0 - ("Gloups. The cpu on which I'm running just turned off!. See you!"); + ("Gloups. The cpu on which I'm running just turned off!. See you!"); return 0; } else if (a == MSG_TRANSFER_FAILURE) { INFO0("Mmh. Something went wrong. Nevermind. Let's keep going!"); @@ -177,7 +178,8 @@ int slave(int argc, char *argv[]) } /* end_of_slave */ /** Test function */ -MSG_error_t test_all(const char *platform_file, const char *application_file) +MSG_error_t test_all(const char *platform_file, + const char *application_file) { MSG_error_t res = MSG_OK; diff --git a/examples/msg/masterslave/masterslave_forwarder.c b/examples/msg/masterslave/masterslave_forwarder.c index b1a28cfca3..312a922b39 100644 --- a/examples/msg/masterslave/masterslave_forwarder.c +++ b/examples/msg/masterslave/masterslave_forwarder.c @@ -17,7 +17,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, int master(int argc, char *argv[]); int slave(int argc, char *argv[]); int forwarder(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); typedef enum { PORT_22 = 0, @@ -53,7 +54,8 @@ int master(int argc, char *argv[]) for (i = 0; i < number_of_tasks; i++) { sprintf(sprintf_buffer, "Task_%d", i); todo[i] = - MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); + MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, + NULL); } } @@ -85,9 +87,9 @@ int master(int argc, char *argv[]) } INFO0 - ("All tasks have been dispatched. Let's tell everybody the computation is over."); - for (i = 0; i < slaves_count; i++){ - m_task_t finalize=MSG_task_create("finalize", 0, 0, FINALIZE); + ("All tasks have been dispatched. Let's tell everybody the computation is over."); + for (i = 0; i < slaves_count; i++) { + m_task_t finalize = MSG_task_create("finalize", 0, 0, FINALIZE); MSG_task_put(finalize, slaves[i], PORT_22); } @@ -151,7 +153,7 @@ int forwarder(int argc, char *argv[]) INFO1("Received \"%s\"", MSG_task_get_name(task)); if (MSG_task_get_data(task) == FINALIZE) { INFO0 - ("All tasks have been dispatched. Let's tell everybody the computation is over."); + ("All tasks have been dispatched. Let's tell everybody the computation is over."); for (i = 0; i < slaves_count; i++) MSG_task_put(MSG_task_create("finalize", 0, 0, FINALIZE), slaves[i], PORT_22); @@ -174,7 +176,8 @@ int forwarder(int argc, char *argv[]) } /* end_of_forwarder */ /** Test function */ -MSG_error_t test_all(const char *platform_file, const char *application_file) +MSG_error_t test_all(const char *platform_file, + const char *application_file) { MSG_error_t res = MSG_OK; diff --git a/examples/msg/masterslave/masterslave_mailbox.c b/examples/msg/masterslave/masterslave_mailbox.c index 80497e5aba..02ebcc5b5d 100644 --- a/examples/msg/masterslave/masterslave_mailbox.c +++ b/examples/msg/masterslave/masterslave_mailbox.c @@ -5,18 +5,20 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include -#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ -#include "xbt/sysdep.h" /* calloc, printf */ +#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ +#include "xbt/sysdep.h" /* calloc, printf */ /* Create a log channel to have nice outputs. */ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); int master(int argc, char *argv[]); int slave(int argc, char *argv[]); int forwarder(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); /** Emitter function */ int master(int argc, char *argv[]) @@ -28,34 +30,39 @@ int master(int argc, char *argv[]) int i; - INFO2("Got %ld slaves and %ld tasks to process", slaves_count,number_of_tasks); + INFO2("Got %ld slaves and %ld tasks to process", slaves_count, + number_of_tasks); for (i = 0; i < number_of_tasks; i++) { char mailbox[256]; char sprintf_buffer[256]; - m_task_t task=NULL; + m_task_t task = NULL; - sprintf(mailbox,"slave-%ld",i % slaves_count); + sprintf(mailbox, "slave-%ld", i % slaves_count); sprintf(sprintf_buffer, "Task_%d", i); - task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL); - if (number_of_tasks<10000 || i%10000 == 0) - INFO3("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_tasks, mailbox); - + task = + MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, + NULL); + if (number_of_tasks < 10000 || i % 10000 == 0) + INFO3("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, + number_of_tasks, mailbox); + MSG_task_send(task, mailbox); } - - INFO0("All tasks have been dispatched. Let's tell everybody the computation is over."); - for (i = 0; i < slaves_count; i++) { - char mailbox[80]; - - sprintf(mailbox,"slave-%ld",i % slaves_count); - m_task_t finalize = MSG_task_create ("finalize", 0, 0, 0); - MSG_task_send(finalize, mailbox); - } - + + INFO0 + ("All tasks have been dispatched. Let's tell everybody the computation is over."); + for (i = 0; i < slaves_count; i++) { + char mailbox[80]; + + sprintf(mailbox, "slave-%ld", i % slaves_count); + m_task_t finalize = MSG_task_create("finalize", 0, 0, 0); + MSG_task_send(finalize, mailbox); + } + // INFO0("Goodbye now!"); return 0; -} /* end_of_master */ +} /* end_of_master */ /** Receiver function */ int slave(int argc, char *argv[]) @@ -65,21 +72,20 @@ int slave(int argc, char *argv[]) int id = -1; char mailbox[80]; - xbt_assert1(sscanf(argv[1],"%d", &id), - "Invalid argument %s\n",argv[1]); + xbt_assert1(sscanf(argv[1], "%d", &id), + "Invalid argument %s\n", argv[1]); - sprintf(mailbox,"slave-%d",id); + sprintf(mailbox, "slave-%d", id); - while(1) { + while (1) { res = MSG_task_receive(&(task), mailbox); xbt_assert0(res == MSG_OK, "MSG_task_get failed"); // INFO1("Received \"%s\"", MSG_task_get_name(task)); - if (!strcmp(MSG_task_get_name(task),"finalize")) { - MSG_task_destroy(task); - break; + if (!strcmp(MSG_task_get_name(task), "finalize")) { + MSG_task_destroy(task); + break; } - // INFO1("Processing \"%s\"", MSG_task_get_name(task)); MSG_task_execute(task); // INFO1("\"%s\" done", MSG_task_get_name(task)); @@ -88,29 +94,29 @@ int slave(int argc, char *argv[]) } INFO0("I'm done. See you!"); return 0; -} /* end_of_slave */ +} /* end_of_slave */ /** Test function */ MSG_error_t test_all(const char *platform_file, - const char *application_file) + const char *application_file) { MSG_error_t res = MSG_OK; /* MSG_config("workstation/model","KCCFLN05"); */ - { /* Simulation setting */ + { /* Simulation setting */ MSG_set_channel_number(0); MSG_create_environment(platform_file); } - { /* Application deployment */ + { /* Application deployment */ MSG_function_register("master", master); MSG_function_register("slave", slave); MSG_launch_application(application_file); } res = MSG_main(); - - INFO1("Simulation time %g",MSG_get_clock()); + + INFO1("Simulation time %g", MSG_get_clock()); return res; -} /* end_of_test_all */ +} /* end_of_test_all */ /** Main function */ @@ -118,18 +124,18 @@ int main(int argc, char *argv[]) { MSG_error_t res = MSG_OK; - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); if (argc < 3) { - printf ("Usage: %s platform_file deployment_file\n",argv[0]); - printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]); - exit(1); + printf("Usage: %s platform_file deployment_file\n", argv[0]); + printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); } - res = test_all(argv[1],argv[2]); - SIMIX_message_sizes_output("toto.txt"); + res = test_all(argv[1], argv[2]); + SIMIX_message_sizes_output("toto.txt"); MSG_clean(); - if(res==MSG_OK) + if (res == MSG_OK) return 0; else return 1; -} /* end_of_main */ +} /* end_of_main */ diff --git a/examples/msg/mc/bugged1.c b/examples/msg/mc/bugged1.c index 43e4cb44a7..b83efd79b3 100644 --- a/examples/msg/mc/bugged1.c +++ b/examples/msg/mc/bugged1.c @@ -7,54 +7,57 @@ #include #define N 3 -XBT_LOG_NEW_DEFAULT_CATEGORY(example,"this example"); - -int server(int argc,char *argv[]); -int client(int argc,char *argv[]); - -int server(int argc,char *argv[]) { - m_task_t task = NULL; - int count = 0; - while(count < N){ - if(task){ - MSG_task_destroy(task); - task = NULL; - } - MSG_task_receive(&task,"mymailbox"); - count++; - } - MC_assert(atoi(MSG_task_get_name(task)) == 3); +XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example"); + +int server(int argc, char *argv[]); +int client(int argc, char *argv[]); + +int server(int argc, char *argv[]) +{ + m_task_t task = NULL; + int count = 0; + while (count < N) { + if (task) { + MSG_task_destroy(task); + task = NULL; + } + MSG_task_receive(&task, "mymailbox"); + count++; + } + MC_assert(atoi(MSG_task_get_name(task)) == 3); INFO0("OK"); - return 0; + return 0; } -int client(int argc,char *argv[]) { +int client(int argc, char *argv[]) +{ - m_task_t task = MSG_task_create(argv[1], 0/*comp cost*/, 10000/*comm size*/, NULL /*arbitrary data*/); + m_task_t task = + MSG_task_create(argv[1], 0 /*comp cost */ , 10000 /*comm size */ , + NULL /*arbitrary data */ ); - MSG_task_send(task,"mymailbox"); + MSG_task_send(task, "mymailbox"); - INFO0("Sent!"); - return 0; + INFO0("Sent!"); + return 0; } -int main(int argc,char*argv[]) { +int main(int argc, char *argv[]) +{ - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); - MSG_create_environment("platform.xml"); + MSG_create_environment("platform.xml"); - MSG_function_register("server", server); + MSG_function_register("server", server); - MSG_function_register("client", client); + MSG_function_register("client", client); - MSG_launch_application("deploy_bugged1.xml"); + MSG_launch_application("deploy_bugged1.xml"); - MSG_main(); - - return 0; - -} + MSG_main(); + return 0; +} diff --git a/examples/msg/mc/bugged2.c b/examples/msg/mc/bugged2.c index 180db605e0..e5040b7c9a 100644 --- a/examples/msg/mc/bugged2.c +++ b/examples/msg/mc/bugged2.c @@ -7,47 +7,49 @@ #include #define N 3 -XBT_LOG_NEW_DEFAULT_CATEGORY(example,"this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example"); -int server(int argc,char *argv[]); -int client(int argc,char *argv[]); +int server(int argc, char *argv[]); +int client(int argc, char *argv[]); -int server(int argc,char *argv[]) +int server(int argc, char *argv[]) { m_task_t task1, task2; long val1, val2; - MSG_task_receive(&task1,"mymailbox"); - val1 = (long)MSG_task_get_data(task1); + MSG_task_receive(&task1, "mymailbox"); + val1 = (long) MSG_task_get_data(task1); INFO1("Received %lu", val1); - MSG_task_receive(&task2,"mymailbox"); - val2 = (long)MSG_task_get_data(task2); + MSG_task_receive(&task2, "mymailbox"); + val2 = (long) MSG_task_get_data(task2); INFO1("Received %lu", val2); - MC_assert( min(val1, val2) == 1 ); + MC_assert(min(val1, val2) == 1); INFO0("OK"); return 0; } -int client(int argc,char *argv[]) +int client(int argc, char *argv[]) { - m_task_t task1 = MSG_task_create("task", 0, 10000, (void *) atol(argv[1])); - m_task_t task2 = MSG_task_create("task", 0, 10000, (void *) atol(argv[1])); + m_task_t task1 = + MSG_task_create("task", 0, 10000, (void *) atol(argv[1])); + m_task_t task2 = + MSG_task_create("task", 0, 10000, (void *) atol(argv[1])); INFO1("Send %d!", atoi(argv[1])); - MSG_task_send(task1,"mymailbox"); + MSG_task_send(task1, "mymailbox"); INFO1("Send %d!", atoi(argv[1])); - MSG_task_send(task2,"mymailbox"); + MSG_task_send(task2, "mymailbox"); return 0; } -int main(int argc,char*argv[]) +int main(int argc, char *argv[]) { - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); MSG_create_environment("platform.xml"); diff --git a/examples/msg/mc/bugged3.c b/examples/msg/mc/bugged3.c index fa81b63e43..5853337d46 100644 --- a/examples/msg/mc/bugged3.c +++ b/examples/msg/mc/bugged3.c @@ -10,51 +10,52 @@ #include #include -XBT_LOG_NEW_DEFAULT_CATEGORY(bugged3,"this example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(bugged3, "this example"); -int server(int argc,char *argv[]); -int client(int argc,char *argv[]); +int server(int argc, char *argv[]); +int client(int argc, char *argv[]); -int server(int argc,char *argv[]) +int server(int argc, char *argv[]) { m_task_t task1; long val1; msg_comm_t comm1, comm2; - comm1 = MSG_task_irecv(&task1,"mymailbox1"); - comm2 = MSG_task_irecv(&task1,"mymailbox2"); + comm1 = MSG_task_irecv(&task1, "mymailbox1"); + comm2 = MSG_task_irecv(&task1, "mymailbox2"); MSG_comm_wait(comm1, -1); MSG_comm_wait(comm2, -1); - val1 = (long)MSG_task_get_data(task1); + val1 = (long) MSG_task_get_data(task1); INFO1("Received %lu", val1); - + MC_assert(val1 == 2); - + INFO0("OK"); return 0; } -int client(int argc,char *argv[]) +int client(int argc, char *argv[]) { msg_comm_t comm; char *mbox; - m_task_t task1 = MSG_task_create("task", 0, 10000, (void *) atol(argv[1])); + m_task_t task1 = + MSG_task_create("task", 0, 10000, (void *) atol(argv[1])); mbox = bprintf("mymailbox%s", argv[1]); - + INFO1("Send %d!", atoi(argv[1])); - comm = MSG_task_isend(task1,mbox); + comm = MSG_task_isend(task1, mbox); MSG_comm_wait(comm, -1); xbt_free(mbox); - + return 0; } -int main(int argc,char*argv[]) +int main(int argc, char *argv[]) { - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); MSG_create_environment("platform.xml"); diff --git a/examples/msg/mc/centralized_mutex.c b/examples/msg/mc/centralized_mutex.c index 73b27eb018..7b68acee9c 100644 --- a/examples/msg/mc/centralized_mutex.c +++ b/examples/msg/mc/centralized_mutex.c @@ -10,39 +10,41 @@ #define CS_PER_PROCESS 2 XBT_LOG_NEW_DEFAULT_CATEGORY(centralized, "my log messages"); -int coordinator(int argc, char** argv); -int client(int argc, char** argv); +int coordinator(int argc, char **argv); +int client(int argc, char **argv); -int coordinator(int argc, char*argv[]) { - xbt_dynar_t requests=xbt_dynar_new(sizeof(char*),NULL); // dynamic vector storing requests (which are char*) - int CS_used=0; // initially the CS is idle - int todo= AMOUNT_OF_CLIENTS*CS_PER_PROCESS; // amount of releases we are expecting - while(todo>0) { - m_task_t task=NULL; - MSG_task_receive(&task,"coordinator"); +int coordinator(int argc, char *argv[]) +{ + xbt_dynar_t requests = xbt_dynar_new(sizeof(char *), NULL); // dynamic vector storing requests (which are char*) + int CS_used = 0; // initially the CS is idle + int todo = AMOUNT_OF_CLIENTS * CS_PER_PROCESS; // amount of releases we are expecting + while (todo > 0) { + m_task_t task = NULL; + MSG_task_receive(&task, "coordinator"); const char *kind = MSG_task_get_name(task); //is it a request or a release? - if (!strcmp(kind,"request")) { // that's a request + if (!strcmp(kind, "request")) { // that's a request char *req = MSG_task_get_data(task); - if (CS_used) { // need to push the request in the vector - INFO0("CS already used. Queue the request"); - xbt_dynar_push(requests, &req); - } else { // can serve it immediatly - INFO0("CS idle. Grant immediatly"); - m_task_t answer = MSG_task_create("grant",0,1000,NULL); - MSG_task_send(answer,req); - CS_used = 1; + if (CS_used) { // need to push the request in the vector + INFO0("CS already used. Queue the request"); + xbt_dynar_push(requests, &req); + } else { // can serve it immediatly + INFO0("CS idle. Grant immediatly"); + m_task_t answer = MSG_task_create("grant", 0, 1000, NULL); + MSG_task_send(answer, req); + CS_used = 1; } - } else { // that's a release. Check if someone was waiting for the lock - if (xbt_dynar_length(requests)>0) { - INFO1("CS release. Grant to queued requests (queue size: %lu)",xbt_dynar_length(requests)); - char *req; - xbt_dynar_pop(requests,&req); - MSG_task_send(MSG_task_create("grant",0,1000,NULL),req); - todo--; - } else { // nobody wants it - INFO0("CS release. resource now idle"); - CS_used=0; - todo--; + } else { // that's a release. Check if someone was waiting for the lock + if (xbt_dynar_length(requests) > 0) { + INFO1("CS release. Grant to queued requests (queue size: %lu)", + xbt_dynar_length(requests)); + char *req; + xbt_dynar_pop(requests, &req); + MSG_task_send(MSG_task_create("grant", 0, 1000, NULL), req); + todo--; + } else { // nobody wants it + INFO0("CS release. resource now idle"); + CS_used = 0; + todo--; } } MSG_task_destroy(task); @@ -51,30 +53,34 @@ int coordinator(int argc, char*argv[]) { return 0; } -int client(int argc, char *argv[]) { - int my_pid=MSG_process_get_PID(MSG_process_self()); +int client(int argc, char *argv[]) +{ + int my_pid = MSG_process_get_PID(MSG_process_self()); // use my pid as name of mailbox to contact me - char *my_mailbox=bprintf("%d",my_pid); + char *my_mailbox = bprintf("%d", my_pid); // request the CS 3 times, sleeping a bit in between int i; - for (i=0; i #include -XBT_LOG_NEW_DEFAULT_CATEGORY(random_test,"Random Test"); +XBT_LOG_NEW_DEFAULT_CATEGORY(random_test, "Random Test"); -int server(int argc,char *argv[]); +int server(int argc, char *argv[]); -int server(int argc,char *argv[]) +int server(int argc, char *argv[]) { int val; - val = MC_random(3,6); + val = MC_random(3, 6); INFO1("val=%d", val); INFO0("OK"); return 0; } -int main(int argc,char*argv[]) +int main(int argc, char *argv[]) { - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); MSG_create_environment("platform.xml"); diff --git a/examples/msg/migration/migration.c b/examples/msg/migration/migration.c index 18936c7007..0d83c808fc 100644 --- a/examples/msg/migration/migration.c +++ b/examples/msg/migration/migration.c @@ -17,17 +17,17 @@ static int emigrant(int argc, char *argv[]) { m_task_t task; INFO0 - ("I'll look for a new job on another machine where the grass is greener."); + ("I'll look for a new job on another machine where the grass is greener."); MSG_process_change_host(MSG_get_host_by_name("Boivin")); INFO0("Yeah, found something to do"); task = MSG_task_create("job", 98095000, 0, NULL); MSG_task_execute(task); MSG_task_destroy(task); - MSG_process_sleep (2); + MSG_process_sleep(2); INFO0("Moving back home after work"); MSG_process_change_host(MSG_get_host_by_name("Jacquelin")); MSG_process_change_host(MSG_get_host_by_name("Boivin")); - MSG_process_sleep (4); + MSG_process_sleep(4); INFO0("Uh, nothing to do here. Stopping now"); return 0; } /* end_of_emigrant */ @@ -37,7 +37,8 @@ static int emigrant(int argc, char *argv[]) */ static int policeman(int argc, char *argv[]) { - INFO0("No function in the API to move the emigrant back, so do nothing."); + INFO0 + ("No function in the API to move the emigrant back, so do nothing."); return 0; } /* end_of_policeman */ diff --git a/examples/msg/parallel_task/test_ptask.c b/examples/msg/parallel_task/test_ptask.c index 9beea974a9..b73ab3aef4 100644 --- a/examples/msg/parallel_task/test_ptask.c +++ b/examples/msg/parallel_task/test_ptask.c @@ -17,7 +17,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, int execute(int argc, char *argv[]); int redistribute(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); typedef enum { PORT_22 = 0, @@ -54,12 +55,12 @@ int execute(int argc, char *argv[]) "Invalid argument %s\n", argv[argc - 1]); computation_duration = (double *) calloc(host_list_size, sizeof(double)); communication_table = - (double *) calloc(host_list_size * host_list_size, sizeof(double)); + (double *) calloc(host_list_size * host_list_size, sizeof(double)); for (i = 0; i < host_list_size; i++) { computation_duration[i] = computation_amount / host_list_size; for (j = 0; j < host_list_size; j++) communication_table[i * host_list_size + j] = - communication_amount / (host_list_size * host_list_size); + communication_amount / (host_list_size * host_list_size); } sprintf(buffer, "redist#0\n"); @@ -105,11 +106,11 @@ int redistribute(int argc, char *argv[]) "Invalid argument %s\n", argv[argc - 1]); computation_duration = (double *) calloc(host_list_size, sizeof(double)); communication_table = - (double *) calloc(host_list_size * host_list_size, sizeof(double)); + (double *) calloc(host_list_size * host_list_size, sizeof(double)); for (i = 0; i < host_list_size; i++) { for (j = 0; j < host_list_size; j++) communication_table[i * host_list_size + j] = - communication_amount / (host_list_size * host_list_size); + communication_amount / (host_list_size * host_list_size); } sprintf(buffer, "redist#0\n"); @@ -129,7 +130,8 @@ int redistribute(int argc, char *argv[]) } -MSG_error_t test_all(const char *platform_file, const char *application_file) +MSG_error_t test_all(const char *platform_file, + const char *application_file) { MSG_error_t res = MSG_OK; diff --git a/examples/msg/priority/priority.c b/examples/msg/priority/priority.c index 066b374797..1a311574be 100644 --- a/examples/msg/priority/priority.c +++ b/examples/msg/priority/priority.c @@ -62,7 +62,8 @@ int main(int argc, char *argv[]) MSG_error_t res = MSG_OK; #ifdef _MSC_VER - unsigned int prev_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); + unsigned int prev_exponent_format = + _set_output_format(_TWO_DIGIT_EXPONENT); #endif diff --git a/examples/msg/properties/msg_prop.c b/examples/msg/properties/msg_prop.c index 6c88118de1..5501a255fc 100644 --- a/examples/msg/properties/msg_prop.c +++ b/examples/msg/properties/msg_prop.c @@ -19,7 +19,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test"); int alice(int argc, char *argv[]); int bob(int argc, char *argv[]); int forwarder(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); int alice(int argc, char *argv[]) { @@ -33,7 +34,7 @@ int alice(int argc, char *argv[]) INFO0("== Print the properties of the host"); xbt_dict_foreach(props, cursor, key, data) - INFO2(" Host property: '%s' -> '%s'", key, data); + INFO2(" Host property: '%s' -> '%s'", key, data); INFO0("== Try to get a host property that does not exist"); value = MSG_host_get_property_value(host1, noexist); @@ -41,7 +42,8 @@ int alice(int argc, char *argv[]) INFO0("== Try to get a host property that does exist"); value = MSG_host_get_property_value(host1, exist); - xbt_assert1(value, "\tProperty %s is undefined (where it should)", exist); + xbt_assert1(value, "\tProperty %s is undefined (where it should)", + exist); xbt_assert2(!strcmp(value, "180"), "\tValue of property %s is defined to %s (where it should be 180)", exist, value); @@ -72,7 +74,7 @@ int bob(int argc, char *argv[]) INFO0("== Print the properties of the process"); xbt_dict_foreach(props, cursor, key, data) - INFO2(" Process property: %s -> %s", key, data); + INFO2(" Process property: %s -> %s", key, data); INFO0("== Try to get a process property that does not exist"); @@ -83,7 +85,8 @@ int bob(int argc, char *argv[]) } /** Test function */ -MSG_error_t test_all(const char *platform_file, const char *application_file) +MSG_error_t test_all(const char *platform_file, + const char *application_file) { MSG_function_register("alice", alice); MSG_function_register("bob", bob); diff --git a/examples/msg/sendrecv/sendrecv.c b/examples/msg/sendrecv/sendrecv.c index ae41aff151..d413535edb 100644 --- a/examples/msg/sendrecv/sendrecv.c +++ b/examples/msg/sendrecv/sendrecv.c @@ -19,7 +19,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, int sender(int argc, char *argv[]); int receiver(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); typedef enum { PORT_22 = 0, @@ -55,7 +56,8 @@ int sender(int argc, char *argv[]) /* Latency */ time = MSG_get_clock(); sprintf(sprintf_buffer_la, "latency task"); - task_la = MSG_task_create(sprintf_buffer_la, 0.0, task_comm_size_lat, NULL); + task_la = + MSG_task_create(sprintf_buffer_la, 0.0, task_comm_size_lat, NULL); task_la->data = xbt_new(double, 1); *(double *) task_la->data = time; INFO1("task_la->data = %le", *((double *) task_la->data)); @@ -64,7 +66,8 @@ int sender(int argc, char *argv[]) /* Bandwidth */ time = MSG_get_clock(); sprintf(sprintf_buffer_bw, "bandwidth task"); - task_bw = MSG_task_create(sprintf_buffer_bw, 0.0, task_comm_size_bw, NULL); + task_bw = + MSG_task_create(sprintf_buffer_bw, 0.0, task_comm_size_bw, NULL); task_bw->data = xbt_new(double, 1); *(double *) task_bw->data = time; INFO1("task_bw->data = %le", *((double *) task_bw->data)); @@ -123,7 +126,8 @@ int receiver(int argc, char *argv[]) /** Test function */ -MSG_error_t test_all(const char *platform_file, const char *application_file) +MSG_error_t test_all(const char *platform_file, + const char *application_file) { MSG_error_t res = MSG_OK; @@ -154,17 +158,19 @@ int main(int argc, char *argv[]) MSG_error_t res = MSG_OK; #ifdef _MSC_VER - unsigned int prev_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); + unsigned int prev_exponent_format = + _set_output_format(_TWO_DIGIT_EXPONENT); #endif MSG_global_init(&argc, argv); if (argc != 3) { - CRITICAL1("Usage: %s platform_file deployment_file \n", argv[0]); + CRITICAL1("Usage: %s platform_file deployment_file \n", + argv[0]); CRITICAL1 - ("example: %s msg_platform.xml msg_deployment.xml KCCFLN05_Vegas\n", - argv[0]); + ("example: %s msg_platform.xml msg_deployment.xml KCCFLN05_Vegas\n", + argv[0]); exit(1); } diff --git a/examples/msg/trace/test_trace_integration.c b/examples/msg/trace/test_trace_integration.c index e42c1e96b4..057810d4cf 100644 --- a/examples/msg/trace/test_trace_integration.c +++ b/examples/msg/trace/test_trace_integration.c @@ -18,31 +18,32 @@ int test_trace(int argc, char *argv[]); /** test the trace integration cpu model */ int test_trace(int argc, char *argv[]) { - m_task_t task; - double task_comp_size = 2800; - double task_prio = 1.0; + m_task_t task; + double task_comp_size = 2800; + double task_prio = 1.0; - if (argc != 3) { - printf("Wrong number of arguments!\nUsage:\n\t1) task computational size in FLOPS\n\t2 task priority\n"); - exit(1); - } + if (argc != 3) { + printf + ("Wrong number of arguments!\nUsage:\n\t1) task computational size in FLOPS\n\t2 task priority\n"); + exit(1); + } - task_comp_size = atof(argv[1]); - task_prio = atof(argv[2]); + task_comp_size = atof(argv[1]); + task_prio = atof(argv[2]); - INFO0("Testing the trace integration cpu model: CpuTI"); - INFO1("Task size: %lf", task_comp_size); - INFO1("Task prio: %lf", task_prio); + INFO0("Testing the trace integration cpu model: CpuTI"); + INFO1("Task size: %lf", task_comp_size); + INFO1("Task prio: %lf", task_prio); - /* Create and execute a single task. */ - task = MSG_task_create("proc 0", task_comp_size, 0, NULL); - MSG_task_set_priority(task, task_prio); - MSG_task_execute(task); + /* Create and execute a single task. */ + task = MSG_task_create("proc 0", task_comp_size, 0, NULL); + MSG_task_set_priority(task, task_prio); + MSG_task_execute(task); - INFO0("Test finished"); + INFO0("Test finished"); - return 0; + return 0; } /** Main function */ diff --git a/examples/msg/tracing/categories.c b/examples/msg/tracing/categories.c index e84e9dd6c2..ecc22fb2fc 100644 --- a/examples/msg/tracing/categories.c +++ b/examples/msg/tracing/categories.c @@ -6,16 +6,18 @@ #include #include "msg/msg.h" -#include "xbt/sysdep.h" /* calloc, printf */ +#include "xbt/sysdep.h" /* calloc, printf */ /* Create a log channel to have nice outputs. */ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); int master(int argc, char *argv[]); int slave(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); /** Emitter function */ int master(int argc, char *argv[]) @@ -28,25 +30,25 @@ int master(int argc, char *argv[]) m_task_t task = NULL; //creating task and setting its category - if (i%2){ - task = MSG_task_create ("task_compute", 10000000, 0, NULL); - TRACE_msg_set_task_category (task, "compute"); - }else if (i%3){ - task = MSG_task_create ("task_request", 10, 10, NULL); - TRACE_msg_set_task_category (task, "request"); - }else{ - task = MSG_task_create ("task_data", 10, 10000000, NULL); - TRACE_msg_set_task_category (task, "data"); + if (i % 2) { + task = MSG_task_create("task_compute", 10000000, 0, NULL); + TRACE_msg_set_task_category(task, "compute"); + } else if (i % 3) { + task = MSG_task_create("task_request", 10, 10, NULL); + TRACE_msg_set_task_category(task, "request"); + } else { + task = MSG_task_create("task_data", 10, 10000000, NULL); + TRACE_msg_set_task_category(task, "data"); } MSG_task_send(task, "master_mailbox"); } - - for (i = 0; i < slaves_count; i++) { - m_task_t finalize = MSG_task_create ("finalize", 0, 1000, 0); - TRACE_msg_set_task_category(finalize, "finalize"); - MSG_task_send(finalize, "master_mailbox"); - } - + + for (i = 0; i < slaves_count; i++) { + m_task_t finalize = MSG_task_create("finalize", 0, 1000, 0); + TRACE_msg_set_task_category(finalize, "finalize"); + MSG_task_send(finalize, "master_mailbox"); + } + return 0; } @@ -56,12 +58,12 @@ int slave(int argc, char *argv[]) m_task_t task = NULL; int res; - while(1) { + while (1) { res = MSG_task_receive(&(task), "master_mailbox"); - if (!strcmp(MSG_task_get_name(task),"finalize")) { + if (!strcmp(MSG_task_get_name(task), "finalize")) { MSG_task_destroy(task); - break; + break; } MSG_task_execute(task); @@ -73,22 +75,22 @@ int slave(int argc, char *argv[]) /** Test function */ MSG_error_t test_all(const char *platform_file, - const char *application_file) + const char *application_file) { MSG_error_t res = MSG_OK; - { /* Simulation setting */ + { /* Simulation setting */ MSG_set_channel_number(0); MSG_create_environment(platform_file); } - { /* Application deployment */ + { /* Application deployment */ MSG_function_register("master", master); MSG_function_register("slave", slave); MSG_launch_application(application_file); } res = MSG_main(); - - INFO1("Simulation time %g",MSG_get_clock()); + + INFO1("Simulation time %g", MSG_get_clock()); return res; } @@ -98,30 +100,29 @@ int main(int argc, char *argv[]) { MSG_error_t res = MSG_OK; - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); if (argc < 3) { - printf ("Usage: %s platform_file deployment_file\n",argv[0]); - printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]); - exit(1); + printf("Usage: %s platform_file deployment_file\n", argv[0]); + printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); } - //starting the simulation tracing - TRACE_start (); + TRACE_start(); //declaring user categories - TRACE_category ("compute"); - TRACE_category ("request"); - TRACE_category ("data"); - TRACE_category ("finalize"); + TRACE_category("compute"); + TRACE_category("request"); + TRACE_category("data"); + TRACE_category("finalize"); - res = test_all(argv[1],argv[2]); + res = test_all(argv[1], argv[2]); MSG_clean(); //ending the simulation tracing TRACE_end(); - if(res==MSG_OK) + if (res == MSG_OK) return 0; else return 1; -} /* end_of_main */ +} /* end_of_main */ diff --git a/examples/msg/tracing/ms.c b/examples/msg/tracing/ms.c index d63b04de50..1f7a16871e 100644 --- a/examples/msg/tracing/ms.c +++ b/examples/msg/tracing/ms.c @@ -6,16 +6,18 @@ #include #include "msg/msg.h" -#include "xbt/sysdep.h" /* calloc, printf */ +#include "xbt/sysdep.h" /* calloc, printf */ /* Create a log channel to have nice outputs. */ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); int master(int argc, char *argv[]); int slave(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); /** Emitter function */ int master(int argc, char *argv[]) @@ -26,30 +28,30 @@ int master(int argc, char *argv[]) long slaves_count = atol(argv[4]); //setting the variable "is_master" (previously declared) to value 1 - TRACE_host_variable_set ("is_master", 1); + TRACE_host_variable_set("is_master", 1); - TRACE_mark ("msmark", "start_send_tasks"); + TRACE_mark("msmark", "start_send_tasks"); int i; for (i = 0; i < number_of_tasks; i++) { - m_task_t task=NULL; + m_task_t task = NULL; task = MSG_task_create("task", task_comp_size, task_comm_size, NULL); //setting the variable "task_creation" to value i - TRACE_host_variable_set ("task_creation", i); + TRACE_host_variable_set("task_creation", i); //setting the category of task to "compute" //the category of a task must be defined before it is sent or executed - TRACE_msg_set_task_category (task, "compute"); + TRACE_msg_set_task_category(task, "compute"); MSG_task_send(task, "master_mailbox"); } - TRACE_mark ("msmark", "finish_send_tasks"); - - for (i = 0; i < slaves_count; i++) { - m_task_t finalize = MSG_task_create ("finalize", 0, 0, 0); - TRACE_msg_set_task_category(finalize, "finalize"); - MSG_task_send(finalize, "master_mailbox"); - } - + TRACE_mark("msmark", "finish_send_tasks"); + + for (i = 0; i < slaves_count; i++) { + m_task_t finalize = MSG_task_create("finalize", 0, 0, 0); + TRACE_msg_set_task_category(finalize, "finalize"); + MSG_task_send(finalize, "master_mailbox"); + } + return 0; } @@ -59,19 +61,18 @@ int slave(int argc, char *argv[]) m_task_t task = NULL; int res; - TRACE_host_variable_set ("is_slave", 1); - while(1) { + TRACE_host_variable_set("is_slave", 1); + while (1) { res = MSG_task_receive(&(task), "master_mailbox"); - if (!strcmp(MSG_task_get_name(task),"finalize")) { + if (!strcmp(MSG_task_get_name(task), "finalize")) { MSG_task_destroy(task); - break; + break; } - //adding the value returned by MSG_task_get_compute_duration(task) //to the variable "task_computation" - TRACE_host_variable_add ("task_computation", - MSG_task_get_compute_duration(task)); + TRACE_host_variable_add("task_computation", + MSG_task_get_compute_duration(task)); MSG_task_execute(task); MSG_task_destroy(task); task = NULL; @@ -81,22 +82,22 @@ int slave(int argc, char *argv[]) /** Test function */ MSG_error_t test_all(const char *platform_file, - const char *application_file) + const char *application_file) { MSG_error_t res = MSG_OK; - { /* Simulation setting */ + { /* Simulation setting */ MSG_set_channel_number(0); MSG_create_environment(platform_file); } - { /* Application deployment */ + { /* Application deployment */ MSG_function_register("master", master); MSG_function_register("slave", slave); MSG_launch_application(application_file); } res = MSG_main(); - - INFO1("Simulation time %g",MSG_get_clock()); + + INFO1("Simulation time %g", MSG_get_clock()); return res; } @@ -106,37 +107,36 @@ int main(int argc, char *argv[]) { MSG_error_t res = MSG_OK; - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); if (argc < 3) { - printf ("Usage: %s platform_file deployment_file\n",argv[0]); - printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]); - exit(1); + printf("Usage: %s platform_file deployment_file\n", argv[0]); + printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); } - //starting the simulation tracing - TRACE_start (); + TRACE_start(); //declaring user variables - TRACE_host_variable_declare ("is_slave"); - TRACE_host_variable_declare ("is_master"); - TRACE_host_variable_declare ("task_creation"); - TRACE_host_variable_declare ("task_computation"); + TRACE_host_variable_declare("is_slave"); + TRACE_host_variable_declare("is_master"); + TRACE_host_variable_declare("task_creation"); + TRACE_host_variable_declare("task_computation"); //declaring user markers - TRACE_declare_mark ("msmark"); + TRACE_declare_mark("msmark"); //declaring user categories - TRACE_category ("compute"); - TRACE_category ("finalize"); + TRACE_category("compute"); + TRACE_category("finalize"); - res = test_all(argv[1],argv[2]); + res = test_all(argv[1], argv[2]); MSG_clean(); //ending the simulation tracing TRACE_end(); - if(res==MSG_OK) + if (res == MSG_OK) return 0; else return 1; -} /* end_of_main */ +} /* end_of_main */ diff --git a/examples/msg/tracing/procmig.c b/examples/msg/tracing/procmig.c index c9ebc9929c..e45aab6985 100644 --- a/examples/msg/tracing/procmig.c +++ b/examples/msg/tracing/procmig.c @@ -17,23 +17,23 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, static int emigrant(int argc, char *argv[]) { INFO0("Setting process category"); - TRACE_msg_set_process_category (MSG_process_self(), "emigrant"); - MSG_process_sleep (2); + TRACE_msg_set_process_category(MSG_process_self(), "emigrant"); + MSG_process_sleep(2); INFO0("Migrating to Tremblay"); MSG_process_change_host(MSG_get_host_by_name("Tremblay")); - MSG_process_sleep (2); + MSG_process_sleep(2); INFO0("Migrating to Jupiter"); MSG_process_change_host(MSG_get_host_by_name("Jupiter")); - MSG_process_sleep (2); + MSG_process_sleep(2); INFO0("Migrating to Fafard"); MSG_process_change_host(MSG_get_host_by_name("Fafard")); - MSG_process_sleep (2); + MSG_process_sleep(2); INFO0("Migrating to Ginette"); MSG_process_change_host(MSG_get_host_by_name("Ginette")); - MSG_process_sleep (2); + MSG_process_sleep(2); INFO0("Migrating to Bourassa"); MSG_process_change_host(MSG_get_host_by_name("Bourassa")); - MSG_process_sleep (2); + MSG_process_sleep(2); return 0; } @@ -50,10 +50,9 @@ int main(int argc, char *argv[]) argv[0]); exit(1); } - //starting the simulation trace - TRACE_start (); - TRACE_category ("emigrant"); + TRACE_start(); + TRACE_category("emigrant"); /* Simulation setting */ MSG_create_environment(argv[1]); diff --git a/examples/msg/tracing/tasks.c b/examples/msg/tracing/tasks.c index 2f28834714..ca955ee6b5 100644 --- a/examples/msg/tracing/tasks.c +++ b/examples/msg/tracing/tasks.c @@ -7,16 +7,18 @@ #include #include "msg/msg.h" -#include "xbt/sysdep.h" /* calloc, printf */ +#include "xbt/sysdep.h" /* calloc, printf */ /* Create a log channel to have nice outputs. */ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); int master(int argc, char *argv[]); int slave(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); /** Emitter function */ int master(int argc, char *argv[]) @@ -25,25 +27,26 @@ int master(int argc, char *argv[]) double task_comp_size = atof(argv[2]); double task_comm_size = atof(argv[3]); long slaves_count = atol(argv[4]); - INFO4 ("master %ld %f %f %ld", number_of_tasks, task_comp_size, task_comm_size, slaves_count); + INFO4("master %ld %f %f %ld", number_of_tasks, task_comp_size, + task_comm_size, slaves_count); int i; for (i = 0; i < number_of_tasks; i++) { - m_task_t task=NULL; + m_task_t task = NULL; task = MSG_task_create("task", task_comp_size, task_comm_size, NULL); //setting the category of task to "compute" //the category of a task must be defined before it is sent or executed - TRACE_msg_set_task_category (task, "compute"); + TRACE_msg_set_task_category(task, "compute"); MSG_task_send(task, "master_mailbox"); } - - for (i = 0; i < slaves_count; i++) { - m_task_t finalize = MSG_task_create ("finalize", 0, 0, 0); - TRACE_msg_set_task_category(finalize, "finalize"); - MSG_task_send(finalize, "master_mailbox"); - } - + + for (i = 0; i < slaves_count; i++) { + m_task_t finalize = MSG_task_create("finalize", 0, 0, 0); + TRACE_msg_set_task_category(finalize, "finalize"); + MSG_task_send(finalize, "master_mailbox"); + } + return 0; } @@ -53,16 +56,16 @@ int slave(int argc, char *argv[]) m_task_t task = NULL; int res; - while(1) { + while (1) { res = MSG_task_receive(&(task), "master_mailbox"); - if (res != MSG_OK){ + if (res != MSG_OK) { INFO0("error"); break; } - if (!strcmp(MSG_task_get_name(task),"finalize")) { + if (!strcmp(MSG_task_get_name(task), "finalize")) { MSG_task_destroy(task); - break; + break; } INFO1("Executing task %f", MSG_task_get_compute_duration(task)); @@ -76,22 +79,22 @@ int slave(int argc, char *argv[]) /** Test function */ MSG_error_t test_all(const char *platform_file, - const char *application_file) + const char *application_file) { MSG_error_t res = MSG_OK; - { /* Simulation setting */ + { /* Simulation setting */ MSG_set_channel_number(0); MSG_create_environment(platform_file); } - { /* Application deployment */ + { /* Application deployment */ MSG_function_register("master", master); MSG_function_register("slave", slave); MSG_launch_application(application_file); } res = MSG_main(); - - INFO1("Simulation time %g",MSG_get_clock()); + + INFO1("Simulation time %g", MSG_get_clock()); return res; } @@ -101,28 +104,27 @@ int main(int argc, char *argv[]) { MSG_error_t res = MSG_OK; - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); if (argc < 3) { - printf ("Usage: %s platform_file deployment_file\n",argv[0]); - printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]); - exit(1); + printf("Usage: %s platform_file deployment_file\n", argv[0]); + printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); } - //starting the simulation tracing - TRACE_start (); + TRACE_start(); //declaring user categories - TRACE_category ("compute"); - TRACE_category ("finalize"); + TRACE_category("compute"); + TRACE_category("finalize"); - res = test_all(argv[1],argv[2]); + res = test_all(argv[1], argv[2]); MSG_clean(); //ending the simulation tracing TRACE_end(); - if(res==MSG_OK) + if (res == MSG_OK) return 0; else return 1; -} /* end_of_main */ +} /* end_of_main */ diff --git a/examples/msg/tracing/volume.c b/examples/msg/tracing/volume.c index c8ded0cae5..7210fc5281 100644 --- a/examples/msg/tracing/volume.c +++ b/examples/msg/tracing/volume.c @@ -7,22 +7,24 @@ #include #include "msg/msg.h" -#include "xbt/sysdep.h" /* calloc, printf */ +#include "xbt/sysdep.h" /* calloc, printf */ /* Create a log channel to have nice outputs. */ #include "xbt/log.h" #include "xbt/asserts.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); int master(int argc, char *argv[]); int slave(int argc, char *argv[]); -MSG_error_t test_all(const char *platform_file, const char *application_file); +MSG_error_t test_all(const char *platform_file, + const char *application_file); /** Emitter function */ int master(int argc, char *argv[]) { //defining the category of the master process - TRACE_msg_set_process_category (MSG_process_self(), "master"); + TRACE_msg_set_process_category(MSG_process_self(), "master"); long number_of_tasks = atol(argv[1]); long slaves_count = atol(argv[4]); @@ -30,27 +32,27 @@ int master(int argc, char *argv[]) int c = 10000000; int i; - for (i = 0; i < number_of_tasks; i++){ + for (i = 0; i < number_of_tasks; i++) { m_task_t task = NULL; - task = MSG_task_create ("task_compute", p, c, NULL); - TRACE_msg_set_task_category (task, "compute"); + task = MSG_task_create("task_compute", p, c, NULL); + TRACE_msg_set_task_category(task, "compute"); MSG_task_send(task, "master_mailbox"); task = NULL; - task = MSG_task_create ("task_request", p, c, NULL); - TRACE_msg_set_task_category (task, "request"); + task = MSG_task_create("task_request", p, c, NULL); + TRACE_msg_set_task_category(task, "request"); MSG_task_send(task, "master_mailbox"); task = NULL; - task = MSG_task_create ("task_data", p, c, NULL); - TRACE_msg_set_task_category (task, "data"); + task = MSG_task_create("task_data", p, c, NULL); + TRACE_msg_set_task_category(task, "data"); MSG_task_send(task, "master_mailbox"); } - - for (i = 0; i < slaves_count; i++) { - m_task_t finalize = MSG_task_create ("finalize", 0, 1000, 0); - TRACE_msg_set_task_category(finalize, "finalize"); - MSG_task_send(finalize, "master_mailbox"); - } - + + for (i = 0; i < slaves_count; i++) { + m_task_t finalize = MSG_task_create("finalize", 0, 1000, 0); + TRACE_msg_set_task_category(finalize, "finalize"); + MSG_task_send(finalize, "master_mailbox"); + } + return 0; } @@ -58,17 +60,17 @@ int master(int argc, char *argv[]) int slave(int argc, char *argv[]) { //defining the category of this slave process - TRACE_msg_set_process_category (MSG_process_self(), "slave"); + TRACE_msg_set_process_category(MSG_process_self(), "slave"); m_task_t task = NULL; int res; - while(1) { + while (1) { res = MSG_task_receive(&(task), "master_mailbox"); - if (!strcmp(MSG_task_get_name(task),"finalize")) { + if (!strcmp(MSG_task_get_name(task), "finalize")) { MSG_task_destroy(task); - break; + break; } MSG_task_execute(task); @@ -80,22 +82,22 @@ int slave(int argc, char *argv[]) /** Test function */ MSG_error_t test_all(const char *platform_file, - const char *application_file) + const char *application_file) { MSG_error_t res = MSG_OK; - { /* Simulation setting */ + { /* Simulation setting */ MSG_set_channel_number(0); MSG_create_environment(platform_file); } - { /* Application deployment */ + { /* Application deployment */ MSG_function_register("master", master); MSG_function_register("slave", slave); MSG_launch_application(application_file); } res = MSG_main(); - - INFO1("Simulation time %g",MSG_get_clock()); + + INFO1("Simulation time %g", MSG_get_clock()); return res; } @@ -105,37 +107,36 @@ int main(int argc, char *argv[]) { MSG_error_t res = MSG_OK; - MSG_global_init(&argc,argv); + MSG_global_init(&argc, argv); if (argc < 3) { - printf ("Usage: %s platform_file deployment_file\n",argv[0]); - printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]); - exit(1); + printf("Usage: %s platform_file deployment_file\n", argv[0]); + printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]); + exit(1); } - //starting the simulation tracing with the TRACE_VOLUME mask // - the communication volume among processes expects that: // - the processes involved have a category // - the tasks sent have a category - TRACE_start (); + TRACE_start(); //declaring user categories (for tasks) - TRACE_category ("compute"); - TRACE_category ("request"); - TRACE_category ("data"); - TRACE_category ("finalize"); + TRACE_category("compute"); + TRACE_category("request"); + TRACE_category("data"); + TRACE_category("finalize"); //declaring user categories (for processes) - TRACE_category ("master"); - TRACE_category ("slave"); + TRACE_category("master"); + TRACE_category("slave"); - res = test_all(argv[1],argv[2]); + res = test_all(argv[1], argv[2]); MSG_clean(); //ending the simulation tracing TRACE_end(); - if(res==MSG_OK) + if (res == MSG_OK) return 0; else return 1; -} /* end_of_main */ +} /* end_of_main */ diff --git a/examples/simdag/dax/dax_test.c b/examples/simdag/dax/dax_test.c index 464531d719..8ae9424c22 100644 --- a/examples/simdag/dax/dax_test.c +++ b/examples/simdag/dax/dax_test.c @@ -25,7 +25,8 @@ static int name_compare_hosts(const void *n1, const void *n2) return strcmp(name1, name2); } -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ xbt_dynar_t dax, changed; unsigned int cursor; SD_task_t task; @@ -36,14 +37,19 @@ int main(int argc, char **argv) { /* Check our arguments */ if (argc < 3) { INFO1("Usage: %s platform_file dax_file [trace_file]", argv[0]); - INFO1("example: %s ../sd_platform.xml Montage_50.xml Montage_50.mytrace", argv[0]); + INFO1 + ("example: %s ../sd_platform.xml Montage_50.xml Montage_50.mytrace", + argv[0]); exit(1); } char *tracefilename; if (argc == 3) { - char *last=strrchr(argv[2],'.'); + char *last = strrchr(argv[2], '.'); - tracefilename=bprintf("%.*s.trace",(int)(last==NULL?strlen(argv[2]):last-argv[2]),argv[2]); + tracefilename = + bprintf("%.*s.trace", + (int) (last == NULL ? strlen(argv[2]) : last - argv[2]), + argv[2]); } else { tracefilename = xbt_strdup(argv[3]); } @@ -52,67 +58,77 @@ int main(int argc, char **argv) { SD_create_environment(argv[1]); /* load the DAX file */ - dax=SD_daxload(argv[2]); + dax = SD_daxload(argv[2]); /* Display all the tasks */ - INFO0("------------------- Display all tasks of the loaded DAG ---------------------------"); - xbt_dynar_foreach(dax,cursor,task) { + INFO0 + ("------------------- Display all tasks of the loaded DAG ---------------------------"); + xbt_dynar_foreach(dax, cursor, task) { SD_task_dump(task); } - FILE *dotout = fopen("dax.dot","w"); - fprintf(dotout,"digraph A {\n"); - xbt_dynar_foreach(dax,cursor,task) { - SD_task_dotty(task,dotout); + FILE *dotout = fopen("dax.dot", "w"); + fprintf(dotout, "digraph A {\n"); + xbt_dynar_foreach(dax, cursor, task) { + SD_task_dotty(task, dotout); } - fprintf(dotout,"}\n"); + fprintf(dotout, "}\n"); fclose(dotout); /* Schedule them all on the first workstation */ INFO0("------------------- Schedule tasks ---------------------------"); - const SD_workstation_t *ws_list = SD_workstation_get_list(); + const SD_workstation_t *ws_list = SD_workstation_get_list(); int totalHosts = SD_workstation_get_number(); qsort((void *) ws_list, totalHosts, sizeof(SD_workstation_t), name_compare_hosts); int count = SD_workstation_get_number(); - xbt_dynar_foreach(dax,cursor,task) { + xbt_dynar_foreach(dax, cursor, task) { if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) { - if (!strcmp(SD_task_get_name(task),"end")) - SD_task_schedulel(task,1,ws_list[0]); + if (!strcmp(SD_task_get_name(task), "end")) + SD_task_schedulel(task, 1, ws_list[0]); else - SD_task_schedulel(task,1,ws_list[cursor%count]); + SD_task_schedulel(task, 1, ws_list[cursor % count]); } } - INFO0("------------------- Run the schedule ---------------------------"); + INFO0 + ("------------------- Run the schedule ---------------------------"); changed = SD_simulate(-1); xbt_dynar_free_container(&changed); - INFO0("------------------- Produce the trace file---------------------------"); - INFO1("Producing the trace of the run into %s",tracefilename); - FILE*out = fopen(tracefilename,"w"); - xbt_assert1(out,"Cannot write to %s",tracefilename); + INFO0 + ("------------------- Produce the trace file---------------------------"); + INFO1("Producing the trace of the run into %s", tracefilename); + FILE *out = fopen(tracefilename, "w"); + xbt_assert1(out, "Cannot write to %s", tracefilename); free(tracefilename); - xbt_dynar_foreach(dax,cursor,task) { + xbt_dynar_foreach(dax, cursor, task) { int kind = SD_task_get_kind(task); SD_workstation_t *wsl = SD_task_get_workstation_list(task); switch (kind) { case SD_TASK_COMP_SEQ: - fprintf(out,"[%f] %s compute %f # %s\n",SD_task_get_start_time(task), - SD_workstation_get_name(wsl[0]),SD_task_get_amount(task), - SD_task_get_name(task)); + fprintf(out, "[%f] %s compute %f # %s\n", + SD_task_get_start_time(task), + SD_workstation_get_name(wsl[0]), SD_task_get_amount(task), + SD_task_get_name(task)); break; case SD_TASK_COMM_E2E: - fprintf(out,"[%f] %s send %s %f # %s\n",SD_task_get_start_time(task), - SD_workstation_get_name(wsl[0]),SD_workstation_get_name(wsl[1]), - SD_task_get_amount(task), SD_task_get_name(task)); - fprintf(out,"[%f] %s recv %s %f # %s\n",SD_task_get_finish_time(task), - SD_workstation_get_name(wsl[1]),SD_workstation_get_name(wsl[0]), - SD_task_get_amount(task), SD_task_get_name(task)); + fprintf(out, "[%f] %s send %s %f # %s\n", + SD_task_get_start_time(task), + SD_workstation_get_name(wsl[0]), + SD_workstation_get_name(wsl[1]), SD_task_get_amount(task), + SD_task_get_name(task)); + fprintf(out, "[%f] %s recv %s %f # %s\n", + SD_task_get_finish_time(task), + SD_workstation_get_name(wsl[1]), + SD_workstation_get_name(wsl[0]), SD_task_get_amount(task), + SD_task_get_name(task)); break; default: - xbt_die(bprintf("Task %s is of unknown kind %d",SD_task_get_name(task),SD_task_get_kind(task))); + xbt_die(bprintf + ("Task %s is of unknown kind %d", SD_task_get_name(task), + SD_task_get_kind(task))); } SD_task_destroy(task); } diff --git a/examples/simdag/dot/dot_test.c b/examples/simdag/dot/dot_test.c index 23a8c2c194..4a6da7bf27 100644 --- a/examples/simdag/dot/dot_test.c +++ b/examples/simdag/dot/dot_test.c @@ -16,97 +16,111 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this SimDag example"); -int main(int argc, char **argv) { - xbt_dynar_t dot, changed; - unsigned int cursor; - SD_task_t task; - - /* initialisation of SD */ - SD_init(&argc, argv); - - /* Check our arguments */ - if (argc < 3) { - INFO1("Usage: %s platform_file dot_file [trace_file]", argv[0]); - INFO1("example: %s ../2clusters.xml dag.dot dag.mytrace", argv[0]); - exit(1); +int main(int argc, char **argv) +{ + xbt_dynar_t dot, changed; + unsigned int cursor; + SD_task_t task; + + /* initialisation of SD */ + SD_init(&argc, argv); + + /* Check our arguments */ + if (argc < 3) { + INFO1("Usage: %s platform_file dot_file [trace_file]", argv[0]); + INFO1("example: %s ../2clusters.xml dag.dot dag.mytrace", argv[0]); + exit(1); + } + char *tracefilename; + if (argc == 3) { + char *last = strrchr(argv[2], '.'); + + tracefilename = + bprintf("%.*s.trace", + (int) (last == NULL ? strlen(argv[2]) : last - argv[2]), + argv[2]); + } else { + tracefilename = xbt_strdup(argv[3]); + } + + /* creation of the environment */ + SD_create_environment(argv[1]); + + /* load the DOT file */ + dot = SD_dotload(argv[2]); + + /* Display all the tasks */ + INFO0 + ("------------------- Display all tasks of the loaded DAG ---------------------------"); + xbt_dynar_foreach(dot, cursor, task) { + SD_task_dump(task); + } + + FILE *dotout = fopen("dot.dot", "w"); + fprintf(dotout, "digraph A {\n"); + xbt_dynar_foreach(dot, cursor, task) { + SD_task_dotty(task, dotout); + } + fprintf(dotout, "}\n"); + fclose(dotout); + + /* Schedule them all on the first workstation */ + INFO0("------------------- Schedule tasks ---------------------------"); + const SD_workstation_t *ws_list = SD_workstation_get_list(); + + int count = SD_workstation_get_number(); + xbt_dynar_foreach(dot, cursor, task) { + if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) { + if (!strcmp(SD_task_get_name(task), "end")) + SD_task_schedulel(task, 1, ws_list[0]); + else + SD_task_schedulel(task, 1, ws_list[cursor % count]); } - char *tracefilename; - if (argc == 3) { - char *last=strrchr(argv[2],'.'); - - tracefilename=bprintf("%.*s.trace",(int)(last==NULL?strlen(argv[2]):last-argv[2]),argv[2]); - } else { - tracefilename = xbt_strdup(argv[3]); - } - - /* creation of the environment */ - SD_create_environment(argv[1]); - - /* load the DOT file */ - dot=SD_dotload(argv[2]); - - /* Display all the tasks */ - INFO0("------------------- Display all tasks of the loaded DAG ---------------------------"); - xbt_dynar_foreach(dot,cursor,task) { - SD_task_dump(task); - } - - FILE *dotout = fopen("dot.dot","w"); - fprintf(dotout,"digraph A {\n"); - xbt_dynar_foreach(dot,cursor,task) { - SD_task_dotty(task,dotout); - } - fprintf(dotout,"}\n"); - fclose(dotout); - - /* Schedule them all on the first workstation */ - INFO0("------------------- Schedule tasks ---------------------------"); - const SD_workstation_t *ws_list = SD_workstation_get_list(); - - int count = SD_workstation_get_number(); - xbt_dynar_foreach(dot,cursor,task) { - if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) { - if (!strcmp(SD_task_get_name(task),"end")) - SD_task_schedulel(task,1,ws_list[0]); - else - SD_task_schedulel(task,1,ws_list[cursor%count]); - } - } - - INFO0("------------------- Run the schedule ---------------------------"); - changed = SD_simulate(-1); - xbt_dynar_free_container(&changed); - INFO0("------------------- Produce the trace file---------------------------"); - INFO1("Producing the trace of the run into %s",tracefilename); - FILE*out = fopen(tracefilename,"w"); - xbt_assert1(out,"Cannot write to %s",tracefilename); - free(tracefilename); - - xbt_dynar_foreach(dot,cursor,task) { - int kind = SD_task_get_kind(task); - SD_workstation_t *wsl = SD_task_get_workstation_list(task); - switch (kind) { - case SD_TASK_COMP_SEQ: - fprintf(out,"[%f] %s compute %f # %s\n",SD_task_get_start_time(task), - SD_workstation_get_name(wsl[0]),SD_task_get_amount(task), - SD_task_get_name(task)); - break; - case SD_TASK_COMM_E2E: - fprintf(out,"[%f] %s send %s %f # %s\n",SD_task_get_start_time(task), - SD_workstation_get_name(wsl[0]),SD_workstation_get_name(wsl[1]), - SD_task_get_amount(task), SD_task_get_name(task)); - fprintf(out,"[%f] %s recv %s %f # %s\n",SD_task_get_finish_time(task), - SD_workstation_get_name(wsl[1]),SD_workstation_get_name(wsl[0]), - SD_task_get_amount(task), SD_task_get_name(task)); - break; - default: - xbt_die(bprintf("Task %s is of unknown kind %d",SD_task_get_name(task),SD_task_get_kind(task))); - } - SD_task_destroy(task); + } + + INFO0 + ("------------------- Run the schedule ---------------------------"); + changed = SD_simulate(-1); + xbt_dynar_free_container(&changed); + INFO0 + ("------------------- Produce the trace file---------------------------"); + INFO1("Producing the trace of the run into %s", tracefilename); + FILE *out = fopen(tracefilename, "w"); + xbt_assert1(out, "Cannot write to %s", tracefilename); + free(tracefilename); + + xbt_dynar_foreach(dot, cursor, task) { + int kind = SD_task_get_kind(task); + SD_workstation_t *wsl = SD_task_get_workstation_list(task); + switch (kind) { + case SD_TASK_COMP_SEQ: + fprintf(out, "[%f] %s compute %f # %s\n", + SD_task_get_start_time(task), + SD_workstation_get_name(wsl[0]), SD_task_get_amount(task), + SD_task_get_name(task)); + break; + case SD_TASK_COMM_E2E: + fprintf(out, "[%f] %s send %s %f # %s\n", + SD_task_get_start_time(task), + SD_workstation_get_name(wsl[0]), + SD_workstation_get_name(wsl[1]), SD_task_get_amount(task), + SD_task_get_name(task)); + fprintf(out, "[%f] %s recv %s %f # %s\n", + SD_task_get_finish_time(task), + SD_workstation_get_name(wsl[1]), + SD_workstation_get_name(wsl[0]), SD_task_get_amount(task), + SD_task_get_name(task)); + break; + default: + xbt_die(bprintf + ("Task %s is of unknown kind %d", SD_task_get_name(task), + SD_task_get_kind(task))); } - fclose(out); + SD_task_destroy(task); + } + fclose(out); - /* exit */ - SD_exit(); - return 0; + /* exit */ + SD_exit(); + return 0; } diff --git a/examples/simdag/scheduling/minmin_test.c b/examples/simdag/scheduling/minmin_test.c index 72ee23b1d6..7fb1ccab51 100644 --- a/examples/simdag/scheduling/minmin_test.c +++ b/examples/simdag/scheduling/minmin_test.c @@ -18,138 +18,144 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test, typedef struct _WorkstationAttribute *WorkstationAttribute; struct _WorkstationAttribute { - /* Earliest time at wich a workstation is ready to execute a task*/ - double available_at; + /* Earliest time at wich a workstation is ready to execute a task */ + double available_at; }; -static void SD_workstation_allocate_attribute(SD_workstation_t workstation){ - void *data; - data = calloc(1,sizeof(struct _WorkstationAttribute)); - SD_workstation_set_data(workstation, data); +static void SD_workstation_allocate_attribute(SD_workstation_t workstation) +{ + void *data; + data = calloc(1, sizeof(struct _WorkstationAttribute)); + SD_workstation_set_data(workstation, data); } -static void SD_workstation_free_attribute(SD_workstation_t workstation){ - free(SD_workstation_get_data(workstation)); - SD_workstation_set_data(workstation, NULL); +static void SD_workstation_free_attribute(SD_workstation_t workstation) +{ + free(SD_workstation_get_data(workstation)); + SD_workstation_set_data(workstation, NULL); } -static double SD_workstation_get_available_at( SD_workstation_t workstation){ - WorkstationAttribute attr = - (WorkstationAttribute) SD_workstation_get_data(workstation); - return attr->available_at; +static double SD_workstation_get_available_at(SD_workstation_t workstation) +{ + WorkstationAttribute attr = + (WorkstationAttribute) SD_workstation_get_data(workstation); + return attr->available_at; } static void SD_workstation_set_available_at(SD_workstation_t workstation, - double time){ - WorkstationAttribute attr = - (WorkstationAttribute) SD_workstation_get_data(workstation); - attr->available_at=time; - SD_workstation_set_data(workstation, attr); + double time) +{ + WorkstationAttribute attr = + (WorkstationAttribute) SD_workstation_get_data(workstation); + attr->available_at = time; + SD_workstation_set_data(workstation, attr); } -static xbt_dynar_t get_ready_tasks(xbt_dynar_t dax){ +static xbt_dynar_t get_ready_tasks(xbt_dynar_t dax) +{ unsigned int i; xbt_dynar_t ready_tasks; SD_task_t task; - ready_tasks= xbt_dynar_new(sizeof(SD_task_t), NULL); - xbt_dynar_foreach(dax, i, task){ + ready_tasks = xbt_dynar_new(sizeof(SD_task_t), NULL); + xbt_dynar_foreach(dax, i, task) { if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ && - SD_task_get_state(task) == SD_SCHEDULABLE){ + SD_task_get_state(task) == SD_SCHEDULABLE) { xbt_dynar_push(ready_tasks, &task); } } DEBUG1("There are %lu ready tasks", xbt_dynar_length(ready_tasks)); - + return ready_tasks; } -static double finish_on_at(SD_task_t task, SD_workstation_t workstation){ +static double finish_on_at(SD_task_t task, SD_workstation_t workstation) +{ unsigned int i; - double data_available=0.; - double redist_time=0; + double data_available = 0.; + double redist_time = 0; double last_data_available; - SD_task_t parent,grand_parent; + SD_task_t parent, grand_parent; xbt_dynar_t parents, grand_parents; - + int grand_parent_nworkstations; SD_workstation_t *grand_parent_workstation_list; - + parents = SD_task_get_parents(task); - + if (xbt_dynar_length(parents)) { /* compute last_data_available */ - last_data_available=-1.0; - xbt_dynar_foreach(parents, i, parent){ - + last_data_available = -1.0; + xbt_dynar_foreach(parents, i, parent) { + /* normal case */ if (SD_task_get_kind(parent) == SD_TASK_COMM_E2E) { - grand_parents = SD_task_get_parents(parent); - - if (xbt_dynar_length(grand_parents) > 1) { - ERROR1("Warning: transfer %s has 2 parents", - SD_task_get_name(parent)); - } - xbt_dynar_get_cpy(grand_parents, 0, &grand_parent); - - grand_parent_nworkstations = - SD_task_get_workstation_count(grand_parent); - grand_parent_workstation_list = - SD_task_get_workstation_list(grand_parent); - /* Estimate the redistribution time from this parent */ - redist_time = - SD_route_get_communication_time(grand_parent_workstation_list[0], - workstation, - SD_task_get_amount(parent)); - data_available = - SD_task_get_finish_time(grand_parent) + redist_time; - - xbt_dynar_free_container(&grand_parents); + grand_parents = SD_task_get_parents(parent); + + if (xbt_dynar_length(grand_parents) > 1) { + ERROR1("Warning: transfer %s has 2 parents", + SD_task_get_name(parent)); + } + xbt_dynar_get_cpy(grand_parents, 0, &grand_parent); + + grand_parent_nworkstations = + SD_task_get_workstation_count(grand_parent); + grand_parent_workstation_list = + SD_task_get_workstation_list(grand_parent); + /* Estimate the redistribution time from this parent */ + redist_time = + SD_route_get_communication_time(grand_parent_workstation_list + [0], workstation, + SD_task_get_amount(parent)); + data_available = + SD_task_get_finish_time(grand_parent) + redist_time; + + xbt_dynar_free_container(&grand_parents); } - + /* no transfer, control dependency */ if (SD_task_get_kind(parent) == SD_TASK_COMP_SEQ) { - data_available = SD_task_get_finish_time(parent); + data_available = SD_task_get_finish_time(parent); } - + if (last_data_available < data_available) - last_data_available = data_available; - + last_data_available = data_available; + } - + xbt_dynar_free_container(&parents); - + return MAX(SD_workstation_get_available_at(workstation), - last_data_available) + - SD_workstation_get_computation_time(workstation, - SD_task_get_amount(task)); + last_data_available) + + SD_workstation_get_computation_time(workstation, + SD_task_get_amount(task)); } else { xbt_dynar_free_container(&parents); - - return SD_workstation_get_available_at(workstation)+ - SD_workstation_get_computation_time(workstation, - SD_task_get_amount(task)); + + return SD_workstation_get_available_at(workstation) + + SD_workstation_get_computation_time(workstation, + SD_task_get_amount(task)); } } -static SD_workstation_t SD_task_get_best_workstation (SD_task_t task){ +static SD_workstation_t SD_task_get_best_workstation(SD_task_t task) +{ int i; - double EFT, min_EFT=-1.0; - const SD_workstation_t *workstations = SD_workstation_get_list (); - int nworkstations = SD_workstation_get_number (); + double EFT, min_EFT = -1.0; + const SD_workstation_t *workstations = SD_workstation_get_list(); + int nworkstations = SD_workstation_get_number(); SD_workstation_t best_workstation; - + best_workstation = workstations[0]; min_EFT = finish_on_at(task, workstations[0]); - - for (i=1; i\n"); - fprintf(out,"\n"); - fprintf(out," \n"); - fprintf(out," \n"); - fprintf(out," \n"); - fprintf(out," \n", - nworkstations); - fprintf(out," \n"); - fprintf(out," \n"); - fprintf(out," \n"); - - xbt_dynar_foreach(dax, i, task){ - fprintf(out," \n"); - fprintf(out," \n", - SD_task_get_name(task)); - fprintf(out," \n"); + fprintf(out, "\n"); + fprintf(out, " \n"); + fprintf(out, " \n"); + fprintf(out, " \n"); + fprintf(out, + " \n", + nworkstations); + fprintf(out, " \n"); + fprintf(out, " \n"); + fprintf(out, " \n"); + + xbt_dynar_foreach(dax, i, task) { + fprintf(out, " \n"); + fprintf(out, " \n", + SD_task_get_name(task)); + fprintf(out, " \n"); + fprintf(out, "computation\"/>\n"); if (SD_task_get_kind(task) == SD_TASK_COMM_E2E) - fprintf(out,"transfer\"/>\n"); - - fprintf(out," \n", - SD_task_get_start_time(task)); - fprintf(out," \n", - SD_task_get_finish_time(task)); - fprintf(out," \n"); - + fprintf(out, "transfer\"/>\n"); + + fprintf(out, + " \n", + SD_task_get_start_time(task)); + fprintf(out, + " \n", + SD_task_get_finish_time(task)); + fprintf(out, " \n"); + current_nworkstations = SD_task_get_workstation_count(task); - - fprintf(out," \n", - current_nworkstations); - - fprintf(out," \n"); + + fprintf(out, + " \n", + current_nworkstations); + + fprintf(out, " \n"); list = SD_task_get_workstation_list(task); - for (j=0;j\n",k); - fprintf(out, - " \n"); - break; - } + for (j = 0; j < current_nworkstations; j++) { + for (k = 0; k < nworkstations; k++) { + if (!strcmp(SD_workstation_get_name(workstations[k]), + SD_workstation_get_name(list[j]))) { + fprintf(out, " \n", + k); + fprintf(out, + " \n"); + break; + } } } - fprintf(out," \n"); - fprintf(out," \n"); - fprintf(out," \n"); + fprintf(out, " \n"); + fprintf(out, " \n"); + fprintf(out, " \n"); } - fprintf(out," \n"); - fprintf(out,"\n"); + fprintf(out, " \n"); + fprintf(out, "\n"); } -int main(int argc, char **argv) { - unsigned int cursor, selected_idx=0; +int main(int argc, char **argv) +{ + unsigned int cursor, selected_idx = 0; double finish_time, min_finish_time = -1.0; - SD_task_t task, selected_task=NULL; + SD_task_t task, selected_task = NULL; xbt_dynar_t ready_tasks; - SD_workstation_t workstation, selected_workstation=NULL; - int total_nworkstations=0; - const SD_workstation_t *workstations=NULL; + SD_workstation_t workstation, selected_workstation = NULL; + int total_nworkstations = 0; + const SD_workstation_t *workstations = NULL; xbt_dynar_t dax, changed; - FILE *out=NULL; + FILE *out = NULL; /* initialization of SD */ SD_init(&argc, argv); @@ -237,17 +250,19 @@ int main(int argc, char **argv) { /* Check our arguments */ if (argc < 3) { INFO1("Usage: %s platform_file dax_file [jedule_file]", argv[0]); - INFO1("example: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", - argv[0]); + INFO1 + ("example: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", + argv[0]); exit(1); } char *tracefilename; if (argc == 3) { - char *last=strrchr(argv[2],'.'); + char *last = strrchr(argv[2], '.'); - tracefilename=bprintf("%.*s.jed", - (int)(last==NULL?strlen(argv[2]):last-argv[2]), - argv[2]); + tracefilename = bprintf("%.*s.jed", + (int) (last == + NULL ? strlen(argv[2]) : last - + argv[2]), argv[2]); } else { tracefilename = xbt_strdup(argv[3]); } @@ -258,26 +273,26 @@ int main(int argc, char **argv) { /* Allocating the workstation attribute */ total_nworkstations = SD_workstation_get_number(); workstations = SD_workstation_get_list(); - - for(cursor=0; cursor0){ - for(i=0;i<2; i++){ + while (xbt_dynar_length(changed_tasks = SD_simulate(-1.0)) > 0) { + for (i = 0; i < 2; i++) { task = SD_workstation_get_current_task(workstations[i]); if (task) - kind = SD_task_get_kind(task); - else{ - INFO1("There is no task running on %s", - SD_workstation_get_name(workstations[i])); - continue; + kind = SD_task_get_kind(task); + else { + INFO1("There is no task running on %s", + SD_workstation_get_name(workstations[i])); + continue; } - switch (kind){ + switch (kind) { case SD_TASK_COMP_SEQ: - INFO2("%s is currently running on %s (SD_TASK_COMP_SEQ)", - SD_task_get_name(task), - SD_workstation_get_name(workstations[i])); - break; + INFO2("%s is currently running on %s (SD_TASK_COMP_SEQ)", + SD_task_get_name(task), + SD_workstation_get_name(workstations[i])); + break; case SD_TASK_COMM_E2E: - INFO2("%s is currently running on %s (SD_TASK_COMM_E2E)", - SD_task_get_name(task), - SD_workstation_get_name(workstations[i])); - break; + INFO2("%s is currently running on %s (SD_TASK_COMM_E2E)", + SD_task_get_name(task), + SD_workstation_get_name(workstations[i])); + break; case SD_TASK_NOT_TYPED: - INFO1("Task running on %s has no type", - SD_workstation_get_name(workstations[i])); - break; + INFO1("Task running on %s has no type", + SD_workstation_get_name(workstations[i])); + break; default: - ERROR0("Shouldn't be here"); + ERROR0("Shouldn't be here"); } } xbt_dynar_free_container(&changed_tasks); diff --git a/examples/simdag/sd_test.c b/examples/simdag/sd_test.c index 1aa17d15f0..886f80b5e8 100644 --- a/examples/simdag/sd_test.c +++ b/examples/simdag/sd_test.c @@ -63,17 +63,20 @@ int main(int argc, char **argv) computation_amount2 = 1000000; communication_amount12 = 2000000; communication_amount21 = 3000000; - INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1, - SD_workstation_get_computation_time(w1, computation_amount1)); - INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2, - SD_workstation_get_computation_time(w2, computation_amount2)); + INFO3("Computation time for %f flops on %s: %f", computation_amount1, + name1, SD_workstation_get_computation_time(w1, + computation_amount1)); + INFO3("Computation time for %f flops on %s: %f", computation_amount2, + name2, SD_workstation_get_computation_time(w2, + computation_amount2)); INFO2("Route between %s and %s:", name1, name2); route = SD_route_get_list(w1, w2); route_size = SD_route_get_size(w1, w2); for (i = 0; i < route_size; i++) { INFO3(" Link %s: latency = %f, bandwidth = %f", - SD_link_get_name(route[i]), SD_link_get_current_latency(route[i]), + SD_link_get_name(route[i]), + SD_link_get_current_latency(route[i]), SD_link_get_current_bandwidth(route[i])); } INFO2("Route latency = %f, route bandwidth = %f", @@ -162,8 +165,9 @@ int main(int argc, char **argv) /* estimated time */ task = taskD; INFO2("Estimated time for '%s': %f", SD_task_get_name(task), - SD_task_get_execution_time(task, workstation_number, workstation_list, - computation_amount, communication_amount)); + SD_task_get_execution_time(task, workstation_number, + workstation_list, computation_amount, + communication_amount)); /* let's launch the simulation! */ @@ -177,11 +181,10 @@ int main(int argc, char **argv) computation_amount, communication_amount, rate); changed_tasks = SD_simulate(-1.0); - xbt_dynar_foreach(changed_tasks, ctr, task){ - INFO3("Task '%s' start time: %f, finish time: %f", + xbt_dynar_foreach(changed_tasks, ctr, task) { + INFO3("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), - SD_task_get_start_time(task), - SD_task_get_finish_time(task)); + SD_task_get_start_time(task), SD_task_get_finish_time(task)); } xbt_dynar_get_cpy(changed_tasks, 0, &checkD); diff --git a/examples/simdag/sd_test2.c b/examples/simdag/sd_test2.c index 018486021a..cc86f17543 100644 --- a/examples/simdag/sd_test2.c +++ b/examples/simdag/sd_test2.c @@ -68,7 +68,8 @@ int main(int argc, char **argv) hosts = SD_workstation_get_list(); /* sorting hosts by hostname */ - qsort((void *) hosts, n_hosts, sizeof(SD_workstation_t), nameCompareHosts); + qsort((void *) hosts, n_hosts, sizeof(SD_workstation_t), + nameCompareHosts); /* creation of the tasks */ taskInit = SD_task_create("Initial", NULL, 1.0); @@ -176,11 +177,12 @@ int main(int argc, char **argv) /* scheduling the tasks */ - SD_task_schedule(taskInit, 1, hosts, SD_SCHED_NO_COST, SD_SCHED_NO_COST, -1.0); - SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, SD_SCHED_NO_COST, PtoPcomm1_table, - -1.0); - SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, SD_SCHED_NO_COST, PtoPcomm2_table, + SD_task_schedule(taskInit, 1, hosts, SD_SCHED_NO_COST, SD_SCHED_NO_COST, -1.0); + SD_task_schedule(PtoPComm1, 2, PtoPcomm1_hosts, SD_SCHED_NO_COST, + PtoPcomm1_table, -1.0); + SD_task_schedule(PtoPComm2, 2, PtoPcomm2_hosts, SD_SCHED_NO_COST, + PtoPcomm2_table, -1.0); SD_task_schedule(ParComp_wocomm, 5, ParComp_wocomm_hosts, ParComp_wocomm_cost, ParComp_wocomm_table, -1.0); SD_task_schedule(IntraRedist, 5, IntraRedist_hosts, IntraRedist_cost, @@ -191,7 +193,8 @@ int main(int argc, char **argv) InterRedist_table, -1.0); SD_task_schedule(ParComp_wcomm2, 5, ParComp_wcomm2_hosts, ParComp_wcomm2_cost, ParComp_wcomm2_table, -1.0); - SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost, SD_SCHED_NO_COST, -1.0); + SD_task_schedule(taskFinal, 1, &(hosts[9]), &final_cost, + SD_SCHED_NO_COST, -1.0); /* let's launch the simulation! */ changed_tasks = SD_simulate(-1.0); diff --git a/examples/simdag/sd_test_console.c b/examples/simdag/sd_test_console.c index 8e20d43f93..ad8d4b4998 100644 --- a/examples/simdag/sd_test_console.c +++ b/examples/simdag/sd_test_console.c @@ -63,17 +63,20 @@ int main(int argc, char **argv) computation_amount2 = 1000000; communication_amount12 = 2000000; communication_amount21 = 3000000; - INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1, - SD_workstation_get_computation_time(w1, computation_amount1)); - INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2, - SD_workstation_get_computation_time(w2, computation_amount2)); + INFO3("Computation time for %f flops on %s: %f", computation_amount1, + name1, SD_workstation_get_computation_time(w1, + computation_amount1)); + INFO3("Computation time for %f flops on %s: %f", computation_amount2, + name2, SD_workstation_get_computation_time(w2, + computation_amount2)); INFO2("Route between %s and %s:", name1, name2); route = SD_route_get_list(w1, w2); route_size = SD_route_get_size(w1, w2); for (i = 0; i < route_size; i++) { INFO3(" Link %s: latency = %f, bandwidth = %f", - SD_link_get_name(route[i]), SD_link_get_current_latency(route[i]), + SD_link_get_name(route[i]), + SD_link_get_current_latency(route[i]), SD_link_get_current_bandwidth(route[i])); } INFO2("Route latency = %f, route bandwidth = %f", @@ -162,8 +165,9 @@ int main(int argc, char **argv) /* estimated time */ task = taskD; INFO2("Estimated time for '%s': %f", SD_task_get_name(task), - SD_task_get_execution_time(task, workstation_number, workstation_list, - computation_amount, communication_amount)); + SD_task_get_execution_time(task, workstation_number, + workstation_list, computation_amount, + communication_amount)); /* let's launch the simulation! */ @@ -177,11 +181,10 @@ int main(int argc, char **argv) computation_amount, communication_amount, rate); changed_tasks = SD_simulate(-1.0); - xbt_dynar_foreach(changed_tasks, ctr, task){ - INFO3("Task '%s' start time: %f, finish time: %f", + xbt_dynar_foreach(changed_tasks, ctr, task) { + INFO3("Task '%s' start time: %f, finish time: %f", SD_task_get_name(task), - SD_task_get_start_time(task), - SD_task_get_finish_time(task)); + SD_task_get_start_time(task), SD_task_get_finish_time(task)); } xbt_dynar_get_cpy(changed_tasks, 0, &checkD); diff --git a/examples/smpi/allreduce.c b/examples/smpi/allreduce.c index 83e6b10c0b..72f5b61c70 100644 --- a/examples/smpi/allreduce.c +++ b/examples/smpi/allreduce.c @@ -26,32 +26,32 @@ **/ static int ibm_test(int rank, int size) { - int success = 1; + int success = 1; #define MAXLEN 10000 - int root = 0, i, j, k; - int out[MAXLEN]; - int in[MAXLEN]; - - for (j = 1; j <= MAXLEN; j *= 10) { - for (i = 0; i < j; i++) - out[i] = i; - - MPI_Allreduce(out, in, j, MPI_INT, MPI_SUM, MPI_COMM_WORLD); - MPI_Barrier(MPI_COMM_WORLD); - - if (rank == root) { - for (k = 0; k < j; k++) { - if (in[k] != k * size) { - printf("bad answer (%d) at index %d of %d (should be %d)", in[k], k, - j, k * size); - success = 0; - break; - } - } - } - } - return (success); + int root = 0, i, j, k; + int out[MAXLEN]; + int in[MAXLEN]; + + for (j = 1; j <= MAXLEN; j *= 10) { + for (i = 0; i < j; i++) + out[i] = i; + + MPI_Allreduce(out, in, j, MPI_INT, MPI_SUM, MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); + + if (rank == root) { + for (k = 0; k < j; k++) { + if (in[k] != k * size) { + printf("bad answer (%d) at index %d of %d (should be %d)", in[k], + k, j, k * size); + success = 0; + break; + } + } + } + } + return (success); } diff --git a/examples/smpi/alltoall2.c b/examples/smpi/alltoall2.c index a46f765dbb..ef2068e0a7 100644 --- a/examples/smpi/alltoall2.c +++ b/examples/smpi/alltoall2.c @@ -42,42 +42,44 @@ #define MAXLEN 10000 - -int main( int argc, char *argv[] ) + +int main(int argc, char *argv[]) { #define N 1000000 - int *out, *in,i,j,k; - int myself,tasks; - - out = malloc(N*sizeof(int)); - in = malloc(N*sizeof(int)); - if ((out==NULL) || (in==NULL)) { - printf("Error: cannot allocate N bytes for in or out arrays\n"); - exit(1); - } - MPI_Init( &argc,&argv ); - MPI_Comm_rank(MPI_COMM_WORLD,&myself); - MPI_Comm_size(MPI_COMM_WORLD,&tasks); - for(j=1;j<=MAXLEN;j*=10) { - if ( 0 == myself ) { - printf("* calling MPI_Alltoall with buffers of %d ints\n",j); - } - for(i=0;i bad answer (%d) at index %d of %d (should be %d)\n",myself,in[k+i*j],k+i*j,j*tasks,i); - break; - } - } - } - } - MPI_Barrier(MPI_COMM_WORLD); - if(myself==0) printf("TEST COMPLETE\n"); - MPI_Finalize(); - return EXIT_SUCCESS; + int *out, *in, i, j, k; + int myself, tasks; + + out = malloc(N * sizeof(int)); + in = malloc(N * sizeof(int)); + if ((out == NULL) || (in == NULL)) { + printf("Error: cannot allocate N bytes for in or out arrays\n"); + exit(1); + } + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myself); + MPI_Comm_size(MPI_COMM_WORLD, &tasks); + for (j = 1; j <= MAXLEN; j *= 10) { + if (0 == myself) { + printf("* calling MPI_Alltoall with buffers of %d ints\n", j); + } + for (i = 0; i < j * tasks; i++) + out[i] = myself; + + MPI_Alltoall(out, j, MPI_INT, in, j, MPI_INT, MPI_COMM_WORLD); + + for (i = 0; i < tasks; i++) { + for (k = 0; k < j; k++) { + if (in[k + i * j] != i) { + printf("<%d> bad answer (%d) at index %d of %d (should be %d)\n", + myself, in[k + i * j], k + i * j, j * tasks, i); + break; + } + } + } + } + MPI_Barrier(MPI_COMM_WORLD); + if (myself == 0) + printf("TEST COMPLETE\n"); + MPI_Finalize(); + return EXIT_SUCCESS; } diff --git a/examples/smpi/alltoall_basic.c b/examples/smpi/alltoall_basic.c index 56aa80e497..485752e2ef 100644 --- a/examples/smpi/alltoall_basic.c +++ b/examples/smpi/alltoall_basic.c @@ -15,48 +15,51 @@ #define EXIT_FAILURE 1 #endif -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { - int rank, size; - int i; - int *sb; - int *rb; - int status; - - MPI_Init(&argc,&argv); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); - MPI_Comm_size(MPI_COMM_WORLD,&size); - - sb = (int *)malloc(size*sizeof(int)); - if ( !sb ) { - perror( "can't allocate send buffer" );fflush(stderr); - MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE); - } - rb = (int *)malloc(size*sizeof(int)); - if ( !rb ) { - perror( "can't allocate recv buffer");fflush(stderr); - free(sb); - MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); - } - for ( i=0 ; i < size ; ++i ) { - sb[i] = rank + 1; - rb[i] = 0; - } - status = MPI_Alltoall(sb, 1, MPI_INT, rb, 1, MPI_INT, MPI_COMM_WORLD); + int rank, size; + int i; + int *sb; + int *rb; + int status; - printf("[%d] rcvbuf=[",rank); - for (i=0;i +#include #include #include @@ -53,7 +53,7 @@ static void print_buffer_int(void *buf, int len, char *msg, int rank) { int tmp, *v; - printf("**<%d> %s (#%d): ", rank, msg,len); + printf("**<%d> %s (#%d): ", rank, msg, len); for (tmp = 0; tmp < len; tmp++) { v = buf; printf("[%d]", v[tmp]); @@ -63,109 +63,109 @@ static void print_buffer_int(void *buf, int len, char *msg, int rank) } -int main( int argc, char **argv ) +int main(int argc, char **argv) { - MPI_Comm comm; - int *sbuf, *rbuf, *erbuf; - int rank, size; - int *sendcounts, *recvcounts, *rdispls, *sdispls; - int i, j, *p, err; - - MPI_Init( &argc, &argv ); - err = 0; - - comm = MPI_COMM_WORLD; - - /* Create the buffer */ - MPI_Comm_size( comm, &size ); - MPI_Comm_rank( comm, &rank ); - sbuf = (int *)malloc( size * size * sizeof(int) ); - rbuf = (int *)malloc( size * size * sizeof(int) ); - erbuf = (int *)malloc( size * size * sizeof(int) ); // expected - if (!sbuf || !rbuf) { - fprintf( stderr, "Could not allocated buffers!\n" ); - MPI_Abort( comm, 1 ); - } - - /* Load up the buffers */ - for (i=0; i got %d expected %d for %dth\n", - rank, p[j],(i*(i+1))/2 + j, j ); - err++; - } - } - } - - /* Summary */ - if ( err > 0) { - printf("<%d> Alltoallv test: failure (%d errors).\n",rank,err); - } - if ( 0==rank ) { - printf("* Alltoallv TEST COMPLETE.\n"); - } - free( sdispls ); - free( rdispls ); - free( recvcounts ); - free( sendcounts ); - free( rbuf ); - free( sbuf ); - - MPI_Barrier( MPI_COMM_WORLD); - MPI_Finalize(); - return 0; + MPI_Comm comm; + int *sbuf, *rbuf, *erbuf; + int rank, size; + int *sendcounts, *recvcounts, *rdispls, *sdispls; + int i, j, *p, err; + + MPI_Init(&argc, &argv); + err = 0; + + comm = MPI_COMM_WORLD; + + /* Create the buffer */ + MPI_Comm_size(comm, &size); + MPI_Comm_rank(comm, &rank); + sbuf = (int *) malloc(size * size * sizeof(int)); + rbuf = (int *) malloc(size * size * sizeof(int)); + erbuf = (int *) malloc(size * size * sizeof(int)); // expected + if (!sbuf || !rbuf) { + fprintf(stderr, "Could not allocated buffers!\n"); + MPI_Abort(comm, 1); + } + + /* Load up the buffers */ + for (i = 0; i < size * size; i++) { + sbuf[i] = i + 100 * rank; + rbuf[i] = -i; + erbuf[i] = -i; + } + + /* Create and load the arguments to alltoallv */ + sendcounts = (int *) malloc(size * sizeof(int)); + recvcounts = (int *) malloc(size * sizeof(int)); + rdispls = (int *) malloc(size * sizeof(int)); + sdispls = (int *) malloc(size * sizeof(int)); + if (!sendcounts || !recvcounts || !rdispls || !sdispls) { + fprintf(stderr, "Could not allocate arg items!\n"); + MPI_Abort(comm, 1); + } + for (i = 0; i < size; i++) { + sendcounts[i] = i; + recvcounts[i] = rank; + rdispls[i] = i * rank; + sdispls[i] = (i * (i + 1)) / 2; + } + + /* debug */ + /* + print_buffer_int( sbuf, size*size, strdup("sbuf:"),rank); + print_buffer_int( sendcounts, size, strdup("scount:"),rank); + print_buffer_int( recvcounts, size, strdup("rcount:"),rank); + print_buffer_int( sdispls, size, strdup("sdisp:"),rank); + print_buffer_int( rdispls, size, strdup("rdisp:"),rank); + */ + + + /* debug : erbuf */ + /* debug + for (i=0; i got %d expected %d for %dth\n", + rank, p[j], (i * (i + 1)) / 2 + j, j); + err++; + } + } + } + + /* Summary */ + if (err > 0) { + printf("<%d> Alltoallv test: failure (%d errors).\n", rank, err); + } + if (0 == rank) { + printf("* Alltoallv TEST COMPLETE.\n"); + } + free(sdispls); + free(rdispls); + free(recvcounts); + free(sendcounts); + free(rbuf); + free(sbuf); + + MPI_Barrier(MPI_COMM_WORLD); + MPI_Finalize(); + return 0; } diff --git a/examples/smpi/barrier.c b/examples/smpi/barrier.c index be4ded853d..568015ec72 100644 --- a/examples/smpi/barrier.c +++ b/examples/smpi/barrier.c @@ -8,27 +8,27 @@ #include -int main (int argc, char **argv) { - int size, rank; - int root=0; - int value; - double start_timer; +int main(int argc, char **argv) +{ + int size, rank; + int root = 0; + int value; + double start_timer; - MPI_Init(&argc, &argv); - MPI_Comm_size(MPI_COMM_WORLD, &size); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &size); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); start_timer = MPI_Wtime(); - MPI_Barrier( MPI_COMM_WORLD ); + MPI_Barrier(MPI_COMM_WORLD); - MPI_Barrier( MPI_COMM_WORLD ); + MPI_Barrier(MPI_COMM_WORLD); if (0 == rank) { - printf("... Barrier ....\n"); - printf("Elapsed=%lf s\n", MPI_Wtime() - start_timer); + printf("... Barrier ....\n"); + printf("Elapsed=%lf s\n", MPI_Wtime() - start_timer); } MPI_Finalize(); return 0; } - diff --git a/examples/smpi/bcast.c b/examples/smpi/bcast.c index ba172dd73d..72ad419524 100644 --- a/examples/smpi/bcast.c +++ b/examples/smpi/bcast.c @@ -28,7 +28,7 @@ int main(int argc, char **argv) } MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD); if (value != 17) { - printf("node %d has value %d after broadcast\n", rank, value); + printf("node %d has value %d after broadcast\n", rank, value); } MPI_Barrier(MPI_COMM_WORLD); diff --git a/examples/smpi/bcbench.c b/examples/smpi/bcbench.c index b603babe4e..75defac0eb 100644 --- a/examples/smpi/bcbench.c +++ b/examples/smpi/bcbench.c @@ -74,8 +74,9 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } seconds = - (double) (stop_time->tv_sec - start_time->tv_sec) + - (double) (stop_time->tv_usec - start_time->tv_usec) / ONE_MILLION; + (double) (stop_time->tv_sec - start_time->tv_sec) + + (double) (stop_time->tv_usec - + start_time->tv_usec) / ONE_MILLION; } free(buffer); diff --git a/examples/smpi/compute2.c b/examples/smpi/compute2.c index 4811b803fe..8f82144bc0 100644 --- a/examples/smpi/compute2.c +++ b/examples/smpi/compute2.c @@ -13,7 +13,7 @@ int main(int argc, char *argv[]) double d; MPI_Init(&argc, &argv); d = 2.0; -/* SMPI_DO_ONCE */{ +/* SMPI_DO_ONCE */ { for (i = 0; i < atoi(argv[1]); i++) { if (d < 10000) { d = d * d; diff --git a/examples/smpi/compute3.c b/examples/smpi/compute3.c index ed22bfce77..ad823a2c24 100644 --- a/examples/smpi/compute3.c +++ b/examples/smpi/compute3.c @@ -13,7 +13,7 @@ int main(int argc, char *argv[]) double d; MPI_Init(&argc, &argv); d = 2.0; -/* SMPI_DO_ONCE */{ +/* SMPI_DO_ONCE */ { for (i = 0; i < atoi(argv[1]); i++) { if (d < 10000) { d = d * d; @@ -23,7 +23,7 @@ int main(int argc, char *argv[]) } printf("%d %f\n", i, d); } -/* SMPI_DO_ONCE */{ +/* SMPI_DO_ONCE */ { for (i = 0; i < 2 * atoi(argv[1]); i++) { if (d < 10000) { d = d * d; diff --git a/examples/smpi/get_processor_name.c b/examples/smpi/get_processor_name.c index 21cdc54534..05a26164f2 100644 --- a/examples/smpi/get_processor_name.c +++ b/examples/smpi/get_processor_name.c @@ -7,7 +7,8 @@ #include #include -int main (int argc, char **argv) { +int main(int argc, char **argv) +{ int size, rank; char name[MPI_MAX_PROCESSOR_NAME]; @@ -17,7 +18,7 @@ int main (int argc, char **argv) { MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Get_processor_name(name,&len); + MPI_Get_processor_name(name, &len); printf("rank %d is running on host %s\n", rank, name); MPI_Finalize(); return 0; diff --git a/examples/smpi/mvmul.c b/examples/smpi/mvmul.c index 18b34203f4..a32812155f 100644 --- a/examples/smpi/mvmul.c +++ b/examples/smpi/mvmul.c @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) MPI_Status status; struct timeval *start_time = NULL, *stop_time = NULL; long parallel_usecs, parallel_usecs_total = - 0, sequential_usecs, sequential_usecs_total = 0; + 0, sequential_usecs, sequential_usecs_total = 0; MPI_Init(&argc, &argv); @@ -91,15 +91,16 @@ int main(int argc, char *argv[]) for (i = 1, j = n; i < size && j < N; i++, j += k) { k = N / size + ((i < (N % size)) ? 1 : 0); - MPI_Send(matrix + N * j, N * k, MPI_DOUBLE, i, 0, MPI_COMM_WORLD); + MPI_Send(matrix + N * j, N * k, MPI_DOUBLE, i, 0, + MPI_COMM_WORLD); MPI_Send(vector, N, MPI_DOUBLE, i, 0, MPI_COMM_WORLD); } // sanity check #ifdef DEBUG if (i != size || j != N) { - printf("index calc error: i = %d, size = %d, j = %d, N = %d\n", i, - size, j, N); + printf("index calc error: i = %d, size = %d, j = %d, N = %d\n", + i, size, j, N); MPI_Abort(MPI_COMM_WORLD, SANITY_ERROR); exit(SANITY_ERROR); } @@ -131,14 +132,15 @@ int main(int argc, char *argv[]) for (i = 1, j = n; i < size && j < N; i++, j += k) { k = N / size + ((i < (N % size)) ? 1 : 0); - MPI_Recv(vcalc + j, k, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &status); + MPI_Recv(vcalc + j, k, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, + &status); } // sanity check #ifdef DEBUG if (i != size || j != N) { - printf("index calc error 2: i = %d, size = %d, j = %d, N = %d\n", i, - size, j, N); + printf("index calc error 2: i = %d, size = %d, j = %d, N = %d\n", + i, size, j, N); MPI_Abort(MPI_COMM_WORLD, SANITY_ERROR); exit(SANITY_ERROR); } @@ -151,8 +153,8 @@ int main(int argc, char *argv[]) } parallel_usecs = - (stop_time->tv_sec * 1000000 + stop_time->tv_usec) - - (start_time->tv_sec * 1000000 + start_time->tv_usec); + (stop_time->tv_sec * 1000000 + stop_time->tv_usec) - + (start_time->tv_sec * 1000000 + start_time->tv_usec); if (-1 == gettimeofday(start_time, NULL)) { printf("couldn't set start_time on node 0!\n"); @@ -175,8 +177,8 @@ int main(int argc, char *argv[]) } sequential_usecs = - (stop_time->tv_sec * 1000000 + stop_time->tv_usec) - - (start_time->tv_sec * 1000000 + start_time->tv_usec); + (stop_time->tv_sec * 1000000 + stop_time->tv_usec) - + (start_time->tv_sec * 1000000 + start_time->tv_usec); // verify correctness for (i = 0; i < N && vcalc[i] == vcheck[i]; i++); @@ -185,11 +187,11 @@ int main(int argc, char *argv[]) if (i == N) { printf - ("ptime: %ld us, stime: %ld us, speedup: %.3f, nodes: %d, efficiency: %.3f\n", - parallel_usecs, sequential_usecs, - (double) sequential_usecs / (double) parallel_usecs, size, - (double) sequential_usecs / ((double) parallel_usecs * - (double) size)); + ("ptime: %ld us, stime: %ld us, speedup: %.3f, nodes: %d, efficiency: %.3f\n", + parallel_usecs, sequential_usecs, + (double) sequential_usecs / (double) parallel_usecs, size, + (double) sequential_usecs / ((double) parallel_usecs * + (double) size)); parallel_usecs_total += parallel_usecs; sequential_usecs_total += sequential_usecs; @@ -213,14 +215,15 @@ int main(int argc, char *argv[]) printf("prog: blocking, "); if (0 < successful_iterations) { printf - ("iterations: %d, avg. ptime: %.3f us, avg. stime: %.3f us, avg. speedup: %.3f, nodes: %d, avg. efficiency: %.3f\n", - successful_iterations, - (double) parallel_usecs_total / (double) successful_iterations, - (double) sequential_usecs_total / (double) successful_iterations, - (double) sequential_usecs_total / (double) parallel_usecs_total, - size, - (double) sequential_usecs_total / ((double) parallel_usecs_total * - (double) size)); + ("iterations: %d, avg. ptime: %.3f us, avg. stime: %.3f us, avg. speedup: %.3f, nodes: %d, avg. efficiency: %.3f\n", + successful_iterations, + (double) parallel_usecs_total / (double) successful_iterations, + (double) sequential_usecs_total / + (double) successful_iterations, + (double) sequential_usecs_total / (double) parallel_usecs_total, + size, + (double) sequential_usecs_total / + ((double) parallel_usecs_total * (double) size)); } else { printf("no successful iterations!\n"); } diff --git a/examples/smpi/pingpong.c b/examples/smpi/pingpong.c index e7b4a7de75..871c229b9d 100644 --- a/examples/smpi/pingpong.c +++ b/examples/smpi/pingpong.c @@ -11,54 +11,59 @@ int main(int argc, char *argv[]) { - const int tag1 = 42, tag2= 43; /* Message tag */ - int rank; - int size; - int msg=99; - int err; - int pivot; - MPI_Status status; + const int tag1 = 42, tag2 = 43; /* Message tag */ + int rank; + int size; + int msg = 99; + int err; + int pivot; + MPI_Status status; - err = MPI_Init(&argc, &argv); /* Initialize MPI */ - if (err != MPI_SUCCESS) { - printf("MPI initialization failed!\n"); - exit(1); - } - err = MPI_Comm_size(MPI_COMM_WORLD, &size); /* Get nr of tasks */ - err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* Get id of this process */ - if ( size < 2 ) { - printf("run this program with exactly 2 processes (-np 2)\n"); - MPI_Finalize(); - exit(0); - } - if (0 == rank) { - printf("\n *** Ping-pong test (MPI_Send/MPI_Recv) ***\n\n"); - } + err = MPI_Init(&argc, &argv); /* Initialize MPI */ + if (err != MPI_SUCCESS) { + printf("MPI initialization failed!\n"); + exit(1); + } + err = MPI_Comm_size(MPI_COMM_WORLD, &size); /* Get nr of tasks */ + err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* Get id of this process */ + if (size < 2) { + printf("run this program with exactly 2 processes (-np 2)\n"); + MPI_Finalize(); + exit(0); + } + if (0 == rank) { + printf("\n *** Ping-pong test (MPI_Send/MPI_Recv) ***\n\n"); + } - /* start pingpong tests between several pairs */ - for (pivot=0; pivot [%d]\n",pivot,pivot,pivot+1); + if (pivot == rank) { + printf("\n== pivot=%d : pingpong [%d] <--> [%d]\n", pivot, pivot, + pivot + 1); - int dst= rank + 1; - printf("[%d] About to send 1st message '%d' to process [%d] \n", rank,msg, dst); - err = MPI_Send(&msg, 1, MPI_INT, dst, tag1, MPI_COMM_WORLD); + int dst = rank + 1; + printf("[%d] About to send 1st message '%d' to process [%d] \n", + rank, msg, dst); + err = MPI_Send(&msg, 1, MPI_INT, dst, tag1, MPI_COMM_WORLD); - err = MPI_Recv(&msg, 1, MPI_INT, dst, tag2, MPI_COMM_WORLD, &status); /* Receive a message */ - printf("[%d] Received relpy message '%d' from process [%d] \n", rank,msg, dst); + err = MPI_Recv(&msg, 1, MPI_INT, dst, tag2, MPI_COMM_WORLD, &status); /* Receive a message */ + printf("[%d] Received relpy message '%d' from process [%d] \n", rank, + msg, dst); - } - if ((pivot+1) == rank) { - int src= rank - 1; - err = MPI_Recv(&msg, 1, MPI_INT, src, tag1, MPI_COMM_WORLD, &status); /* Receive a message */ - printf("[%d] Received 1st message '%d' from process [%d] \n", rank,msg, src); - msg++; - printf("[%d] increment message's value to '%d'\n", rank,msg); - printf("[%d] About to send back message '%d' to process [%d] \n", rank,msg, src); - err = MPI_Send(&msg, 1, MPI_INT, src, tag2, MPI_COMM_WORLD); - } - } - err = MPI_Finalize(); /* Terminate MPI */ - return 0; + } + if ((pivot + 1) == rank) { + int src = rank - 1; + err = MPI_Recv(&msg, 1, MPI_INT, src, tag1, MPI_COMM_WORLD, &status); /* Receive a message */ + printf("[%d] Received 1st message '%d' from process [%d] \n", rank, + msg, src); + msg++; + printf("[%d] increment message's value to '%d'\n", rank, msg); + printf("[%d] About to send back message '%d' to process [%d] \n", + rank, msg, src); + err = MPI_Send(&msg, 1, MPI_INT, src, tag2, MPI_COMM_WORLD); + } + } + err = MPI_Finalize(); /* Terminate MPI */ + return 0; } diff --git a/examples/smpi/reduce.c b/examples/smpi/reduce.c index bd4e151f24..2946edc930 100644 --- a/examples/smpi/reduce.c +++ b/examples/smpi/reduce.c @@ -43,8 +43,8 @@ static int ibm_test(int rank, int size) if (rank == root) { for (k = 0; k < j; k++) { if (in[k] != k * size) { - printf("bad answer (%d) at index %d of %d (should be %d)", in[k], k, - j, k * size); + printf("bad answer (%d) at index %d of %d (should be %d)", in[k], + k, j, k * size); success = 0; break; } @@ -81,7 +81,8 @@ int main(int argc, char **argv) //printf("[%d] has value %d\n", rank, value); MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD); - MPI_Reduce(&value, &sum_mirror, 1, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD); + MPI_Reduce(&value, &sum_mirror, 1, MPI_INT, MPI_SUM, root, + MPI_COMM_WORLD); MPI_Reduce(&value, &min, 1, MPI_INT, MPI_MIN, root, MPI_COMM_WORLD); MPI_Reduce(&value, &max, 1, MPI_INT, MPI_MAX, root, MPI_COMM_WORLD); diff --git a/examples/smpi/scatter.c b/examples/smpi/scatter.c index 8833cea19f..e4a63037e5 100644 --- a/examples/smpi/scatter.c +++ b/examples/smpi/scatter.c @@ -24,106 +24,112 @@ #include #include -static int ibm_test(int rank, int size) { +static int ibm_test(int rank, int size) +{ #define MAXLEN 10000 - int success = 1; - int root=0; - int i,j,k; - int *out; - int *in; - - - out = malloc(MAXLEN*64*sizeof(int)); - in = malloc(MAXLEN*sizeof(int)); - - for(j=1;j<=MAXLEN;j*=10){ - root=(root+1)%size; - if (rank == root) - for(i=0;i -static int test(int myid, int numprocs) { +static int test(int myid, int numprocs) +{ // The tags should match on the sender and receiver side. // The distinction between sendtag and recvtag is mainly // useful to make some other Recv or Send calls match the sendrecv. @@ -16,53 +17,54 @@ static int test(int myid, int numprocs) { #define BUFLEN 10 - int left, right; - int buffer[BUFLEN], buffer2[BUFLEN]; - int i; - MPI_Status status; + int left, right; + int buffer[BUFLEN], buffer2[BUFLEN]; + int i; + MPI_Status status; - for (i=0;iindex); - - unschedule(ctx); - - if(ctx->failure) - { - INFO1("0ups the scheduler initialization failed bye {%d}.",ctx->index); - xbt_os_thread_exit(&exit_code); - } - - INFO1("I'm the owner of the context %d : I'm started",ctx->index); - INFO0("Wait a minute, I do my job"); - - /* do its job */ - exit_code = job_execute(ctx->job); - - INFO1("Have finished my job, bye {%d}\n",ctx->index); - - xbt_os_sem_release(ctx->end); - - xbt_os_thread_exit(&exit_code); + int i = 0; + int exit_code = 1; + ctx_t ctx = (ctx_t) param; + + INFO1("Hello i'm the owner of the context %d, i'm waiting for starting", + ctx->index); + + unschedule(ctx); + + if (ctx->failure) { + INFO1("0ups the scheduler initialization failed bye {%d}.", + ctx->index); + xbt_os_thread_exit(&exit_code); + } + + INFO1("I'm the owner of the context %d : I'm started", ctx->index); + INFO0("Wait a minute, I do my job"); + + /* do its job */ + exit_code = job_execute(ctx->job); + + INFO1("Have finished my job, bye {%d}\n", ctx->index); + + xbt_os_sem_release(ctx->end); + + xbt_os_thread_exit(&exit_code); } -void schedule(ctx_t c) +void schedule(ctx_t c) { - xbt_os_sem_release(c->begin); /* allow C to go */ - xbt_os_sem_acquire(c->end); /* wait C's end */ + xbt_os_sem_release(c->begin); /* allow C to go */ + xbt_os_sem_acquire(c->end); /* wait C's end */ } -void unschedule(ctx_t c) +void unschedule(ctx_t c) { - xbt_os_sem_release(c->end); /* I'm done, dude */ - xbt_os_sem_acquire(c->begin); /* can I start again? */ + xbt_os_sem_release(c->end); /* I'm done, dude */ + xbt_os_sem_acquire(c->begin); /* can I start again? */ } -ctx_t -ctx_new(job_t job) +ctx_t ctx_new(job_t job) { - ctx_t ctx = xbt_new0(s_ctx_t,1); - ctx->index = ++__next_ctx_ID; - ctx->begin = xbt_os_sem_init(0); - ctx->end = xbt_os_sem_init(0); - ctx->failure = 0; - ctx->job = job; - - return ctx; + ctx_t ctx = xbt_new0(s_ctx_t, 1); + ctx->index = ++__next_ctx_ID; + ctx->begin = xbt_os_sem_init(0); + ctx->end = xbt_os_sem_init(0); + ctx->failure = 0; + ctx->job = job; + + return ctx; } -int -ctx_free(ctx_t* ref) +int ctx_free(ctx_t * ref) { - ctx_t ctx; - if(!(*ref)) - return EINVAL; - - ctx = *ref; - - xbt_os_sem_destroy(ctx->begin); - xbt_os_sem_destroy(ctx->end); - job_free(&(ctx->job)); - free(ctx); - *ref = NULL; - - return 0; + ctx_t ctx; + if (!(*ref)) + return EINVAL; + + ctx = *ref; + + xbt_os_sem_destroy(ctx->begin); + xbt_os_sem_destroy(ctx->end); + job_free(&(ctx->job)); + free(ctx); + *ref = NULL; + + return 0; } -sched_t -sched_new(int size) +sched_t sched_new(int size) { - sched_t sched; - - if(size <= 0) - { - errno = EINVAL; - return NULL; - } - - sched = xbt_new0(s_sched_t,1); - - if(!sched) - { - errno = ENOMEM; - return NULL; - } - - sched->ctxs = xbt_new0(ctx_t,size); - - if(!(sched->ctxs)) - { - errno = ENOMEM; - free(sched); - return NULL; - } - - sched->size = 0; - sched->capacity = size; - - return sched; + sched_t sched; + + if (size <= 0) { + errno = EINVAL; + return NULL; + } + + sched = xbt_new0(s_sched_t, 1); + + if (!sched) { + errno = ENOMEM; + return NULL; + } + + sched->ctxs = xbt_new0(ctx_t, size); + + if (!(sched->ctxs)) { + errno = ENOMEM; + free(sched); + return NULL; + } + + sched->size = 0; + sched->capacity = size; + + return sched; } -int -sched_add_job(sched_t sched, job_t job) +int sched_add_job(sched_t sched, job_t job) { - if(!sched || !job) - return EINVAL; - - if(sched->capacity < sched->size) - return ENOBUFS; - - sched->ctxs[(sched->size)++] = ctx_new(job); - - return 0; + if (!sched || !job) + return EINVAL; + + if (sched->capacity < sched->size) + return ENOBUFS; + + sched->ctxs[(sched->size)++] = ctx_new(job); + + return 0; } -int -sched_init(sched_t sched) +int sched_init(sched_t sched) { - int i,j; - int success = 1; - - if(!sched) - return EINVAL; - - for(i = 0; i < sched->size; i++) - { - sched->ctxs[i]->imp = xbt_os_thread_create("thread",ctx_function,(void*)sched->ctxs[i]); - - xbt_os_sem_acquire(sched->ctxs[i]->end); - } - - if(!success) - { - for(j = 0; j < i; j++) - { - sched->ctxs[j]->failure = 1; - xbt_os_sem_release(sched->ctxs[j]->begin); - } - - for(j = 0; j < i; j++) - { - xbt_os_thread_join(sched->ctxs[j]->imp,0); - - ctx_free(&(sched->ctxs[j])); - } - - return -1; - - } - - return 0; + int i, j; + int success = 1; + + if (!sched) + return EINVAL; + + for (i = 0; i < sched->size; i++) { + sched->ctxs[i]->imp = + xbt_os_thread_create("thread", ctx_function, + (void *) sched->ctxs[i]); + + xbt_os_sem_acquire(sched->ctxs[i]->end); + } + + if (!success) { + for (j = 0; j < i; j++) { + sched->ctxs[j]->failure = 1; + xbt_os_sem_release(sched->ctxs[j]->begin); + } + + for (j = 0; j < i; j++) { + xbt_os_thread_join(sched->ctxs[j]->imp, 0); + + ctx_free(&(sched->ctxs[j])); + } + + return -1; + + } + + return 0; } -int -sched_schedule(sched_t sched) +int sched_schedule(sched_t sched) { - int i; - - if(!sched) - return EINVAL; - - for(i = 0; i < sched->size; i++) - schedule(sched->ctxs[i]); - - return 0; + int i; + + if (!sched) + return EINVAL; + + for (i = 0; i < sched->size; i++) + schedule(sched->ctxs[i]); + + return 0; } -int -sched_clean(sched_t sched) +int sched_clean(sched_t sched) { - int i; - - if(!sched) - return EINVAL; - - for(i = 0; i < sched->size; i++) - { - xbt_os_thread_join(sched->ctxs[i]->imp,NULL); - - ctx_free(&(sched->ctxs[i])); - } - - return 0; + int i; + + if (!sched) + return EINVAL; + + for (i = 0; i < sched->size; i++) { + xbt_os_thread_join(sched->ctxs[i]->imp, NULL); + + ctx_free(&(sched->ctxs[i])); + } + + return 0; } -int -sched_free(sched_t* ref) +int sched_free(sched_t * ref) { - if(*ref) - return EINVAL; - - free(((sched_t)(*ref))->ctxs); - - *ref = NULL; - - return 0; + if (*ref) + return EINVAL; + + free(((sched_t) (*ref))->ctxs); + + *ref = NULL; + + return 0; } -int -job(int argc, char** argv) +int job(int argc, char **argv) { - int i = 0; - - INFO0("I'm the job : I'm going to print all the args of my commande line"); - - INFO1("-- Arguments (%d):",argc); - - for(i = 0; i < argc; i++) - INFO2(" ---- [%i] %s",i,argv[i]); - - return 0; + int i = 0; + + INFO0 + ("I'm the job : I'm going to print all the args of my commande line"); + + INFO1("-- Arguments (%d):", argc); + + for (i = 0; i < argc; i++) + INFO2(" ---- [%i] %s", i, argv[i]); + + return 0; } -job_t -job_new(pfn_func_t func, int argc, char** argv) +job_t job_new(pfn_func_t func, int argc, char **argv) { - job_t job; - int i; - - /* todo check the parameters */ - job = xbt_new0(s_job_t,1); - - if(!job) - { - errno = ENOMEM; - return NULL; - } - - job->argv = xbt_new0(char*,argc); - - if(!(job->argv)) - { - free(job); - errno = ENOMEM; - return NULL; - } - - for(i = 0; i < argc; i++) - job->argv[i] = strdup(argv[i]); - - job->func = func; - job->argc = argc; - - return job; + job_t job; + int i; + + /* todo check the parameters */ + job = xbt_new0(s_job_t, 1); + + if (!job) { + errno = ENOMEM; + return NULL; + } + + job->argv = xbt_new0(char *, argc); + + if (!(job->argv)) { + free(job); + errno = ENOMEM; + return NULL; + } + + for (i = 0; i < argc; i++) + job->argv[i] = strdup(argv[i]); + + job->func = func; + job->argc = argc; + + return job; } -int -job_execute(job_t job) +int job_execute(job_t job) { - if(!job) - return EINVAL; - - return (*(job->func))(job->argc, job->argv); + if (!job) + return EINVAL; + + return (*(job->func)) (job->argc, job->argv); } -int -job_free(job_t* ref) +int job_free(job_t * ref) { - job_t job; - int i; - - if(!(*ref)) - return EINVAL; - - job = *ref; - - for(i = 0; i < job->argc; i++) - free(job->argv[i]); - - free(job->argv); - free(*ref); - *ref = NULL; - - return 0; -} + job_t job; + int i; + + if (!(*ref)) + return EINVAL; + job = *ref; + for (i = 0; i < job->argc; i++) + free(job->argv[i]); + free(job->argv); + free(*ref); + *ref = NULL; + + return 0; +} diff --git a/teshsuite/gras/datadesc/datadesc_structs.c b/teshsuite/gras/datadesc/datadesc_structs.c index 155ebbf7a2..8a9ac55ccd 100644 --- a/teshsuite/gras/datadesc/datadesc_structs.c +++ b/teshsuite/gras/datadesc/datadesc_structs.c @@ -2,67 +2,412 @@ #include "gras.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(structs,test,"Logs about the gigantic struct test"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(structs, test, + "Logs about the gigantic struct test"); #define READ 0 #define WRITE 1 #define RW 2 -void write_read(const char *type,void *src, void *dst, gras_socket_t *sock, int direction); - -GRAS_DEFINE_TYPE(cccc,struct cccc { char a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(ccsc,struct ccsc { char a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(ccic,struct ccic { char a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(cclc,struct cclc { char a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(ccLc,struct ccLc { char a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(ccfc,struct ccfc { char a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(ccdc,struct ccdc { char a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(sccc,struct sccc { short int a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(scsc,struct scsc { short int a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(scic,struct scic { short int a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(sclc,struct sclc { short int a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(scLc,struct scLc { short int a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(scfc,struct scfc { short int a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(scdc,struct scdc { short int a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(iccc,struct iccc { int a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(icsc,struct icsc { int a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(icic,struct icic { int a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(iclc,struct iclc { int a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(icLc,struct icLc { int a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(icfc,struct icfc { int a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(icdc,struct icdc { int a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(lccc,struct lccc { long int a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(lcsc,struct lcsc { long int a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(lcic,struct lcic { long int a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(lclc,struct lclc { long int a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(lcLc,struct lcLc { long int a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(lcfc,struct lcfc { long int a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(lcdc,struct lcdc { long int a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(Lccc,struct Lccc { long long int a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(Lcsc,struct Lcsc { long long int a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(Lcic,struct Lcic { long long int a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(Lclc,struct Lclc { long long int a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(LcLc,struct LcLc { long long int a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(Lcfc,struct Lcfc { long long int a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(Lcdc,struct Lcdc { long long int a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(fccc,struct fccc { float a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(fcsc,struct fcsc { float a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(fcic,struct fcic { float a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(fclc,struct fclc { float a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(fcLc,struct fcLc { float a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(fcfc,struct fcfc { float a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(fcdc,struct fcdc { float a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(dccc,struct dccc { double a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(dcsc,struct dcsc { double a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(dcic,struct dcic { double a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(dclc,struct dclc { double a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(dcLc,struct dcLc { double a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(dcfc,struct dcfc { double a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(dcdc,struct dcdc { double a; char b; double c;char d;};) +void write_read(const char *type, void *src, void *dst, + gras_socket_t * sock, int direction); +GRAS_DEFINE_TYPE(cccc, struct cccc { + char a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccsc, struct ccsc { + char a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccic, struct ccic { + char a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(cclc, struct cclc { + char a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccLc, struct ccLc { + char a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccfc, struct ccfc { + char a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccdc, struct ccdc { + char a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(sccc, struct sccc { + short int a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scsc, struct scsc { + short int a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scic, struct scic { + short int a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(sclc, struct sclc { + short int a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scLc, struct scLc { + short int a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scfc, struct scfc { + short int a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scdc, struct scdc { + short int a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(iccc, struct iccc { + int a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icsc, struct icsc { + int a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icic, struct icic { + int a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(iclc, struct iclc { + int a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icLc, struct icLc { + int a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icfc, struct icfc { + int a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icdc, struct icdc { + int a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lccc, struct lccc { + long int a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcsc, struct lcsc { + long int a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcic, struct lcic { + long int a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lclc, struct lclc { + long int a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcLc, struct lcLc { + long int a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcfc, struct lcfc { + long int a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcdc, struct lcdc { + long int a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lccc, struct Lccc { + long long int a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lcsc, struct Lcsc { + long long int a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lcic, struct Lcic { + long long int a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lclc, struct Lclc { + long long int a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(LcLc, struct LcLc { + long long int a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lcfc, struct Lcfc { + long long int a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lcdc, struct Lcdc { + long long int a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fccc, struct fccc { + float a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcsc, struct fcsc { + float a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcic, struct fcic { + float a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fclc, struct fclc { + float a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcLc, struct fcLc { + float a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcfc, struct fcfc { + float a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcdc, struct fcdc { + float a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dccc, struct dccc { + double a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcsc, struct dcsc { + double a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcic, struct dcic { + double a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dclc, struct dclc { + double a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcLc, struct dcLc { + double a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcfc, struct dcfc { + double a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcdc, struct dcdc { + double a; + char b; + double c; + char d; + }; + + ) #define test(a) xbt_assert(a) void register_structures(void); -void register_structures(void) { +void register_structures(void) +{ gras_msgtype_declare("cccc", gras_datadesc_by_symbol(cccc)); gras_msgtype_declare("ccsc", gras_datadesc_by_symbol(ccsc)); gras_msgtype_declare("ccic", gras_datadesc_by_symbol(ccic)); @@ -113,497 +458,647 @@ void register_structures(void) { gras_msgtype_declare("dcfc", gras_datadesc_by_symbol(dcfc)); gras_msgtype_declare("dcdc", gras_datadesc_by_symbol(dcdc)); } -void test_structures(gras_socket_t *sock, int direction); -void test_structures(gras_socket_t *sock, int direction) { - struct cccc my_cccc = {'w'+(char)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_cccc2; - struct ccsc my_ccsc = {'w'+(char)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_ccsc2; - struct ccic my_ccic = {'w'+(char)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_ccic2; - struct cclc my_cclc = {'w'+(char)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_cclc2; - struct ccLc my_ccLc = {'w'+(char)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_ccLc2; - struct ccfc my_ccfc = {'w'+(char)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_ccfc2; - struct ccdc my_ccdc = {'w'+(char)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_ccdc2; - struct sccc my_sccc = {134+(short int)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_sccc2; - struct scsc my_scsc = {134+(short int)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_scsc2; - struct scic my_scic = {134+(short int)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_scic2; - struct sclc my_sclc = {134+(short int)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_sclc2; - struct scLc my_scLc = {134+(short int)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_scLc2; - struct scfc my_scfc = {134+(short int)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_scfc2; - struct scdc my_scdc = {134+(short int)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_scdc2; - struct iccc my_iccc = {-11249+(int)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_iccc2; - struct icsc my_icsc = {-11249+(int)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_icsc2; - struct icic my_icic = {-11249+(int)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_icic2; - struct iclc my_iclc = {-11249+(int)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_iclc2; - struct icLc my_icLc = {-11249+(int)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_icLc2; - struct icfc my_icfc = {-11249+(int)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_icfc2; - struct icdc my_icdc = {-11249+(int)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_icdc2; - struct lccc my_lccc = {31319919+(long int)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_lccc2; - struct lcsc my_lcsc = {31319919+(long int)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_lcsc2; - struct lcic my_lcic = {31319919+(long int)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_lcic2; - struct lclc my_lclc = {31319919+(long int)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_lclc2; - struct lcLc my_lcLc = {31319919+(long int)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_lcLc2; - struct lcfc my_lcfc = {31319919+(long int)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_lcfc2; - struct lcdc my_lcdc = {31319919+(long int)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_lcdc2; - struct Lccc my_Lccc = {-232130010+(long long int)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_Lccc2; - struct Lcsc my_Lcsc = {-232130010+(long long int)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_Lcsc2; - struct Lcic my_Lcic = {-232130010+(long long int)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_Lcic2; - struct Lclc my_Lclc = {-232130010+(long long int)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_Lclc2; - struct LcLc my_LcLc = {-232130010+(long long int)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_LcLc2; - struct Lcfc my_Lcfc = {-232130010+(long long int)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_Lcfc2; - struct Lcdc my_Lcdc = {-232130010+(long long int)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_Lcdc2; - struct fccc my_fccc = {-11313.1135+(float)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_fccc2; - struct fcsc my_fcsc = {-11313.1135+(float)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_fcsc2; - struct fcic my_fcic = {-11313.1135+(float)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_fcic2; - struct fclc my_fclc = {-11313.1135+(float)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_fclc2; - struct fcLc my_fcLc = {-11313.1135+(float)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_fcLc2; - struct fcfc my_fcfc = {-11313.1135+(float)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_fcfc2; - struct fcdc my_fcdc = {-11313.1135+(float)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_fcdc2; - struct dccc my_dccc = {1424420.11331+(double)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_dccc2; - struct dcsc my_dcsc = {1424420.11331+(double)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_dcsc2; - struct dcic my_dcic = {1424420.11331+(double)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_dcic2; - struct dclc my_dclc = {1424420.11331+(double)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_dclc2; - struct dcLc my_dcLc = {1424420.11331+(double)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_dcLc2; - struct dcfc my_dcfc = {1424420.11331+(double)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_dcfc2; - struct dcdc my_dcdc = {1424420.11331+(double)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_dcdc2; - INFO0("---- Test on all possible struct having 3 fields (49 structs) ----"); - write_read("cccc", &my_cccc, &my_cccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_cccc.a == my_cccc2.a); - test(my_cccc.b == my_cccc2.b); - test(my_cccc.c == my_cccc2.c); - test(my_cccc.d == my_cccc2.d); - if (!failed) VERB0("Passed cccc"); - } - write_read("ccsc", &my_ccsc, &my_ccsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccsc.a == my_ccsc2.a); - test(my_ccsc.b == my_ccsc2.b); - test(my_ccsc.c == my_ccsc2.c); - test(my_ccsc.d == my_ccsc2.d); - if (!failed) VERB0("Passed ccsc"); - } - write_read("ccic", &my_ccic, &my_ccic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccic.a == my_ccic2.a); - test(my_ccic.b == my_ccic2.b); - test(my_ccic.c == my_ccic2.c); - test(my_ccic.d == my_ccic2.d); - if (!failed) VERB0("Passed ccic"); - } - write_read("cclc", &my_cclc, &my_cclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_cclc.a == my_cclc2.a); - test(my_cclc.b == my_cclc2.b); - test(my_cclc.c == my_cclc2.c); - test(my_cclc.d == my_cclc2.d); - if (!failed) VERB0("Passed cclc"); - } - write_read("ccLc", &my_ccLc, &my_ccLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccLc.a == my_ccLc2.a); - test(my_ccLc.b == my_ccLc2.b); - test(my_ccLc.c == my_ccLc2.c); - test(my_ccLc.d == my_ccLc2.d); - if (!failed) VERB0("Passed ccLc"); - } - write_read("ccfc", &my_ccfc, &my_ccfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccfc.a == my_ccfc2.a); - test(my_ccfc.b == my_ccfc2.b); - test(my_ccfc.c == my_ccfc2.c); - test(my_ccfc.d == my_ccfc2.d); - if (!failed) VERB0("Passed ccfc"); - } - write_read("ccdc", &my_ccdc, &my_ccdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccdc.a == my_ccdc2.a); - test(my_ccdc.b == my_ccdc2.b); - test(my_ccdc.c == my_ccdc2.c); - test(my_ccdc.d == my_ccdc2.d); - if (!failed) VERB0("Passed ccdc"); - } - write_read("sccc", &my_sccc, &my_sccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_sccc.a == my_sccc2.a); - test(my_sccc.b == my_sccc2.b); - test(my_sccc.c == my_sccc2.c); - test(my_sccc.d == my_sccc2.d); - if (!failed) VERB0("Passed sccc"); - } - write_read("scsc", &my_scsc, &my_scsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scsc.a == my_scsc2.a); - test(my_scsc.b == my_scsc2.b); - test(my_scsc.c == my_scsc2.c); - test(my_scsc.d == my_scsc2.d); - if (!failed) VERB0("Passed scsc"); - } - write_read("scic", &my_scic, &my_scic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scic.a == my_scic2.a); - test(my_scic.b == my_scic2.b); - test(my_scic.c == my_scic2.c); - test(my_scic.d == my_scic2.d); - if (!failed) VERB0("Passed scic"); - } - write_read("sclc", &my_sclc, &my_sclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_sclc.a == my_sclc2.a); - test(my_sclc.b == my_sclc2.b); - test(my_sclc.c == my_sclc2.c); - test(my_sclc.d == my_sclc2.d); - if (!failed) VERB0("Passed sclc"); - } - write_read("scLc", &my_scLc, &my_scLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scLc.a == my_scLc2.a); - test(my_scLc.b == my_scLc2.b); - test(my_scLc.c == my_scLc2.c); - test(my_scLc.d == my_scLc2.d); - if (!failed) VERB0("Passed scLc"); - } - write_read("scfc", &my_scfc, &my_scfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scfc.a == my_scfc2.a); - test(my_scfc.b == my_scfc2.b); - test(my_scfc.c == my_scfc2.c); - test(my_scfc.d == my_scfc2.d); - if (!failed) VERB0("Passed scfc"); - } - write_read("scdc", &my_scdc, &my_scdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scdc.a == my_scdc2.a); - test(my_scdc.b == my_scdc2.b); - test(my_scdc.c == my_scdc2.c); - test(my_scdc.d == my_scdc2.d); - if (!failed) VERB0("Passed scdc"); - } - write_read("iccc", &my_iccc, &my_iccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_iccc.a == my_iccc2.a); - test(my_iccc.b == my_iccc2.b); - test(my_iccc.c == my_iccc2.c); - test(my_iccc.d == my_iccc2.d); - if (!failed) VERB0("Passed iccc"); - } - write_read("icsc", &my_icsc, &my_icsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icsc.a == my_icsc2.a); - test(my_icsc.b == my_icsc2.b); - test(my_icsc.c == my_icsc2.c); - test(my_icsc.d == my_icsc2.d); - if (!failed) VERB0("Passed icsc"); - } - write_read("icic", &my_icic, &my_icic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icic.a == my_icic2.a); - test(my_icic.b == my_icic2.b); - test(my_icic.c == my_icic2.c); - test(my_icic.d == my_icic2.d); - if (!failed) VERB0("Passed icic"); - } - write_read("iclc", &my_iclc, &my_iclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_iclc.a == my_iclc2.a); - test(my_iclc.b == my_iclc2.b); - test(my_iclc.c == my_iclc2.c); - test(my_iclc.d == my_iclc2.d); - if (!failed) VERB0("Passed iclc"); - } - write_read("icLc", &my_icLc, &my_icLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icLc.a == my_icLc2.a); - test(my_icLc.b == my_icLc2.b); - test(my_icLc.c == my_icLc2.c); - test(my_icLc.d == my_icLc2.d); - if (!failed) VERB0("Passed icLc"); - } - write_read("icfc", &my_icfc, &my_icfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icfc.a == my_icfc2.a); - test(my_icfc.b == my_icfc2.b); - test(my_icfc.c == my_icfc2.c); - test(my_icfc.d == my_icfc2.d); - if (!failed) VERB0("Passed icfc"); - } - write_read("icdc", &my_icdc, &my_icdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icdc.a == my_icdc2.a); - test(my_icdc.b == my_icdc2.b); - test(my_icdc.c == my_icdc2.c); - test(my_icdc.d == my_icdc2.d); - if (!failed) VERB0("Passed icdc"); - } - write_read("lccc", &my_lccc, &my_lccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lccc.a == my_lccc2.a); - test(my_lccc.b == my_lccc2.b); - test(my_lccc.c == my_lccc2.c); - test(my_lccc.d == my_lccc2.d); - if (!failed) VERB0("Passed lccc"); - } - write_read("lcsc", &my_lcsc, &my_lcsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcsc.a == my_lcsc2.a); - test(my_lcsc.b == my_lcsc2.b); - test(my_lcsc.c == my_lcsc2.c); - test(my_lcsc.d == my_lcsc2.d); - if (!failed) VERB0("Passed lcsc"); - } - write_read("lcic", &my_lcic, &my_lcic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcic.a == my_lcic2.a); - test(my_lcic.b == my_lcic2.b); - test(my_lcic.c == my_lcic2.c); - test(my_lcic.d == my_lcic2.d); - if (!failed) VERB0("Passed lcic"); - } - write_read("lclc", &my_lclc, &my_lclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lclc.a == my_lclc2.a); - test(my_lclc.b == my_lclc2.b); - test(my_lclc.c == my_lclc2.c); - test(my_lclc.d == my_lclc2.d); - if (!failed) VERB0("Passed lclc"); - } - write_read("lcLc", &my_lcLc, &my_lcLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcLc.a == my_lcLc2.a); - test(my_lcLc.b == my_lcLc2.b); - test(my_lcLc.c == my_lcLc2.c); - test(my_lcLc.d == my_lcLc2.d); - if (!failed) VERB0("Passed lcLc"); - } - write_read("lcfc", &my_lcfc, &my_lcfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcfc.a == my_lcfc2.a); - test(my_lcfc.b == my_lcfc2.b); - test(my_lcfc.c == my_lcfc2.c); - test(my_lcfc.d == my_lcfc2.d); - if (!failed) VERB0("Passed lcfc"); - } - write_read("lcdc", &my_lcdc, &my_lcdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcdc.a == my_lcdc2.a); - test(my_lcdc.b == my_lcdc2.b); - test(my_lcdc.c == my_lcdc2.c); - test(my_lcdc.d == my_lcdc2.d); - if (!failed) VERB0("Passed lcdc"); - } - write_read("Lccc", &my_Lccc, &my_Lccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lccc.a == my_Lccc2.a); - test(my_Lccc.b == my_Lccc2.b); - test(my_Lccc.c == my_Lccc2.c); - test(my_Lccc.d == my_Lccc2.d); - if (!failed) VERB0("Passed Lccc"); - } - write_read("Lcsc", &my_Lcsc, &my_Lcsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lcsc.a == my_Lcsc2.a); - test(my_Lcsc.b == my_Lcsc2.b); - test(my_Lcsc.c == my_Lcsc2.c); - test(my_Lcsc.d == my_Lcsc2.d); - if (!failed) VERB0("Passed Lcsc"); - } - write_read("Lcic", &my_Lcic, &my_Lcic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lcic.a == my_Lcic2.a); - test(my_Lcic.b == my_Lcic2.b); - test(my_Lcic.c == my_Lcic2.c); - test(my_Lcic.d == my_Lcic2.d); - if (!failed) VERB0("Passed Lcic"); - } - write_read("Lclc", &my_Lclc, &my_Lclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lclc.a == my_Lclc2.a); - test(my_Lclc.b == my_Lclc2.b); - test(my_Lclc.c == my_Lclc2.c); - test(my_Lclc.d == my_Lclc2.d); - if (!failed) VERB0("Passed Lclc"); - } - write_read("LcLc", &my_LcLc, &my_LcLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_LcLc.a == my_LcLc2.a); - test(my_LcLc.b == my_LcLc2.b); - test(my_LcLc.c == my_LcLc2.c); - test(my_LcLc.d == my_LcLc2.d); - if (!failed) VERB0("Passed LcLc"); - } - write_read("Lcfc", &my_Lcfc, &my_Lcfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lcfc.a == my_Lcfc2.a); - test(my_Lcfc.b == my_Lcfc2.b); - test(my_Lcfc.c == my_Lcfc2.c); - test(my_Lcfc.d == my_Lcfc2.d); - if (!failed) VERB0("Passed Lcfc"); - } - write_read("Lcdc", &my_Lcdc, &my_Lcdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lcdc.a == my_Lcdc2.a); - test(my_Lcdc.b == my_Lcdc2.b); - test(my_Lcdc.c == my_Lcdc2.c); - test(my_Lcdc.d == my_Lcdc2.d); - if (!failed) VERB0("Passed Lcdc"); - } - write_read("fccc", &my_fccc, &my_fccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fccc.a == my_fccc2.a); - test(my_fccc.b == my_fccc2.b); - test(my_fccc.c == my_fccc2.c); - test(my_fccc.d == my_fccc2.d); - if (!failed) VERB0("Passed fccc"); - } - write_read("fcsc", &my_fcsc, &my_fcsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcsc.a == my_fcsc2.a); - test(my_fcsc.b == my_fcsc2.b); - test(my_fcsc.c == my_fcsc2.c); - test(my_fcsc.d == my_fcsc2.d); - if (!failed) VERB0("Passed fcsc"); - } - write_read("fcic", &my_fcic, &my_fcic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcic.a == my_fcic2.a); - test(my_fcic.b == my_fcic2.b); - test(my_fcic.c == my_fcic2.c); - test(my_fcic.d == my_fcic2.d); - if (!failed) VERB0("Passed fcic"); - } - write_read("fclc", &my_fclc, &my_fclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fclc.a == my_fclc2.a); - test(my_fclc.b == my_fclc2.b); - test(my_fclc.c == my_fclc2.c); - test(my_fclc.d == my_fclc2.d); - if (!failed) VERB0("Passed fclc"); - } - write_read("fcLc", &my_fcLc, &my_fcLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcLc.a == my_fcLc2.a); - test(my_fcLc.b == my_fcLc2.b); - test(my_fcLc.c == my_fcLc2.c); - test(my_fcLc.d == my_fcLc2.d); - if (!failed) VERB0("Passed fcLc"); - } - write_read("fcfc", &my_fcfc, &my_fcfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcfc.a == my_fcfc2.a); - test(my_fcfc.b == my_fcfc2.b); - test(my_fcfc.c == my_fcfc2.c); - test(my_fcfc.d == my_fcfc2.d); - if (!failed) VERB0("Passed fcfc"); - } - write_read("fcdc", &my_fcdc, &my_fcdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcdc.a == my_fcdc2.a); - test(my_fcdc.b == my_fcdc2.b); - test(my_fcdc.c == my_fcdc2.c); - test(my_fcdc.d == my_fcdc2.d); - if (!failed) VERB0("Passed fcdc"); - } - write_read("dccc", &my_dccc, &my_dccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dccc.a == my_dccc2.a); - test(my_dccc.b == my_dccc2.b); - test(my_dccc.c == my_dccc2.c); - test(my_dccc.d == my_dccc2.d); - if (!failed) VERB0("Passed dccc"); - } - write_read("dcsc", &my_dcsc, &my_dcsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcsc.a == my_dcsc2.a); - test(my_dcsc.b == my_dcsc2.b); - test(my_dcsc.c == my_dcsc2.c); - test(my_dcsc.d == my_dcsc2.d); - if (!failed) VERB0("Passed dcsc"); - } - write_read("dcic", &my_dcic, &my_dcic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcic.a == my_dcic2.a); - test(my_dcic.b == my_dcic2.b); - test(my_dcic.c == my_dcic2.c); - test(my_dcic.d == my_dcic2.d); - if (!failed) VERB0("Passed dcic"); - } - write_read("dclc", &my_dclc, &my_dclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dclc.a == my_dclc2.a); - test(my_dclc.b == my_dclc2.b); - test(my_dclc.c == my_dclc2.c); - test(my_dclc.d == my_dclc2.d); - if (!failed) VERB0("Passed dclc"); - } - write_read("dcLc", &my_dcLc, &my_dcLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcLc.a == my_dcLc2.a); - test(my_dcLc.b == my_dcLc2.b); - test(my_dcLc.c == my_dcLc2.c); - test(my_dcLc.d == my_dcLc2.d); - if (!failed) VERB0("Passed dcLc"); - } - write_read("dcfc", &my_dcfc, &my_dcfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcfc.a == my_dcfc2.a); - test(my_dcfc.b == my_dcfc2.b); - test(my_dcfc.c == my_dcfc2.c); - test(my_dcfc.d == my_dcfc2.d); - if (!failed) VERB0("Passed dcfc"); - } - write_read("dcdc", &my_dcdc, &my_dcdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcdc.a == my_dcdc2.a); - test(my_dcdc.b == my_dcdc2.b); - test(my_dcdc.c == my_dcdc2.c); - test(my_dcdc.d == my_dcdc2.d); - if (!failed) VERB0("Passed dcdc"); + +void test_structures(gras_socket_t * sock, int direction); +void test_structures(gras_socket_t * sock, int direction) +{ + struct cccc my_cccc = + { 'w' + (char) 1, 'w' + (char) 2, 'w' + (char) 3, 'w' + (char) 4 }, + my_cccc2; + struct ccsc my_ccsc = + { 'w' + (char) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_ccsc2; + struct ccic my_ccic = + { 'w' + (char) 1, 'w' + (char) 2, -11249 + (int) 3, 'w' + (char) 4 }, + my_ccic2; + struct cclc my_cclc = + { 'w' + (char) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_cclc2; + struct ccLc my_ccLc = + { 'w' + (char) 1, 'w' + (char) 2, -232130010 + (long long int) 3, +'w' + (char) 4 }, my_ccLc2; + struct ccfc my_ccfc = + { 'w' + (char) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_ccfc2; + struct ccdc my_ccdc = + { 'w' + (char) 1, 'w' + (char) 2, 1424420.11331 + (double) 3, +'w' + (char) 4 }, my_ccdc2; + struct sccc my_sccc = + { 134 + (short int) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_sccc2; + struct scsc my_scsc = + { 134 + (short int) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_scsc2; + struct scic my_scic = + { 134 + (short int) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_scic2; + struct sclc my_sclc = + { 134 + (short int) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_sclc2; + struct scLc my_scLc = + { 134 + (short int) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_scLc2; + struct scfc my_scfc = + { 134 + (short int) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_scfc2; + struct scdc my_scdc = + { 134 + (short int) 1, 'w' + (char) 2, 1424420.11331 + (double) 3, +'w' + (char) 4 }, my_scdc2; + struct iccc my_iccc = + { -11249 + (int) 1, 'w' + (char) 2, 'w' + (char) 3, 'w' + (char) 4 }, + my_iccc2; + struct icsc my_icsc = + { -11249 + (int) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_icsc2; + struct icic my_icic = + { -11249 + (int) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_icic2; + struct iclc my_iclc = + { -11249 + (int) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_iclc2; + struct icLc my_icLc = + { -11249 + (int) 1, 'w' + (char) 2, -232130010 + (long long int) 3, +'w' + (char) 4 }, my_icLc2; + struct icfc my_icfc = + { -11249 + (int) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_icfc2; + struct icdc my_icdc = + { -11249 + (int) 1, 'w' + (char) 2, 1424420.11331 + (double) 3, +'w' + (char) 4 }, my_icdc2; + struct lccc my_lccc = + { 31319919 + (long int) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_lccc2; + struct lcsc my_lcsc = + { 31319919 + (long int) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_lcsc2; + struct lcic my_lcic = + { 31319919 + (long int) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_lcic2; + struct lclc my_lclc = + { 31319919 + (long int) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_lclc2; + struct lcLc my_lcLc = + { 31319919 + (long int) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_lcLc2; + struct lcfc my_lcfc = + { 31319919 + (long int) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_lcfc2; + struct lcdc my_lcdc = + { 31319919 + (long int) 1, 'w' + (char) 2, +1424420.11331 + (double) 3, 'w' + (char) 4 }, my_lcdc2; + struct Lccc my_Lccc = + { -232130010 + (long long int) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_Lccc2; + struct Lcsc my_Lcsc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +134 + (short int) 3, 'w' + (char) 4 }, my_Lcsc2; + struct Lcic my_Lcic = + { -232130010 + (long long int) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_Lcic2; + struct Lclc my_Lclc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +31319919 + (long int) 3, 'w' + (char) 4 }, my_Lclc2; + struct LcLc my_LcLc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_LcLc2; + struct Lcfc my_Lcfc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +-11313.1135 + (float) 3, 'w' + (char) 4 }, my_Lcfc2; + struct Lcdc my_Lcdc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +1424420.11331 + (double) 3, 'w' + (char) 4 }, my_Lcdc2; + struct fccc my_fccc = + { -11313.1135 + (float) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_fccc2; + struct fcsc my_fcsc = + { -11313.1135 + (float) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_fcsc2; + struct fcic my_fcic = + { -11313.1135 + (float) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_fcic2; + struct fclc my_fclc = + { -11313.1135 + (float) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_fclc2; + struct fcLc my_fcLc = + { -11313.1135 + (float) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_fcLc2; + struct fcfc my_fcfc = + { -11313.1135 + (float) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_fcfc2; + struct fcdc my_fcdc = + { -11313.1135 + (float) 1, 'w' + (char) 2, +1424420.11331 + (double) 3, 'w' + (char) 4 }, my_fcdc2; + struct dccc my_dccc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_dccc2; + struct dcsc my_dcsc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_dcsc2; + struct dcic my_dcic = + { 1424420.11331 + (double) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_dcic2; + struct dclc my_dclc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, +31319919 + (long int) 3, 'w' + (char) 4 }, my_dclc2; + struct dcLc my_dcLc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_dcLc2; + struct dcfc my_dcfc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, +-11313.1135 + (float) 3, 'w' + (char) 4 }, my_dcfc2; + struct dcdc my_dcdc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, +1424420.11331 + (double) 3, 'w' + (char) 4 }, my_dcdc2; + INFO0 + ("---- Test on all possible struct having 3 fields (49 structs) ----"); + write_read("cccc", &my_cccc, &my_cccc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_cccc.a == my_cccc2.a); + test(my_cccc.b == my_cccc2.b); + test(my_cccc.c == my_cccc2.c); + test(my_cccc.d == my_cccc2.d); + if (!failed) + VERB0("Passed cccc"); + } + write_read("ccsc", &my_ccsc, &my_ccsc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccsc.a == my_ccsc2.a); + test(my_ccsc.b == my_ccsc2.b); + test(my_ccsc.c == my_ccsc2.c); + test(my_ccsc.d == my_ccsc2.d); + if (!failed) + VERB0("Passed ccsc"); + } + write_read("ccic", &my_ccic, &my_ccic2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccic.a == my_ccic2.a); + test(my_ccic.b == my_ccic2.b); + test(my_ccic.c == my_ccic2.c); + test(my_ccic.d == my_ccic2.d); + if (!failed) + VERB0("Passed ccic"); + } + write_read("cclc", &my_cclc, &my_cclc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_cclc.a == my_cclc2.a); + test(my_cclc.b == my_cclc2.b); + test(my_cclc.c == my_cclc2.c); + test(my_cclc.d == my_cclc2.d); + if (!failed) + VERB0("Passed cclc"); + } + write_read("ccLc", &my_ccLc, &my_ccLc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccLc.a == my_ccLc2.a); + test(my_ccLc.b == my_ccLc2.b); + test(my_ccLc.c == my_ccLc2.c); + test(my_ccLc.d == my_ccLc2.d); + if (!failed) + VERB0("Passed ccLc"); + } + write_read("ccfc", &my_ccfc, &my_ccfc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccfc.a == my_ccfc2.a); + test(my_ccfc.b == my_ccfc2.b); + test(my_ccfc.c == my_ccfc2.c); + test(my_ccfc.d == my_ccfc2.d); + if (!failed) + VERB0("Passed ccfc"); + } + write_read("ccdc", &my_ccdc, &my_ccdc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccdc.a == my_ccdc2.a); + test(my_ccdc.b == my_ccdc2.b); + test(my_ccdc.c == my_ccdc2.c); + test(my_ccdc.d == my_ccdc2.d); + if (!failed) + VERB0("Passed ccdc"); + } + write_read("sccc", &my_sccc, &my_sccc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_sccc.a == my_sccc2.a); + test(my_sccc.b == my_sccc2.b); + test(my_sccc.c == my_sccc2.c); + test(my_sccc.d == my_sccc2.d); + if (!failed) + VERB0("Passed sccc"); + } + write_read("scsc", &my_scsc, &my_scsc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scsc.a == my_scsc2.a); + test(my_scsc.b == my_scsc2.b); + test(my_scsc.c == my_scsc2.c); + test(my_scsc.d == my_scsc2.d); + if (!failed) + VERB0("Passed scsc"); + } + write_read("scic", &my_scic, &my_scic2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scic.a == my_scic2.a); + test(my_scic.b == my_scic2.b); + test(my_scic.c == my_scic2.c); + test(my_scic.d == my_scic2.d); + if (!failed) + VERB0("Passed scic"); + } + write_read("sclc", &my_sclc, &my_sclc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_sclc.a == my_sclc2.a); + test(my_sclc.b == my_sclc2.b); + test(my_sclc.c == my_sclc2.c); + test(my_sclc.d == my_sclc2.d); + if (!failed) + VERB0("Passed sclc"); + } + write_read("scLc", &my_scLc, &my_scLc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scLc.a == my_scLc2.a); + test(my_scLc.b == my_scLc2.b); + test(my_scLc.c == my_scLc2.c); + test(my_scLc.d == my_scLc2.d); + if (!failed) + VERB0("Passed scLc"); + } + write_read("scfc", &my_scfc, &my_scfc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scfc.a == my_scfc2.a); + test(my_scfc.b == my_scfc2.b); + test(my_scfc.c == my_scfc2.c); + test(my_scfc.d == my_scfc2.d); + if (!failed) + VERB0("Passed scfc"); + } + write_read("scdc", &my_scdc, &my_scdc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scdc.a == my_scdc2.a); + test(my_scdc.b == my_scdc2.b); + test(my_scdc.c == my_scdc2.c); + test(my_scdc.d == my_scdc2.d); + if (!failed) + VERB0("Passed scdc"); + } + write_read("iccc", &my_iccc, &my_iccc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_iccc.a == my_iccc2.a); + test(my_iccc.b == my_iccc2.b); + test(my_iccc.c == my_iccc2.c); + test(my_iccc.d == my_iccc2.d); + if (!failed) + VERB0("Passed iccc"); + } + write_read("icsc", &my_icsc, &my_icsc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icsc.a == my_icsc2.a); + test(my_icsc.b == my_icsc2.b); + test(my_icsc.c == my_icsc2.c); + test(my_icsc.d == my_icsc2.d); + if (!failed) + VERB0("Passed icsc"); + } + write_read("icic", &my_icic, &my_icic2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icic.a == my_icic2.a); + test(my_icic.b == my_icic2.b); + test(my_icic.c == my_icic2.c); + test(my_icic.d == my_icic2.d); + if (!failed) + VERB0("Passed icic"); + } + write_read("iclc", &my_iclc, &my_iclc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_iclc.a == my_iclc2.a); + test(my_iclc.b == my_iclc2.b); + test(my_iclc.c == my_iclc2.c); + test(my_iclc.d == my_iclc2.d); + if (!failed) + VERB0("Passed iclc"); + } + write_read("icLc", &my_icLc, &my_icLc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icLc.a == my_icLc2.a); + test(my_icLc.b == my_icLc2.b); + test(my_icLc.c == my_icLc2.c); + test(my_icLc.d == my_icLc2.d); + if (!failed) + VERB0("Passed icLc"); + } + write_read("icfc", &my_icfc, &my_icfc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icfc.a == my_icfc2.a); + test(my_icfc.b == my_icfc2.b); + test(my_icfc.c == my_icfc2.c); + test(my_icfc.d == my_icfc2.d); + if (!failed) + VERB0("Passed icfc"); + } + write_read("icdc", &my_icdc, &my_icdc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icdc.a == my_icdc2.a); + test(my_icdc.b == my_icdc2.b); + test(my_icdc.c == my_icdc2.c); + test(my_icdc.d == my_icdc2.d); + if (!failed) + VERB0("Passed icdc"); + } + write_read("lccc", &my_lccc, &my_lccc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lccc.a == my_lccc2.a); + test(my_lccc.b == my_lccc2.b); + test(my_lccc.c == my_lccc2.c); + test(my_lccc.d == my_lccc2.d); + if (!failed) + VERB0("Passed lccc"); + } + write_read("lcsc", &my_lcsc, &my_lcsc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcsc.a == my_lcsc2.a); + test(my_lcsc.b == my_lcsc2.b); + test(my_lcsc.c == my_lcsc2.c); + test(my_lcsc.d == my_lcsc2.d); + if (!failed) + VERB0("Passed lcsc"); + } + write_read("lcic", &my_lcic, &my_lcic2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcic.a == my_lcic2.a); + test(my_lcic.b == my_lcic2.b); + test(my_lcic.c == my_lcic2.c); + test(my_lcic.d == my_lcic2.d); + if (!failed) + VERB0("Passed lcic"); + } + write_read("lclc", &my_lclc, &my_lclc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lclc.a == my_lclc2.a); + test(my_lclc.b == my_lclc2.b); + test(my_lclc.c == my_lclc2.c); + test(my_lclc.d == my_lclc2.d); + if (!failed) + VERB0("Passed lclc"); + } + write_read("lcLc", &my_lcLc, &my_lcLc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcLc.a == my_lcLc2.a); + test(my_lcLc.b == my_lcLc2.b); + test(my_lcLc.c == my_lcLc2.c); + test(my_lcLc.d == my_lcLc2.d); + if (!failed) + VERB0("Passed lcLc"); + } + write_read("lcfc", &my_lcfc, &my_lcfc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcfc.a == my_lcfc2.a); + test(my_lcfc.b == my_lcfc2.b); + test(my_lcfc.c == my_lcfc2.c); + test(my_lcfc.d == my_lcfc2.d); + if (!failed) + VERB0("Passed lcfc"); + } + write_read("lcdc", &my_lcdc, &my_lcdc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcdc.a == my_lcdc2.a); + test(my_lcdc.b == my_lcdc2.b); + test(my_lcdc.c == my_lcdc2.c); + test(my_lcdc.d == my_lcdc2.d); + if (!failed) + VERB0("Passed lcdc"); + } + write_read("Lccc", &my_Lccc, &my_Lccc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lccc.a == my_Lccc2.a); + test(my_Lccc.b == my_Lccc2.b); + test(my_Lccc.c == my_Lccc2.c); + test(my_Lccc.d == my_Lccc2.d); + if (!failed) + VERB0("Passed Lccc"); + } + write_read("Lcsc", &my_Lcsc, &my_Lcsc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lcsc.a == my_Lcsc2.a); + test(my_Lcsc.b == my_Lcsc2.b); + test(my_Lcsc.c == my_Lcsc2.c); + test(my_Lcsc.d == my_Lcsc2.d); + if (!failed) + VERB0("Passed Lcsc"); + } + write_read("Lcic", &my_Lcic, &my_Lcic2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lcic.a == my_Lcic2.a); + test(my_Lcic.b == my_Lcic2.b); + test(my_Lcic.c == my_Lcic2.c); + test(my_Lcic.d == my_Lcic2.d); + if (!failed) + VERB0("Passed Lcic"); + } + write_read("Lclc", &my_Lclc, &my_Lclc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lclc.a == my_Lclc2.a); + test(my_Lclc.b == my_Lclc2.b); + test(my_Lclc.c == my_Lclc2.c); + test(my_Lclc.d == my_Lclc2.d); + if (!failed) + VERB0("Passed Lclc"); + } + write_read("LcLc", &my_LcLc, &my_LcLc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_LcLc.a == my_LcLc2.a); + test(my_LcLc.b == my_LcLc2.b); + test(my_LcLc.c == my_LcLc2.c); + test(my_LcLc.d == my_LcLc2.d); + if (!failed) + VERB0("Passed LcLc"); + } + write_read("Lcfc", &my_Lcfc, &my_Lcfc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lcfc.a == my_Lcfc2.a); + test(my_Lcfc.b == my_Lcfc2.b); + test(my_Lcfc.c == my_Lcfc2.c); + test(my_Lcfc.d == my_Lcfc2.d); + if (!failed) + VERB0("Passed Lcfc"); + } + write_read("Lcdc", &my_Lcdc, &my_Lcdc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lcdc.a == my_Lcdc2.a); + test(my_Lcdc.b == my_Lcdc2.b); + test(my_Lcdc.c == my_Lcdc2.c); + test(my_Lcdc.d == my_Lcdc2.d); + if (!failed) + VERB0("Passed Lcdc"); + } + write_read("fccc", &my_fccc, &my_fccc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fccc.a == my_fccc2.a); + test(my_fccc.b == my_fccc2.b); + test(my_fccc.c == my_fccc2.c); + test(my_fccc.d == my_fccc2.d); + if (!failed) + VERB0("Passed fccc"); + } + write_read("fcsc", &my_fcsc, &my_fcsc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcsc.a == my_fcsc2.a); + test(my_fcsc.b == my_fcsc2.b); + test(my_fcsc.c == my_fcsc2.c); + test(my_fcsc.d == my_fcsc2.d); + if (!failed) + VERB0("Passed fcsc"); + } + write_read("fcic", &my_fcic, &my_fcic2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcic.a == my_fcic2.a); + test(my_fcic.b == my_fcic2.b); + test(my_fcic.c == my_fcic2.c); + test(my_fcic.d == my_fcic2.d); + if (!failed) + VERB0("Passed fcic"); + } + write_read("fclc", &my_fclc, &my_fclc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fclc.a == my_fclc2.a); + test(my_fclc.b == my_fclc2.b); + test(my_fclc.c == my_fclc2.c); + test(my_fclc.d == my_fclc2.d); + if (!failed) + VERB0("Passed fclc"); + } + write_read("fcLc", &my_fcLc, &my_fcLc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcLc.a == my_fcLc2.a); + test(my_fcLc.b == my_fcLc2.b); + test(my_fcLc.c == my_fcLc2.c); + test(my_fcLc.d == my_fcLc2.d); + if (!failed) + VERB0("Passed fcLc"); + } + write_read("fcfc", &my_fcfc, &my_fcfc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcfc.a == my_fcfc2.a); + test(my_fcfc.b == my_fcfc2.b); + test(my_fcfc.c == my_fcfc2.c); + test(my_fcfc.d == my_fcfc2.d); + if (!failed) + VERB0("Passed fcfc"); + } + write_read("fcdc", &my_fcdc, &my_fcdc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcdc.a == my_fcdc2.a); + test(my_fcdc.b == my_fcdc2.b); + test(my_fcdc.c == my_fcdc2.c); + test(my_fcdc.d == my_fcdc2.d); + if (!failed) + VERB0("Passed fcdc"); + } + write_read("dccc", &my_dccc, &my_dccc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dccc.a == my_dccc2.a); + test(my_dccc.b == my_dccc2.b); + test(my_dccc.c == my_dccc2.c); + test(my_dccc.d == my_dccc2.d); + if (!failed) + VERB0("Passed dccc"); + } + write_read("dcsc", &my_dcsc, &my_dcsc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcsc.a == my_dcsc2.a); + test(my_dcsc.b == my_dcsc2.b); + test(my_dcsc.c == my_dcsc2.c); + test(my_dcsc.d == my_dcsc2.d); + if (!failed) + VERB0("Passed dcsc"); + } + write_read("dcic", &my_dcic, &my_dcic2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcic.a == my_dcic2.a); + test(my_dcic.b == my_dcic2.b); + test(my_dcic.c == my_dcic2.c); + test(my_dcic.d == my_dcic2.d); + if (!failed) + VERB0("Passed dcic"); + } + write_read("dclc", &my_dclc, &my_dclc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dclc.a == my_dclc2.a); + test(my_dclc.b == my_dclc2.b); + test(my_dclc.c == my_dclc2.c); + test(my_dclc.d == my_dclc2.d); + if (!failed) + VERB0("Passed dclc"); + } + write_read("dcLc", &my_dcLc, &my_dcLc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcLc.a == my_dcLc2.a); + test(my_dcLc.b == my_dcLc2.b); + test(my_dcLc.c == my_dcLc2.c); + test(my_dcLc.d == my_dcLc2.d); + if (!failed) + VERB0("Passed dcLc"); + } + write_read("dcfc", &my_dcfc, &my_dcfc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcfc.a == my_dcfc2.a); + test(my_dcfc.b == my_dcfc2.b); + test(my_dcfc.c == my_dcfc2.c); + test(my_dcfc.d == my_dcfc2.d); + if (!failed) + VERB0("Passed dcfc"); + } + write_read("dcdc", &my_dcdc, &my_dcdc2, sock, direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcdc.a == my_dcdc2.a); + test(my_dcdc.b == my_dcdc2.b); + test(my_dcdc.c == my_dcdc2.c); + test(my_dcdc.d == my_dcdc2.d); + if (!failed) + VERB0("Passed dcdc"); } } diff --git a/teshsuite/gras/datadesc/datadesc_usage.c b/teshsuite/gras/datadesc/datadesc_usage.c index ac8e05d4ab..8caa457b6d 100644 --- a/teshsuite/gras/datadesc/datadesc_usage.c +++ b/teshsuite/gras/datadesc/datadesc_usage.c @@ -126,8 +126,8 @@ static void test_dynar_scal(gras_socket_t sock, int direction) int ret = xbt_dynar_get_as(j, cpt, int); if (cpt != ret) { CRITICAL3 - ("The retrieved value for cpt=%d is not the same than the injected one (%d!=%d)", - cpt, ret, cpt); + ("The retrieved value for cpt=%d is not the same than the injected one (%d!=%d)", + cpt, ret, cpt); xbt_abort(); } } @@ -245,7 +245,8 @@ static void test_hetestruct(gras_socket_t sock, int 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_assert2(i->l1 == j->l1, "i->l1(=%ld) != j->l1(=%ld)", i->l1, + j->l1); xbt_assert(i->l2 == j->l2); free(j); } @@ -456,17 +457,21 @@ static void test_dynar_ref(gras_socket_t sock, int direction) /**** 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];};) + 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; +typedef struct s_pbio pbio_t; - static void test_pbio(gras_socket_t sock, int direction) +static void test_pbio(gras_socket_t sock, int direction) { int cpt; int cpt2; @@ -474,7 +479,7 @@ GRAS_DEFINE_TYPE(s_pbio, struct s_pbio { /* structure presented in the IE pbio_t i, j; INFO0 - ("---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ----"); + ("---- Test on the PBIO IEEE struct (also tests GRAS DEFINE TYPE) ----"); pbio_type = gras_datadesc_by_symbol(s_pbio); /* Fill in that damn struct */ @@ -540,20 +545,19 @@ GRAS_DEFINE_TYPE(s_pbio, struct s_pbio { /* structure presented in the IE } 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 */ - }; - - ) + int num_lits; + int *literals GRAS_ANNOTE(size, num_lits); /* Tells GRAS where to find the size */ + };) - typedef struct s_clause Clause; +typedef struct s_clause Clause; - static void test_clause(gras_socket_t sock, int direction) +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) ----"); + ("---- Test on struct containing dynamic array and its size (cbps test) ----"); /* create and fill the struct */ i = xbt_new(Clause, 1); @@ -583,7 +587,7 @@ 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) ----"); + ("---- Test on struct containing dynamic array and its size when size=0 (cbps test) ----"); /* create and fill the struct */ i = xbt_new(Clause, 1); @@ -634,7 +638,8 @@ static void register_types(void) 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_datadesc_ref("homostruct*", + gras_datadesc_by_name("homostruct")); gras_msgtype_declare("homostruct*", my_type); my_type = gras_datadesc_struct("hetestruct"); @@ -648,12 +653,13 @@ static void register_types(void) 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_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); + 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); @@ -664,7 +670,8 @@ static void register_types(void) gras_datadesc_by_name("homostruct")); gras_datadesc_struct_close(my_type); my_type = - gras_datadesc_ref("nestedstruct*", gras_datadesc_by_name("nestedstruct")); + gras_datadesc_ref("nestedstruct*", + gras_datadesc_by_name("nestedstruct")); gras_msgtype_declare("nestedstruct*", my_type); my_type = gras_datadesc_struct("chained_list_t"); @@ -677,7 +684,7 @@ static void register_types(void) gras_msgtype_declare("chained_list_t*", ref_my_type); my_type = - gras_datadesc_dynar(gras_datadesc_by_name("string"), &free_string); + 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); @@ -717,13 +724,14 @@ int main(int argc, char *argv[]) printf(" --write file: writes the description to the given file\n"); printf(" --copy: copy the description in memory\n"); printf - (" --regen: write the description to the file of the current architecture\n"); + (" --regen: write the description to the file of the current architecture\n"); printf(" --help: displays this message\n"); exit(0); } else if (!strcmp(argv[cpt], "--regen")) { direction = WRITE; filename = - bprintf("datadesc.%s", gras_datadesc_arch_name(gras_arch_selfid())); + bprintf("datadesc.%s", + gras_datadesc_arch_name(gras_arch_selfid())); } else if (!strcmp(argv[cpt], "--read")) { direction = READ; } else if (!strcmp(argv[cpt], "--write")) { @@ -736,11 +744,13 @@ int main(int argc, char *argv[]) } if (direction == WRITE) { - INFO1("Write to file %s", strrchr(filename,'/')?strrchr(filename,'/')+1:filename); + INFO1("Write to file %s", + strrchr(filename, '/') ? strrchr(filename, '/') + 1 : filename); sock = gras_socket_client_from_file(filename); } if (direction == READ) { - INFO1("Read from file %s", strrchr(filename,'/')?strrchr(filename,'/')+1:filename); + INFO1("Read from file %s", + strrchr(filename, '/') ? strrchr(filename, '/') + 1 : filename); sock = gras_socket_server_from_file(filename); } if (direction == COPY) { diff --git a/teshsuite/gras/msg_handle/msg_handle.c b/teshsuite/gras/msg_handle/msg_handle.c index 678115b1d7..0c57449009 100644 --- a/teshsuite/gras/msg_handle/msg_handle.c +++ b/teshsuite/gras/msg_handle/msg_handle.c @@ -16,7 +16,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific to this test"); int server(int argc, char *argv[]); int client(int argc, char *argv[]); -static int server_cb_hello_handler(gras_msg_cb_ctx_t ctx, void *payload_data) +static int server_cb_hello_handler(gras_msg_cb_ctx_t ctx, + void *payload_data) { INFO0("Got the message"); return 0; diff --git a/teshsuite/msg/get_sender.c b/teshsuite/msg/get_sender.c index 14419322a6..a69d93fc05 100644 --- a/teshsuite/msg/get_sender.c +++ b/teshsuite/msg/get_sender.c @@ -14,7 +14,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific to this example"); static int send(int argc, char *argv[]) { INFO0("Sending"); - MSG_task_put(MSG_task_create("Blah", 0.0, 0.0, NULL), MSG_host_self(), 0); + MSG_task_put(MSG_task_create("Blah", 0.0, 0.0, NULL), MSG_host_self(), + 0); MSG_process_sleep(1.); /* FIXME: if the sender exits before the receiver calls get_sender(), bad thing happens */ INFO0("Exiting"); return 0; diff --git a/teshsuite/simdag/basic0.c b/teshsuite/simdag/basic0.c index a178f226f2..69c5821d17 100644 --- a/teshsuite/simdag/basic0.c +++ b/teshsuite/simdag/basic0.c @@ -40,8 +40,8 @@ int main(int argc, char **argv) /* let's launch the simulation! */ - SD_task_schedule(taskInit, 1, SD_workstation_get_list(), no_cost, no_cost, - -1.0); + SD_task_schedule(taskInit, 1, SD_workstation_get_list(), no_cost, + no_cost, -1.0); SD_task_schedule(taskA, 2, SD_workstation_get_list(), no_cost, communication_amount1, -1.0); SD_task_schedule(taskB, 2, SD_workstation_get_list(), no_cost, diff --git a/teshsuite/simdag/basic1.c b/teshsuite/simdag/basic1.c index f9e216a64b..d8b8fc4a09 100644 --- a/teshsuite/simdag/basic1.c +++ b/teshsuite/simdag/basic1.c @@ -42,8 +42,8 @@ int main(int argc, char **argv) workstation = SD_workstation_get_list(); /* let's launch the simulation! */ - SD_task_schedule(taskInit, 1, SD_workstation_get_list(), &no_cost, &no_cost, - -1.0); + SD_task_schedule(taskInit, 1, SD_workstation_get_list(), &no_cost, + &no_cost, -1.0); SD_task_schedule(taskA, 1, &workstation[0], &no_cost, &communication_amount1, -1.0); SD_task_schedule(taskB, 1, &workstation[1], &no_cost, diff --git a/teshsuite/simdag/basic2.c b/teshsuite/simdag/basic2.c index 2f9d23009d..0f9f6fc87e 100644 --- a/teshsuite/simdag/basic2.c +++ b/teshsuite/simdag/basic2.c @@ -41,8 +41,8 @@ int main(int argc, char **argv) workstation = SD_workstation_get_list(); /* let's launch the simulation! */ - SD_task_schedule(taskInit, 1, SD_workstation_get_list(), &no_cost, &no_cost, - -1.0); + SD_task_schedule(taskInit, 1, SD_workstation_get_list(), &no_cost, + &no_cost, -1.0); SD_task_schedule(taskA, 1, &workstation[0], &no_cost, &communication_amount1, -1.0); SD_task_schedule(taskB, 1, &workstation[1], &no_cost, diff --git a/teshsuite/simdag/basic3.c b/teshsuite/simdag/basic3.c index 2fa069a9f8..e0437d67ba 100644 --- a/teshsuite/simdag/basic3.c +++ b/teshsuite/simdag/basic3.c @@ -34,8 +34,8 @@ int main(int argc, char **argv) taskFin = SD_task_create("Task Fin", NULL, 1.0); /* let's launch the simulation! */ - SD_task_schedule(taskInit, 1, SD_workstation_get_list(), no_cost, no_cost, - -1.0); + SD_task_schedule(taskInit, 1, SD_workstation_get_list(), no_cost, + no_cost, -1.0); SD_task_schedule(taskA, 2, SD_workstation_get_list(), no_cost, no_cost, -1.0); SD_task_schedule(taskFin, 1, SD_workstation_get_list(), no_cost, no_cost, diff --git a/teshsuite/simdag/basic4.c b/teshsuite/simdag/basic4.c index 7009d3d7c7..a55cf24730 100644 --- a/teshsuite/simdag/basic4.c +++ b/teshsuite/simdag/basic4.c @@ -38,8 +38,8 @@ int main(int argc, char **argv) /* let's launch the simulation! */ - SD_task_schedule(taskInit, 1, SD_workstation_get_list(), no_cost, no_cost, - -1.0); + SD_task_schedule(taskInit, 1, SD_workstation_get_list(), no_cost, + no_cost, -1.0); SD_task_schedule(taskA, 2, SD_workstation_get_list(), no_cost, amount, -1.0); SD_task_schedule(taskFin, 1, SD_workstation_get_list(), no_cost, no_cost, diff --git a/teshsuite/simdag/basic5.c b/teshsuite/simdag/basic5.c index 48a988b326..2b3a6c9e3e 100644 --- a/teshsuite/simdag/basic5.c +++ b/teshsuite/simdag/basic5.c @@ -38,8 +38,8 @@ int main(int argc, char **argv) taskB = SD_task_create("Task B", NULL, 1.0); /* let's launch the simulation! */ - SD_task_schedule(taskInit, 1, SD_workstation_get_list(), no_cost, no_cost, - -1.0); + SD_task_schedule(taskInit, 1, SD_workstation_get_list(), no_cost, + no_cost, -1.0); SD_task_schedule(taskA, 2, SD_workstation_get_list(), no_cost, amount, -1.0); SD_task_schedule(taskB, 1, SD_workstation_get_list(), comput, no_cost, diff --git a/teshsuite/simdag/basic6.c b/teshsuite/simdag/basic6.c index d5c3078e63..e2516dde64 100644 --- a/teshsuite/simdag/basic6.c +++ b/teshsuite/simdag/basic6.c @@ -25,10 +25,10 @@ int main(int argc, char **argv) taskA = SD_task_create("Task A", NULL, 1.0); taskB = SD_task_create("Task B", NULL, 1.0); - SD_task_schedule(taskA, 1, SD_workstation_get_list(), comp_cost, comm_cost, - -1.0); - SD_task_schedule(taskB, 1, SD_workstation_get_list(), comp_cost, comm_cost, - -1.0); + SD_task_schedule(taskA, 1, SD_workstation_get_list(), comp_cost, + comm_cost, -1.0); + SD_task_schedule(taskB, 1, SD_workstation_get_list(), comp_cost, + comm_cost, -1.0); SD_simulate(-1.0); diff --git a/teshsuite/simdag/network/p2p/test_latency1.c b/teshsuite/simdag/network/p2p/test_latency1.c index 6b99c39f95..7a3b152688 100644 --- a/teshsuite/simdag/network/p2p/test_latency1.c +++ b/teshsuite/simdag/network/p2p/test_latency1.c @@ -1,5 +1,5 @@ /* Latency tests */ - + /* Copyright (c) 2007, 2009, 2010. The SimGrid Team. * All rights reserved. */ diff --git a/teshsuite/simdag/network/p2p/test_latency2.c b/teshsuite/simdag/network/p2p/test_latency2.c index a29803d9c5..e5e1e4ad9a 100644 --- a/teshsuite/simdag/network/p2p/test_latency2.c +++ b/teshsuite/simdag/network/p2p/test_latency2.c @@ -1,5 +1,5 @@ /* Latency tests */ - + /* Copyright (c) 2007, 2009, 2010. The SimGrid Team. * All rights reserved. */ diff --git a/teshsuite/simdag/network/p2p/test_latency3.c b/teshsuite/simdag/network/p2p/test_latency3.c index cd85602894..ff385fb880 100644 --- a/teshsuite/simdag/network/p2p/test_latency3.c +++ b/teshsuite/simdag/network/p2p/test_latency3.c @@ -1,5 +1,5 @@ /* Latency tests */ - + /* Copyright (c) 2007, 2009, 2010. The SimGrid Team. * All rights reserved. */ diff --git a/teshsuite/simdag/network/p2p/test_latency_bound.c b/teshsuite/simdag/network/p2p/test_latency_bound.c index c506d7979a..c52cc146c6 100644 --- a/teshsuite/simdag/network/p2p/test_latency_bound.c +++ b/teshsuite/simdag/network/p2p/test_latency_bound.c @@ -1,5 +1,5 @@ /* Latency tests */ - + /* Copyright (c) 2007, 2009, 2010. The SimGrid Team. * All rights reserved. */ diff --git a/teshsuite/simdag/network/test_reinit_costs.c b/teshsuite/simdag/network/test_reinit_costs.c index 1fbd3daf64..c269ba7d39 100644 --- a/teshsuite/simdag/network/test_reinit_costs.c +++ b/teshsuite/simdag/network/test_reinit_costs.c @@ -68,8 +68,8 @@ static SD_task_t create_root_with_costs() SD_task_t root; root = SD_task_create("Root", NULL, 1.0); - SD_task_schedule(root, 2, SD_workstation_get_list(), comp_cost, comm_cost, - -1.0); + SD_task_schedule(root, 2, SD_workstation_get_list(), comp_cost, + comm_cost, -1.0); return root; } diff --git a/teshsuite/simdag/platforms/basic_parsing_test.c b/teshsuite/simdag/platforms/basic_parsing_test.c index 6455f43d79..1d9f08c8fa 100644 --- a/teshsuite/simdag/platforms/basic_parsing_test.c +++ b/teshsuite/simdag/platforms/basic_parsing_test.c @@ -20,7 +20,7 @@ int main(int argc, char **argv) const SD_link_t *route; const char *name1; const char *name2; - int route_size,i,j,k; + int route_size, i, j, k; int list_size; SD_init(&argc, argv); @@ -30,60 +30,57 @@ int main(int argc, char **argv) printf("Workstation number: %d, link number: %d\n", SD_workstation_get_number(), SD_link_get_number()); -if(argc == 3) -{ - if(!strcmp(argv[2],"ONE_LINK")) - { - workstations = SD_workstation_get_list(); - w1 = workstations[0]; - w2 = workstations[1]; - name1 = SD_workstation_get_name(w1); - name2 = SD_workstation_get_name(w2); + if (argc == 3) { + if (!strcmp(argv[2], "ONE_LINK")) { + workstations = SD_workstation_get_list(); + w1 = workstations[0]; + w2 = workstations[1]; + name1 = SD_workstation_get_name(w1); + name2 = SD_workstation_get_name(w2); - printf("Route between %s and %s\n", name1, name2); - route = SD_route_get_list(w1, w2); - route_size = SD_route_get_size(w1, w2); - printf("Route size %d\n", route_size); - for (i = 0; i < route_size; i++) { - printf(" Link %s: latency = %f, bandwidth = %f\n", - SD_link_get_name(route[i]), SD_link_get_current_latency(route[i]), - SD_link_get_current_bandwidth(route[i])); - } - printf("Route latency = %f, route bandwidth = %f\n", - SD_route_get_current_latency(w1, w2), - SD_route_get_current_bandwidth(w1, w2)); + printf("Route between %s and %s\n", name1, name2); + route = SD_route_get_list(w1, w2); + route_size = SD_route_get_size(w1, w2); + printf("Route size %d\n", route_size); + for (i = 0; i < route_size; i++) { + printf(" Link %s: latency = %f, bandwidth = %f\n", + SD_link_get_name(route[i]), + SD_link_get_current_latency(route[i]), + SD_link_get_current_bandwidth(route[i])); + } + printf("Route latency = %f, route bandwidth = %f\n", + SD_route_get_current_latency(w1, w2), + SD_route_get_current_bandwidth(w1, w2)); - } - if(!strcmp(argv[2],"FULL_LINK")) - { - workstations = SD_workstation_get_list(); - list_size = SD_workstation_get_number(); - for(i = 0; i < list_size; i++) - { - w1 = workstations[i]; - name1 = SD_workstation_get_name(w1); - for(j = 0 ; j < list_size; j++) - { - w2 = workstations[j]; - name2 = SD_workstation_get_name(w2); - printf("Route between %s and %s\n", name1, name2); - route = SD_route_get_list(w1, w2); - route_size = SD_route_get_size(w1, w2); - printf("\tRoute size %d\n", route_size); - for (k = 0; k < route_size; k++) { - printf("\tLink %s: latency = %f, bandwidth = %f\n", - SD_link_get_name(route[k]), SD_link_get_current_latency(route[k]), - SD_link_get_current_bandwidth(route[k])); - } - printf("\tRoute latency = %f, route bandwidth = %f\n", - SD_route_get_current_latency(w1, w2), - SD_route_get_current_bandwidth(w1, w2)); - } - } + } + if (!strcmp(argv[2], "FULL_LINK")) { + workstations = SD_workstation_get_list(); + list_size = SD_workstation_get_number(); + for (i = 0; i < list_size; i++) { + w1 = workstations[i]; + name1 = SD_workstation_get_name(w1); + for (j = 0; j < list_size; j++) { + w2 = workstations[j]; + name2 = SD_workstation_get_name(w2); + printf("Route between %s and %s\n", name1, name2); + route = SD_route_get_list(w1, w2); + route_size = SD_route_get_size(w1, w2); + printf("\tRoute size %d\n", route_size); + for (k = 0; k < route_size; k++) { + printf("\tLink %s: latency = %f, bandwidth = %f\n", + SD_link_get_name(route[k]), + SD_link_get_current_latency(route[k]), + SD_link_get_current_bandwidth(route[k])); + } + printf("\tRoute latency = %f, route bandwidth = %f\n", + SD_route_get_current_latency(w1, w2), + SD_route_get_current_bandwidth(w1, w2)); + } + } - } + } -} + } SD_exit(); return 0; diff --git a/teshsuite/simdag/platforms/is_router_test.c b/teshsuite/simdag/platforms/is_router_test.c index 3520683586..60f3b5bdb0 100644 --- a/teshsuite/simdag/platforms/is_router_test.c +++ b/teshsuite/simdag/platforms/is_router_test.c @@ -17,8 +17,8 @@ int main(int argc, char **argv) int size; xbt_dict_t eltms = xbt_dict_new(); SD_init(&argc, argv); - xbt_dict_cursor_t cursor=NULL; - char *key,*data; + xbt_dict_cursor_t cursor = NULL; + char *key, *data; /* creation of the environment */ SD_create_environment(argv[1]); @@ -26,10 +26,12 @@ int main(int argc, char **argv) eltms = global_routing->where_network_elements; size = xbt_dict_size(eltms); - printf("Workstation number: %d, link number: %d, elmts number: %d\n",SD_workstation_get_number(), SD_link_get_number(),size); + printf("Workstation number: %d, link number: %d, elmts number: %d\n", + SD_workstation_get_number(), SD_link_get_number(), size); - xbt_dict_foreach(eltms,cursor,key,data) { - printf(" - Seen: \"%s\" is type : %d\n",key,(int) global_routing->get_network_element_type(key)); + xbt_dict_foreach(eltms, cursor, key, data) { + printf(" - Seen: \"%s\" is type : %d\n", key, + (int) global_routing->get_network_element_type(key)); } //printf("%s is router : %d\n",name1,global_routing->is_router(name1)); xbt_dict_free(&eltms); diff --git a/teshsuite/xbt/log_large_test.c b/teshsuite/xbt/log_large_test.c index aab5f275ea..d51d8f363a 100644 --- a/teshsuite/xbt/log_large_test.c +++ b/teshsuite/xbt/log_large_test.c @@ -38,8 +38,8 @@ int main(int argc, char *argv[]) xbt_init(&argc, argv); - INFO10("This is a very large message:\n0%s1%s2%s3%s4%s5%s6%s7%s8%s9%s", tmp, - tmp, tmp, tmp, tmp, tmp, tmp, tmp, tmp, tmp); + INFO10("This is a very large message:\n0%s1%s2%s3%s4%s5%s6%s7%s8%s9%s", + tmp, tmp, tmp, tmp, tmp, tmp, tmp, tmp, tmp, tmp); INFO1("Done (strlen>%d)", (int) (10 * strlen(tmp))); free(tmp); diff --git a/teshsuite/xbt/parallel_log_crashtest.c b/teshsuite/xbt/parallel_log_crashtest.c index f606f437a1..7fb2715531 100644 --- a/teshsuite/xbt/parallel_log_crashtest.c +++ b/teshsuite/xbt/parallel_log_crashtest.c @@ -70,7 +70,9 @@ int crasher(int argc, char *argv[]) /* spawn threads */ for (i = 0; i < crasher_amount; i++) { char *name = bprintf("thread %d", i); - crashers[i] = xbt_thread_create(name, &crasher_thread, &id[i],0/*not joinable*/); + crashers[i] = + xbt_thread_create(name, &crasher_thread, &id[i], + 0 /*not joinable */ ); free(name); } diff --git a/testsuite/simdag/sd_test.c b/testsuite/simdag/sd_test.c index 3031f3183c..5f3451ba7e 100644 --- a/testsuite/simdag/sd_test.c +++ b/testsuite/simdag/sd_test.c @@ -54,9 +54,8 @@ int main(int argc, char **argv) workstations = SD_workstation_get_list(); - for(i=0 ; i < SD_workstation_get_number() ; i++) - { - INFO1("name : %s",SD_workstation_get_name(workstations[i]) ); + for (i = 0; i < SD_workstation_get_number(); i++) { + INFO1("name : %s", SD_workstation_get_name(workstations[i])); } w1 = workstations[0]; @@ -73,15 +72,18 @@ int main(int argc, char **argv) taskC = SD_task_create("Task C", NULL, 30.0); taskD = SD_task_create("Task D", NULL, 60.0); - INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1, - SD_workstation_get_computation_time(w1, computation_amount1)); - INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2, - SD_workstation_get_computation_time(w2, computation_amount2)); + INFO3("Computation time for %f flops on %s: %f", computation_amount1, + name1, SD_workstation_get_computation_time(w1, + computation_amount1)); + INFO3("Computation time for %f flops on %s: %f", computation_amount2, + name2, SD_workstation_get_computation_time(w2, + computation_amount2)); INFO2("Route between %s and %s:", name1, name2); for (i = 0; i < route_size; i++) { INFO3("\tLink %s: latency = %f, bandwidth = %f", - SD_link_get_name(route[i]), SD_link_get_current_latency(route[i]), + SD_link_get_name(route[i]), + SD_link_get_current_latency(route[i]), SD_link_get_current_bandwidth(route[i])); } INFO2("Route latency = %f, route bandwidth = %f", @@ -104,7 +106,8 @@ int main(int argc, char **argv) TRY { SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */ - xbt_assert0(0, "Hey, I can add a dependency between Task A and Task A!"); + xbt_assert0(0, + "Hey, I can add a dependency between Task A and Task A!"); } CATCH(ex) { } @@ -147,7 +150,7 @@ int main(int argc, char **argv) const int workstation_number = 2; const SD_workstation_t workstation_list[] = { w1, w2 }; double computation_amount[] = - { computation_amount1, computation_amount2 }; + { computation_amount1, computation_amount2 }; double communication_amount[] = { 0, communication_amount12, communication_amount21, 0 @@ -178,7 +181,7 @@ int main(int argc, char **argv) xbt_dynar_get_cpy(changed_tasks, 0, &checkD); xbt_dynar_get_cpy(changed_tasks, 1, &checkC); xbt_dynar_get_cpy(changed_tasks, 2, &checkB); - + xbt_assert0(checkD == taskD && checkC == taskC && checkB == taskB, "Unexpected simulation results"); diff --git a/testsuite/surf/lmm_usage.c b/testsuite/surf/lmm_usage.c index b47fbff345..5e8f6ab63a 100644 --- a/testsuite/surf/lmm_usage.c +++ b/testsuite/surf/lmm_usage.c @@ -16,7 +16,8 @@ #include "xbt/module.h" #include -XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, + "Messages specific for surf example"); #define PRINT_VAR(var) DEBUG1(#var " = %g",lmm_variable_getvalue(var)); #define SHOW_EXPR(expr) DEBUG1(#expr " = %g",expr); @@ -151,7 +152,7 @@ void test1(method_t method) lmm_solve(Sys); } else if (method == LAGRANGE_VEGAS) { double x = 3 * a / 4 - 3 * b / 8 + - sqrt(9 * b * b + 4 * a * a - 4 * a * b) / 8; + sqrt(9 * b * b + 4 * a * a - 4 * a * b) / 8; /* Computed with mupad and D_f=1.0 */ double max_deviation = 0.0; if (x > a) { @@ -163,12 +164,14 @@ void test1(method_t method) lagrange_solve(Sys); - max_deviation = MAX(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); - max_deviation = MAX(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); + max_deviation = + MAX(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); + max_deviation = + MAX(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); if (max_deviation > MAXMIN_PRECISION) { WARN1("Max Deviation from optimal solution : %g", max_deviation); @@ -196,12 +199,14 @@ void test1(method_t method) x = a; lagrange_solve(Sys); - max_deviation = MAX(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); - max_deviation = MAX(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_1) - x)); + max_deviation = + MAX(max_deviation, fabs(lmm_variable_getvalue(R_3) - x)); + max_deviation = + MAX(max_deviation, fabs(lmm_variable_getvalue(R_2) - (b - a + x))); max_deviation = - MAX(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); + MAX(max_deviation, fabs(lmm_variable_getvalue(R_1_2_3) - (a - x))); if (max_deviation > MAXMIN_PRECISION) { WARN1("Max Deviation from optimal solution : %g", max_deviation); @@ -416,7 +421,7 @@ void test3(method_t method) for (j = 0; j < 16; j++) { tmp_name[i + j] = bprintf("X_%03d", j); tmp_var[j] = - lmm_variable_new(Sys, (void *) tmp_name[i + j], 1.0, -1.0, 15); + lmm_variable_new(Sys, (void *) tmp_name[i + j], 1.0, -1.0, 15); lmm_update_variable_weight(Sys, tmp_var[j], 1.0); } diff --git a/testsuite/surf/surf_usage.c b/testsuite/surf/surf_usage.c index 9d5cfedf48..75c08d3c17 100644 --- a/testsuite/surf/surf_usage.c +++ b/testsuite/surf/surf_usage.c @@ -14,7 +14,8 @@ #include "surf/surf.h" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, + "Messages specific for surf example"); const char *string_action(e_surf_action_state_t state); const char *string_action(e_surf_action_state_t state) @@ -58,12 +59,12 @@ void test(char *platform) /*********************** CPU ***********************************/ DEBUG1("%p", surf_cpu_model); - cpuA = surf_model_resource_by_name(surf_cpu_model,"Cpu A"); - cpuB = surf_model_resource_by_name(surf_cpu_model,"Cpu B"); + cpuA = surf_model_resource_by_name(surf_cpu_model, "Cpu A"); + cpuB = surf_model_resource_by_name(surf_cpu_model, "Cpu B"); /* Let's check that those two processors exist */ - DEBUG2("%s : %p",surf_resource_name(cpuA), cpuA); - DEBUG2("%s : %p",surf_resource_name(cpuB), cpuB); + DEBUG2("%s : %p", surf_resource_name(cpuA), cpuA); + DEBUG2("%s : %p", surf_resource_name(cpuB), cpuB); /* Let's do something on it */ actionA = surf_cpu_model->extension.cpu.execute(cpuA, 1000.0); @@ -71,9 +72,9 @@ void test(char *platform) actionC = surf_cpu_model->extension.cpu.sleep(cpuB, 7.32); /* Use whatever calling style you want... */ - stateActionA = surf_cpu_model->action_state_get(actionA); /* When you know actionA model type */ - stateActionB = actionB->model_type->action_state_get(actionB); /* If you're unsure about it's model type */ - stateActionC = surf_cpu_model->action_state_get(actionC); /* When you know actionA model type */ + stateActionA = surf_cpu_model->action_state_get(actionA); /* When you know actionA model type */ + stateActionB = actionB->model_type->action_state_get(actionB); /* If you're unsure about it's model type */ + stateActionC = surf_cpu_model->action_state_get(actionC); /* When you know actionA model type */ /* And just look at the state of these tasks */ DEBUG2("actionA : %p (%s)", actionA, string_action(stateActionA)); @@ -82,8 +83,8 @@ void test(char *platform) /*********************** Network *******************************/ DEBUG1("%p", surf_network_model); - cardA = surf_model_resource_by_name(surf_network_model,"Cpu A"); - cardB = surf_model_resource_by_name(surf_network_model,"Cpu B"); + cardA = surf_model_resource_by_name(surf_network_model, "Cpu A"); + cardB = surf_model_resource_by_name(surf_network_model, "Cpu B"); /* Let's check that those two processors exist */ DEBUG2("%s : %p", surf_resource_name(cardA), cardA); @@ -91,8 +92,8 @@ void test(char *platform) /* Let's do something on it */ commAB = - surf_network_model->extension.network.communicate("Cpu A","Cpu B", - 150.0, -1.0); + surf_network_model->extension.network.communicate("Cpu A", "Cpu B", + 150.0, -1.0); surf_solve(); /* Takes traces into account. Returns 0.0 */ do { @@ -112,19 +113,21 @@ void test(char *platform) } DEBUG0("\t Network actions"); while ((action = - xbt_swag_extract(surf_network_model->states.failed_action_set))) { + xbt_swag_extract(surf_network_model->states. + failed_action_set))) { DEBUG1("\t * Failed : %p", action); action->model_type->action_unref(action); } while ((action = - xbt_swag_extract(surf_network_model->states.done_action_set))) { + xbt_swag_extract(surf_network_model->states. + done_action_set))) { DEBUG1("\t * Done : %p", action); action->model_type->action_unref(action); } } while ((xbt_swag_size(surf_network_model->states.running_action_set) || xbt_swag_size(surf_cpu_model->states.running_action_set)) && - surf_solve() >= 0.0); + surf_solve() >= 0.0); DEBUG0("Simulation Terminated"); } diff --git a/testsuite/surf/surf_usage2.c b/testsuite/surf/surf_usage2.c index 8be876df57..eda5f21c4d 100644 --- a/testsuite/surf/surf_usage2.c +++ b/testsuite/surf/surf_usage2.c @@ -13,7 +13,8 @@ #include "surf/surf.h" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, + "Messages specific for surf example"); const char *string_action(e_surf_action_state_t state); const char *string_action(e_surf_action_state_t state) @@ -48,16 +49,21 @@ void test(char *platform) int running; int workstation_id = - find_model_description(surf_workstation_model_description, "CLM03"); + find_model_description(surf_workstation_model_description, "CLM03"); - surf_workstation_model_description[workstation_id].model_init_preparse(platform); + surf_workstation_model_description[workstation_id]. + model_init_preparse(platform); parse_platform_file(platform); - if (surf_workstation_model_description[workstation_id].model_init_postparse) - surf_workstation_model_description[workstation_id].model_init_postparse(); + if (surf_workstation_model_description[workstation_id]. + model_init_postparse) + surf_workstation_model_description[workstation_id]. + model_init_postparse(); /*********************** WORKSTATION ***********************************/ - workstationA = surf_model_resource_by_name(surf_workstation_model,"Cpu A"); - workstationB = surf_model_resource_by_name(surf_workstation_model,"Cpu B"); + workstationA = + surf_model_resource_by_name(surf_workstation_model, "Cpu A"); + workstationB = + surf_model_resource_by_name(surf_workstation_model, "Cpu B"); /* Let's check that those two processors exist */ DEBUG2("%s : %p", surf_resource_name(workstationA), workstationA); @@ -65,16 +71,18 @@ void test(char *platform) /* Let's do something on it */ actionA = - surf_workstation_model->extension.workstation.execute(workstationA, 1000.0); + surf_workstation_model->extension.workstation.execute(workstationA, + 1000.0); actionB = - surf_workstation_model->extension.workstation.execute(workstationB, 1000.0); + surf_workstation_model->extension.workstation.execute(workstationB, + 1000.0); actionC = - surf_workstation_model->extension.workstation.sleep(workstationB, 7.32); + surf_workstation_model->extension.workstation.sleep(workstationB, + 7.32); commAB = - surf_workstation_model->extension.workstation.communicate(workstationA, - workstationB, 150.0, - -1.0); + surf_workstation_model->extension.workstation. + communicate(workstationA, workstationB, 150.0, -1.0); surf_solve(); /* Takes traces into account. Returns 0.0 */ do { @@ -88,13 +96,11 @@ void test(char *platform) xbt_dynar_foreach(model_list, iter, model) { DEBUG1("\t %s actions", model->name); - while ((action = - xbt_swag_extract(model->states.failed_action_set))) { + while ((action = xbt_swag_extract(model->states.failed_action_set))) { DEBUG1("\t * Failed : %p", action); model->action_unref(action); } - while ((action = - xbt_swag_extract(model->states.done_action_set))) { + while ((action = xbt_swag_extract(model->states.done_action_set))) { DEBUG1("\t * Done : %p", action); model->action_unref(action); } diff --git a/testsuite/surf/trace_usage.c b/testsuite/surf/trace_usage.c index 53d3e29674..ea7b09b14e 100644 --- a/testsuite/surf/trace_usage.c +++ b/testsuite/surf/trace_usage.c @@ -16,7 +16,8 @@ #include "surf/surf.h" #include "xbt/log.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, + "Messages specific for surf example"); void test(void); void test(void) diff --git a/testsuite/xbt/graphxml_usage.c b/testsuite/xbt/graphxml_usage.c index a95b61a8fe..a8f82b88eb 100644 --- a/testsuite/xbt/graphxml_usage.c +++ b/testsuite/xbt/graphxml_usage.c @@ -55,13 +55,15 @@ void test(char *graph_file) xbt_dynar_t edges = NULL; xbt_dynar_t nodes = NULL; - xbt_graph_t graph = xbt_graph_read(graph_file, &node_label_and_data, NULL); + xbt_graph_t graph = + xbt_graph_read(graph_file, &node_label_and_data, NULL); n = xbt_dynar_length(xbt_graph_get_nodes(graph)); if (test_export_xml) { INFO0("---- Testing XML export. Exporting to testgraph.xml ----"); - xbt_graph_export_graphxml(graph, "testgraph.xml", NULL, NULL, NULL, NULL); + xbt_graph_export_graphxml(graph, "testgraph.xml", NULL, NULL, NULL, + NULL); } if (test_export_dot) { INFO0("---- Testing GraphViz export. Exporting to testgraph.dot ----"); diff --git a/testsuite/xbt/heap_bench.c b/testsuite/xbt/heap_bench.c index 0c548ef956..417f987e9e 100644 --- a/testsuite/xbt/heap_bench.c +++ b/testsuite/xbt/heap_bench.c @@ -29,7 +29,7 @@ int compare_double(const void *a, const void *b); void test_heap_validity(int size); void test_heap_mean_operation(int size); -void test_reset_heap(xbt_heap_t *heap, int size); +void test_reset_heap(xbt_heap_t * heap, int size); int compare_double(const void *a, const void *b) @@ -104,7 +104,7 @@ void test_heap_mean_operation(int size) xbt_heap_free(heap); } -void test_reset_heap(xbt_heap_t *heap, int size) +void test_reset_heap(xbt_heap_t * heap, int size) { int i; xbt_heap_free(*heap); diff --git a/testsuite/xbt/log_usage.c b/testsuite/xbt/log_usage.c index 64a3cd1409..707cf02863 100644 --- a/testsuite/xbt/log_usage.c +++ b/testsuite/xbt/log_usage.c @@ -14,7 +14,8 @@ -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(test, top, "Logging specific to this test"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(test, top, + "Logging specific to this test"); XBT_LOG_NEW_CATEGORY(top, "Useless test channel"); #ifdef __BORLANDC__ diff --git a/tools/gras/stub_generator.c b/tools/gras/stub_generator.c index 47dd65a611..66c259665d 100644 --- a/tools/gras/stub_generator.c +++ b/tools/gras/stub_generator.c @@ -58,7 +58,8 @@ static s_process_t process; static void parse_process_init(void) { - xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL); + xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, + NULL); xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL); process.argc = 1; process.argv = xbt_new(char *, 1); @@ -70,7 +71,8 @@ static void parse_process_init(void) static void parse_argument(void) { process.argc++; - process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *)); + process.argv = + xbt_realloc(process.argv, (process.argc) * sizeof(char *)); process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value); } @@ -103,8 +105,8 @@ int main(int argc, char *argv[]) for (i = 1; i < argc; i++) { int need_removal = 0; if (!strncmp("--extra-process=", argv[i], strlen("--extra-process="))) { - xbt_dict_set(process_function_set, argv[i] + strlen("--extra-process="), - NULL, NULL); + xbt_dict_set(process_function_set, + argv[i] + strlen("--extra-process="), NULL, NULL); need_removal = 1; } @@ -130,7 +132,8 @@ int main(int argc, char *argv[]) DEBUG2("%p %p", parse_process_init, &parse_process_init); surfxml_add_callback(STag_surfxml_process_cb_list, &parse_process_init); surfxml_add_callback(ETag_surfxml_argument_cb_list, &parse_argument); - surfxml_add_callback(ETag_surfxml_process_cb_list, &parse_process_finalize); + surfxml_add_callback(ETag_surfxml_process_cb_list, + &parse_process_finalize); for (i = 2; i < argc; i++) { deployment_file = argv[i]; diff --git a/tools/gras/unix_stub_generator.c b/tools/gras/unix_stub_generator.c index 2fee052b3f..69d342ded7 100644 --- a/tools/gras/unix_stub_generator.c +++ b/tools/gras/unix_stub_generator.c @@ -65,14 +65,14 @@ char *warning = NULL; /**********************************************/ const char *SIM_PREEMBULE = - "/* specific to Borland Compiler */\n" - "#ifdef __BORLANDC__\n" - "#pragma hdrstop\n" - "#endif\n\n" - "#include \n" - "#include \n" - "#include \"msg/msg.h\"\n" - "#include \n" "\n" "char *gras_log=NULL;\n"; + "/* specific to Borland Compiler */\n" + "#ifdef __BORLANDC__\n" + "#pragma hdrstop\n" + "#endif\n\n" + "#include \n" + "#include \n" + "#include \"msg/msg.h\"\n" + "#include \n" "\n" "char *gras_log=NULL;\n"; #define SIM_LAUNCH_FUNC \ @@ -95,15 +95,15 @@ const char *SIM_PREEMBULE = "}\n" const char *SIM_MAIN_POSTEMBULE = "\n" - "\n" - " gras_launch_application(argv[2]);\n" - "\n" - " /* Run the simulation */\n" - " gras_main();\n" - "\n" - " /* cleanup the place */\n" - " gras_clean();\n" - " if (gras_log)\n" " free(gras_log);\n" " return 0;\n" "}\n"; + "\n" + " gras_launch_application(argv[2]);\n" + "\n" + " /* Run the simulation */\n" + " gras_main();\n" + "\n" + " /* cleanup the place */\n" + " gras_clean();\n" + " if (gras_log)\n" " free(gras_log);\n" " return 0;\n" "}\n"; @@ -158,7 +158,8 @@ void generate_sim(char *project) " gras_create_environment(argv[1]);\n" "\n" " /* Application deployment */\n"); xbt_dict_foreach(process_function_set, cursor, key, data) { - fprintf(FICOUT, " gras_function_register(\"%s\", launch_%s);\n", key, key); + fprintf(FICOUT, " gras_function_register(\"%s\", launch_%s);\n", key, + key); } fprintf(FICOUT, "%s", SIM_MAIN_POSTEMBULE); fclose(FICOUT); @@ -178,7 +179,8 @@ void generate_rl(char *project) xbt_dict_foreach(process_function_set, cursor, key, data) { filename = - xbt_new(char, strlen(project) + strlen(RL_SOURCENAME) + strlen(key)); + xbt_new(char, + strlen(project) + strlen(RL_SOURCENAME) + strlen(key)); sprintf(filename, RL_SOURCENAME, project, key); @@ -290,7 +292,8 @@ void generate_makefile_local(char *project, char *deployment) char *filename = NULL; FILE *FICOUT = NULL; - filename = xbt_new(char, strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL)); + filename = + xbt_new(char, strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL)); sprintf(filename, MAKEFILE_FILENAME_LOCAL, project); FICOUT = fopen(filename, "w"); @@ -325,7 +328,8 @@ void generate_makefile_local(char *project, char *deployment) } fprintf(FICOUT, "\n"); - fprintf(FICOUT, "OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n"); + fprintf(FICOUT, + "OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n"); fprintf(FICOUT, "BIN_FILES = "); @@ -352,13 +356,13 @@ void generate_makefile_local(char *project, char *deployment) deployment); fprintf(FICOUT, "\n## Generate the binaries\n"); - fprintf(FICOUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n", project, - project); + fprintf(FICOUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n", + project, project); fprintf(FICOUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n"); xbt_dict_foreach(process_function_set, cursor, key, data) { - fprintf(FICOUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, - key, project, key); + fprintf(FICOUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", + project, key, project, key); fprintf(FICOUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n"); } diff --git a/tools/gras/windows_stub_generator.c b/tools/gras/windows_stub_generator.c index e8c8d87422..585ba12e61 100644 --- a/tools/gras/windows_stub_generator.c +++ b/tools/gras/windows_stub_generator.c @@ -82,7 +82,8 @@ borland_project_write_tabs(borland_project_t project, unsigned int count); * @param name The name of the node. */ static void -borland_project_begin_xml_node(borland_project_t project, const char *name); +borland_project_begin_xml_node(borland_project_t project, + const char *name); /* @@ -100,8 +101,8 @@ borland_project_end_xml_node(borland_project_t project, const char *name); * @param value The value of the element */ static void -borland_project_write_xml_element(borland_project_t project, const char *name, - const char *value); +borland_project_write_xml_element(borland_project_t project, + const char *name, const char *value); /* * Write a FILE xml element in the borland project file. @@ -184,7 +185,8 @@ find_file_path(const char *root_dir, const char *file_name, char *path); /* * generate a Microsoft Visual project file*/ -static void generate_dsp_project(dsp_t project, int is_rl, const char *name); +static void generate_dsp_project(dsp_t project, int is_rl, + const char *name); static void generate_borland_project(borland_project_t project, int is_rl, @@ -218,16 +220,16 @@ generate_borland_project(borland_project_t project, int is_rl, /* construct and write the borland project binary path */ binary_path = - xbt_new0(char, strlen(project->name) + strlen(project->bin_dir) + 6); + xbt_new0(char, strlen(project->name) + strlen(project->bin_dir) + 6); sprintf(binary_path, "%s\\%s.exe", project->bin_dir, project->name); borland_project_write_xml_element(project, "PROJECT", binary_path); xbt_free(binary_path); /* construct an write the object files to generate by the compiler */ obj_path = - xbt_new0(char, - strlen(project->name) + strlen(name) + - (2 * strlen(project->obj_dir)) + 11); + xbt_new0(char, + strlen(project->name) + strlen(name) + + (2 * strlen(project->obj_dir)) + 11); sprintf(binary_path, "%s\\%s.obj\n%s\\%s.obj", project->obj_dir, project->name, project->obj_dir, name); borland_project_write_xml_element(project, "OBJFILES", obj_path); @@ -256,15 +258,15 @@ generate_borland_project(borland_project_t project, int is_rl, if (is_rl) { lib_files = - xbt_new0(char, - (2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + - 2); + xbt_new0(char, + (2 * (strlen(project->lib_dir) + 1)) + + strlen("libgras.lib") + 2); sprintf(lib_files, "%s\\libgras.lib", project->lib_dir); } else { lib_files = - xbt_new0(char, - (2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + - 2); + xbt_new0(char, + (2 * (strlen(project->lib_dir) + 1)) + + strlen("simgrid.lib") + 2); sprintf(lib_files, "%s\\simgrid.lib", project->lib_dir); } @@ -331,7 +333,7 @@ generate_borland_project(borland_project_t project, int is_rl, } include_path = - xbt_new0(char, strlen("$(BCB)\\include") + strlen(__gras_path) + 2); + xbt_new0(char, strlen("$(BCB)\\include") + strlen(__gras_path) + 2); sprintf(include_path, "$(BCB)\\include;%s", __gras_path); borland_project_write_xml_element(project, "INCLUDEPATH", include_path); @@ -454,20 +456,21 @@ generate_borland_project(borland_project_t project, int is_rl, /* construct and write the list of file elements */ /* add the bpf file to the list */ - borland_project_write_file_element(project, main_source, "", project->name, - "BPF", "", ""); + borland_project_write_file_element(project, main_source, "", + project->name, "BPF", "", ""); xbt_free(main_source); /* FIXME : check the source file directory */ /* add the generated source file to the list */ file_name = - xbt_new0(char, strlen(project->src_dir) + strlen(project->name) + 5); + xbt_new0(char, strlen(project->src_dir) + strlen(project->name) + 5); sprintf(file_name, "%s\\_%s.c", project->src_dir, project->name); borland_project_write_file_element(project, file_name, "", project->name, "CCompiler", "", ""); - memset(file_name, 0, strlen(project->src_dir) + strlen(project->name) + 4); + memset(file_name, 0, + strlen(project->src_dir) + strlen(project->name) + 4); sprintf(file_name, "%s\\%s.c", project->src_dir, name); borland_project_write_file_element(project, file_name, "", name, "CCompiler", "", ""); @@ -479,16 +482,18 @@ generate_borland_project(borland_project_t project, int is_rl, if (is_rl) { file_name = - xbt_new0(char, strlen(project->lib_dir) + strlen("libgras.lib") + 2); + xbt_new0(char, + strlen(project->lib_dir) + strlen("libgras.lib") + 2); sprintf(file_name, "%s\\libgras.lib", project->lib_dir); - borland_project_write_file_element(project, file_name, "", "libgras.lib", - "LibTool", "", ""); + borland_project_write_file_element(project, file_name, "", + "libgras.lib", "LibTool", "", ""); } else { file_name = - xbt_new0(char, strlen(project->lib_dir) + strlen("simgrid.lib") + 2); + xbt_new0(char, + strlen(project->lib_dir) + strlen("simgrid.lib") + 2); sprintf(file_name, "%s\\simgrid.lib", project->lib_dir); - borland_project_write_file_element(project, file_name, "", "simgrid.lib", - "LibTool", "", ""); + borland_project_write_file_element(project, file_name, "", + "simgrid.lib", "LibTool", "", ""); } @@ -519,7 +524,8 @@ generate_borland_project(borland_project_t project, int is_rl, borland_project_close(project); } -void borland_project_write_tabs(borland_project_t project, unsigned int count) +void borland_project_write_tabs(borland_project_t project, + unsigned int count) { unsigned int pos; @@ -538,7 +544,8 @@ borland_project_begin_xml_node(borland_project_t project, const char *name) level++; } -void borland_project_end_xml_node(borland_project_t project, const char *name) +void borland_project_end_xml_node(borland_project_t project, + const char *name) { level--; @@ -550,8 +557,8 @@ void borland_project_end_xml_node(borland_project_t project, const char *name) void -borland_project_write_xml_element(borland_project_t project, const char *name, - const char *value) +borland_project_write_xml_element(borland_project_t project, + const char *name, const char *value) { borland_project_write_tabs(project, level); fprintf(project->stream, "<%s value=\"%s\"/>\n", name, value); @@ -607,21 +614,21 @@ void borland_project_write_ide_options(borland_project_t project) { const char *ide_options = - "[Version Info]\nIncludeVerInfo=0\nAutoIncBuild=0\nMajorVer=1\nMinorVer=0\nRelease=0\nBuild=0\nDebug=0\nPreRelease=0\nSpecial=0\nPrivate=0\nDLL=0\nLocale=1036\nCodePage=1252\n\n" - "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" - "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" - "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" - "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" - "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" - "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" - "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" - "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" - "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" - "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" - "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" - "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" - "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" - "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n"; + "[Version Info]\nIncludeVerInfo=0\nAutoIncBuild=0\nMajorVer=1\nMinorVer=0\nRelease=0\nBuild=0\nDebug=0\nPreRelease=0\nSpecial=0\nPrivate=0\nDLL=0\nLocale=1036\nCodePage=1252\n\n" + "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" + "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" + "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" + "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" + "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" + "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" + "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" + "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" + "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" + "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" + "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" + "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" + "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" + "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n"; fprintf(project->stream, ide_options); } @@ -658,11 +665,11 @@ void generate_borland_simulation_project(const char *name) strcpy(borland_project.src_dir, buffer); borland_project.name = - xbt_new0(char, strlen(name) + strlen("simulator") + 2); + xbt_new0(char, strlen(name) + strlen("simulator") + 2); sprintf(borland_project.name, "%s_simulator", name); borland_project.bin_dir = - xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1); + xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1); sprintf(borland_project.bin_dir, "%s\\bin", buffer); hDir = FindFirstFile(borland_project.bin_dir, &wfd); @@ -671,7 +678,7 @@ void generate_borland_simulation_project(const char *name) CreateDirectory(borland_project.bin_dir, NULL); borland_project.obj_dir = - xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1); + xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1); sprintf(borland_project.obj_dir, "%s\\obj", buffer); hDir = FindFirstFile(borland_project.obj_dir, &wfd); @@ -705,7 +712,8 @@ void generate_borland_real_life_project(const char *name) borland_project.lib_dir = xbt_new0(char, MAX_PATH); - GetEnvironmentVariable("LIB_GRAS_PATH", borland_project.lib_dir, MAX_PATH); + GetEnvironmentVariable("LIB_GRAS_PATH", borland_project.lib_dir, + MAX_PATH); GetCurrentDirectory(MAX_PATH, buffer); @@ -714,7 +722,7 @@ void generate_borland_real_life_project(const char *name) strcpy(borland_project.src_dir, buffer); borland_project.bin_dir = - xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1); + xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1); sprintf(borland_project.bin_dir, "%s\\bin", buffer); hDir = FindFirstFile(borland_project.bin_dir, &wfd); @@ -723,7 +731,7 @@ void generate_borland_real_life_project(const char *name) CreateDirectory(borland_project.bin_dir, NULL); borland_project.obj_dir = - xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1); + xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1); sprintf(borland_project.obj_dir, "%s\\obj", buffer); hDir = FindFirstFile(borland_project.obj_dir, &wfd); @@ -923,7 +931,8 @@ void generate_dsp_project(dsp_t project, int is_rl, const char *name) fprintf(project->stream, "!MESSAGE use the Export Makefile command and run\n"); fprintf(project->stream, "!MESSAGE\n"); - fprintf(project->stream, "!MESSAGE NMAKE /f \"%s.mak\".\n", project->name); + fprintf(project->stream, "!MESSAGE NMAKE /f \"%s.mak\".\n", + project->name); fprintf(project->stream, "!MESSAGE\n"); fprintf(project->stream, "!MESSAGE You can specify a configuration when running NMAKE\n"); @@ -1028,7 +1037,8 @@ void generate_dsp_project(dsp_t project, int is_rl, const char *name) fprintf(project->stream, "!ENDIF\n\n"); fprintf(project->stream, "# Begin Target\n\n"); - fprintf(project->stream, "# Name \"%s - Win32 Release\"\n", project->name); + fprintf(project->stream, "# Name \"%s - Win32 Release\"\n", + project->name); fprintf(project->stream, "# Name \"%s - Win32 Debug\"\n", project->name); fprintf(project->stream, "# Begin Group \"Source Files\"\n\n"); fprintf(project->stream, diff --git a/tools/tesh/run_context.c b/tools/tesh/run_context.c index 2c92bb7576..1b98444b22 100644 --- a/tools/tesh/run_context.c +++ b/tools/tesh/run_context.c @@ -40,8 +40,8 @@ static void armageddon_sighandler(int signum) static void wait_it(rctx_t rctx) { - VERB2("Join thread %p which were running background cmd <%s>", rctx->runner, - rctx->filepos); + VERB2("Join thread %p which were running background cmd <%s>", + rctx->runner, rctx->filepos); xbt_os_thread_join(rctx->runner, NULL); } @@ -135,7 +135,8 @@ void rctx_armageddon(rctx_t initiator, int exitcode) xbt_os_mutex_release(armageddon_mutex); return; } - DEBUG1("Armageddon request by <%s> got the lock. Let's go amok", filepos); + DEBUG1("Armageddon request by <%s> got the lock. Let's go amok", + filepos); armageddon_initiator = initiator; xbt_os_mutex_release(armageddon_mutex); @@ -249,9 +250,9 @@ void rctx_pushline(const char *filepos, char kind, char *line) if (rctx->cmd) { if (!rctx->is_empty) { ERROR2 - ("[%s] More than one command in this chunk of lines (previous: %s).\n" - " Cannot guess which input/output belongs to which command.", - filepos, rctx->cmd); + ("[%s] More than one command in this chunk of lines (previous: %s).\n" + " Cannot guess which input/output belongs to which command.", + filepos, rctx->cmd); ERROR1("Test suite `%s': NOK (syntax error)", testsuite_name); rctx_armageddon(rctx, 1); return; @@ -349,8 +350,8 @@ static void *thread_writer(void *r) int got; DEBUG1("Still %d chars to write", rctx->input->used - posw); got = - write(rctx->child_to, rctx->input->data + posw, - rctx->input->used - posw); + write(rctx->child_to, rctx->input->data + posw, + rctx->input->used - posw); if (got > 0) posw += got; if (got < 0) { @@ -401,8 +402,10 @@ static void *thread_reader(void *r) /* let this thread wait for the child so that the main thread can detect the timeout without blocking on the wait */ got_pid = waitpid(rctx->pid, &rctx->status, 0); if (got_pid != rctx->pid) { - perror(bprintf("(%s) Cannot wait for the child %s (got pid %d where pid %d were expected;status=%d)", - xbt_thread_self_name(), rctx->cmd, (int)got_pid, (int)rctx->pid,rctx->status)); + perror(bprintf + ("(%s) Cannot wait for the child %s (got pid %d where pid %d were expected;status=%d)", + xbt_thread_self_name(), rctx->cmd, (int) got_pid, + (int) rctx->pid, rctx->status)); ERROR1("Test suite `%s': NOK (system error)", testsuite_name); rctx_armageddon(rctx, 4); return NULL; @@ -540,9 +543,9 @@ void rctx_start(void) rctx->reader_done = 0; rctx->reader = - xbt_os_thread_create("reader", thread_reader, (void *) rctx); + xbt_os_thread_create("reader", thread_reader, (void *) rctx); rctx->writer = - xbt_os_thread_create("writer", thread_writer, (void *) rctx); + xbt_os_thread_create("writer", thread_writer, (void *) rctx); } else { /* child */ xbt_os_mutex_release(armageddon_mutex); @@ -577,7 +580,8 @@ void rctx_start(void) DEBUG2("Launch a thread to wait for %s %d", old->cmd, old->pid); runner = xbt_os_thread_create(old->cmd, rctx_wait, (void *) old); old->runner = runner; - VERB3("Launched thread %p to wait for %s %d", runner, old->cmd, old->pid); + VERB3("Launched thread %p to wait for %s %d", runner, old->cmd, + old->pid); xbt_dynar_push(bg_jobs, &old); xbt_os_mutex_release(armageddon_mutex); } @@ -634,7 +638,8 @@ void *rctx_wait(void *r) /* Check for broken pipe */ if (rctx->brokenpipe) - VERB0("Warning: Child did not consume all its input (I got broken pipe)"); + VERB0 + ("Warning: Child did not consume all its input (I got broken pipe)"); /* Check for timeouts */ if (rctx->timeout) { @@ -682,9 +687,10 @@ void *rctx_wait(void *r) if (WIFEXITED(rctx->status) && WEXITSTATUS(rctx->status) != rctx->expected_return) { if (rctx->expected_return) - ERROR4("Test suite `%s': NOK (<%s> returned code %d instead of %d)", - testsuite_name, rctx->filepos, - WEXITSTATUS(rctx->status), rctx->expected_return); + ERROR4 + ("Test suite `%s': NOK (<%s> returned code %d instead of %d)", + testsuite_name, rctx->filepos, WEXITSTATUS(rctx->status), + rctx->expected_return); else ERROR3("Test suite `%s': NOK (<%s> returned code %d)", testsuite_name, rctx->filepos, WEXITSTATUS(rctx->status)); @@ -721,11 +727,12 @@ void *rctx_wait(void *r) INFO2("Output of <%s> so far: \n||%s", rctx->filepos, out); free(out); } else if (rctx->output == e_output_check - && (rctx->output_got->used != rctx->output_wanted->used - || strcmp(rctx->output_got->data, rctx->output_wanted->data))) { + && (rctx->output_got->used != rctx->output_wanted->used + || strcmp(rctx->output_got->data, + rctx->output_wanted->data))) { if (XBT_LOG_ISENABLED(tesh, xbt_log_priority_info)) { char *diff = - xbt_str_diff(rctx->output_wanted->data, rctx->output_got->data); + xbt_str_diff(rctx->output_wanted->data, rctx->output_got->data); ERROR2("Output of <%s> mismatch:\n%s", rctx->filepos, diff); free(diff); } diff --git a/tools/tesh/run_context.h b/tools/tesh/run_context.h index 203472f8b4..a188bd5775 100644 --- a/tools/tesh/run_context.h +++ b/tools/tesh/run_context.h @@ -89,4 +89,4 @@ void *rctx_wait(void *rctx); /* Parse a line comming from the suite file, and add this into the rctx */ void rctx_pushline(const char *filepos, char kind, char *line); -#endif /* TESH_RUN_CONTEXT_H */ +#endif /* TESH_RUN_CONTEXT_H */ diff --git a/tools/tesh/tesh.c b/tools/tesh/tesh.c index 0a495b8180..03f4259af7 100644 --- a/tools/tesh/tesh.c +++ b/tools/tesh/tesh.c @@ -218,7 +218,7 @@ int main(int argc, char *argv[]) exit(1); } INFO1("Change directory to %s", argv[i + 1]); - memmove(argv + i, argv + i + 2, (argc - i - 1)*sizeof(char*)); + memmove(argv + i, argv + i + 2, (argc - i - 1) * sizeof(char *)); argc -= 2; i -= 2; } diff --git a/tools/tesh/tesh.h b/tools/tesh/tesh.h index 206493b1e1..d393903bee 100644 --- a/tools/tesh/tesh.h +++ b/tools/tesh/tesh.h @@ -40,4 +40,4 @@ extern char **environ; xbt_dict_t env; /* the environment, stored as a dict (for variable substitution) */ -#endif /* TESH_H */ +#endif /* TESH_H */ diff --git a/tools/tesh2/include/com.h b/tools/tesh2/include/com.h index 6c78a63a8c..71a19b3dc0 100644 --- a/tools/tesh2/include/com.h +++ b/tools/tesh2/include/com.h @@ -14,112 +14,91 @@ * This file contains all the declarations common declarations and definitions * and global variables of tesh. * - */ - + */ + #include #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + /* * the semaphore used by the runner to wait the end of all the units - */ -extern xbt_os_sem_t -units_sem; - + */ + extern xbt_os_sem_t units_sem; + /* * the semaphore used to synchronize the jobs - */ -extern xbt_os_sem_t -jobs_sem; - - -/* the list of tesh include directories */ -extern xbt_dynar_t -include_dirs; - + */ + extern xbt_os_sem_t jobs_sem; + +/* the list of tesh include directories */ + extern xbt_dynar_t include_dirs; + /* * if 1, an interruption was requested by a command or a * unit. - */ -extern int -interrupted; - + */ + extern int interrupted; + /* * if 1, tesh doesn't display the commands launched. - */ -extern int -silent_flag; - + */ + extern int silent_flag; + /* * if 1, tesh simulates the run. - */ -extern int -dry_run_flag; - -/* ? */ -extern int -just_print_flag; - + */ + extern int dry_run_flag; + +/* ? */ + extern int just_print_flag; + /* if 1, tesh diplay the current directory. -*/ -extern int -print_directory_flag; - +*/ + extern int print_directory_flag; + /* * this directory object represents the root directory. - */ -extern directory_t -root_directory; - + */ + extern directory_t root_directory; + /* * if 1, the summary is detailed. - */ -extern int -detail_summary_flag; - + */ + extern int detail_summary_flag; + /* * the tesh exit code. - */ -extern int -exit_code; - -extern int -err_kind; - -extern char* -err_line; - + */ + extern int exit_code; + extern int err_kind; + extern char * err_line; + /* * the list of the errors of the run. - */ -extern xbt_dynar_t -errors; - + */ + extern xbt_dynar_t errors; + /* * if 1, it's the tesh root (the parent of all tesh processes). - */ -extern int -is_tesh_root; - + */ + extern int is_tesh_root; + /* * if 1, keep going when some commands can't be founded - */ -extern int -keep_going_flag; - + */ + extern int keep_going_flag; + /* * if 1, ignore failures of units or commands. - */ -extern int -keep_going_unit_flag; - - - + */ + extern int keep_going_unit_flag; + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /* !__COM_H */ +#endif /* !__COM_H */ diff --git a/tools/tesh2/include/command.h b/tools/tesh2/include/command.h index 1d57cb1945..c438cd2c7d 100644 --- a/tools/tesh2/include/command.h +++ b/tools/tesh2/include/command.h @@ -10,17 +10,18 @@ * This file contains all the declarations of the functions related with * the tesh command type. * - */ - + */ + #ifndef __COMMAND_H #define __COMMAND_H - + #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + /*! \brief command_new - create a new fstream. * * \param unit The unit contained the command. @@ -38,10 +39,10 @@ extern "C" { * [EINVAL] if one of the parameters is invalid. * [ENOMEM] if the system has not enough space to allocate * the command. - */ -command_t -command_new(unit_t unit, context_t context, xbt_os_mutex_t mutex); - + */ + command_t + command_new(unit_t unit, context_t context, xbt_os_mutex_t mutex); + /*! \brief command_free - destroy a command object. * * \param ptr A pointer to the command object to destroy. @@ -53,10 +54,9 @@ command_new(unit_t unit, context_t context, xbt_os_mutex_t mutex); * errors : * [EINVAL] if the command object pointed to by the ptr parameter is invalid. * - */ -int -command_free(command_t* ptr); - + */ + int command_free(command_t * ptr); + /*! \brief command_run - run a command object. * * \param command The command to run. @@ -72,32 +72,28 @@ command_free(command_t* ptr); * The type of running (asynchonus or no) depend of the * context of the command. * - */ -int -command_run(command_t command); - + */ + int command_run(command_t command); + /*! \brief command_exec - execute a command object. * * \param command The command object to run. * \param command_line The command line of the process to create. - */ -void -command_exec(command_t command, const char* command_line); - + */ + void command_exec(command_t command, const char *command_line); + /*! \brief command_wait - wait for the end of a command. * * \param command The command object to wait for. - */ -void -command_wait(command_t command); - + */ + void command_wait(command_t command); + /*! \brief command_interrupt - wait for the end of a command. * * \param command The command object to interrupt. - */ -void -command_interrupt(command_t command); - + */ + void command_interrupt(command_t command); + /*! \brief command_summarize - print the summary of the execution of a command. * * \param command The command object to display the summary. @@ -106,10 +102,9 @@ command_interrupt(command_t command); * The summary of the command is displayed only if the user * specifies both summary and detail-summary options on the * tesh command line. - */ -void -command_summarize(command_t command); - + */ + void command_summarize(command_t command); + /*! \brief command_handle_failure - handle a failure caused by a command. * * \param command The command to handle the failure. @@ -121,17 +116,13 @@ command_summarize(command_t command); * keep-going on the command line of tesh, only the unit * containing the failed command is interrupted and all * other units continue. - */ -void -command_handle_failure(command_t command, cs_reason_t reason); - -void command_kill(command_t command); - -void -command_check(command_t command); - + */ + void command_handle_failure(command_t command, cs_reason_t reason); + void command_kill(command_t command); + void command_check(command_t command); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /* !_COMMAND_H */ +#endif /* !_COMMAND_H */ diff --git a/tools/tesh2/include/context.h b/tools/tesh2/include/context.h index a20fb83440..494be9523a 100644 --- a/tools/tesh2/include/context.h +++ b/tools/tesh2/include/context.h @@ -10,17 +10,18 @@ * This file contains all the declarations of the functions related with * the tesh context type. * - */ - + */ + #ifndef _CONTEXT_H #define _CONTEXT_H - + #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + /*! \brief create_new - create a new context. * * \return If successful the function returns the newly created @@ -28,10 +29,9 @@ extern "C" { * global variable errno with the appropiate error code. * [ENOMEM] if the system has not enough space to allocate * the context. - */ -context_t -context_new(void); - + */ + context_t context_new(void); + /*! \brief context_free - destroy a context object. * * \param ptr A pointer to the context object to destroy. @@ -43,10 +43,9 @@ context_new(void); * errors : * [EINVAL] if the context object pointed to by the ptr parameter is invalid. * - */ -int -context_free(context_t* ptr); - + */ + int context_free(context_t * ptr); + /*! \brief context_dup - duplicate a context object. * * \param context The context to duplicate. @@ -59,11 +58,9 @@ context_free(context_t* ptr); * [EINVAL] if the parameter is invalid. * [ENOMEM] if there is not enough memory to allocate the duplicate. * - */ -context_t -context_dup(context_t context); - - + */ + context_t context_dup(context_t context); + /*! \brief context_reset - reset a context object. * * \param context The context to reset. @@ -75,23 +72,14 @@ context_dup(context_t context); * errors : * [EINVAL] if the parameter is invalid. * - */ -int -context_reset(context_t context); - -void -context_clear(context_t context); - -void -context_input_write(context_t context, const char* buffer); - -void -context_ouput_read(context_t context, const char* buffer); - - - + */ + int context_reset(context_t context); + void context_clear(context_t context); + void context_input_write(context_t context, const char *buffer); + void context_ouput_read(context_t context, const char *buffer); + #ifdef __cplusplus -extern } -#endif +extern} +#endif /* */ -#endif /* !_CONTEXT_H */ +#endif /* !_CONTEXT_H */ diff --git a/tools/tesh2/include/def.h b/tools/tesh2/include/def.h index 362448cb59..02879587fa 100644 --- a/tools/tesh2/include/def.h +++ b/tools/tesh2/include/def.h @@ -13,14 +13,14 @@ /* must be defined first */ #ifdef _XBT_WIN32 - #define _WIN32_WINNT 0x0400 - - #if (_MSC_VER >= 1400 && !defined(_CRT_SECURE_NO_DEPRECATE)) - #define _CRT_SECURE_NO_DEPRECATE - #endif - - #include /* for getcwd(), _chdir() */ - +#define _WIN32_WINNT 0x0400 + +#if (_MSC_VER >= 1400 && !defined(_CRT_SECURE_NO_DEPRECATE)) +#define _CRT_SECURE_NO_DEPRECATE +#endif + +#include /* for getcwd(), _chdir() */ + #endif #include @@ -30,32 +30,32 @@ extern "C" { #endif #ifdef _XBT_WIN32 - - #define strdup _strdup - #define chdir _chdir - #define getcwd _getcwd - - #ifndef S_ISDIR - #define S_ISDIR(__mode) (((__mode) & S_IFMT) == S_IFDIR) - #endif - - #ifndef S_ISREG - #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) - #endif - - #define INDEFINITE_PID NULL - #define INDEFINITE_FD NULL + +#define strdup _strdup +#define chdir _chdir +#define getcwd _getcwd + +#ifndef S_ISDIR +#define S_ISDIR(__mode) (((__mode) & S_IFMT) == S_IFDIR) +#endif + +#ifndef S_ISREG +#define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) +#endif + +#define INDEFINITE_PID NULL +#define INDEFINITE_FD NULL #else - #define INDEFINITE_PID ((int)-1) - #define INDEFINITE_FD ((int)-1) +#define INDEFINITE_PID ((int)-1) +#define INDEFINITE_FD ((int)-1) #endif #ifndef PATH_MAX - #define PATH_MAX ((unsigned int)260) +#define PATH_MAX ((unsigned int)260) #endif #ifndef VAR_NAME_MAX - #define VAR_NAME_MAX ((unsigned int) 80) +#define VAR_NAME_MAX ((unsigned int) 80) #endif #define INDEFINITE ((int)-1) @@ -66,6 +66,4 @@ extern "C" { #ifdef __cplusplus } #endif - -#endif /* !__DEF_H */ - +#endif /* !__DEF_H */ diff --git a/tools/tesh2/include/directories.h b/tools/tesh2/include/directories.h index 75401f5b15..050ff7b720 100644 --- a/tools/tesh2/include/directories.h +++ b/tools/tesh2/include/directories.h @@ -2,35 +2,25 @@ #define __DIRECTORIES_H #include - + #ifdef __cplusplus -extern "C" { -#endif - -directories_t -directories_new(void); - -int -directories_add(directories_t directories, directory_t directory); - -int -directories_contains(directories_t directories, directory_t directory); - -int -directories_load(directories_t directories, fstreams_t fstreams, xbt_dynar_t suffixes); - -int -directories_free(void** directoriesptr); - - -int -directories_get_size(directories_t directories); - -int -directories_is_empty(directories_t directories); - +extern "C" { + +#endif /* */ + directories_t directories_new(void); + int + directories_add(directories_t directories, directory_t directory); + int + directories_contains(directories_t directories, + directory_t directory); + int directories_load(directories_t directories, + fstreams_t fstreams, xbt_dynar_t suffixes); + int directories_free(void **directoriesptr); + int directories_get_size(directories_t directories); + int directories_is_empty(directories_t directories); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /*!__DIRECTORIES_H */ +#endif /*!__DIRECTORIES_H */ diff --git a/tools/tesh2/include/directory.h b/tools/tesh2/include/directory.h index 22c56be1cc..7359f1475b 100644 --- a/tools/tesh2/include/directory.h +++ b/tools/tesh2/include/directory.h @@ -2,32 +2,22 @@ #define __DIRECTORY_H #include - + #ifdef __cplusplus -extern "C" { -#endif - -directory_t -directory_new(const char* name); - -int -directory_open(directory_t directory); - -int -directory_close(directory_t directory); - -int -directory_load(directory_t directory, fstreams_t fstreams, xbt_dynar_t suffixes); - -int -directory_free(void** directoryptr); - -const char* -directory_get_name(directory_t directory); - - +extern "C" { + +#endif /* */ + directory_t directory_new(const char *name); + int directory_open(directory_t directory); + int directory_close(directory_t directory); + int + directory_load(directory_t directory, fstreams_t fstreams, + xbt_dynar_t suffixes); + int directory_free(void **directoryptr); + const char * directory_get_name(directory_t directory); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /*!__DIRECTORY_H */ +#endif /*!__DIRECTORY_H */ diff --git a/tools/tesh2/include/excludes.h b/tools/tesh2/include/excludes.h index 4897a65ad6..59a7f1fc17 100644 --- a/tools/tesh2/include/excludes.h +++ b/tools/tesh2/include/excludes.h @@ -2,31 +2,20 @@ #define __EXCLUDES_H #include - + #ifdef __cplusplus -extern "C" { -#endif - -excludes_t -excludes_new(void); - -int -excludes_add(excludes_t excludes, fstream_t fstream); - -int -excludes_contains(excludes_t excludes, fstream_t fstream); - -int -excludes_is_empty(excludes_t excludes); - -int -excludes_check(excludes_t excludes, fstreams_t fstreams); - -int -excludes_free(void** excludesptr); - +extern "C" { + +#endif /* */ + excludes_t excludes_new(void); + int excludes_add(excludes_t excludes, fstream_t fstream); + int excludes_contains(excludes_t excludes, fstream_t fstream); + int excludes_is_empty(excludes_t excludes); + int excludes_check(excludes_t excludes, fstreams_t fstreams); + int excludes_free(void **excludesptr); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /*!__EXCLUDES_H */ +#endif /*!__EXCLUDES_H */ diff --git a/tools/tesh2/include/explode.h b/tools/tesh2/include/explode.h index 84c571a6d7..20cb5d39d4 100644 --- a/tools/tesh2/include/explode.h +++ b/tools/tesh2/include/explode.h @@ -2,18 +2,16 @@ #define __EXPLODE_H #include - + #ifdef __cplusplus -extern "C" { -#endif - -char** -explode(char separator, const char *string); - - +extern "C" { + +#endif /* */ + char ** explode(char separator, const char *string); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /* !__EXPLODE_H */ +#endif /* !__EXPLODE_H */ diff --git a/tools/tesh2/include/fstream.h b/tools/tesh2/include/fstream.h index 9cb9b40948..2183b21734 100644 --- a/tools/tesh2/include/fstream.h +++ b/tools/tesh2/include/fstream.h @@ -10,16 +10,17 @@ * This file contains all the declarations of the functions related with * the tesh fstream type. * - */ + */ #ifndef __FSTREAM_H #define __FSTREAM_H - + #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + /*! \brief fstream_new - create a new fstream. * * \param directory The directory of the tesh file. @@ -36,10 +37,9 @@ extern "C" { * [EINVAL] if one of the parameters is invalid. * [ENOMEM] if the system has not enough space to allocate * the file stream. - */ -fstream_t -fstream_new(const char* directory, const char* name); - + */ + fstream_t fstream_new(const char *directory, const char *name); + /*! \brief fstream_open - open a file stream object. * * \param fstream The file stream to open. @@ -54,10 +54,9 @@ fstream_new(const char* directory, const char* name); * * This function may also fail and set errno for any of * the errors specified for the function fopen. - */ -int -fstream_open(fstream_t fstream); - + */ + int fstream_open(fstream_t fstream); + /*! \brief fstream_close - close a file stream object. * * \param fstream The file stream to close. @@ -73,10 +72,9 @@ fstream_open(fstream_t fstream); * * This function may also fail and set errno for any of * the errors specified for the function fclose. - */ -int -fstream_close(fstream_t fstream); - + */ + int fstream_close(fstream_t fstream); + /*! \brief fstream_free - destroy a file stream object. * * \param ptr A pointer to the file stream object to destroy. @@ -95,33 +93,28 @@ fstream_close(fstream_t fstream); * remarks : * Il the file stream object is opened the function close it * before its destruction. - */ -int -fstream_free(fstream_t* ptr); - -int -fstream_parse(fstream_t fstream, xbt_os_mutex_t mutex); - -void -fstream_lex_line(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char * filepos, char *line); - -void -fstream_process_token(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char* filepos, char token, char *line); - -void -fstream_handle_include(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char* file_name, const char* description); - -void -fstream_handle_suite(fstream_t fstream, const char* description, const char* filepos); - -int -fstream_launch_command(fstream_t fstream, context_t context, xbt_os_mutex_t mutex); - -long fstream_getline(fstream_t fstream, char **buf, size_t *n); - + */ + int fstream_free(fstream_t * ptr); + int fstream_parse(fstream_t fstream, xbt_os_mutex_t mutex); + void + fstream_lex_line(fstream_t fstream, context_t context, + xbt_os_mutex_t mutex, const char *filepos, + char *line); + void fstream_process_token(fstream_t fstream, context_t context, + xbt_os_mutex_t mutex, const char *filepos, + char token, char *line); + void fstream_handle_include(fstream_t fstream, context_t context, + xbt_os_mutex_t mutex, + const char *file_name, + const char *description); + void fstream_handle_suite(fstream_t fstream, const char *description, + const char *filepos); + int fstream_launch_command(fstream_t fstream, context_t context, + xbt_os_mutex_t mutex); + long fstream_getline(fstream_t fstream, char **buf, size_t * n); + #ifdef __cplusplus -} -#endif - - -#endif /*! __FSTREAM_H */ +} +#endif /* */ + +#endif /*! __FSTREAM_H */ diff --git a/tools/tesh2/include/fstreams.h b/tools/tesh2/include/fstreams.h index 4998d748a8..afff0cbf17 100644 --- a/tools/tesh2/include/fstreams.h +++ b/tools/tesh2/include/fstreams.h @@ -10,16 +10,17 @@ * This file contains all the declarations of the functions related with * the tesh fstreams type. * - */ + */ #ifndef __FSTREAMS_H #define __FSTREAMS_H - + #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + /*! \brief fstreams_new - create a new fstreams. * * \param directory The directory of the tesh file. @@ -36,39 +37,19 @@ extern "C" { * [EINVAL] if one of the parameters is invalid. * [ENOMEM] if the system has not enough space to allocate * the file stream. - */ -fstreams_t -fstreams_new(void_f_pvoid_t fn_finalize); - -int -fstreams_exclude(fstreams_t fstreams, excludes_t excludes); - -int -fstreams_contains(fstreams_t fstreams, fstream_t fstream); - -int -fstreams_add(fstreams_t fstreams, fstream_t fstream); - -int -fstreams_free(void** fstreamsptr); - -int -fstreams_get_size(fstreams_t fstreams); - -int -fstreams_is_empty(fstreams_t fstreams); - -int -fstreams_contains(fstreams_t fstreams, fstream_t fstream); - -int -fstreams_load(fstreams_t fstreams); - - - + */ + fstreams_t fstreams_new(void_f_pvoid_t fn_finalize); + int fstreams_exclude(fstreams_t fstreams, excludes_t excludes); + int fstreams_contains(fstreams_t fstreams, fstream_t fstream); + int fstreams_add(fstreams_t fstreams, fstream_t fstream); + int fstreams_free(void **fstreamsptr); + int fstreams_get_size(fstreams_t fstreams); + int fstreams_is_empty(fstreams_t fstreams); + int fstreams_contains(fstreams_t fstreams, fstream_t fstream); + int fstreams_load(fstreams_t fstreams); + #ifdef __cplusplus -} -#endif - - -#endif /* !__FSTREAMS_H */ +} +#endif /* */ + +#endif /* !__FSTREAMS_H */ diff --git a/tools/tesh2/include/getpath.h b/tools/tesh2/include/getpath.h index 8ddf6b3507..cf6f22d50a 100644 --- a/tools/tesh2/include/getpath.h +++ b/tools/tesh2/include/getpath.h @@ -1,12 +1,11 @@ #ifndef __GETPATH_H #define __GETPATH_H - - - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + /* getpath th -- get the path of the file name specified by the first parameter * of the function and store the path in its second parmater. * the function returns the length of the path of the file. @@ -25,10 +24,9 @@ extern "C" { * [ENOMEM] because this function use calloc, errno can be set with * this error code. * - */ -int -getpath(const char* file_name, char** path); - + */ + int getpath(const char *file_name, char **path); + /* translatepath -- path translation * * param totranslate The path to translate. @@ -42,13 +40,11 @@ getpath(const char* file_name, char** path); * [ENOMEM] because this function use calloc, errno can be set with * this error code. - */ -int -translatepath(const char* totranslate, char** translated); - + */ + int translatepath(const char *totranslate, char **translated); + #ifdef __cplusplus -} -#endif - - -#endif /* !__GETPATH_H */ +} +#endif /* */ + +#endif /* !__GETPATH_H */ diff --git a/tools/tesh2/include/is_cmd.h b/tools/tesh2/include/is_cmd.h index 4c6d743b74..112588a939 100644 --- a/tools/tesh2/include/is_cmd.h +++ b/tools/tesh2/include/is_cmd.h @@ -2,17 +2,16 @@ #define __IS_CMD_H #include - + #ifdef __cplusplus -extern "C" { -#endif - -int -is_cmd(char** path, char** builtin, const char* p); - +extern "C" { + +#endif /* */ + int is_cmd(char **path, char **builtin, const char *p); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /* !__IS_CMD_H */ +#endif /* !__IS_CMD_H */ diff --git a/tools/tesh2/include/reader.h b/tools/tesh2/include/reader.h index 623f1ff27b..3a731d2cb2 100644 --- a/tools/tesh2/include/reader.h +++ b/tools/tesh2/include/reader.h @@ -11,18 +11,18 @@ * This file contains all the declarations of the functions related with * the tesh writer type. * - */ - + */ + #ifndef __READER_H #define __READER_H - + #include - + #ifdef __cplusplus -extern "C" { -#endif - - +extern "C" { + +#endif /* */ + /*! \brief reader_new - create a new reader. * * \param command The command owning the stdout readed by the reader. @@ -35,10 +35,9 @@ extern "C" { * [EINVAL] if the parameter is invalid. * [ENOMEM] if the system has not enough space to allocate * the reader. - */ -reader_t -reader_new(command_t command); - + */ + reader_t reader_new(command_t command); + /*! \brief reader_free - destroy a reader object. * * \param ptr A pointer to the reader object to destroy. @@ -51,18 +50,13 @@ reader_new(command_t command); * [EINVAL] if the reader object pointed to by the parameter ptr is invalid. * * - */ -int -reader_free(reader_t* ptr); - -void -reader_read(reader_t reader); - -void -reader_wait(reader_t reader); - + */ + int reader_free(reader_t * ptr); + void reader_read(reader_t reader); + void reader_wait(reader_t reader); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /* !__READER_H */ +#endif /* !__READER_H */ diff --git a/tools/tesh2/include/readline.h b/tools/tesh2/include/readline.h index 2298c3a690..8d9297eafd 100644 --- a/tools/tesh2/include/readline.h +++ b/tools/tesh2/include/readline.h @@ -2,19 +2,16 @@ #define __READLINE_H #include - + #ifdef __cplusplus -extern "C" { -#endif - -long -readline(FILE* stream, char **buf, size_t *n); - +extern "C" { + +#endif /* */ + long readline(FILE * stream, char **buf, size_t * n); + #ifdef __cplusplus -} -#endif - - - -#endif /* !__READLINE_H */ +} +#endif /* */ + +#endif /* !__READLINE_H */ diff --git a/tools/tesh2/include/runner.h b/tools/tesh2/include/runner.h index 836a0db5fe..4166a860d2 100644 --- a/tools/tesh2/include/runner.h +++ b/tools/tesh2/include/runner.h @@ -10,17 +10,18 @@ * This file contains all the declarations of the functions related with * the tesh runner type. * - */ - + */ + #ifndef __RUNNER_H #define __RUNNER_H - + #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + /*! \brief runner_init - initialize the tesh runner. * * \param check_syntax_flag If 1, the runner check the syntax of all the tesh files before running. @@ -34,37 +35,30 @@ extern "C" { * [EALREADY] if the runner is already initialized. * [ENOMEM] if the system has not enough space to initialize the runner. * [ESYNTAX] if the parameter check_syntax_flag is 1 and a syntax error is detected. - */ -int -runner_init(/*int check_syntax_flag, */int timeout, fstreams_t fstreams); - + */ + int + runner_init( /*int check_syntax_flag, */ int timeout, + fstreams_t fstreams); + /*! \brief runner_run - run the tesh files. - */ -void -runner_run(void); - + */ + void runner_run(void); + /*! \brief runner_destroy - destroy the runner (release all the resources allocated by the runner) - */ -void -runner_destroy(void); - + */ + void runner_destroy(void); + /*! \brief runner_summarize - display the summary of the execution of all the tests of the tesh files. - */ -void -runner_summarize(void); - + */ + void runner_summarize(void); + /*! \brief runner_interrupt - interrupt all the units of the run. - */ -void -runner_interrupt(void); - -int -runner_is_timedout(void); - - + */ + void runner_interrupt(void); + int runner_is_timedout(void); + #ifdef __cplusplus -} -#endif - - -#endif /* !__RUNNER_H */ +} +#endif /* */ + +#endif /* !__RUNNER_H */ diff --git a/tools/tesh2/include/str_replace.h b/tools/tesh2/include/str_replace.h index 4c18e355d2..8f12af5551 100644 --- a/tools/tesh2/include/str_replace.h +++ b/tools/tesh2/include/str_replace.h @@ -2,18 +2,19 @@ #define __STR_REPLACE_H #include - + #ifdef __cplusplus -extern "C" { -#endif -int -str_replace(char** str, const char *what, const char *with, const char* delimiters); - -int -str_replace_all(char** str, const char* what, const char* with, const char* delimiters); - +extern "C" { + +#endif /* */ + int + str_replace(char **str, const char *what, const char *with, + const char *delimiters); + int str_replace_all(char **str, const char *what, const char *with, + const char *delimiters); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /* !__STR_REPLACE_H */ +#endif /* !__STR_REPLACE_H */ diff --git a/tools/tesh2/include/timer.h b/tools/tesh2/include/timer.h index 1b37c9d4dc..65489c06cf 100644 --- a/tools/tesh2/include/timer.h +++ b/tools/tesh2/include/timer.h @@ -11,18 +11,18 @@ * This file contains all the declarations of the functions related with * the tesh timer type. * - */ - + */ + #ifndef __TIMER_H #define __TIMER_H - + #include - + #ifdef __cplusplus -extern "C" { -#endif - - +extern "C" { + +#endif /* */ + /*! \brief timer_new - create a new timer. * * \param command The command to keep a wath. @@ -35,10 +35,9 @@ extern "C" { * [EINVAL] if the parameter is invalid. * [ENOMEM] if the system has not enough space to allocate * the timer. - */ -ttimer_t -timer_new(command_t command); - + */ + ttimer_t timer_new(command_t command); + /*! \brief timer_free - destroy a timer object. * * \param ptr A pointer to the timer object to destroy. @@ -51,19 +50,13 @@ timer_new(command_t command); * [EINVAL] if the timer object pointed to by the parameter ptr is invalid. * * - */ -int -timer_free(ttimer_t* ptr); - -void -timer_time(ttimer_t timer); - -void -timer_wait(ttimer_t timer); - + */ + int timer_free(ttimer_t * ptr); + void timer_time(ttimer_t timer); + void timer_wait(ttimer_t timer); + #ifdef __cplusplus -} -#endif - - -#endif /* !__TIMER_H */ +} +#endif /* */ + +#endif /* !__TIMER_H */ diff --git a/tools/tesh2/include/types.h b/tools/tesh2/include/types.h index 322d81c229..a9f4d35a7f 100644 --- a/tools/tesh2/include/types.h +++ b/tools/tesh2/include/types.h @@ -10,9 +10,9 @@ * This file declares the types used to run a set of tesh files. * */ - - -#ifndef __TYPES_H + + +#ifndef __TYPES_H #define __TYPES_H #include @@ -31,8 +31,8 @@ extern "C" { * byte type definition */ #ifndef __BYTE_T_DEFINED - typedef unsigned char byte; - #define __BYTE_T_DEFINED + typedef unsigned char byte; +#define __BYTE_T_DEFINED #endif /* @@ -40,329 +40,310 @@ extern "C" { */ #ifdef _XBT_WIN32 - - #ifndef __FD_T_DEFINED - typedef HANDLE fd_t; - #define __FD_T_DEFINED - #endif - - #ifndef __PID_T_DEFINED - typedef HANDLE pid_t; - #define __PID_T_DEFINED - #endif - + +#ifndef __FD_T_DEFINED + typedef HANDLE fd_t; +#define __FD_T_DEFINED +#endif + +#ifndef __PID_T_DEFINED + typedef HANDLE pid_t; +#define __PID_T_DEFINED +#endif + #else - #ifndef __FD_T_DEFINED - typedef int fd_t; - #define __FD_T_DEFINED - #endif - - #ifndef __PID_T_DEFINED - typedef int pid_t; - #define __PID_T_DEFINED - #endif +#ifndef __FD_T_DEFINED + typedef int fd_t; +#define __FD_T_DEFINED +#endif + +#ifndef __PID_T_DEFINED + typedef int pid_t; +#define __PID_T_DEFINED +#endif #endif /* forward declarations */ -struct s_unit; /* this structure represents a tesh unit */ - -struct s_runner; -struct s_units; -struct s_unit; -struct s_excludes; -struct s_fstreams; -struct s_fstream; -struct s_directories; -struct s_directory; -struct s_writer; -struct s_reader; -struct s_timer; -struct s_context; -struct s_command; -struct s_variable; -struct s_error; + struct s_unit; /* this structure represents a tesh unit */ + + struct s_runner; + struct s_units; + struct s_unit; + struct s_excludes; + struct s_fstreams; + struct s_fstream; + struct s_directories; + struct s_directory; + struct s_writer; + struct s_reader; + struct s_timer; + struct s_context; + struct s_command; + struct s_variable; + struct s_error; /* * declaration of the tesh unit type which represents a tesh file * to run. */ -typedef struct s_unit -{ - char* description; /* an optional description of the unit */ - struct s_fstream* fstream; /* the file stream used to parse the tesh file */ - struct s_runner* runner; /* the runner of the unit */ - xbt_dynar_t commands; /* a vector containing all the commands parsed from the tesh file */ - int cmd_nb; /* number of created commands of the unit */ - int started_cmd_nb; /* number of started commands of the unit */ - int interrupted_cmd_nb; /* number of interrupted commands of the unit */ - int failed_cmd_nb; /* number of failed commands of the unit */ - int successeded_cmd_nb; /* number of successeded commands of the unit */ - int terminated_cmd_nb; /* number of ended commands */ - int waiting_cmd_nb; /* REMOVE THIS FIELD LATER */ - xbt_os_thread_t thread; /* all the units run in its own thread */ - xbt_os_sem_t sem; /* used by the last command of the unit to signal the end of the unit */ - xbt_os_mutex_t mutex; /* used to synchronously access to the properties of the runner */ - unsigned interrupted : 1; /* if 1, the unit is interrupted by the runner */ - unsigned failed : 1; /* if 1, the unit is failed */ - unsigned successeded : 1; /* if 1, the unit is successeded */ - unsigned parsed : 1; /* if 1, the tesh file of the unit is parsed */ - unsigned released : 1; /* if 1, the unit is released */ - unsigned is_running_suite : 1; /* if 1, the unit is running a suite */ - struct s_unit* owner; /* the unit owned the unit is included */ - struct s_unit* root; /* the root unit */ - xbt_dynar_t suites; /* the suites contained by the unit */ - int exit_code; /* the exit code of the unit */ - int err_kind; - char* err_line; - xbt_dynar_t includes; - char* filepos; -}s_unit_t,* unit_t; + typedef struct s_unit { + char *description; /* an optional description of the unit */ + struct s_fstream *fstream; /* the file stream used to parse the tesh file */ + struct s_runner *runner; /* the runner of the unit */ + xbt_dynar_t commands; /* a vector containing all the commands parsed from the tesh file */ + int cmd_nb; /* number of created commands of the unit */ + int started_cmd_nb; /* number of started commands of the unit */ + int interrupted_cmd_nb; /* number of interrupted commands of the unit */ + int failed_cmd_nb; /* number of failed commands of the unit */ + int successeded_cmd_nb; /* number of successeded commands of the unit */ + int terminated_cmd_nb; /* number of ended commands */ + int waiting_cmd_nb; /* REMOVE THIS FIELD LATER */ + xbt_os_thread_t thread; /* all the units run in its own thread */ + xbt_os_sem_t sem; /* used by the last command of the unit to signal the end of the unit */ + xbt_os_mutex_t mutex; /* used to synchronously access to the properties of the runner */ + unsigned interrupted:1; /* if 1, the unit is interrupted by the runner */ + unsigned failed:1; /* if 1, the unit is failed */ + unsigned successeded:1; /* if 1, the unit is successeded */ + unsigned parsed:1; /* if 1, the tesh file of the unit is parsed */ + unsigned released:1; /* if 1, the unit is released */ + unsigned is_running_suite:1; /* if 1, the unit is running a suite */ + struct s_unit *owner; /* the unit owned the unit is included */ + struct s_unit *root; /* the root unit */ + xbt_dynar_t suites; /* the suites contained by the unit */ + int exit_code; /* the exit code of the unit */ + int err_kind; + char *err_line; + xbt_dynar_t includes; + char *filepos; + } s_unit_t, *unit_t; /* * declaration of the tesh file stream type used to manage the tesh file. */ -typedef struct s_fstream -{ - char* name; /* the name of the file stream (same as the name of the tesh file) */ - char* directory; /* the directory containing the tesh file */ - FILE* stream; /* the system file stream */ - struct s_unit* unit; /* a reference to the unit using the file stream object */ - unsigned parsed:1; -}s_fstream_t,* fstream_t; + typedef struct s_fstream { + char *name; /* the name of the file stream (same as the name of the tesh file) */ + char *directory; /* the directory containing the tesh file */ + FILE *stream; /* the system file stream */ + struct s_unit *unit; /* a reference to the unit using the file stream object */ + unsigned parsed:1; + } s_fstream_t, *fstream_t; /* * command status */ -typedef enum e_command_status -{ - cs_initialized = 0, /* the is initialized */ - cs_started = 1, /* the command is started */ - cs_in_progress = 2, /* the command is execited */ - cs_waiting = 3, /* the command is waiting the writer, the reader and the timer */ - cs_interrupted = 4, /* the command is interrupted */ - cs_failed = 5, /* the command is failed */ - cs_successeded = 6, /* the command is successeded */ - cs_killed = 7, /* the command is killed */ - csr_fcntl_function_failed = 8 /* the fcntl function failed */ -}command_status_t; + typedef enum e_command_status { + cs_initialized = 0, /* the is initialized */ + cs_started = 1, /* the command is started */ + cs_in_progress = 2, /* the command is execited */ + cs_waiting = 3, /* the command is waiting the writer, the reader and the timer */ + cs_interrupted = 4, /* the command is interrupted */ + cs_failed = 5, /* the command is failed */ + cs_successeded = 6, /* the command is successeded */ + cs_killed = 7, /* the command is killed */ + csr_fcntl_function_failed = 8 /* the fcntl function failed */ + } command_status_t; /* * reason of the status of the command */ -typedef enum e_command_status_raison -{ - csr_unknown = 0, /* unknown reason */ - csr_read_failure = 1, /* a read operation failed */ - csr_read_pipe_broken = 2, /* the pipe used to read from the stdout of the command is broken */ - csr_timeout = 3, /* timeout */ - csr_write_failure = 4, /* a write operation failed */ - csr_write_pipe_broken = 5, /* the pipe used to write to the stdin of the command is broken */ - csr_fork_function_failure = 6, /* can't execute the command */ - csr_wait_failure = 8, /* the wait process function failed */ - csr_interruption_request = 9, /* the command has received an interruption request */ - csr_command_not_found = 10, /* the command is not found */ - csr_exit_codes_dont_match = 11, - csr_outputs_dont_match = 12, - csr_signals_dont_match = 13, - csr_unexpected_signal_caught = 14, - csr_expected_signal_not_received = 15, - csr_pipe_function_failed = 16, /* the function pipe() or CreatePipe() fails */ - csr_dup2_function_failure = 17, - csr_execlp_function_failure = 18, - csr_create_process_function_failure = 19, - csr_waitpid_function_failure = 20, - csr_get_exit_code_process_function_failure = 21, - csr_shell_failed = 22 -}cs_reason_t; - - - - -typedef struct s_variable -{ - char* name; - char* val; - int used; - int env; - int err; -}s_variable_t,* variable_t; + typedef enum e_command_status_raison { + csr_unknown = 0, /* unknown reason */ + csr_read_failure = 1, /* a read operation failed */ + csr_read_pipe_broken = 2, /* the pipe used to read from the stdout of the command is broken */ + csr_timeout = 3, /* timeout */ + csr_write_failure = 4, /* a write operation failed */ + csr_write_pipe_broken = 5, /* the pipe used to write to the stdin of the command is broken */ + csr_fork_function_failure = 6, /* can't execute the command */ + csr_wait_failure = 8, /* the wait process function failed */ + csr_interruption_request = 9, /* the command has received an interruption request */ + csr_command_not_found = 10, /* the command is not found */ + csr_exit_codes_dont_match = 11, + csr_outputs_dont_match = 12, + csr_signals_dont_match = 13, + csr_unexpected_signal_caught = 14, + csr_expected_signal_not_received = 15, + csr_pipe_function_failed = 16, /* the function pipe() or CreatePipe() fails */ + csr_dup2_function_failure = 17, + csr_execlp_function_failure = 18, + csr_create_process_function_failure = 19, + csr_waitpid_function_failure = 20, + csr_get_exit_code_process_function_failure = 21, + csr_shell_failed = 22 + } cs_reason_t; + + + + + typedef struct s_variable { + char *name; + char *val; + int used; + int env; + int err; + } s_variable_t, *variable_t; /* * declaration of the tesh timer type */ -typedef struct s_timer -{ - xbt_os_thread_t thread; /* asynchronous timer */ - struct s_command* command; /* the timed command */ - int timeouted; /* if 1, the timer is timeouted */ - xbt_os_sem_t started; -}s_timer_t,* ttimer_t; + typedef struct s_timer { + xbt_os_thread_t thread; /* asynchronous timer */ + struct s_command *command; /* the timed command */ + int timeouted; /* if 1, the timer is timeouted */ + xbt_os_sem_t started; + } s_timer_t, *ttimer_t; /* * declaration of the tesh reader type */ -typedef struct s_reader -{ - xbt_os_thread_t thread; /* asynchonous reader */ - struct s_command* command; /* the command of the reader */ - int failed; /* if 1, the reader failed */ - int broken_pipe; /* if 1, the pipe used by the reader is broken */ - int done; - xbt_os_sem_t started; -}s_reader_t,* reader_t; + typedef struct s_reader { + xbt_os_thread_t thread; /* asynchonous reader */ + struct s_command *command; /* the command of the reader */ + int failed; /* if 1, the reader failed */ + int broken_pipe; /* if 1, the pipe used by the reader is broken */ + int done; + xbt_os_sem_t started; + } s_reader_t, *reader_t; /* * declaration of the tesh writer type */ -typedef struct s_writer -{ - xbt_os_thread_t thread; /* asynchronous writer */ - struct s_command* command; /* the command of the writer */ - int failed; /* if 1, the writer failed */ - int broken_pipe; /* if 1, the pipe used by the writer is broken */ - xbt_os_sem_t written; - xbt_os_sem_t can_write; - int done; -}s_writer_t,* writer_t; - - -typedef struct s_units -{ - xbt_dynar_t items; - int number_of_runned_units; /* the number of units runned */ - int number_of_ended_units; /* the number of units over */ - -}s_units_t,* units_t; + typedef struct s_writer { + xbt_os_thread_t thread; /* asynchronous writer */ + struct s_command *command; /* the command of the writer */ + int failed; /* if 1, the writer failed */ + int broken_pipe; /* if 1, the pipe used by the writer is broken */ + xbt_os_sem_t written; + xbt_os_sem_t can_write; + int done; + } s_writer_t, *writer_t; + + + typedef struct s_units { + xbt_dynar_t items; + int number_of_runned_units; /* the number of units runned */ + int number_of_ended_units; /* the number of units over */ + + } s_units_t, *units_t; /* * declaration of the tesh runner type */ -typedef struct s_runner -{ - struct s_units* units; - int timeouted; /* if 1, the runner is timeouted */ - int timeout; /* the timeout of the runner */ - int interrupted; /* if 1, the runner failed */ - int number_of_runned_units; /* the number of units runned by the runner */ - int number_of_ended_units; /* the number of ended units */ - int waiting; /* if 1, the runner is waiting the end of all the units */ - xbt_os_thread_t thread; /* the timer thread */ - xbt_dynar_t variables; - - int total_of_tests; - int total_of_successeded_tests; - int total_of_failed_tests; - int total_of_interrupted_tests; - - int total_of_units; - int total_of_successeded_units; - int total_of_failed_units; - int total_of_interrupted_units; - - int total_of_suites; - int total_of_successeded_suites; - int total_of_failed_suites; - int total_of_interrupted_suites; - char** path; - char** builtin; -}s_runner_t,* runner_t; - - -typedef struct s_fstreams -{ - xbt_dynar_t items; -}s_fstreams_t,* fstreams_t; - - -typedef struct s_excludes -{ - xbt_dynar_t items; -}s_excludes_t,* excludes_t; - -typedef struct s_directory -{ - char* name; - DIR* stream; -}s_directory_t,* directory_t; - -typedef struct s_directories -{ - xbt_dynar_t items; -}s_directories_t,* directories_t; - - -typedef enum -{ - oh_check, - oh_display, - oh_ignore -}output_handling_t; + typedef struct s_runner { + struct s_units *units; + int timeouted; /* if 1, the runner is timeouted */ + int timeout; /* the timeout of the runner */ + int interrupted; /* if 1, the runner failed */ + int number_of_runned_units; /* the number of units runned by the runner */ + int number_of_ended_units; /* the number of ended units */ + int waiting; /* if 1, the runner is waiting the end of all the units */ + xbt_os_thread_t thread; /* the timer thread */ + xbt_dynar_t variables; + + int total_of_tests; + int total_of_successeded_tests; + int total_of_failed_tests; + int total_of_interrupted_tests; + + int total_of_units; + int total_of_successeded_units; + int total_of_failed_units; + int total_of_interrupted_units; + + int total_of_suites; + int total_of_successeded_suites; + int total_of_failed_suites; + int total_of_interrupted_suites; + char **path; + char **builtin; + } s_runner_t, *runner_t; + + + typedef struct s_fstreams { + xbt_dynar_t items; + } s_fstreams_t, *fstreams_t; + + + typedef struct s_excludes { + xbt_dynar_t items; + } s_excludes_t, *excludes_t; + + typedef struct s_directory { + char *name; + DIR *stream; + } s_directory_t, *directory_t; + + typedef struct s_directories { + xbt_dynar_t items; + } s_directories_t, *directories_t; + + + typedef enum { + oh_check, + oh_display, + oh_ignore + } output_handling_t; /* * declaration of the tesh context type */ -typedef struct s_context -{ - char* command_line; /* the command line of the command to execute */ - const char* line; /* the current parsed line */ - char* pos; - int exit_code; /* the expected exit code of the command */ - char* signal; /* the expected signal raised by the command */ - int timeout; /* the timeout of the test */ - xbt_strbuff_t input; /* the input to write in the stdin of the command to run */ - xbt_strbuff_t output; /* the expected output of the command of the test */ - output_handling_t output_handling; - int async; /* if 1, the command is asynchronous */ - - #ifdef _XBT_WIN32 - char* t_command_line; /* translate the command line on Windows */ - unsigned is_not_found:1; - #endif - -}s_context_t,* context_t; + typedef struct s_context { + char *command_line; /* the command line of the command to execute */ + const char *line; /* the current parsed line */ + char *pos; + int exit_code; /* the expected exit code of the command */ + char *signal; /* the expected signal raised by the command */ + int timeout; /* the timeout of the test */ + xbt_strbuff_t input; /* the input to write in the stdin of the command to run */ + xbt_strbuff_t output; /* the expected output of the command of the test */ + output_handling_t output_handling; + int async; /* if 1, the command is asynchronous */ + +#ifdef _XBT_WIN32 + char *t_command_line; /* translate the command line on Windows */ + unsigned is_not_found:1; +#endif + + } s_context_t, *context_t; /* * declaration of the tesh command type */ -typedef struct s_command -{ - unit_t root; - unit_t unit; /* the unit of the command */ - struct s_context* context; /* the context of the execution of the command */ - xbt_os_thread_t thread; /* asynchronous command */ - struct s_writer* writer; /* the writer used to write in the command stdin */ - struct s_reader* reader; /* the reader used to read from the command stout */ - struct s_timer* timer; /* the timer used for the command */ - command_status_t status; /* the current status of the command */ - cs_reason_t reason; /* the reason of the state of the command */ - int successeded; /* if 1, the command is successeded */ - int interrupted; /* if 1, the command is interrupted */ - int failed; /* if 1, the command is failed */ - pid_t pid; /* the program id of the command */ - xbt_strbuff_t output; /* the output of the command */ - fd_t stdout_fd; /* the stdout fd of the command */ - fd_t stdin_fd; /* the stdin fd of the command */ - int exit_code; /* the exit code of the command */ - #ifdef _XBT_WIN32 - unsigned long stat_val; - #else - int stat_val; - #endif - char* signal; /* the signal raised by the command if any */ - xbt_os_mutex_t mutex; - - #ifndef _XBT_WIN32 - int killed; /* if 1, the command was killed */ - int execlp_errno; - #endif - -}s_command_t,* command_t; + typedef struct s_command { + unit_t root; + unit_t unit; /* the unit of the command */ + struct s_context *context; /* the context of the execution of the command */ + xbt_os_thread_t thread; /* asynchronous command */ + struct s_writer *writer; /* the writer used to write in the command stdin */ + struct s_reader *reader; /* the reader used to read from the command stout */ + struct s_timer *timer; /* the timer used for the command */ + command_status_t status; /* the current status of the command */ + cs_reason_t reason; /* the reason of the state of the command */ + int successeded; /* if 1, the command is successeded */ + int interrupted; /* if 1, the command is interrupted */ + int failed; /* if 1, the command is failed */ + pid_t pid; /* the program id of the command */ + xbt_strbuff_t output; /* the output of the command */ + fd_t stdout_fd; /* the stdout fd of the command */ + fd_t stdin_fd; /* the stdin fd of the command */ + int exit_code; /* the exit code of the command */ +#ifdef _XBT_WIN32 + unsigned long stat_val; +#else + int stat_val; +#endif + char *signal; /* the signal raised by the command if any */ + xbt_os_mutex_t mutex; -#ifdef __cplusplus -} +#ifndef _XBT_WIN32 + int killed; /* if 1, the command was killed */ + int execlp_errno; #endif -#endif /* !__TYPES_H */ + } s_command_t, *command_t; +#ifdef __cplusplus +} +#endif +#endif /* !__TYPES_H */ diff --git a/tools/tesh2/include/unit.h b/tools/tesh2/include/unit.h index 7b92ab773e..8e9510cdf4 100644 --- a/tools/tesh2/include/unit.h +++ b/tools/tesh2/include/unit.h @@ -10,17 +10,18 @@ * This file contains all the declarations of the functions related with * the tesh unit concept. * - */ - + */ + #ifndef __UNIT_H #define __UNIT_H - + #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + /*! \brief unit_new - create a new unit. * * \param runner The runner which runs the unit. @@ -35,10 +36,11 @@ extern "C" { * [EINVAL] if one of the parameters is invalid. * [ENOMEM] if the system has not enough space to allocate * the unit. - */ -unit_t -unit_new(runner_t runner, unit_t root, unit_t owner, fstream_t fstream); - + */ + unit_t + unit_new(runner_t runner, unit_t root, unit_t owner, + fstream_t fstream); + /*! \brief unit_free - destroy a tesh unit. * * \param ptr A pointer to the unit to destroy. @@ -49,10 +51,9 @@ unit_new(runner_t runner, unit_t root, unit_t owner, fstream_t fstream); * * errors : * [EINVAL] if the pointer to the unit to destroy is invalid. - */ -int -unit_free(unit_t* ptr); - + */ + int unit_free(unit_t * ptr); + /*! \brief unit_run - run a tesh unit. * * \param unit The unit to run. @@ -68,11 +69,9 @@ unit_free(unit_t* ptr); * * remarks : If the runner is interrupted during a call of this function, * the unit is not launched but its flag interrupted is signaled. - */ -int -unit_run(unit_t unit, xbt_os_mutex_t mutex); - - + */ + int unit_run(unit_t unit, xbt_os_mutex_t mutex); + /*! \brief unit_interrupt - interrupt a tesh unit. * * \param unit The unit to interrupt. @@ -87,10 +86,9 @@ unit_run(unit_t unit, xbt_os_mutex_t mutex); * * remarks : If the runner is interrupted during a call of this function, * the unit is not launched but its flag interrupted is signaled. - */ -int -unit_interrupt(unit_t unit); - + */ + int unit_interrupt(unit_t unit); + /*! \brief unit_summuarize - summarize the run of tesh unit. * * \param unit The unit to summarize the run. @@ -101,19 +99,14 @@ unit_interrupt(unit_t unit); * * errors : * [EINVAL] if the unit specified as parameter is invalid. - */ -int -unit_summuarize(unit_t unit); - -int -unit_reset(unit_t unit); - -void -unit_set_error(unit_t unit, int errcode, int kind, const char* line); - + */ + int unit_summuarize(unit_t unit); + int unit_reset(unit_t unit); + void + unit_set_error(unit_t unit, int errcode, int kind, const char *line); + #ifdef __cplusplus -} -#endif - - -#endif /* !__UNIT_H */ +} +#endif /* */ + +#endif /* !__UNIT_H */ diff --git a/tools/tesh2/include/units.h b/tools/tesh2/include/units.h index affcc94d78..46cd698b50 100644 --- a/tools/tesh2/include/units.h +++ b/tools/tesh2/include/units.h @@ -2,45 +2,24 @@ #define __UNITS_H #include - + #ifdef __cplusplus -extern "C" { -#endif - -units_t -units_new(runner_t runner, fstreams_t fstreams); - -int -units_is_empty(units_t unit); - -int -units_get_size(units_t unit); - -int -units_run_all(units_t units, xbt_os_mutex_t mutex); - -int -units_join_all(units_t units); - -int -units_interrupt_all(units_t units); - -int -units_reset_all(units_t units); - - -int -units_summuarize(units_t units); - -int -units_free(void** unitsptr); - - +extern "C" { + +#endif /* */ + units_t units_new(runner_t runner, fstreams_t fstreams); + int units_is_empty(units_t unit); + int units_get_size(units_t unit); + int units_run_all(units_t units, xbt_os_mutex_t mutex); + int units_join_all(units_t units); + int units_interrupt_all(units_t units); + int units_reset_all(units_t units); + int units_summuarize(units_t units); + int units_free(void **unitsptr); + #ifdef __cplusplus -extern } -#endif - - -#endif /* !__UNITS_H */ - - +extern} +#endif /* */ + +#endif /* !__UNITS_H */ + diff --git a/tools/tesh2/include/variable.h b/tools/tesh2/include/variable.h index 8341c797a9..64cc65da46 100644 --- a/tools/tesh2/include/variable.h +++ b/tools/tesh2/include/variable.h @@ -2,28 +2,19 @@ #define __VARIABLE_H #include - + #ifdef __cplusplus -extern "C" { -#endif - -variable_t -variable_new(const char* name, const char* val); - -int -variable_free(variable_t* variableptr); - -int -variable_is_used(variable_t variable); - -int -variable_set_used(variable_t variable); - - +extern "C" { + +#endif /* */ + variable_t variable_new(const char *name, const char *val); + int variable_free(variable_t * variableptr); + int variable_is_used(variable_t variable); + int variable_set_used(variable_t variable); + #ifdef __cplusplus -} -#endif - - -#endif /*!__VARIABLE_H */ +} +#endif /* */ + +#endif /*!__VARIABLE_H */ diff --git a/tools/tesh2/include/writer.h b/tools/tesh2/include/writer.h index 1fe2c85f95..40f6cb5635 100644 --- a/tools/tesh2/include/writer.h +++ b/tools/tesh2/include/writer.h @@ -11,17 +11,18 @@ * This file contains all the declarations of the functions related with * the tesh writer type. * - */ - + */ + #ifndef __WRITER_H #define __WRITER_H - + #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + /*! \brief writer_new - create a new writer. * * \param command The command owning the stdin written by the writer. @@ -34,11 +35,9 @@ extern "C" { * [EINVAL] if the parameter is invalid. * [ENOMEM] if the system has not enough space to allocate * the writer. - */ -writer_t -writer_new(command_t command); - - + */ + writer_t writer_new(command_t command); + /*! \brief writer_free - destroy a writer object. * * \param ptr A pointer to the writer object to destroy. @@ -51,18 +50,13 @@ writer_new(command_t command); * [EINVAL] if the writer object pointed to by the parameter ptr is invalid. * * - */ -int -writer_free(writer_t* ptr); - -void -writer_write(writer_t writer); - -void -writer_wait(writer_t writer); - + */ + int writer_free(writer_t * ptr); + void writer_write(writer_t writer); + void writer_wait(writer_t writer); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /* !__WRITER_H */ +#endif /* !__WRITER_H */ diff --git a/tools/tesh2/include/xerrno.h b/tools/tesh2/include/xerrno.h index 843bbe4115..19db3959c6 100644 --- a/tools/tesh2/include/xerrno.h +++ b/tools/tesh2/include/xerrno.h @@ -3,11 +3,12 @@ #include #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + #define ECMDTIMEDOUT ((int)102) /* Command timed out */ #define ECMDNOTFOUND ((int)107) /* the command is not found */ #define EEXITCODENOTMATCH ((int)108) /* the exit codes don't match */ @@ -24,21 +25,16 @@ extern "C" { #define EINCLUDENOTFOUND ((int)125) /* the include file specified by a metacommand is not found */ #define ESUFFIXTOOLONG ((int)126) /* the suffix is too long */ #define EINVCMDLINE ((int)139) /* invalid command line */ - + #ifndef EALREADY #define EALREADY ((int)131) -#endif - -const char* -error_get_at(int pos, int* code); - -const char* -error_to_string(int errcode, int kind); - +#endif /* */ + const char * error_get_at(int pos, int *code); + const char * error_to_string(int errcode, int kind); + #ifdef __cplusplus -} -#endif - - -#endif /* !__XERRNO_H */ +} +#endif /* */ + +#endif /* !__XERRNO_H */ diff --git a/tools/tesh2/include/xsignal.h b/tools/tesh2/include/xsignal.h index d4d42da072..2a562e148d 100644 --- a/tools/tesh2/include/xsignal.h +++ b/tools/tesh2/include/xsignal.h @@ -3,199 +3,193 @@ #include #include - + #ifdef __cplusplus -extern "C" { -#endif - +extern "C" { + +#endif /* */ + #ifdef _XBT_WIN32 - + /* terminal line hangup */ #ifndef SIGHUP #define SIGHUP 1 -#endif - -/* interrupt program */ +#endif /* */ + +/* interrupt program */ #ifndef SIGINT #define SIGINT 2 -#endif - -/* quit program */ +#endif /* */ + +/* quit program */ #ifndef SIGQUIT #define SIGQUIT 3 -#endif - -/* illegal instruction */ +#endif /* */ + +/* illegal instruction */ #ifndef SIGILL #define SIGILL 4 -#endif - -/* trace trap */ +#endif /* */ + +/* trace trap */ #ifndef SIGTRAP #define SIGTRAP 5 -#endif - -/* abnormal termination triggered by abort call */ +#endif /* */ + +/* abnormal termination triggered by abort call */ #ifndef SIGABRT #define SIGABRT 6 -#endif - -/* floating point exception */ +#endif /* */ + +/* floating point exception */ #ifndef SIGFPE #define SIGFPE 8 -#endif - -/* kill program */ +#endif /* */ + +/* kill program */ #ifndef SIGKILL #define SIGKILL 9 -#endif - -/* bus error */ +#endif /* */ + +/* bus error */ #ifndef SIGBUS #define SIGBUS 10 -#endif - -/* segment violation */ +#endif /* */ + +/* segment violation */ #ifndef SIGSEGV #define SIGSEGV 11 -#endif - -/* non-existent system call invoked */ +#endif /* */ + +/* non-existent system call invoked */ #ifndef SIGSYS #define SIGSYS 12 -#endif - +#endif /* */ + /* write on a pipe with no reader */ #ifndef SIGPIPE #define SIGPIPE 13 -#endif - -/* real-time timer expired */ +#endif /* */ + +/* real-time timer expired */ #ifndef SIGALRM #define SIGALRM 14 -#endif - -/* software termination signal from kill */ +#endif /* */ + +/* software termination signal from kill */ #ifdef SIGTERM #define SIGTERM 15 -#endif - -/* urgent condition present on socket */ +#endif /* */ + +/* urgent condition present on socket */ #ifndef SIGURG #define SIGURG 16 -#endif - -/* stop (cannot be caught orignored) */ +#endif /* */ + +/* stop (cannot be caught orignored) */ #ifndef SIGSTOP #define SIGSTOP 17 -#endif - -/* stop signal generated from keyboard */ +#endif /* */ + +/* stop signal generated from keyboard */ #ifndef SIGTSTP #define SIGTSTP 18 -#endif - -/* continue after stop */ +#endif /* */ + +/* continue after stop */ #ifndef SIGCONT #define SIGCONT 19 -#endif - +#endif /* */ + /* child status has changed */ #ifndef SIGCHLD #define SIGCHLD 20 -#endif - -/* background read attempted from control terminal */ +#endif /* */ + +/* background read attempted from control terminal */ #ifndef SIGTTIN #define SIGTTIN 21 -#endif - -/* background write attempted to control terminal */ +#endif /* */ + +/* background write attempted to control terminal */ #ifndef SIGTTOU #define SIGTTOU 22 -#endif - -/* I/O is possible on a descriptor see fcntl(2)) */ +#endif /* */ + +/* I/O is possible on a descriptor see fcntl(2)) */ #ifndef SIGIO #define SIGIO 23 -#endif - -/* cpu time limit exceeded (see setrlimit(2)) */ +#endif /* */ + +/* cpu time limit exceeded (see setrlimit(2)) */ #ifndef SIGXCPU #define SIGXCPU 24 -#endif - -/* file size limit exceeded (see setrlimit(2)) */ +#endif /* */ + +/* file size limit exceeded (see setrlimit(2)) */ #ifndef SIGXFSZ #define SIGXFSZ 25 -#endif - -/* virtual time alarm (see setitimer(2)) */ +#endif /* */ + +/* virtual time alarm (see setitimer(2)) */ #ifndef SIGVTALRM #define SIGVTALRM 26 -#endif - -/* profiling timer alarm (see setitimer(2)) */ +#endif /* */ + +/* profiling timer alarm (see setitimer(2)) */ #ifndef SIGPROF #define SIGPROF 27 -#endif - -/* window size change */ +#endif /* */ + +/* window size change */ #ifndef SIGWINCH #define SIGWINCH 28 -#endif - -/* user defined signal 1 */ +#endif /* */ + +/* user defined signal 1 */ #ifndef SIGUSR1 #define SIGUSR1 30 -#endif - -/* user defined signal 2 */ +#endif /* */ + +/* user defined signal 2 */ #ifndef SIGUSR2 #define SIGUSR2 31 -#endif - - -int -is_an_unhandled_exception(DWORD exit_code); - +#endif /* */ + int is_an_unhandled_exception(DWORD exit_code); + /* *return a non-zero value if status was returned for a child process that terminated normally. - */ + */ #define WIFEXITED(__status) !is_an_unhandled_exception((__status)) - + /* if the value of WIFEXITED(__status) is non-zero, this macro evaluates the value the child * process returned from main(). - */ + */ #define WEXITSTATUS(__status) (__status) - + /* return a non-zero value if status was returned for a child process that terminated due to the * receipt of a signal that was not caught - */ + */ #define WIFSIGNALED(__status) is_an_unhandled_exception((__status)) - + /* if the value of WIFSIGNALED(__status) is non-zero, this macro evaluates to the number of the * signal that caused the termination of the child process. - */ + */ #define WTERMSIG(__status) (__status) - -#endif /* _XBT_WIN32 */ - - + +#endif /* _XBT_WIN32 */ + #ifdef _XBT_WIN32 -const char* -signal_name(DWORD got, const char* expected); -#else -const char* -signal_name(unsigned int got, char *expected); -#endif - - -int -sig_exists(const char* sig_name); - + const char * signal_name(DWORD got, const char *expected); + +#else /* */ + const char * signal_name(unsigned int got, char *expected); + +#endif /* */ + int sig_exists(const char *sig_name); + #ifdef __cplusplus -} -#endif +} +#endif /* */ -#endif /* !__XSIGNAL_H */ +#endif /* !__XSIGNAL_H */ diff --git a/tools/tesh2/src/command.c b/tools/tesh2/src/command.c index 677979f7d9..d43adf1384 100644 --- a/tools/tesh2/src/command.c +++ b/tools/tesh2/src/command.c @@ -10,1225 +10,1211 @@ * This file contains all the definitions of the functions related with * the tesh command type. * - */ + */ #include #include #include #include #include #include - + #ifndef _XBT_WIN32 #include #include #include #include -#else -char * -tow32cmd(const char* cmd) -{ - static char w32cmd[PATH_MAX + 1] = {0}; - char cmd_buf[PATH_MAX + 1] = {0}; - size_t i,j, len; - - if(!cmd) - { - errno = EINVAL; - return NULL; - } - - /* TODO : if ~*/ - if(cmd[0] != '.') - { - strcpy(w32cmd, cmd); - return w32cmd; - } - - i = j = 0; - len = strlen(cmd); - - while(i < len) - { - if(cmd[i] != ' ' && cmd[i] != '\t' && cmd[i] != '>') - cmd_buf[j++] = cmd[i]; - else - break; - - i++; - } - - _fullpath(w32cmd, cmd_buf, sizeof(w32cmd)); - - if(!strstr(w32cmd, ".exe")) - strcat(w32cmd, ".exe "); - - strcat(w32cmd, cmd + i); - - - /*printf("w32cmd : %s", w32cmd);*/ - - return w32cmd; -} -#endif - +#else /* */ +char * tow32cmd(const char *cmd) +{ + static char w32cmd[PATH_MAX + 1] = { 0 }; + char cmd_buf[PATH_MAX + 1] = { 0 }; + size_t i, j, len; + if (!cmd) + { + errno = EINVAL; + return NULL; + } + + /* TODO : if ~ */ + if (cmd[0] != '.') + { + strcpy(w32cmd, cmd); + return w32cmd; + } + i = j = 0; + len = strlen(cmd); + while (i < len) + { + if (cmd[i] != ' ' && cmd[i] != '\t' && cmd[i] != '>') + cmd_buf[j++] = cmd[i]; + + else + break; + i++; + } + _fullpath(w32cmd, cmd_buf, sizeof(w32cmd)); + if (!strstr(w32cmd, ".exe")) + strcat(w32cmd, ".exe "); + strcat(w32cmd, cmd + i); + + /*printf("w32cmd : %s", w32cmd); */ + return w32cmd; + } + + +#endif /* */ + #include - + #include - + #include - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - -static void* -command_start(void* p); - - -command_t -command_new(unit_t unit, context_t context, xbt_os_mutex_t mutex) -{ - command_t command; - - command = xbt_new0(s_command_t, 1); - - /* get the context of the execution of the command */ - if(!(command->context = context_dup(context))) - { - free(command); - return NULL; - } - - /* the exit code of the command is indefinite */ - command->exit_code = INDEFINITE; - - /* the signal of the command is indefinite */ - command->signal = INDEFINITE_SIGNAL; - - command->failed = 0; - command->interrupted = 0; - - /* the mutex used to safetly access to the command unit properties */ - command->mutex = mutex; - - command->output = xbt_strbuff_new(); - - command->pid = INDEFINITE_PID; - - command->stat_val = -1; - - /* set the unit of the command */ - command->root = unit->root ? unit->root : unit; - command->unit = unit; - - /* all the commands are runned in a thread */ - command->thread = NULL; - - command->successeded = 0; - - command->reader = reader_new(command); - - if(context->input->used) - command->writer = writer_new(command); - else - command->writer = NULL; - - if(context->timeout != INDEFINITE) - command->timer = timer_new(command); - else - command->timer = NULL; - - command->status = cs_initialized; - command->reason = csr_unknown; - - command->stdin_fd = INDEFINITE_FD; - command->stdout_fd = INDEFINITE_FD; - - - /* register the command */ - xbt_os_mutex_acquire(mutex); - - xbt_dynar_push(unit->commands, &command); - command->root->cmd_nb++; - xbt_os_mutex_release(mutex); - - #ifndef _XBT_WIN32 - command->killed = 0; - command->execlp_errno = 0; - #endif - - - return command; -} - -int -command_run(command_t command) -{ - if(!silent_flag && !interrupted) - INFO2("[%s] %s",command->context->pos, command->context->command_line); - - if(!just_print_flag) - { - if(!interrupted) - { - /* start the command in a thread*/ - if(command->context->async) - { - command->thread = xbt_os_thread_create("", command_start, command); - - } - else - { - /* start the command in the main thread */ - command_start(command); - } - } - else - { - command_interrupt(command); - } - - - } - - return 0; - -} - -static void* -command_start(void* p) -{ - command_t command = (command_t)p; - unit_t root = command->root; - - /* the command is started */ - command->status = cs_started; - - /* increment the number of started commands of the unit */ - xbt_os_mutex_acquire(command->mutex); - (root->started_cmd_nb)++; - xbt_os_mutex_release(command->mutex); - - /* execute the command of the test */ - - #ifndef _XBT_WIN32 - command_exec(command, command->context->command_line); - #else - /* play the translated command line on Windows */ - command_exec(command, command->context->t_command_line); - #endif - - if(cs_in_progress == command->status) - { - /* wait the process if it is in progress */ - command_wait(command); - - if(cs_failed != command->status && cs_interrupted != command->status) - command_check(command); - } - - xbt_os_mutex_acquire(command->mutex); - - /* if it's the last command of the root unit */ - if(!root->interrupted && root->parsed && (root->started_cmd_nb == (root->failed_cmd_nb + root->interrupted_cmd_nb + root->successeded_cmd_nb))) - { - /* first release the mutex */ - root->released = 1; - xbt_os_mutex_release(command->mutex); - /* the last command release the unit */ - xbt_os_sem_release(root->sem); - } - else - xbt_os_mutex_release(command->mutex); - - - /* wait the end of the timer, the reader and the writer */ - if(command->timer && command->timer->thread) - timer_wait(command->timer); - - /* wait the end of the writer */ - if(command->writer && command->writer->thread) - writer_wait(command->writer); - - /* wait the end of the reader */ - if(command->reader && command->reader->thread) - reader_wait(command->reader); - - - - return NULL; -} - + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + static void * command_start(void *p); + command_t +command_new(unit_t unit, context_t context, xbt_os_mutex_t mutex) +{ + command_t command; + command = xbt_new0(s_command_t, 1); + + /* get the context of the execution of the command */ + if (!(command->context = context_dup(context))) + { + free(command); + return NULL; + } + + /* the exit code of the command is indefinite */ + command->exit_code = INDEFINITE; + + /* the signal of the command is indefinite */ + command->signal = INDEFINITE_SIGNAL; + command->failed = 0; + command->interrupted = 0; + + /* the mutex used to safetly access to the command unit properties */ + command->mutex = mutex; + command->output = xbt_strbuff_new(); + command->pid = INDEFINITE_PID; + command->stat_val = -1; + + /* set the unit of the command */ + command->root = unit->root ? unit->root : unit; + command->unit = unit; + + /* all the commands are runned in a thread */ + command->thread = NULL; + command->successeded = 0; + command->reader = reader_new(command); + if (context->input->used) + command->writer = writer_new(command); + + else + command->writer = NULL; + if (context->timeout != INDEFINITE) + command->timer = timer_new(command); + + else + command->timer = NULL; + command->status = cs_initialized; + command->reason = csr_unknown; + command->stdin_fd = INDEFINITE_FD; + command->stdout_fd = INDEFINITE_FD; + + /* register the command */ + xbt_os_mutex_acquire(mutex); + xbt_dynar_push(unit->commands, &command); + command->root->cmd_nb++; + xbt_os_mutex_release(mutex); + +#ifndef _XBT_WIN32 + command->killed = 0; + command->execlp_errno = 0; + +#endif /* */ + return command; + } + + int command_run(command_t command) +{ + if (!silent_flag && !interrupted) + INFO2("[%s] %s", command->context->pos, + command->context->command_line); + if (!just_print_flag) + { + if (!interrupted) + { + + /* start the command in a thread */ + if (command->context->async) + { + command->thread = + xbt_os_thread_create("", command_start, command); + } + + else + { + + /* start the command in the main thread */ + command_start(command); + } + } + + else + { + command_interrupt(command); + } + } + return 0; + } + + static void * command_start(void *p) +{ + command_t command = (command_t) p; + unit_t root = command->root; + + /* the command is started */ + command->status = cs_started; + + /* increment the number of started commands of the unit */ + xbt_os_mutex_acquire(command->mutex); + (root->started_cmd_nb)++; + xbt_os_mutex_release(command->mutex); + + /* execute the command of the test */ + +#ifndef _XBT_WIN32 + command_exec(command, command->context->command_line); + +#else /* */ + /* play the translated command line on Windows */ + command_exec(command, command->context->t_command_line); + +#endif /* */ + if (cs_in_progress == command->status) + { + + /* wait the process if it is in progress */ + command_wait(command); + if (cs_failed != command->status + && cs_interrupted != command->status) + command_check(command); + } + xbt_os_mutex_acquire(command->mutex); + + /* if it's the last command of the root unit */ + if (!root->interrupted && root->parsed + && (root->started_cmd_nb == + (root->failed_cmd_nb + root->interrupted_cmd_nb + + root->successeded_cmd_nb))) + { + + /* first release the mutex */ + root->released = 1; + xbt_os_mutex_release(command->mutex); + + /* the last command release the unit */ + xbt_os_sem_release(root->sem); + } + + else + xbt_os_mutex_release(command->mutex); + + /* wait the end of the timer, the reader and the writer */ + if (command->timer && command->timer->thread) + timer_wait(command->timer); + + /* wait the end of the writer */ + if (command->writer && command->writer->thread) + writer_wait(command->writer); + + /* wait the end of the reader */ + if (command->reader && command->reader->thread) + reader_wait(command->reader); + return NULL; + } + + #ifdef _XBT_WIN32 - + #ifndef BUFSIZE #define BUFSIZE 4096 -#endif -void -command_exec(command_t command, const char* command_line) -{ - - STARTUPINFO si = {0}; /* contains the informations about the child process windows*/ - PROCESS_INFORMATION pi = {0}; /* contains child process informations */ - SECURITY_ATTRIBUTES sa = {0}; /* contains the security descriptor for the pipe handles */ - HANDLE child_stdin_handle[2] = {NULL}; /* child_stdin_handle[1] <-> stdout of the child process */ - HANDLE child_stdout_handle[2] = {NULL}; /* child_stdout_handle[0] <-> stdin of the child process */ - HANDLE child_stderr = NULL; - - - sa.nLength = sizeof(SECURITY_ATTRIBUTES); - sa.lpSecurityDescriptor = NULL; /* use default security for the pipe handles */ - - sa.bInheritHandle = TRUE; /* the pipe handles can be inherited */ - - if(!CreatePipe(&(child_stdin_handle[0]),&(child_stdin_handle[1]),&sa,0)) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); - - unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - - command->failed = 1; - command->status = cs_failed; - - return; - } - - - if(!DuplicateHandle(GetCurrentProcess(),(child_stdin_handle[1]),GetCurrentProcess(),&(child_stderr),0,TRUE,DUPLICATE_SAME_ACCESS)) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); - - unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - - CloseHandle(child_stdin_handle[0]); - CloseHandle(child_stdin_handle[1]); - - command->failed = 1; - command->status = cs_failed; - - return; - } - - if(!CreatePipe(&(child_stdout_handle[0]),&(child_stdout_handle[1]),&sa,0)) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); - unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - - CloseHandle(child_stdout_handle[0]); - CloseHandle(child_stdout_handle[1]); - CloseHandle(child_stdin_handle[0]); - CloseHandle(child_stdin_handle[1]); - - command->failed = 1; - command->status = cs_failed; - - return; - } - - /* Read handle for read operations on the child std output. */ - if(!DuplicateHandle(GetCurrentProcess(),(child_stdin_handle[0]),GetCurrentProcess(),&(command->stdout_fd),0,FALSE, DUPLICATE_SAME_ACCESS)) - { - CloseHandle(child_stdout_handle[0]); - CloseHandle(child_stdout_handle[1]); - CloseHandle(child_stdin_handle[0]); - CloseHandle(child_stdin_handle[1]); - - command->failed = 1; - command->status = cs_failed; - - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); - unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - - return; - } - - - /* Write handle for write operations on the child std input. */ - if(!DuplicateHandle(GetCurrentProcess(),(child_stdout_handle[1]),GetCurrentProcess(),&(command->stdin_fd), 0,FALSE,DUPLICATE_SAME_ACCESS)) - { - CloseHandle(child_stdout_handle[0]); - CloseHandle(child_stdout_handle[1]); - CloseHandle(child_stdin_handle[0]); - CloseHandle(child_stdin_handle[1]); - - command->failed = 1; - command->status = cs_failed; - - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); - - unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - - return; - } - - CloseHandle(child_stdin_handle[0]); - CloseHandle(child_stdout_handle[1]); - - - if(command->timer) - { - /* launch the timer */ - timer_time(command->timer); - } - - if(command->reader) - { - /* launch the reader */ - reader_read(command->reader); - } - - - if(command->writer) - { - /* launch the writer */ - writer_write(command->writer); - } - - /* if there is a reader wait for its starting */ - if(command->reader) - xbt_os_sem_acquire(command->reader->started); - - /* if there is a reader wait for its ending */ - if(command->writer) - xbt_os_sem_acquire(command->writer->written); - - /* if there is a reader wait for its starting */ - if(command->timer) - xbt_os_sem_acquire(command->timer->started); - - si.cb = sizeof(STARTUPINFO); - - si.dwFlags |= STARTF_USESTDHANDLES; - si.hStdOutput = child_stdin_handle[1]; - si.hStdInput = child_stdout_handle[0]; - si.hStdError = child_stderr; - - /* launch the process */ - if(!CreateProcess( - NULL, - tow32cmd(command_line), - NULL, - NULL, - TRUE, - CREATE_NO_WINDOW, - NULL, - NULL, - &si, - &pi) - ) - { - - if(ERROR_FILE_NOT_FOUND == GetLastError()) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(ECMDNOTFOUND, 1)); - unit_set_error(command->unit, ECMDNOTFOUND, 1, command->context->pos); - command_handle_failure(command, csr_command_not_found); - } - else - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0)); - - unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - command_handle_failure(command, csr_create_process_function_failure); - } - - } - else - { - /* the command is running */ - command->status = cs_in_progress; - - /* save the pid of the command */ - command->pid = pi.hProcess; - - /* close non used thread handle */ - CloseHandle(pi.hThread); - - } - - - /* close non used handles */ - CloseHandle(child_stdin_handle[1]); - CloseHandle(child_stdout_handle[0]); - CloseHandle(child_stderr); - - -} -#else -void -command_exec(command_t command, const char* command_line) -{ - int child_stdin_fd[2] ; - int child_stdout_fd[2]; - - #ifdef __CHKCMD - int rv = is_cmd(command->unit->runner->path, command->unit->runner->builtin, command_line); - - if(rv != 0) - { - - if(rv == EINVAL) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(rv, 0)); - unit_set_error(command->unit, rv, 0, command->context->pos); - } - else - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(rv, 1)); - unit_set_error(command->unit, rv, 1, command->context->pos); - } - - command_handle_failure(command, csr_command_not_found); - - return; - } - - #endif - - - if(command->writer) - { - if(pipe(child_stdin_fd)) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); - - unit_set_error(command->unit, errno, 0, command->context->pos); - - command_handle_failure(command, csr_pipe_function_failed); - - - - return; - } - } - - if(command->reader) - { - if(pipe(child_stdout_fd)) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); - - if(command->writer) - { - close(child_stdin_fd[0]); - close(child_stdin_fd[1]); - } - - unit_set_error(command->unit, errno, 0, command->context->pos); - - command_handle_failure(command, csr_pipe_function_failed); - - return; - } - } - - if(command->writer) - { - if(fcntl(child_stdin_fd[1], F_SETFL, fcntl(child_stdin_fd[1], F_GETFL) | O_NONBLOCK) < 0) - { - - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); - - close(child_stdin_fd[0]); - close(child_stdin_fd[1]); - - if(command->reader) - { - close(child_stdout_fd[0]); - close(child_stdout_fd[1]); - } - - unit_set_error(command->unit, errno, 0, command->context->pos); - - command_handle_failure(command, csr_fcntl_function_failed); - - return; - } - } - - /* to write to the child stdin */ - command->stdin_fd = child_stdin_fd[1]; - - /* to read from the child stdout */ - command->stdout_fd = child_stdout_fd[0]; - - /* launch the reader if any*/ - if(command->reader) - reader_read(command->reader); - - /* launch the writer if any */ - if(command->writer) - writer_write(command->writer); - - /* launch the timer if any */ - if(command->timer) - timer_time(command->timer); - - /* if there is a reader wait for its starting */ - if(command->reader) - xbt_os_sem_acquire(command->reader->started); - - /* if there is a reader wait for its ending */ - if(command->writer) - xbt_os_sem_acquire(command->writer->written); - - /* if there is a reader wait for its starting */ - if(command->timer) - xbt_os_sem_acquire(command->timer->started); - - /* update the state of the command, assume it is in progress */ - command->status = cs_in_progress; - - command->pid= fork(); - - if(command->pid < 0) - {/* error */ - if(command->writer) - { - close(child_stdin_fd[0]); - close(child_stdin_fd[1]); - } - - if(command->reader) - { - close(child_stdout_fd[0]); - close(child_stdout_fd[1]); - } - - ERROR2("[%s] Cannot fork the command `%s'", command->context->pos, command->context->command_line); - unit_set_error(command->unit, errno, 0, command->context->pos); - command_handle_failure(command,csr_fork_function_failure); - } - else - { - if(command->pid) - {/* father */ - - /* close unused file descriptors */ - if(command->writer) - close(child_stdin_fd[0]); - - if(command->reader) - close(child_stdout_fd[1]); - } - else - {/* child */ - - /* close unused file descriptors */ - if(command->writer) - close(child_stdin_fd[1]); - - if(command->reader) - close(child_stdout_fd[0]); - - if(command->writer) - { - /* redirect stdin to child_stdin_fd[0] (now fgets(), getchar() ... read from the pipe */ - if(dup2(child_stdin_fd[0],STDIN_FILENO) < 0) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); - command->unit->exit_code = errno; - - unit_set_error(command->unit, errno, 0, command->context->pos); - command_handle_failure(command,csr_dup2_function_failure); - } - - /* close the unused file descriptor */ - close(child_stdin_fd[0]); - } - - if(command->reader) - { - - /* redirect stdout and stderr to child_stdout_fd[1] (now printf(), perror()... write to the pipe */ - if(dup2(child_stdout_fd[1],STDOUT_FILENO) < 0) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); - - unit_set_error(command->unit, errno, 0, command->context->pos); - command_handle_failure(command, csr_dup2_function_failure); - } - - if(dup2(child_stdout_fd[1], STDERR_FILENO) < 0) - { - ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(errno, 0)); - unit_set_error(command->unit, errno, 0, command->context->pos); - command_handle_failure(command, csr_dup2_function_failure); - } - - /* close the unused file descriptor */ - close(child_stdout_fd[1]); - } - - /* launch the command */ - if(execlp("/bin/sh", "sh", "-c", command->context->command_line, NULL) < 0) - command->execlp_errno = errno; - } - } -} -#endif - +#endif /* */ +void command_exec(command_t command, const char *command_line) +{ + STARTUPINFO si = { + 0}; /* contains the informations about the child process windows */ + PROCESS_INFORMATION pi = { + 0}; /* contains child process informations */ + SECURITY_ATTRIBUTES sa = { + 0}; /* contains the security descriptor for the pipe handles */ + HANDLE child_stdin_handle[2] = { + NULL}; /* child_stdin_handle[1] <-> stdout of the child process */ + HANDLE child_stdout_handle[2] = { + NULL}; /* child_stdout_handle[0] <-> stdin of the child process */ + HANDLE child_stderr = NULL; + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.lpSecurityDescriptor = NULL; /* use default security for the pipe handles */ + sa.bInheritHandle = TRUE; /* the pipe handles can be inherited */ + if (!CreatePipe + (&(child_stdin_handle[0]), &(child_stdin_handle[1]), &sa, 0)) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, + error_to_string((int) GetLastError(), 0)); + unit_set_error(command->unit, (int) GetLastError(), 0, + command->context->pos); + command->failed = 1; + command->status = cs_failed; + return; + } + if (!DuplicateHandle + (GetCurrentProcess(), (child_stdin_handle[1]), + GetCurrentProcess(), &(child_stderr), 0, TRUE, + DUPLICATE_SAME_ACCESS)) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, + error_to_string((int) GetLastError(), 0)); + unit_set_error(command->unit, (int) GetLastError(), 0, + command->context->pos); + CloseHandle(child_stdin_handle[0]); + CloseHandle(child_stdin_handle[1]); + command->failed = 1; + command->status = cs_failed; + return; + } + if (!CreatePipe + (&(child_stdout_handle[0]), &(child_stdout_handle[1]), &sa, 0)) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, + error_to_string((int) GetLastError(), 0)); + unit_set_error(command->unit, (int) GetLastError(), 0, + command->context->pos); + CloseHandle(child_stdout_handle[0]); + CloseHandle(child_stdout_handle[1]); + CloseHandle(child_stdin_handle[0]); + CloseHandle(child_stdin_handle[1]); + command->failed = 1; + command->status = cs_failed; + return; + } + + /* Read handle for read operations on the child std output. */ + if (!DuplicateHandle + (GetCurrentProcess(), (child_stdin_handle[0]), + GetCurrentProcess(), &(command->stdout_fd), 0, FALSE, + DUPLICATE_SAME_ACCESS)) + { + CloseHandle(child_stdout_handle[0]); + CloseHandle(child_stdout_handle[1]); + CloseHandle(child_stdin_handle[0]); + CloseHandle(child_stdin_handle[1]); + command->failed = 1; + command->status = cs_failed; + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, + error_to_string((int) GetLastError(), 0)); + unit_set_error(command->unit, (int) GetLastError(), 0, + command->context->pos); + return; + } + + /* Write handle for write operations on the child std input. */ + if (!DuplicateHandle + (GetCurrentProcess(), (child_stdout_handle[1]), + GetCurrentProcess(), &(command->stdin_fd), 0, FALSE, + DUPLICATE_SAME_ACCESS)) + { + CloseHandle(child_stdout_handle[0]); + CloseHandle(child_stdout_handle[1]); + CloseHandle(child_stdin_handle[0]); + CloseHandle(child_stdin_handle[1]); + command->failed = 1; + command->status = cs_failed; + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, + error_to_string((int) GetLastError(), 0)); + unit_set_error(command->unit, (int) GetLastError(), 0, + command->context->pos); + return; + } + CloseHandle(child_stdin_handle[0]); + CloseHandle(child_stdout_handle[1]); + if (command->timer) + { + + /* launch the timer */ + timer_time(command->timer); + } + if (command->reader) + { + + /* launch the reader */ + reader_read(command->reader); + } + if (command->writer) + { + + /* launch the writer */ + writer_write(command->writer); + } + + /* if there is a reader wait for its starting */ + if (command->reader) + xbt_os_sem_acquire(command->reader->started); + + /* if there is a reader wait for its ending */ + if (command->writer) + xbt_os_sem_acquire(command->writer->written); + + /* if there is a reader wait for its starting */ + if (command->timer) + xbt_os_sem_acquire(command->timer->started); + si.cb = sizeof(STARTUPINFO); + si.dwFlags |= STARTF_USESTDHANDLES; + si.hStdOutput = child_stdin_handle[1]; + si.hStdInput = child_stdout_handle[0]; + si.hStdError = child_stderr; + + /* launch the process */ + if (!CreateProcess + ( NULL, tow32cmd(command_line), NULL, NULL, TRUE, + CREATE_NO_WINDOW, NULL, NULL, &si, &pi) ) + { + if (ERROR_FILE_NOT_FOUND == GetLastError()) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, error_to_string(ECMDNOTFOUND, + 1)); + unit_set_error(command->unit, ECMDNOTFOUND, 1, + command->context->pos); + command_handle_failure(command, csr_command_not_found); + } + + else + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, + error_to_string((int) GetLastError(), 0)); + unit_set_error(command->unit, (int) GetLastError(), 0, + command->context->pos); + command_handle_failure(command, + csr_create_process_function_failure); + } } + + else + { + + /* the command is running */ + command->status = cs_in_progress; + + /* save the pid of the command */ + command->pid = pi.hProcess; + + /* close non used thread handle */ + CloseHandle(pi.hThread); + } + + /* close non used handles */ + CloseHandle(child_stdin_handle[1]); + CloseHandle(child_stdout_handle[0]); + CloseHandle(child_stderr); + } + + +#else /* */ +void command_exec(command_t command, const char *command_line) +{ + int child_stdin_fd[2]; + int child_stdout_fd[2]; + +#ifdef __CHKCMD + int rv = + is_cmd(command->unit->runner->path, command->unit->runner->builtin, + command_line); + if (rv != 0) + { + if (rv == EINVAL) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, error_to_string(rv, 0)); + unit_set_error(command->unit, rv, 0, command->context->pos); + } + + else + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, error_to_string(rv, 1)); + unit_set_error(command->unit, rv, 1, command->context->pos); + } + command_handle_failure(command, csr_command_not_found); + return; + } + +#endif /* */ + if (command->writer) + { + if (pipe(child_stdin_fd)) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, error_to_string(errno, 0)); + unit_set_error(command->unit, errno, 0, command->context->pos); + command_handle_failure(command, csr_pipe_function_failed); + return; + } + } + if (command->reader) + { + if (pipe(child_stdout_fd)) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, error_to_string(errno, 0)); + if (command->writer) + { + close(child_stdin_fd[0]); + close(child_stdin_fd[1]); + } + unit_set_error(command->unit, errno, 0, command->context->pos); + command_handle_failure(command, csr_pipe_function_failed); + return; + } + } + if (command->writer) + { + if (fcntl + (child_stdin_fd[1], F_SETFL, + fcntl(child_stdin_fd[1], F_GETFL) | O_NONBLOCK) < 0) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, error_to_string(errno, 0)); + close(child_stdin_fd[0]); + close(child_stdin_fd[1]); + if (command->reader) + { + close(child_stdout_fd[0]); + close(child_stdout_fd[1]); + } + unit_set_error(command->unit, errno, 0, command->context->pos); + command_handle_failure(command, csr_fcntl_function_failed); + return; + } + } + + /* to write to the child stdin */ + command->stdin_fd = child_stdin_fd[1]; + + /* to read from the child stdout */ + command->stdout_fd = child_stdout_fd[0]; + + /* launch the reader if any */ + if (command->reader) + reader_read(command->reader); + + /* launch the writer if any */ + if (command->writer) + writer_write(command->writer); + + /* launch the timer if any */ + if (command->timer) + timer_time(command->timer); + + /* if there is a reader wait for its starting */ + if (command->reader) + xbt_os_sem_acquire(command->reader->started); + + /* if there is a reader wait for its ending */ + if (command->writer) + xbt_os_sem_acquire(command->writer->written); + + /* if there is a reader wait for its starting */ + if (command->timer) + xbt_os_sem_acquire(command->timer->started); + + /* update the state of the command, assume it is in progress */ + command->status = cs_in_progress; + command->pid = fork(); + if (command->pid < 0) + { /* error */ + if (command->writer) + { + close(child_stdin_fd[0]); + close(child_stdin_fd[1]); + } + if (command->reader) + { + close(child_stdout_fd[0]); + close(child_stdout_fd[1]); + } + ERROR2("[%s] Cannot fork the command `%s'", command->context->pos, + command->context->command_line); + unit_set_error(command->unit, errno, 0, command->context->pos); + command_handle_failure(command, csr_fork_function_failure); + } + + else + { + if (command->pid) + { /* father */ + + /* close unused file descriptors */ + if (command->writer) + close(child_stdin_fd[0]); + if (command->reader) + close(child_stdout_fd[1]); + } + + else + { /* child */ + + /* close unused file descriptors */ + if (command->writer) + close(child_stdin_fd[1]); + if (command->reader) + close(child_stdout_fd[0]); + if (command->writer) + { + + /* redirect stdin to child_stdin_fd[0] (now fgets(), getchar() ... read from the pipe */ + if (dup2(child_stdin_fd[0], STDIN_FILENO) < 0) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, error_to_string(errno, + 0)); + command->unit->exit_code = errno; + unit_set_error(command->unit, errno, 0, command->context->pos); + command_handle_failure(command, csr_dup2_function_failure); + } + + /* close the unused file descriptor */ + close(child_stdin_fd[0]); + } + if (command->reader) + { + + /* redirect stdout and stderr to child_stdout_fd[1] (now printf(), perror()... write to the pipe */ + if (dup2(child_stdout_fd[1], STDOUT_FILENO) < 0) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, error_to_string(errno, + 0)); + unit_set_error(command->unit, errno, 0, command->context->pos); + command_handle_failure(command, csr_dup2_function_failure); + } + if (dup2(child_stdout_fd[1], STDERR_FILENO) < 0) + { + ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, + command->context->command_line, error_to_string(errno, + 0)); + unit_set_error(command->unit, errno, 0, command->context->pos); + command_handle_failure(command, csr_dup2_function_failure); + } + + /* close the unused file descriptor */ + close(child_stdout_fd[1]); + } + + /* launch the command */ + if (execlp + ("/bin/sh", "sh", "-c", command->context->command_line, + NULL) < 0) + command->execlp_errno = errno; + } + } + } + + +#endif /* */ + #ifdef _XBT_WIN32 -void -command_wait(command_t command) -{ - /* wait for the command terminaison */ - DWORD rv; - - if(WAIT_FAILED == WaitForSingleObject(command->pid, INFINITE)) - { - ERROR2("[%s] Cannot wait for the child`%s'", command->context->pos, command->context->command_line); - - unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - - command_handle_failure(command, csr_wait_failure ); - /* TODO : see for the interruption */ - } - else - { - /* don't take care of the timer or the writer or the reader failue */ - if(cs_failed != command->status && cs_interrupted != command->status) - { - if(!GetExitCodeProcess(command->pid,&rv)) - { - ERROR2("[%s] Cannot get the exit code of the process `%s'",command->context->pos, command->context->command_line); - - unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - - command_handle_failure(command, csr_get_exit_code_process_function_failure ); - } - else - command->stat_val = command->exit_code = rv; - } - } -} -#else -void -command_wait(command_t command) -{ - if(!command->execlp_errno) - { - /* let this thread wait for the child so that the main thread can detect the timeout without blocking on the wait */ - int pid = waitpid(command->pid, &(command->stat_val), 0); - - if(pid != command->pid) - { - ERROR2("[%s] Cannot wait for the child`%s'", command->context->pos, command->context->command_line); - - unit_set_error(command->unit, errno, 0, command->context->pos); - - command_handle_failure(command, csr_waitpid_function_failure); - } - else - { - if(WIFEXITED(command->stat_val)) - command->exit_code = WEXITSTATUS(command->stat_val); - } - } - else - { - ERROR2("[%s] Cannot execute the command `%s'", command->context->pos, command->context->command_line); - - unit_set_error(command->unit, command->execlp_errno, 0, command->context->pos); - - command_handle_failure(command, csr_execlp_function_failure); - } -} -#endif - -void -command_check(command_t command) -{ - int success = 1; - cs_reason_t reason; - - /* we have a signal, store it */ - if(WIFSIGNALED(command->stat_val)) - { - command->signal = strdup(signal_name(WTERMSIG(command->stat_val),command->context->signal)); - } - - /* we have a signal and no signal is expected */ - if(WIFSIGNALED(command->stat_val) && !command->context->signal) - { - success = 0; - ERROR3("[%s] `%s' : NOK (unexpected signal `%s' caught)", command->context->pos, command->context->command_line, command->signal); - - unit_set_error(command->unit, EUNXPSIG, 1, command->context->pos); - - reason = csr_unexpected_signal_caught; - } - - /* we have a signal that differ form the expected signal */ - if(WIFSIGNALED(command->stat_val) && command->context->signal && strcmp(signal_name(WTERMSIG(command->stat_val),command->context->signal),command->context->signal)) - { - - ERROR4("[%s] `%s' : NOK (got signal `%s' instead of `%s')", command->context->pos, command->context->command_line, command->signal, command->context->signal); - - if(success) - { - success = 0; - unit_set_error(command->unit, ESIGNOTMATCH, 1, command->context->pos); - } - - reason = csr_signals_dont_match; - } - - /* we don't receive the expected signal */ - if(!WIFSIGNALED(command->stat_val) && command->context->signal) - { - - ERROR3("[%s] `%s' : NOK (expected `%s' not received)", command->context->pos, command->context->command_line, command->context->signal); - - if(success) - { - success = 0; - unit_set_error(command->unit, ESIGNOTRECEIVED, 1, command->context->pos); - } - - reason = csr_expected_signal_not_received; - } - - /* if the command exit normaly and we expect a exit code : test it */ - if(WIFEXITED(command->stat_val) /* && INDEFINITE != command->context->exit_code*/) - { - /* the exit codes don't match */ - if(WEXITSTATUS(command->stat_val) != command->context->exit_code) - { - ERROR4("[%s] %s : NOK (returned code `%d' instead `%d')", command->context->pos, command->context->command_line, WEXITSTATUS(command->stat_val), command->context->exit_code); - - if(success) - { - success = 0; - unit_set_error(command->unit, EEXITCODENOTMATCH, 1, command->context->pos); - } - - reason = csr_exit_codes_dont_match; - } - } - - /* make sure the reader done */ - while(!command->reader->done) - xbt_os_thread_yield(); - - #ifdef _XBT_WIN32 - CloseHandle(command->stdout_fd); - #else - close(command->stdout_fd); - #endif - - command->stdout_fd = INDEFINITE_FD; - - xbt_strbuff_chomp(command->output); - xbt_strbuff_chomp(command->context->output); - xbt_strbuff_trim(command->output); - xbt_strbuff_trim(command->context->output); - - if(!success && !strcmp(command->output->data, command->context->output->data)) - { - xbt_dynar_t a = xbt_str_split(command->output->data, "\n"); - char *out = xbt_str_join(a,"\n||"); - xbt_dynar_free(&a); - INFO2("Output of <%s> so far: \n||%s", command->context->pos,out); - free(out); - } - /* if ouput handling flag is specified check the output */ - else if(oh_check == command->context->output_handling && command->reader) - { - if(command->output->used != command->context->output->used || strcmp(command->output->data, command->context->output->data)) - { - char *diff; - - - ERROR2("[%s] `%s' : NOK (outputs mismatch):", command->context->pos, command->context->command_line); - - if(success) - { - unit_set_error(command->unit, EOUTPUTNOTMATCH, 1, command->context->pos); - success = 0; - } - - reason = csr_outputs_dont_match; - - /* display the diff */ - diff = xbt_str_diff(command->context->output->data,command->output->data); - INFO1("%s",diff); - free(diff); - } - } - else if (oh_ignore == command->context->output_handling) - { - INFO1("(ignoring the output of <%s> as requested)",command->context->line); - } - else if (oh_display == command->context->output_handling) - { - xbt_dynar_t a = xbt_str_split(command->output->data, "\n"); - char *out = xbt_str_join(a,"\n||"); - xbt_dynar_free(&a); - INFO3("[%s] Here is the (ignored) command `%s' output: \n||%s",command->context->pos, command->context->command_line, out); - free(out); - } - - if(success) - { - xbt_os_mutex_acquire(command->mutex); - - if(command->status != cs_interrupted) - { - /* signal the success of the command */ - command->status = cs_successeded; - command->successeded = 1; - - /* increment the number of successeded command of the unit */ - (command->root->successeded_cmd_nb)++; - } - - xbt_os_mutex_release(command->mutex); - } - else - { - command_handle_failure(command, reason); - } -} - +void command_wait(command_t command) +{ + + /* wait for the command terminaison */ + DWORD rv; + if (WAIT_FAILED == WaitForSingleObject(command->pid, INFINITE)) + { + ERROR2("[%s] Cannot wait for the child`%s'", command->context->pos, + command->context->command_line); + unit_set_error(command->unit, (int) GetLastError(), 0, + command->context->pos); + command_handle_failure(command, csr_wait_failure); + + /* TODO : see for the interruption */ + } + + else + { + + /* don't take care of the timer or the writer or the reader failue */ + if (cs_failed != command->status + && cs_interrupted != command->status) + { + if (!GetExitCodeProcess(command->pid, &rv)) + { + ERROR2("[%s] Cannot get the exit code of the process `%s'", + command->context->pos, command->context->command_line); + unit_set_error(command->unit, (int) GetLastError(), 0, + command->context->pos); + command_handle_failure(command, + csr_get_exit_code_process_function_failure); + } + + else + command->stat_val = command->exit_code = rv; + } + } + } + + +#else /* */ +void command_wait(command_t command) +{ + if (!command->execlp_errno) + { + + /* let this thread wait for the child so that the main thread can detect the timeout without blocking on the wait */ + int pid = waitpid(command->pid, &(command->stat_val), 0); + if (pid != command->pid) + { + ERROR2("[%s] Cannot wait for the child`%s'", command->context->pos, + command->context->command_line); + unit_set_error(command->unit, errno, 0, command->context->pos); + command_handle_failure(command, csr_waitpid_function_failure); + } + + else + { + if (WIFEXITED(command->stat_val)) + command->exit_code = WEXITSTATUS(command->stat_val); + } + } + + else + { + ERROR2("[%s] Cannot execute the command `%s'", command->context->pos, + command->context->command_line); + unit_set_error(command->unit, command->execlp_errno, 0, + command->context->pos); + command_handle_failure(command, csr_execlp_function_failure); + } + } + + +#endif /* */ + void command_check(command_t command) +{ + int success = 1; + cs_reason_t reason; + + /* we have a signal, store it */ + if (WIFSIGNALED(command->stat_val)) + { + command->signal = + strdup(signal_name + (WTERMSIG(command->stat_val), command->context->signal)); + } + + /* we have a signal and no signal is expected */ + if (WIFSIGNALED(command->stat_val) && !command->context->signal) + { + success = 0; + ERROR3("[%s] `%s' : NOK (unexpected signal `%s' caught)", + command->context->pos, command->context->command_line, + command->signal); + unit_set_error(command->unit, EUNXPSIG, 1, command->context->pos); + reason = csr_unexpected_signal_caught; + } + + /* we have a signal that differ form the expected signal */ + if (WIFSIGNALED(command->stat_val) && command->context->signal + && + strcmp(signal_name + (WTERMSIG(command->stat_val), command->context->signal), + command->context->signal)) + { + ERROR4("[%s] `%s' : NOK (got signal `%s' instead of `%s')", + command->context->pos, command->context->command_line, + command->signal, command->context->signal); + if (success) + { + success = 0; + unit_set_error(command->unit, ESIGNOTMATCH, 1, + command->context->pos); + } + reason = csr_signals_dont_match; + } + + /* we don't receive the expected signal */ + if (!WIFSIGNALED(command->stat_val) && command->context->signal) + { + ERROR3("[%s] `%s' : NOK (expected `%s' not received)", + command->context->pos, command->context->command_line, + command->context->signal); + if (success) + { + success = 0; + unit_set_error(command->unit, ESIGNOTRECEIVED, 1, + command->context->pos); + } + reason = csr_expected_signal_not_received; + } + + /* if the command exit normaly and we expect a exit code : test it */ + if (WIFEXITED(command->stat_val) + /* && INDEFINITE != command->context->exit_code */ ) + { + + /* the exit codes don't match */ + if (WEXITSTATUS(command->stat_val) != command->context->exit_code) + { + ERROR4("[%s] %s : NOK (returned code `%d' instead `%d')", + command->context->pos, command->context->command_line, + WEXITSTATUS(command->stat_val), command->context->exit_code); + if (success) + { + success = 0; + unit_set_error(command->unit, EEXITCODENOTMATCH, 1, + command->context->pos); + } + reason = csr_exit_codes_dont_match; + } + } + + /* make sure the reader done */ + while (!command->reader->done) + xbt_os_thread_yield(); + #ifdef _XBT_WIN32 -void -command_kill(command_t command) -{ - if(INDEFINITE_PID != command->pid) - { - INFO2("[%s] Kill the process `%s'", command->context->pos, command->context->command_line); - TerminateProcess(command->pid, INDEFINITE); - } -} -#else -void -command_kill(command_t command) -{ - if(INDEFINITE_PID != command->pid) - { - kill(command->pid,SIGTERM); - - if(!command->context->signal) - command->context->signal = strdup("SIGTERM"); - - command->exit_code = INDEFINITE; - command->killed = 1; - - usleep(100); - - INFO2("[%s] Kill the process `%s'", command->context->pos, command->context->command_line); - kill(command->pid,SIGKILL); - - - } -} -#endif - -void -command_interrupt(command_t command) -{ - xbt_os_mutex_acquire(command->mutex); - - if((command->status != cs_interrupted) && (command->status != cs_failed) && (command->status != cs_successeded)) - { - command->status = cs_interrupted; - command->reason = csr_interruption_request; - command->interrupted = 1; - command->unit->interrupted = 1; - - xbt_os_mutex_acquire(command->root->mutex); - (command->root->interrupted_cmd_nb)++; - xbt_os_mutex_release(command->root->mutex); - - if(command->pid != INDEFINITE_PID) - command_kill(command); - } - - xbt_os_mutex_release(command->mutex); - - -} - -void -command_summarize(command_t command) -{ - if(cs_successeded != command->status) - { - - #ifndef _XBT_WIN32 - if(command->killed) - printf(" \n"); - #endif - - /* display the reason of the status of the command */ - switch(command->reason) - { - /* the function pipe or CreatePipe() fails */ - case csr_pipe_function_failed : - printf(" reason : pipe() or CreatePipe() function failed (system error)\n"); - break; - - case csr_shell_failed : - printf(" reason : shell failed (may be command not found)\n"); - break; - - case csr_get_exit_code_process_function_failure : - printf(" reason : ExitCodeProcess() function failed (system error)\n"); - break; - - /* reader failure reasons*/ - case csr_read_pipe_broken : - printf(" reason : command read pipe broken\n"); - break; - - case csr_read_failure : - printf(" reason : command stdout read failed\n"); - break; - - /* writer failure reasons */ - case csr_write_failure : - printf(" reason : command stdin write failed\n"); - break; - - case csr_write_pipe_broken : - printf(" reason : command write pipe broken\n"); - break; - - /* timer reason */ - case csr_timeout : - printf(" reason : command timeouted\n"); - break; - - /* command failure reason */ - case csr_command_not_found : - printf(" reason : command not found\n"); - break; - - /* context failure reasons */ - case csr_exit_codes_dont_match : - printf(" reason : exit codes don't match\n"); - - break; - - /* dup2 function failure reasons */ - case csr_dup2_function_failure : - printf(" reason : dup2() function failed\n"); - - break; - - /* execlp function failure reasons */ - case csr_execlp_function_failure : - printf(" reason : execlp() function failed\n"); - - break; - - /* waitpid function failure reasons */ - case csr_waitpid_function_failure : - printf(" reason : waitpid() function failed\n"); - - break; - - /* CreateProcess function failure reasons */ - case csr_create_process_function_failure : - printf(" reason : CreateProcesss() function failed\n"); - - break; - - case csr_outputs_dont_match : - { - /*char *diff;*/ - printf(" reason : ouputs don't match\n"); - /*diff = xbt_str_diff(command->context->output->data,command->output->data); - printf(" output diff :\n%s\n",diff); - free(diff);*/ - } - - break; - - case csr_signals_dont_match : - printf(" reason : signals don't match\n"); - break; - - case csr_unexpected_signal_caught: - printf(" reason : unexpected signal caught\n"); - break; - - case csr_expected_signal_not_received : - printf(" reason : expected signal not receipt\n"); - break; - - /* system failure reasons */ - case csr_fork_function_failure : - printf(" reason : fork function failed\n"); - break; - - case csr_wait_failure : - printf(" reason : wait command failure\n"); - break; - - /* global/local interruption */ - case csr_interruption_request : - printf(" reason : the command receive a interruption request\n"); - break; - - /* unknown ? */ - case csr_unknown : - printf(" reason : unknown \n"); - } - } - - if(csr_command_not_found != command->reason && csr_fork_function_failure != command->reason && csr_execlp_function_failure != command->reason) - { - if(INDEFINITE != command->exit_code) - /* the command exit code */ - printf(" exit code : %d\n",command->exit_code); - - /* if an expected exit code was specified display it */ - if(INDEFINITE != command->context->exit_code) - printf(" expected exit code : %d\n",command->context->exit_code); - else - printf(" no expected exit code specified\n"); - - /* no expected signal expected */ - if(NULL == command->context->signal) - { - printf(" no expected signal specified\n"); - - if(command->signal) - printf(" but got signal : %s\n",command->signal); - - } - /* if an expected exit code was specified display it */ - else - { - if(NULL != command->signal) - printf(" signal : %s\n",command->signal); - else - printf(" no signal caugth\n"); - } - - /* if the command has out put and the metacommand display output is specified display it */ - if(command->output && (0 != command->output->used) && (oh_display == command->context->output_handling)) - { - xbt_dynar_t a = xbt_str_split(command->output->data, "\n"); - char *out = xbt_str_join(a,"\n||"); - xbt_dynar_free(&a); - printf(" output :\n||%s",out); - free(out); - } - } - - printf("\n"); -} - -void -command_handle_failure(command_t command, cs_reason_t reason) -{ - unit_t root = command->root; - - xbt_os_mutex_acquire(command->mutex); - - if((command->status != cs_interrupted) && (command->status != cs_failed)) - { - command->status = cs_failed; - command->reason = reason; - command->failed = 1; - - command->unit->failed = 1; - - xbt_os_mutex_acquire(root->mutex); - - /* increment the number of failed command of the unit */ - root->failed_cmd_nb++; - - /* if the --ignore-failures option is not specified */ - if(!keep_going_unit_flag) - { - if(!root->interrupted) - { - /* the unit interrupted (exit for the loop) */ - root->interrupted = 1; - - /* release the unit */ - xbt_os_sem_release(root->sem); - } - - /* if the --keep-going option is not specified */ - if(!keep_going_flag) - { - if(!interrupted) - { - /* request an global interruption by the runner */ - interrupted = 1; - - /* release the runner */ - xbt_os_sem_release(units_sem); - } - } - } - - xbt_os_mutex_release(root->mutex); - } - - xbt_os_mutex_release(command->mutex); -} - -int -command_free(command_t* ptr) -{ - /* close the stdin and the stdout pipe handles */ - - #ifdef _XBT_WIN32 - if((*ptr)->stdin_fd != INDEFINITE_FD) - CloseHandle((*ptr)->stdin_fd); - - if((*ptr)->stdout_fd != INDEFINITE_FD) - CloseHandle((*ptr)->stdout_fd); - - #else - - if((*ptr)->stdin_fd != INDEFINITE_FD) - close((*ptr)->stdin_fd); - - if((*ptr)->stdout_fd != INDEFINITE_FD) - close((*ptr)->stdout_fd); - #endif - - if((*ptr)->timer) - { - if(timer_free(&((*ptr)->timer)) < 0) - return -1; - } - - if((*ptr)->writer) - { - if(writer_free(&((*ptr)->writer)) < 0) - return -1; - } - - if((*ptr)->reader) - { - if(reader_free(&((*ptr)->reader)) < 0) - return -1; - } - - if((*ptr)->output) - xbt_strbuff_free((*ptr)->output); - - if((*ptr)->context) - { - if(context_free(&((*ptr)->context)) < 0) - return -1; - } - - if((*ptr)->signal) - free((*ptr)->signal); - - free(*ptr); - - *ptr = NULL; - - return 0; -} - - - + CloseHandle(command->stdout_fd); + +#else /* */ + close(command->stdout_fd); + +#endif /* */ + command->stdout_fd = INDEFINITE_FD; + xbt_strbuff_chomp(command->output); + xbt_strbuff_chomp(command->context->output); + xbt_strbuff_trim(command->output); + xbt_strbuff_trim(command->context->output); + if (!success + && !strcmp(command->output->data, command->context->output->data)) + { + xbt_dynar_t a = xbt_str_split(command->output->data, "\n"); + char *out = xbt_str_join(a, "\n||"); + xbt_dynar_free(&a); + INFO2("Output of <%s> so far: \n||%s", command->context->pos, out); + free(out); + } + + /* if ouput handling flag is specified check the output */ + else if (oh_check == command->context->output_handling + && command->reader) + { + if (command->output->used != command->context->output->used + || strcmp(command->output->data, command->context->output->data)) + { + char *diff; + ERROR2("[%s] `%s' : NOK (outputs mismatch):", + command->context->pos, command->context->command_line); + if (success) + { + unit_set_error(command->unit, EOUTPUTNOTMATCH, 1, + command->context->pos); + success = 0; + } + reason = csr_outputs_dont_match; + + /* display the diff */ + diff = + xbt_str_diff(command->context->output->data, + command->output->data); + INFO1("%s", diff); + free(diff); + } + } + + else if (oh_ignore == command->context->output_handling) + { + INFO1("(ignoring the output of <%s> as requested)", + command->context->line); + } + + else if (oh_display == command->context->output_handling) + { + xbt_dynar_t a = xbt_str_split(command->output->data, "\n"); + char *out = xbt_str_join(a, "\n||"); + xbt_dynar_free(&a); + INFO3("[%s] Here is the (ignored) command `%s' output: \n||%s", + command->context->pos, command->context->command_line, out); + free(out); + } + if (success) + { + xbt_os_mutex_acquire(command->mutex); + if (command->status != cs_interrupted) + { + + /* signal the success of the command */ + command->status = cs_successeded; + command->successeded = 1; + + /* increment the number of successeded command of the unit */ + (command->root->successeded_cmd_nb)++; + } + xbt_os_mutex_release(command->mutex); + } + + else + { + command_handle_failure(command, reason); + } + } + + +#ifdef _XBT_WIN32 +void command_kill(command_t command) +{ + if (INDEFINITE_PID != command->pid) + { + INFO2("[%s] Kill the process `%s'", command->context->pos, + command->context->command_line); + TerminateProcess(command->pid, INDEFINITE); + } + } + + +#else /* */ +void command_kill(command_t command) +{ + if (INDEFINITE_PID != command->pid) + { + kill(command->pid, SIGTERM); + if (!command->context->signal) + command->context->signal = strdup("SIGTERM"); + command->exit_code = INDEFINITE; + command->killed = 1; + usleep(100); + INFO2("[%s] Kill the process `%s'", command->context->pos, + command->context->command_line); + kill(command->pid, SIGKILL); + } + } + + +#endif /* */ + void command_interrupt(command_t command) +{ + xbt_os_mutex_acquire(command->mutex); + if ((command->status != cs_interrupted) + && (command->status != cs_failed) + && (command->status != cs_successeded)) + { + command->status = cs_interrupted; + command->reason = csr_interruption_request; + command->interrupted = 1; + command->unit->interrupted = 1; + xbt_os_mutex_acquire(command->root->mutex); + (command->root->interrupted_cmd_nb)++; + xbt_os_mutex_release(command->root->mutex); + if (command->pid != INDEFINITE_PID) + command_kill(command); + } + xbt_os_mutex_release(command->mutex); + } + + void command_summarize(command_t command) +{ + if (cs_successeded != command->status) + { + +#ifndef _XBT_WIN32 + if (command->killed) + printf(" \n"); + +#endif /* */ + + /* display the reason of the status of the command */ + switch (command->reason) + { + + /* the function pipe or CreatePipe() fails */ + case csr_pipe_function_failed: + + printf + (" reason : pipe() or CreatePipe() function failed (system error)\n"); + break; + case csr_shell_failed: + printf + (" reason : shell failed (may be command not found)\n"); + break; + case csr_get_exit_code_process_function_failure: + printf + (" reason : ExitCodeProcess() function failed (system error)\n"); + break; + + /* reader failure reasons */ + case csr_read_pipe_broken: + + printf + (" reason : command read pipe broken\n"); + break; + case csr_read_failure: + printf + (" reason : command stdout read failed\n"); + break; + + /* writer failure reasons */ + case csr_write_failure: + + printf + (" reason : command stdin write failed\n"); + break; + case csr_write_pipe_broken: + printf + (" reason : command write pipe broken\n"); + break; + + /* timer reason */ + case csr_timeout: + + printf + (" reason : command timeouted\n"); + break; + + /* command failure reason */ + case csr_command_not_found: + + printf + (" reason : command not found\n"); + break; + + /* context failure reasons */ + case csr_exit_codes_dont_match: + + printf + (" reason : exit codes don't match\n"); + break; + + /* dup2 function failure reasons */ + case csr_dup2_function_failure: + + printf + (" reason : dup2() function failed\n"); + break; + + /* execlp function failure reasons */ + case csr_execlp_function_failure: + + printf + (" reason : execlp() function failed\n"); + break; + + /* waitpid function failure reasons */ + case csr_waitpid_function_failure: + + printf + (" reason : waitpid() function failed\n"); + break; + + /* CreateProcess function failure reasons */ + case csr_create_process_function_failure: + + printf + (" reason : CreateProcesss() function failed\n"); + break; + case csr_outputs_dont_match: + { + + /*char *diff; */ + printf + (" reason : ouputs don't match\n"); + + /*diff = xbt_str_diff(command->context->output->data,command->output->data); + printf(" output diff :\n%s\n",diff); + free(diff); */ + } + break; + case csr_signals_dont_match: + printf + (" reason : signals don't match\n"); + break; + case csr_unexpected_signal_caught: + printf + (" reason : unexpected signal caught\n"); + break; + case csr_expected_signal_not_received: + printf + (" reason : expected signal not receipt\n"); + break; + + /* system failure reasons */ + case csr_fork_function_failure: + + printf + (" reason : fork function failed\n"); + break; + case csr_wait_failure: + printf + (" reason : wait command failure\n"); + break; + + /* global/local interruption */ + case csr_interruption_request: + + printf + (" reason : the command receive a interruption request\n"); + break; + + /* unknown ? */ + case csr_unknown: + printf(" reason : unknown \n"); + } + } + if (csr_command_not_found != command->reason + && csr_fork_function_failure != command->reason + && csr_execlp_function_failure != command->reason) + { + if (INDEFINITE != command->exit_code) + + /* the command exit code */ + printf(" exit code : %d\n", + command->exit_code); + + /* if an expected exit code was specified display it */ + if (INDEFINITE != command->context->exit_code) + printf(" expected exit code : %d\n", + command->context->exit_code); + + else + printf(" no expected exit code specified\n"); + + /* no expected signal expected */ + if (NULL == command->context->signal) + { + printf(" no expected signal specified\n"); + if (command->signal) + printf(" but got signal : %s\n", + command->signal); + } + + /* if an expected exit code was specified display it */ + else + { + if (NULL != command->signal) + printf(" signal : %s\n", + command->signal); + + else + printf(" no signal caugth\n"); + } + + /* if the command has out put and the metacommand display output is specified display it */ + if (command->output && (0 != command->output->used) + && (oh_display == command->context->output_handling)) + { + xbt_dynar_t a = xbt_str_split(command->output->data, "\n"); + char *out = xbt_str_join(a, "\n||"); + xbt_dynar_free(&a); + printf(" output :\n||%s", out); + free(out); + } + } + printf("\n"); + } void command_handle_failure(command_t command, cs_reason_t reason) +{ + unit_t root = command->root; + xbt_os_mutex_acquire(command->mutex); + if ((command->status != cs_interrupted) + && (command->status != cs_failed)) + { + command->status = cs_failed; + command->reason = reason; + command->failed = 1; + command->unit->failed = 1; + xbt_os_mutex_acquire(root->mutex); + + /* increment the number of failed command of the unit */ + root->failed_cmd_nb++; + + /* if the --ignore-failures option is not specified */ + if (!keep_going_unit_flag) + { + if (!root->interrupted) + { + + /* the unit interrupted (exit for the loop) */ + root->interrupted = 1; + + /* release the unit */ + xbt_os_sem_release(root->sem); + } + + /* if the --keep-going option is not specified */ + if (!keep_going_flag) + { + if (!interrupted) + { + + /* request an global interruption by the runner */ + interrupted = 1; + + /* release the runner */ + xbt_os_sem_release(units_sem); + } + } + } + xbt_os_mutex_release(root->mutex); + } + xbt_os_mutex_release(command->mutex); + } + + int command_free(command_t * ptr) +{ + + /* close the stdin and the stdout pipe handles */ + +#ifdef _XBT_WIN32 + if ((*ptr)->stdin_fd != INDEFINITE_FD) + CloseHandle((*ptr)->stdin_fd); + if ((*ptr)->stdout_fd != INDEFINITE_FD) + CloseHandle((*ptr)->stdout_fd); + +#else /* */ + if ((*ptr)->stdin_fd != INDEFINITE_FD) + close((*ptr)->stdin_fd); + if ((*ptr)->stdout_fd != INDEFINITE_FD) + close((*ptr)->stdout_fd); + +#endif /* */ + if ((*ptr)->timer) + { + if (timer_free(&((*ptr)->timer)) < 0) + return -1; + } + if ((*ptr)->writer) + { + if (writer_free(&((*ptr)->writer)) < 0) + return -1; + } + if ((*ptr)->reader) + { + if (reader_free(&((*ptr)->reader)) < 0) + return -1; + } + if ((*ptr)->output) + xbt_strbuff_free((*ptr)->output); + if ((*ptr)->context) + { + if (context_free(&((*ptr)->context)) < 0) + return -1; + } + if ((*ptr)->signal) + free((*ptr)->signal); + free(*ptr); + *ptr = NULL; + return 0; + } + + diff --git a/tools/tesh2/src/context.c b/tools/tesh2/src/context.c index 918e8102af..5db6beefbc 100644 --- a/tools/tesh2/src/context.c +++ b/tools/tesh2/src/context.c @@ -10,229 +10,181 @@ * This file contains all the definitions of the functions related with * the tesh context type. * - */ - + */ + #include - - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + #define INDEFINITE_SIGNAL NULL - -context_t -context_new(void) -{ - context_t context = xbt_new0(s_context_t,1); - - context->line = NULL; - context->pos = NULL; - context->command_line = NULL; - context->exit_code = 0; - context->timeout = INDEFINITE; - context->input = xbt_strbuff_new(); - context->output = xbt_strbuff_new(); - context->signal = INDEFINITE_SIGNAL; - context->output_handling = oh_check; - context->async = 0; - - #ifdef _XBT_WIN32 - context->t_command_line = NULL; - context->is_not_found = 0; - #endif - - return context; -} - -int -context_free(context_t* ptr) -{ - if(((*ptr)->input)) - xbt_strbuff_free(((*ptr)->input)); - - if(((*ptr)->output)) - xbt_strbuff_free(((*ptr)->output)); - - if((*ptr)->command_line) - free((*ptr)->command_line); - - if((*ptr)->pos) - free((*ptr)->pos); - - if((*ptr)->signal) - free((*ptr)->signal); - - #ifdef _XBT_WIN32 - if((*ptr)->t_command_line) - free((*ptr)->t_command_line); - #endif - - *ptr = NULL; - - return 0; -} - -int -context_reset(context_t context) -{ - context->line = NULL; - context->pos = NULL; - - if(context->command_line) - { - free(context->command_line); - context->command_line = NULL; - } - - #ifdef _XBT_WIN32 - if(context->t_command_line) - { - free(context->t_command_line); - context->t_command_line = NULL; - } - - context->is_not_found = 0; - - #endif - - if(context->pos) - { - free(context->pos); - context->pos = NULL; - } - - if(context->input) - xbt_strbuff_empty(context->input); - - if(context->output) - xbt_strbuff_empty(context->output); - - if(context->signal) - { - free(context->signal); - context->signal = NULL; - } - - /* default expected exit code */ - context->exit_code = 0; - - context->output_handling = oh_check; - context->async = 0; - - return 0; - -} - -context_t -context_dup(context_t context) -{ - context_t dup; - - dup = xbt_new0(s_context_t, 1); - - dup->line = context->line; - dup->pos = strdup(context->pos); - dup->command_line = strdup(context->command_line); - - - #ifdef _XBT_WIN32 - dup->t_command_line = strdup(context->t_command_line); - dup->is_not_found = context->is_not_found; - #endif - - dup->exit_code = context->exit_code; - dup->timeout = context->timeout; - dup->output = NULL; - dup->input = NULL; - dup->signal = NULL; - - if(context->input->used) - { - dup->input = xbt_strbuff_new(); - xbt_strbuff_append(dup->input,context->input->data); - } - - dup->output = xbt_strbuff_new(); - - if(context->output->used) - { - xbt_strbuff_append(dup->output,context->output->data); - } - - if(context->signal) - { - if(!(dup->signal = strdup(context->signal))) - { - free(dup); - return NULL; - } - } - - dup->output_handling = context->output_handling; - - dup->async = context->async; - - return dup; -} - -void -context_clear(context_t context) -{ - context->line = NULL; - context->pos = NULL; - - if(context->command_line) - { - free(context->command_line); - context->command_line = NULL; - } - - #ifdef _XBT_WIN32 - if(context->t_command_line) - { - free(context->t_command_line); - context->t_command_line = NULL; - } - context->is_not_found = 0; - - #endif - - if(context->pos) - { - free(context->pos); - context->pos = NULL; - } - - context->exit_code = 0; - context->timeout = INDEFINITE; - - if(context->input) - xbt_strbuff_empty(context->input); - - if(context->output) - xbt_strbuff_empty(context->output); - - if(context->signal) - { - free(context->signal); - context->signal = INDEFINITE_SIGNAL; - } - - context->output_handling = oh_check; - context->async = 0; - -} - -void -context_input_write(context_t context, const char* buffer) -{ - xbt_strbuff_append(context->input, buffer); -} - -void -context_ouput_read(context_t context, const char* buffer) -{ - xbt_strbuff_append(context->output, buffer); -} - - - + context_t context_new(void) +{ + context_t context = xbt_new0(s_context_t, 1); + context->line = NULL; + context->pos = NULL; + context->command_line = NULL; + context->exit_code = 0; + context->timeout = INDEFINITE; + context->input = xbt_strbuff_new(); + context->output = xbt_strbuff_new(); + context->signal = INDEFINITE_SIGNAL; + context->output_handling = oh_check; + context->async = 0; + +#ifdef _XBT_WIN32 + context->t_command_line = NULL; + context->is_not_found = 0; + +#endif /* */ + return context; + } + + int context_free(context_t * ptr) +{ + if (((*ptr)->input)) + xbt_strbuff_free(((*ptr)->input)); + if (((*ptr)->output)) + xbt_strbuff_free(((*ptr)->output)); + if ((*ptr)->command_line) + free((*ptr)->command_line); + if ((*ptr)->pos) + free((*ptr)->pos); + if ((*ptr)->signal) + free((*ptr)->signal); + +#ifdef _XBT_WIN32 + if ((*ptr)->t_command_line) + free((*ptr)->t_command_line); + +#endif /* */ + *ptr = NULL; + return 0; + } + + int context_reset(context_t context) +{ + context->line = NULL; + context->pos = NULL; + if (context->command_line) + { + free(context->command_line); + context->command_line = NULL; + } + +#ifdef _XBT_WIN32 + if (context->t_command_line) + { + free(context->t_command_line); + context->t_command_line = NULL; + } + context->is_not_found = 0; + +#endif /* */ + if (context->pos) + { + free(context->pos); + context->pos = NULL; + } + if (context->input) + xbt_strbuff_empty(context->input); + if (context->output) + xbt_strbuff_empty(context->output); + if (context->signal) + { + free(context->signal); + context->signal = NULL; + } + + /* default expected exit code */ + context->exit_code = 0; + context->output_handling = oh_check; + context->async = 0; + return 0; + } + + context_t context_dup(context_t context) +{ + context_t dup; + dup = xbt_new0(s_context_t, 1); + dup->line = context->line; + dup->pos = strdup(context->pos); + dup->command_line = strdup(context->command_line); + +#ifdef _XBT_WIN32 + dup->t_command_line = strdup(context->t_command_line); + dup->is_not_found = context->is_not_found; + +#endif /* */ + dup->exit_code = context->exit_code; + dup->timeout = context->timeout; + dup->output = NULL; + dup->input = NULL; + dup->signal = NULL; + if (context->input->used) + { + dup->input = xbt_strbuff_new(); + xbt_strbuff_append(dup->input, context->input->data); + } + dup->output = xbt_strbuff_new(); + if (context->output->used) + { + xbt_strbuff_append(dup->output, context->output->data); + } + if (context->signal) + { + if (!(dup->signal = strdup(context->signal))) + { + free(dup); + return NULL; + } + } + dup->output_handling = context->output_handling; + dup->async = context->async; + return dup; + } + + void context_clear(context_t context) +{ + context->line = NULL; + context->pos = NULL; + if (context->command_line) + { + free(context->command_line); + context->command_line = NULL; + } + +#ifdef _XBT_WIN32 + if (context->t_command_line) + { + free(context->t_command_line); + context->t_command_line = NULL; + } + context->is_not_found = 0; + +#endif /* */ + if (context->pos) + { + free(context->pos); + context->pos = NULL; + } + context->exit_code = 0; + context->timeout = INDEFINITE; + if (context->input) + xbt_strbuff_empty(context->input); + if (context->output) + xbt_strbuff_empty(context->output); + if (context->signal) + { + free(context->signal); + context->signal = INDEFINITE_SIGNAL; + } + context->output_handling = oh_check; + context->async = 0; + } + + void context_input_write(context_t context, const char *buffer) +{ + xbt_strbuff_append(context->input, buffer); + } void context_ouput_read(context_t context, const char *buffer) +{ + xbt_strbuff_append(context->output, buffer); + } diff --git a/tools/tesh2/src/directories.c b/tools/tesh2/src/directories.c index 3b480b093b..b57d85c98b 100644 --- a/tools/tesh2/src/directories.c +++ b/tools/tesh2/src/directories.c @@ -1,120 +1,93 @@ #include #include + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + directories_t directories_new(void) +{ + directories_t directories = xbt_new0(s_directories_t, 1); + directories->items = + xbt_dynar_new(sizeof(directory_t), (void_f_pvoid_t) directory_free); + return directories; + } + + int directories_get_size(directories_t directories) +{ + if (!directories) + { + errno = EINVAL; + return -1; + } + return xbt_dynar_length(directories->items); + } + + int directories_is_empty(directories_t directories) +{ + if (!directories) + { + errno = EINVAL; + return -1; + } + return (0 == xbt_dynar_length(directories->items)); + } + + int directories_add(directories_t directories, directory_t directory) +{ + directory_t cur; + unsigned int i; + if (!directories) + return EINVAL; + xbt_dynar_foreach(directories->items, i, cur) { + if (!strcmp(cur->name, directory->name)) + return EEXIST; + } + xbt_dynar_push(directories->items, &directory); + return 0; + } + + int +directories_contains(directories_t directories, directory_t directory) +{ + directory_t * cur; + unsigned int i; + if (!directories) + return EINVAL; + xbt_dynar_foreach(directories->items, i, cur) { + if (!strcmp((*cur)->name, directory->name)) + return 1; + } + return 0; + } + + int +directories_load(directories_t directories, fstreams_t fstreams, + xbt_dynar_t suffixes) +{ + directory_t directory; + int rv; + unsigned int i; + if (!directories || !fstreams || !suffixes) + return EINVAL; + xbt_dynar_foreach(directories->items, i, directory) { + if ((rv = directory_open(directory))) + return rv; + if ((rv = directory_load(directory, fstreams, suffixes))) + return rv; + if ((rv = directory_close(directory))) + return rv; + } + return 0; + } + + int directories_free(void **directoriesptr) +{ + directories_t directories; + if (!(*directoriesptr)) + return EINVAL; + directories = (directories_t) (*directoriesptr); + if (directories->items) + xbt_dynar_free(&(directories->items)); + free(*directoriesptr); + *directoriesptr = NULL; + return 0; + } + -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - -directories_t -directories_new(void) -{ - directories_t directories = xbt_new0(s_directories_t, 1); - - directories->items = xbt_dynar_new(sizeof(directory_t), (void_f_pvoid_t)directory_free); - - return directories; -} - -int -directories_get_size(directories_t directories) -{ - if(!directories) - { - errno = EINVAL; - return -1; - } - - return xbt_dynar_length(directories->items); -} - -int -directories_is_empty(directories_t directories) -{ - if(!directories) - { - errno = EINVAL; - return -1; - } - - return (0 == xbt_dynar_length(directories->items)); -} - -int -directories_add(directories_t directories, directory_t directory) -{ - directory_t cur; - unsigned int i; - - if(!directories) - return EINVAL; - - xbt_dynar_foreach(directories->items, i, cur) - { - if(!strcmp(cur->name, directory->name)) - return EEXIST; - } - - xbt_dynar_push(directories->items, &directory); - - return 0; -} - -int -directories_contains(directories_t directories, directory_t directory) -{ - directory_t* cur; - unsigned int i; - - if(!directories) - return EINVAL; - - xbt_dynar_foreach(directories->items, i, cur) - { - if(!strcmp((*cur)->name, directory->name)) - return 1; - } - - return 0; -} - -int -directories_load(directories_t directories, fstreams_t fstreams, xbt_dynar_t suffixes) -{ - directory_t directory; - int rv; - unsigned int i; - - if(!directories || !fstreams || !suffixes) - return EINVAL; - - xbt_dynar_foreach(directories->items, i, directory) - { - if((rv = directory_open(directory))) - return rv; - - if((rv = directory_load(directory, fstreams, suffixes))) - return rv; - - if((rv = directory_close(directory))) - return rv; - } - - return 0; -} - -int -directories_free(void** directoriesptr) -{ - directories_t directories; - - if(!(*directoriesptr)) - return EINVAL; - - directories = (directories_t)(*directoriesptr); - - if(directories->items) - xbt_dynar_free(&(directories->items)); - - free(*directoriesptr); - *directoriesptr = NULL; - - return 0; -} diff --git a/tools/tesh2/src/directory.c b/tools/tesh2/src/directory.c index ac6bf4bdd4..756fb43b82 100644 --- a/tools/tesh2/src/directory.c +++ b/tools/tesh2/src/directory.c @@ -1,157 +1,124 @@ #include #include #include - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - -directory_t -directory_new(const char* name) -{ - directory_t directory; - - if(!name) - { - errno = EINVAL; - return NULL; - } - - directory = xbt_new0(s_directory_t, 1); - - - directory->name = strdup(name); - - - directory->stream = NULL; - - return directory; -} - -int -directory_open(directory_t directory) -{ - if(!directory || directory->stream) - return EINVAL; - - if(!(directory->stream = opendir(directory->name))) - return errno; - - return 0; -} - - -int -directory_close(directory_t directory) -{ - if(!directory) - return EINVAL; - - if(!directory->stream) - return EBADF; - - if(closedir(directory->stream)) - return errno; - - directory->stream = NULL; - return 0; -} - -int -directory_load(directory_t directory, fstreams_t fstreams, xbt_dynar_t suffixes) -{ - struct dirent* entry ={0}; - s_fstream_t sfstream = {0}; - char* suffix; - unsigned int i; - int has_valid_suffix; - int is_empty = 1; - int rv; - - if(!directory || !fstreams) - return EINVAL; - - if(!directory->stream) - return EBADF; - - sfstream.directory = strdup(directory->name); - - while((entry = readdir(directory->stream))) - { - has_valid_suffix = 0; - - xbt_dynar_foreach(suffixes, i, suffix) - { - if(!strncmp(suffix, entry->d_name + (strlen(entry->d_name) - strlen(suffix)), strlen(suffix))) - { - has_valid_suffix = 1; - break; - } - } - - if(!has_valid_suffix) - continue; - - sfstream.name = strdup(entry->d_name); - - /* check first if the file stream is already in the file streams to run */ - if(fstreams_contains(fstreams, &sfstream)) - { - WARN1("file %s already registred", entry->d_name); - free(sfstream.name); - continue; - } - - /* add the fstream to the list of file streams to run */ - if((rv = fstreams_add(fstreams, fstream_new(directory->name, entry->d_name)))) - { - free(sfstream.directory); - free(sfstream.name); - return rv; - } - - is_empty = 0; - free(sfstream.name); - } - - if(is_empty) - WARN1("no tesh file found in the directory %s", directory->name); - - free(sfstream.directory); - - - return 0; -} - -int -directory_free(void** directoryptr) -{ - directory_t directory; - - if(!(*directoryptr)) - return EINVAL; - - directory = *((directory_t*)directoryptr); - - if(directory->stream) - if(directory_close(directory)) - return errno; - - if(directory->name) - free(directory->name); - - free(*directoryptr); - *directoryptr = NULL; - - return 0; -} - -const char* -directory_get_name(directory_t directory) -{ - if(!directory) - { - errno = EINVAL; - return NULL; - } - - return (const char*)directory->name; -} + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + directory_t directory_new(const char *name) +{ + directory_t directory; + if (!name) + { + errno = EINVAL; + return NULL; + } + directory = xbt_new0(s_directory_t, 1); + directory->name = strdup(name); + directory->stream = NULL; + return directory; + } + + int directory_open(directory_t directory) +{ + if (!directory || directory->stream) + return EINVAL; + if (!(directory->stream = opendir(directory->name))) + return errno; + return 0; + } + + int directory_close(directory_t directory) +{ + if (!directory) + return EINVAL; + if (!directory->stream) + return EBADF; + if (closedir(directory->stream)) + return errno; + directory->stream = NULL; + return 0; + } + + int +directory_load(directory_t directory, fstreams_t fstreams, + xbt_dynar_t suffixes) +{ + struct dirent *entry = { 0 }; + s_fstream_t sfstream = { + 0}; + char *suffix; + unsigned int i; + int has_valid_suffix; + int is_empty = 1; + int rv; + if (!directory || !fstreams) + return EINVAL; + if (!directory->stream) + return EBADF; + sfstream.directory = strdup(directory->name); + while ((entry = readdir(directory->stream))) + { + has_valid_suffix = 0; + xbt_dynar_foreach(suffixes, i, suffix) { + if (!strncmp + (suffix, + entry->d_name + (strlen(entry->d_name) - strlen(suffix)), + strlen(suffix))) + { + has_valid_suffix = 1; + break; + } + } + if (!has_valid_suffix) + continue; + sfstream.name = strdup(entry->d_name); + + /* check first if the file stream is already in the file streams to run */ + if (fstreams_contains(fstreams, &sfstream)) + { + WARN1("file %s already registred", entry->d_name); + free(sfstream.name); + continue; + } + + /* add the fstream to the list of file streams to run */ + if ((rv = + fstreams_add(fstreams, + fstream_new(directory->name, entry->d_name)))) + { + free(sfstream.directory); + free(sfstream.name); + return rv; + } + is_empty = 0; + free(sfstream.name); + } + if (is_empty) + WARN1("no tesh file found in the directory %s", directory->name); + free(sfstream.directory); + return 0; + } + + int directory_free(void **directoryptr) +{ + directory_t directory; + if (!(*directoryptr)) + return EINVAL; + directory = *((directory_t *) directoryptr); + if (directory->stream) + if (directory_close(directory)) + return errno; + if (directory->name) + free(directory->name); + free(*directoryptr); + *directoryptr = NULL; + return 0; + } + + const char * directory_get_name(directory_t directory) +{ + if (!directory) + { + errno = EINVAL; + return NULL; + } + return (const char *) directory->name; + } diff --git a/tools/tesh2/src/excludes.c b/tools/tesh2/src/excludes.c index ddfe0e1d8c..d5897460b7 100644 --- a/tools/tesh2/src/excludes.c +++ b/tools/tesh2/src/excludes.c @@ -1,114 +1,89 @@ #include #include + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + excludes_t excludes_new(void) +{ + excludes_t excludes = xbt_new0(s_excludes_t, 1); + excludes->items = + xbt_dynar_new(sizeof(fstream_t), (void_f_pvoid_t) fstream_free); + return excludes; + } + + int excludes_is_empty(excludes_t excludes) +{ + if (!excludes) + { + errno = EINVAL; + return 0; + } + return (0 == xbt_dynar_length(excludes->items)); + } + + int excludes_contains(excludes_t excludes, fstream_t fstream) +{ + fstream_t cur; + unsigned int i; + if (!excludes || !fstream) + { + errno = EINVAL; + return 0; + } + xbt_dynar_foreach(excludes->items, i, cur) { + if (!strcmp(fstream->name, cur->name) + && !strcmp(fstream->directory, cur->directory)) + return 1; + } + return 0; + } + + int excludes_add(excludes_t excludes, fstream_t fstream) +{ + if (!excludes) + return EINVAL; + if (excludes_contains(excludes, fstream)) + return EEXIST; + xbt_dynar_push(excludes->items, &fstream); + return 0; + } + + int excludes_check(excludes_t excludes, fstreams_t fstreams) +{ + fstream_t exclude; + fstream_t fstream; + int success = 1; + int exists; + unsigned int i; + if (!excludes || !fstreams) + return EINVAL; + xbt_dynar_foreach(excludes->items, i, exclude) { + exists = 1; + xbt_dynar_foreach(fstreams->items, i, fstream) { + exists = 0; + if (!strcmp(fstream->name, exclude->name) + && !strcmp(fstream->directory, exclude->directory)) + { + exists = 1; + break; + } + } + if (!exists) + { + success = 0; + WARN1("cannot exclude the file %s", exclude->name); + } + } + return success; + } + + int excludes_free(void **excludesptr) +{ + if (!(*excludesptr)) + return EINVAL; + if ((*((excludes_t *) excludesptr))->items) + xbt_dynar_free((&(*((excludes_t *) excludesptr))->items)); + free(*excludesptr); + *excludesptr = NULL; + return 0; + } + -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - -excludes_t -excludes_new(void) -{ - excludes_t excludes = xbt_new0(s_excludes_t, 1); - - excludes->items = xbt_dynar_new(sizeof(fstream_t), (void_f_pvoid_t)fstream_free); - - return excludes; -} - -int -excludes_is_empty(excludes_t excludes) -{ - if(!excludes) - { - errno = EINVAL; - return 0; - } - - return (0 == xbt_dynar_length(excludes->items)); -} - -int -excludes_contains(excludes_t excludes, fstream_t fstream) -{ - fstream_t cur; - unsigned int i; - - if(!excludes || !fstream) - { - errno = EINVAL; - return 0; - } - - xbt_dynar_foreach(excludes->items, i, cur) - { - if(!strcmp(fstream->name, cur->name) && !strcmp(fstream->directory, cur->directory)) - return 1; - } - - return 0; -} - -int -excludes_add(excludes_t excludes, fstream_t fstream) -{ - if(!excludes) - return EINVAL; - - if(excludes_contains(excludes, fstream)) - return EEXIST; - - xbt_dynar_push(excludes->items, &fstream); - - return 0; -} - -int -excludes_check(excludes_t excludes, fstreams_t fstreams) -{ - fstream_t exclude; - fstream_t fstream; - int success = 1; - int exists; - unsigned int i; - - if(!excludes || !fstreams) - return EINVAL; - - - xbt_dynar_foreach(excludes->items, i, exclude) - { - exists = 1; - - xbt_dynar_foreach(fstreams->items, i, fstream) - { - exists = 0; - - if(!strcmp(fstream->name, exclude->name) && !strcmp(fstream->directory, exclude->directory)) - { - exists = 1; - break; - } - } - - if(!exists) - { - success = 0; - WARN1("cannot exclude the file %s",exclude->name); - } - } - - return success; -} - -int -excludes_free(void** excludesptr) -{ - if(!(*excludesptr)) - return EINVAL; - - if((*((excludes_t*)excludesptr))->items) - xbt_dynar_free((&(*((excludes_t*)excludesptr))->items)); - - free(*excludesptr); - *excludesptr = NULL; - - return 0; -} diff --git a/tools/tesh2/src/explode.c b/tools/tesh2/src/explode.c index fd4a49e99d..63b79932ca 100644 --- a/tools/tesh2/src/explode.c +++ b/tools/tesh2/src/explode.c @@ -1,45 +1,37 @@ #include - -char** -explode(char separator, const char *string) -{ - int pos = 0; - int i, len = 1; - int number = 2; - char **table; - const char* p = string; - - for (i = 0; p[i] != '\0'; i++) - if (p[i] == separator) - number++; - - - table = (char**)calloc(number, sizeof(char*)); - - i = 0; + char ** explode(char separator, const char *string) +{ + int pos = 0; + int i, len = 1; + int number = 2; + char **table; + const char *p = string; + for (i = 0; p[i] != '\0'; i++) + if (p[i] == separator) + number++; + table = (char **) calloc(number, sizeof(char *)); + i = 0; + while (*p++ != '\0') + { + if (*p == separator) + { + table[i] = (char *) calloc(len + 1, sizeof(char)); + strncpy(table[i], string + pos, len); + pos += len + 1; + len = 0; + i++; + } - while (*p++ != '\0') - { - if(*p == separator) - { - table[i] = (char*)calloc(len + 1, sizeof(char)); - strncpy(table[i], string + pos , len); - pos += len + 1; - len = 0; - i++; - } - else - len++; - } - - if(len > 1) - { - table[i] = (char*)calloc(len + 1, sizeof(char)); - strncpy(table[i], string + pos , len); - } - - - table[++i] = NULL; - - return table; -} + else + len++; + } + if (len > 1) + { + table[i] = (char *) calloc(len + 1, sizeof(char)); + strncpy(table[i], string + pos, len); + } + table[++i] = NULL; + return table; + } + + diff --git a/tools/tesh2/src/fstream.c b/tools/tesh2/src/fstream.c index f0e39111fd..a0b2dd88ea 100644 --- a/tools/tesh2/src/fstream.c +++ b/tools/tesh2/src/fstream.c @@ -10,8 +10,8 @@ * This file contains all the definitions of the functions related with * the tesh file stream type. * - */ - + */ + #include #include #include @@ -19,2465 +19,2241 @@ #include #include #include - + #include - + #include #include - + #ifndef _XBT_WIN32 #include -#endif - +#endif /* */ + #ifdef _XBT_WIN32 -static int -is_w32_cmd(char* cmd, char** path) -{ - size_t i = 0; - struct stat stat_buff = {0}; - char buff[PATH_MAX + 1] = {0}; - - - - if(!cmd) - { - errno = EINVAL; - return 0; - } - - if(stat(cmd, &stat_buff) || !S_ISREG(stat_buff.st_mode)) - { - if(path) - { - for (i = 0; path[i] != NULL; i++) - { - /* use Cat.exe on Windows */ - if(!strcmp(cmd, "cat")) - cmd[0] = 'C'; - - sprintf(buff,"%s\\%s",path[i], cmd); - - if(!stat(buff, &stat_buff) && S_ISREG(stat_buff.st_mode)) - return 1; - } - } - } - else - return 1; - - - return 0; -} -#endif - - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - - -long fstream_getline(fstream_t fstream, char **buf, size_t *n) { - - return readline(fstream->stream, buf, n); - -} - -static void -failure(unit_t unit) -{ - if(!keep_going_unit_flag) - { - unit_t root = unit->root ? unit->root : unit; - - if(!root->interrupted) - { - /* the unit interrupted (exit for the loop) */ - root->interrupted = 1; - - /* release the unit */ - xbt_os_sem_release(root->sem); - } - - /* if the --keep-going option is not specified */ - if(!keep_going_flag) - { - if(!interrupted) - { - /* request an global interruption by the runner */ - interrupted = 1; - - /* release the runner */ - xbt_os_sem_release(units_sem); - } - } - } -} - -fstream_t -fstream_new(const char* directory, const char* name) -{ - fstream_t fstream; - - if(!name) - { - errno = EINVAL; - return NULL; - } - - if(!directory && !strcmp("stdin", name)) - { - fstream = xbt_new0(s_fstream_t, 1); - fstream->name = strdup("stdin"); - return fstream; - } - else if(!directory) - { - errno = EINVAL; - return NULL; - } - - fstream = xbt_new0(s_fstream_t, 1); - - if(!(fstream->name = strdup(name))) - { - free(fstream); - return NULL; - } - - if(!(fstream->directory = strdup(directory))) - { - free(fstream->name); - free(fstream); - return NULL; - } - - fstream->stream = NULL; - fstream->unit = NULL; - fstream->parsed = 0; - - - return fstream; -} - -int -fstream_open(fstream_t fstream) -{ - char path[PATH_MAX + 1] = {0}; - - /* check the parameter */ - if(!(fstream)) - { - errno = EINVAL; - return -1; - } - - if(!fstream || fstream->stream) - { - errno = EALREADY; - return -1; - } - - if(!strcmp(fstream->name, "stdin")) - { - fstream->stream = stdin; - return 0; - } - - #ifndef _XBT_WIN32 - sprintf(path,"%s/%s",fstream->directory, fstream->name); - #else - sprintf(path,"%s\\%s",fstream->directory, fstream->name); - #endif - - if(!(fstream->stream = fopen(path, "r"))) - { - return -1; - } - - return 0; -} - -int -fstream_close(fstream_t fstream) -{ - /* check the parameter */ - if(!(fstream) || !strcmp(fstream->name, "stdin") ) - { - errno = EINVAL; - return -1; - } - - if(!fstream->stream) - return EBADF; - - if(EOF == fclose(fstream->stream)) - return -1; - - fstream->stream = NULL; - - return 0; -} - -int -fstream_free(fstream_t* ptr) -{ - - /* check the parameter */ - if(!(*ptr)) - { - errno = EINVAL; - return -1; - } +static int is_w32_cmd(char *cmd, char **path) +{ + size_t i = 0; + struct stat stat_buff = { 0 }; + char buff[PATH_MAX + 1] = { 0 }; + if (!cmd) + { + errno = EINVAL; + return 0; + } + if (stat(cmd, &stat_buff) || !S_ISREG(stat_buff.st_mode)) + { + if (path) + { + for (i = 0; path[i] != NULL; i++) + { + + /* use Cat.exe on Windows */ + if (!strcmp(cmd, "cat")) + cmd[0] = 'C'; + sprintf(buff, "%s\\%s", path[i], cmd); + if (!stat(buff, &stat_buff) && S_ISREG(stat_buff.st_mode)) + return 1; + } + } + } + + else + return 1; + return 0; + } + + +#endif /* */ + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + long fstream_getline(fstream_t fstream, char **buf, size_t * n) +{ + return readline(fstream->stream, buf, n); + } + + static void failure(unit_t unit) +{ + if (!keep_going_unit_flag) + { + unit_t root = unit->root ? unit->root : unit; + if (!root->interrupted) + { + + /* the unit interrupted (exit for the loop) */ + root->interrupted = 1; + + /* release the unit */ + xbt_os_sem_release(root->sem); + } + + /* if the --keep-going option is not specified */ + if (!keep_going_flag) + { + if (!interrupted) + { + + /* request an global interruption by the runner */ + interrupted = 1; + + /* release the runner */ + xbt_os_sem_release(units_sem); + } + } + } + } + + fstream_t fstream_new(const char *directory, const char *name) +{ + fstream_t fstream; + if (!name) + { + errno = EINVAL; + return NULL; + } + if (!directory && !strcmp("stdin", name)) + { + fstream = xbt_new0(s_fstream_t, 1); + fstream->name = strdup("stdin"); + return fstream; + } + + else if (!directory) + { + errno = EINVAL; + return NULL; + } + fstream = xbt_new0(s_fstream_t, 1); + if (!(fstream->name = strdup(name))) + { + free(fstream); + return NULL; + } + if (!(fstream->directory = strdup(directory))) + { + free(fstream->name); + free(fstream); + return NULL; + } + fstream->stream = NULL; + fstream->unit = NULL; + fstream->parsed = 0; + return fstream; + } + + int fstream_open(fstream_t fstream) +{ + char path[PATH_MAX + 1] = { 0 }; + + /* check the parameter */ + if (!(fstream)) + { + errno = EINVAL; + return -1; + } + if (!fstream || fstream->stream) + { + errno = EALREADY; + return -1; + } + if (!strcmp(fstream->name, "stdin")) + { + fstream->stream = stdin; + return 0; + } + +#ifndef _XBT_WIN32 + sprintf(path, "%s/%s", fstream->directory, fstream->name); + +#else /* */ + sprintf(path, "%s\\%s", fstream->directory, fstream->name); + +#endif /* */ + if (!(fstream->stream = fopen(path, "r"))) + { + return -1; + } + return 0; + } + + int fstream_close(fstream_t fstream) +{ + + /* check the parameter */ + if (!(fstream) || !strcmp(fstream->name, "stdin")) + { + errno = EINVAL; + return -1; + } + if (!fstream->stream) + return EBADF; + if (EOF == fclose(fstream->stream)) + return -1; + fstream->stream = NULL; + return 0; + } + + int fstream_free(fstream_t * ptr) +{ + + /* check the parameter */ + if (!(*ptr)) + { + errno = EINVAL; + return -1; + } + if (!(*ptr)) + return EINVAL; + if ((*ptr)->stream) + fclose((*ptr)->stream); + if ((*ptr)->name) + free((*ptr)->name); + if ((*ptr)->directory) + free((*ptr)->directory); + free(*ptr); + *ptr = NULL; + return 0; + } + + int fstream_parse(fstream_t fstream, xbt_os_mutex_t mutex) +{ + size_t len; + char *line = NULL; + int line_num = 0; + char file_pos[256]; + xbt_strbuff_t buff; + int buffbegin = 0; + context_t context; + unit_t unit; + + /* Count the line length while checking wheather it's blank */ + int blankline; + int linelen; + + /* Deal with \ at the end of the line, and call handle_line on result */ + int to_be_continued; + + /* check the parameter */ + if (!(fstream) || !mutex) + { + errno = EINVAL; + return -1; + } + buff = xbt_strbuff_new(); + if (!(context = context_new())) + return -1; + unit = fstream->unit; + + /*while(!(unit->root->interrupted) && getline(&line, &len, fstream->stream) != -1) */ + while (!(unit->root->interrupted) + && fstream_getline(fstream, &line, &len) != -1) + { + blankline = 1; + linelen = 0; + to_be_continued = 0; + line_num++; + while (line[linelen] != '\0') + { + if (line[linelen] != ' ' && line[linelen] != '\t' + && line[linelen] != '\n' && line[linelen] != '\r') + blankline = 0; + linelen++; + } + if (blankline) + { + if (!context->command_line + && (context->input->used || context->output->used)) + { + snprintf(file_pos, 256, "%s:%d", fstream->name, line_num); + ERROR1("[%s] Error : no command found in the last chunk of lines", + file_pos); + unit_set_error(fstream->unit, ESYNTAX, 1, file_pos); + failure(unit); + break; + } + + else if (unit->is_running_suite) + { /* it's the end of a suite */ + unit_t * current_suite = + xbt_dynar_get_ptr(unit->suites, + xbt_dynar_length(unit->suites) - 1); + if (!xbt_dynar_length((*current_suite)->includes)) + { + ERROR2("[%s] Malformated suite `(%s)' : include missing", + file_pos, (*current_suite)->description); + unit_set_error(*current_suite, ESYNTAX, 1, file_pos); + failure(unit); + } + unit->is_running_suite = 0; + } + if (context->command_line) + { + +#ifdef _XBT_WIN32 + if (!context->is_not_found) + { + +#endif /* */ + if (fstream_launch_command(fstream, context, mutex) < 0) + break; + +#ifdef _XBT_WIN32 + } + +#endif /* */ + } + continue; + } + if (linelen > 1 && line[linelen - 2] == '\\') + { + if (linelen > 2 && line[linelen - 3] == '\\') + { + + /* Damn. Escaped \ */ + line[linelen - 2] = '\n'; + line[linelen - 1] = '\0'; + } + + else + { + to_be_continued = 1; + line[linelen - 2] = '\0'; + linelen -= 2; + if (!buff->used) + buffbegin = line_num; + } + } + if (buff->used || to_be_continued) + { + xbt_strbuff_append(buff, line); + if (!to_be_continued) + { + snprintf(file_pos, 256, "%s:%d", fstream->name, buffbegin); + fstream_lex_line(fstream, context, mutex, file_pos, buff->data); + xbt_strbuff_empty(buff); + } + } - if(!(*ptr)) - return EINVAL; - - if((*ptr)->stream) - fclose((*ptr)->stream); - - if((*ptr)->name) - free((*ptr)->name); - - if((*ptr)->directory) - free((*ptr)->directory); - - free(*ptr); - - *ptr = NULL; - - return 0; - -} - -int -fstream_parse(fstream_t fstream, xbt_os_mutex_t mutex) -{ - size_t len; - char * line = NULL; - int line_num = 0; - char file_pos[256]; - xbt_strbuff_t buff; - int buffbegin = 0; - context_t context; - unit_t unit; - - /* Count the line length while checking wheather it's blank */ - int blankline; - int linelen; - /* Deal with \ at the end of the line, and call handle_line on result */ - int to_be_continued; - - /* check the parameter */ - if(!(fstream) || !mutex) - { - errno = EINVAL; - return -1; - } + else + { + snprintf(file_pos, 256, "%s:%d", fstream->name, line_num); + fstream_lex_line(fstream, context, mutex, file_pos, line); + } + } + + /* Check that last command of the file ran well */ + if (context->command_line) + { - buff = xbt_strbuff_new(); - - if(!(context = context_new())) - return -1; - - unit = fstream->unit; - - /*while(!(unit->root->interrupted) && getline(&line, &len, fstream->stream) != -1)*/ - while(!(unit->root->interrupted) && fstream_getline(fstream, &line, &len) != -1) - { - - blankline=1; - linelen = 0; - to_be_continued = 0; - - line_num++; - - while(line[linelen] != '\0') - { - if (line[linelen] != ' ' && line[linelen] != '\t' && line[linelen]!='\n' && line[linelen]!='\r') - blankline = 0; - - linelen++; - } - - if(blankline) - { - if(!context->command_line && (context->input->used || context->output->used)) - { - snprintf(file_pos,256,"%s:%d",fstream->name, line_num); - ERROR1("[%s] Error : no command found in the last chunk of lines", file_pos); - - unit_set_error(fstream->unit, ESYNTAX, 1, file_pos); - - failure(unit); - break; - } - else if(unit->is_running_suite) - {/* it's the end of a suite */ - - unit_t* current_suite = xbt_dynar_get_ptr(unit->suites, xbt_dynar_length(unit->suites) - 1); - - if(!xbt_dynar_length((*current_suite)->includes)) - { - ERROR2("[%s] Malformated suite `(%s)' : include missing", file_pos, (*current_suite)->description); - - unit_set_error(*current_suite, ESYNTAX, 1, file_pos); - - failure(unit); - - } - - unit->is_running_suite = 0; - } - - if(context->command_line) - { - #ifdef _XBT_WIN32 - if(!context->is_not_found) - { - #endif - if(fstream_launch_command(fstream, context, mutex) < 0) - break; - - #ifdef _XBT_WIN32 - } - #endif - } - - continue; - } - - if(linelen>1 && line[linelen-2]=='\\') - { - if(linelen>2 && line[linelen-3] == '\\') - { - /* Damn. Escaped \ */ - line[linelen-2] = '\n'; - line[linelen-1] = '\0'; - } - else - { - to_be_continued = 1; - line[linelen-2] = '\0'; - linelen -= 2; - - if (!buff->used) - buffbegin = line_num; - } - } - - if(buff->used || to_be_continued) - { - xbt_strbuff_append(buff,line); - - if (!to_be_continued) - { - snprintf(file_pos,256,"%s:%d",fstream->name, buffbegin); - fstream_lex_line(fstream, context, mutex, file_pos, buff->data); - xbt_strbuff_empty(buff); - } - } - else - { - snprintf(file_pos,256,"%s:%d",fstream->name, line_num); - fstream_lex_line(fstream, context, mutex, file_pos, line); - } - } - - /* Check that last command of the file ran well */ - if(context->command_line) - { - #ifdef _XBT_WIN32 - if(!context->is_not_found) - { - #endif - - if(fstream_launch_command(fstream, context, mutex) < 0) - return -1; - - #ifdef _XBT_WIN32 - } - #endif - } - - /* clear buffers */ - if(line) - free(line); - - xbt_strbuff_free(buff); - - if(context_free(&context) < 0) - return -1; - - return (exit_code || errno) ? -1 : 0; -} - - -void -fstream_lex_line(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char * filepos, char *line) -{ - char* line2; - variable_t variable; - unsigned int i; - char exp[PATH_MAX + 1] = {0}; - unit_t unit = fstream->unit; - xbt_dynar_t variables = unit->runner->variables; - char* p= NULL; - char* end = NULL; - char* val = NULL; - char buff[PATH_MAX + 1] = {0}; - size_t len; - char delimiters[4] = {' ', '\t', '\n', '\0'}; - - int j; - - if(line[0] == '#') - return; - - if(unit->is_running_suite && strncmp(line, "! include", strlen("! include"))) - {/* it's the end of a suite */ - - unit_t* current_suite = xbt_dynar_get_ptr(unit->suites, xbt_dynar_length(unit->suites) - 1); - - if(!xbt_dynar_length((*current_suite)->includes)) - ERROR2("[%s] Malformated suite `(%s)': include missing", filepos, (*current_suite)->description); - else - ERROR2("[%s] Malformated suite `(%s)': blank line missing", filepos, (*current_suite)->description); - - unit_set_error(*current_suite, ESYNTAX, 1, filepos); - - failure(fstream->unit); - } - - context->line = strdup(filepos); - - /* search end */ - xbt_str_rtrim(line + 2,"\n"); - - line2 = strdup(line); - - len = strlen(line2 + 2) + 1; - - /* replace each variable by its value */ - xbt_os_mutex_acquire(unit->mutex); - - - /* replace all existing - ${var} - ${var:=val} - ${var:+val} - ${var:-val} - ${var:?val} - ${#var} - */ - - xbt_dynar_foreach(variables, i, variable) - { - if(!(p = strstr(line2 + 2, "${"))) - break; - - memset(buff, 0, len); - - sprintf(buff,"${%s",variable->name); - - /* FALSE */ - if((p = strstr(line2 + 2, buff))) - { - memset(buff, 0, len); - p--; - j = 0; - - while(*(p++) != '\0') - { - buff[j++] = *p; - - if(*p == '}') - break; - } - - if(buff[j - 1] != '}') - { - xbt_os_mutex_release(unit->mutex); - - - ERROR2("[%s] Syntax error : `%s'.",filepos, p - j); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - if((p = strstr(buff , ":="))) - { - /* ${var:=val} */ - - /* if the value of the variable is empty, update its value by the value*/ - p += 2; - - end = strchr(p, '}'); - - if(!end || (end == p)) - { - xbt_os_mutex_release(unit->mutex); - - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(buff, "${")); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - val = (char*) calloc((size_t)(end - p) + 1, sizeof(char)); - - strncpy(val, p,(end - p)); - - - /* replace the expression by the expression of the value of the variable*/ - sprintf(exp, "${%s:=%s}", variable->name, val); - - if(variable->val) - str_replace_all(&line2, exp, variable->val, NULL); - else - { - str_replace_all(&line2, exp, val, NULL); - - variable->val = strdup(val); - } - - memset(exp, 0, VAR_NAME_MAX + 1); - - if(val) - { - free(val); - val = NULL; - } - - } - else if((p = strstr(buff, ":-"))) - { - /* ${var:-val} */ - - /* if the value of the variable is empty, replace the expression by the value */ - p += 2; - end = strchr(p, '}'); - - if(!end || (end == p)) - { - xbt_os_mutex_release(unit->mutex); - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${")); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - val = (char*) calloc((size_t)(end - p) + 1, sizeof(char)); - - strncpy(val, p,(end - p)); - - sprintf(exp, "${%s:-%s}", variable->name, val); - - str_replace_all(&line2, exp, variable->val ? variable->val : val, NULL); - - - memset(exp, 0, VAR_NAME_MAX + 1); - - if(val) - { - free(val); - val = NULL; - } - - } - else if((p = strstr(buff, ":+"))) - { - /* ${var:+val} */ - - /* if the value of the variable is not empty, replace the expression by the value */ - p += 2; - - end = strchr(p, '}'); - - if(!end || (end == p)) - { - xbt_os_mutex_release(unit->mutex); - - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${")); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - val = (char*) calloc((size_t)(end - p) + 1, sizeof(char)); - - strncpy(val, p,(end - p)); - - sprintf(exp, "${%s:+%s}", variable->name, val); - - if(variable->val) - { - str_replace_all(&line2, exp, val, NULL); - } - else - { - str_replace_all(&line2, exp, NULL , NULL); - variable->val = strdup(val); - } - - memset(exp, 0, VAR_NAME_MAX + 1); - - if(val) - { - free(val); - val = NULL; - } - } - else if((p = strstr(buff, ":?"))) - { - /* ${var:?val} */ - - /* if the value of the variable is not empty, replace the expression by the value */ - p += 2; - end = strchr(p, '}'); - - if(!end || (end == p)) - { - xbt_os_mutex_release(unit->mutex); - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${")); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - val = (char*) calloc((size_t)(end - p) + 1, sizeof(char)); - - strncpy(val, p,(end - p)); - - sprintf(exp, "${%s:?%s}", variable->name, val); - - if(variable->val) - str_replace_all(&line2, exp, variable->val, NULL); - else - { - - xbt_os_mutex_release(unit->mutex); - - ERROR2("[%s] %s.",filepos, val); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - memset(exp, 0, VAR_NAME_MAX + 1); - - if(val) - { - free(val); - val = NULL; - } - } - } - } - - /* replace all existing $var */ - xbt_dynar_foreach(variables, i, variable) - { - if(!strchr(line2 + 2, '$')) - break; - - if(strstr(line2 + 2, variable->name)) - { - - sprintf(exp, "${#%s}", variable->name); - - if(strstr(line2 + 2, exp)) - { - - if(variable->val) - { - char slen[4] = {0}; - sprintf(slen,"%d", (int)strlen(variable->val)); - str_replace_all(&line2, exp, slen, NULL); - } - else - str_replace_all(&line2, exp, "0", NULL); - } - - memset(exp, 0, VAR_NAME_MAX + 1); - - sprintf(exp, "${%s}", variable->name); - - if(strstr(line2 + 2, exp)) - { - if(variable->val) - str_replace_all(&line2, exp, variable->val, NULL); - else - str_replace_all(&line2, exp, NULL, NULL); - } - - memset(exp, 0, VAR_NAME_MAX + 1); - - sprintf(exp, "$%s", variable->name); - - if((p = strstr(line2 + 2, exp))) - { - if((p + strlen(variable->name) + 1)[0] != '\0' && !(isalpha((p + strlen(variable->name) + 1)[0]))) - delimiters[0] = (p + strlen(variable->name) + 1)[0]; - - if(variable->val) - str_replace_all(&line2, exp, variable->val, delimiters); - else - str_replace_all(&line2, exp, NULL, delimiters); - } - - memset(exp, 0, VAR_NAME_MAX + 1); - - } - } - - while((p = strstr(line2 + 2, "${"))) - { - /*if(*(p+1) != '{') - { - j = 0; - p --; - - while(*(p++) != '\0') - { - if(*p != ' ' && *p !='\t') - exp[j++] = *p; - else - break; - - } - - str_replace_all(&line2, exp, NULL, " \t\n\r"); - memset(exp, 0, VAR_NAME_MAX + 1); - }. - else - */ - { - char* begin = NULL; - - j = 0; - p --; - - while(*(p++) != '\0') - { - if((!begin && *p != ' ' && *p !='\t') || begin) - { - /* `:' must be before this caracter, bad substitution : exit loop - || - the current character is already present, bad substitution : exit loop - */ - if( - ( - *(p - 1) != ':' && ( - (*p == '=') || (*p == '-') || (*p == '+') || (*p == '?') - ) - ) - || - ( - begin && ( - (*p == ':') || (*p == '=') || (*p == '-') || (*p == '+') || (*p == '?') - ) - ) - ) - break; - else - exp[j++] = *p; - - if(*p == ':') - { - /* save the begining of the value */ - if((*(p+1) == '=') || (*(p+1) == '-') || (*(p+1) == '+') || (*(p+1) == '?')) - { - begin = p + 2; - exp[j++] = *(p+1); - p++; - continue; - - } - else - /* the current char is `:' but the next is invalid, bad substitution : exit loop */ - break; - } - /* end of the substitution : exit loop */ - else if(*p == '}') - break; - } - else - break; - } - - if(exp[j - 1] == '}') - { - if(exp[2] == '#') - { - /* ${#var} */ - - - if(4 == strlen(exp)) - { - xbt_os_mutex_release(unit->mutex); - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$')); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - str_replace_all(&line2, exp, "0", NULL); - } - else if(strstr(exp,":=")) - { - /* ${var:=value} */ - - end = strchr(p, '}'); - - if(!end || (end == begin)) - { - xbt_os_mutex_release(unit->mutex); - - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$')); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - variable = xbt_new0(s_variable_t, 1); - - variable->val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char)); - - strncpy(variable->val, begin ,(end - begin)); - - begin = exp + 2; - end = strchr(exp, ':'); - - if(!end || (end == begin)) - { - xbt_os_mutex_release(unit->mutex); - - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$')); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - variable->name = (char*) calloc((size_t)(end - begin) + 1, sizeof(char)); - - strncpy(variable->name, exp + 2 ,(end - begin)); - - str_replace_all(&line2, exp, variable->val, NULL); - - xbt_dynar_push(variables, &variable); - - } - else if(strstr(exp,":-")) - { - /* ${var:-value} */ - - - end = strchr(p, '}'); - - if(!end || (end == begin)) - { - xbt_os_mutex_release(unit->mutex); - - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$')); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char)); - - strncpy(val, begin ,(end - begin)); - - str_replace_all(&line2, exp, val, NULL); - - if(val) - free(val); - - } - else if(strstr(exp,":+")) - { - /* ${var:+value} */ - - end = strchr(p, '}'); - - if(!end || (end == begin)) - { - xbt_os_mutex_release(unit->mutex); - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$')); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - str_replace_all(&line2, exp, NULL, NULL); - } - else if(strstr(exp,":?")) - { - /* ${var:?value} */ - - end = strchr(p, '}'); - - if(!end || (end == begin)) - { - xbt_os_mutex_release(unit->mutex); - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$')); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - val = (char*) calloc((size_t)(end - begin) + 1, sizeof(char)); - - strncpy(val, begin ,(end - begin)); - - xbt_os_mutex_release(unit->mutex); - - ERROR2("[%s] : `%s'.",filepos, val); - - if(val) - free(val); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - - return; - - } - else - { - /* ${var} */ - - if(3 == strlen(exp)) - { - xbt_os_mutex_release(unit->mutex); - - ERROR2("[%s] Bad substitution : `%s'.",filepos, strchr(line2 + 2, '$')); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - str_replace_all(&line2, exp, NULL, NULL); - - } - - memset(exp, 0, VAR_NAME_MAX + 1); - } - else - { - xbt_os_mutex_release(unit->mutex); - - if(strstr(line2 + 2, "${")) - ERROR2("[%s] Bad substitution : `%s'.",filepos, strstr(line2, "${")); - else - ERROR2("[%s] Syntax error : `%s'.",filepos, strstr(line2, "${")); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(fstream->unit); - return; - } - - } - - } - - while(1) - { - p = line2 + (line2[0] =='<' ? 4 : 2); - - if((p = strchr(p, '$'))) - { - if(*(p+1) != ' ') - { - j = 0; - p --; - - while(*(p++) != '\0') - { - if(*p != ' ' && *p !='\t') - exp[j++] = *p; - else - break; - - } - - str_replace_all(&line2, exp, NULL, " \t\n\r"); - memset(exp, 0, VAR_NAME_MAX + 1); - } - else - { - /* maybe < $ cmd */ - p++; - } - } - else - break; - } - - xbt_os_mutex_release(unit->mutex); - - switch(line2[0]) - { - /*case '#': - break; - */ - - case '$': - case '&': - - if(line[1] != ' ') - { - - if(line2[0] == '$') - ERROR1("[%s] Missing space after `$' `(usage : $ )'", filepos); - else - ERROR1("[%s] Missing space after & `(usage : & )'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - context->async = (line2[0] == '&'); - - - /* further trim useless chars which are significant for in/output */ - xbt_str_rtrim(line2 + 2," \t"); - - /* deal with CD commands here, not in context */ - if(!strncmp("cd ",line2 + 2, 3)) - { - char* dir = strdup(line2 + 4); - - if(context->command_line) - { - if(fstream_launch_command(fstream, context, mutex) < 0) - return; - } - - /* search begining */ - while(*(dir++) == ' '); - - dir--; - - if(!dry_run_flag) - { - if(!silent_flag) - INFO2("[%s] cd %s", filepos, dir); - - if(!just_print_flag) - { - if(chdir(dir)) - { - ERROR3("[%s] Chdir to %s failed: %s",filepos, dir,error_to_string(errno, 0)); - unit_set_error(fstream->unit, errno, 0, filepos); - - failure(unit); - } - } - } - - break; - } - else - { - fstream_process_token(fstream, context, mutex, filepos, line2[0], line2 + 2); - break; - } - - case '<': - case '>': - case '!': - - if(line[0] == '!' && line[1] != ' ') - { - ERROR1("[%s] Missing space after `!' `(usage : ! [[=]value])'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - fstream_process_token(fstream, context, mutex, filepos, line2[0], line2 + 2); - break; - - case 'p': - - { - unsigned int j; - int is_blank = 1; - - char* prompt = line2 + 2; - - for(j = 0; j < strlen(prompt); j++) - { - if (prompt[j] != ' ' && prompt[j] != '\t') - { - is_blank = 0; - break; - } - } - - if(is_blank) - { - ERROR1("[%s] Bad usage of the metacommand p `(usage : p )'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - if(!dry_run_flag) - INFO2("[%s] %s",filepos,prompt); - } - - - break; - - case 'P': - - { - unsigned int j; - int is_blank = 1; - - char* prompt = line2 + 2; - - for(j = 0; j < strlen(prompt); j++) - if (prompt[j] != ' ' && prompt[j] != '\t') - is_blank = 0; - - if(is_blank) - { - ERROR1("[%s] Bad usage of the metacommand P `(usage : P )'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - if(!dry_run_flag) - CRITICAL2("[%s] %s",filepos, prompt); - } - - break; - - case 'D': - if(unit->description) - WARN2("[%s] Description already specified `%s'",filepos, line2 + 2); - else - { - unsigned int j; - int is_blank = 1; - - char* desc = line2 + 2; - - for(j = 0; j < strlen(desc); j++) - if (desc[j] != ' ' && desc[j] != '\t') - is_blank = 0; - - if(is_blank) - { - ERROR1("[%s] Bad usage of the metacommand D `(usage : D )'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - unit->description = strdup(desc); - } - break; - - default: - ERROR2("[%s] Syntax error `%s'", filepos, line2); - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(unit); - break; - } - - free(line2); -} - -void -fstream_process_token(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char* filepos, char token, char *line) -{ - unit_t unit = fstream->unit; - - switch (token) - { - case '$': - case '&': - - if(context->command_line) - { - - if(context->output->used || context->input->used) - { - ERROR2("[%s] More than one command in this chunk of lines (previous: %s).\nDunno which input/output belongs to which command.",filepos, context->command_line); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(unit); - return; - } - - if(fstream_launch_command(fstream, context, mutex) < 0) - return; - - VERB1("[%s] More than one command in this chunk of lines",filepos); - } - - { - size_t j, - is_blank = 1; - - for(j = 0; j < strlen(line); j++) - if (line[j] != ' ' && line[j] != '\t') - is_blank = 0; - - if(is_blank) - { - if(token == '$') - ERROR1("[%s] Undefinite command for `$' `(usage: $ )'", filepos); - else - ERROR1("[%s] Undefinite command for `&' `(usage: & )'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - } - - context->command_line = strdup(line); - - xbt_str_ltrim(context->command_line," "); - - context->line = /*strdup(filepos)*/ filepos; - context->pos = strdup(filepos); - - #ifdef _XBT_WIN32 - { - - /* translate the command line */ - - char* path = NULL; - char* delimiter; - char command_line[PATH_MAX + 1] = {0}; - size_t i = 0; - char* args = NULL; - - - - /*if(strstr(context->command_line,".exe")) - strcpy(command_line,context->command_line);*/ - - { - size_t len; - - size_t j = 0; - - len = strlen(context->command_line); - - while(i < len) - { - if(context->command_line[i] != ' ' && context->command_line[i] != '\t' && context->command_line[i] != '>') - command_line[j++] = context->command_line[i]; - else - break; - - i++; - } - - if(!strstr(context->command_line,".exe")) - strcat(command_line,".exe"); - - args = strdup(context->command_line + i); - } - - if(!is_w32_cmd(command_line, fstream->unit->runner->path) && getpath(command_line, &path) < 0) - { - command_t command; - - ERROR3("[%s] `%s' : NOK (%s)", filepos, command_line, error_to_string(ECMDNOTFOUND, 1)); - unit_set_error(fstream->unit, ECMDNOTFOUND, 1, filepos); - - context->is_not_found = 1; - - command = command_new(fstream->unit, context, mutex); - - command->status = cs_failed; - command->reason = csr_command_not_found; - - failure(unit); - - - return; - } - - delimiter = strrchr(command_line,'/'); - - if(!delimiter) - delimiter = strrchr(command_line,'\\'); - - /*free(context->command_line);*/ - - - if(path) - { - if(args) - { - context->t_command_line = (char*)calloc(strlen(path) + strlen(delimiter ? delimiter + 1 : command_line) + strlen(args) + 2, sizeof(char)); - sprintf(context->t_command_line,"%s\\%s%s",path,delimiter ? delimiter + 1 : command_line, args); - - free(args); - - } - else - { - context->t_command_line = (char*)calloc(strlen(path) + strlen(delimiter ? delimiter + 1 : command_line) + 2, sizeof(char)); - sprintf(context->t_command_line,"%s\\%s",path,delimiter ? delimiter + 1 : command_line); - } - - free(path); - } - else - { - if(args) - { - - context->t_command_line = (char*)calloc(strlen(command_line) + strlen(args) + 1, sizeof(char)); - sprintf(context->t_command_line,"%s%s",command_line, args); - - - free(args); - - } - else - { - context->t_command_line = (char*)calloc(strlen(command_line) + 1, sizeof(char)); - strcpy(context->t_command_line,command_line); - } - } - - - } - #endif - - - break; - - case '<': - xbt_strbuff_append(context->input,line); - xbt_strbuff_append(context->input,"\n"); - break; - - case '>': - xbt_strbuff_append(context->output,line); - xbt_strbuff_append(context->output,"\n"); - break; - - case '!': - - if(context->command_line) - { - if(fstream_launch_command(fstream, context, mutex) < 0) - return; - } - - if(!strncmp(line,"timeout no",strlen("timeout no"))) - { - VERB1("[%s] (disable timeout)", filepos); - context->timeout = INDEFINITE; - } - else if(!strncmp(line,"timeout ",strlen("timeout "))) - { - int i = 0; - unsigned int j; - int is_blank = 1; - char* p = line + strlen("timeout "); - - - for(j = 0; j < strlen(p); j++) - if (p[j] != ' ' && p[j] != '\t') - is_blank = 0; - - if(is_blank) - { - ERROR1("[%s] Undefinite timeout value `(usage :timeout )'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - while(p[i] != '\0') - { - if(!isdigit(p[i])) - { - ERROR2("[%s] Invalid timeout value `(%s)' : `(usage :timeout )'", filepos, line + strlen("timeout ")); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - i++; - } - - context->timeout = atoi(line + strlen("timeout")); - VERB2("[%s] (new timeout value: %d)",filepos,context->timeout); - - } - else if (!strncmp(line,"expect signal ",strlen("expect signal "))) - { - unsigned int j; - int is_blank = 1; - - - char* p = line + strlen("expect signal "); - - - for(j = 0; j < strlen(p); j++) - if (p[j] != ' ' && p[j] != '\t') - is_blank = 0; - - if(is_blank) - { - ERROR1("[%s] Undefinite signal name `(usage :expect signal )'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - context->signal = strdup(line + strlen("expect signal ")); - - xbt_str_trim(context->signal," \n"); - - #ifdef _XBT_WIN32 - if(!strstr("SIGSEGVSIGTRAPSIGBUSSIGFPESIGILL", context->signal)) - { - ERROR2("[%s] Signal `%s' not supported by this platform", filepos, context->signal); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - - failure(unit); - return; - } - #else - if(!sig_exists(context->signal)) - { - ERROR2("[%s] Signal `%s' not supported by Tesh", filepos, context->signal); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - - failure(unit); - return; - } - - #endif - - - VERB2("[%s] (next command must raise signal %s)", filepos, context->signal); - - } - else if (!strncmp(line,"expect return ",strlen("expect return "))) - { - - int i = 0; - unsigned int j; - int is_blank = 1; - char* p = line + strlen("expect return "); - - - for(j = 0; j < strlen(p); j++) - if (p[j] != ' ' && p[j] != '\t') - is_blank = 0; - - if(is_blank) - { - ERROR1("[%s] Undefinite return value `(usage :expect return )'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - while(p[i] != '\0') - { - if(!isdigit(p[i])) - { - ERROR2("[%s] Invalid exit code value `(%s)' : must be an integer >= 0 and <=255", filepos, line + strlen("expect return ")); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - i++; - } - - context->exit_code = atoi(line+strlen("expect return ")); - VERB2("[%s] (next command must return code %d)",filepos, context->exit_code); - - } - else if (!strncmp(line,"output ignore",strlen("output ignore"))) - { - context->output_handling = oh_ignore; - VERB1("[%s] (ignore output of next command)", filepos); - - } - else if (!strncmp(line,"output display",strlen("output display"))) - { - context->output_handling = oh_display; - VERB1("[%s] (ignore output of next command)", filepos); - - } - else if(!strncmp(line,"include ", strlen("include "))) - { - char* p1; - char* p2; - - p1 = line + strlen("include"); - - while(*p1 == ' ' || *p1 == '\t') - p1++; - - - if(p1[0] == '\0') - { - ERROR1("[%s] no file specified : `(usage : include [])'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - else - { - char file_name[PATH_MAX + 1] = {0}; - - p2 = p1; - - while(*p2 != '\0' && *p2 != ' ' && *p2 != '\t') - p2++; - - strncpy(file_name, p1, p2 - p1); - - - if(p2[0] != '\0') - while(*p2 == ' ' || *p2 == '\t') - p2++; - - fstream_handle_include(fstream, context, mutex, file_name, p2[0] != '\0' ? p2 : NULL); - - } - } - else if(!strncmp(line,"suite ", strlen("suite "))) - { - unsigned int j; - int is_blank = 1; - char* p = line + strlen("suite "); - - - for(j = 0; j < strlen(p); j++) - if (p[j] != ' ' && p[j] != '\t') - is_blank = 0; - - if(is_blank) - { - ERROR1("[%s] Undefinite suit description : `(usage : suite )", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - if(unit->is_running_suite) - { - ERROR1("[%s] Suite already in progress", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - fstream_handle_suite(fstream, line + strlen("suite "), filepos); - } - else if(!strncmp(line,"unsetenv ", strlen("unsetenv "))) - { - unsigned int i, j; - int exists = 0; - int env = 0; - int err = 0; - variable_t variable; - int is_blank; - - char* name = line + strlen("unsetenv "); - - is_blank = 1; - - for(j = 0; j < strlen(name); j++) - if (name[j] != ' ' && name[j] != '\t') - is_blank = 0; - - if(is_blank) - { - ERROR1("[%s] Bad usage of the metacommand unsetenv : `(usage : unsetenv variable)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - xbt_os_mutex_acquire(unit->mutex); - - - xbt_dynar_foreach(unit->runner->variables, i, variable) - { - if(!strcmp(variable->name, name)) - { - env = variable->env; - err = variable->err; - exists = 1; - break; - } - } - - if(env) - { - if(exists) - { - #ifndef _XBT_WIN32 - unsetenv(name); - #else - SetEnvironmentVariable(name, NULL); - #endif - xbt_dynar_cursor_rm(unit->runner->variables, &i); - } - else - { - ERROR2("[%s] `(%s)' environment variable not found : impossible to unset it",filepos, name); - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - failure(unit); - return; - } - } - else - { - if(exists) - { - if(!err) - { - ERROR2("[%s] `(%s)' is not an environment variable : use `unset' instead `unsetenv'",filepos, name); - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(unit); - xbt_os_mutex_release(unit->mutex); - return; - } - else - { - ERROR2("[%s] `(%s)' is not an environment variable (it's a system variable) : impossible to unset it",filepos, name); - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - failure(unit); - return; - } - } - else - { - ERROR2("[%s] `(%s)' environment variable not found : impossible to unset it",filepos, name); - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - failure(unit); - return; - } - } - - xbt_os_mutex_release(unit->mutex); - - - } - else if(!strncmp(line,"setenv ", strlen("setenv "))) - { - char* val; - char name[PATH_MAX + 1] = {0}; - char* p; - unsigned int i; - int is_blank; - unsigned int j; - - p = line + strlen("setenv "); - - val = strchr(p, '='); - - if(val) - { - variable_t variable; - int exists = 0; - int env = 0; - int err = 0; - val++; - - /* syntax error */ - if(val[0] == '\0' || val[0] ==' ' || val[0] =='\t') - { - ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - - - strncpy(name, p, (val - p -1)); - - is_blank = 1; - - for(j = 0; j < strlen(name); j++) - if (name[j] != ' ' && name[j] != '\t') - is_blank = 0; - - if(is_blank) - { - - ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - /* test if the variable is already registred */ - xbt_os_mutex_acquire(unit->mutex); - - xbt_dynar_foreach(unit->runner->variables, i, variable) - { - if(!strcmp(variable->name, name)) - { - env = variable->env; - err = variable->err; - exists = 1; - break; - } - } - - /* if the variable is already registred, update its value; - * otherwise register it. - */ - if(exists) - { - if(env) - { - if(!strcmp(val, variable->val)) - WARN3("[%s] This environment variable `(%s)' is already set with the value `(%s)'", filepos, name, val); - - free(variable->val); - variable->val = strdup(val); - - #ifdef _XBT_WIN32 - SetEnvironmentVariable(variable->name, variable->val); - #else - setenv(variable->name, variable->val, 1); - #endif - } - else - { - if(err) - ERROR2("[%s] Conflict : a system variable `(%s)' already exists", filepos, name); - else - ERROR2("[%s] Conflict : (none environment) variable `(%s)' already exists", filepos, name); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - failure(unit); - return; - } - } - else - { - if(err) - { - ERROR2("[%s] A system variable named `(%s)' already exists", filepos, name); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - failure(unit); - return; - } - else - { - variable = variable_new(name, val); - variable->env = 1; - - xbt_dynar_push(unit->runner->variables, &variable); - - #ifdef _XBT_WIN32 - SetEnvironmentVariable(variable->name, variable->val); - #else - setenv(variable->name, variable->val, 0); - #endif - } - } - - xbt_os_mutex_release(unit->mutex); - - } - else - { - ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(unit); - return; - } - } - else if(!strncmp(line,"unset ", strlen("unset "))) - { - unsigned int i, j; - int exists = 0; - int env = 0; - int err = 0; - variable_t variable; - int is_blank; - - char* name = line + strlen("unset "); - - is_blank = 1; - - for(j = 0; j < strlen(name); j++) - if (name[j] != ' ' && name[j] != '\t') - is_blank = 0; - - if(is_blank) - { - - ERROR1("[%s] Bad usage of the metacommand unset `(usage : unset variable)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - - xbt_os_mutex_acquire(unit->mutex); - - xbt_dynar_foreach(unit->runner->variables, i, variable) - { - if(!strcmp(variable->name, name)) - { - env = variable->env; - err = variable->err; - exists = 1; - break; - } - } - - if(!env && !err) - { - if(exists) - { - /*xbt_dynar_remove_at(unit->runner->variables, i, NULL);*/ - /*xbt_dynar_cursor_rm(unit->runner->variables, &i);*/ - if(variable->val) - { - free(variable->val); - variable->val = NULL; - } - else - { - WARN2("[%s] Variable `(%s)' already unseted",filepos, variable->name); - } - } - else - { - ERROR2("[%s] `(%s)' variable not found",filepos, name); - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - failure(unit); - return; - } - } - else if(env) - { - ERROR2("[%s] `(%s)' is an environment variable use `unsetenv' instead `unset'",filepos, name); - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - failure(unit); - return; - } - else if(err) - { - ERROR2("[%s] `(%s)' is system variable : you can unset it",filepos, name); - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - failure(unit); - return; - } - - xbt_os_mutex_release(unit->mutex); - - } - else if(!strncmp(line,"set ", strlen("set "))) - { - char* val; - char name[PATH_MAX + 1] = {0}; - unsigned int j; - int is_blank; - - val = strchr(line + strlen("set "), '='); - - if(val) - { - variable_t variable; - int exists = 0; - unsigned int i; - int err; - int env; - - val++; - - - /* syntax error */ - if(val[0] == '\0') - { - ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - else if(val[0] ==' ' || val[0] =='\t') - { - strncpy(name, line + strlen("set "), (val - (line + strlen("set ")))); - - ERROR2("[%s] No space avaible after`(%s)'", filepos, name); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - - /* assume it's a varibale */ - - strncpy(name, line + strlen("set "), (val - (line + strlen("set ")) -1)); - - is_blank = 1; - - for(j = 0; j < strlen(name); j++) - if (name[j] != ' ' && name[j] != '\t') - is_blank = 0; - - if(is_blank) - { - - ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - xbt_os_mutex_acquire(unit->mutex); - - /* test if the variable is already registred */ - xbt_dynar_foreach(unit->runner->variables, i, variable) - { - if(!strcmp(variable->name, name)) - { - exists = 1; - err = variable->err; - env = variable->env; - break; - } - } - - /* if the variable is already registred, update its value (if same value warns); - * otherwise register it. - */ - if(exists) - { - if(err) - { - ERROR2("[%s] A system variable named `(%s)' already exists", filepos, name); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - - failure(unit); - return; - } - if(env) - { - ERROR2("[%s] `(%s)' is an environment variable use `setenv' instead `set'", filepos, name); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - - failure(unit); - return; - } - else - { - if(!strcmp(val, variable->val)) - WARN3("[%s] Variable `(%s)' already contains value `<%s>'",filepos, variable->name, val); - - free(variable->val); - variable->val = strdup(val); - } - } - else - { - variable_t new_var = variable_new(name, val); - xbt_dynar_push(unit->runner->variables, &new_var); - } - - - xbt_os_mutex_release(unit->mutex); - } - else - { - ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(unit); - return; - } - } - else - {/* assume it's a variable */ - char* val; - char name[PATH_MAX + 1] = {0}; - unsigned int i, j; - int is_blank; - - val = strchr(line, '='); - - if(val) - { - variable_t variable; - int exists = 0; - int err; - int env; - val++; - - - /* syntax error */ - if(val[0] == '\0') - { - strncpy(name, line, (val - line -1)); - - is_blank = 1; - - for(j = 0; j < strlen(name); j++) - if (name[j] != ' ' && name[j] != '\t') - is_blank = 0; - - if(is_blank) - ERROR1("[%s] Bad usage of Tesh variable mechanism `(usage : variable=value)'", filepos); - else if(!strcmp("setenv", name)) - ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos); - else if(!strcmp("set", name)) - ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos); - else - ERROR2("[%s] Undefined variable `(%s)'", filepos, name); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - else if(val[0] ==' ' || val[0] =='\t') - { - strncpy(name, line, (val - line)); - - ERROR2("[%s] No space avaible after`(%s)'", filepos, name); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - } - - - /* assume it's a varibale */ - - strncpy(name, line, (val - line -1)); - - is_blank = 1; - - for(j = 0; j < strlen(name); j++) - if (name[j] != ' ' && name[j] != '\t') - is_blank = 0; - - if(is_blank) - { - - ERROR1("[%s] Bad usage of Tesh variable capability `(usage : variable=value)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - - if(!strcmp("set", name)) - { - ERROR1("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(unit); - return; - } - else if(!strcmp("setenv", name)) - { - ERROR1("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", filepos); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - failure(unit); - return; - } - - xbt_os_mutex_acquire(unit->mutex); - - /* test if the variable is already registred */ - xbt_dynar_foreach(unit->runner->variables, i, variable) - { - if(!strcmp(variable->name, name)) - { - exists = 1; - err = variable->err; - env = variable->env; - break; - } - } - - /* if the variable is already registred, update its value (if same value warns); - * otherwise register it. - */ - if(exists) - { - if(err) - { - ERROR2("[%s] A system variable named `(%s)' already exists", filepos, name); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - failure(unit); - return; - } - if(env) - { - ERROR2("[%s] `(%s)' is an environment variable use `setenv' metacommand", filepos, name); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - xbt_os_mutex_release(unit->mutex); - - failure(unit); - return; - } - else - { - if(!strcmp(val, variable->val)) - WARN3("[%s] Variable `(%s)' already contains value `<%s>'",filepos, variable->name, val); - - free(variable->val); - variable->val = strdup(val); - } - } - else - { - variable_t new_var = variable_new(name, val); - xbt_dynar_push(unit->runner->variables, &new_var); - } - - - xbt_os_mutex_release(unit->mutex); - - } - else - { - if(!strncmp("setenv", line, strlen("setenv"))) - ERROR1("[%s] Bad usage of the metacommand setenv : `(usage : setenv variable=value)'", filepos); - else if(!strncmp("set", line, strlen("set"))) - ERROR1("[%s] Bad usage of the metacommand set : `(usage : set variable=value)'", filepos); - else if(!strncmp("unsetenv", line, strlen("unsetenv"))) - ERROR1("[%s] Bad usage of the metacommand unsetenv : `(usage : unsetenv variable)'", filepos); - else if(!strncmp("unset", line, strlen("unset"))) - ERROR1("[%s] Bad usage of the metacommand unset : `(usage : unset variable)'", filepos); - else if(!strncmp("timeout", line, strlen("timeout"))) - ERROR1("[%s] Bad usage of the metacommand timeout : `(usage : timeout )'", filepos); - else if(!strncmp("expect signal", line, strlen("expect signal"))) - ERROR1("[%s] Bad usage of the metacommand expect signal : `(usage : expect signal )'", filepos); - else if(!strncmp("expect return", line, strlen("expect return"))) - ERROR1("[%s] Bad usage of the metacommand expect return : `(usage : expect return =0 <=255)>)'", filepos); - else if(!strncmp("include", line, strlen("include"))) - ERROR1("[%s] Bad usage of the metacommand include :`(usage : include [])'", filepos); - else if(!strncmp("suite", line, strlen("suite"))) - ERROR1("[%s] Bad usage of the metacommand suite : `(usage : suite )'", filepos); - else - ERROR2("[%s] Unknown metacommand: `%s'",filepos,line); - - unit_set_error(fstream->unit, ESYNTAX, 1, filepos); - - failure(unit); - return; - } - } - - break; - } -} - -void -fstream_handle_include(fstream_t fstream, context_t context, xbt_os_mutex_t mutex, const char* file_name, const char* description) -{ - directory_t dir; - char* prev_directory = NULL; - fstream_t _fstream = NULL; - struct stat buffer = {0}; - unit_t unit = fstream->unit; - - if(!stat(file_name, &buffer) && S_ISREG(buffer.st_mode)) - { - /* the file is in the current directory */ - _fstream = fstream_new(getcwd(NULL, 0), file_name); - fstream_open(_fstream); - } - /* the file to include is not in the current directory, check if it is in a include directory */ - else - { - unsigned int i; - prev_directory = getcwd(NULL, 0); - - xbt_dynar_foreach(include_dirs, i, dir) - { - chdir(dir->name); - - if(!stat(file_name, &buffer) && S_ISREG(buffer.st_mode)) - { - _fstream = fstream_new(dir->name, file_name); - fstream_open(_fstream); - break; - } - } - - chdir(prev_directory); - free(prev_directory); - } - - /* the file to include is not found handle the failure */ - if(!_fstream) - { - if(file_name[0] == '$') - { - ERROR3("[%s] Include file `(%s)' not found or variable `(%s)' doesn't exist",context->line, file_name, file_name + 1); - - } - else - { - /* may be a variable */ - variable_t variable; - int exists = 0; - unsigned int i; - - xbt_dynar_foreach(unit->runner->variables, i, variable) - { - if(!strcmp(variable->name, file_name)) - { - exists = 1; - break; - } - } - - if(exists) - ERROR3("[%s] Include file `(%s)' not found (if you want to use the variable <%s> add the prefix `$')",context->line, file_name, file_name); - else - ERROR2("[%s] Include file `(%s)' not found",context->line, file_name); - } - - unit_set_error(fstream->unit, EINCLUDENOTFOUND, 1, context->line); - - failure(fstream->unit); - - return; - } - else - { - if(!unit->is_running_suite) - {/* it's the unit of a suite */ - unit_t include = unit_new(unit->runner, unit->root, unit, _fstream); - - include->mutex = unit->root->mutex; - - if(description) - include->description = strdup(description); - - xbt_dynar_push(unit->includes, &include); - - if(!dry_run_flag) - { - if(description) - INFO2("Include from %s (%s)", _fstream->name, description); - else - INFO1("Include from %s", _fstream->name); - - } - else - INFO1("Checking include %s...",_fstream->name); - - fstream_parse(_fstream, mutex); - } - else - {/* it's a include */ - - unit_t* owner; - unit_t include; - - owner = xbt_dynar_get_ptr(unit->suites, xbt_dynar_length(unit->suites) - 1); - - include = unit_new(unit->runner, unit->root, *owner, _fstream); - - include->mutex = unit->root->mutex; - - if(description) - include->description = strdup(description); - - xbt_dynar_push((*owner)->includes, &include); - - if(!dry_run_flag) - { - if(description) - INFO2("Include from %s (%s)", _fstream->name, description); - else - INFO1("Include from %s", _fstream->name); - } - else - INFO1("Checking include %s...",_fstream->name); - - fstream_parse(_fstream, mutex); - } - } -} - -void -fstream_handle_suite(fstream_t fstream, const char* description, const char* filepos) -{ - unit_t unit = fstream->unit; - unit_t suite = unit_new(unit->runner, unit->root, unit, NULL); - - if(description) - suite->description = strdup(description); - - suite->filepos = strdup(filepos); - - xbt_dynar_push(unit->suites, &suite); - unit->is_running_suite = 1; - - if(!dry_run_flag) - INFO1("Test suite %s", description); - else - INFO1("Checking suite %s...",description); - -} - -int -fstream_launch_command(fstream_t fstream, context_t context, xbt_os_mutex_t mutex) -{ - unit_t unit = fstream->unit; - - if(!dry_run_flag) - { - command_t command; - - if(!(command = command_new(unit, context, mutex))) - { - if(EINVAL == errno) - { - ERROR3("[%s] Cannot instantiate the command `%s' (%d)",context->pos, strerror(errno), errno); - - unit_set_error(unit, errno, 0, context->pos); - failure(unit); - return -1; - } - else if(ENOMEM == errno) - { - ERROR3("[%s] Cannot instantiate the command `%s' (%d)",context->pos, strerror(errno), errno); - - unit_set_error(unit, errno, 0, context->pos); - - failure(unit); - return -1; - } - } - - if(command_run(command) < 0) - { - ERROR3("[%s] Cannot run the command `%s' (%d)",context->pos, strerror(errno), errno); - unit_set_error(unit, errno, 0, context->pos); - failure(unit); - return -1; - } - } - - if(context_reset(context) < 0) - { - ERROR3("[%s] Cannot reset the context of the command `%s' (%d)",context->pos, strerror(errno), errno); - - unit_set_error(fstream->unit, errno, 0, context->pos); - - failure(unit); - return -1; - } - - return 0; -} - - - - +#ifdef _XBT_WIN32 + if (!context->is_not_found) + { + +#endif /* */ + if (fstream_launch_command(fstream, context, mutex) < 0) + return -1; + +#ifdef _XBT_WIN32 + } + +#endif /* */ + } + + /* clear buffers */ + if (line) + free(line); + xbt_strbuff_free(buff); + if (context_free(&context) < 0) + return -1; + return (exit_code || errno) ? -1 : 0; + } + + void +fstream_lex_line(fstream_t fstream, context_t context, + xbt_os_mutex_t mutex, const char *filepos, char *line) +{ + char *line2; + variable_t variable; + unsigned int i; + char exp[PATH_MAX + 1] = { 0 }; + unit_t unit = fstream->unit; + xbt_dynar_t variables = unit->runner->variables; + char *p = NULL; + char *end = NULL; + char *val = NULL; + char buff[PATH_MAX + 1] = { 0 }; + size_t len; + char delimiters[4] = { ' ', '\t', '\n', '\0' }; + int j; + if (line[0] == '#') + return; + if (unit->is_running_suite + && strncmp(line, "! include", strlen("! include"))) + { /* it's the end of a suite */ + unit_t * current_suite = + xbt_dynar_get_ptr(unit->suites, + xbt_dynar_length(unit->suites) - 1); + if (!xbt_dynar_length((*current_suite)->includes)) + ERROR2("[%s] Malformated suite `(%s)': include missing", filepos, + (*current_suite)->description); + + else + ERROR2("[%s] Malformated suite `(%s)': blank line missing", filepos, + (*current_suite)->description); + unit_set_error(*current_suite, ESYNTAX, 1, filepos); + failure(fstream->unit); + } + context->line = strdup(filepos); + + /* search end */ + xbt_str_rtrim(line + 2, "\n"); + line2 = strdup(line); + len = strlen(line2 + 2) + 1; + + /* replace each variable by its value */ + xbt_os_mutex_acquire(unit->mutex); + + /* replace all existing + ${var} + ${var:=val} + ${var:+val} + ${var:-val} + ${var:?val} + ${#var} + */ + xbt_dynar_foreach(variables, i, variable) { + if (!(p = strstr(line2 + 2, "${"))) + break; + memset(buff, 0, len); + sprintf(buff, "${%s", variable->name); + + /* FALSE */ + if ((p = strstr(line2 + 2, buff))) + { + memset(buff, 0, len); + p--; + j = 0; + while (*(p++) != '\0') + { + buff[j++] = *p; + if (*p == '}') + break; + } + if (buff[j - 1] != '}') + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Syntax error : `%s'.", filepos, p - j); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + if ((p = strstr(buff, ":="))) + { + + /* ${var:=val} */ + + /* if the value of the variable is empty, update its value by the value */ + p += 2; + end = strchr(p, '}'); + if (!end || (end == p)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strstr(buff, "${")); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + val = (char *) calloc((size_t) (end - p) + 1, sizeof(char)); + strncpy(val, p, (end - p)); + + /* replace the expression by the expression of the value of the variable */ + sprintf(exp, "${%s:=%s}", variable->name, val); + if (variable->val) + str_replace_all(&line2, exp, variable->val, NULL); + + else + { + str_replace_all(&line2, exp, val, NULL); + variable->val = strdup(val); + } + memset(exp, 0, VAR_NAME_MAX + 1); + if (val) + { + free(val); + val = NULL; + } + } + + else if ((p = strstr(buff, ":-"))) + { + + /* ${var:-val} */ + + /* if the value of the variable is empty, replace the expression by the value */ + p += 2; + end = strchr(p, '}'); + if (!end || (end == p)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strstr(line2, "${")); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + val = (char *) calloc((size_t) (end - p) + 1, sizeof(char)); + strncpy(val, p, (end - p)); + sprintf(exp, "${%s:-%s}", variable->name, val); + str_replace_all(&line2, exp, variable->val ? variable->val : val, + NULL); + memset(exp, 0, VAR_NAME_MAX + 1); + if (val) + { + free(val); + val = NULL; + } + } + + else if ((p = strstr(buff, ":+"))) + { + + /* ${var:+val} */ + + /* if the value of the variable is not empty, replace the expression by the value */ + p += 2; + end = strchr(p, '}'); + if (!end || (end == p)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strstr(line2, "${")); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + val = (char *) calloc((size_t) (end - p) + 1, sizeof(char)); + strncpy(val, p, (end - p)); + sprintf(exp, "${%s:+%s}", variable->name, val); + if (variable->val) + { + str_replace_all(&line2, exp, val, NULL); + } + + else + { + str_replace_all(&line2, exp, NULL, NULL); + variable->val = strdup(val); + } + memset(exp, 0, VAR_NAME_MAX + 1); + if (val) + { + free(val); + val = NULL; + } + } + + else if ((p = strstr(buff, ":?"))) + { + + /* ${var:?val} */ + + /* if the value of the variable is not empty, replace the expression by the value */ + p += 2; + end = strchr(p, '}'); + if (!end || (end == p)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strstr(line2, "${")); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + val = (char *) calloc((size_t) (end - p) + 1, sizeof(char)); + strncpy(val, p, (end - p)); + sprintf(exp, "${%s:?%s}", variable->name, val); + if (variable->val) + str_replace_all(&line2, exp, variable->val, NULL); + + else + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] %s.", filepos, val); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + memset(exp, 0, VAR_NAME_MAX + 1); + if (val) + { + free(val); + val = NULL; + } + } + } + } + + /* replace all existing $var */ + xbt_dynar_foreach(variables, i, variable) { + if (!strchr(line2 + 2, '$')) + break; + if (strstr(line2 + 2, variable->name)) + { + sprintf(exp, "${#%s}", variable->name); + if (strstr(line2 + 2, exp)) + { + if (variable->val) + { + char slen[4] = { 0 }; + sprintf(slen, "%d", (int) strlen(variable->val)); + str_replace_all(&line2, exp, slen, NULL); + } + + else + str_replace_all(&line2, exp, "0", NULL); + } + memset(exp, 0, VAR_NAME_MAX + 1); + sprintf(exp, "${%s}", variable->name); + if (strstr(line2 + 2, exp)) + { + if (variable->val) + str_replace_all(&line2, exp, variable->val, NULL); + + else + str_replace_all(&line2, exp, NULL, NULL); + } + memset(exp, 0, VAR_NAME_MAX + 1); + sprintf(exp, "$%s", variable->name); + if ((p = strstr(line2 + 2, exp))) + { + if ((p + strlen(variable->name) + 1)[0] != '\0' + && !(isalpha((p + strlen(variable->name) + 1)[0]))) + delimiters[0] = (p + strlen(variable->name) + 1)[0]; + if (variable->val) + str_replace_all(&line2, exp, variable->val, delimiters); + + else + str_replace_all(&line2, exp, NULL, delimiters); + } + memset(exp, 0, VAR_NAME_MAX + 1); + } + } + while ((p = strstr(line2 + 2, "${"))) + { + + /*if(*(p+1) != '{') + { + j = 0; + p --; + + while(*(p++) != '\0') + { + if(*p != ' ' && *p !='\t') + exp[j++] = *p; + else + break; + + } + + str_replace_all(&line2, exp, NULL, " \t\n\r"); + memset(exp, 0, VAR_NAME_MAX + 1); + }. + else + */ + { + char *begin = NULL; + j = 0; + p--; + while (*(p++) != '\0') + { + if ((!begin && *p != ' ' && *p != '\t') || begin) + { + + /* `:' must be before this caracter, bad substitution : exit loop + || + the current character is already present, bad substitution : exit loop + */ + if ( + ( *(p - 1) != ':' && ( + (*p == '=') || (*p == '-') + || (*p == '+') + || (*p == '?') ) ) || ( begin + && + ( + (*p == + ':') + || (*p + == + '=') + || (*p + == + '-') + || (*p + == + '+') + || (*p + == + '?') + ) ) + ) + break; + + else + exp[j++] = *p; + if (*p == ':') + { + + /* save the begining of the value */ + if ((*(p + 1) == '=') || (*(p + 1) == '-') + || (*(p + 1) == '+') || (*(p + 1) == '?')) + { + begin = p + 2; + exp[j++] = *(p + 1); + p++; + continue; + } + + else + + /* the current char is `:' but the next is invalid, bad substitution : exit loop */ + break; + } + + /* end of the substitution : exit loop */ + else if (*p == '}') + break; + } + + else + break; + } + if (exp[j - 1] == '}') + { + if (exp[2] == '#') + { + + /* ${#var} */ + if (4 == strlen(exp)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strchr(line2 + 2, '$')); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + str_replace_all(&line2, exp, "0", NULL); + } + + else if (strstr(exp, ":=")) + { + + /* ${var:=value} */ + end = strchr(p, '}'); + if (!end || (end == begin)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strchr(line2 + 2, '$')); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + variable = xbt_new0(s_variable_t, 1); + variable->val = + (char *) calloc((size_t) (end - begin) + 1, sizeof(char)); + strncpy(variable->val, begin, (end - begin)); + begin = exp + 2; + end = strchr(exp, ':'); + if (!end || (end == begin)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strchr(line2 + 2, '$')); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + variable->name = + (char *) calloc((size_t) (end - begin) + 1, sizeof(char)); + strncpy(variable->name, exp + 2, (end - begin)); + str_replace_all(&line2, exp, variable->val, NULL); + xbt_dynar_push(variables, &variable); + } + + else if (strstr(exp, ":-")) + { + + /* ${var:-value} */ + end = strchr(p, '}'); + if (!end || (end == begin)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strchr(line2 + 2, '$')); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + val = + (char *) calloc((size_t) (end - begin) + 1, sizeof(char)); + strncpy(val, begin, (end - begin)); + str_replace_all(&line2, exp, val, NULL); + if (val) + free(val); + } + + else if (strstr(exp, ":+")) + { + + /* ${var:+value} */ + end = strchr(p, '}'); + if (!end || (end == begin)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strchr(line2 + 2, '$')); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + str_replace_all(&line2, exp, NULL, NULL); + } + + else if (strstr(exp, ":?")) + { + + /* ${var:?value} */ + end = strchr(p, '}'); + if (!end || (end == begin)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strchr(line2 + 2, '$')); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + val = + (char *) calloc((size_t) (end - begin) + 1, sizeof(char)); + strncpy(val, begin, (end - begin)); + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] : `%s'.", filepos, val); + if (val) + free(val); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + + else + { + + /* ${var} */ + if (3 == strlen(exp)) + { + xbt_os_mutex_release(unit->mutex); + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strchr(line2 + 2, '$')); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + str_replace_all(&line2, exp, NULL, NULL); + } + memset(exp, 0, VAR_NAME_MAX + 1); + } + + else + { + xbt_os_mutex_release(unit->mutex); + if (strstr(line2 + 2, "${")) + ERROR2("[%s] Bad substitution : `%s'.", filepos, + strstr(line2, "${")); + + else + ERROR2("[%s] Syntax error : `%s'.", filepos, + strstr(line2, "${")); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(fstream->unit); + return; + } + } + } + while (1) + { + p = line2 + (line2[0] == '<' ? 4 : 2); + if ((p = strchr(p, '$'))) + { + if (*(p + 1) != ' ') + { + j = 0; + p--; + while (*(p++) != '\0') + { + if (*p != ' ' && *p != '\t') + exp[j++] = *p; + + else + break; + } + str_replace_all(&line2, exp, NULL, " \t\n\r"); + memset(exp, 0, VAR_NAME_MAX + 1); + } + + else + { + + /* maybe < $ cmd */ + p++; + } + } + + else + break; + } + xbt_os_mutex_release(unit->mutex); + switch (line2[0]) + { + + /*case '#': + break; + */ + case '$': + case '&': + if (line[1] != ' ') + { + if (line2[0] == '$') + ERROR1("[%s] Missing space after `$' `(usage : $ )'", + filepos); + + else + ERROR1("[%s] Missing space after & `(usage : & )'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + context->async = (line2[0] == '&'); + + /* further trim useless chars which are significant for in/output */ + xbt_str_rtrim(line2 + 2, " \t"); + + /* deal with CD commands here, not in context */ + if (!strncmp("cd ", line2 + 2, 3)) + { + char *dir = strdup(line2 + 4); + if (context->command_line) + { + if (fstream_launch_command(fstream, context, mutex) < 0) + return; + } + + /* search begining */ + while (*(dir++) == ' '); + dir--; + if (!dry_run_flag) + { + if (!silent_flag) + INFO2("[%s] cd %s", filepos, dir); + if (!just_print_flag) + { + if (chdir(dir)) + { + ERROR3("[%s] Chdir to %s failed: %s", filepos, dir, + error_to_string(errno, 0)); + unit_set_error(fstream->unit, errno, 0, filepos); + failure(unit); + } + } + } + break; + } + + else + { + fstream_process_token(fstream, context, mutex, filepos, line2[0], + line2 + 2); + break; + } + case '<': + case '>': + case '!': + if (line[0] == '!' && line[1] != ' ') + { + ERROR1 + ("[%s] Missing space after `!' `(usage : ! [[=]value])'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + fstream_process_token(fstream, context, mutex, filepos, line2[0], + line2 + 2); + break; + case 'p': + { + unsigned int j; + int is_blank = 1; + char *prompt = line2 + 2; + for (j = 0; j < strlen(prompt); j++) + { + if (prompt[j] != ' ' && prompt[j] != '\t') + { + is_blank = 0; + break; + } + } + if (is_blank) + { + ERROR1 + ("[%s] Bad usage of the metacommand p `(usage : p )'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + if (!dry_run_flag) + INFO2("[%s] %s", filepos, prompt); + } + break; + case 'P': + { + unsigned int j; + int is_blank = 1; + char *prompt = line2 + 2; + for (j = 0; j < strlen(prompt); j++) + if (prompt[j] != ' ' && prompt[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Bad usage of the metacommand P `(usage : P )'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + if (!dry_run_flag) + CRITICAL2("[%s] %s", filepos, prompt); + } + break; + case 'D': + if (unit->description) + WARN2("[%s] Description already specified `%s'", filepos, + line2 + 2); + + else + { + unsigned int j; + int is_blank = 1; + char *desc = line2 + 2; + for (j = 0; j < strlen(desc); j++) + if (desc[j] != ' ' && desc[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Bad usage of the metacommand D `(usage : D )'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + unit->description = strdup(desc); + } + break; + default: + ERROR2("[%s] Syntax error `%s'", filepos, line2); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + break; + } + free(line2); + } + + void +fstream_process_token(fstream_t fstream, context_t context, + xbt_os_mutex_t mutex, const char *filepos, + char token, char *line) +{ + unit_t unit = fstream->unit; + switch (token) + { + case '$': + case '&': + if (context->command_line) + { + if (context->output->used || context->input->used) + { + ERROR2 + ("[%s] More than one command in this chunk of lines (previous: %s).\nDunno which input/output belongs to which command.", + filepos, context->command_line); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + if (fstream_launch_command(fstream, context, mutex) < 0) + return; + VERB1("[%s] More than one command in this chunk of lines", + filepos); + } + { + size_t j, is_blank = 1; + for (j = 0; j < strlen(line); j++) + if (line[j] != ' ' && line[j] != '\t') + is_blank = 0; + if (is_blank) + { + if (token == '$') + ERROR1("[%s] Undefinite command for `$' `(usage: $ )'", + filepos); + + else + ERROR1("[%s] Undefinite command for `&' `(usage: & )'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + } + context->command_line = strdup(line); + xbt_str_ltrim(context->command_line, " "); + context->line = /*strdup(filepos) */ filepos; + context->pos = strdup(filepos); + +#ifdef _XBT_WIN32 + { + + /* translate the command line */ + char *path = NULL; + char *delimiter; + char command_line[PATH_MAX + 1] = { 0 }; + size_t i = 0; + char *args = NULL; + + /*if(strstr(context->command_line,".exe")) + strcpy(command_line,context->command_line); */ + { + size_t len; + size_t j = 0; + len = strlen(context->command_line); + while (i < len) + { + if (context->command_line[i] != ' ' + && context->command_line[i] != '\t' + && context->command_line[i] != '>') + command_line[j++] = context->command_line[i]; + + else + break; + i++; + } + if (!strstr(context->command_line, ".exe")) + strcat(command_line, ".exe"); + args = strdup(context->command_line + i); + } + if (!is_w32_cmd(command_line, fstream->unit->runner->path) + && getpath(command_line, &path) < 0) + { + command_t command; + ERROR3("[%s] `%s' : NOK (%s)", filepos, command_line, + error_to_string(ECMDNOTFOUND, 1)); + unit_set_error(fstream->unit, ECMDNOTFOUND, 1, filepos); + context->is_not_found = 1; + command = command_new(fstream->unit, context, mutex); + command->status = cs_failed; + command->reason = csr_command_not_found; + failure(unit); + return; + } + delimiter = strrchr(command_line, '/'); + if (!delimiter) + delimiter = strrchr(command_line, '\\'); + + /*free(context->command_line); */ + if (path) + { + if (args) + { + context->t_command_line = + (char *) calloc(strlen(path) + + strlen(delimiter ? delimiter + + 1 : command_line) + strlen(args) + 2, + sizeof(char)); + sprintf(context->t_command_line, "%s\\%s%s", path, + delimiter ? delimiter + 1 : command_line, args); + free(args); + } + + else + { + context->t_command_line = + (char *) calloc(strlen(path) + + strlen(delimiter ? delimiter + + 1 : command_line) + 2, sizeof(char)); + sprintf(context->t_command_line, "%s\\%s", path, + delimiter ? delimiter + 1 : command_line); + } free(path); + } + + else + { + if (args) + { + context->t_command_line = + (char *) calloc(strlen(command_line) + strlen(args) + 1, + sizeof(char)); + sprintf(context->t_command_line, "%s%s", command_line, args); + free(args); + } + + else + { + context->t_command_line = + (char *) calloc(strlen(command_line) + 1, sizeof(char)); + strcpy(context->t_command_line, command_line); + } } } +#endif /* */ + break; + case '<': + xbt_strbuff_append(context->input, line); + xbt_strbuff_append(context->input, "\n"); + break; + case '>': + xbt_strbuff_append(context->output, line); + xbt_strbuff_append(context->output, "\n"); + break; + case '!': + if (context->command_line) + { + if (fstream_launch_command(fstream, context, mutex) < 0) + return; + } + if (!strncmp(line, "timeout no", strlen("timeout no"))) + { + VERB1("[%s] (disable timeout)", filepos); + context->timeout = INDEFINITE; + } + + else if (!strncmp(line, "timeout ", strlen("timeout "))) + { + int i = 0; + unsigned int j; + int is_blank = 1; + char *p = line + strlen("timeout "); + for (j = 0; j < strlen(p); j++) + if (p[j] != ' ' && p[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Undefinite timeout value `(usage :timeout )'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + while (p[i] != '\0') + { + if (!isdigit(p[i])) + { + ERROR2 + ("[%s] Invalid timeout value `(%s)' : `(usage :timeout )'", + filepos, line + strlen("timeout ")); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + i++; + } + context->timeout = atoi(line + strlen("timeout")); + VERB2("[%s] (new timeout value: %d)", filepos, context->timeout); + } + + else if (!strncmp(line, "expect signal ", strlen("expect signal "))) + { + unsigned int j; + int is_blank = 1; + char *p = line + strlen("expect signal "); + for (j = 0; j < strlen(p); j++) + if (p[j] != ' ' && p[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Undefinite signal name `(usage :expect signal )'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + context->signal = strdup(line + strlen("expect signal ")); + xbt_str_trim(context->signal, " \n"); + +#ifdef _XBT_WIN32 + if (!strstr("SIGSEGVSIGTRAPSIGBUSSIGFPESIGILL", context->signal)) + { + ERROR2("[%s] Signal `%s' not supported by this platform", filepos, + context->signal); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + +#else /* */ + if (!sig_exists(context->signal)) + { + ERROR2("[%s] Signal `%s' not supported by Tesh", filepos, + context->signal); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + +#endif /* */ + VERB2("[%s] (next command must raise signal %s)", filepos, + context->signal); + } + + else if (!strncmp(line, "expect return ", strlen("expect return "))) + { + int i = 0; + unsigned int j; + int is_blank = 1; + char *p = line + strlen("expect return "); + for (j = 0; j < strlen(p); j++) + if (p[j] != ' ' && p[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Undefinite return value `(usage :expect return )'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + while (p[i] != '\0') + { + if (!isdigit(p[i])) + { + ERROR2 + ("[%s] Invalid exit code value `(%s)' : must be an integer >= 0 and <=255", + filepos, line + strlen("expect return ")); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + i++; + } + context->exit_code = atoi(line + strlen("expect return ")); + VERB2("[%s] (next command must return code %d)", filepos, + context->exit_code); + } + + else if (!strncmp(line, "output ignore", strlen("output ignore"))) + { + context->output_handling = oh_ignore; + VERB1("[%s] (ignore output of next command)", filepos); + } + + else if (!strncmp(line, "output display", strlen("output display"))) + { + context->output_handling = oh_display; + VERB1("[%s] (ignore output of next command)", filepos); + } + + else if (!strncmp(line, "include ", strlen("include "))) + { + char *p1; + char *p2; + p1 = line + strlen("include"); + while (*p1 == ' ' || *p1 == '\t') + p1++; + if (p1[0] == '\0') + { + ERROR1 + ("[%s] no file specified : `(usage : include [])'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + + else + { + char file_name[PATH_MAX + 1] = { 0 }; + p2 = p1; + while (*p2 != '\0' && *p2 != ' ' && *p2 != '\t') + p2++; + strncpy(file_name, p1, p2 - p1); + if (p2[0] != '\0') + while (*p2 == ' ' || *p2 == '\t') + p2++; + fstream_handle_include(fstream, context, mutex, file_name, + p2[0] != '\0' ? p2 : NULL); + } + } + + else if (!strncmp(line, "suite ", strlen("suite "))) + { + unsigned int j; + int is_blank = 1; + char *p = line + strlen("suite "); + for (j = 0; j < strlen(p); j++) + if (p[j] != ' ' && p[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Undefinite suit description : `(usage : suite )", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + if (unit->is_running_suite) + { + ERROR1("[%s] Suite already in progress", filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + fstream_handle_suite(fstream, line + strlen("suite "), filepos); + } + + else if (!strncmp(line, "unsetenv ", strlen("unsetenv "))) + { + unsigned int i, j; + int exists = 0; + int env = 0; + int err = 0; + variable_t variable; + int is_blank; + char *name = line + strlen("unsetenv "); + is_blank = 1; + for (j = 0; j < strlen(name); j++) + if (name[j] != ' ' && name[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Bad usage of the metacommand unsetenv : `(usage : unsetenv variable)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + xbt_os_mutex_acquire(unit->mutex); + xbt_dynar_foreach(unit->runner->variables, i, variable) { + if (!strcmp(variable->name, name)) + { + env = variable->env; + err = variable->err; + exists = 1; + break; + } + } + if (env) + { + if (exists) + { + +#ifndef _XBT_WIN32 + unsetenv(name); + +#else /* */ + SetEnvironmentVariable(name, NULL); + +#endif /* */ + xbt_dynar_cursor_rm(unit->runner->variables, &i); + } + + else + { + ERROR2 + ("[%s] `(%s)' environment variable not found : impossible to unset it", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + } + + else + { + if (exists) + { + if (!err) + { + ERROR2 + ("[%s] `(%s)' is not an environment variable : use `unset' instead `unsetenv'", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + xbt_os_mutex_release(unit->mutex); + return; + } + + else + { + ERROR2 + ("[%s] `(%s)' is not an environment variable (it's a system variable) : impossible to unset it", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + } + + else + { + ERROR2 + ("[%s] `(%s)' environment variable not found : impossible to unset it", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + } + xbt_os_mutex_release(unit->mutex); + } + + else if (!strncmp(line, "setenv ", strlen("setenv "))) + { + char *val; + char name[PATH_MAX + 1] = { 0 }; + char *p; + unsigned int i; + int is_blank; + unsigned int j; + p = line + strlen("setenv "); + val = strchr(p, '='); + if (val) + { + variable_t variable; + int exists = 0; + int env = 0; + int err = 0; + val++; + + /* syntax error */ + if (val[0] == '\0' || val[0] == ' ' || val[0] == '\t') + { + ERROR1 + ("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + strncpy(name, p, (val - p - 1)); + is_blank = 1; + for (j = 0; j < strlen(name); j++) + if (name[j] != ' ' && name[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + + /* test if the variable is already registred */ + xbt_os_mutex_acquire(unit->mutex); + xbt_dynar_foreach(unit->runner->variables, i, variable) { + if (!strcmp(variable->name, name)) + { + env = variable->env; + err = variable->err; + exists = 1; + break; + } + } + + /* if the variable is already registred, update its value; + * otherwise register it. + */ + if (exists) + { + if (env) + { + if (!strcmp(val, variable->val)) + WARN3 + ("[%s] This environment variable `(%s)' is already set with the value `(%s)'", + filepos, name, val); + free(variable->val); + variable->val = strdup(val); + +#ifdef _XBT_WIN32 + SetEnvironmentVariable(variable->name, variable->val); + +#else /* */ + setenv(variable->name, variable->val, 1); + +#endif /* */ + } + + else + { + if (err) + ERROR2 + ("[%s] Conflict : a system variable `(%s)' already exists", + filepos, name); + + else + ERROR2 + ("[%s] Conflict : (none environment) variable `(%s)' already exists", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + } + + else + { + if (err) + { + ERROR2("[%s] A system variable named `(%s)' already exists", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + + else + { + variable = variable_new(name, val); + variable->env = 1; + xbt_dynar_push(unit->runner->variables, &variable); + +#ifdef _XBT_WIN32 + SetEnvironmentVariable(variable->name, variable->val); + +#else /* */ + setenv(variable->name, variable->val, 0); + +#endif /* */ + } + } + xbt_os_mutex_release(unit->mutex); + } + + else + { + ERROR1 + ("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + } + + else if (!strncmp(line, "unset ", strlen("unset "))) + { + unsigned int i, j; + int exists = 0; + int env = 0; + int err = 0; + variable_t variable; + int is_blank; + char *name = line + strlen("unset "); + is_blank = 1; + for (j = 0; j < strlen(name); j++) + if (name[j] != ' ' && name[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Bad usage of the metacommand unset `(usage : unset variable)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + xbt_os_mutex_acquire(unit->mutex); + xbt_dynar_foreach(unit->runner->variables, i, variable) { + if (!strcmp(variable->name, name)) + { + env = variable->env; + err = variable->err; + exists = 1; + break; + } + } + if (!env && !err) + { + if (exists) + { + + /*xbt_dynar_remove_at(unit->runner->variables, i, NULL); */ + /*xbt_dynar_cursor_rm(unit->runner->variables, &i); */ + if (variable->val) + { + free(variable->val); + variable->val = NULL; + } + + else + { + WARN2("[%s] Variable `(%s)' already unseted", filepos, + variable->name); + } + } + + else + { + ERROR2("[%s] `(%s)' variable not found", filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + } + + else if (env) + { + ERROR2 + ("[%s] `(%s)' is an environment variable use `unsetenv' instead `unset'", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + + else if (err) + { + ERROR2("[%s] `(%s)' is system variable : you can unset it", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + xbt_os_mutex_release(unit->mutex); + } + + else if (!strncmp(line, "set ", strlen("set "))) + { + char *val; + char name[PATH_MAX + 1] = { 0 }; + unsigned int j; + int is_blank; + val = strchr(line + strlen("set "), '='); + if (val) + { + variable_t variable; + int exists = 0; + unsigned int i; + int err; + int env; + val++; + + /* syntax error */ + if (val[0] == '\0') + { + ERROR1 + ("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + + else if (val[0] == ' ' || val[0] == '\t') + { + strncpy(name, line + strlen("set "), + (val - (line + strlen("set ")))); + ERROR2("[%s] No space avaible after`(%s)'", filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + + /* assume it's a varibale */ + strncpy(name, line + strlen("set "), + (val - (line + strlen("set ")) - 1)); + is_blank = 1; + for (j = 0; j < strlen(name); j++) + if (name[j] != ' ' && name[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + xbt_os_mutex_acquire(unit->mutex); + + /* test if the variable is already registred */ + xbt_dynar_foreach(unit->runner->variables, i, variable) { + if (!strcmp(variable->name, name)) + { + exists = 1; + err = variable->err; + env = variable->env; + break; + } + } + + /* if the variable is already registred, update its value (if same value warns); + * otherwise register it. + */ + if (exists) + { + if (err) + { + ERROR2("[%s] A system variable named `(%s)' already exists", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + if (env) + { + ERROR2 + ("[%s] `(%s)' is an environment variable use `setenv' instead `set'", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + + else + { + if (!strcmp(val, variable->val)) + WARN3("[%s] Variable `(%s)' already contains value `<%s>'", + filepos, variable->name, val); + free(variable->val); + variable->val = strdup(val); + } + } + + else + { + variable_t new_var = variable_new(name, val); + xbt_dynar_push(unit->runner->variables, &new_var); + } + xbt_os_mutex_release(unit->mutex); + } + + else + { + ERROR1 + ("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + } + + else + { /* assume it's a variable */ + char *val; + char name[PATH_MAX + 1] = { 0 }; + unsigned int i, j; + int is_blank; + val = strchr(line, '='); + if (val) + { + variable_t variable; + int exists = 0; + int err; + int env; + val++; + + /* syntax error */ + if (val[0] == '\0') + { + strncpy(name, line, (val - line - 1)); + is_blank = 1; + for (j = 0; j < strlen(name); j++) + if (name[j] != ' ' && name[j] != '\t') + is_blank = 0; + if (is_blank) + ERROR1 + ("[%s] Bad usage of Tesh variable mechanism `(usage : variable=value)'", + filepos); + + else if (!strcmp("setenv", name)) + ERROR1 + ("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", + filepos); + + else if (!strcmp("set", name)) + ERROR1 + ("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", + filepos); + + else + ERROR2("[%s] Undefined variable `(%s)'", filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + + else if (val[0] == ' ' || val[0] == '\t') + { + strncpy(name, line, (val - line)); + ERROR2("[%s] No space avaible after`(%s)'", filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + } + + /* assume it's a varibale */ + strncpy(name, line, (val - line - 1)); + is_blank = 1; + for (j = 0; j < strlen(name); j++) + if (name[j] != ' ' && name[j] != '\t') + is_blank = 0; + if (is_blank) + { + ERROR1 + ("[%s] Bad usage of Tesh variable capability `(usage : variable=value)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + if (!strcmp("set", name)) + { + ERROR1 + ("[%s] Bad usage of the metacommand set `(usage : set variable=value)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + + else if (!strcmp("setenv", name)) + { + ERROR1 + ("[%s] Bad usage of the metacommand setenv `(usage : setenv variable=value)'", + filepos); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + xbt_os_mutex_acquire(unit->mutex); + + /* test if the variable is already registred */ + xbt_dynar_foreach(unit->runner->variables, i, variable) { + if (!strcmp(variable->name, name)) + { + exists = 1; + err = variable->err; + env = variable->env; + break; + } + } + + /* if the variable is already registred, update its value (if same value warns); + * otherwise register it. + */ + if (exists) + { + if (err) + { + ERROR2("[%s] A system variable named `(%s)' already exists", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + if (env) + { + ERROR2 + ("[%s] `(%s)' is an environment variable use `setenv' metacommand", + filepos, name); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + xbt_os_mutex_release(unit->mutex); + failure(unit); + return; + } + + else + { + if (!strcmp(val, variable->val)) + WARN3("[%s] Variable `(%s)' already contains value `<%s>'", + filepos, variable->name, val); + free(variable->val); + variable->val = strdup(val); + } + } + + else + { + variable_t new_var = variable_new(name, val); + xbt_dynar_push(unit->runner->variables, &new_var); + } + xbt_os_mutex_release(unit->mutex); + } + + else + { + if (!strncmp("setenv", line, strlen("setenv"))) + ERROR1 + ("[%s] Bad usage of the metacommand setenv : `(usage : setenv variable=value)'", + filepos); + + else if (!strncmp("set", line, strlen("set"))) + ERROR1 + ("[%s] Bad usage of the metacommand set : `(usage : set variable=value)'", + filepos); + + else if (!strncmp("unsetenv", line, strlen("unsetenv"))) + ERROR1 + ("[%s] Bad usage of the metacommand unsetenv : `(usage : unsetenv variable)'", + filepos); + + else if (!strncmp("unset", line, strlen("unset"))) + ERROR1 + ("[%s] Bad usage of the metacommand unset : `(usage : unset variable)'", + filepos); + + else if (!strncmp("timeout", line, strlen("timeout"))) + ERROR1 + ("[%s] Bad usage of the metacommand timeout : `(usage : timeout )'", + filepos); + + else if (!strncmp("expect signal", line, strlen("expect signal"))) + ERROR1 + ("[%s] Bad usage of the metacommand expect signal : `(usage : expect signal )'", + filepos); + + else if (!strncmp("expect return", line, strlen("expect return"))) + ERROR1 + ("[%s] Bad usage of the metacommand expect return : `(usage : expect return =0 <=255)>)'", + filepos); + + else if (!strncmp("include", line, strlen("include"))) + ERROR1 + ("[%s] Bad usage of the metacommand include :`(usage : include [])'", + filepos); + + else if (!strncmp("suite", line, strlen("suite"))) + ERROR1 + ("[%s] Bad usage of the metacommand suite : `(usage : suite )'", + filepos); + + else + ERROR2("[%s] Unknown metacommand: `%s'", filepos, line); + unit_set_error(fstream->unit, ESYNTAX, 1, filepos); + failure(unit); + return; + } + } + break; + } + } + + void +fstream_handle_include(fstream_t fstream, context_t context, + xbt_os_mutex_t mutex, const char *file_name, + const char *description) +{ + directory_t dir; + char *prev_directory = NULL; + fstream_t _fstream = NULL; + struct stat buffer = { 0 }; + unit_t unit = fstream->unit; + if (!stat(file_name, &buffer) && S_ISREG(buffer.st_mode)) + { + + /* the file is in the current directory */ + _fstream = fstream_new(getcwd(NULL, 0), file_name); + fstream_open(_fstream); + } + + /* the file to include is not in the current directory, check if it is in a include directory */ + else + { + unsigned int i; + prev_directory = getcwd(NULL, 0); + xbt_dynar_foreach(include_dirs, i, dir) { + chdir(dir->name); + if (!stat(file_name, &buffer) && S_ISREG(buffer.st_mode)) + { + _fstream = fstream_new(dir->name, file_name); + fstream_open(_fstream); + break; + } + } + chdir(prev_directory); + free(prev_directory); + } + + /* the file to include is not found handle the failure */ + if (!_fstream) + { + if (file_name[0] == '$') + { + ERROR3 + ("[%s] Include file `(%s)' not found or variable `(%s)' doesn't exist", + context->line, file_name, file_name + 1); + } + + else + { + + /* may be a variable */ + variable_t variable; + int exists = 0; + unsigned int i; + xbt_dynar_foreach(unit->runner->variables, i, variable) { + if (!strcmp(variable->name, file_name)) + { + exists = 1; + break; + } + } + if (exists) + ERROR3 + ("[%s] Include file `(%s)' not found (if you want to use the variable <%s> add the prefix `$')", + context->line, file_name, file_name); + + else + ERROR2("[%s] Include file `(%s)' not found", context->line, + file_name); + } + unit_set_error(fstream->unit, EINCLUDENOTFOUND, 1, context->line); + failure(fstream->unit); + return; + } + + else + { + if (!unit->is_running_suite) + { /* it's the unit of a suite */ + unit_t include = unit_new(unit->runner, unit->root, unit, _fstream); + include->mutex = unit->root->mutex; + if (description) + include->description = strdup(description); + xbt_dynar_push(unit->includes, &include); + if (!dry_run_flag) + { + if (description) + INFO2("Include from %s (%s)", _fstream->name, description); + + else + INFO1("Include from %s", _fstream->name); + } + + else + INFO1("Checking include %s...", _fstream->name); + fstream_parse(_fstream, mutex); + } + + else + { /* it's a include */ + unit_t * owner; + unit_t include; + owner = + xbt_dynar_get_ptr(unit->suites, + xbt_dynar_length(unit->suites) - 1); + include = unit_new(unit->runner, unit->root, *owner, _fstream); + include->mutex = unit->root->mutex; + if (description) + include->description = strdup(description); + xbt_dynar_push((*owner)->includes, &include); + if (!dry_run_flag) + { + if (description) + INFO2("Include from %s (%s)", _fstream->name, description); + + else + INFO1("Include from %s", _fstream->name); + } + + else + INFO1("Checking include %s...", _fstream->name); + fstream_parse(_fstream, mutex); + } + } + } + + void +fstream_handle_suite(fstream_t fstream, const char *description, + const char *filepos) +{ + unit_t unit = fstream->unit; + unit_t suite = unit_new(unit->runner, unit->root, unit, NULL); + if (description) + suite->description = strdup(description); + suite->filepos = strdup(filepos); + xbt_dynar_push(unit->suites, &suite); + unit->is_running_suite = 1; + if (!dry_run_flag) + INFO1("Test suite %s", description); + + else + INFO1("Checking suite %s...", description); + } + + int +fstream_launch_command(fstream_t fstream, context_t context, + xbt_os_mutex_t mutex) +{ + unit_t unit = fstream->unit; + if (!dry_run_flag) + { + command_t command; + if (!(command = command_new(unit, context, mutex))) + { + if (EINVAL == errno) + { + ERROR3("[%s] Cannot instantiate the command `%s' (%d)", + context->pos, strerror(errno), errno); + unit_set_error(unit, errno, 0, context->pos); + failure(unit); + return -1; + } + + else if (ENOMEM == errno) + { + ERROR3("[%s] Cannot instantiate the command `%s' (%d)", + context->pos, strerror(errno), errno); + unit_set_error(unit, errno, 0, context->pos); + failure(unit); + return -1; + } + } + if (command_run(command) < 0) + { + ERROR3("[%s] Cannot run the command `%s' (%d)", context->pos, + strerror(errno), errno); + unit_set_error(unit, errno, 0, context->pos); + failure(unit); + return -1; + } + } + if (context_reset(context) < 0) + { + ERROR3("[%s] Cannot reset the context of the command `%s' (%d)", + context->pos, strerror(errno), errno); + unit_set_error(fstream->unit, errno, 0, context->pos); + failure(unit); + return -1; + } + return 0; + } + + diff --git a/tools/tesh2/src/fstreams.c b/tools/tesh2/src/fstreams.c index 5fb75df75d..66336a370d 100644 --- a/tools/tesh2/src/fstreams.c +++ b/tools/tesh2/src/fstreams.c @@ -1,128 +1,100 @@ #include #include #include + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + fstreams_t fstreams_new(void_f_pvoid_t fn_finalize) +{ + fstreams_t fstreams = xbt_new0(s_fstreams_t, 1); + fstreams->items = xbt_dynar_new(sizeof(fstream_t), fn_finalize); + return fstreams; + } + + int fstreams_exclude(fstreams_t fstreams, excludes_t excludes) +{ + fstream_t fstream; + unsigned int i; + if (!fstreams || !excludes) + return EINVAL; + if (excludes_is_empty(excludes)) + return 0; + + /* collecte the file streams to exclude */ + xbt_dynar_foreach(fstreams->items, i, fstream) { + if (excludes_contains(excludes, fstream)) + { + INFO1("excluding %s", fstream->name); + xbt_dynar_cursor_rm(fstreams->items, &i); + } + } + return 0; + } + + int fstreams_contains(fstreams_t fstreams, fstream_t fstream) +{ + fstream_t cur; + unsigned int i; + if (!fstreams || !fstream) + { + errno = EINVAL; + return 0; + } + xbt_dynar_foreach(fstreams->items, i, cur) { + if (!strcmp(cur->name, fstream->name) + && !strcmp(cur->directory, fstream->directory)) + return 1; + } + return 0; + } + + int fstreams_load(fstreams_t fstreams) +{ + fstream_t fstream; + unsigned int i; + if (!fstreams) + return EINVAL; + xbt_dynar_foreach(fstreams->items, i, fstream) { + fstream_open(fstream); + } + return 0; + } + + int fstreams_add(fstreams_t fstreams, fstream_t fstream) +{ + if (!fstreams) + return EINVAL; + xbt_dynar_push(fstreams->items, &fstream); + return 0; + } + + int fstreams_free(void **fstreamsptr) +{ + if (!(*fstreamsptr)) + return EINVAL; + if ((*((fstreams_t *) fstreamsptr))->items) + xbt_dynar_free(&((*((fstreams_t *) fstreamsptr))->items)); + free(*fstreamsptr); + *fstreamsptr = NULL; + return 0; + } + + int fstreams_get_size(fstreams_t fstreams) +{ + if (!fstreams) + { + errno = EINVAL; + return -1; + } + return xbt_dynar_length(fstreams->items); + } + + int fstreams_is_empty(fstreams_t fstreams) +{ + if (!fstreams) + { + errno = EINVAL; + return -1; + } + return (0 == xbt_dynar_length(fstreams->items)); + } + -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - -fstreams_t -fstreams_new(void_f_pvoid_t fn_finalize) -{ - fstreams_t fstreams = xbt_new0(s_fstreams_t, 1); - fstreams->items = xbt_dynar_new(sizeof(fstream_t), fn_finalize); - - return fstreams; -} - -int -fstreams_exclude(fstreams_t fstreams, excludes_t excludes) -{ - fstream_t fstream; - unsigned int i; - - if(!fstreams || !excludes) - return EINVAL; - - if(excludes_is_empty(excludes)) - return 0; - - /* collecte the file streams to exclude */ - xbt_dynar_foreach(fstreams->items, i, fstream) - { - if(excludes_contains(excludes, fstream)) - { - INFO1("excluding %s",fstream->name); - xbt_dynar_cursor_rm(fstreams->items, &i); - } - } - - return 0; -} - -int -fstreams_contains(fstreams_t fstreams, fstream_t fstream) -{ - fstream_t cur; - unsigned int i; - - if(!fstreams || !fstream) - { - errno = EINVAL; - return 0; - } - - xbt_dynar_foreach(fstreams->items, i, cur) - { - if(!strcmp(cur->name, fstream->name) && !strcmp(cur->directory, fstream->directory)) - return 1; - } - - return 0; -} - -int -fstreams_load(fstreams_t fstreams) -{ - fstream_t fstream; - unsigned int i; - - if(!fstreams ) - return EINVAL; - - xbt_dynar_foreach(fstreams->items, i, fstream) - { - fstream_open(fstream); - } - - - return 0; -} - -int -fstreams_add(fstreams_t fstreams, fstream_t fstream) -{ - if(!fstreams) - return EINVAL; - - xbt_dynar_push(fstreams->items, &fstream); - - return 0; -} - -int -fstreams_free(void** fstreamsptr) -{ - if(!(* fstreamsptr)) - return EINVAL; - - if((*((fstreams_t*)fstreamsptr))->items) - xbt_dynar_free(&((*((fstreams_t*)fstreamsptr))->items)); - - free(*fstreamsptr); - - *fstreamsptr = NULL; - return 0; -} - -int -fstreams_get_size(fstreams_t fstreams) -{ - if(!fstreams) - { - errno = EINVAL; - return -1; - } - - return xbt_dynar_length(fstreams->items); -} - -int -fstreams_is_empty(fstreams_t fstreams) -{ - if(!fstreams) - { - errno = EINVAL; - return -1; - } - - return (0 == xbt_dynar_length(fstreams->items)); -} diff --git a/tools/tesh2/src/getpath.c b/tools/tesh2/src/getpath.c index 4f768d7482..d3e9913a39 100644 --- a/tools/tesh2/src/getpath.c +++ b/tools/tesh2/src/getpath.c @@ -1,307 +1,269 @@ #include - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + /*#include #include -*/ - +*/ + #include #include - + #ifndef _XBT_WIN32 #include -#else -#endif - +#else /* */ +#endif /* */ + #include #include - + #ifndef PATH_MAX #define PATH_MAX 255 -#endif - +#endif /* */ + #ifndef _XBT_WIN32 -int -getpath(const char* file, char** path) -{ - char buffer1[PATH_MAX + 1] = {0}; - char buffer2[PATH_MAX + 1] = {0}; - char buffer3[PATH_MAX + 1] = {0}; - char *p1,*p2; - size_t len = strlen(file); - char* last_delimiter = NULL; - struct stat buffer = {0}; - - strncpy(buffer1, file, len); - - /* remove the /////// */ - while((p1 = strstr(buffer1, "//"))) - { - if(p1[2]) - strcpy(p1, p1 + 1); - else - p1[1] = '\0'; - } - - if(*buffer1 == '~') - { - for(p2 = buffer2, p1 = buffer1 + 1; *p1 && (*p1 != '/'); *p2++ = *p1++); - *p2 = '\0'; - - if(buffer2[0] == '\0') - { - char* home = getenv("HOME"); - - if(home) - { - strcpy(buffer2, home); - } - else - { - struct passwd* pw = getpwuid(getuid()); - - if(!pw) - { - *path = NULL; - return -1; - } - - strcpy(buffer2,pw->pw_dir); - } - - strcat(buffer2, p1); - } - - } - else if (buffer1[0] != '/') - { - - getcwd(buffer2, PATH_MAX + 1); - - if(buffer1[0] == '.' && buffer1[1] == '/') - { /* replace */ - strcat(buffer2, &buffer1[1]); - } - else - { - strcat(buffer2, "/"); - strcat(buffer2, buffer1); - } - } - else - { - strcpy(buffer2, buffer1); /* copy */ - } - - /* - * check for /.. - */ - while((p1 = strstr( buffer2, "/.." ))) - { - for( p2 = p1; --p2 > buffer2 && *p2 != '/'; ); - - if (*(p1 + 3)) - memmove(p2, p1+3, strlen(p1+3)+1); - else - *p2 = '\0'; - } - - /* - * try to find links, and resolve them. - */ - p1 = strtok( buffer2, "/" ); - - *buffer3 = '\0'; - - while(p1) - { - strcat( buffer3, "/" ); - strcat( buffer3, p1 ); - - len = readlink(buffer3, buffer1, PATH_MAX); - - if (len != -1) - { - *(buffer1 + len) = '\0'; - strcpy(buffer3, buffer1 ); - } - - p1 = strtok( NULL, "/" ); - } - - if(stat(buffer3, &buffer) || !S_ISREG(buffer.st_mode)) - { - *path = NULL; - errno = ENOENT; - return -1; - } - - last_delimiter = strrchr(buffer3, '/'); - - len = strlen(buffer3); - - if(last_delimiter) - len -=strlen(last_delimiter); - - *path = (char*) calloc(len + 1, sizeof(char)); - - if(!(*path)) - { - *path = NULL; - return -1; - } - - strncpy(*path, buffer3, len); - - return len; -} - -int -translatepath(const char* totranslate, char** translated) -{ - char buffer1[PATH_MAX + 1] = {0}; - char buffer2[PATH_MAX + 1] = {0}; - char buffer3[PATH_MAX + 1] = {0}; - char *p1,*p2; - size_t len; - struct stat buffer = {0}; - - len = strlen(totranslate); - - strncpy(buffer1, totranslate, len); - - if(!strcmp(buffer1,".")) - { - *translated = getcwd(NULL,0); - return strlen(*translated); - } - else if(!strcmp(buffer1, "/..")) - { - *translated = strdup("/"); - return strlen(*translated); - } - - while((p1 = strstr(buffer1, "//"))) - if(p1[2]) - strcpy(p1, p1 + 1); - else - p1[1] = '\0'; - - if (buffer1[0] == '~') - { - for (p2 = buffer2, p1 = buffer1 + 1; *p1 && (*p1 != '/'); *(p2++) = *(p1++)); - - *p2 = '\0'; - - if(buffer2[0] == '\0') - { - char* home = getenv("HOME"); - - if(home) - { - strcpy(buffer2, home); - } - else - { - struct passwd* pw = getpwuid(getuid()); /* get entry */ - - if(!pw) - { - *translated = NULL; - return -1; - } - - strcpy(buffer2,pw->pw_dir); - } - - strcat(buffer2, p1); - } - } - else if (*buffer1 != '/') - { - - getcwd(buffer2, PATH_MAX + 1); - - if (*buffer1 == '.' && *(buffer1 + 1) == '/') - { - strcat(buffer2, buffer1+1); - } - else - { - strcat(buffer2, "/"); - strcat(buffer2, buffer1); - } - } - else - { - strcpy(buffer2, buffer1); - } - - /* - * check for /.. - */ - while((p1 = strstr( buffer2, "/.." ))) - { - for( p2 = p1; --p2 > buffer2 && *p2 != '/'; ); - - if (*(p1 + 3)) - memmove(p2, p1+3, strlen(p1+3)+1); - else - *p2 = '\0'; - } - - /* - * try to find links. - */ - p1 = strtok( buffer2, "/" ); - - - *buffer3 = '\0'; - - while(p1) - { - strcat( buffer3, "/" ); - strcat( buffer3, p1 ); - - len = readlink(buffer3, buffer1, PATH_MAX); - - if (len != -1) - { - *(buffer1 + len) = '\0'; - strcpy(buffer3, buffer1 ); - } - - p1 = strtok( NULL, "/" ); - } - - if (!(*buffer3)) - strcpy(buffer3, "/" ); - - len = strlen(buffer3); - - if(stat(buffer3, &buffer) || !S_ISDIR(buffer.st_mode)) - { - *translated = NULL; - errno = ENOTDIR; - return -1; - } - - - *translated = (char*) calloc(len + 1, sizeof(char)); - - if(!(*translated)) - { - *translated = NULL; - return -1; - } - - strncpy(*translated, buffer3, len); - - return len; -} -#else +int getpath(const char *file, char **path) +{ + char buffer1[PATH_MAX + 1] = { 0 }; + char buffer2[PATH_MAX + 1] = { 0 }; + char buffer3[PATH_MAX + 1] = { 0 }; + char *p1, *p2; + size_t len = strlen(file); + char *last_delimiter = NULL; + struct stat buffer = { 0 }; + strncpy(buffer1, file, len); + + /* remove the /////// */ + while ((p1 = strstr(buffer1, "//"))) + { + if (p1[2]) + strcpy(p1, p1 + 1); + + else + p1[1] = '\0'; + } + if (*buffer1 == '~') + { + for (p2 = buffer2, p1 = buffer1 + 1; *p1 && (*p1 != '/'); + *p2++ = *p1++); + *p2 = '\0'; + if (buffer2[0] == '\0') + { + char *home = getenv("HOME"); + if (home) + { + strcpy(buffer2, home); + } + + else + { + struct passwd *pw = getpwuid(getuid()); + if (!pw) + { + *path = NULL; + return -1; + } + strcpy(buffer2, pw->pw_dir); + } + strcat(buffer2, p1); + } + } + + else if (buffer1[0] != '/') + { + getcwd(buffer2, PATH_MAX + 1); + if (buffer1[0] == '.' && buffer1[1] == '/') + { /* replace */ + strcat(buffer2, &buffer1[1]); + } + + else + { + strcat(buffer2, "/"); + strcat(buffer2, buffer1); + } + } + + else + { + strcpy(buffer2, buffer1); /* copy */ + } + + /* + * check for /.. + */ + while ((p1 = strstr(buffer2, "/.."))) + { + for (p2 = p1; --p2 > buffer2 && *p2 != '/';); + if (*(p1 + 3)) + memmove(p2, p1 + 3, strlen(p1 + 3) + 1); + + else + *p2 = '\0'; + } + + /* + * try to find links, and resolve them. + */ + p1 = strtok(buffer2, "/"); + *buffer3 = '\0'; + while (p1) + { + strcat(buffer3, "/"); + strcat(buffer3, p1); + len = readlink(buffer3, buffer1, PATH_MAX); + if (len != -1) + { + *(buffer1 + len) = '\0'; + strcpy(buffer3, buffer1); + } + p1 = strtok(NULL, "/"); + } + if (stat(buffer3, &buffer) || !S_ISREG(buffer.st_mode)) + { + *path = NULL; + errno = ENOENT; + return -1; + } + last_delimiter = strrchr(buffer3, '/'); + len = strlen(buffer3); + if (last_delimiter) + len -= strlen(last_delimiter); + *path = (char *) calloc(len + 1, sizeof(char)); + if (!(*path)) + { + *path = NULL; + return -1; + } + strncpy(*path, buffer3, len); + return len; + } + + int translatepath(const char *totranslate, char **translated) +{ + char buffer1[PATH_MAX + 1] = { 0 }; + char buffer2[PATH_MAX + 1] = { 0 }; + char buffer3[PATH_MAX + 1] = { 0 }; + char *p1, *p2; + size_t len; + struct stat buffer = { 0 }; + len = strlen(totranslate); + strncpy(buffer1, totranslate, len); + if (!strcmp(buffer1, ".")) + { + *translated = getcwd(NULL, 0); + return strlen(*translated); + } + + else if (!strcmp(buffer1, "/..")) + { + *translated = strdup("/"); + return strlen(*translated); + } + while ((p1 = strstr(buffer1, "//"))) + if (p1[2]) + strcpy(p1, p1 + 1); + + else + p1[1] = '\0'; + if (buffer1[0] == '~') + { + for (p2 = buffer2, p1 = buffer1 + 1; *p1 && (*p1 != '/'); + *(p2++) = *(p1++)); + *p2 = '\0'; + if (buffer2[0] == '\0') + { + char *home = getenv("HOME"); + if (home) + { + strcpy(buffer2, home); + } + + else + { + struct passwd *pw = getpwuid(getuid()); /* get entry */ + if (!pw) + { + *translated = NULL; + return -1; + } + strcpy(buffer2, pw->pw_dir); + } + strcat(buffer2, p1); + } + } + + else if (*buffer1 != '/') + { + getcwd(buffer2, PATH_MAX + 1); + if (*buffer1 == '.' && *(buffer1 + 1) == '/') + { + strcat(buffer2, buffer1 + 1); + } + + else + { + strcat(buffer2, "/"); + strcat(buffer2, buffer1); + } + } + + else + { + strcpy(buffer2, buffer1); + } + + /* + * check for /.. + */ + while ((p1 = strstr(buffer2, "/.."))) + { + for (p2 = p1; --p2 > buffer2 && *p2 != '/';); + if (*(p1 + 3)) + memmove(p2, p1 + 3, strlen(p1 + 3) + 1); + + else + *p2 = '\0'; + } + + /* + * try to find links. + */ + p1 = strtok(buffer2, "/"); + *buffer3 = '\0'; + while (p1) + { + strcat(buffer3, "/"); + strcat(buffer3, p1); + len = readlink(buffer3, buffer1, PATH_MAX); + if (len != -1) + { + *(buffer1 + len) = '\0'; + strcpy(buffer3, buffer1); + } + p1 = strtok(NULL, "/"); + } + if (!(*buffer3)) + strcpy(buffer3, "/"); + len = strlen(buffer3); + if (stat(buffer3, &buffer) || !S_ISDIR(buffer.st_mode)) + { + *translated = NULL; + errno = ENOTDIR; + return -1; + } + *translated = (char *) calloc(len + 1, sizeof(char)); + if (!(*translated)) + { + *translated = NULL; + return -1; + } + strncpy(*translated, buffer3, len); + return len; + } + + +#else /* */ /*int getpath(const char* file, char** path) { @@ -332,166 +294,144 @@ getpath(const char* file, char** path) *path = strncpy(*path, buffer, strlen(buffer) - strlen(part) - 1); return (int)(strlen(buffer) - strlen(part) -1); -}*/ - -int -getpath(const char* file, char** path) -{ - char buf1[PATH_MAX + 1] = {0}; - char buf2[PATH_MAX + 1] = {0}; - struct stat info = {0}; - - char* delimiter; - - if(!file) - { - *path = NULL; - return -1; - } - - delimiter = strrchr(file,'/'); - - if(!delimiter) - delimiter = strrchr(file,'\\'); - - if(!delimiter) - { - *path = getcwd(NULL,0); - } - else - { - strncpy(buf2, file, (delimiter - file)); - - if(translatepath(buf2, path) < 0) - { - if(errno == ENOTDIR) - errno = ENOENT; - - return -1; - } - } - - sprintf(buf1,"%s\\%s", *path, delimiter ? delimiter + 1 : file); - - - if(stat(buf1, &info) || !S_ISREG(info.st_mode)) - { - free(*path); - *path = NULL; - errno = ENOENT; - return -1; - } - - return (int) strlen(*path); -} - - -int -translatepath(const char* totranslate, char** translated) -{ - char buffer1[PATH_MAX + 1] = {0}; - char buffer2[PATH_MAX + 1] = {0}; - char *p1; - int i, len; - - struct stat stat_buf = {0}; - - len = (int)strlen(totranslate); - - strncpy(buffer1, totranslate, len); - - while((p1 = strstr(buffer1, "//"))) - if(p1[2]) - strcpy(p1, p1 + 1); - else - p1[1] = '\0'; - - if(buffer1[strlen(buffer1) - 1] == '/' || buffer1[strlen(buffer1) - 1] == '\\') - buffer1[strlen(buffer1) - 1] = '\0'; - - /* return the current directory */ - if(!strcmp(totranslate,".") || !strcmp(totranslate,"./")) - { - *translated = getcwd(NULL,0); - return (int)strlen(*translated); - } - /* return the previous directory */ - else if(!strcmp(totranslate,"..") || !strcmp(totranslate,"../")) - { - getcwd(buffer1, PATH_MAX + 1); - p1 = strrchr(buffer1, '\\'); - *translated = (char*) calloc((p1 - buffer1) + 1, sizeof(char)); - strncpy(*translated, buffer1, (p1 - buffer1)); - - return (int)strlen(*translated); - } - /* return the root directory */ - else if(!strcmp(totranslate, "/")) - { - *translated = getcwd(NULL,0); - (*translated)[2] = '\0'; - - return (int)strlen(*translated); - } - /* it's a relative directory name build the full directory name (directory)*/ - else if( buffer1[0] != '.' && buffer1[0] != '/' && buffer1[1] != ':' && !stat(totranslate, &stat_buf) && S_ISDIR(stat_buf.st_mode)) - { - for(i = 0; buffer1[i] !='\0'; i++) - { - if(buffer1[i] == '/') - buffer2[i] = '\\'; - else - buffer2[i] = buffer1[i]; - } - - memset(buffer1, 0, PATH_MAX + 1); - getcwd(buffer1, PATH_MAX + 1); - strcat(buffer1,"\\"); - strcat(buffer1,buffer2); - - *translated = (char*) calloc(strlen(buffer1) + 1, sizeof(char)); - strcpy(*translated, buffer1); - - return (int)strlen(*translated); - } - else if(buffer1[0] == '~') - { - /* TODO */ - *translated = NULL; - errno = ENOSYS; - return -1; - } - else if (*buffer1 == '.') - { - _fullpath(buffer2, buffer1, sizeof(buffer1)); - } - else - strcpy(buffer2, buffer1); - - if(stat(buffer2, &stat_buf) || !S_ISDIR(stat_buf.st_mode)) - { - *translated = NULL; - errno = ENOTDIR; - return -1; - } - - - - len = (int)strlen(buffer2); - - - - *translated = (char*) calloc(len + 1, sizeof(char)); - strcpy(*translated, buffer2); - - if(!(*translated)) - { - *translated = NULL; - return -1; - } - - return len; -} -#endif - - +}*/ + int getpath(const char *file, char **path) +{ + char buf1[PATH_MAX + 1] = { 0 }; + char buf2[PATH_MAX + 1] = { 0 }; + struct stat info = { 0 }; + char *delimiter; + if (!file) + { + *path = NULL; + return -1; + } + delimiter = strrchr(file, '/'); + if (!delimiter) + delimiter = strrchr(file, '\\'); + if (!delimiter) + { + *path = getcwd(NULL, 0); + } + + else + { + strncpy(buf2, file, (delimiter - file)); + if (translatepath(buf2, path) < 0) + { + if (errno == ENOTDIR) + errno = ENOENT; + return -1; + } + } + sprintf(buf1, "%s\\%s", *path, delimiter ? delimiter + 1 : file); + if (stat(buf1, &info) || !S_ISREG(info.st_mode)) + { + free(*path); + *path = NULL; + errno = ENOENT; + return -1; + } + return (int) strlen(*path); + } int translatepath(const char *totranslate, char **translated) +{ + char buffer1[PATH_MAX + 1] = { 0 }; + char buffer2[PATH_MAX + 1] = { 0 }; + char *p1; + int i, len; + struct stat stat_buf = { 0 }; + len = (int) strlen(totranslate); + strncpy(buffer1, totranslate, len); + while ((p1 = strstr(buffer1, "//"))) + if (p1[2]) + strcpy(p1, p1 + 1); + + else + p1[1] = '\0'; + if (buffer1[strlen(buffer1) - 1] == '/' + || buffer1[strlen(buffer1) - 1] == '\\') + buffer1[strlen(buffer1) - 1] = '\0'; + + /* return the current directory */ + if (!strcmp(totranslate, ".") || !strcmp(totranslate, "./")) + { + *translated = getcwd(NULL, 0); + return (int) strlen(*translated); + } + + /* return the previous directory */ + else if (!strcmp(totranslate, "..") || !strcmp(totranslate, "../")) + { + getcwd(buffer1, PATH_MAX + 1); + p1 = strrchr(buffer1, '\\'); + *translated = (char *) calloc((p1 - buffer1) + 1, sizeof(char)); + strncpy(*translated, buffer1, (p1 - buffer1)); + return (int) strlen(*translated); + } + + /* return the root directory */ + else if (!strcmp(totranslate, "/")) + { + *translated = getcwd(NULL, 0); + (*translated)[2] = '\0'; + return (int) strlen(*translated); + } + + /* it's a relative directory name build the full directory name (directory) */ + else if (buffer1[0] != '.' && buffer1[0] != '/' && buffer1[1] != ':' + && !stat(totranslate, &stat_buf) + && S_ISDIR(stat_buf.st_mode)) + { + for (i = 0; buffer1[i] != '\0'; i++) + { + if (buffer1[i] == '/') + buffer2[i] = '\\'; + + else + buffer2[i] = buffer1[i]; + } + memset(buffer1, 0, PATH_MAX + 1); + getcwd(buffer1, PATH_MAX + 1); + strcat(buffer1, "\\"); + strcat(buffer1, buffer2); + *translated = (char *) calloc(strlen(buffer1) + 1, sizeof(char)); + strcpy(*translated, buffer1); + return (int) strlen(*translated); + } + + else if (buffer1[0] == '~') + { + + /* TODO */ + *translated = NULL; + errno = ENOSYS; + return -1; + } + + else if (*buffer1 == '.') + { + _fullpath(buffer2, buffer1, sizeof(buffer1)); + } + + else + strcpy(buffer2, buffer1); + if (stat(buffer2, &stat_buf) || !S_ISDIR(stat_buf.st_mode)) + { + *translated = NULL; + errno = ENOTDIR; + return -1; + } + len = (int) strlen(buffer2); + *translated = (char *) calloc(len + 1, sizeof(char)); + strcpy(*translated, buffer2); + if (!(*translated)) + { + *translated = NULL; + return -1; + } + return len; + } + + +#endif /* */ + diff --git a/tools/tesh2/src/is_cmd.c b/tools/tesh2/src/is_cmd.c index 528bc509c7..fca4fb6d36 100644 --- a/tools/tesh2/src/is_cmd.c +++ b/tools/tesh2/src/is_cmd.c @@ -2,72 +2,60 @@ #include -int -is_cmd(char** path, char** builtin, const char* p) +int is_cmd(char **path, char **builtin, const char *p) { - size_t i = 0; - size_t j = 0; - int yes = 0; + size_t i = 0; + size_t j = 0; + int yes = 0; - struct stat stat_buff = {0}; - char command[PATH_MAX + 1] = {0}; - char buff[PATH_MAX + 1] = {0}; - size_t len; + struct stat stat_buff = { 0 }; + char command[PATH_MAX + 1] = { 0 }; + char buff[PATH_MAX + 1] = { 0 }; + size_t len; - if(!p) - return EINVAL; - - len = strlen(p); - while(i < len) - { - if(p[i] != ' ' && p[i] != '\t' && p[i] != '>') - command[j++] = p[i]; - else - break; - - i++; - } - - - /* check first if it's a shell buitin */ - - if(builtin) - { - for(i = 0; builtin[i] != NULL; i++) - { - if(!strcmp(builtin[i], command)) - return 0; - } - } - - if(stat(command, &stat_buff) || !S_ISREG(stat_buff.st_mode)) - { - if(path) - { - for (i = 0; path[i] != NULL; i++) - { - - sprintf(buff,"%s/%s",path[i], command); - - if(!stat(buff, &stat_buff) && S_ISREG(stat_buff.st_mode)) - { - - if(!access(buff, X_OK)) - { - yes = 1; - break; - } - } - } - } - } - else - { - - if(!access(command, X_OK)) - yes = 1; - } - - return yes ? 0 : ECMDNOTFOUND; -} + if (!p) + return EINVAL; + + len = strlen(p); + while (i < len) { + if (p[i] != ' ' && p[i] != '\t' && p[i] != '>') + command[j++] = p[i]; + else + break; + + i++; + } + + + /* check first if it's a shell buitin */ + + if (builtin) { + for (i = 0; builtin[i] != NULL; i++) { + if (!strcmp(builtin[i], command)) + return 0; + } + } + if (stat(command, &stat_buff) || !S_ISREG(stat_buff.st_mode)) { + if (path) { + for (i = 0; path[i] != NULL; i++) { + + sprintf(buff, "%s/%s", path[i], command); + + if (!stat(buff, &stat_buff) && S_ISREG(stat_buff.st_mode)) { + + if (!access(buff, X_OK)) { + yes = 1; + break; + } + } + } + } + } else { + + if (!access(command, X_OK)) + yes = 1; + } + + return yes ? 0 : ECMDNOTFOUND; +} diff --git a/tools/tesh2/src/main.c b/tools/tesh2/src/main.c index c169f1ef51..9bcd3ede0b 100644 --- a/tools/tesh2/src/main.c +++ b/tools/tesh2/src/main.c @@ -22,42 +22,37 @@ /* * entry used to define the parameter of a tesh option. */ -typedef struct s_optentry -{ - int c; /* the character of the option */ - - /* - * the type of the argument of the option - */ - enum - { - flag, /* it's a flag option, by default the flag is set to zero */ - string, /* the option has strings as argument */ - number /* the option has an integral positive number as argument */ - }type; - - byte* value; /* the value of the option */ - byte* optional_value; /* the optional value of the option if not specified */ - const char * long_name; /* the long name of the command */ -}s_optentry_t,* optentry_t; +typedef struct s_optentry { + int c; /* the character of the option */ + + /* + * the type of the argument of the option + */ + enum { + flag, /* it's a flag option, by default the flag is set to zero */ + string, /* the option has strings as argument */ + number /* the option has an integral positive number as argument */ + } type; + + byte *value; /* the value of the option */ + byte *optional_value; /* the optional value of the option if not specified */ + const char *long_name; /* the long name of the command */ +} s_optentry_t, *optentry_t; /* logs */ -XBT_LOG_NEW_DEFAULT_CATEGORY(tesh,"TEst SHell utility"); +XBT_LOG_NEW_DEFAULT_CATEGORY(tesh, "TEst SHell utility"); #ifdef _XBT_WIN32 /* Windows specific : the previous process error mode */ -static UINT -prev_error_mode = 0; +static UINT prev_error_mode = 0; #endif /* this object represents the root directory */ -directory_t -root_directory = NULL; +directory_t root_directory = NULL; /* the current version of tesh */ -static const char* -version = "1.0"; +static const char *version = "1.0"; /* ------------------------------------------------------------ */ /* options */ @@ -69,43 +64,38 @@ version = "1.0"; /* --jobs is specified with arg */ -static int -jobs_nb = -2; +static int + jobs_nb = -2; /* --jobs option is not specified (use the default job count) */ -static int -default_jobs_nb = 1; +static int + default_jobs_nb = 1; /* --jobs is specified but has no arg (one job per unit) */ -static int -optional_jobs_nb = -1; +static int + optional_jobs_nb = -1; /* the global timeout */ static int -timeout = INDEFINITE; + timeout = INDEFINITE; /* ------------------------------------------------------------ */ /* strings */ /* ------------------------------------------------------------ */ /* --C change the directory before running the units */ -static directories_t -directories = NULL; +static directories_t directories = NULL; /* the include directories : see the !i metacommand */ -xbt_dynar_t -include_dirs = NULL; +xbt_dynar_t include_dirs = NULL; /* the list of tesh files to run */ -static fstreams_t -fstreams = NULL; +static fstreams_t fstreams = NULL; /* the list of tesh file suffixes */ -static xbt_dynar_t -suffixes = NULL; +static xbt_dynar_t suffixes = NULL; -static excludes_t -excludes = NULL; +static excludes_t excludes = NULL; /* ------------------------------------------------------------ */ @@ -115,323 +105,295 @@ excludes = NULL; /* if 1, keep going when some commands can't be found * default value 0 : not keep going */ -int -keep_going_flag = 0; +int + keep_going_flag = 0; /* if 1, ignore failures from commands * default value : do not ignore failures */ -int -keep_going_unit_flag = 0; +int + keep_going_unit_flag = 0; /* if 1, display tesh usage */ -static int -print_usage_flag = 0; +static int + print_usage_flag = 0; /* if 1, display the tesh version */ -static int -print_version_flag = 0; +static int + print_version_flag = 0; /* if 1, the status of all the units is display at * the end. */ static int -summary_flag = 0; + summary_flag = 0; /* if 1 and the flag want_summay is set to 1 tesh display the detailed summary of the run */ -int -detail_summary_flag = 0; +int + detail_summary_flag = 0; /* if 1, the directories are displayed */ -int -print_directory_flag = 0; +int + print_directory_flag = 0; /* if 1, just check the syntax of all the tesh files * do not run them. */ int -dry_run_flag = 0; + dry_run_flag = 0; /* if 1, display the tesh files syntax and exit */ static int -print_readme_flag = 0; + print_readme_flag = 0; -int -silent_flag = 0; +int + silent_flag = 0; -int -just_print_flag = 0; +int + just_print_flag = 0; /* the semaphore used to synchronize the jobs */ -xbt_os_sem_t -jobs_sem = NULL; +xbt_os_sem_t jobs_sem = NULL; /* the semaphore used by the runner to wait the end of all the units */ -xbt_os_sem_t -units_sem = NULL; +xbt_os_sem_t units_sem = NULL; static int -loaded = 0; - -int -interrupted = 0; + loaded = 0; int -exit_code = 0; + interrupted = 0; int -err_kind = 0; + exit_code = 0; -char* -err_line = NULL; +int + err_kind = 0; +char *err_line = NULL; -pid_t -pid =0; -int -is_tesh_root = 1; +pid_t pid = 0; -/* the table of the entries of the options */ -static const struct s_optentry opt_entries[] = -{ - { 'C', string, (byte*)NULL, 0, "directory" }, - { 'x', string, (byte*)&suffixes, 0, "suffix" }, - { 'f', string, (byte*)&fstreams, 0, "file" }, - { 'h', flag, (byte*)&print_usage_flag, 0, "help" }, - { 'a', flag, (byte*)&print_readme_flag, 0, "README" }, - { 'k', flag, (byte*)&keep_going_flag, 0, "keep-going" }, - { 'i', flag, (byte*)&keep_going_unit_flag, 0, "keep-going-unit"}, - { 'I', string, (byte*)&include_dirs, 0, "include-dir" }, - { 'j', number, (byte*)&jobs_nb, (byte*) &optional_jobs_nb, "jobs" }, - { 'm', flag, (byte*)&detail_summary_flag, 0, "detail-summary" }, - { 'c', flag, (byte*)&just_print_flag, 0, "just-print" }, - { 's', flag, (byte*)&silent_flag, 0, "silent" }, - { 'V', flag, (byte*)&print_version_flag, 0, "version" }, - { 'w', flag, (byte*)&print_directory_flag, 0,"dont-print-directory" }, - { 'n', flag, (byte*)&dry_run_flag, 0, "dry-run"}, - { 't', number, (byte*)&timeout, 0, "timeout" }, - { 'r', string, (byte*)&directories, 0, "load-directory"}, - { 'v', flag, (byte*)&summary_flag, 0, "summary"}, - { 'F', string,(byte*)&excludes, 0, "exclude"}, - { 'l', string, (byte*)NULL, 0, "log" }, - { 0, 0, 0, 0, 0} +int + is_tesh_root = 1; + +/* the table of the entries of the options */ +static const struct s_optentry opt_entries[] = { + {'C', string, (byte *) NULL, 0, "directory"}, + {'x', string, (byte *) & suffixes, 0, "suffix"}, + {'f', string, (byte *) & fstreams, 0, "file"}, + {'h', flag, (byte *) & print_usage_flag, 0, "help"}, + {'a', flag, (byte *) & print_readme_flag, 0, "README"}, + {'k', flag, (byte *) & keep_going_flag, 0, "keep-going"}, + {'i', flag, (byte *) & keep_going_unit_flag, 0, "keep-going-unit"}, + {'I', string, (byte *) & include_dirs, 0, "include-dir"}, + {'j', number, (byte *) & jobs_nb, (byte *) & optional_jobs_nb, "jobs"}, + {'m', flag, (byte *) & detail_summary_flag, 0, "detail-summary"}, + {'c', flag, (byte *) & just_print_flag, 0, "just-print"}, + {'s', flag, (byte *) & silent_flag, 0, "silent"}, + {'V', flag, (byte *) & print_version_flag, 0, "version"}, + {'w', flag, (byte *) & print_directory_flag, 0, "dont-print-directory"}, + {'n', flag, (byte *) & dry_run_flag, 0, "dry-run"}, + {'t', number, (byte *) & timeout, 0, "timeout"}, + {'r', string, (byte *) & directories, 0, "load-directory"}, + {'v', flag, (byte *) & summary_flag, 0, "summary"}, + {'F', string, (byte *) & excludes, 0, "exclude"}, + {'l', string, (byte *) NULL, 0, "log"}, + {0, 0, 0, 0, 0} }; /* the tesh usage */ -static const char* usage[] = -{ - "Options:\n", - " -C DIRECTORY, --directory=DIRECTORY Change to DIRECTORY before running any commands.\n", - " -e, --environment-overrides Environment variables override files.\n", - " -f FILE, --file=FILE Read FILE as a teshfile.\n", - " remark :\n", - " all argument of the command line without\n", - " option is dealed as a tesh file.\n", - " -h, --help Print this message and exit.\n", - " -i, --keep-going-unit Ignore failures from commands.\n", - " The possible failures are :\n", - " - the exit code differ from the expected\n", - " - the signal throw differ from the expected\n", - " - the output differ from the expected\n", - " - the read pipe is broken\n", - " - the write pipe is broken\n", - " - the command assigned delay is outdated\n", - " -I DIRECTORY, --include-dir=DIRECTORY Search DIRECTORY for included files.\n", - " -j [N], --jobs[=N] Allow N units at once; infinite units with\n" - " no arg.\n", - " -k, --keep-going Keep going when some commands can't be made or\n", - " failed.\n", - " -c, --just-print Don't actually run any commands; just print them.\n", - " -s, --silent, Don't echo commands.\n", - " -V, --version Print the version number of tesh and exit.\n", - " -d, --dont-print-directory Don't display the current directory.\n", - " -n, --dry-run Check the syntax of the specified tesh files, display the result and exit.\n", - " -t, --timeout Wait the end of the commands at most timeout seconds.\n", - " -x, --suffix Consider the new suffix for the tesh files.\n" - " remark :\n", - " the default suffix for the tesh files is \".tesh\".\n", - " -a, --README Print the read me file and exit.\n", - " -r, --load-directory Run all the tesh files located in the directories specified by the option --directory.\n", - " -v, --summary Display the status of the commands.\n", - " -m, --detail-summary Detail the summary of the run.\n", - " -F file , --exclude=FILE Ignore the tesh file FILE.\n", - " -l format, --log Format of the xbt logs.\n", - NULL +static const char *usage[] = { + "Options:\n", + " -C DIRECTORY, --directory=DIRECTORY Change to DIRECTORY before running any commands.\n", + " -e, --environment-overrides Environment variables override files.\n", + " -f FILE, --file=FILE Read FILE as a teshfile.\n", + " remark :\n", + " all argument of the command line without\n", + " option is dealed as a tesh file.\n", + " -h, --help Print this message and exit.\n", + " -i, --keep-going-unit Ignore failures from commands.\n", + " The possible failures are :\n", + " - the exit code differ from the expected\n", + " - the signal throw differ from the expected\n", + " - the output differ from the expected\n", + " - the read pipe is broken\n", + " - the write pipe is broken\n", + " - the command assigned delay is outdated\n", + " -I DIRECTORY, --include-dir=DIRECTORY Search DIRECTORY for included files.\n", + " -j [N], --jobs[=N] Allow N units at once; infinite units with\n" + " no arg.\n", + " -k, --keep-going Keep going when some commands can't be made or\n", + " failed.\n", + " -c, --just-print Don't actually run any commands; just print them.\n", + " -s, --silent, Don't echo commands.\n", + " -V, --version Print the version number of tesh and exit.\n", + " -d, --dont-print-directory Don't display the current directory.\n", + " -n, --dry-run Check the syntax of the specified tesh files, display the result and exit.\n", + " -t, --timeout Wait the end of the commands at most timeout seconds.\n", + " -x, --suffix Consider the new suffix for the tesh files.\n" + " remark :\n", + " the default suffix for the tesh files is \".tesh\".\n", + " -a, --README Print the read me file and exit.\n", + " -r, --load-directory Run all the tesh files located in the directories specified by the option --directory.\n", + " -v, --summary Display the status of the commands.\n", + " -m, --detail-summary Detail the summary of the run.\n", + " -F file , --exclude=FILE Ignore the tesh file FILE.\n", + " -l format, --log Format of the xbt logs.\n", + NULL }; -/* the string of options of tesh */ -static char -optstring[1 + sizeof (opt_entries) / sizeof (opt_entries[0]) * 3]; +/* the string of options of tesh */ +static char + optstring[1 + sizeof(opt_entries) / sizeof(opt_entries[0]) * 3]; /* the option table of tesh */ -static struct -option longopts[(sizeof (opt_entries) / sizeof (s_optentry_t))]; +static struct +option longopts[(sizeof(opt_entries) / sizeof(s_optentry_t))]; -static void -init_options(void); +static void init_options(void); -static int -process_command_line(int argc, char** argv); +static int process_command_line(int argc, char **argv); -static void -load(void); +static void load(void); -static void -print_usage(void); +static void print_usage(void); -static void -print_version(void); +static void print_version(void); -static void -finalize(void); +static void finalize(void); -static void -print_readme(void); +static void print_readme(void); -static int -init(void); +static int init(void); -static int -screen_cleaned; +static int screen_cleaned; -static int -finalized = 0; +static int finalized = 0; -static int -sig_int = 0; +static int sig_int = 0; #ifdef _XBT_WIN32 -static void -sig_int_handler(int signum) +static void sig_int_handler(int signum) { - if(!finalized) - { - sig_int = 1; - runner_interrupt(); - while(!finalized); - } - + if (!finalized) { + sig_int = 1; + runner_interrupt(); + while (!finalized); + } + } #endif -static void -free_string(void* str) +static void free_string(void *str) { - free(*(void**)str); + free(*(void **) str); } -int -main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - /* set the locale to the default*/ - setlocale(LC_ALL,""); - - /* xbt initialization */ - xbt_init(&argc, argv); - - /* initialize tesh */ - if(init() < 0) - finalize(); - - /* process the command line */ - if(process_command_line(argc, argv) < 0) - finalize(); - - /* move to the root directory (the directory may change during the command line processing) */ - chdir(root_directory->name); - - /* the user wants to display the usage of tesh */ - if(print_version_flag) - { - print_version(); - - if(!print_usage_flag) - finalize(); - } - - /* the user wants to display the usage of tesh */ - if(print_usage_flag) - { - print_usage(); - finalize(); - } - - /* the user wants to display the semantic of the tesh file metacommands */ - if(print_readme_flag) - { - print_readme(); - finalize(); - } - - /* load tesh files */ - load(); - - - /* use by the finalize function to known if it must display the tesh usage */ - loaded = 1; - - if(-2 == jobs_nb) - {/* --jobs is not specified (use the default value) */ - jobs_nb = default_jobs_nb; - } - else if(optional_jobs_nb == jobs_nb) - {/* --jobs option is specified with no args (use one job per unit) */ - jobs_nb = fstreams_get_size(fstreams); - } - - if(jobs_nb > fstreams_get_size(fstreams)) - {/* --jobs = N is specified and N is more than the number of tesh files */ - - WARN0("Number of requested jobs exceed the number of files to run"); - - /* assume one job per file */ - jobs_nb = fstreams_get_size(fstreams); - } - - if(jobs_nb != 1 && dry_run_flag) - { - jobs_nb = 1; - INFO0("Dry run specified : force jobs count to 1"); - } - - /* initialize the semaphore used to synchronize all the units */ - jobs_sem = xbt_os_sem_init(jobs_nb); - - /* initialize the semaphore used by the runner to wait for the end of all units */ - units_sem = xbt_os_sem_init(0); - - /* initialize the runner */ - if(runner_init(/*check_syntax_flag,*/ timeout, fstreams) < 0) - finalize(); - - if(just_print_flag && silent_flag) - silent_flag = 0; - - if(just_print_flag && dry_run_flag) - WARN0("mismatch in the syntax : --just-check-syntax and --just-display options at same time"); - - /* run all the units */ - runner_run(); - - if(runner_is_timedout()) - ERROR1("Tesh timed out after `(%d)' seconds", timeout); - - /* show the result of the units */ - if(detail_summary_flag ||summary_flag || dry_run_flag) - runner_summarize(); - - /* all the test are runned, destroy the runner */ - runner_destroy(); - - /* then, finalize tesh (release all the allocated memory and exits) */ - finalize(); - - #ifndef _XBT_WIN32 - return exit_code; - #endif - + /* set the locale to the default */ + setlocale(LC_ALL, ""); + + /* xbt initialization */ + xbt_init(&argc, argv); + + /* initialize tesh */ + if (init() < 0) + finalize(); + + /* process the command line */ + if (process_command_line(argc, argv) < 0) + finalize(); + + /* move to the root directory (the directory may change during the command line processing) */ + chdir(root_directory->name); + + /* the user wants to display the usage of tesh */ + if (print_version_flag) { + print_version(); + + if (!print_usage_flag) + finalize(); + } + + /* the user wants to display the usage of tesh */ + if (print_usage_flag) { + print_usage(); + finalize(); + } + + /* the user wants to display the semantic of the tesh file metacommands */ + if (print_readme_flag) { + print_readme(); + finalize(); + } + + /* load tesh files */ + load(); + + + /* use by the finalize function to known if it must display the tesh usage */ + loaded = 1; + + if (-2 == jobs_nb) { /* --jobs is not specified (use the default value) */ + jobs_nb = default_jobs_nb; + } else if (optional_jobs_nb == jobs_nb) { /* --jobs option is specified with no args (use one job per unit) */ + jobs_nb = fstreams_get_size(fstreams); + } + + if (jobs_nb > fstreams_get_size(fstreams)) { /* --jobs = N is specified and N is more than the number of tesh files */ + + WARN0("Number of requested jobs exceed the number of files to run"); + + /* assume one job per file */ + jobs_nb = fstreams_get_size(fstreams); + } + + if (jobs_nb != 1 && dry_run_flag) { + jobs_nb = 1; + INFO0("Dry run specified : force jobs count to 1"); + } + + /* initialize the semaphore used to synchronize all the units */ + jobs_sem = xbt_os_sem_init(jobs_nb); + + /* initialize the semaphore used by the runner to wait for the end of all units */ + units_sem = xbt_os_sem_init(0); + + /* initialize the runner */ + if (runner_init( /*check_syntax_flag, */ timeout, fstreams) < 0) + finalize(); + + if (just_print_flag && silent_flag) + silent_flag = 0; + + if (just_print_flag && dry_run_flag) + WARN0 + ("mismatch in the syntax : --just-check-syntax and --just-display options at same time"); + + /* run all the units */ + runner_run(); + + if (runner_is_timedout()) + ERROR1("Tesh timed out after `(%d)' seconds", timeout); + + /* show the result of the units */ + if (detail_summary_flag || summary_flag || dry_run_flag) + runner_summarize(); + + /* all the test are runned, destroy the runner */ + runner_destroy(); + + /* then, finalize tesh (release all the allocated memory and exits) */ + finalize(); + +#ifndef _XBT_WIN32 + return exit_code; +#endif + } /* init -- initialize tesh : allocated all the objects needed by tesh to run @@ -443,261 +405,252 @@ main(int argc, char* argv[]) -static int -init(void) +static int init(void) { - char* buffer; - char* suffix = strdup(".tesh"); - - #ifdef _XBT_WIN32 - /* Windows specific : don't display the general-protection-fault message box and - * the the critical-error-handler message box (instead the system send the error - * to the calling process : tesh) - */ - prev_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); - - /* handle the interrupt signal */ - signal(SIGINT, sig_int_handler); - #else - /* Ignore pipe issues. - * They will show up when we try to send data to dead buddies, - * but we will stop doing so when we're done with provided input - */ - /* - struct sigaction act; - memset(&act,0, sizeof(struct sigaction)); - act.sa_handler = SIG_IGN; - sigaction(SIGPIPE, &act, NULL); - - memset(&act,0, sizeof(struct sigaction)); - act.sa_handler = sig_int_handler; - sigaction(SIGINT, &act, NULL);*/ - - #endif - - - - - /* used to store the files to run */ - if(!(fstreams = fstreams_new((void_f_pvoid_t)fstream_free))) - { - ERROR1("(system error) %s", strerror(errno)); - return -1; - } - - /* register the current directory */ - if(!(buffer = getcwd(NULL, 0))) - { - ERROR1("(system error) %s", strerror(errno)); - return -1; - } - - /* save the root directory */ - if(!(root_directory = directory_new(buffer))) - { - ERROR1("(system error) %s", strerror(errno)); - return -1; - } - - free(buffer); - - /* the directories to loads */ - if(!(directories = directories_new())) - { - ERROR1("(system error) %s", strerror(errno)); - return -1; - } - - /* the include directories */ - include_dirs = xbt_dynar_new(sizeof(directory_t), (void_f_pvoid_t)directory_free); - - /* the excluded files */ - if(!(excludes = excludes_new())) - { - ERROR1("(system error) %s", strerror(errno)); - return -1; - } - - /* the suffixes */ - suffixes = xbt_dynar_new(sizeof(char*),free_string); - - /* register the default suffix ".tesh" */ - xbt_dynar_push(suffixes, &suffix); - - return 0; + char *buffer; + char *suffix = strdup(".tesh"); + +#ifdef _XBT_WIN32 + /* Windows specific : don't display the general-protection-fault message box and + * the the critical-error-handler message box (instead the system send the error + * to the calling process : tesh) + */ + prev_error_mode = + SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); + + /* handle the interrupt signal */ + signal(SIGINT, sig_int_handler); +#else + /* Ignore pipe issues. + * They will show up when we try to send data to dead buddies, + * but we will stop doing so when we're done with provided input + */ + /* + struct sigaction act; + memset(&act,0, sizeof(struct sigaction)); + act.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &act, NULL); + + memset(&act,0, sizeof(struct sigaction)); + act.sa_handler = sig_int_handler; + sigaction(SIGINT, &act, NULL); */ + +#endif + + + + + /* used to store the files to run */ + if (!(fstreams = fstreams_new((void_f_pvoid_t) fstream_free))) { + ERROR1("(system error) %s", strerror(errno)); + return -1; + } + + /* register the current directory */ + if (!(buffer = getcwd(NULL, 0))) { + ERROR1("(system error) %s", strerror(errno)); + return -1; + } + + /* save the root directory */ + if (!(root_directory = directory_new(buffer))) { + ERROR1("(system error) %s", strerror(errno)); + return -1; + } + + free(buffer); + + /* the directories to loads */ + if (!(directories = directories_new())) { + ERROR1("(system error) %s", strerror(errno)); + return -1; + } + + /* the include directories */ + include_dirs = + xbt_dynar_new(sizeof(directory_t), (void_f_pvoid_t) directory_free); + + /* the excluded files */ + if (!(excludes = excludes_new())) { + ERROR1("(system error) %s", strerror(errno)); + return -1; + } + + /* the suffixes */ + suffixes = xbt_dynar_new(sizeof(char *), free_string); + + /* register the default suffix ".tesh" */ + xbt_dynar_push(suffixes, &suffix); + + return 0; } /* load -- load the tesh files to run */ -static void -load(void) +static void load(void) { - - /* if the directories object is not empty load all the tesh files contained in - * the directories specified in the command line (this tesh files must have the - * a suffix specified in the suffixes object. - */ - if(!directories_is_empty(directories)) - directories_load(directories, fstreams, suffixes); - - /* if no tesh file has been specified in the command line try to load the default tesh file - * teshfile from the current directory - */ - if(fstreams_is_empty(fstreams)) - { - struct stat buffer = {0}; - - /* add the default tesh file if it exists in the current directory */ - if(!stat("teshfile", &buffer) && S_ISREG(buffer.st_mode)) - fstreams_add(fstreams, fstream_new(getcwd(NULL, 0), "teshfile")); - } - - /* excludes the files specified in the command line and stored in the excludes object */ - if(!excludes_is_empty(excludes) && !fstreams_is_empty(fstreams)) - { - /* check the files to excludes before */ - excludes_check(excludes, fstreams); - - /* exclude the specified tesh files */ - fstreams_exclude(fstreams, excludes); - } - - /* if the fstreams object is empty use the stdin */ - if(fstreams_is_empty(fstreams)) - fstreams_add(fstreams, fstream_new(NULL, "stdin")); - - /* load the tesh files (open them) */ - fstreams_load(fstreams); - + + /* if the directories object is not empty load all the tesh files contained in + * the directories specified in the command line (this tesh files must have the + * a suffix specified in the suffixes object. + */ + if (!directories_is_empty(directories)) + directories_load(directories, fstreams, suffixes); + + /* if no tesh file has been specified in the command line try to load the default tesh file + * teshfile from the current directory + */ + if (fstreams_is_empty(fstreams)) { + struct stat buffer = { 0 }; + + /* add the default tesh file if it exists in the current directory */ + if (!stat("teshfile", &buffer) && S_ISREG(buffer.st_mode)) + fstreams_add(fstreams, fstream_new(getcwd(NULL, 0), "teshfile")); + } + + /* excludes the files specified in the command line and stored in the excludes object */ + if (!excludes_is_empty(excludes) && !fstreams_is_empty(fstreams)) { + /* check the files to excludes before */ + excludes_check(excludes, fstreams); + + /* exclude the specified tesh files */ + fstreams_exclude(fstreams, excludes); + } + + /* if the fstreams object is empty use the stdin */ + if (fstreams_is_empty(fstreams)) + fstreams_add(fstreams, fstream_new(NULL, "stdin")); + + /* load the tesh files (open them) */ + fstreams_load(fstreams); + } /* finalize -- cleanup all the allocated objects and display the tesh usage if needed */ -static void -finalize(void) +static void finalize(void) { - /* delete the fstreams object */ - if(fstreams) - fstreams_free((void**)&fstreams); - - /* delete the excludes object */ - if(excludes) - excludes_free((void**)&excludes); - - /* delete the directories object */ - if(directories) - directories_free((void**)&directories); - - /* delete the root directory object */ - if(root_directory) - directory_free((void**)&root_directory); - - /* delete the include directories object */ - if(include_dirs) - xbt_dynar_free(&include_dirs); - - /* delete the list of tesh files suffixes */ - if(suffixes) - xbt_dynar_free(&suffixes); - - /* destroy the semaphore used to synchronize the units */ - if(jobs_sem) - xbt_os_sem_destroy(jobs_sem); - - /* destroy the semaphore used by the runner used to wait for the end of the units */ - if(units_sem) - xbt_os_sem_destroy(units_sem); - - /* Windows specific (restore the previouse error mode */ - #ifdef _XBT_WIN32 - SetErrorMode(prev_error_mode); - #endif - - if(sig_int) - INFO0("Tesh interrupted (receive a SIGINT)"); - else if(!summary_flag && !detail_summary_flag && !dry_run_flag && !silent_flag && !just_print_flag && !print_version_flag && !print_usage_flag && is_tesh_root) - { - if(!exit_code) - INFO2("Tesh terminated with exit code %d : %s",exit_code, "success"); - else - { - if(err_line) - ERROR3("Tesh terminated with exit code `(<%s> %s)' (%d)",err_line, error_to_string(exit_code, err_kind), exit_code); - else - ERROR2("Tesh terminated with exit code `(%s)' (%d)", error_to_string(exit_code, err_kind), exit_code); - - } - } - - if(err_line) - free(err_line); - - /* exit from the xbt framework */ - - finalized = 1; - - /* exit with the last error code */ - if(!sig_int) - exit(exit_code); + /* delete the fstreams object */ + if (fstreams) + fstreams_free((void **) &fstreams); + + /* delete the excludes object */ + if (excludes) + excludes_free((void **) &excludes); + + /* delete the directories object */ + if (directories) + directories_free((void **) &directories); + + /* delete the root directory object */ + if (root_directory) + directory_free((void **) &root_directory); + + /* delete the include directories object */ + if (include_dirs) + xbt_dynar_free(&include_dirs); + + /* delete the list of tesh files suffixes */ + if (suffixes) + xbt_dynar_free(&suffixes); + + /* destroy the semaphore used to synchronize the units */ + if (jobs_sem) + xbt_os_sem_destroy(jobs_sem); + + /* destroy the semaphore used by the runner used to wait for the end of the units */ + if (units_sem) + xbt_os_sem_destroy(units_sem); + + /* Windows specific (restore the previouse error mode */ +#ifdef _XBT_WIN32 + SetErrorMode(prev_error_mode); +#endif + + if (sig_int) + INFO0("Tesh interrupted (receive a SIGINT)"); + else if (!summary_flag && !detail_summary_flag && !dry_run_flag + && !silent_flag && !just_print_flag && !print_version_flag + && !print_usage_flag && is_tesh_root) { + if (!exit_code) + INFO2("Tesh terminated with exit code %d : %s", exit_code, + "success"); + else { + if (err_line) + ERROR3("Tesh terminated with exit code `(<%s> %s)' (%d)", err_line, + error_to_string(exit_code, err_kind), exit_code); + else + ERROR2("Tesh terminated with exit code `(%s)' (%d)", + error_to_string(exit_code, err_kind), exit_code); + + } + } + + if (err_line) + free(err_line); + + /* exit from the xbt framework */ + + finalized = 1; + + /* exit with the last error code */ + if (!sig_int) + exit(exit_code); } /* init_options -- initialize the options string */ -static void -init_options (void) +static void init_options(void) { - char *p; - unsigned int i; - - /* the function has been already called */ - if(optstring[0] != '\0') - return; - - p = optstring; - - *p++ = '-'; - - for (i = 0; opt_entries[i].c != '\0'; ++i) - { - /* initialize the long name of the option*/ - longopts[i].name = (opt_entries[i].long_name == 0 ? "" : opt_entries[i].long_name); - - /* getopt_long returns the value of val */ - longopts[i].flag = 0; - - /* the short option */ - longopts[i].val = opt_entries[i].c; - - /* add the short option in the options string */ - *p++ = opt_entries[i].c; - - switch (opt_entries[i].type) - { - /* if this option is used to set a flag or if the argument must be ignored - * the option has no argument - */ - case flag: - longopts[i].has_arg = no_argument; - break; - - /* the option has an argument */ - case string: - case number: - - *p++ = ':'; - - if(opt_entries[i].optional_value != 0) - { - *p++ = ':'; - - longopts[i].has_arg = optional_argument; - } - else - longopts[i].has_arg = required_argument; - - break; - } - } - - *p = '\0'; - longopts[i].name = 0; + char *p; + unsigned int i; + + /* the function has been already called */ + if (optstring[0] != '\0') + return; + + p = optstring; + + *p++ = '-'; + + for (i = 0; opt_entries[i].c != '\0'; ++i) { + /* initialize the long name of the option */ + longopts[i].name = + (opt_entries[i].long_name == 0 ? "" : opt_entries[i].long_name); + + /* getopt_long returns the value of val */ + longopts[i].flag = 0; + + /* the short option */ + longopts[i].val = opt_entries[i].c; + + /* add the short option in the options string */ + *p++ = opt_entries[i].c; + + switch (opt_entries[i].type) { + /* if this option is used to set a flag or if the argument must be ignored + * the option has no argument + */ + case flag: + longopts[i].has_arg = no_argument; + break; + + /* the option has an argument */ + case string: + case number: + + *p++ = ':'; + + if (opt_entries[i].optional_value != 0) { + *p++ = ':'; + + longopts[i].has_arg = optional_argument; + } else + longopts[i].has_arg = required_argument; + + break; + } + } + + *p = '\0'; + longopts[i].name = 0; } /* process_command_line -- process the command line @@ -710,507 +663,457 @@ init_options (void) * and sets the global variable errno to indicate the error. * * errors [ENOENT] A file name specified in the command line does not exist - */ + */ -static int -process_command_line(int argc, char** argv) +static int process_command_line(int argc, char **argv) { - register const struct s_optentry* entry; - register int c; - directory_t directory; - fstream_t fstream; - - /* initialize the options string of tesh */ - init_options(); - - /* let the function getopt_long display the errors if any */ - opterr = 1; - - /* set option index to zero */ - optind = 0; - - while (optind < argc) - { - c = getopt_long(argc, argv, optstring, longopts, (int *) 0); - - if(c == EOF) - { - /* end of the command line or "--". */ - break; - } - else if (c == 1) - { - /* no option specified, assume it's a tesh file to run */ - char* path; - char* delimiter; - - /* getpath returns -1 when the file to get the path doesn't exist */ - if(getpath(optarg, &path) < 0) - { - exit_code = errno; - err_kind = 0; - - if(ENOENT == errno) - ERROR1("File %s does not exist", optarg); - else - ERROR0("Insufficient memory is available to parse the command line : system error"); - - return -1; - } - - /* get to the last / (if any) to get the short name of the file */ - delimiter = strrchr(optarg,'/'); - - #ifdef _XBT_WIN32 - if(!delimiter) - delimiter = strrchr(optarg,'\\'); - #endif - - /* create a new file stream which represents the tesh file to run */ - fstream = fstream_new(path, delimiter ? delimiter + 1 : optarg); - - free(path); - - /* if the list of all tesh files to run already contains this file - * destroy it and display a warning, otherwise add it in the list. - */ - if(fstreams_contains(fstreams, fstream)) - { - fstream_free(&fstream); - WARN1("File %s already specified to be run", optarg); - } - else - fstreams_add(fstreams, fstream); - - } - else if (c == '?') - { - /* unknown option, let getopt_long() displays the error */ - ERROR0("Command line processing failed : invalid command line"); - exit_code = EINVCMDLINE; - err_kind = 1; - return -1; - } - else - { - for(entry = opt_entries; entry->c != '\0'; ++entry) - - if(c == entry->c) - { - - switch (entry->type) - { - /* impossible */ - default: - ERROR0("Command line processing failed : internal error"); - exit_code = EPROCCMDLINE; - err_kind = 1; - return -1; - - - /* flag options */ - case flag: - /* set the flag to one */ - *(int*) entry->value = 1; - - break; - - /* string options */ - case string: - - if(!optarg) - { - /* an option with a optional arg is specified use the entry->optional_value */ - optarg = (char*)entry->optional_value; - } - else if (*optarg == '\0') - { - /* a non optional argument is not specified */ - ERROR2("Option %c \"%s\"requires an argument",entry->c,entry->long_name); - exit_code = ENOARG; - err_kind = 1; - return -1; - } - - /* --load-directory option */ - if(!strcmp(entry->long_name,"load-directory")) - { - char* path; - - if(translatepath(optarg, &path) < 0) - { - exit_code = errno; - err_kind = 0; - - if(ENOTDIR == errno) - ERROR1("%s is not a directory",optarg); - else - ERROR0("Insufficient memory is available to process the command line - system error"); - - return -1; - - } - else - { - - directory = directory_new(path); - free(path); - - if(directories_contains(directories, directory)) - { - directory_free((void**)&directory); - WARN1("Directory %s already specified to be load",optarg); - } - else - directories_add(directories, directory); - - - } - } - else if(!strcmp(entry->long_name,"directory")) - { - char* path ; - - if(translatepath(optarg, &path) < 0) - { - exit_code = errno; - err_kind = 0; - - if(ENOTDIR == errno) - ERROR1("%s is not a directory",optarg); - else - ERROR0("Insufficient memory is available to process the command line - system error"); - - return -1; - } - else - { - char* buffer = getcwd(NULL, 0); - - - if(!strcmp(buffer, path)) - WARN1("Already in the directory %s", optarg); - else if(!print_directory_flag) - INFO1("Entering directory \"%s\"",path); - - chdir(path); - free(path); - - free(buffer); - } - } - - /* --suffix option */ - else if(!strcmp(entry->long_name,"suffix")) - { - if(strlen(optarg) > MAX_SUFFIX) - { - ERROR1("Suffix %s too long",optarg); - exit_code = ESUFFIXTOOLONG; - err_kind = 1; - return -1; - } - - if(optarg[0] == '.') - { - char* cur; - unsigned int i; - int exists = 0; - - char* suffix = xbt_new0(char, MAX_SUFFIX + 2); - sprintf(suffix,".%s",optarg); - - xbt_dynar_foreach(suffixes, i, cur) - { - if(!strcmp(suffix, cur)) - { - exists = 1; - break; - } - } - - if(exists) - WARN1("Suffix %s already specified to be used", optarg); - else - xbt_dynar_push(suffixes, &suffix); - } - else - { - char* cur; - unsigned int i; - int exists = 0; - - xbt_dynar_foreach(suffixes, i, cur) - { - if(!strcmp(optarg, cur)) - { - exists = 1; - break; - } - } - - if(exists) - WARN1("Suffix %s already specified to be used", optarg); - else - { - char* suffix = strdup(optarg); - xbt_dynar_push(suffixes, &suffix); - } - } - } - /* --file option */ - else if(!strcmp(entry->long_name,"file")) - { - char* path; - char* delimiter; - - if(getpath(optarg, &path) < 0) - { - exit_code = errno; - err_kind = 0; - - if(ENOENT == errno) - ERROR1("File %s does not exist", optarg); - else - ERROR1("System error :`(%s)'", strerror(errno)); - - return -1; - } - - delimiter = strrchr(optarg,'/'); - - #ifdef _XBT_WIN32 - if(!delimiter) - delimiter = strrchr(optarg,'\\'); - #endif - - fstream = fstream_new(path, delimiter ? delimiter + 1 : optarg); - - free(path); - - if(fstreams_contains(fstreams, fstream)) - { - fstream_free(&fstream); - WARN1("File %s already specified to run", optarg); - } - else - fstreams_add(fstreams, fstream); - } - /* --include-dir option */ - else if(!strcmp(entry->long_name,"include-dir")) - { - - char* path ; - - if(translatepath(optarg, &path) < 0) - { - exit_code = errno; - err_kind = 0; - - if(ENOTDIR == errno) - ERROR1("%s is not a directory",optarg); - else - ERROR0("Insufficient memory is available to process the command line - system error"); - - return -1; - } - - else - { - int exists = 0; - unsigned int i; - directory_t cur; - directory = directory_new(path); - free(path); - - xbt_dynar_foreach(include_dirs, i , cur) - { - if(!strcmp(cur->name, optarg)) - { - exists = 1; - break; - } - } - - if(exists) - { - directory_free((void**)&directory); - WARN1("Include directory %s already specified to be used",optarg); - - } - else - xbt_dynar_push(include_dirs, &directory); - - } - } - /* --exclude option */ - else if(!strcmp(entry->long_name,"exclude")) - { - char* path; - char* delimiter; - - if(getpath(optarg, &path) < 0) - { - exit_code = errno; - err_kind = 0; - - if(ENOENT == errno) - ERROR1("file %s does not exist", optarg); - else - ERROR0("Insufficient memory is available to process the command line - system error"); - - return -1; - } - - delimiter = strrchr(optarg,'/'); - - #ifdef _XBT_WIN32 - if(!delimiter) - delimiter = strrchr(optarg,'\\'); - #endif - - fstream = fstream_new(path, delimiter ? delimiter + 1 : optarg); - free(path); - - if(excludes_contains(excludes, fstream)) - { - fstream_free(&fstream); - WARN1("File %s already specified to be exclude", optarg); - } - else - excludes_add(excludes, fstream); - - } - else if(!strcmp(entry->long_name,"log")) - { - /* NOTHING TODO : log for xbt */ - } - else - { - INFO1("Unexpected option %s", optarg); - return -1; - } - - - break; - - /* strictly positve number options */ - case number: - - if ((NULL == optarg) && (argc > optind)) - { - const char* cp; - - for (cp = argv[optind]; isdigit(cp[0]); ++cp) - if(cp[0] == '\0') - optarg = argv[optind++]; - } - - /* the number option is specified */ - if(NULL != optarg) - { - int i = atoi(optarg); - const char *cp; - - for (cp = optarg; isdigit(cp[0]); ++cp); - - if (i < 1 || cp[0] != '\0') - { - ERROR2("Option %c \"%s\" requires an strictly positive integer as argument",entry->c, entry->long_name); - exit_code = ENOTPOSITIVENUM; - err_kind = 1; - return -1; - } - else - *(int*)entry->value = i; - } - /* the number option is specified but has no arg, use the optional value*/ - else - *(int*)entry->value = *(int*) entry->optional_value; - - break; - - } - break; - } - } - } - - return 0; + register const struct s_optentry *entry; + register int c; + directory_t directory; + fstream_t fstream; + + /* initialize the options string of tesh */ + init_options(); + + /* let the function getopt_long display the errors if any */ + opterr = 1; + + /* set option index to zero */ + optind = 0; + + while (optind < argc) { + c = getopt_long(argc, argv, optstring, longopts, (int *) 0); + + if (c == EOF) { + /* end of the command line or "--". */ + break; + } else if (c == 1) { + /* no option specified, assume it's a tesh file to run */ + char *path; + char *delimiter; + + /* getpath returns -1 when the file to get the path doesn't exist */ + if (getpath(optarg, &path) < 0) { + exit_code = errno; + err_kind = 0; + + if (ENOENT == errno) + ERROR1("File %s does not exist", optarg); + else + ERROR0 + ("Insufficient memory is available to parse the command line : system error"); + + return -1; + } + + /* get to the last / (if any) to get the short name of the file */ + delimiter = strrchr(optarg, '/'); + +#ifdef _XBT_WIN32 + if (!delimiter) + delimiter = strrchr(optarg, '\\'); +#endif + + /* create a new file stream which represents the tesh file to run */ + fstream = fstream_new(path, delimiter ? delimiter + 1 : optarg); + + free(path); + + /* if the list of all tesh files to run already contains this file + * destroy it and display a warning, otherwise add it in the list. + */ + if (fstreams_contains(fstreams, fstream)) { + fstream_free(&fstream); + WARN1("File %s already specified to be run", optarg); + } else + fstreams_add(fstreams, fstream); + + } else if (c == '?') { + /* unknown option, let getopt_long() displays the error */ + ERROR0("Command line processing failed : invalid command line"); + exit_code = EINVCMDLINE; + err_kind = 1; + return -1; + } else { + for (entry = opt_entries; entry->c != '\0'; ++entry) + + if (c == entry->c) { + + switch (entry->type) { + /* impossible */ + default: + ERROR0("Command line processing failed : internal error"); + exit_code = EPROCCMDLINE; + err_kind = 1; + return -1; + + + /* flag options */ + case flag: + /* set the flag to one */ + *(int *) entry->value = 1; + + break; + + /* string options */ + case string: + + if (!optarg) { + /* an option with a optional arg is specified use the entry->optional_value */ + optarg = (char *) entry->optional_value; + } else if (*optarg == '\0') { + /* a non optional argument is not specified */ + ERROR2("Option %c \"%s\"requires an argument", entry->c, + entry->long_name); + exit_code = ENOARG; + err_kind = 1; + return -1; + } + + /* --load-directory option */ + if (!strcmp(entry->long_name, "load-directory")) { + char *path; + + if (translatepath(optarg, &path) < 0) { + exit_code = errno; + err_kind = 0; + + if (ENOTDIR == errno) + ERROR1("%s is not a directory", optarg); + else + ERROR0 + ("Insufficient memory is available to process the command line - system error"); + + return -1; + + } else { + + directory = directory_new(path); + free(path); + + if (directories_contains(directories, directory)) { + directory_free((void **) &directory); + WARN1("Directory %s already specified to be load", + optarg); + } else + directories_add(directories, directory); + + + } + } else if (!strcmp(entry->long_name, "directory")) { + char *path; + + if (translatepath(optarg, &path) < 0) { + exit_code = errno; + err_kind = 0; + + if (ENOTDIR == errno) + ERROR1("%s is not a directory", optarg); + else + ERROR0 + ("Insufficient memory is available to process the command line - system error"); + + return -1; + } else { + char *buffer = getcwd(NULL, 0); + + + if (!strcmp(buffer, path)) + WARN1("Already in the directory %s", optarg); + else if (!print_directory_flag) + INFO1("Entering directory \"%s\"", path); + + chdir(path); + free(path); + + free(buffer); + } + } + + /* --suffix option */ + else if (!strcmp(entry->long_name, "suffix")) { + if (strlen(optarg) > MAX_SUFFIX) { + ERROR1("Suffix %s too long", optarg); + exit_code = ESUFFIXTOOLONG; + err_kind = 1; + return -1; + } + + if (optarg[0] == '.') { + char *cur; + unsigned int i; + int exists = 0; + + char *suffix = xbt_new0(char, MAX_SUFFIX + 2); + sprintf(suffix, ".%s", optarg); + + xbt_dynar_foreach(suffixes, i, cur) { + if (!strcmp(suffix, cur)) { + exists = 1; + break; + } + } + + if (exists) + WARN1("Suffix %s already specified to be used", optarg); + else + xbt_dynar_push(suffixes, &suffix); + } else { + char *cur; + unsigned int i; + int exists = 0; + + xbt_dynar_foreach(suffixes, i, cur) { + if (!strcmp(optarg, cur)) { + exists = 1; + break; + } + } + + if (exists) + WARN1("Suffix %s already specified to be used", optarg); + else { + char *suffix = strdup(optarg); + xbt_dynar_push(suffixes, &suffix); + } + } + } + /* --file option */ + else if (!strcmp(entry->long_name, "file")) { + char *path; + char *delimiter; + + if (getpath(optarg, &path) < 0) { + exit_code = errno; + err_kind = 0; + + if (ENOENT == errno) + ERROR1("File %s does not exist", optarg); + else + ERROR1("System error :`(%s)'", strerror(errno)); + + return -1; + } + + delimiter = strrchr(optarg, '/'); + +#ifdef _XBT_WIN32 + if (!delimiter) + delimiter = strrchr(optarg, '\\'); +#endif + + fstream = + fstream_new(path, delimiter ? delimiter + 1 : optarg); + + free(path); + + if (fstreams_contains(fstreams, fstream)) { + fstream_free(&fstream); + WARN1("File %s already specified to run", optarg); + } else + fstreams_add(fstreams, fstream); + } + /* --include-dir option */ + else if (!strcmp(entry->long_name, "include-dir")) { + + char *path; + + if (translatepath(optarg, &path) < 0) { + exit_code = errno; + err_kind = 0; + + if (ENOTDIR == errno) + ERROR1("%s is not a directory", optarg); + else + ERROR0 + ("Insufficient memory is available to process the command line - system error"); + + return -1; + } + + else { + int exists = 0; + unsigned int i; + directory_t cur; + directory = directory_new(path); + free(path); + + xbt_dynar_foreach(include_dirs, i, cur) { + if (!strcmp(cur->name, optarg)) { + exists = 1; + break; + } + } + + if (exists) { + directory_free((void **) &directory); + WARN1 + ("Include directory %s already specified to be used", + optarg); + + } else + xbt_dynar_push(include_dirs, &directory); + + } + } + /* --exclude option */ + else if (!strcmp(entry->long_name, "exclude")) { + char *path; + char *delimiter; + + if (getpath(optarg, &path) < 0) { + exit_code = errno; + err_kind = 0; + + if (ENOENT == errno) + ERROR1("file %s does not exist", optarg); + else + ERROR0 + ("Insufficient memory is available to process the command line - system error"); + + return -1; + } + + delimiter = strrchr(optarg, '/'); + +#ifdef _XBT_WIN32 + if (!delimiter) + delimiter = strrchr(optarg, '\\'); +#endif + + fstream = + fstream_new(path, delimiter ? delimiter + 1 : optarg); + free(path); + + if (excludes_contains(excludes, fstream)) { + fstream_free(&fstream); + WARN1("File %s already specified to be exclude", optarg); + } else + excludes_add(excludes, fstream); + + } else if (!strcmp(entry->long_name, "log")) { + /* NOTHING TODO : log for xbt */ + } else { + INFO1("Unexpected option %s", optarg); + return -1; + } + + + break; + + /* strictly positve number options */ + case number: + + if ((NULL == optarg) && (argc > optind)) { + const char *cp; + + for (cp = argv[optind]; isdigit(cp[0]); ++cp) + if (cp[0] == '\0') + optarg = argv[optind++]; + } + + /* the number option is specified */ + if (NULL != optarg) { + int i = atoi(optarg); + const char *cp; + + for (cp = optarg; isdigit(cp[0]); ++cp); + + if (i < 1 || cp[0] != '\0') { + ERROR2 + ("Option %c \"%s\" requires an strictly positive integer as argument", + entry->c, entry->long_name); + exit_code = ENOTPOSITIVENUM; + err_kind = 1; + return -1; + } else + *(int *) entry->value = i; + } + /* the number option is specified but has no arg, use the optional value */ + else + *(int *) entry->value = *(int *) entry->optional_value; + + break; + + } + break; + } + } + } + + return 0; } -static void -print_usage(void) +static void print_usage(void) { - const char **cpp; - FILE* stream; - - stream = exit_code ? stderr : stdout; - - if(!screen_cleaned) - { - #ifdef _XBT_WIN32 - system("cls"); - #else - system("clear"); - #endif - screen_cleaned = 1; - } - - fprintf (stream, "Usage: tesh [options] [file] ...\n"); - - for (cpp = usage; *cpp; ++cpp) - fputs (*cpp, stream); - - fprintf(stream, "\nReport bugs to \n"); + const char **cpp; + FILE *stream; + + stream = exit_code ? stderr : stdout; + + if (!screen_cleaned) { +#ifdef _XBT_WIN32 + system("cls"); +#else + system("clear"); +#endif + screen_cleaned = 1; + } + + fprintf(stream, "Usage: tesh [options] [file] ...\n"); + + for (cpp = usage; *cpp; ++cpp) + fputs(*cpp, stream); + + fprintf(stream, + "\nReport bugs to \n"); } -static void -print_version(void) +static void print_version(void) { - if(!screen_cleaned) - { - #ifdef _XBT_WIN32 - system("cls"); - #else - system("clear"); - #endif - screen_cleaned = 1; - } - - /* TODO : display the version of tesh */ - printf("Version :\n"); - printf(" tesh version %s : Mini shell specialized in running test units by Martin Quinson \n", version); - printf(" and Malek Cherier\n"); - printf(" Copyright (c) 2007, 2008 Martin Quinson, Malek Cherier\n"); - printf(" All rights reserved\n"); - printf(" This program is free software; you can redistribute it and/or modify it\n"); - printf(" under the terms of the license (GNU LGPL) which comes with this package.\n\n"); - - if(!print_usage_flag) - printf("Report bugs to "); + if (!screen_cleaned) { +#ifdef _XBT_WIN32 + system("cls"); +#else + system("clear"); +#endif + screen_cleaned = 1; + } + + /* TODO : display the version of tesh */ + printf("Version :\n"); + printf + (" tesh version %s : Mini shell specialized in running test units by Martin Quinson \n", + version); + printf(" and Malek Cherier\n"); + printf(" Copyright (c) 2007, 2008 Martin Quinson, Malek Cherier\n"); + printf(" All rights reserved\n"); + printf + (" This program is free software; you can redistribute it and/or modify it\n"); + printf + (" under the terms of the license (GNU LGPL) which comes with this package.\n\n"); + + if (!print_usage_flag) + printf + ("Report bugs to "); } -static void -print_readme(void) +static void print_readme(void) { - size_t len; - char * line = NULL; - - FILE* stream = fopen("examples/README.tesh", "r"); - - if(!stream) - { - ERROR0("Unable to locate the README.txt file"); - exit_code = EREADMENOTFOUND; - err_kind = 1; - return; - } - - while(getline(&line, &len, stream) != -1) - printf("%s",line); - - fclose(stream); -} + size_t len; + char *line = NULL; + + FILE *stream = fopen("examples/README.tesh", "r"); + if (!stream) { + ERROR0("Unable to locate the README.txt file"); + exit_code = EREADMENOTFOUND; + err_kind = 1; + return; + } + while (getline(&line, &len, stream) != -1) + printf("%s", line); + + fclose(stream); +} diff --git a/tools/tesh2/src/reader.c b/tools/tesh2/src/reader.c index 6aa254ae7e..1d37853a17 100644 --- a/tools/tesh2/src/reader.c +++ b/tools/tesh2/src/reader.c @@ -10,255 +10,251 @@ * This file contains all the definitions of the functions related with * the tesh reader type. * - */ - + */ + #include #include #include - - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - - -static void* -reader_start_routine(void* p); - -reader_t -reader_new(command_t command) -{ - reader_t reader; - - /* TODO : check the parameter */ - - reader = xbt_new0(s_reader_t, 1); - - reader->thread = NULL; - reader->command = command; - reader->broken_pipe = 0; - reader->failed = 0; - reader->done = 0; - - reader->started = xbt_os_sem_init(0); - - return reader; -} - -int -reader_free(reader_t* ptr) -{ - if((*ptr)->started) - xbt_os_sem_destroy((*ptr)->started); - - free(*ptr); - - *ptr = NULL; - - return 0; -} - -void -reader_read(reader_t reader) -{ - reader->thread = xbt_os_thread_create("", reader_start_routine, reader); -} - + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + static void * reader_start_routine(void *p); + reader_t reader_new(command_t command) +{ + reader_t reader; + + /* TODO : check the parameter */ + reader = xbt_new0(s_reader_t, 1); + reader->thread = NULL; + reader->command = command; + reader->broken_pipe = 0; + reader->failed = 0; + reader->done = 0; + reader->started = xbt_os_sem_init(0); + return reader; + } + + int reader_free(reader_t * ptr) +{ + if ((*ptr)->started) + xbt_os_sem_destroy((*ptr)->started); + free(*ptr); + *ptr = NULL; + return 0; + } + + void reader_read(reader_t reader) +{ + reader->thread = xbt_os_thread_create("", reader_start_routine, reader); + } + #ifdef _XBT_WIN32 -static void* -reader_start_routine(void* p) -{ - reader_t reader = (reader_t)p; - command_t command = reader->command; - - xbt_strbuff_t output = command->output; - HANDLE stdout_fd = command->stdout_fd; - - DWORD number_of_bytes_to_read = 1024; /*command->context->output->used;*/ - DWORD number_of_bytes_readed = 0; - - char* buffer = (char*)calloc(number_of_bytes_to_read + 1,sizeof(char)); - char* clean = (char*)calloc(number_of_bytes_to_read + 1,sizeof(char)); - size_t i, j; - - xbt_os_sem_release(reader->started); - - while(!command->failed && !command->interrupted && !command->successeded && !reader->failed && !reader->broken_pipe) - { - if(!ReadFile(stdout_fd, buffer, number_of_bytes_to_read, &number_of_bytes_readed, NULL) || (0 == number_of_bytes_readed)) - { - if(GetLastError() == ERROR_BROKEN_PIPE) - reader->broken_pipe = 1; - else - reader->failed = 1; - - } - else - { - if(number_of_bytes_readed > 0) - { - for(i= 0, j= 0; i < number_of_bytes_readed; i++) - if((buffer[i]) != '\r') - clean[j++] = buffer[i]; - - xbt_strbuff_append(output,clean); - - memset(buffer, 0, 1024); - memset(clean, 0, 1024); - } - else - { - xbt_os_thread_yield(); - } - } - } - - free(clean); - free(buffer); - - xbt_strbuff_chomp(command->output); - xbt_strbuff_trim(command->output); - - reader->done = 1; - - if(command->failed) - { - if(command->reason == csr_write_failure) - { - if(command->output->used) - INFO2("[%s] Output on write failure:\n%s",command->context->pos, command->output->data); - else - INFO1("[%s] No output before write failure",command->context->pos); - } - else if(command->reason == csr_write_pipe_broken) - { - if(command->output->used) - INFO2("[%s] Output on broken pipe:\n%s",command->context->pos, command->output->data); - else - INFO1("[%s] No output before broken pipe",command->context->pos); - } - } - else if(command->interrupted) - { - if(command->output->used) - INFO2("[%s] Output on interruption:\n%s",command->context->pos, command->output->data); - else - INFO1("[%s] No output before interruption",command->context->pos); - } - else if(reader->failed && !command->failed && !command->interrupted && !command->successeded) - { - ERROR2("[%s] Error while reading output of child `%s'", command->context->pos, command->context->command_line); - - if(command->output->used) - INFO2("[%s] Output on read failure:\n%s",command->context->pos, command->output->data); - else - INFO1("[%s] No output before read failure",command->context->pos); - - unit_set_error(command->unit, errno, 0, command->context->pos); - command_kill(command); - command_handle_failure(command, csr_read_failure); - } - - - - return NULL; -} - -#else -static void* -reader_start_routine(void* p) -{ - reader_t reader = (reader_t)p; - command_t command = reader->command; - xbt_strbuff_t output = command->output; - int stdout_fd = command->stdout_fd; - int number_of_bytes_readed; - int number_of_bytes_to_read = (1024 > SSIZE_MAX) ? SSIZE_MAX : 1024; - - int total = 0; - - char* buffer = (char*)calloc(number_of_bytes_to_read,sizeof(char)); - xbt_os_sem_release(reader->started); - - do - { - number_of_bytes_readed = read(stdout_fd, buffer, number_of_bytes_to_read); - - if(number_of_bytes_readed < 0 && errno != EINTR && errno != EAGAIN) - { - reader->failed = 1; - } - - if(number_of_bytes_readed > 0) - { - buffer[number_of_bytes_readed]='\0'; - xbt_strbuff_append(output,buffer); - total += total; - } - else - { - xbt_os_thread_yield(); - } - - }while(!command->failed && !command->interrupted && !command->successeded && !reader->failed && (number_of_bytes_readed != 0 /* end of file <-> normal exit */)); - - free(buffer); - - if(close(command->stdout_fd) < 0) - { - /* TODO */ - } - else - command->stdout_fd = INDEFINITE_FD; - - xbt_strbuff_chomp(command->output); - xbt_strbuff_trim(command->output); - - reader->done = 1; - - if(command->failed) - { - if(command->reason == csr_write_failure) - { - if(command->output->used) - INFO2("[%s] Output on write failure:\n%s",command->context->pos, command->output->data); - else - INFO1("[%s] No output before write failur",command->context->pos); - } - else if(command->reason == csr_write_pipe_broken) - { - if(command->output->used) - INFO2("[%s] Output on broken pipe:\n%s",command->context->pos, command->output->data); - else - INFO1("[%s] No output before broken pipe",command->context->pos); - } - } - else if(command->interrupted) - { - if(command->output->used) - INFO2("[%s] Output on interruption:\n%s",command->context->pos, command->output->data); - else - INFO1("[%s] No output before interruption",command->context->pos); - } - else if(reader->failed && !command->failed && !command->interrupted && !command->successeded) - { - ERROR2("[%s] Error while reading output of child `%s'", command->context->pos, command->context->command_line); - - if(command->output->used) - INFO2("[%s] Output on read failure:\n%s",command->context->pos, command->output->data); - else - INFO1("[%s] No output before read failure",command->context->pos); - - unit_set_error(command->unit, errno, 0, command->context->pos); - command_kill(command); - command_handle_failure(command, csr_read_failure); - } - - - return NULL; -} -#endif +static void * reader_start_routine(void *p) +{ + reader_t reader = (reader_t) p; + command_t command = reader->command; + xbt_strbuff_t output = command->output; + HANDLE stdout_fd = command->stdout_fd; + DWORD number_of_bytes_to_read = 1024; /*command->context->output->used; */ + DWORD number_of_bytes_readed = 0; + char *buffer = + (char *) calloc(number_of_bytes_to_read + 1, sizeof(char)); + char *clean = + (char *) calloc(number_of_bytes_to_read + 1, sizeof(char)); + size_t i, j; + xbt_os_sem_release(reader->started); + while (!command->failed && !command->interrupted + && !command->successeded && !reader->failed + && !reader->broken_pipe) + { + if (!ReadFile + (stdout_fd, buffer, number_of_bytes_to_read, + &number_of_bytes_readed, NULL) || (0 == number_of_bytes_readed)) + { + if (GetLastError() == ERROR_BROKEN_PIPE) + reader->broken_pipe = 1; + + else + reader->failed = 1; + } + + else + { + if (number_of_bytes_readed > 0) + { + for (i = 0, j = 0; i < number_of_bytes_readed; i++) + if ((buffer[i]) != '\r') + clean[j++] = buffer[i]; + xbt_strbuff_append(output, clean); + memset(buffer, 0, 1024); + memset(clean, 0, 1024); + } + + else + { + xbt_os_thread_yield(); + } + } + } + free(clean); + free(buffer); + xbt_strbuff_chomp(command->output); + xbt_strbuff_trim(command->output); + reader->done = 1; + if (command->failed) + { + if (command->reason == csr_write_failure) + { + if (command->output->used) + INFO2("[%s] Output on write failure:\n%s", command->context->pos, + command->output->data); + + else + INFO1("[%s] No output before write failure", + command->context->pos); + } + + else if (command->reason == csr_write_pipe_broken) + { + if (command->output->used) + INFO2("[%s] Output on broken pipe:\n%s", command->context->pos, + command->output->data); + + else + INFO1("[%s] No output before broken pipe", command->context->pos); + } + } + + else if (command->interrupted) + { + if (command->output->used) + INFO2("[%s] Output on interruption:\n%s", command->context->pos, + command->output->data); + + else + INFO1("[%s] No output before interruption", command->context->pos); + } + + else if (reader->failed && !command->failed && !command->interrupted + && !command->successeded) + { + ERROR2("[%s] Error while reading output of child `%s'", + command->context->pos, command->context->command_line); + if (command->output->used) + INFO2("[%s] Output on read failure:\n%s", command->context->pos, + command->output->data); + + else + INFO1("[%s] No output before read failure", command->context->pos); + unit_set_error(command->unit, errno, 0, command->context->pos); + command_kill(command); + command_handle_failure(command, csr_read_failure); + } + return NULL; + } + + +#else /* */ +static void * reader_start_routine(void *p) +{ + reader_t reader = (reader_t) p; + command_t command = reader->command; + xbt_strbuff_t output = command->output; + int stdout_fd = command->stdout_fd; + int number_of_bytes_readed; + int number_of_bytes_to_read = (1024 > SSIZE_MAX) ? SSIZE_MAX : 1024; + int total = 0; + char *buffer = (char *) calloc(number_of_bytes_to_read, sizeof(char)); + xbt_os_sem_release(reader->started); + + do + { + number_of_bytes_readed = + read(stdout_fd, buffer, number_of_bytes_to_read); + if (number_of_bytes_readed < 0 && errno != EINTR && errno != EAGAIN) + { + reader->failed = 1; + } + if (number_of_bytes_readed > 0) + { + buffer[number_of_bytes_readed] = '\0'; + xbt_strbuff_append(output, buffer); + total += total; + } + + else + { + xbt_os_thread_yield(); + } + } while (!command->failed && !command->interrupted + && !command->successeded && !reader->failed + && (number_of_bytes_readed != + 0 /* end of file <-> normal exit */ )); + free(buffer); + if (close(command->stdout_fd) < 0) + { + + /* TODO */ + } + + else + command->stdout_fd = INDEFINITE_FD; + xbt_strbuff_chomp(command->output); + xbt_strbuff_trim(command->output); + reader->done = 1; + if (command->failed) + { + if (command->reason == csr_write_failure) + { + if (command->output->used) + INFO2("[%s] Output on write failure:\n%s", command->context->pos, + command->output->data); + + else + INFO1("[%s] No output before write failur", + command->context->pos); + } + + else if (command->reason == csr_write_pipe_broken) + { + if (command->output->used) + INFO2("[%s] Output on broken pipe:\n%s", command->context->pos, + command->output->data); + + else + INFO1("[%s] No output before broken pipe", command->context->pos); + } + } + + else if (command->interrupted) + { + if (command->output->used) + INFO2("[%s] Output on interruption:\n%s", command->context->pos, + command->output->data); + + else + INFO1("[%s] No output before interruption", command->context->pos); + } + + else if (reader->failed && !command->failed && !command->interrupted + && !command->successeded) + { + ERROR2("[%s] Error while reading output of child `%s'", + command->context->pos, command->context->command_line); + if (command->output->used) + INFO2("[%s] Output on read failure:\n%s", command->context->pos, + command->output->data); + + else + INFO1("[%s] No output before read failure", command->context->pos); + unit_set_error(command->unit, errno, 0, command->context->pos); + command_kill(command); + command_handle_failure(command, csr_read_failure); + } + return NULL; + } + -void -reader_wait(reader_t reader) -{ - xbt_os_thread_join(reader->thread, NULL); -} +#endif /* */ + void reader_wait(reader_t reader) +{ + xbt_os_thread_join(reader->thread, NULL); + } diff --git a/tools/tesh2/src/readline.c b/tools/tesh2/src/readline.c index 6a2c674340..02abf77feb 100644 --- a/tools/tesh2/src/readline.c +++ b/tools/tesh2/src/readline.c @@ -2,79 +2,69 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); -long -readline(FILE* stream, char **buf, size_t *n) +long readline(FILE * stream, char **buf, size_t * n) { - size_t i; - int ch; - int cr = 0; - fpos_t pos; - - if (!*buf) { - *buf = calloc(512, sizeof(char)); - *n = 512; - } - - if (feof(stream)) - return (ssize_t)-1; - - for (i=0; (ch = fgetc(stream)) != EOF; i++) - { - if (i >= (*n) + 1) - *buf = xbt_realloc(*buf, *n += 512); - - - (*buf)[i] = ch; - - if(cr && (*buf)[i] != '\n') - { - /* old Mac os uses CR */ - i--; - (*buf)[i] = '\n'; - - /* move to the previous pos (pos of the CR) */ - fsetpos(stream, &pos); - - /* process as linux now */ - cr --; - } - - if((*buf)[i] == '\n') - { - if(cr) - { - /* Windows uses CRLF */ - (*buf)[i - 1] = '\n'; - (*buf)[i] = '\0'; - break; - } - else - { - /* Unix use LF */ - i++; - (*buf)[i] = '\0'; - break; - } - } - else if(ch == '\r') - { - cr ++; - - /* register the CR position for mac */ - fgetpos(stream, &pos); - } - } - - - if (i == *n) - *buf = xbt_realloc(*buf, *n += 1); - - /* Mac os file ended with a blank line */ - if(ch == EOF && (*buf)[i - 1] == '\r') - (*buf)[i - 1] = '\n'; - - (*buf)[i] = '\0'; - - return (ssize_t)i; -} + size_t i; + int ch; + int cr = 0; + fpos_t pos; + + if (!*buf) { + *buf = calloc(512, sizeof(char)); + *n = 512; + } + + if (feof(stream)) + return (ssize_t) - 1; + + for (i = 0; (ch = fgetc(stream)) != EOF; i++) { + if (i >= (*n) + 1) + *buf = xbt_realloc(*buf, *n += 512); + + + (*buf)[i] = ch; + + if (cr && (*buf)[i] != '\n') { + /* old Mac os uses CR */ + i--; + (*buf)[i] = '\n'; + + /* move to the previous pos (pos of the CR) */ + fsetpos(stream, &pos); + /* process as linux now */ + cr--; + } + + if ((*buf)[i] == '\n') { + if (cr) { + /* Windows uses CRLF */ + (*buf)[i - 1] = '\n'; + (*buf)[i] = '\0'; + break; + } else { + /* Unix use LF */ + i++; + (*buf)[i] = '\0'; + break; + } + } else if (ch == '\r') { + cr++; + + /* register the CR position for mac */ + fgetpos(stream, &pos); + } + } + + + if (i == *n) + *buf = xbt_realloc(*buf, *n += 1); + + /* Mac os file ended with a blank line */ + if (ch == EOF && (*buf)[i - 1] == '\r') + (*buf)[i - 1] = '\n'; + + (*buf)[i] = '\0'; + + return (ssize_t) i; +} diff --git a/tools/tesh2/src/runner.c b/tools/tesh2/src/runner.c index 35f06916b3..39babd4b42 100644 --- a/tools/tesh2/src/runner.c +++ b/tools/tesh2/src/runner.c @@ -10,697 +10,593 @@ * This file contains all the definitions of the functions related with * the tesh runner type. * - */ + */ #include #include #include #include #include - + #include /* for error code */ #include /* for calloc() */ #include - + #include #include - + #ifndef _XBT_WIN32 #include -#endif - - - - - +#endif /* */ + #define _RUNNER_HASHCODE 0xFEFEAAAA - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + #if (!defined(__BUILTIN) && defined(__CHKCMD) && !defined(_XBT_WIN32)) -static const char* builtin[] = -{ - "alias", - "bind", - "builtin", - "caller", - "cd", - "command", - "compgen", - "complete", - "declare", - "disown", - "echo", - "enable", - "eval", - "exec", - "export", - "false", - "fc", - "function", - "getopts", - "hash", - "history", - "jobs", - "let", - "logout", - "printf", - "pwd", - "readonly", - "shift", - "shopt", - "source", - "suspend", - "test", - "time", - "times", - "trap", - "true", - "type", - "typeset", - "ulimit", - "umask", - "unalias", - "unset", - NULL -}; - +static const char *builtin[] = + { "alias", "bind", "builtin", "caller", "cd", "command", + "compgen", "complete", "declare", "disown", "echo", "enable", "eval", "exec", "export", + "false", "fc", "function", "getopts", "hash", "history", "jobs", "let", "logout", + "printf", "pwd", "readonly", "shift", "shopt", "source", "suspend", "test", "time", + "times", "trap", "true", "type", "typeset", "ulimit", "umask", "unalias", "unset", + NULL +}; + + #define __BUILTIN_MAX ((size_t)42) -#endif - - +#endif /* */ + # ifdef __APPLE__ -/* under darwin, the environment gets added to the process at startup time. So, it's not defined at library link time, forcing us to extra tricks */ +/* under darwin, the environment gets added to the process at startup time. So, it's not defined at library link time, forcing us to extra tricks */ # include # define environ (*_NSGetEnviron()) # else - #ifdef _XBT_WIN32 - /* the environment, as specified by the opengroup, used to initialize the process properties */ - # define environ **wenviron; - #else - extern char **environ; - #endif -# endif +#ifdef _XBT_WIN32 + /* the environment, as specified by the opengroup, used to initialize the process properties */ +# define environ **wenviron; +#else /* */ +extern char **environ; +#endif /* */ +# endif + #ifndef _XBT_WIN32 -extern char** -environ; -#endif - -/* the unique tesh runner */ -static runner_t -runner = NULL; - -/* wait for the tesh runner terminaison */ -static void -runner_wait(void); - -static void* -runner_start_routine(void* p); - +extern char ** environ; +#endif /* */ + +/* the unique tesh runner */ +static runner_t runner = NULL; + +/* wait for the tesh runner terminaison */ +static void runner_wait(void); + static void * runner_start_routine(void *p); + /* check the syntax of the tesh files if * the check_syntax_flag is specified. Returns * 0 if the syntax is clean. - */ + */ /*static void -check_syntax(void);*/ - +check_syntax(void);*/ + #ifdef _XBT_WIN32 - -static HANDLE -timer_handle = NULL; - - -static void* -runner_start_routine(void* p) -{ - - LARGE_INTEGER li; - - li.QuadPart=- runner->timeout * 10000000; /* 10000000 = 10 000 000 * 100 nanoseconds = 1 second */ - - /* create the waitable timer */ - timer_handle = CreateWaitableTimer(NULL, TRUE, NULL); - - /* set a timer to wait for timeout seconds */ - SetWaitableTimer(timer_handle, &li, 0, NULL, NULL, 0); + static HANDLE timer_handle = NULL; + static void * runner_start_routine(void *p) +{ + LARGE_INTEGER li; + li.QuadPart = -runner->timeout * 10000000; /* 10000000 = 10 000 000 * 100 nanoseconds = 1 second */ + + /* create the waitable timer */ + timer_handle = CreateWaitableTimer(NULL, TRUE, NULL); + + /* set a timer to wait for timeout seconds */ + SetWaitableTimer(timer_handle, &li, 0, NULL, NULL, 0); + + /* wait for the timer */ + WaitForSingleObject(timer_handle, INFINITE); + if (runner->waiting) + { + exit_code = ELEADTIME; + err_kind = 1; + runner->timeouted = 1; + xbt_os_sem_release(units_sem); + } + return NULL; + } + + +#else /* */ +static void * runner_start_routine(void *p) +{ + struct timespec ts; + int timeout = runner->timeout; + while (timeout-- && runner->waiting) + { + ts.tv_sec = 1; + ts.tv_nsec = 0L; + + do + { + nanosleep(&ts, &ts); + } while (EINTR == errno); + } + if (errno) + { - /* wait for the timer */ - WaitForSingleObject(timer_handle, INFINITE); - - if(runner->waiting) - { - exit_code = ELEADTIME; - err_kind = 1; - runner->timeouted = 1; - xbt_os_sem_release(units_sem); - } - - return NULL; -} - -#else -static void* -runner_start_routine(void* p) -{ - struct timespec ts; - int timeout = runner->timeout; - - - while(timeout-- && runner->waiting) - { - ts.tv_sec = 1; - ts.tv_nsec = 0L; - - do - { - nanosleep(&ts, &ts); - }while(EINTR == errno); - } - - if(errno) - { - /* TODO process the error */ - } - else - { - if(runner->waiting) - { - exit_code = ELEADTIME; - err_kind = 1; - runner->timeouted = 1; - xbt_os_sem_release(units_sem); - } - } - - return NULL; -} -#endif - - -int -runner_init(/*int check_syntax_flag, */int timeout, fstreams_t fstreams) -{ - - int i; - char* val; - char buffer[PATH_MAX + 1] = {0}; - - int code; - const char* cstr; - variable_t variable; - - #if (defined(__CHKCMD) && defined(__BUILTIN) && !defined(_XBT_WIN32)) - FILE* s; - int n = 0; - size_t len; - char* line = NULL; - int is_blank; - #endif - - - if(runner) - { - ERROR0("The runner is already initialized"); - return -1; - } - - runner = xbt_new0(s_runner_t, 1); - - runner->path = NULL; - runner->builtin = NULL; - - if(!(runner->units = units_new(runner, fstreams))) - { - free(runner); - runner = NULL; - return -1; - } - - runner->timeout = timeout; - runner->timeouted = 0; - runner->interrupted = 0; - runner->number_of_ended_units = 0; - runner->number_of_runned_units = 0; - runner->waiting = 0; - - runner->total_of_tests = 0; - runner->total_of_successeded_tests = 0; - runner->total_of_failed_tests = 0; - runner->total_of_interrupted_tests = 0; - - runner->total_of_units = 0; - runner->total_of_successeded_units = 0; - runner->total_of_failed_units = 0; - runner->total_of_interrupted_units = 0; - - runner->total_of_suites = 0; - runner->total_of_successeded_suites = 0; - runner->total_of_failed_suites = 0; - runner->total_of_interrupted_suites = 0; - - /* initialize the vector of variables */ - runner->variables = xbt_dynar_new(sizeof(variable_t), (void_f_pvoid_t)variable_free); - - /* add the environment variables in the vector */ - for(i = 0; environ[i] != NULL; i++) - { - val = strchr(environ[i], '='); - - if(val) - { - val++; - - if(val[0] != '\0') - strncpy(buffer, environ[i], (val - environ[i] -1)); - - if(!strcmp("TESH_PPID", buffer)) - is_tesh_root = 0; - - variable = variable_new(buffer, val); - variable->env = 1; - xbt_dynar_push(runner->variables, &variable); - - #ifndef _XBT_WIN32 - if(!strcmp("PATH", buffer)) - #else - if(!strcmp("Path", buffer) || !strcmp("PATH", buffer)) - #endif - { - char* p; - size_t j,k, len; - - /* get the list of paths */ - - #ifdef _XBT_WIN32 - runner->path = explode(';', val); - #else - runner->path = explode(':', val); - #endif - - /* remove spaces and backslahes at the end of the path */ - for (k = 0; runner->path[k] != NULL; k++) - { - p = runner->path[k]; - - len = strlen(p); - - #ifndef _XBT_WIN32 - for(j = len - 1; p[j] == '/' || p[j] == ' '; j--) - #else - for(j = len - 1; p[j] == '\\' || p[j] == ' '; j--) - #endif - p[j] = '\0'; - } - } - - - memset(buffer, 0, PATH_MAX + 1); - } - } - - if(is_tesh_root) - { - char* tesh_dir = getcwd(NULL, 0); - - sprintf(buffer,"%d",getpid()); - - #ifndef _XBT_WIN32 - setenv("TESH_PPID", buffer, 0); - setenv("TESH_DIR", tesh_dir, 0); - #else - SetEnvironmentVariable("TESH_PPID", buffer); - SetEnvironmentVariable("TESH_DIR", tesh_dir); - #endif - - variable = variable_new("TESH_PPID", buffer); - variable->err = 1; - - xbt_dynar_push(runner->variables, &variable); - - variable = variable_new("TESH_DIR", tesh_dir); - variable->err = 1; - - xbt_dynar_push(runner->variables, &variable); - - free(tesh_dir); - } - - variable = variable_new("EXIT_SUCCESS", "0"); - variable->err = 1; - - xbt_dynar_push(runner->variables, &variable); - - variable = variable_new("EXIT_FAILURE", "1"); - variable->err = 1; - - xbt_dynar_push(runner->variables, &variable); - - variable = variable_new("TRUE", "0"); - variable->err = 1; - - xbt_dynar_push(runner->variables, &variable); - - variable = variable_new("FALSE", "1"); - variable->err = 1; - - xbt_dynar_push(runner->variables, &variable); - - i = 0; - - /* add the errors variables */ - while((cstr = error_get_at(i++, &code))) - { - sprintf(buffer,"%d",code); - variable = variable_new(cstr, buffer); - variable->err = 1; - xbt_dynar_push(runner->variables, &variable); - } - - /* if the user want check the syntax, check it */ - /*if(check_syntax_flag) - check_syntax(); - */ - - #if (!defined(_XBT_WIN32) && defined(__CHKCMD)) - #if defined(__BUILTIN) - - if(!is_tesh_root) - { - /* compute the full path the builtin.def file */ - sprintf(buffer,"%s/builtin.def",getenv("TESH_DIR")); - - if(!(s = fopen(buffer, "r"))) - { - ERROR1("File `(%s)' not found", buffer); - return -1; - } - - } - else - { - if(!(s = fopen("builtin.def", "r"))) - { - ERROR0("File `(builtin.def)' not found"); - return -1; - } - } - - if(s) - { - fpos_t begin; - - fgetpos(s, &begin); - - while(readline(s, &line, &len) != -1) - { - i = 0; - is_blank = 1; - - - while(line[i] != '\0') - { - if (line[i] != ' ' && line[i] != '\t' && line[i]!='\n' && line[i]!='\r') - { - is_blank = 0; - break; - } - - i++; - } - - if(!is_blank) - n++; - } - - fsetpos(s, &begin); - free(line); - line = NULL; - - if(n) - { - char* l; - - runner->builtin = xbt_new0(char*, n + 1); /* (char**) calloc(n + 1, sizeof(char*));*/ - - n = 0; - - while(readline(s, &line, &len) != -1) - { - i = 0; - is_blank = 1; - - while(line[i] != '\0') - { - if (line[i] != ' ' && line[i] != '\t' && line[i]!='\n' && line[i]!='\r') - { - is_blank = 0; - break; - } - - i++; - } - - if(!is_blank) - { - l = strdup(line); - - l[strlen(l) - 1] = '\0'; - - (runner->builtin)[n++] = l; - - } - } - - } - else - { - WARN0("The file `(builtin.def)' is empty"); - free(runner->builtin); - runner->builtin = NULL; - } - - - fclose(s); - - if(line) - free(line); - - } - - #else - runner->builtin = xbt_new0(char*, __BUILTIN_MAX + 1); /* (char**) calloc(__BUILTIN_MAX + 1, sizeof(char*));*/ - - for(i = 0; i < __BUILTIN_MAX; i++) - runner->builtin[i] = strdup(builtin[i]); - #endif - #endif - - return exit_code ? -1 : 0; -} - -void -runner_destroy(void) -{ - int i; - - if(runner->units) - units_free((void**)(&(runner->units))); - - if(runner->variables) - xbt_dynar_free(&runner->variables); - - #ifdef _XBT_WIN32 - CloseHandle(timer_handle); - #endif - - if(runner->thread) - xbt_os_thread_join(runner->thread, NULL); - - if(runner->path) - { - for (i = 0; runner->path[i] != NULL; i++) - free(runner->path[i]); - - free(runner->path); - } - - if(runner->builtin) - { - for (i = 0; runner->builtin[i] != NULL; i++) - free(runner->builtin[i]); - - free(runner->builtin); - } - - free(runner); - - - runner = NULL; -} - -void -runner_run(void) -{ - /* allocate the mutex used by the units to asynchronously access - * to the properties of the runner. - */ - xbt_os_mutex_t mutex = xbt_os_mutex_init(); - - /* run all the units */ - units_run_all(runner->units, mutex); - - - if(!interrupted) - runner_wait(); - - - /* if the runner is timeouted or receive a interruption request - * , interrupt all the active units. - */ - if(runner->timeouted || interrupted) - runner_interrupt(); - - /* joins all the units */ - units_join_all(runner->units); - - /* release the mutex resource */ - xbt_os_mutex_destroy(mutex); - -} - -static void -runner_wait(void) -{ - if(runner->timeout > 0) - runner->thread = xbt_os_thread_create("", runner_start_routine, NULL); - - /* signal that the runner is waiting */ - runner->waiting = 1; - - /* wait for the end of all the units */ - xbt_os_sem_acquire(units_sem); - - - runner->waiting = 0; -} - - - + /* TODO process the error */ + } + + else + { + if (runner->waiting) + { + exit_code = ELEADTIME; + err_kind = 1; + runner->timeouted = 1; + xbt_os_sem_release(units_sem); + } + } + return NULL; + } + + +#endif /* */ + int +runner_init( /*int check_syntax_flag, */ int timeout, + fstreams_t fstreams) +{ + int i; + char *val; + char buffer[PATH_MAX + 1] = { 0 }; + int code; + const char *cstr; + variable_t variable; + +#if (defined(__CHKCMD) && defined(__BUILTIN) && !defined(_XBT_WIN32)) + FILE * s; + int n = 0; + size_t len; + char *line = NULL; + int is_blank; + +#endif /* */ + if (runner) + { + ERROR0("The runner is already initialized"); + return -1; + } + runner = xbt_new0(s_runner_t, 1); + runner->path = NULL; + runner->builtin = NULL; + if (!(runner->units = units_new(runner, fstreams))) + { + free(runner); + runner = NULL; + return -1; + } + runner->timeout = timeout; + runner->timeouted = 0; + runner->interrupted = 0; + runner->number_of_ended_units = 0; + runner->number_of_runned_units = 0; + runner->waiting = 0; + runner->total_of_tests = 0; + runner->total_of_successeded_tests = 0; + runner->total_of_failed_tests = 0; + runner->total_of_interrupted_tests = 0; + runner->total_of_units = 0; + runner->total_of_successeded_units = 0; + runner->total_of_failed_units = 0; + runner->total_of_interrupted_units = 0; + runner->total_of_suites = 0; + runner->total_of_successeded_suites = 0; + runner->total_of_failed_suites = 0; + runner->total_of_interrupted_suites = 0; + + /* initialize the vector of variables */ + runner->variables = + xbt_dynar_new(sizeof(variable_t), (void_f_pvoid_t) variable_free); + + /* add the environment variables in the vector */ + for (i = 0; environ[i] != NULL; i++) + { + val = strchr(environ[i], '='); + if (val) + { + val++; + if (val[0] != '\0') + strncpy(buffer, environ[i], (val - environ[i] - 1)); + if (!strcmp("TESH_PPID", buffer)) + is_tesh_root = 0; + variable = variable_new(buffer, val); + variable->env = 1; + xbt_dynar_push(runner->variables, &variable); + +#ifndef _XBT_WIN32 + if (!strcmp("PATH", buffer)) + +#else /* */ + if (!strcmp("Path", buffer) || !strcmp("PATH", buffer)) + +#endif /* */ + { + char *p; + size_t j, k, len; + + /* get the list of paths */ + +#ifdef _XBT_WIN32 + runner->path = explode(';', val); + +#else /* */ + runner->path = explode(':', val); + +#endif /* */ + + /* remove spaces and backslahes at the end of the path */ + for (k = 0; runner->path[k] != NULL; k++) + { + p = runner->path[k]; + len = strlen(p); + +#ifndef _XBT_WIN32 + for (j = len - 1; p[j] == '/' || p[j] == ' '; j--) + +#else /* */ + for (j = len - 1; p[j] == '\\' || p[j] == ' '; j--) + +#endif /* */ + p[j] = '\0'; + } + } + memset(buffer, 0, PATH_MAX + 1); + } + } + if (is_tesh_root) + { + char *tesh_dir = getcwd(NULL, 0); + sprintf(buffer, "%d", getpid()); + +#ifndef _XBT_WIN32 + setenv("TESH_PPID", buffer, 0); + setenv("TESH_DIR", tesh_dir, 0); + +#else /* */ + SetEnvironmentVariable("TESH_PPID", buffer); + SetEnvironmentVariable("TESH_DIR", tesh_dir); + +#endif /* */ + variable = variable_new("TESH_PPID", buffer); + variable->err = 1; + xbt_dynar_push(runner->variables, &variable); + variable = variable_new("TESH_DIR", tesh_dir); + variable->err = 1; + xbt_dynar_push(runner->variables, &variable); + free(tesh_dir); + } + variable = variable_new("EXIT_SUCCESS", "0"); + variable->err = 1; + xbt_dynar_push(runner->variables, &variable); + variable = variable_new("EXIT_FAILURE", "1"); + variable->err = 1; + xbt_dynar_push(runner->variables, &variable); + variable = variable_new("TRUE", "0"); + variable->err = 1; + xbt_dynar_push(runner->variables, &variable); + variable = variable_new("FALSE", "1"); + variable->err = 1; + xbt_dynar_push(runner->variables, &variable); + i = 0; + + /* add the errors variables */ + while ((cstr = error_get_at(i++, &code))) + { + sprintf(buffer, "%d", code); + variable = variable_new(cstr, buffer); + variable->err = 1; + xbt_dynar_push(runner->variables, &variable); + } + + /* if the user want check the syntax, check it */ + /*if(check_syntax_flag) + check_syntax(); + */ + +#if (!defined(_XBT_WIN32) && defined(__CHKCMD)) +#if defined(__BUILTIN) + if (!is_tesh_root) + { + + /* compute the full path the builtin.def file */ + sprintf(buffer, "%s/builtin.def", getenv("TESH_DIR")); + if (!(s = fopen(buffer, "r"))) + { + ERROR1("File `(%s)' not found", buffer); + return -1; + } + } + + else + { + if (!(s = fopen("builtin.def", "r"))) + { + ERROR0("File `(builtin.def)' not found"); + return -1; + } + } + if (s) + { + fpos_t begin; + fgetpos(s, &begin); + while (readline(s, &line, &len) != -1) + { + i = 0; + is_blank = 1; + while (line[i] != '\0') + { + if (line[i] != ' ' && line[i] != '\t' && line[i] != '\n' + && line[i] != '\r') + { + is_blank = 0; + break; + } + i++; + } + if (!is_blank) + n++; + } + fsetpos(s, &begin); + free(line); + line = NULL; + if (n) + { + char *l; + runner->builtin = xbt_new0(char *, n + 1); /* (char**) calloc(n + 1, sizeof(char*)); */ + n = 0; + while (readline(s, &line, &len) != -1) + { + i = 0; + is_blank = 1; + while (line[i] != '\0') + { + if (line[i] != ' ' && line[i] != '\t' && line[i] != '\n' + && line[i] != '\r') + { + is_blank = 0; + break; + } + i++; + } + if (!is_blank) + { + l = strdup(line); + l[strlen(l) - 1] = '\0'; + (runner->builtin)[n++] = l; + } + } + } + + else + { + WARN0("The file `(builtin.def)' is empty"); + free(runner->builtin); + runner->builtin = NULL; + } + fclose(s); + if (line) + free(line); + } + +#else /* */ + runner->builtin = xbt_new0(char *, __BUILTIN_MAX + 1); /* (char**) calloc(__BUILTIN_MAX + 1, sizeof(char*)); */ + for (i = 0; i < __BUILTIN_MAX; i++) + runner->builtin[i] = strdup(builtin[i]); + +#endif /* */ +#endif /* */ + return exit_code ? -1 : 0; + } + + void runner_destroy(void) +{ + int i; + if (runner->units) + units_free((void **) (&(runner->units))); + if (runner->variables) + xbt_dynar_free(&runner->variables); + +#ifdef _XBT_WIN32 + CloseHandle(timer_handle); + +#endif /* */ + if (runner->thread) + xbt_os_thread_join(runner->thread, NULL); + if (runner->path) + { + for (i = 0; runner->path[i] != NULL; i++) + free(runner->path[i]); + free(runner->path); + } + if (runner->builtin) + { + for (i = 0; runner->builtin[i] != NULL; i++) + free(runner->builtin[i]); + free(runner->builtin); + } + free(runner); + runner = NULL; + } + + void runner_run(void) +{ + + /* allocate the mutex used by the units to asynchronously access + * to the properties of the runner. + */ + xbt_os_mutex_t mutex = xbt_os_mutex_init(); + + /* run all the units */ + units_run_all(runner->units, mutex); + if (!interrupted) + runner_wait(); + + /* if the runner is timeouted or receive a interruption request + * , interrupt all the active units. + */ + if (runner->timeouted || interrupted) + runner_interrupt(); + + /* joins all the units */ + units_join_all(runner->units); + + /* release the mutex resource */ + xbt_os_mutex_destroy(mutex); + } + + static void runner_wait(void) +{ + if (runner->timeout > 0) + runner->thread = xbt_os_thread_create("", runner_start_routine, NULL); + + /* signal that the runner is waiting */ + runner->waiting = 1; + + /* wait for the end of all the units */ + xbt_os_sem_acquire(units_sem); + runner->waiting = 0; + } + + /* * interrupt all the active units. * this function is called when the lead time of the execution is reached * or when a failed unit requests an interruption of the execution. - */ -void -runner_interrupt(void) -{ - units_interrupt_all(runner->units); -} - -void -runner_summarize(void) -{ - - if(!dry_run_flag) - { - #ifndef _XBT_WIN32 - struct rusage r_usage; - #else - FILETIME start_time; - FILETIME exit_time; - FILETIME kernel_time; - FILETIME user_time; - SYSTEMTIME si; - #endif - - printf("\n TEst SHell utility - mini shell specialized in running test units.\n"); - printf(" =============================================================================\n"); - - units_summuarize(runner->units); - - printf(" =====================================================================%s\n", - runner->total_of_failed_tests ? "== FAILED": (runner->total_of_interrupted_tests || runner->total_of_interrupted_units) ? "==== INTR" : "====== OK"); - - printf(" TOTAL : Suite(s): %.0f%% ok (%d suite(s): %d ok", - (runner->total_of_suites ? (1-((double)runner->total_of_failed_suites + (double)runner->total_of_interrupted_suites)/(double)runner->total_of_suites)*100.0 : 100.0), - runner->total_of_suites, runner->total_of_successeded_suites); - - if(runner->total_of_failed_suites > 0) - printf(", %d failed", runner->total_of_failed_suites); - - if(runner->total_of_interrupted_suites > 0) - printf(", %d interrupted)", runner->total_of_interrupted_suites); - - printf(")\n"); - - printf(" Unit(s): %.0f%% ok (%d unit(s): %d ok", - (runner->total_of_units ? (1-((double)runner->total_of_failed_units + (double)runner->total_of_interrupted_units)/(double)runner->total_of_units)*100.0 : 100.0), - runner->total_of_units, runner->total_of_successeded_units); - - if(runner->total_of_failed_units > 0) - printf(", %d failed", runner->total_of_failed_units); - - if(runner->total_of_interrupted_units > 0) - printf(", %d interrupted)", runner->total_of_interrupted_units); - - printf(")\n"); - - printf(" Test(s): %.0f%% ok (%d test(s): %d ok", - (runner->total_of_tests ? (1-((double)runner->total_of_failed_tests + (double)runner->total_of_interrupted_tests)/(double)runner->total_of_tests)*100.0 : 100.0), - runner->total_of_tests, runner->total_of_successeded_tests); - - if(runner->total_of_failed_tests > 0) - printf(", %d failed", runner->total_of_failed_tests); - - if(runner->total_of_interrupted_tests > 0) - printf(", %d interrupted)", runner->total_of_interrupted_tests); - - printf(")\n\n"); - - #ifndef _XBT_WIN32 - if(!getrusage(RUSAGE_SELF, &r_usage)) - { - - printf(" Total tesh user time used: %ld second(s) %ld microsecond(s)\n", r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec); - printf(" Total tesh system time used: %ld second(s) %ld microsecond(s)\n\n", r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec); - - if(!getrusage(RUSAGE_CHILDREN, &r_usage)) - { - printf(" Total children user time used: %ld second(s) %ld microsecond(s)\n", r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec); - printf(" Total children system time used: %ld second(s) %ld microsecond(s)\n\n", r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec); - - } - } - #else - - if(GetProcessTimes(GetCurrentProcess(), &start_time, &exit_time, &kernel_time, &user_time)) - { - FileTimeToSystemTime(&user_time, &si); - - printf(" User time used: %2u Hour(s) %2u Minute(s) %2u Second(s) %3u Millisecond(s)\n", si.wHour, si.wMinute, si.wSecond, si.wMilliseconds ); - - FileTimeToSystemTime(&kernel_time, &si); - - printf(" Kernel time used: %2u Hour(s) %2u Minute(s) %2u Second(s) %3u Millisecond(s)\n", si.wHour, si.wMinute, si.wSecond, si.wMilliseconds ); - } - - - - #endif - } - else - { - if(exit_code) - ERROR0("Syntax NOK"); - else if(!exit_code) - INFO0("Syntax 0K"); - } -} - -int -runner_is_timedout(void) -{ - return runner->timeouted; -} - + */ +void runner_interrupt(void) +{ + units_interrupt_all(runner->units); + } void runner_summarize(void) +{ + if (!dry_run_flag) + { + +#ifndef _XBT_WIN32 + struct rusage r_usage; + +#else /* */ + FILETIME start_time; + FILETIME exit_time; + FILETIME kernel_time; + FILETIME user_time; + SYSTEMTIME si; + +#endif /* */ + printf + ("\n TEst SHell utility - mini shell specialized in running test units.\n"); + printf + (" =============================================================================\n"); + units_summuarize(runner->units); + printf + (" =====================================================================%s\n", + runner->total_of_failed_tests ? "== FAILED" : (runner-> + total_of_interrupted_tests + || runner-> + total_of_interrupted_units) + ? "==== INTR" : "====== OK"); + printf(" TOTAL : Suite(s): %.0f%% ok (%d suite(s): %d ok", + (runner-> + total_of_suites ? (1 - + ((double) runner-> + total_of_failed_suites + + (double) runner-> + total_of_interrupted_suites) / + (double) runner->total_of_suites) * + 100.0 : 100.0), runner->total_of_suites, + runner->total_of_successeded_suites); + if (runner->total_of_failed_suites > 0) + printf(", %d failed", runner->total_of_failed_suites); + if (runner->total_of_interrupted_suites > 0) + printf(", %d interrupted)", runner->total_of_interrupted_suites); + printf(")\n"); + printf(" Unit(s): %.0f%% ok (%d unit(s): %d ok", + (runner-> + total_of_units ? (1 - + ((double) runner->total_of_failed_units + + (double) runner-> + total_of_interrupted_units) / + (double) runner->total_of_units) * + 100.0 : 100.0), runner->total_of_units, + runner->total_of_successeded_units); + if (runner->total_of_failed_units > 0) + printf(", %d failed", runner->total_of_failed_units); + if (runner->total_of_interrupted_units > 0) + printf(", %d interrupted)", runner->total_of_interrupted_units); + printf(")\n"); + printf(" Test(s): %.0f%% ok (%d test(s): %d ok", + (runner-> + total_of_tests ? (1 - + ((double) runner->total_of_failed_tests + + (double) runner-> + total_of_interrupted_tests) / + (double) runner->total_of_tests) * + 100.0 : 100.0), runner->total_of_tests, + runner->total_of_successeded_tests); + if (runner->total_of_failed_tests > 0) + printf(", %d failed", runner->total_of_failed_tests); + if (runner->total_of_interrupted_tests > 0) + printf(", %d interrupted)", runner->total_of_interrupted_tests); + printf(")\n\n"); + +#ifndef _XBT_WIN32 + if (!getrusage(RUSAGE_SELF, &r_usage)) + { + printf + (" Total tesh user time used: %ld second(s) %ld microsecond(s)\n", + r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec); + printf + (" Total tesh system time used: %ld second(s) %ld microsecond(s)\n\n", + r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec); + if (!getrusage(RUSAGE_CHILDREN, &r_usage)) + { + printf + (" Total children user time used: %ld second(s) %ld microsecond(s)\n", + r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec); + printf + (" Total children system time used: %ld second(s) %ld microsecond(s)\n\n", + r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec); + } + } + +#else /* */ + if (GetProcessTimes + (GetCurrentProcess(), &start_time, &exit_time, &kernel_time, + &user_time)) + { + FileTimeToSystemTime(&user_time, &si); + printf + (" User time used: %2u Hour(s) %2u Minute(s) %2u Second(s) %3u Millisecond(s)\n", + si.wHour, si.wMinute, si.wSecond, si.wMilliseconds); + FileTimeToSystemTime(&kernel_time, &si); + printf + (" Kernel time used: %2u Hour(s) %2u Minute(s) %2u Second(s) %3u Millisecond(s)\n", + si.wHour, si.wMinute, si.wSecond, si.wMilliseconds); + } + +#endif /* */ + } + + else + { + if (exit_code) + ERROR0("Syntax NOK"); + + else if (!exit_code) + INFO0("Syntax 0K"); + } + } + + int runner_is_timedout(void) +{ + return runner->timeouted; + } + + diff --git a/tools/tesh2/src/str_replace.c b/tools/tesh2/src/str_replace.c index df147e456e..976d93ca2b 100644 --- a/tools/tesh2/src/str_replace.c +++ b/tools/tesh2/src/str_replace.c @@ -4,105 +4,91 @@ #include #include - -int -str_replace(char** str, const char* what, const char* with, const char* delimiters) -{ - size_t pos, i, len; - char* begin = NULL; - char* buf; - int size; - - if(!*str || !what) - { - errno = EINVAL; - return -1; - } - - if(delimiters) - { - char* delimited; - - if(!(delimited = (char*) calloc((strlen(what) + 2) , sizeof(char)))) - return -1; - - len = strlen(delimiters); - - for(i = 0; i < len; i++) - { - memset(delimited, 0, (strlen(what) + 2)); - - sprintf(delimited,"%s%c", what, delimiters[i]); - - if((begin = strstr(*str, delimited))) - break; - } - - free(delimited); - } - else - begin = strstr(*str, what); - - - if(!begin && (size = (int)strlen(*str) - (int)strlen(what)) >= 0 && !strcmp(*str + size, what)) - begin = strstr(*str, what); - - if(!begin) - { - errno = ESRCH; - return -1; - } - - pos = begin - *str; - - i = 0; - - pos += strlen(what); - - if(begin == *str) - { - if(!(buf = (char*) calloc((with ? strlen(with) : 0) + ((pos < strlen(*str)) ? strlen(*str + pos) : 0) + 1, sizeof(char)))) - return -1; - - if(with) - strcpy(buf, with); - - if(pos < strlen(*str)) - strcpy(buf + (with ? strlen(with) : 0), *str + pos); - } - else - { - if(!(buf = (char*) calloc((begin - *str) + (with ? strlen(with) : 0) + ((pos < strlen(*str)) ? strlen(*str + pos) : 0) + 1, sizeof(char)))) - return -1; - - strncpy(buf, *str, (begin - *str)); - - if(with) - strcpy(buf + (begin - *str) , with); - - if(pos < strlen(*str)) - strcpy(buf + (begin - *str) + (with ? strlen(with) : 0), *str + pos); - } - - free(*str); - - *str = buf; - - return 0; - -} - -int -str_replace_all(char** str, const char* what, const char* with, const char* delimiters) -{ - int rv; - - while(!(rv = str_replace(str, what, with, delimiters))); - - return (errno == ESRCH) ? 0 : -1; -} - - - - - + int +str_replace(char **str, const char *what, const char *with, + const char *delimiters) +{ + size_t pos, i, len; + char *begin = NULL; + char *buf; + int size; + if (!*str || !what) + { + errno = EINVAL; + return -1; + } + if (delimiters) + { + char *delimited; + if (!(delimited = (char *) calloc((strlen(what) + 2), sizeof(char)))) + return -1; + len = strlen(delimiters); + for (i = 0; i < len; i++) + { + memset(delimited, 0, (strlen(what) + 2)); + sprintf(delimited, "%s%c", what, delimiters[i]); + if ((begin = strstr(*str, delimited))) + break; + } + free(delimited); + } + + else + begin = strstr(*str, what); + if (!begin && (size = (int) strlen(*str) - (int) strlen(what)) >= 0 + && !strcmp(*str + size, what)) + begin = strstr(*str, what); + if (!begin) + { + errno = ESRCH; + return -1; + } + pos = begin - *str; + i = 0; + pos += strlen(what); + if (begin == *str) + { + if (! + (buf = + (char *) calloc((with ? strlen(with) : 0) + + ((pos < + strlen(*str)) ? strlen(*str + pos) : 0) + 1, + sizeof(char)))) + return -1; + if (with) + strcpy(buf, with); + if (pos < strlen(*str)) + strcpy(buf + (with ? strlen(with) : 0), *str + pos); + } + + else + { + if (! + (buf = + (char *) calloc((begin - *str) + (with ? strlen(with) : 0) + + ((pos < + strlen(*str)) ? strlen(*str + pos) : 0) + 1, + sizeof(char)))) + return -1; + strncpy(buf, *str, (begin - *str)); + if (with) + strcpy(buf + (begin - *str), with); + if (pos < strlen(*str)) + strcpy(buf + (begin - *str) + (with ? strlen(with) : 0), + *str + pos); + } + free(*str); + *str = buf; + return 0; + } + + int +str_replace_all(char **str, const char *what, const char *with, + const char *delimiters) +{ + int rv; + while (!(rv = str_replace(str, what, with, delimiters))); + return (errno == ESRCH) ? 0 : -1; + } + + diff --git a/tools/tesh2/src/timer.c b/tools/tesh2/src/timer.c index 44a6c32bc3..550f8aeb23 100644 --- a/tools/tesh2/src/timer.c +++ b/tools/tesh2/src/timer.c @@ -10,100 +10,79 @@ * This file contains all the definitions of the functions related with * the tesh timer type. * - */ - + */ + #include #include #include - - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - -static void* -timer_start_routine(void* p); - -ttimer_t -timer_new(command_t command) -{ - ttimer_t timer; - - timer = xbt_new0(s_timer_t, 1); - - timer->command = command; - timer->thread = NULL; - timer->timeouted = 0; - timer->started = xbt_os_sem_init(0); - - return timer; -} - -int -timer_free(ttimer_t* ptr) -{ - if((*ptr)->started) - xbt_os_sem_destroy((*ptr)->started); - - free(*ptr); - - *ptr = NULL; - - return 0; -} - -void -timer_time(ttimer_t timer) -{ - timer->thread = xbt_os_thread_create("", timer_start_routine, timer); -} - -static void* -timer_start_routine(void* p) -{ - ttimer_t timer = (ttimer_t)p; - command_t command = timer->command; - - int now = (int)time(NULL); - int lead_time = now + command->context->timeout; - - xbt_os_sem_release(timer->started); - - while(!command->failed && !command->interrupted && !command->successeded && !timer->timeouted) - { - if(lead_time >= now) - { - xbt_os_thread_yield(); - now = (int)time(NULL); - } - else - { - timer->timeouted = 1; - } - } - - if(timer->timeouted && !command->failed && !command->successeded && !command->interrupted) - { - ERROR3("[%s] `%s' timed out after %d sec", command->context->pos, command->context->command_line, command->context->timeout); - - - unit_set_error(command->unit, ECMDTIMEDOUT, 1, command->context->pos); - - command_kill(command); - command_handle_failure(command, csr_timeout); - - while(!command->reader->done) - xbt_os_thread_yield(); - - if(command->output->used) - INFO2("[%s] Output on timeout:\n%s",command->context->pos, command->output->data); - else - INFO1("[%s] No output before timeout",command->context->pos); - } - - return NULL; -} - -void -timer_wait(ttimer_t timer) -{ - xbt_os_thread_join(timer->thread, NULL); -} + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + static void * timer_start_routine(void *p); + ttimer_t timer_new(command_t command) +{ + ttimer_t timer; + timer = xbt_new0(s_timer_t, 1); + timer->command = command; + timer->thread = NULL; + timer->timeouted = 0; + timer->started = xbt_os_sem_init(0); + return timer; + } + + int timer_free(ttimer_t * ptr) +{ + if ((*ptr)->started) + xbt_os_sem_destroy((*ptr)->started); + free(*ptr); + *ptr = NULL; + return 0; + } + + void timer_time(ttimer_t timer) +{ + timer->thread = xbt_os_thread_create("", timer_start_routine, timer); + } static void * timer_start_routine(void *p) +{ + ttimer_t timer = (ttimer_t) p; + command_t command = timer->command; + int now = (int) time(NULL); + int lead_time = now + command->context->timeout; + xbt_os_sem_release(timer->started); + while (!command->failed && !command->interrupted + && !command->successeded && !timer->timeouted) + { + if (lead_time >= now) + { + xbt_os_thread_yield(); + now = (int) time(NULL); + } + + else + { + timer->timeouted = 1; + } + } + if (timer->timeouted && !command->failed && !command->successeded + && !command->interrupted) + { + ERROR3("[%s] `%s' timed out after %d sec", command->context->pos, + command->context->command_line, command->context->timeout); + unit_set_error(command->unit, ECMDTIMEDOUT, 1, + command->context->pos); + command_kill(command); + command_handle_failure(command, csr_timeout); + while (!command->reader->done) + xbt_os_thread_yield(); + if (command->output->used) + INFO2("[%s] Output on timeout:\n%s", command->context->pos, + command->output->data); + + else + INFO1("[%s] No output before timeout", command->context->pos); + } + return NULL; + } + + void timer_wait(ttimer_t timer) +{ + xbt_os_thread_join(timer->thread, NULL); + } diff --git a/tools/tesh2/src/unit.c b/tools/tesh2/src/unit.c index afadd9b151..566c6e4a75 100644 --- a/tools/tesh2/src/unit.c +++ b/tools/tesh2/src/unit.c @@ -10,8 +10,8 @@ * This file contains all the definitions of the functions related with * the tesh unit concept. * - */ - + */ + #include #include #include @@ -19,11 +19,8 @@ #include #include #include - - - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + /*! \brief unit_start - start the processing of the tesh file representing by the unit * * \param p A void pointer to the unit representing the tesh file to process. @@ -47,899 +44,817 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); * 6) Its release the next waiting unit (if any) by releasing the jobs semaphore. * 7) If its the last unit, it release the runner by releasing the semaphore used to wait for the end of all the units. * - */ -static void* -unit_start(void* p) -{ - xbt_os_thread_t thread; - xbt_os_mutex_t mutex; - unit_t include, suite; - unsigned int itc, itu, its; - int include_nb, suite_nb; - command_t command; - - unit_t root = (unit_t)p; - - /* increment the number of running units */ - xbt_os_mutex_acquire(root->mutex); - root->runner->number_of_runned_units++; - xbt_os_mutex_release(root->mutex); - - /* must acquire the jobs semaphore to start */ - /*xbt_os_sem_acquire(jobs_sem);*/ - - /* initialize the mutex used to synchronize the access to the properties of this unit */ - mutex = xbt_os_mutex_init(); - - if(!dry_run_flag) - INFO1("Test unit from %s",root->fstream->name); - else - INFO1("Checking unit %s...",root->fstream->name); - - /* launch the parsing of the unit */ - fstream_parse(root->fstream, mutex); - - /* if the unit is not interrupted and not failed the unit, all the file is parsed - * so all the command are launched - */ - if(!root->interrupted) - { - root->parsed = 1; - - /* all the commands have terminated before the end of the parsing of the tesh file - * so the unit release the semaphore itself - */ - if(!root->released && (root->started_cmd_nb == (root->failed_cmd_nb + root->interrupted_cmd_nb + root->successeded_cmd_nb))) - xbt_os_sem_release(root->sem); - } - - /* wait the end of all the commands or a command failure or an interruption */ - - xbt_os_sem_acquire(root->sem); - - - if(root->interrupted) - { - - xbt_dynar_foreach(root->commands, itc , command) - { - if(command->status == cs_in_progress) - command_interrupt(command); - } - - /* interrupt all the running commands of the included units */ - include_nb = xbt_dynar_length(root->includes); - - xbt_dynar_foreach(root->includes, itu, include) - { - xbt_dynar_foreach(include->commands, itc, command) - { - if(command->status == cs_in_progress) - command_interrupt(command); - } - } - - /* interrupt all the running commands of the unit */ - suite_nb = xbt_dynar_length(root->suites); - - xbt_dynar_foreach(root->suites, its, suite) - { - include_nb = xbt_dynar_length(suite->includes); - - xbt_dynar_foreach(suite->includes, itu, include) - { - xbt_dynar_foreach(include->commands, itc, command) - { - if(command->status == cs_in_progress) - command_interrupt(command); - } - } - } - } - - /* wait the end of the command threads of the unit */ - xbt_dynar_foreach(root->commands, itc, command) - { - thread = command->thread; - - if(thread) - xbt_os_thread_join(thread,NULL); - } - - /* wait the end of the command threads of the included units of the unit */ - include_nb = xbt_dynar_length(root->includes); - - xbt_dynar_foreach(root->includes, itu, include) - { - xbt_dynar_foreach(include->commands, itc, command) - { - thread = command->thread; - - if(thread) - xbt_os_thread_join(thread,NULL); - } - - if(!dry_run_flag) - { - if(!include->exit_code && !include->interrupted) - INFO1("Include from %s OK",include->fstream->name); - else if(include->exit_code) - ERROR3("Include `%s' NOK : (<%s> %s)", include->fstream->name, include->err_line, error_to_string(include->exit_code, include->err_kind)); - else if(include->interrupted && !include->exit_code) - INFO1("Include `(%s)' INTR",include->fstream->name); - } - } - - /* interrupt all the running commands of the unit */ - suite_nb = xbt_dynar_length(root->suites); - - xbt_dynar_foreach(root->suites, its, suite) - { - include_nb = xbt_dynar_length(suite->includes); - - if(!include_nb) - { - if(!suite->exit_code) - { - unit_set_error(suite, ESYNTAX, 1, suite->filepos); - ERROR2("[%s] Empty suite `(%s)' detected (no includes added)", suite->filepos, suite->description); - - /* if the --keep-going option is not specified */ - if(!keep_going_flag) - { - if(!interrupted) - { - /* request an global interruption by the runner */ - interrupted = 1; - - /* release the runner */ - xbt_os_sem_release(units_sem); - } - } - } - } - - xbt_dynar_foreach(suite->includes, itu, include) - { - xbt_dynar_foreach(include->commands, itc, command) - { - thread = command->thread; - - if(thread) - xbt_os_thread_join(thread,NULL); - } - - if(!include->exit_code && !include->interrupted) - { - if(!dry_run_flag) - INFO1("Include from %s OK",include->fstream->name); - } - else if(include->exit_code) - { - if(!dry_run_flag) - ERROR3("Include `%s' NOK : (<%s> %s)", include->fstream->name, command->context->pos, error_to_string(include->exit_code, include->err_kind)); - - suite->exit_code = include->exit_code; - suite->err_kind = include->err_kind; - suite->err_line = strdup(include->err_line); - } - else if(include->interrupted && !include->exit_code) - { - if(!dry_run_flag) - INFO1("Include `(%s)' INTR",include->fstream->name); - - suite->interrupted = 1; - } - - } - - if(!dry_run_flag ) - { - if(!suite->exit_code && !suite->interrupted) - INFO1("Test suite from %s OK",suite->description); - else if(suite->exit_code) - ERROR3("Test suite `%s' NOK : (<%s> %s) ", suite->description, suite->err_line, error_to_string(suite->exit_code, suite->err_kind)); - else if(suite->interrupted && !suite->exit_code) - INFO1("Test suite `(%s)' INTR",suite->description); - } - } - - /* you can now destroy the mutex used to synchrone the command accesses to the properties of the unit */ - xbt_os_mutex_destroy(mutex); - - /* update the number of ended units of the runner */ - xbt_os_mutex_acquire(root->mutex); - - /* increment the number of ended units */ - root->runner->number_of_ended_units++; - - if(!dry_run_flag ) - { - if(root->interrupted && !root->exit_code) - INFO1("Test unit from %s INTR",root->fstream->name); - else if(!root->exit_code) - INFO1("Test unit from %s OK",root->fstream->name); - else if(root->exit_code) - ERROR3("Test unit `%s': NOK (<%s> %s)",root->fstream->name, root->err_line, error_to_string(root->exit_code, root->err_kind)); - } - - /* if it's the last unit, release the runner */ - if((root->runner->number_of_runned_units == root->runner->number_of_ended_units)) - { - /* if all the commands of the unit are successeded itc's a successeded unit */ - if(root->successeded_cmd_nb == root->cmd_nb && !root->exit_code /* case of only one cd : nb = successeded = 0)*/) - root->successeded = 1; - - /* first release the mutex */ - xbt_os_mutex_release(root->mutex); - - /* release the runner */ - xbt_os_sem_release(units_sem); - } - else - xbt_os_mutex_release(root->mutex); - - /* release the jobs semaphore, then the next waiting unit can start */ - xbt_os_sem_release(jobs_sem); - - return NULL; - -} - - -unit_t -unit_new(runner_t runner, unit_t root, unit_t owner, fstream_t fstream) -{ - unit_t unit; - - unit = xbt_new0(s_unit_t, 1); - - /* instantiate the vector used to store all the commands of the unit */ - unit->commands = xbt_dynar_new(sizeof(command_t), (void_f_pvoid_t)command_free); - - /* instantiate the vector used to store all the included units */ - unit->includes = xbt_dynar_new(sizeof(unit_t), (void_f_pvoid_t)unit_free); - - /* instantiate the vector used to store all the included suites */ - unit->suites = xbt_dynar_new(sizeof(unit_t), (void_f_pvoid_t)unit_free); - - /* the runner used to launch the tesh unit */ - unit->runner = runner; - - /* the file stream object to use to parse the tesh file */ - unit->fstream = fstream; - - if(fstream) - fstream->unit = unit; - - /* if no root parameter specified assume that itc's the root of all the units */ - unit->root = root ? root : unit; - - /* the owner of the suite */ - unit->owner = owner; - - unit->thread = NULL; - unit->started_cmd_nb = 0; - unit->interrupted_cmd_nb = 0; - unit->failed_cmd_nb = 0; - unit->successeded_cmd_nb = 0; - unit->terminated_cmd_nb = 0; - unit->waiting_cmd_nb = 0; - unit->interrupted = 0; - unit->failed = 0; - unit->successeded = 0; - unit->parsed = 0; - unit->released = 0; - unit->owner = owner; - unit->is_running_suite = 0; - unit->description = NULL; - unit->sem = NULL; - unit->exit_code = 0; - unit->err_kind = 0; - unit->err_line = NULL; - unit->filepos = NULL; - - - - return unit; -} - -void -unit_set_error(unit_t unit, int errcode, int kind, const char* line) -{ - if(!unit->exit_code) - { - unit->exit_code = errcode; - unit->err_kind = kind; - unit->err_line = strdup(line); - - if(unit->root && !unit->root->exit_code) - { - unit->root->exit_code = errcode; - unit->root->err_kind = kind; - unit->root->err_line = strdup(line); - } - - if(!exit_code) - { - - exit_code = errcode; - err_kind = kind; - err_line = strdup(line); - } - } - -} - -int -unit_free(unit_t* ptr) -{ - if(!(*ptr)) - { - errno = EINVAL; - return -1; - } - - if((*ptr)->commands) - xbt_dynar_free(&((*ptr)->commands)); - - if((*ptr)->includes) - xbt_dynar_free(&((*ptr)->includes)); - - if((*ptr)->suites) - xbt_dynar_free(&((*ptr)->suites)); - - /* if the unit is interrupted during its run, the semaphore is NULL */ - if((*ptr)->sem) - xbt_os_sem_destroy((*ptr)->sem); - - if((*ptr)->description) - free((*ptr)->description); - - if((*ptr)->err_line) - free((*ptr)->err_line); - - if((*ptr)->filepos) - free((*ptr)->filepos); - - free(*ptr); - *ptr = NULL; - - return 0; -} - -int -unit_run(unit_t unit, xbt_os_mutex_t mutex) -{ - /* check the parameters */ - if(!(unit) || !mutex) - { - errno = EINVAL; - xbt_os_sem_release(jobs_sem); - return -1; - - } - - if(!interrupted) - { - unit->mutex = mutex; - - unit->sem = xbt_os_sem_init(0); - - /* start the unit */ - unit->thread = xbt_os_thread_create("", unit_start, unit); - } - else - { - /* the unit is interrupted by the runner before its starting - * in this case the unit semaphore is NULL take care of that - * in the function unit_free() - */ - unit->interrupted = 1; - xbt_os_sem_release(jobs_sem); - } - - return 0; - -} - -int -unit_interrupt(unit_t unit) -{ - /* check the parameter */ - if(!(unit)) - { - errno = EINVAL; - return -1; - } + */ +static void * unit_start(void *p) +{ + xbt_os_thread_t thread; + xbt_os_mutex_t mutex; + unit_t include, suite; + unsigned int itc, itu, its; + int include_nb, suite_nb; + command_t command; + unit_t root = (unit_t) p; + + /* increment the number of running units */ + xbt_os_mutex_acquire(root->mutex); + root->runner->number_of_runned_units++; + xbt_os_mutex_release(root->mutex); + + /* must acquire the jobs semaphore to start */ + /*xbt_os_sem_acquire(jobs_sem); */ + + /* initialize the mutex used to synchronize the access to the properties of this unit */ + mutex = xbt_os_mutex_init(); + if (!dry_run_flag) + INFO1("Test unit from %s", root->fstream->name); + + else + INFO1("Checking unit %s...", root->fstream->name); + + /* launch the parsing of the unit */ + fstream_parse(root->fstream, mutex); + + /* if the unit is not interrupted and not failed the unit, all the file is parsed + * so all the command are launched + */ + if (!root->interrupted) + { + root->parsed = 1; + + /* all the commands have terminated before the end of the parsing of the tesh file + * so the unit release the semaphore itself + */ + if (!root->released + && (root->started_cmd_nb == + (root->failed_cmd_nb + root->interrupted_cmd_nb + + root->successeded_cmd_nb))) + xbt_os_sem_release(root->sem); + } + + /* wait the end of all the commands or a command failure or an interruption */ + xbt_os_sem_acquire(root->sem); + if (root->interrupted) + { + xbt_dynar_foreach(root->commands, itc, command) { + if (command->status == cs_in_progress) + command_interrupt(command); + } + + /* interrupt all the running commands of the included units */ + include_nb = xbt_dynar_length(root->includes); + xbt_dynar_foreach(root->includes, itu, include) { + xbt_dynar_foreach(include->commands, itc, command) { + if (command->status == cs_in_progress) + command_interrupt(command); + } + } + + /* interrupt all the running commands of the unit */ + suite_nb = xbt_dynar_length(root->suites); + xbt_dynar_foreach(root->suites, its, suite) { + include_nb = xbt_dynar_length(suite->includes); + xbt_dynar_foreach(suite->includes, itu, include) { + xbt_dynar_foreach(include->commands, itc, command) { + if (command->status == cs_in_progress) + command_interrupt(command); + } + } + } + } + + /* wait the end of the command threads of the unit */ + xbt_dynar_foreach(root->commands, itc, command) { + thread = command->thread; + if (thread) + xbt_os_thread_join(thread, NULL); + } + + /* wait the end of the command threads of the included units of the unit */ + include_nb = xbt_dynar_length(root->includes); + xbt_dynar_foreach(root->includes, itu, include) { + xbt_dynar_foreach(include->commands, itc, command) { + thread = command->thread; + if (thread) + xbt_os_thread_join(thread, NULL); + } + if (!dry_run_flag) + { + if (!include->exit_code && !include->interrupted) + INFO1("Include from %s OK", include->fstream->name); + + else if (include->exit_code) + ERROR3("Include `%s' NOK : (<%s> %s)", include->fstream->name, + include->err_line, error_to_string(include->exit_code, + include->err_kind)); + + else if (include->interrupted && !include->exit_code) + INFO1("Include `(%s)' INTR", include->fstream->name); + } + } + + /* interrupt all the running commands of the unit */ + suite_nb = xbt_dynar_length(root->suites); + xbt_dynar_foreach(root->suites, its, suite) { + include_nb = xbt_dynar_length(suite->includes); + if (!include_nb) + { + if (!suite->exit_code) + { + unit_set_error(suite, ESYNTAX, 1, suite->filepos); + ERROR2("[%s] Empty suite `(%s)' detected (no includes added)", + suite->filepos, suite->description); + + /* if the --keep-going option is not specified */ + if (!keep_going_flag) + { + if (!interrupted) + { + + /* request an global interruption by the runner */ + interrupted = 1; + + /* release the runner */ + xbt_os_sem_release(units_sem); + } + } + } + } + xbt_dynar_foreach(suite->includes, itu, include) { + xbt_dynar_foreach(include->commands, itc, command) { + thread = command->thread; + if (thread) + xbt_os_thread_join(thread, NULL); + } + if (!include->exit_code && !include->interrupted) + { + if (!dry_run_flag) + INFO1("Include from %s OK", include->fstream->name); + } + + else if (include->exit_code) + { + if (!dry_run_flag) + ERROR3("Include `%s' NOK : (<%s> %s)", include->fstream->name, + command->context->pos, + error_to_string(include->exit_code, include->err_kind)); + suite->exit_code = include->exit_code; + suite->err_kind = include->err_kind; + suite->err_line = strdup(include->err_line); + } + + else if (include->interrupted && !include->exit_code) + { + if (!dry_run_flag) + INFO1("Include `(%s)' INTR", include->fstream->name); + suite->interrupted = 1; + } + } + if (!dry_run_flag) + { + if (!suite->exit_code && !suite->interrupted) + INFO1("Test suite from %s OK", suite->description); + + else if (suite->exit_code) + ERROR3("Test suite `%s' NOK : (<%s> %s) ", suite->description, + suite->err_line, error_to_string(suite->exit_code, + suite->err_kind)); + + else if (suite->interrupted && !suite->exit_code) + INFO1("Test suite `(%s)' INTR", suite->description); + } + } + + /* you can now destroy the mutex used to synchrone the command accesses to the properties of the unit */ + xbt_os_mutex_destroy(mutex); + + /* update the number of ended units of the runner */ + xbt_os_mutex_acquire(root->mutex); + + /* increment the number of ended units */ + root->runner->number_of_ended_units++; + if (!dry_run_flag) + { + if (root->interrupted && !root->exit_code) + INFO1("Test unit from %s INTR", root->fstream->name); - /* if the unit is already interrupted, signal the error */ - if(unit->interrupted) - { - errno = EALREADY; - return -1; - } + else if (!root->exit_code) + INFO1("Test unit from %s OK", root->fstream->name); - /* interrupt the run of the specified unit */ - unit->interrupted = 1; - xbt_os_sem_release(unit->sem); - - return 0; -} - -/* just print the title of the root unit or a suite (if any) */ -static void -print_title(const char* description) -{ - register int i; - char title[80]; - size_t len = strlen(description); - - title[0]=' '; - - for (i = 1; i < 79; i++) - title[i]='='; - - title[i++]='\n'; - title[79]='\0'; - - sprintf(title + 40 - (len + 4)/2, "[ %s ]",description); - title[40 + (len + 5 ) / 2] = '='; - - printf("\n%s\n",title); -} - -int -unit_summuarize(unit_t unit) -{ - command_t command; - unsigned int itc, itu, its; - unit_t include; - unit_t suite; - char* p; - char title[PATH_MAX + 1] = {0}; - - int number_of_tests = 0; /* number of tests of a unit contained by this unit */ - int number_of_failed_tests = 0; /* number of failed test of a unit contained by this unit */ - int number_of_successeded_tests = 0; /* number of successeded tests of a unit contained by this unit */ - int number_of_interrupted_tests = 0; /* number of interrupted tests of a unit contained by this unit */ - - int number_of_tests_of_suite = 0; /* number of tests of a suite contained by this unit */ - int number_of_interrupted_tests_of_suite = 0; /* number of interrupted tests of a suite contained by this unit */ - int number_of_failed_tests_of_suite = 0; /* number of failed tests of a suite contained by this unit */ - int number_of_successeded_tests_of_suite = 0; /* number of successeded tests of a suite contained by this */ - - int number_of_units = 0; /* number of units contained by a suite */ - int number_of_failed_units = 0; /* number of failed units contained by a suite */ - int number_of_successeded_units = 0; /* number of successeded units contained by a suite */ - int number_of_interrupted_units = 0; /* number of interrupted units contained by a suite */ - - int total_of_tests = 0; /* total of the tests contained by this unit */ - int total_of_failed_tests = 0; /* total of failed tests contained by this unit */ - int total_of_successeded_tests = 0; /* total of successeded tests contained by this unit */ - int total_of_interrupted_tests = 0; /* total of interrupted tests contained by this unit */ - - int total_of_units = 0; /* total of units contained by this unit */ - int total_of_failed_units = 0; /* total of failed units contained by this unit */ - int total_of_successeded_units = 0; /* total of successeded units contained by this unit */ - int total_of_interrupted_units = 0; /* total of interrutped units contained by this unit */ - - int total_of_suites = 0; /* total of suites contained by this unit */ - int total_of_failed_suites = 0; /* total of failed suites contained by this unit */ - int total_of_successeded_suites = 0; /* total of successeded suites contained by this unit */ - int total_of_interrupted_suites = 0; /* total of interrupted suites contained by this unit */ - - /* check the parameter */ - if(!(unit)) - { - errno = EINVAL; - return -1; - } - - if((unit->description) && strlen(unit->description) < 76) - strcpy(title, unit->description); - else - sprintf(title, "file : %s",unit->fstream->name); - - if(unit->interrupted) - { - if(strlen(title) + strlen(" (interrupted)") < 76) - strcat(title, " (interrupted)"); - else - { - memset(title, 0, PATH_MAX + 1); - sprintf(title, "file : %s",unit->fstream->name); - strcat(title, " (interrupted)"); - - } - } - - print_title(title); - - number_of_tests = xbt_dynar_length(unit->commands); - - /* tests */ - xbt_dynar_foreach(unit->commands, itc, command) - { - if(command->status == cs_interrupted) - number_of_interrupted_tests++; - else if(command->status == cs_failed) - number_of_failed_tests++; - else if(command->status == cs_successeded) - number_of_successeded_tests++; - } - - - if(number_of_tests) - { - asprintf(&p," Test(s): ........................................................................."); - - p[70] = '\0'; - printf("%s", p); - free(p); - - if(number_of_failed_tests > 0) - printf(".. failed\n"); - else if(number_of_interrupted_tests > 0) - printf("interrupt\n"); - else - printf(".... ..ok\n"); - - xbt_dynar_foreach(unit->commands, itc, command) - { - printf(" %s: %s [%s]\n", - command->status == cs_interrupted ? "INTR " - : command->status == cs_failed ? "FAILED" - : command->status == cs_successeded ? "PASS " - : "UNKNWN", - command->context->command_line, - command->context->pos); - - if(detail_summary_flag) - command_summarize(command); - } - - printf(" =====================================================================%s\n", - number_of_failed_tests ? "== FAILED": number_of_interrupted_tests ? "==== INTR" : "====== OK"); - - printf(" Summary: Test(s): %.0f%% ok (%d test(s): %d ok", - ((1-((double)number_of_failed_tests + (double)number_of_interrupted_tests)/(double)number_of_tests)*100.0), - number_of_tests, number_of_successeded_tests); - - if(number_of_failed_tests > 0) - printf(", %d failed", number_of_failed_tests); - - if(number_of_interrupted_tests > 0) - printf(", %d interrupted)", number_of_interrupted_tests); - - printf(")\n\n"); - - total_of_tests = number_of_tests; - total_of_failed_tests = number_of_failed_tests; - total_of_interrupted_tests = number_of_interrupted_tests; - total_of_successeded_tests = number_of_successeded_tests; - } - - - - /* includes */ - total_of_failed_units = total_of_interrupted_units = total_of_successeded_units = 0; - number_of_failed_units = number_of_successeded_units = number_of_interrupted_units = 0; - number_of_units = xbt_dynar_length(unit->includes); - - xbt_dynar_foreach(unit->includes, itu, include) - { - - number_of_interrupted_tests = number_of_failed_tests = number_of_successeded_tests = 0; - - number_of_tests = xbt_dynar_length(include->commands); - - xbt_dynar_foreach(include->commands, itc, command) - { - if(command->status == cs_interrupted) - number_of_interrupted_tests++; - else if(command->status == cs_failed) - number_of_failed_tests++; - else if(command->status == cs_successeded) - number_of_successeded_tests++; - } - - asprintf(&p," Unit: %s ............................................................................", include->description && strlen(include->description) < 60 ? include->description : include->fstream->name); - - p[70] = '\0'; - printf("%s", p); - free(p); - - if(number_of_failed_tests > 0) - { - total_of_failed_units++; - printf(".. failed\n"); - } - else if(number_of_interrupted_tests > 0) - { - total_of_interrupted_units++; - printf("interrupt\n"); - } - else - { - total_of_successeded_units++; - printf(".... ..ok\n"); - } - - if(detail_summary_flag) - { - - xbt_dynar_foreach(include->commands, itc, command) - { - printf(" %s: %s [%s]\n", - command->status == cs_interrupted ? "INTR " - : command->status == cs_failed ? "FAILED" - : command->status == cs_successeded ? "PASS " - : "UNKNWN", - command->context->command_line, - command->context->pos); - - command_summarize(command); - } - - - } - - printf(" =====================================================================%s\n", - number_of_failed_tests ? "== FAILED": number_of_interrupted_tests ? "==== INTR" : "====== OK"); - - - printf(" Summary: Test(s): %.0f%% ok (%d test(s): %d ok", - (number_of_tests ? (1-((double)number_of_failed_tests + (double)number_of_interrupted_tests)/(double)number_of_tests)*100.0 : 100.0), - number_of_tests, number_of_successeded_tests); - - if(number_of_failed_tests > 0) - printf(", %d failed", number_of_failed_tests); - - if(number_of_interrupted_tests > 0) - printf(", %d interrupted)", number_of_interrupted_tests); - - printf(")\n\n"); - - - total_of_tests += number_of_tests; - total_of_failed_tests += number_of_failed_tests; - total_of_interrupted_tests += number_of_interrupted_tests; - total_of_successeded_tests += number_of_successeded_tests; - } - - /* suites */ - total_of_units = number_of_units; - - total_of_failed_suites = total_of_successeded_suites = total_of_interrupted_suites = 0; - - total_of_suites = xbt_dynar_length(unit->suites); - - xbt_dynar_foreach(unit->suites, its, suite) - { - print_title(suite->description); - - number_of_tests_of_suite = number_of_interrupted_tests_of_suite = number_of_failed_tests_of_suite = number_of_successeded_tests_of_suite = 0; - - number_of_interrupted_units = number_of_failed_units = number_of_successeded_units = 0; - - number_of_units = xbt_dynar_length(suite->includes); - - xbt_dynar_foreach(suite->includes, itu, include) - { - number_of_interrupted_tests = number_of_failed_tests = number_of_successeded_tests = 0; - - number_of_tests = xbt_dynar_length(include->commands); - - - xbt_dynar_foreach(include->commands, itc, command) - { - if(command->status == cs_interrupted) - number_of_interrupted_tests++; - else if(command->status == cs_failed) - number_of_failed_tests++; - else if(command->status == cs_successeded) - number_of_successeded_tests++; - } - - asprintf(&p," Unit: %s ............................................................................", include->description && strlen(include->description) < 60 ? include->description : include->fstream->name); - - p[70] = '\0'; - printf("%s", p); - free(p); - - if(number_of_failed_tests > 0) - { - number_of_failed_units++; - printf(".. failed\n"); - } - else if(number_of_interrupted_tests > 0) - { - number_of_interrupted_units++; - printf("interrupt\n"); - } - else - { - number_of_successeded_units++; - printf(".... ..ok\n"); - } - - number_of_interrupted_tests_of_suite += number_of_interrupted_tests; - number_of_failed_tests_of_suite += number_of_failed_tests; - number_of_successeded_tests_of_suite += number_of_successeded_tests; - - number_of_tests_of_suite += number_of_tests; - - total_of_tests += number_of_tests; - total_of_failed_tests += number_of_failed_tests; - total_of_interrupted_tests += number_of_interrupted_tests; - total_of_successeded_tests += number_of_successeded_tests; - - if(detail_summary_flag) - { - - xbt_dynar_foreach(include->commands, itc, command) - { - printf(" %s: %s [%s]\n", - command->status == cs_interrupted ? "INTR " - : command->status == cs_failed ? "FAILED" - : command->status == cs_successeded ? "PASS " - : "UNKNWN", - command->context->command_line, - command->context->pos); - - command_summarize(command); - } - - - } - - } - - printf(" =====================================================================%s\n", - number_of_failed_tests_of_suite ? "== FAILED": number_of_interrupted_tests_of_suite ? "==== INTR" : "====== OK"); - - if(number_of_failed_tests_of_suite > 0) - total_of_failed_suites++; - else if(number_of_interrupted_tests_of_suite) - total_of_interrupted_suites++; - else - total_of_successeded_suites++; - - total_of_failed_units += number_of_failed_units; - total_of_interrupted_units += number_of_interrupted_units; - total_of_successeded_units += number_of_successeded_units; - - total_of_units += number_of_units; - - printf(" Summary: Unit(s): %.0f%% ok (%d unit(s): %d ok", - (number_of_units ? (1-((double)number_of_failed_units + (double)number_of_interrupted_units)/(double)number_of_units)*100.0 : 100.0), - number_of_units, number_of_successeded_units); - - if(number_of_failed_units > 0) - printf(", %d failed", number_of_failed_units); - - if(number_of_interrupted_units > 0) - printf(", %d interrupted)", number_of_interrupted_units); - - printf(")\n"); - - printf(" Test(s): %.0f%% ok (%d test(s): %d ok", - (number_of_tests_of_suite ? (1-((double)number_of_failed_tests_of_suite + (double)number_of_interrupted_tests_of_suite)/(double)number_of_tests_of_suite)*100.0 : 100.0), - number_of_tests_of_suite, number_of_successeded_tests_of_suite); - - if(number_of_failed_tests_of_suite > 0) - printf(", %d failed", number_of_failed_tests_of_suite); - - if(number_of_interrupted_tests_of_suite > 0) - printf(", %d interrupted)", number_of_interrupted_tests_of_suite); - - printf(")\n\n"); - } - - printf(" TOTAL : Suite(s): %.0f%% ok (%d suite(s): %d ok", - (total_of_suites ? (1-((double)total_of_failed_suites + (double)total_of_interrupted_suites)/(double)total_of_suites)*100.0 : 100.0), - total_of_suites, total_of_successeded_suites); - - if(total_of_failed_suites > 0) - printf(", %d failed", total_of_failed_suites); - - if(total_of_interrupted_suites > 0) - printf(", %d interrupted)", total_of_interrupted_suites); - - printf(")\n"); - - printf(" Unit(s): %.0f%% ok (%d unit(s): %d ok", - (total_of_units ? (1-((double)total_of_failed_units + (double)total_of_interrupted_units)/(double)total_of_units)*100.0 : 100.0), - total_of_units, total_of_successeded_units); - - if(total_of_failed_units > 0) - printf(", %d failed", total_of_failed_units); - - if(total_of_interrupted_units > 0) - printf(", %d interrupted)", total_of_interrupted_units); - - printf(")\n"); - - printf(" Test(s): %.0f%% ok (%d test(s): %d ok", - (total_of_tests ? (1-((double)total_of_failed_tests + (double)total_of_interrupted_tests)/(double)total_of_tests)*100.0 : 100.0), - total_of_tests, total_of_successeded_tests); - - if(total_of_failed_tests > 0) - printf(", %d failed", total_of_failed_tests); - - if(total_of_interrupted_tests > 0) - printf(", %d interrupted)", total_of_interrupted_tests); - - printf(")\n\n"); - - if(unit->interrupted) - unit->runner->total_of_interrupted_units++; - else if(total_of_failed_tests > 0) - unit->runner->total_of_failed_units++; - else - unit->runner->total_of_successeded_units++; - - unit->runner->total_of_tests += total_of_tests; - unit->runner->total_of_failed_tests += total_of_failed_tests; - unit->runner->total_of_successeded_tests += total_of_successeded_tests; - unit->runner->total_of_interrupted_tests += total_of_interrupted_tests; - - unit->runner->total_of_units += total_of_units + 1; - unit->runner->total_of_successeded_units += total_of_successeded_units; - unit->runner->total_of_failed_units += total_of_failed_units; - unit->runner->total_of_interrupted_units += total_of_interrupted_units; - - unit->runner->total_of_suites += total_of_suites; - unit->runner->total_of_successeded_suites += total_of_successeded_suites; - unit->runner->total_of_failed_suites += total_of_failed_suites; - unit->runner->total_of_interrupted_suites += total_of_interrupted_suites; - - return 0; -} - -int -unit_reset(unit_t unit) -{ - unit_t cur; - unsigned int i; - - /* reset all the suites of the unit */ - xbt_dynar_foreach(unit->suites, i, cur) - { - unit_reset(cur); - } - - - /* reset all the includes of the unit */ - xbt_dynar_foreach(unit->includes, i, cur) - { - unit_reset(cur); - } - - fseek(unit->fstream->stream,0L, SEEK_SET); - unit->parsed = 0; - unit->cmd_nb = 0; - unit->started_cmd_nb = 0; - unit->interrupted_cmd_nb = 0; - unit->failed_cmd_nb = 0; - unit->successeded_cmd_nb = 0; - unit->terminated_cmd_nb = 0; - unit->waiting_cmd_nb = 0; - unit->interrupted = 0; - unit->failed = 0; - unit->successeded = 0; - unit->parsed = 0; - unit->released = 0; - unit->is_running_suite = 0; - - if(unit->description) - { - free(unit->description); - unit->description = NULL; - } + else if (root->exit_code) + ERROR3("Test unit `%s': NOK (<%s> %s)", root->fstream->name, + root->err_line, error_to_string(root->exit_code, + root->err_kind)); + } + + /* if it's the last unit, release the runner */ + if ((root->runner->number_of_runned_units == + root->runner->number_of_ended_units)) + { + + /* if all the commands of the unit are successeded itc's a successeded unit */ + if (root->successeded_cmd_nb == root->cmd_nb + && !root-> + exit_code /* case of only one cd : nb = successeded = 0) */ ) + root->successeded = 1; + + /* first release the mutex */ + xbt_os_mutex_release(root->mutex); + + /* release the runner */ + xbt_os_sem_release(units_sem); + } + + else + xbt_os_mutex_release(root->mutex); + + /* release the jobs semaphore, then the next waiting unit can start */ + xbt_os_sem_release(jobs_sem); + return NULL; + } + + unit_t +unit_new(runner_t runner, unit_t root, unit_t owner, fstream_t fstream) +{ + unit_t unit; + unit = xbt_new0(s_unit_t, 1); + + /* instantiate the vector used to store all the commands of the unit */ + unit->commands = + xbt_dynar_new(sizeof(command_t), (void_f_pvoid_t) command_free); + + /* instantiate the vector used to store all the included units */ + unit->includes = + xbt_dynar_new(sizeof(unit_t), (void_f_pvoid_t) unit_free); + + /* instantiate the vector used to store all the included suites */ + unit->suites = + xbt_dynar_new(sizeof(unit_t), (void_f_pvoid_t) unit_free); + + /* the runner used to launch the tesh unit */ + unit->runner = runner; + + /* the file stream object to use to parse the tesh file */ + unit->fstream = fstream; + if (fstream) + fstream->unit = unit; + + /* if no root parameter specified assume that itc's the root of all the units */ + unit->root = root ? root : unit; + + /* the owner of the suite */ + unit->owner = owner; + unit->thread = NULL; + unit->started_cmd_nb = 0; + unit->interrupted_cmd_nb = 0; + unit->failed_cmd_nb = 0; + unit->successeded_cmd_nb = 0; + unit->terminated_cmd_nb = 0; + unit->waiting_cmd_nb = 0; + unit->interrupted = 0; + unit->failed = 0; + unit->successeded = 0; + unit->parsed = 0; + unit->released = 0; + unit->owner = owner; + unit->is_running_suite = 0; + unit->description = NULL; + unit->sem = NULL; + unit->exit_code = 0; + unit->err_kind = 0; + unit->err_line = NULL; + unit->filepos = NULL; + return unit; + } + + void +unit_set_error(unit_t unit, int errcode, int kind, const char *line) +{ + if (!unit->exit_code) + { + unit->exit_code = errcode; + unit->err_kind = kind; + unit->err_line = strdup(line); + if (unit->root && !unit->root->exit_code) + { + unit->root->exit_code = errcode; + unit->root->err_kind = kind; + unit->root->err_line = strdup(line); + } + if (!exit_code) + { + exit_code = errcode; + err_kind = kind; + err_line = strdup(line); + } + } + } + + int unit_free(unit_t * ptr) +{ + if (!(*ptr)) + { + errno = EINVAL; + return -1; + } + if ((*ptr)->commands) + xbt_dynar_free(&((*ptr)->commands)); + if ((*ptr)->includes) + xbt_dynar_free(&((*ptr)->includes)); + if ((*ptr)->suites) + xbt_dynar_free(&((*ptr)->suites)); + + /* if the unit is interrupted during its run, the semaphore is NULL */ + if ((*ptr)->sem) + xbt_os_sem_destroy((*ptr)->sem); + if ((*ptr)->description) + free((*ptr)->description); + if ((*ptr)->err_line) + free((*ptr)->err_line); + if ((*ptr)->filepos) + free((*ptr)->filepos); + free(*ptr); + *ptr = NULL; + return 0; + } + + int unit_run(unit_t unit, xbt_os_mutex_t mutex) +{ + + /* check the parameters */ + if (!(unit) || !mutex) + { + errno = EINVAL; + xbt_os_sem_release(jobs_sem); + return -1; + } + if (!interrupted) + { + unit->mutex = mutex; + unit->sem = xbt_os_sem_init(0); + + /* start the unit */ + unit->thread = xbt_os_thread_create("", unit_start, unit); + } + + else + { + + /* the unit is interrupted by the runner before its starting + * in this case the unit semaphore is NULL take care of that + * in the function unit_free() + */ + unit->interrupted = 1; + xbt_os_sem_release(jobs_sem); + } + return 0; + } + + int unit_interrupt(unit_t unit) +{ + + /* check the parameter */ + if (!(unit)) + { + errno = EINVAL; + return -1; + } + + /* if the unit is already interrupted, signal the error */ + if (unit->interrupted) + { + errno = EALREADY; + return -1; + } + + /* interrupt the run of the specified unit */ + unit->interrupted = 1; + xbt_os_sem_release(unit->sem); + return 0; + } + + +/* just print the title of the root unit or a suite (if any) */ +static void print_title(const char *description) +{ + register int i; + char title[80]; + size_t len = strlen(description); + title[0] = ' '; + for (i = 1; i < 79; i++) + title[i] = '='; + title[i++] = '\n'; + title[79] = '\0'; + sprintf(title + 40 - (len + 4) / 2, "[ %s ]", description); + title[40 + (len + 5) / 2] = '='; + printf("\n%s\n", title); + } + + int unit_summuarize(unit_t unit) +{ + command_t command; + unsigned int itc, itu, its; + unit_t include; + unit_t suite; + char *p; + char title[PATH_MAX + 1] = { 0 }; + int number_of_tests = 0; /* number of tests of a unit contained by this unit */ + int number_of_failed_tests = 0; /* number of failed test of a unit contained by this unit */ + int number_of_successeded_tests = 0; /* number of successeded tests of a unit contained by this unit */ + int number_of_interrupted_tests = 0; /* number of interrupted tests of a unit contained by this unit */ + int number_of_tests_of_suite = 0; /* number of tests of a suite contained by this unit */ + int number_of_interrupted_tests_of_suite = 0; /* number of interrupted tests of a suite contained by this unit */ + int number_of_failed_tests_of_suite = 0; /* number of failed tests of a suite contained by this unit */ + int number_of_successeded_tests_of_suite = 0; /* number of successeded tests of a suite contained by this */ + int number_of_units = 0; /* number of units contained by a suite */ + int number_of_failed_units = 0; /* number of failed units contained by a suite */ + int number_of_successeded_units = 0; /* number of successeded units contained by a suite */ + int number_of_interrupted_units = 0; /* number of interrupted units contained by a suite */ + int total_of_tests = 0; /* total of the tests contained by this unit */ + int total_of_failed_tests = 0; /* total of failed tests contained by this unit */ + int total_of_successeded_tests = 0; /* total of successeded tests contained by this unit */ + int total_of_interrupted_tests = 0; /* total of interrupted tests contained by this unit */ + int total_of_units = 0; /* total of units contained by this unit */ + int total_of_failed_units = 0; /* total of failed units contained by this unit */ + int total_of_successeded_units = 0; /* total of successeded units contained by this unit */ + int total_of_interrupted_units = 0; /* total of interrutped units contained by this unit */ + int total_of_suites = 0; /* total of suites contained by this unit */ + int total_of_failed_suites = 0; /* total of failed suites contained by this unit */ + int total_of_successeded_suites = 0; /* total of successeded suites contained by this unit */ + int total_of_interrupted_suites = 0; /* total of interrupted suites contained by this unit */ + + /* check the parameter */ + if (!(unit)) + { + errno = EINVAL; + return -1; + } + if ((unit->description) && strlen(unit->description) < 76) + strcpy(title, unit->description); + + else + sprintf(title, "file : %s", unit->fstream->name); + if (unit->interrupted) + { + if (strlen(title) + strlen(" (interrupted)") < 76) + strcat(title, " (interrupted)"); + + else + { + memset(title, 0, PATH_MAX + 1); + sprintf(title, "file : %s", unit->fstream->name); + strcat(title, " (interrupted)"); + } + } + print_title(title); + number_of_tests = xbt_dynar_length(unit->commands); + + /* tests */ + xbt_dynar_foreach(unit->commands, itc, command) { + if (command->status == cs_interrupted) + number_of_interrupted_tests++; + + else if (command->status == cs_failed) + number_of_failed_tests++; + + else if (command->status == cs_successeded) + number_of_successeded_tests++; + } + if (number_of_tests) + { + asprintf(&p, + " Test(s): ........................................................................."); + p[70] = '\0'; + printf("%s", p); + free(p); + if (number_of_failed_tests > 0) + printf(".. failed\n"); + + else if (number_of_interrupted_tests > 0) + printf("interrupt\n"); + + else + printf(".... ..ok\n"); + xbt_dynar_foreach(unit->commands, itc, command) { + printf(" %s: %s [%s]\n", + command->status == + cs_interrupted ? "INTR " : command->status == + cs_failed ? "FAILED" : command->status == + cs_successeded ? "PASS " : "UNKNWN", + command->context->command_line, command->context->pos); + if (detail_summary_flag) + command_summarize(command); + } + printf + (" =====================================================================%s\n", + number_of_failed_tests ? "== FAILED" : + number_of_interrupted_tests ? "==== INTR" : "====== OK"); + printf(" Summary: Test(s): %.0f%% ok (%d test(s): %d ok", + ((1 - + ((double) number_of_failed_tests + + (double) number_of_interrupted_tests) / + (double) number_of_tests) * 100.0), number_of_tests, + number_of_successeded_tests); + if (number_of_failed_tests > 0) + printf(", %d failed", number_of_failed_tests); + if (number_of_interrupted_tests > 0) + printf(", %d interrupted)", number_of_interrupted_tests); + printf(")\n\n"); + total_of_tests = number_of_tests; + total_of_failed_tests = number_of_failed_tests; + total_of_interrupted_tests = number_of_interrupted_tests; + total_of_successeded_tests = number_of_successeded_tests; + } + + /* includes */ + total_of_failed_units = total_of_interrupted_units = + total_of_successeded_units = 0; + number_of_failed_units = number_of_successeded_units = + number_of_interrupted_units = 0; + number_of_units = xbt_dynar_length(unit->includes); + xbt_dynar_foreach(unit->includes, itu, include) { + number_of_interrupted_tests = number_of_failed_tests = + number_of_successeded_tests = 0; + number_of_tests = xbt_dynar_length(include->commands); + xbt_dynar_foreach(include->commands, itc, command) { + if (command->status == cs_interrupted) + number_of_interrupted_tests++; + + else if (command->status == cs_failed) + number_of_failed_tests++; + + else if (command->status == cs_successeded) + number_of_successeded_tests++; + } + asprintf(&p, + " Unit: %s ............................................................................", + include->description + && strlen(include->description) < + 60 ? include->description : include->fstream->name); + p[70] = '\0'; + printf("%s", p); + free(p); + if (number_of_failed_tests > 0) + { + total_of_failed_units++; + printf(".. failed\n"); + } + + else if (number_of_interrupted_tests > 0) + { + total_of_interrupted_units++; + printf("interrupt\n"); + } + + else + { + total_of_successeded_units++; + printf(".... ..ok\n"); + } + if (detail_summary_flag) + { + xbt_dynar_foreach(include->commands, itc, command) { + printf(" %s: %s [%s]\n", + command->status == + cs_interrupted ? "INTR " : command->status == + cs_failed ? "FAILED" : command->status == + cs_successeded ? "PASS " : "UNKNWN", + command->context->command_line, command->context->pos); + command_summarize(command); + } + } + printf + (" =====================================================================%s\n", + number_of_failed_tests ? "== FAILED" : + number_of_interrupted_tests ? "==== INTR" : "====== OK"); + printf(" Summary: Test(s): %.0f%% ok (%d test(s): %d ok", + (number_of_tests + ? (1 - + ((double) number_of_failed_tests + + (double) number_of_interrupted_tests) / + (double) number_of_tests) * 100.0 : 100.0), + number_of_tests, number_of_successeded_tests); + if (number_of_failed_tests > 0) + printf(", %d failed", number_of_failed_tests); + if (number_of_interrupted_tests > 0) + printf(", %d interrupted)", number_of_interrupted_tests); + printf(")\n\n"); + total_of_tests += number_of_tests; + total_of_failed_tests += number_of_failed_tests; + total_of_interrupted_tests += number_of_interrupted_tests; + total_of_successeded_tests += number_of_successeded_tests; + } + + /* suites */ + total_of_units = number_of_units; + total_of_failed_suites = total_of_successeded_suites = + total_of_interrupted_suites = 0; + total_of_suites = xbt_dynar_length(unit->suites); + xbt_dynar_foreach(unit->suites, its, suite) { + print_title(suite->description); + number_of_tests_of_suite = number_of_interrupted_tests_of_suite = + number_of_failed_tests_of_suite = + number_of_successeded_tests_of_suite = 0; + number_of_interrupted_units = number_of_failed_units = + number_of_successeded_units = 0; + number_of_units = xbt_dynar_length(suite->includes); + xbt_dynar_foreach(suite->includes, itu, include) { + number_of_interrupted_tests = number_of_failed_tests = + number_of_successeded_tests = 0; + number_of_tests = xbt_dynar_length(include->commands); + xbt_dynar_foreach(include->commands, itc, command) { + if (command->status == cs_interrupted) + number_of_interrupted_tests++; + + else if (command->status == cs_failed) + number_of_failed_tests++; + + else if (command->status == cs_successeded) + number_of_successeded_tests++; + } + asprintf(&p, + " Unit: %s ............................................................................", + include->description + && strlen(include->description) < + 60 ? include->description : include->fstream->name); + p[70] = '\0'; + printf("%s", p); + free(p); + if (number_of_failed_tests > 0) + { + number_of_failed_units++; + printf(".. failed\n"); + } + + else if (number_of_interrupted_tests > 0) + { + number_of_interrupted_units++; + printf("interrupt\n"); + } + + else + { + number_of_successeded_units++; + printf(".... ..ok\n"); + } + number_of_interrupted_tests_of_suite += + number_of_interrupted_tests; + number_of_failed_tests_of_suite += number_of_failed_tests; + number_of_successeded_tests_of_suite += number_of_successeded_tests; + number_of_tests_of_suite += number_of_tests; + total_of_tests += number_of_tests; + total_of_failed_tests += number_of_failed_tests; + total_of_interrupted_tests += number_of_interrupted_tests; + total_of_successeded_tests += number_of_successeded_tests; + if (detail_summary_flag) + { + xbt_dynar_foreach(include->commands, itc, command) { + printf(" %s: %s [%s]\n", + command->status == + cs_interrupted ? "INTR " : command->status == + cs_failed ? "FAILED" : command->status == + cs_successeded ? "PASS " : "UNKNWN", + command->context->command_line, command->context->pos); + command_summarize(command); + } + } + } + printf + (" =====================================================================%s\n", + number_of_failed_tests_of_suite ? "== FAILED" : + number_of_interrupted_tests_of_suite ? "==== INTR" : "====== OK"); + if (number_of_failed_tests_of_suite > 0) + total_of_failed_suites++; + + else if (number_of_interrupted_tests_of_suite) + total_of_interrupted_suites++; + + else + total_of_successeded_suites++; + total_of_failed_units += number_of_failed_units; + total_of_interrupted_units += number_of_interrupted_units; + total_of_successeded_units += number_of_successeded_units; + total_of_units += number_of_units; + printf(" Summary: Unit(s): %.0f%% ok (%d unit(s): %d ok", + (number_of_units + ? (1 - + ((double) number_of_failed_units + + (double) number_of_interrupted_units) / + (double) number_of_units) * 100.0 : 100.0), + number_of_units, number_of_successeded_units); + if (number_of_failed_units > 0) + printf(", %d failed", number_of_failed_units); + if (number_of_interrupted_units > 0) + printf(", %d interrupted)", number_of_interrupted_units); + printf(")\n"); + printf(" Test(s): %.0f%% ok (%d test(s): %d ok", + (number_of_tests_of_suite + ? (1 - + ((double) number_of_failed_tests_of_suite + + (double) number_of_interrupted_tests_of_suite) / + (double) number_of_tests_of_suite) * 100.0 : 100.0), + number_of_tests_of_suite, + number_of_successeded_tests_of_suite); + if (number_of_failed_tests_of_suite > 0) + printf(", %d failed", number_of_failed_tests_of_suite); + if (number_of_interrupted_tests_of_suite > 0) + printf(", %d interrupted)", number_of_interrupted_tests_of_suite); + printf(")\n\n"); + } + printf(" TOTAL : Suite(s): %.0f%% ok (%d suite(s): %d ok", + (total_of_suites + ? (1 - + ((double) total_of_failed_suites + + (double) total_of_interrupted_suites) / + (double) total_of_suites) * 100.0 : 100.0), + total_of_suites, total_of_successeded_suites); + if (total_of_failed_suites > 0) + printf(", %d failed", total_of_failed_suites); + if (total_of_interrupted_suites > 0) + printf(", %d interrupted)", total_of_interrupted_suites); + printf(")\n"); + printf(" Unit(s): %.0f%% ok (%d unit(s): %d ok", + (total_of_units + ? (1 - + ((double) total_of_failed_units + + (double) total_of_interrupted_units) / + (double) total_of_units) * 100.0 : 100.0), total_of_units, + total_of_successeded_units); + if (total_of_failed_units > 0) + printf(", %d failed", total_of_failed_units); + if (total_of_interrupted_units > 0) + printf(", %d interrupted)", total_of_interrupted_units); + printf(")\n"); + printf(" Test(s): %.0f%% ok (%d test(s): %d ok", + (total_of_tests + ? (1 - + ((double) total_of_failed_tests + + (double) total_of_interrupted_tests) / + (double) total_of_tests) * 100.0 : 100.0), total_of_tests, + total_of_successeded_tests); + if (total_of_failed_tests > 0) + printf(", %d failed", total_of_failed_tests); + if (total_of_interrupted_tests > 0) + printf(", %d interrupted)", total_of_interrupted_tests); + printf(")\n\n"); + if (unit->interrupted) + unit->runner->total_of_interrupted_units++; + + else if (total_of_failed_tests > 0) + unit->runner->total_of_failed_units++; + + else + unit->runner->total_of_successeded_units++; + unit->runner->total_of_tests += total_of_tests; + unit->runner->total_of_failed_tests += total_of_failed_tests; + unit->runner->total_of_successeded_tests += total_of_successeded_tests; + unit->runner->total_of_interrupted_tests += total_of_interrupted_tests; + unit->runner->total_of_units += total_of_units + 1; + unit->runner->total_of_successeded_units += total_of_successeded_units; + unit->runner->total_of_failed_units += total_of_failed_units; + unit->runner->total_of_interrupted_units += total_of_interrupted_units; + unit->runner->total_of_suites += total_of_suites; + unit->runner->total_of_successeded_suites += + total_of_successeded_suites; + unit->runner->total_of_failed_suites += total_of_failed_suites; + unit->runner->total_of_interrupted_suites += + total_of_interrupted_suites; + return 0; + } + + int unit_reset(unit_t unit) +{ + unit_t cur; + unsigned int i; + + /* reset all the suites of the unit */ + xbt_dynar_foreach(unit->suites, i, cur) { + unit_reset(cur); + } + /* reset all the includes of the unit */ + xbt_dynar_foreach(unit->includes, i, cur) { + unit_reset(cur); + } fseek(unit->fstream->stream, 0L, SEEK_SET); + unit->parsed = 0; + unit->cmd_nb = 0; + unit->started_cmd_nb = 0; + unit->interrupted_cmd_nb = 0; + unit->failed_cmd_nb = 0; + unit->successeded_cmd_nb = 0; + unit->terminated_cmd_nb = 0; + unit->waiting_cmd_nb = 0; + unit->interrupted = 0; + unit->failed = 0; + unit->successeded = 0; + unit->parsed = 0; + unit->released = 0; + unit->is_running_suite = 0; + if (unit->description) + { + free(unit->description); + unit->description = NULL; + } + unit->exit_code = 0; + return 0; + } + - unit->exit_code = 0; - - return 0; -} diff --git a/tools/tesh2/src/units.c b/tools/tesh2/src/units.c index b590f22348..f18b6db8d8 100644 --- a/tools/tesh2/src/units.c +++ b/tools/tesh2/src/units.c @@ -1,179 +1,133 @@ #include #include #include - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - -units_t -units_new(runner_t runner, fstreams_t fstreams) -{ - fstream_t fstream; - unsigned int i; - unit_t unit; - - units_t units = xbt_new0(s_units_t, 1); - - units->items = xbt_dynar_new(sizeof(unit_t), (void_f_pvoid_t)unit_free); - - xbt_dynar_foreach(fstreams->items, i, fstream) - { - unit = unit_new(runner, NULL, NULL, fstream); - xbt_dynar_push(units->items, &unit); - } - - return units; -} - - -int -units_is_empty(units_t units) -{ - if(!units) - { - errno = EINVAL; - return 0; - } - - return (0 == xbt_dynar_length(units->items)); -} - -int -units_get_size(units_t units) -{ - if(!units) - { - errno = EINVAL; - return -1; - } - - return xbt_dynar_length(units->items); -} - - -int -units_run_all(units_t units, xbt_os_mutex_t mutex) -{ - unit_t unit; - unsigned int i; - - if(!units) - return EINVAL; - - if(!xbt_dynar_length(units->items)) - return EAGAIN; - - xbt_dynar_foreach(units->items, i, unit) - { - xbt_os_sem_acquire(jobs_sem); - unit_run(unit, mutex); - } - - return 0; -} - -int -units_join_all(units_t units) -{ - unit_t unit; - unsigned int i; - - if(!units) - return EINVAL; - - if(!xbt_dynar_length(units->items)) - return EAGAIN; - - xbt_dynar_foreach(units->items, i, unit) - { - if(unit->thread) - xbt_os_thread_join(unit->thread, NULL); - } - - return 0; -} - -int -units_interrupt_all(units_t units) -{ - unit_t unit; - unsigned int i; - - if(!units) - return EINVAL; - - if(!xbt_dynar_length(units->items)) - return EAGAIN; - - xbt_dynar_foreach(units->items, i, unit) - { - if(!(unit->successeded) && !(unit->interrupted)) - unit_interrupt(unit); - else - { - if(!unit->released && unit->sem) - { - unit->released = 1; - xbt_os_sem_release(unit->sem); - } - } - - } - - return 0; -} - -int -units_summuarize(units_t units) -{ - unit_t unit; - unsigned int i; - - if(!units) - return EINVAL; - - if(!xbt_dynar_length(units->items)) - return EAGAIN; - - xbt_dynar_foreach(units->items, i, unit) - { - unit_summuarize(unit); - } - - return 0; - -} - -int -units_reset_all(units_t units) -{ - unit_t unit; - unsigned int i; - - if(!units) - return EINVAL; - - if(!xbt_dynar_length(units->items)) - return EAGAIN; - - xbt_dynar_foreach(units->items, i, unit) - { - unit_reset(unit); - } - return 0; -} - -int -units_free(void** unitsptr) -{ - if(!(*unitsptr)) - return EINVAL; - - if((*((units_t*)unitsptr))->items) - xbt_dynar_free(&((*((units_t*)unitsptr))->items)); - - free(*unitsptr); - *unitsptr = NULL; - - return 0; -} - + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + units_t units_new(runner_t runner, fstreams_t fstreams) +{ + fstream_t fstream; + unsigned int i; + unit_t unit; + units_t units = xbt_new0(s_units_t, 1); + units->items = + xbt_dynar_new(sizeof(unit_t), (void_f_pvoid_t) unit_free); + xbt_dynar_foreach(fstreams->items, i, fstream) { + unit = unit_new(runner, NULL, NULL, fstream); + xbt_dynar_push(units->items, &unit); + } + return units; + } + + int units_is_empty(units_t units) +{ + if (!units) + { + errno = EINVAL; + return 0; + } + return (0 == xbt_dynar_length(units->items)); + } + + int units_get_size(units_t units) +{ + if (!units) + { + errno = EINVAL; + return -1; + } + return xbt_dynar_length(units->items); + } + + int units_run_all(units_t units, xbt_os_mutex_t mutex) +{ + unit_t unit; + unsigned int i; + if (!units) + return EINVAL; + if (!xbt_dynar_length(units->items)) + return EAGAIN; + xbt_dynar_foreach(units->items, i, unit) { + xbt_os_sem_acquire(jobs_sem); + unit_run(unit, mutex); + } + return 0; + } + + int units_join_all(units_t units) +{ + unit_t unit; + unsigned int i; + if (!units) + return EINVAL; + if (!xbt_dynar_length(units->items)) + return EAGAIN; + xbt_dynar_foreach(units->items, i, unit) { + if (unit->thread) + xbt_os_thread_join(unit->thread, NULL); + } + return 0; + } + + int units_interrupt_all(units_t units) +{ + unit_t unit; + unsigned int i; + if (!units) + return EINVAL; + if (!xbt_dynar_length(units->items)) + return EAGAIN; + xbt_dynar_foreach(units->items, i, unit) { + if (!(unit->successeded) && !(unit->interrupted)) + unit_interrupt(unit); + + else + { + if (!unit->released && unit->sem) + { + unit->released = 1; + xbt_os_sem_release(unit->sem); + } + } + } + return 0; + } + + int units_summuarize(units_t units) +{ + unit_t unit; + unsigned int i; + if (!units) + return EINVAL; + if (!xbt_dynar_length(units->items)) + return EAGAIN; + xbt_dynar_foreach(units->items, i, unit) { + unit_summuarize(unit); + } + return 0; + } + + int units_reset_all(units_t units) +{ + unit_t unit; + unsigned int i; + if (!units) + return EINVAL; + if (!xbt_dynar_length(units->items)) + return EAGAIN; + xbt_dynar_foreach(units->items, i, unit) { + unit_reset(unit); + } + return 0; + } + + int units_free(void **unitsptr) +{ + if (!(*unitsptr)) + return EINVAL; + if ((*((units_t *) unitsptr))->items) + xbt_dynar_free(&((*((units_t *) unitsptr))->items)); + free(*unitsptr); + *unitsptr = NULL; + return 0; + } + + diff --git a/tools/tesh2/src/variable.c b/tools/tesh2/src/variable.c index 77268da0b0..5c885a97dc 100644 --- a/tools/tesh2/src/variable.c +++ b/tools/tesh2/src/variable.c @@ -1,72 +1,52 @@ #include + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + variable_t variable_new(const char *name, const char *val) +{ + variable_t variable; + if (!name) + { + errno = EINVAL; + return NULL; + } + variable = xbt_new0(s_variable_t, 1); + variable->name = strdup(name); + if (val) + variable->val = strdup(val); + variable->used = 0; + variable->env = 0; + variable->err = 0; + return variable; + } + + int variable_free(variable_t * variableptr) +{ + if (!(*variableptr)) + return EINVAL; + if ((*((variable_t *) (variableptr)))->name) + free((*((variable_t *) (variableptr)))->name); + if ((*((variable_t *) (variableptr)))->val) + free((*((variable_t *) (variableptr)))->val); + free(*variableptr); + *variableptr = NULL; + return 0; + } + + int variable_is_used(variable_t variable) +{ + if (!variable) + { + errno = EINVAL; + return 0; + } + return variable->used; + } + + int variable_set_used(variable_t variable) +{ + if (!variable) + return EINVAL; + variable->used = 1; + return 0; + } + -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - -variable_t -variable_new(const char* name, const char* val) -{ - variable_t variable; - - if(!name) - { - errno = EINVAL; - return NULL; - } - - variable = xbt_new0(s_variable_t, 1); - - variable->name = strdup(name); - - if(val) - variable->val = strdup(val); - - variable->used = 0; - variable->env = 0; - variable->err = 0; - - return variable; - -} - -int -variable_free(variable_t* variableptr) -{ - if(!(*variableptr)) - return EINVAL; - - if((*((variable_t*)(variableptr)))->name) - free((*((variable_t*)(variableptr)))->name); - - if((*((variable_t*)(variableptr)))->val) - free((*((variable_t*)(variableptr)))->val); - - free(*variableptr); - - *variableptr = NULL; - return 0; -} - - -int -variable_is_used(variable_t variable) -{ - if(!variable) - { - errno = EINVAL; - return 0; - } - - return variable->used; -} - - -int -variable_set_used(variable_t variable) -{ - if(!variable) - return EINVAL; - - variable->used = 1; - - return 0; -} diff --git a/tools/tesh2/src/writer.c b/tools/tesh2/src/writer.c index f1f13c5d48..25ef8e2213 100644 --- a/tools/tesh2/src/writer.c +++ b/tools/tesh2/src/writer.c @@ -10,206 +10,186 @@ * This file contains all the definitions of the functions related with * the tesh writer type. * - */ - + */ + #include #include #include - -XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); - -static void* -writer_start_routine(void* p); - -writer_t -writer_new(command_t command) -{ - writer_t writer; - /* TODO : check the parameter */ - - writer = xbt_new0(s_writer_t, 1); - - writer->thread = NULL; - writer->command = command; - writer->written = xbt_os_sem_init(0); - writer->can_write = xbt_os_sem_init(0); - - writer->done = 0; - - return writer; -} - -int -writer_free(writer_t* ptr) -{ - - if((*ptr)->written) - xbt_os_sem_destroy((*ptr)->written); - - if((*ptr)->can_write) - xbt_os_sem_destroy((*ptr)->can_write); - - free(*ptr); - - *ptr = NULL; - - return 0; -} - -void -writer_write(writer_t writer) -{ - writer->thread = xbt_os_thread_create("", writer_start_routine, writer); -} - + XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); + static void * writer_start_routine(void *p); + writer_t writer_new(command_t command) +{ + writer_t writer; + + /* TODO : check the parameter */ + writer = xbt_new0(s_writer_t, 1); + writer->thread = NULL; + writer->command = command; + writer->written = xbt_os_sem_init(0); + writer->can_write = xbt_os_sem_init(0); + writer->done = 0; + return writer; + } + + int writer_free(writer_t * ptr) +{ + if ((*ptr)->written) + xbt_os_sem_destroy((*ptr)->written); + if ((*ptr)->can_write) + xbt_os_sem_destroy((*ptr)->can_write); + free(*ptr); + *ptr = NULL; + return 0; + } + + void writer_write(writer_t writer) +{ + writer->thread = xbt_os_thread_create("", writer_start_routine, writer); + } + #ifdef _XBT_WIN32 -static void* -writer_start_routine(void* p) -{ - writer_t writer = (writer_t)p; - command_t command = writer->command; - - char* input = (char*)(command->context->input->data); - - DWORD number_of_bytes_to_write = command->context->input->used; - DWORD number_of_bytes_written = 0; - - xbt_os_sem_release(writer->written); - - while(!command->failed && !command->interrupted && !command->successeded && ! writer->failed && ! writer->broken_pipe && number_of_bytes_to_write) - { - if(!WriteFile(writer->command->stdin_fd, input, number_of_bytes_to_write, &number_of_bytes_written, NULL)) - { - if(GetLastError() == ERROR_NO_DATA) - writer->broken_pipe = 1; - else - writer->failed = 1; - - } - else - { - input += number_of_bytes_written; - number_of_bytes_to_write -= number_of_bytes_written; - } - } - - command->context->input->data[0]='\0'; - command->context->input->used=0; - - if(writer->failed && !command->successeded && !command->failed && !command->interrupted) - { - ERROR2("[%s] Error while writing input to child `%s'", command->context->pos, command->context->command_line); - unit_set_error(command->unit, (int)GetLastError(), 0, command->context->pos); - command_handle_failure(command, csr_write_failure); - } - /*else if(writer->broken_pipe && !command->successeded && !command->failed && !command->interrupted) - { - - ERROR2("[%s] Pipe broken while writing input to child `%s'", command->context->pos, command->context->command_line); - unit_set_error(command->unit, (int)GetLastError(), 0); - command_kill(command); - command_handle_failure(command, csr_write_pipe_broken); - }*/ - - CloseHandle(command->stdin_fd); - command->stdin_fd = INDEFINITE_FD; - - return NULL; -} -#else -static void* -writer_start_routine(void* p) -{ - writer_t writer = (writer_t)p; - command_t command = writer->command; - int number_of_bytes_to_write = command->context->input->used; - char* input = (char*)(command->context->input->data); - int got; - int released = 0; - - while(!command->failed && !command->interrupted && !command->successeded && number_of_bytes_to_write > 0) - { - got = number_of_bytes_to_write > PIPE_BUF ? PIPE_BUF : number_of_bytes_to_write; - got = write(writer->command->stdin_fd, input, got ); - - if(got < 0) - { - if(EINTR == errno) - continue; - - else if(EAGAIN == errno) - {/* the pipe is full */ - if(!released) - { - xbt_os_sem_release(writer->written); - released = 1; - xbt_os_thread_yield(); - } - - continue; - } - else if(EPIPE == errno) - { - writer->broken_pipe = 1; - break; - } - else - { - writer->failed = 1; - break; - } - - } - - number_of_bytes_to_write -= got; - input += got; - - if(got == 0) - xbt_os_thread_yield(); - - } - - if(!released) - xbt_os_sem_release(writer->written); - - - if(close(command->stdin_fd) < 0) - { - /* TODO */ - } - else - command->stdin_fd = INDEFINITE_FD; - - command->context->input->data[0]='\0'; - command->context->input->used=0; - - if(writer->failed && !command->successeded && !command->failed && !command->interrupted) - { - command_kill(command); - ERROR2("[%s] Error while writing input to child `%s'", command->context->pos, command->context->command_line); - - unit_set_error(command->unit, errno, 0, command->context->pos); - command_handle_failure(command, csr_write_failure); - } - else if(writer->broken_pipe && !command->successeded && !command->failed && !command->interrupted) - { - ERROR2("[%s] Pipe broken while writing input to child `%s'", command->context->pos, command->context->command_line); - - unit_set_error(command->unit, errno, 0, command->context->pos); - command_kill(command); - command_handle_failure(command, csr_write_pipe_broken); - } - - writer->done = 1; - - return NULL; - -} - -#endif -void -writer_wait(writer_t writer) -{ - xbt_os_thread_join(writer->thread, NULL); - -} +static void * writer_start_routine(void *p) +{ + writer_t writer = (writer_t) p; + command_t command = writer->command; + char *input = (char *) (command->context->input->data); + DWORD number_of_bytes_to_write = command->context->input->used; + DWORD number_of_bytes_written = 0; + xbt_os_sem_release(writer->written); + while (!command->failed && !command->interrupted + && !command->successeded && !writer->failed + && !writer->broken_pipe && number_of_bytes_to_write) + { + if (!WriteFile + (writer->command->stdin_fd, input, number_of_bytes_to_write, + &number_of_bytes_written, NULL)) + { + if (GetLastError() == ERROR_NO_DATA) + writer->broken_pipe = 1; + + else + writer->failed = 1; + } + + else + { + input += number_of_bytes_written; + number_of_bytes_to_write -= number_of_bytes_written; + } + } + command->context->input->data[0] = '\0'; + command->context->input->used = 0; + if (writer->failed && !command->successeded && !command->failed + && !command->interrupted) + { + ERROR2("[%s] Error while writing input to child `%s'", + command->context->pos, command->context->command_line); + unit_set_error(command->unit, (int) GetLastError(), 0, + command->context->pos); + command_handle_failure(command, csr_write_failure); + } + + /*else if(writer->broken_pipe && !command->successeded && !command->failed && !command->interrupted) + { + + ERROR2("[%s] Pipe broken while writing input to child `%s'", command->context->pos, command->context->command_line); + unit_set_error(command->unit, (int)GetLastError(), 0); + command_kill(command); + command_handle_failure(command, csr_write_pipe_broken); + } */ + CloseHandle(command->stdin_fd); + command->stdin_fd = INDEFINITE_FD; + return NULL; + } + + +#else /* */ +static void * writer_start_routine(void *p) +{ + writer_t writer = (writer_t) p; + command_t command = writer->command; + int number_of_bytes_to_write = command->context->input->used; + char *input = (char *) (command->context->input->data); + int got; + int released = 0; + while (!command->failed && !command->interrupted + && !command->successeded && number_of_bytes_to_write > 0) + { + got = + number_of_bytes_to_write > + PIPE_BUF ? PIPE_BUF : number_of_bytes_to_write; + got = write(writer->command->stdin_fd, input, got); + if (got < 0) + { + if (EINTR == errno) + continue; + + else if (EAGAIN == errno) + { /* the pipe is full */ + if (!released) + { + xbt_os_sem_release(writer->written); + released = 1; + xbt_os_thread_yield(); + } + continue; + } + + else if (EPIPE == errno) + { + writer->broken_pipe = 1; + break; + } + + else + { + writer->failed = 1; + break; + } + } + number_of_bytes_to_write -= got; + input += got; + if (got == 0) + xbt_os_thread_yield(); + } + if (!released) + xbt_os_sem_release(writer->written); + if (close(command->stdin_fd) < 0) + { + + /* TODO */ + } + + else + command->stdin_fd = INDEFINITE_FD; + command->context->input->data[0] = '\0'; + command->context->input->used = 0; + if (writer->failed && !command->successeded && !command->failed + && !command->interrupted) + { + command_kill(command); + ERROR2("[%s] Error while writing input to child `%s'", + command->context->pos, command->context->command_line); + unit_set_error(command->unit, errno, 0, command->context->pos); + command_handle_failure(command, csr_write_failure); + } + + else if (writer->broken_pipe && !command->successeded && !command->failed + && !command->interrupted) + { + ERROR2("[%s] Pipe broken while writing input to child `%s'", + command->context->pos, command->context->command_line); + unit_set_error(command->unit, errno, 0, command->context->pos); + command_kill(command); + command_handle_failure(command, csr_write_pipe_broken); + } + writer->done = 1; + return NULL; + } + + +#endif /* */ +void writer_wait(writer_t writer) +{ + xbt_os_thread_join(writer->thread, NULL); + } diff --git a/tools/tesh2/src/xerrno.c b/tools/tesh2/src/xerrno.c index 0b8deff47c..91c474f4d0 100644 --- a/tools/tesh2/src/xerrno.c +++ b/tools/tesh2/src/xerrno.c @@ -1,416 +1,398 @@ #include - -typedef struct s_entry -{ - const char* name; - int code; - unsigned kind : 1; /* if 1 it's an error of the application else assume it's a system error */ - const char* string; - -}entry_t; - - -static const -entry_t err[] = -{ - - #ifdef E2BIG - {"E2BIG", E2BIG, 0, "argument list too long"}, - #endif - - #ifdef EACCES - {"EACCES", EACCES, 0, "permission denied"}, - #endif - - #ifdef EADDRINUSE - {"EADDRINUSE", EADDRINUSE, 0, "address in use"}, - #endif - - #ifdef EADDRNOTAVAIL - {"EADDRNOTAVAIL", EADDRNOTAVAIL, 0, "address not available"}, - #endif - - #ifdef EAFNOSUPPORT - {"EAFNOSUPPORT", EAFNOSUPPORT, 0, "address family not supported"}, - #endif - - #ifdef EAGAIN - {"EAGAIN", EAGAIN, 0, "resource unavailable, try again"}, - #endif - - #ifdef EALREADY - {"EALREADY", EALREADY, 0, "connection already in progress"}, - #endif - - #ifdef EBADF - {"EBADF", EBADF, 0, "bad file descriptor"}, - #endif - - #ifdef EBADMSG - {"EBADMSG", EBADMSG, 0, "bad message"}, - #endif - - #ifdef EBUSY - {"EBUSY", EBUSY, 0, "device or resource busy"}, - #endif - - #ifdef ECANCELED - {"ECANCELED", ECANCELED, 0, "operation canceled"}, - #endif - - #ifdef ECHILD - {"ECHILD", ECHILD, 0, "no child processes"}, - #endif - - #ifdef ECONNABORTED - {"ECONNABORTED", ECONNABORTED, 0, "connection aborted"}, - #endif - - #ifdef ECONNREFUSED - {"ECONNREFUSED", ECONNREFUSED, 0, "connection refused"}, - #endif - - #ifdef ECONNRESET - {"ECONNRESET", ECONNRESET, 0, "connection reset"}, - #endif - - #ifdef EDEADLK - {"EDEADLK", EDEADLK, 0, "resource deadlock would occur"}, - #endif - - #ifdef EDESTADDRREQ - {"EDESTADDRREQ", EDESTADDRREQ, 0, "destination address required"}, - #endif - - #ifdef EDOM - {"EDOM", EDOM, 0, "mathematics argument out of domain of function"}, - #endif - - #ifdef EEXIST - {"EEXIST", EEXIST, 0, "file exists"}, - #endif - - #ifdef EFAULT - {"EFAULT", EFAULT, 0, "bad address"}, - #endif - - #ifdef EFBIG - {"EFBIG", EFBIG, 0, "file too large"}, - #endif - - #ifdef EHOSTUNREACH - {"EHOSTUNREACH", EHOSTUNREACH, 0, "host is unreachable"}, - #endif - - #ifdef EIDRM - {"EIDRM", EIDRM, 0, "identifier removed"}, - #endif - - #ifdef EILSEQ - {"EILSEQ", EILSEQ, 0, "illegal byte sequence"}, - #endif - - #ifdef EINPROGRESS - {"EINPROGRESS", EINPROGRESS, 0, "operation in progress"}, - #endif - - #ifdef EINTR - {"EINTR", EINTR, 0, "interrupted function"}, - #endif - - #ifdef EINVAL - {"EINVAL", EINVAL, 0, "invalid argument"}, - #endif - - #ifdef EIO - {"EIO", EIO, 0, "I/O error"}, - #endif - - #ifdef EISCONN - {"EISCONN", EISCONN, 0, "socket is connected"}, - #endif - - #ifdef EISDIR - {"EISDIR", EISDIR, 0, "is a directory"}, - #endif - - #ifdef ELOOP - {"ELOOP", ELOOP, 0, "too many levels of symbolic links"}, - #endif - - #ifdef EMFILE - {"EMFILE", EMFILE, 0, "too many open files"}, - #endif - - #ifdef EMLINK - {"EMLINK", EMLINK, 0, "too many links"}, - #endif - - #ifdef EMSGSIZE - {"EMSGSIZE", EMSGSIZE, 0, "message too large"}, - #endif - - #ifdef ENAMETOOLONG - {"ENAMETOOLONG", ENAMETOOLONG, 0, "filename too long"}, - #endif - - #ifdef ENETDOWN - {"ENETDOWN", ENETDOWN, 0, "network is down"}, - #endif - - #ifdef ENETRESET - {"ENETRESET", ENETRESET, 0, "connection aborted by network"}, - #endif - - #ifdef ENETUNREACH - {"ENETUNREACH", ENETUNREACH, 0, "network unreachable"}, - #endif - - #ifdef ENFILE - {"ENFILE", ENFILE, 0, "too many files open in system"}, - #endif - - #ifdef ENOBUFS - {"ENOBUFS", ENOBUFS, 0, "no buffer space available"}, - #endif - - #ifdef ENODATA - {"ENODATA", ENODATA, 0, "no message is available on the STREAM head read queue"}, - #endif - - #ifdef ENODEV - {"ENODEV", ENODEV, 0, "no such device"}, - #endif - - #ifdef ENOENT - {"ENOENT", ENOENT, 0, "no such file or directory"}, - #endif - - #ifdef ENOEXEC - {"ENOEXEC", ENOEXEC, 0, "executable file format error"}, - #endif - - #ifdef ENOLCK - {"ENOLCK", ENOLCK, 0, "no locks available"}, - #endif - - #ifdef ENOMEM - {"ENOMEM", ENOMEM, 0, "not enough space"}, - #endif - - #ifdef ENOMSG - {"ENOMSG", ENOMSG, 0, "no message of the desired type"}, - #endif - - #ifdef ENOPROTOOPT - {"ENOPROTOOPT", ENOPROTOOPT, 0, "protocol not available"}, - #endif - - #ifdef ENOSPC - {"ENOSPC", ENOSPC, 0, "no space left on device"}, - #endif - - #ifdef ENOSR - {"ENOSR", ENOSR, 0, "no stream resources"}, - #endif - - #ifdef ENOSTR - {"ENOSTR", ENOSTR, 0, "not a stream"}, - #endif - - #ifdef ENOSYS - {"ENOSYS", ENOSYS, 0, "function not supported"}, - #endif - - #ifdef ENOTCONN - {"ENOTCONN", ENOTCONN, 0, "the socket is not connected"}, - #endif - - #ifdef ENOTDIR - {"ENOTDIR", ENOTDIR, 0, "not a directory"}, - #endif - - #ifdef ENOTEMPTY - {"ENOTEMPTY", ENOTEMPTY, 0, "directory not empty"}, - #endif - - #ifdef ENOTSOCK - {"ENOTSOCK", ENOTSOCK, 0, "not a socket"}, - #endif - - #ifdef ENOTSUP - {"ENOTSUP", ENOTSUP, 0, "not supported"}, - #endif - - #ifdef ENOTTY - {"ENOTTY", ENOTTY, 0, "inappropriate I/O control operation"}, - #endif - - #ifdef ENXIO - {"ENXIO", ENXIO, 0, "no such device or address"}, - #endif - - #ifdef EOPNOTSUPP - {"EOPNOTSUPP", EOPNOTSUPP, 0, "operation not supported on socket"}, - #endif - - #ifdef EOVERFLOW - {"EOVERFLOW", EOVERFLOW, 0, "value too large to be stored in data type"}, - #endif - - #ifdef EPERM - {"EPERM", EPERM, 0, "operation not permitted"}, - #endif - - #ifdef EPIPE - {"EPIPE", EPIPE, 0, "broken pipe"}, - #endif - - #ifdef EPROTO - {"EPROTO", EPROTO, 0, "protocol error"}, - #endif - - #ifdef EPROTONOSUPPORT - {"EPROTONOSUPPORT", EPROTONOSUPPORT, 0, "protocol not supported"}, - #endif - - #ifdef EPROTOTYPE - {"EPROTOTYPE", EPROTOTYPE, 0, "protocol wrong type for socket"}, - #endif - - #ifdef ERANGE - {"ERANGE", ERANGE, 0, "result too large"}, - #endif - - #ifdef EROFS - {"EROFS", EROFS, 0, "read-only file system"}, - #endif - - #ifdef ESPIPE - {"ESPIPE", ESPIPE, 0, "invalid seek"}, - #endif - - #ifdef ESRCH - {"ESRCH", ESRCH, 0, "no such process"}, - #endif - - #ifdef ETIME - {"ETIME", ETIME, 0, "stream ioctl() timeout"}, - #endif - - #ifdef ETIMEDOUT - {"ETIMEDOUT", ETIMEDOUT, 0, "connection timed out"}, - #endif - - #ifdef ETXTBSY - {"ETXTBSY", ETXTBSY, 0, "text file busy"}, - #endif - - #ifdef EWOULDBLOCK - {"EWOULDBLOCK", EWOULDBLOCK, 0, "operation would block"}, - #endif - - #ifdef EXDEV - {"EXDEV", EXDEV, 0, "cross-device link"}, - #endif - - {"ECMDTIMEDOUT", ECMDTIMEDOUT, 1, "command timed out"}, - - {"ECMDNOTFOUND", ECMDNOTFOUND,1, "command not found"}, - - {"EEXITCODENOTMATCH", EEXITCODENOTMATCH,1, "exit code mismatch"}, - - {"EOUTPUTNOTMATCH", EOUTPUTNOTMATCH,1, "output mismatch"}, - - {"ESIGNOTMATCH", ESIGNOTMATCH,1, "signal mismatch"}, - - {"EUNXPSIG", EUNXPSIG,1, "unexpected signal caught"}, - - {"ESIGNOTRECEIPT", ESIGNOTRECEIVED,1, "expected signal not receipt"}, - - {"EPROCCMDLINE", EPROCCMDLINE, 1, "command line processing failed"}, - - {"ENOARG", ENOARG, 1, "none optional argument not specified"}, - - {"ENOTPOSITIVENUM", ENOTPOSITIVENUM, 1, "argument option not strictly positive"}, - - {"ESYNTAX", ESYNTAX,1, "syntax error"}, - - {"ELEADTIME", ELEADTIME, 1, "timed out"}, - - {"EREADMENOTFOUND", EREADMENOTFOUND,1, "unable to locate the README.txt file"}, - - {"EINCLUDENOTFOUND", EINCLUDENOTFOUND, 1, "include file not found"}, - - {"ESUFFIXTOOLONG", ESUFFIXTOOLONG,1, "suffix too long"}, - - {"EINVCMDLINE", EINVCMDLINE,1, "invalid command line"}, - - {"unkwown", -1, 0, "unknown"} -}; - + typedef struct s_entry { + const char *name; + int code; + unsigned kind:1; /* if 1 it's an error of the application else assume it's a system error */ + const char *string; + } entry_t; + static const entry_t err[] = { +#ifdef E2BIG + {"E2BIG", E2BIG, 0, "argument list too long"}, +#endif /* */ + +#ifdef EACCES + {"EACCES", EACCES, 0, "permission denied"}, +#endif /* */ + +#ifdef EADDRINUSE + {"EADDRINUSE", EADDRINUSE, 0, "address in use"}, +#endif /* */ + +#ifdef EADDRNOTAVAIL + {"EADDRNOTAVAIL", EADDRNOTAVAIL, 0, "address not available"}, +#endif /* */ + +#ifdef EAFNOSUPPORT + {"EAFNOSUPPORT", EAFNOSUPPORT, 0, "address family not supported"}, +#endif /* */ + +#ifdef EAGAIN + {"EAGAIN", EAGAIN, 0, "resource unavailable, try again"}, +#endif /* */ + +#ifdef EALREADY + {"EALREADY", EALREADY, 0, "connection already in progress"}, +#endif /* */ + +#ifdef EBADF + {"EBADF", EBADF, 0, "bad file descriptor"}, +#endif /* */ + +#ifdef EBADMSG + {"EBADMSG", EBADMSG, 0, "bad message"}, +#endif /* */ + +#ifdef EBUSY + {"EBUSY", EBUSY, 0, "device or resource busy"}, +#endif /* */ + +#ifdef ECANCELED + {"ECANCELED", ECANCELED, 0, "operation canceled"}, +#endif /* */ + +#ifdef ECHILD + {"ECHILD", ECHILD, 0, "no child processes"}, +#endif /* */ + +#ifdef ECONNABORTED + {"ECONNABORTED", ECONNABORTED, 0, "connection aborted"}, +#endif /* */ + +#ifdef ECONNREFUSED + {"ECONNREFUSED", ECONNREFUSED, 0, "connection refused"}, +#endif /* */ + +#ifdef ECONNRESET + {"ECONNRESET", ECONNRESET, 0, "connection reset"}, +#endif /* */ + +#ifdef EDEADLK + {"EDEADLK", EDEADLK, 0, "resource deadlock would occur"}, +#endif /* */ + +#ifdef EDESTADDRREQ + {"EDESTADDRREQ", EDESTADDRREQ, 0, "destination address required"}, +#endif /* */ + +#ifdef EDOM + {"EDOM", EDOM, 0, "mathematics argument out of domain of function"}, +#endif /* */ + +#ifdef EEXIST + {"EEXIST", EEXIST, 0, "file exists"}, +#endif /* */ + +#ifdef EFAULT + {"EFAULT", EFAULT, 0, "bad address"}, +#endif /* */ + +#ifdef EFBIG + {"EFBIG", EFBIG, 0, "file too large"}, +#endif /* */ + +#ifdef EHOSTUNREACH + {"EHOSTUNREACH", EHOSTUNREACH, 0, "host is unreachable"}, +#endif /* */ + +#ifdef EIDRM + {"EIDRM", EIDRM, 0, "identifier removed"}, +#endif /* */ + +#ifdef EILSEQ + {"EILSEQ", EILSEQ, 0, "illegal byte sequence"}, +#endif /* */ + +#ifdef EINPROGRESS + {"EINPROGRESS", EINPROGRESS, 0, "operation in progress"}, +#endif /* */ + +#ifdef EINTR + {"EINTR", EINTR, 0, "interrupted function"}, +#endif /* */ + +#ifdef EINVAL + {"EINVAL", EINVAL, 0, "invalid argument"}, +#endif /* */ + +#ifdef EIO + {"EIO", EIO, 0, "I/O error"}, +#endif /* */ + +#ifdef EISCONN + {"EISCONN", EISCONN, 0, "socket is connected"}, +#endif /* */ + +#ifdef EISDIR + {"EISDIR", EISDIR, 0, "is a directory"}, +#endif /* */ + +#ifdef ELOOP + {"ELOOP", ELOOP, 0, "too many levels of symbolic links"}, +#endif /* */ + +#ifdef EMFILE + {"EMFILE", EMFILE, 0, "too many open files"}, +#endif /* */ + +#ifdef EMLINK + {"EMLINK", EMLINK, 0, "too many links"}, +#endif /* */ + +#ifdef EMSGSIZE + {"EMSGSIZE", EMSGSIZE, 0, "message too large"}, +#endif /* */ + +#ifdef ENAMETOOLONG + {"ENAMETOOLONG", ENAMETOOLONG, 0, "filename too long"}, +#endif /* */ + +#ifdef ENETDOWN + {"ENETDOWN", ENETDOWN, 0, "network is down"}, +#endif /* */ + +#ifdef ENETRESET + {"ENETRESET", ENETRESET, 0, "connection aborted by network"}, +#endif /* */ + +#ifdef ENETUNREACH + {"ENETUNREACH", ENETUNREACH, 0, "network unreachable"}, +#endif /* */ + +#ifdef ENFILE + {"ENFILE", ENFILE, 0, "too many files open in system"}, +#endif /* */ + +#ifdef ENOBUFS + {"ENOBUFS", ENOBUFS, 0, "no buffer space available"}, +#endif /* */ + +#ifdef ENODATA + {"ENODATA", ENODATA, 0, + "no message is available on the STREAM head read queue"}, +#endif /* */ + +#ifdef ENODEV + {"ENODEV", ENODEV, 0, "no such device"}, +#endif /* */ + +#ifdef ENOENT + {"ENOENT", ENOENT, 0, "no such file or directory"}, +#endif /* */ + +#ifdef ENOEXEC + {"ENOEXEC", ENOEXEC, 0, "executable file format error"}, +#endif /* */ + +#ifdef ENOLCK + {"ENOLCK", ENOLCK, 0, "no locks available"}, +#endif /* */ + +#ifdef ENOMEM + {"ENOMEM", ENOMEM, 0, "not enough space"}, +#endif /* */ + +#ifdef ENOMSG + {"ENOMSG", ENOMSG, 0, "no message of the desired type"}, +#endif /* */ + +#ifdef ENOPROTOOPT + {"ENOPROTOOPT", ENOPROTOOPT, 0, "protocol not available"}, +#endif /* */ + +#ifdef ENOSPC + {"ENOSPC", ENOSPC, 0, "no space left on device"}, +#endif /* */ + +#ifdef ENOSR + {"ENOSR", ENOSR, 0, "no stream resources"}, +#endif /* */ + +#ifdef ENOSTR + {"ENOSTR", ENOSTR, 0, "not a stream"}, +#endif /* */ + +#ifdef ENOSYS + {"ENOSYS", ENOSYS, 0, "function not supported"}, +#endif /* */ + +#ifdef ENOTCONN + {"ENOTCONN", ENOTCONN, 0, "the socket is not connected"}, +#endif /* */ + +#ifdef ENOTDIR + {"ENOTDIR", ENOTDIR, 0, "not a directory"}, +#endif /* */ + +#ifdef ENOTEMPTY + {"ENOTEMPTY", ENOTEMPTY, 0, "directory not empty"}, +#endif /* */ + +#ifdef ENOTSOCK + {"ENOTSOCK", ENOTSOCK, 0, "not a socket"}, +#endif /* */ + +#ifdef ENOTSUP + {"ENOTSUP", ENOTSUP, 0, "not supported"}, +#endif /* */ + +#ifdef ENOTTY + {"ENOTTY", ENOTTY, 0, "inappropriate I/O control operation"}, +#endif /* */ + +#ifdef ENXIO + {"ENXIO", ENXIO, 0, "no such device or address"}, +#endif /* */ + +#ifdef EOPNOTSUPP + {"EOPNOTSUPP", EOPNOTSUPP, 0, "operation not supported on socket"}, +#endif /* */ + +#ifdef EOVERFLOW + {"EOVERFLOW", EOVERFLOW, 0, "value too large to be stored in data type"}, +#endif /* */ + +#ifdef EPERM + {"EPERM", EPERM, 0, "operation not permitted"}, +#endif /* */ + +#ifdef EPIPE + {"EPIPE", EPIPE, 0, "broken pipe"}, +#endif /* */ + +#ifdef EPROTO + {"EPROTO", EPROTO, 0, "protocol error"}, +#endif /* */ + +#ifdef EPROTONOSUPPORT + {"EPROTONOSUPPORT", EPROTONOSUPPORT, 0, "protocol not supported"}, +#endif /* */ + +#ifdef EPROTOTYPE + {"EPROTOTYPE", EPROTOTYPE, 0, "protocol wrong type for socket"}, +#endif /* */ + +#ifdef ERANGE + {"ERANGE", ERANGE, 0, "result too large"}, +#endif /* */ + +#ifdef EROFS + {"EROFS", EROFS, 0, "read-only file system"}, +#endif /* */ + +#ifdef ESPIPE + {"ESPIPE", ESPIPE, 0, "invalid seek"}, +#endif /* */ + +#ifdef ESRCH + {"ESRCH", ESRCH, 0, "no such process"}, +#endif /* */ + +#ifdef ETIME + {"ETIME", ETIME, 0, "stream ioctl() timeout"}, +#endif /* */ + +#ifdef ETIMEDOUT + {"ETIMEDOUT", ETIMEDOUT, 0, "connection timed out"}, +#endif /* */ + +#ifdef ETXTBSY + {"ETXTBSY", ETXTBSY, 0, "text file busy"}, +#endif /* */ + +#ifdef EWOULDBLOCK + {"EWOULDBLOCK", EWOULDBLOCK, 0, "operation would block"}, +#endif /* */ + +#ifdef EXDEV + {"EXDEV", EXDEV, 0, "cross-device link"}, +#endif /* */ + + {"ECMDTIMEDOUT", ECMDTIMEDOUT, 1, "command timed out"}, + {"ECMDNOTFOUND", ECMDNOTFOUND, 1, "command not found"}, + {"EEXITCODENOTMATCH", EEXITCODENOTMATCH, 1, "exit code mismatch"}, + {"EOUTPUTNOTMATCH", EOUTPUTNOTMATCH, 1, "output mismatch"}, + {"ESIGNOTMATCH", ESIGNOTMATCH, 1, "signal mismatch"}, + {"EUNXPSIG", EUNXPSIG, 1, "unexpected signal caught"}, + {"ESIGNOTRECEIPT", ESIGNOTRECEIVED, 1, + "expected signal not receipt"}, {"EPROCCMDLINE", EPROCCMDLINE, 1, + "command line processing failed"}, + {"ENOARG", ENOARG, 1, "none optional argument not specified"}, + {"ENOTPOSITIVENUM", ENOTPOSITIVENUM, 1, + "argument option not strictly positive"}, {"ESYNTAX", ESYNTAX, + 1, "syntax error"}, + {"ELEADTIME", ELEADTIME, 1, "timed out"}, {"EREADMENOTFOUND", + EREADMENOTFOUND, 1, + "unable to locate the README.txt file"}, + {"EINCLUDENOTFOUND", EINCLUDENOTFOUND, 1, + "include file not found"}, {"ESUFFIXTOOLONG", ESUFFIXTOOLONG, 1, + "suffix too long"}, + {"EINVCMDLINE", EINVCMDLINE, 1, "invalid command line"}, + {"unkwown", -1, 0, "unknown"} +}; + + #include - + #ifdef _XBT_WIN32 -static char * -w32error_to_string(DWORD errcode) -{ - static char buffer[128]; - - /* - * Special code for winsock error handling. - */ - if (errcode > WSABASEERR) - { - HMODULE hModule = GetModuleHandle("wsock32"); - - if(hModule) - { - FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,hModule, errcode, LANG_NEUTRAL, buffer, 128, NULL); - FreeLibrary(hModule); - } - } - else - { - /* - * Default system message handling - */ - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errcode, LANG_NEUTRAL, buffer, 128, NULL); - } - - return buffer; -} -#endif - -const char* -error_to_string(int errcode, int kind) -{ - int i; - - for(i = 0; err[i].code != -1; i++) - if(err[i].code == errcode && err[i].kind == kind) - return err[i].string; - - #ifdef _XBT_WIN32 - - /* assume it's a W32 error */ - return w32error_to_string((DWORD)errcode); - #else - return "unknow error"; - #endif - -} - -const char* -error_get_at(int pos, int* code) -{ - if(pos < 0 || (pos > (sizeof(err)/sizeof(entry_t)) - 2)) - { - errno = ERANGE; - return NULL; - } - - *code = err[pos].code; - return err[pos].name; -} +static char * w32error_to_string(DWORD errcode) +{ + static char buffer[128]; + + /* + * Special code for winsock error handling. + */ + if (errcode > WSABASEERR) + { + HMODULE hModule = GetModuleHandle("wsock32"); + if (hModule) + { + FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, hModule, errcode, + LANG_NEUTRAL, buffer, 128, NULL); + FreeLibrary(hModule); + } + } + + else + { + + /* + * Default system message handling + */ + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errcode, + LANG_NEUTRAL, buffer, 128, NULL); + } + return buffer; + } + +#endif /* */ + const char * error_to_string(int errcode, int kind) +{ + int i; + for (i = 0; err[i].code != -1; i++) + if (err[i].code == errcode && err[i].kind == kind) + return err[i].string; + +#ifdef _XBT_WIN32 + + /* assume it's a W32 error */ + return w32error_to_string((DWORD) errcode); + +#else /* */ + return "unknow error"; + +#endif /* */ + } + + const char * error_get_at(int pos, int *code) +{ + if (pos < 0 || (pos > (sizeof(err) / sizeof(entry_t)) - 2)) + { + errno = ERANGE; + return NULL; + } + *code = err[pos].code; + return err[pos].name; + } + + diff --git a/tools/tesh2/src/xsignal.c b/tools/tesh2/src/xsignal.c index 3b0755cff6..28e8f31f5d 100644 --- a/tools/tesh2/src/xsignal.c +++ b/tools/tesh2/src/xsignal.c @@ -1,139 +1,129 @@ -/* $Id: signal.c 3483 2007-05-07 11:18:56Z mquinson $ */ - -/* signal -- what TESH needs to know about signals */ - -/* Copyright (c) 2007 Martin Quinson. */ -/* All rights reserved. */ - +/* $Id: signal.c 3483 2007-05-07 11:18:56Z mquinson $ */ + +/* signal -- what TESH needs to know about signals */ + +/* Copyright (c) 2007 Martin Quinson. */ +/* All rights reserved. */ + /* 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. */ - + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include - + #ifdef _XBT_WIN32 -int -is_an_unhandled_exception(DWORD exit_code); - -typedef struct s_exception_entry -{ - DWORD value; - const char* signal; -}s_exception_entry_t,* exception_entry_t; - -static const s_exception_entry_t exceptions[] = -{ - {EXCEPTION_ACCESS_VIOLATION, "SIGSEGV"}, - {EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "SIGSEGV"}, - {EXCEPTION_BREAKPOINT, "SIGTRAP"}, - {EXCEPTION_DATATYPE_MISALIGNMENT, "SIGBUS"}, - {EXCEPTION_FLT_DENORMAL_OPERAND, "SIGFPE"}, - {EXCEPTION_FLT_DIVIDE_BY_ZERO, "SIGFPE"}, - {EXCEPTION_FLT_INEXACT_RESULT, "SIGFPE"}, - {EXCEPTION_FLT_INVALID_OPERATION, "SIGFPE"}, - {EXCEPTION_FLT_OVERFLOW, "SIGFPE"}, - {EXCEPTION_FLT_STACK_CHECK, "SIGFPE"}, - {EXCEPTION_FLT_UNDERFLOW, "SIGFPE"}, - {EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL"}, - {EXCEPTION_IN_PAGE_ERROR, "SIGSEGV"}, - {EXCEPTION_INT_DIVIDE_BY_ZERO, "SIGFPE"}, - {EXCEPTION_INT_OVERFLOW, "SIGFPE"}, - {EXCEPTION_STACK_OVERFLOW, "SIGILL"}, - {EXCEPTION_SINGLE_STEP, "SIGTRAP"}, - {EXCEPTION_NONCONTINUABLE_EXCEPTION, "SIGILL"}, - {EXCEPTION_PRIV_INSTRUCTION, "SIGILL"} -}; -/* number of the entries in the table of exceptions */ +int is_an_unhandled_exception(DWORD exit_code); + typedef struct s_exception_entry { + DWORD value; + const char *signal; + } s_exception_entry_t, *exception_entry_t; + static const s_exception_entry_t exceptions[] = + { +{EXCEPTION_ACCESS_VIOLATION, "SIGSEGV"}, +{EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "SIGSEGV"}, +{EXCEPTION_BREAKPOINT, "SIGTRAP"}, +{EXCEPTION_DATATYPE_MISALIGNMENT, "SIGBUS"}, +{EXCEPTION_FLT_DENORMAL_OPERAND, "SIGFPE"}, +{EXCEPTION_FLT_DIVIDE_BY_ZERO, "SIGFPE"}, +{EXCEPTION_FLT_INEXACT_RESULT, "SIGFPE"}, +{EXCEPTION_FLT_INVALID_OPERATION, "SIGFPE"}, +{EXCEPTION_FLT_OVERFLOW, "SIGFPE"}, +{EXCEPTION_FLT_STACK_CHECK, "SIGFPE"}, +{EXCEPTION_FLT_UNDERFLOW, "SIGFPE"}, +{EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL"}, +{EXCEPTION_IN_PAGE_ERROR, "SIGSEGV"}, +{EXCEPTION_INT_DIVIDE_BY_ZERO, "SIGFPE"}, +{EXCEPTION_INT_OVERFLOW, "SIGFPE"}, +{EXCEPTION_STACK_OVERFLOW, "SIGILL"}, +{EXCEPTION_SINGLE_STEP, "SIGTRAP"}, +{EXCEPTION_NONCONTINUABLE_EXCEPTION, "SIGILL"}, {EXCEPTION_PRIV_INSTRUCTION, "SIGILL"} +}; + + +/* number of the entries in the table of exceptions */ #define MAX_EXECPTION ((unsigned int)19) - -#endif - -typedef struct s_signal_entry { - const char* name; - int number; -} s_signal_entry_t,* signal_entry_t; - -static const s_signal_entry_t signals[] = { - {"SIGHUP" ,SIGHUP}, - {"SIGINT" ,SIGINT}, - {"SIGQUIT" ,SIGQUIT}, - {"SIGILL" ,SIGILL}, - {"SIGTRAP" ,SIGTRAP}, - {"SIGABRT" ,SIGABRT}, - {"SIGFPE" ,SIGFPE}, - {"SIGKILL" ,SIGKILL}, - {"SIGBUS" ,SIGBUS}, - {"SIGSEGV" ,SIGSEGV}, - {"SIGSYS" ,SIGSYS}, - {"SIGPIPE" ,SIGPIPE}, - {"SIGALRM" ,SIGALRM}, - {"SIGTERM" ,SIGTERM}, - {"SIGURG" ,SIGURG}, - {"SIGSTOP" ,SIGSTOP}, - {"SIGTSTP" ,SIGTSTP}, - {"SIGCONT" ,SIGCONT}, - {"SIGCHLD" ,SIGCHLD}, - {"SIGTTIN" ,SIGTTIN}, - {"SIGTTOU" ,SIGTTOU}, - {"SIGIO" ,SIGIO}, - {"SIGXCPU" ,SIGXCPU}, - {"SIGXFSZ" ,SIGXFSZ}, - {"SIGVTALRM",SIGVTALRM}, - {"SIGPROF" ,SIGPROF}, - {"SIGWINCH" ,SIGWINCH}, - {"SIGUSR1" ,SIGUSR1}, - {"SIGUSR2" ,SIGUSR2}, - {"SIG UNKNOWN" ,-1} -}; - + +#endif /* */ + typedef struct s_signal_entry { + const char *name; + int number; + } s_signal_entry_t, *signal_entry_t; + static const s_signal_entry_t signals[] = { + {"SIGHUP", SIGHUP}, + {"SIGINT", SIGINT}, + {"SIGQUIT", SIGQUIT}, + {"SIGILL", SIGILL}, + {"SIGTRAP", SIGTRAP}, + {"SIGABRT", SIGABRT}, + {"SIGFPE", SIGFPE}, + {"SIGKILL", SIGKILL}, + {"SIGBUS", SIGBUS}, + {"SIGSEGV", SIGSEGV}, + {"SIGSYS", SIGSYS}, + {"SIGPIPE", SIGPIPE}, + {"SIGALRM", SIGALRM}, + {"SIGTERM", SIGTERM}, + {"SIGURG", SIGURG}, + {"SIGSTOP", SIGSTOP}, + {"SIGTSTP", SIGTSTP}, + {"SIGCONT", SIGCONT}, + {"SIGCHLD", SIGCHLD}, + {"SIGTTIN", SIGTTIN}, + {"SIGTTOU", SIGTTOU}, + {"SIGIO", SIGIO}, + {"SIGXCPU", SIGXCPU}, + {"SIGXFSZ", SIGXFSZ}, + {"SIGVTALRM", SIGVTALRM}, + {"SIGPROF", SIGPROF}, + {"SIGWINCH", SIGWINCH}, + {"SIGUSR1", SIGUSR1}, {"SIGUSR2", SIGUSR2}, {"SIG UNKNOWN", -1} +}; + + #ifdef _XBT_WIN32 -const char* signal_name(DWORD got, const char* expected) -#else -const char* signal_name(unsigned int got, char *expected) -#endif -{ - int i; - - #ifdef _XBT_WIN32 - - for (i=0; i < MAX_EXECPTION; i++) - if (exceptions[i].value == got) - return (exceptions[i].signal); - #else - if((got == SIGBUS) && !strcmp("SIGSEGV",expected)) - got = SIGSEGV; - - for (i=0; signals[i].number != -1; i++) - if (signals[i].number == got) - return (signals[i].name); - - #endif - return bprintf("SIG UNKNOWN (%d)", got); -} - -int -sig_exists(const char* sig_name) -{ - int i; - - for (i=0; signals[i].number != -1; i++) - if (!strcmp(signals[i].name, sig_name)) - return 1; - - /* not found */ - return 0; -} - - +const char *signal_name(DWORD got, const char *expected) +#else /* */ +const char *signal_name(unsigned int got, char *expected) +#endif /* */ +{ + int i; + #ifdef _XBT_WIN32 -int -is_an_unhandled_exception(DWORD exit_code) -{ - unsigned int i; - - for(i = 0; i < MAX_EXECPTION; i++) - if(exceptions[i].value == exit_code) - return 1; - - return 0; -} -#endif + for (i = 0; i < MAX_EXECPTION; i++) + if (exceptions[i].value == got) + return (exceptions[i].signal); + +#else /* */ + if ((got == SIGBUS) && !strcmp("SIGSEGV", expected)) + got = SIGSEGV; + for (i = 0; signals[i].number != -1; i++) + if (signals[i].number == got) + return (signals[i].name); + +#endif /* */ + return bprintf("SIG UNKNOWN (%d)", got); + } + + int sig_exists(const char *sig_name) +{ + int i; + for (i = 0; signals[i].number != -1; i++) + if (!strcmp(signals[i].name, sig_name)) + return 1; + + /* not found */ + return 0; + } + + +#ifdef _XBT_WIN32 +int is_an_unhandled_exception(DWORD exit_code) +{ + unsigned int i; + for (i = 0; i < MAX_EXECPTION; i++) + if (exceptions[i].value == exit_code) + return 1; + return 0; + } + + +#endif /* */ diff --git a/tools/tesh2/w32/include/dirent.h b/tools/tesh2/w32/include/dirent.h index 2838021e30..a20f2b534c 100644 --- a/tools/tesh2/w32/include/dirent.h +++ b/tools/tesh2/w32/include/dirent.h @@ -3,49 +3,33 @@ #include #include - - + #ifndef S_ISDIR #define S_ISDIR(__mode) (((__mode) & S_IFMT) == S_IFDIR) -#endif - +#endif /* */ + #ifdef __cplusplus -extern "C" { -#endif - -struct dirent -{ - char d_name[MAX_PATH + 1]; -}; - -typedef struct s_DIR -{ - HANDLE file_handle; - DWORD pos; - char directory_name[MAX_PATH+1]; - struct dirent entry; -}DIR,* DIR_t; - -DIR* -opendir(const char* directory_name); - -struct dirent* -readdir(DIR* dir); - -void -rewinddir(DIR* dir); - -int -closedir(DIR* dir); - -off_t -telldir(DIR* dir); - -void -seekdir(DIR* dir, off_t offset); - +extern "C" { + +#endif /* */ + struct dirent { + char d_name[MAX_PATH + 1]; + }; + typedef struct s_DIR { + HANDLE file_handle; + DWORD pos; + char directory_name[MAX_PATH + 1]; + struct dirent entry; + } DIR, *DIR_t; + DIR * opendir(const char *directory_name); + struct dirent * readdir(DIR * dir); + void rewinddir(DIR * dir); + int closedir(DIR * dir); + off_t telldir(DIR * dir); + void seekdir(DIR * dir, off_t offset); + #ifdef __cplusplus -extern } -#endif +extern} +#endif /* */ -#endif /* !__DIRENT_H */ +#endif /* !__DIRENT_H */ diff --git a/tools/tesh2/w32/include/getopt.h b/tools/tesh2/w32/include/getopt.h index 451dc424d1..71013cd9fb 100644 --- a/tools/tesh2/w32/include/getopt.h +++ b/tools/tesh2/w32/include/getopt.h @@ -4,51 +4,34 @@ #define no_argument 0 #define required_argument 1 #define optional_argument 2 - -struct option -{ - const char *name; /* name of the long option */ - - int has_arg; /* - * has_arg is : no_argument (or 0), if the option doesn't take an argument, - * required_argument (or 1) if the option takes an argument, - * optional_argument (or 2) if the option takes an optional argument. - */ - - int *flag; /* specify the mean used to return a result for a long option: - * if flag is NULL, then getopt_long() returns val - * in the other case getopt_long() returns 0, and flag points to the - * variable specified bay the content of the field val when the option - * is found but it is not update if the option is not found. - */ - - int val; /* val is the value returned by getopt_long() when the pointer flag - * is NULL or the value of the variable referenced by the pointer flag - * when the option is found. - */ -}; - -extern int -optind; - -extern char* -optarg; - -extern int -opterr; - -extern int -optopt; - - -int -getopt (int argc, char * const argv[], const char *optstring); - -int -getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex); - -int -getopt_long_only (int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex); - - -#endif /* !__GETOPT_H */ + struct option { + const char *name; /* name of the long option */ + int has_arg; /* + * has_arg is : no_argument (or 0), if the option doesn't take an argument, + * required_argument (or 1) if the option takes an argument, + * optional_argument (or 2) if the option takes an optional argument. + */ + int *flag; /* specify the mean used to return a result for a long option: + * if flag is NULL, then getopt_long() returns val + * in the other case getopt_long() returns 0, and flag points to the + * variable specified bay the content of the field val when the option + * is found but it is not update if the option is not found. + */ + int val; /* val is the value returned by getopt_long() when the pointer flag + * is NULL or the value of the variable referenced by the pointer flag + * when the option is found. + */ + }; + extern int optind; + extern char * optarg; + extern int opterr; + extern int optopt; + int getopt(int argc, char *const argv[], const char *optstring); + int +getopt_long(int argc, char *const argv[], const char *optstring, + const struct option *longopts, int *longindex); + int getopt_long_only(int argc, char *const argv[], + const char *optstring, + const struct option *longopts, int *longindex); + +#endif /* !__GETOPT_H */ diff --git a/tools/tesh2/w32/src/Cat.c b/tools/tesh2/w32/src/Cat.c index 06f24c76a2..6516affab8 100644 --- a/tools/tesh2/w32/src/Cat.c +++ b/tools/tesh2/w32/src/Cat.c @@ -2,7 +2,7 @@ /* must be defined before */ #ifdef _MSC_VER -#define _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_DEPRECATE #endif #include @@ -16,7 +16,7 @@ #include #ifdef _MSC_VER -#define _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_DEPRECATE #define strdup _strdup #define fileno _fileno #define creat _creat @@ -26,12 +26,12 @@ #endif #ifdef max - #undef max - #define max(h,i) ((h) > (i) ? (h) : (i)) +#undef max +#define max(h,i) ((h) > (i) ? (h) : (i)) #endif - + #ifndef S_ISREG - #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) +#define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG) #endif #ifndef STDIN_FILENO @@ -43,267 +43,228 @@ #endif -static +static int exit_code = EXIT_SUCCESS; -static char* -rfname; +static char *rfname; -static char* -wfname = NULL; +static char *wfname = NULL; static int wfd; #ifndef _MSC_VER -static size_t +static size_t #else static int #endif -bsize; + bsize; -static char * -buf = NULL; +static char *buf = NULL; -static int -fnumber = 0; +static int + fnumber = 0; -int -cat_files(char** fnames); +int cat_files(char **fnames); -int -cat(int); +int cat(int); -char** -fnames = NULL; +char **fnames = NULL; -void -exit0(int errcode) +void exit0(int errcode) { - if(fnames) - { - int i; - - for(i = 0; i < fnumber; i++) - free(fnames[i]); - - free(fnames); - } - - if(buf) - free(buf); - - if(wfname) - free(wfname); - - - exit(errcode); + if (fnames) { + int i; + + for (i = 0; i < fnumber; i++) + free(fnames[i]); + + free(fnames); + } + + if (buf) + free(buf); + + if (wfname) + free(wfname); + + + exit(errcode); } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - int i, j; - int success = 1; - int redirect = 0; - int exists = 0; - - struct stat stat_buf = {0}; - - setlocale(LC_ALL, ""); - - bsize = BUFSIZ; - - if(!(buf = (char*)malloc(bsize))) - { - fprintf(stderr, "[ERROR/cat] not enough memory\n"); - exit0(EXIT_FAILURE); - } - - if(argc > 1) - { - if(!(fnames = (char**)calloc(argc, sizeof(char*)))) - { - fprintf(stderr, "[ERROR/cat] not enough memory\n"); - exit0(EXIT_FAILURE); - } - - for(i = 1, j= 0; i < argc; i++) - { - if(!strcmp(argv[i], ">")) - { - redirect = 1; - break; - } - else if(!strcmp(argv[i], ">>")) - { - redirect = 1; - exists = 1; - break; - } - else - { - if(stat(argv[i], &stat_buf)) - { - fprintf(stderr, "[ERROR/cat (1)] could not get information about %s\n",argv[i]); - success = 0; - break; - } - else - { - if(S_ISREG(stat_buf.st_mode)) - { - fnames[j++] = strdup(argv[i]); - fnumber++; - } - else - { - fprintf(stderr, "[ERROR/cat] %s is not a file\n",argv[i]); - success = 0; - break; - } - } - } - } - - if(!success) - exit0(EXIT_FAILURE); - } - - if(redirect) - { - if(i != argc - 2) - { - if(exists) - fprintf(stderr, "[ERROR/cat] syntax error near `>>' (i : %d - argc : %d\n", i , argc); - else - fprintf(stderr, "[ERROR/cat] syntax error near `>' (i : %d - argc : %d\n", i , argc); - - exit0(EXIT_FAILURE); - } - else - { - wfname = strdup(argv[i + 1]); - - if(!exists) - { - if((wfd = creat(wfname, _S_IREAD | _S_IWRITE)) < 0) - { - fprintf(stderr, "[ERROR/cat] could not create %s file\n",wfname); - - exit0(EXIT_FAILURE); - } - } - else - { - if((wfd = open(wfname, O_WRONLY | O_APPEND, 0)) < 0) - { - fprintf(stderr, "[ERROR/cat] could not open %s file\n",wfname); - - exit0(EXIT_FAILURE); - } - } - } - } - else - { - wfd = STDOUT_FILENO; - - if(fstat(wfd, &stat_buf)) - { - fprintf(stderr, "[ERROR/cat (3)] could not get information about stdout\n"); - exit0(EXIT_FAILURE); - } - } - - exit_code = cat_files(fnames); - - if(wfd == STDOUT_FILENO) - { - if(fclose(stdout)) - { - fprintf(stderr, "[ERROR/cat] could not close stdout\n"); - exit_code = EXIT_FAILURE; - } - } - else - { - if(close(wfd)) - { - fprintf(stderr, "[ERROR/cat] could not close %s\n", wfname); - exit_code = EXIT_FAILURE; - } - } - - exit0(exit_code); + int i, j; + int success = 1; + int redirect = 0; + int exists = 0; + + struct stat stat_buf = { 0 }; + + setlocale(LC_ALL, ""); + + bsize = BUFSIZ; + + if (!(buf = (char *) malloc(bsize))) { + fprintf(stderr, "[ERROR/cat] not enough memory\n"); + exit0(EXIT_FAILURE); + } + + if (argc > 1) { + if (!(fnames = (char **) calloc(argc, sizeof(char *)))) { + fprintf(stderr, "[ERROR/cat] not enough memory\n"); + exit0(EXIT_FAILURE); + } + + for (i = 1, j = 0; i < argc; i++) { + if (!strcmp(argv[i], ">")) { + redirect = 1; + break; + } else if (!strcmp(argv[i], ">>")) { + redirect = 1; + exists = 1; + break; + } else { + if (stat(argv[i], &stat_buf)) { + fprintf(stderr, + "[ERROR/cat (1)] could not get information about %s\n", + argv[i]); + success = 0; + break; + } else { + if (S_ISREG(stat_buf.st_mode)) { + fnames[j++] = strdup(argv[i]); + fnumber++; + } else { + fprintf(stderr, "[ERROR/cat] %s is not a file\n", argv[i]); + success = 0; + break; + } + } + } + } + + if (!success) + exit0(EXIT_FAILURE); + } + + if (redirect) { + if (i != argc - 2) { + if (exists) + fprintf(stderr, + "[ERROR/cat] syntax error near `>>' (i : %d - argc : %d\n", + i, argc); + else + fprintf(stderr, + "[ERROR/cat] syntax error near `>' (i : %d - argc : %d\n", + i, argc); + + exit0(EXIT_FAILURE); + } else { + wfname = strdup(argv[i + 1]); + + if (!exists) { + if ((wfd = creat(wfname, _S_IREAD | _S_IWRITE)) < 0) { + fprintf(stderr, "[ERROR/cat] could not create %s file\n", + wfname); + + exit0(EXIT_FAILURE); + } + } else { + if ((wfd = open(wfname, O_WRONLY | O_APPEND, 0)) < 0) { + fprintf(stderr, "[ERROR/cat] could not open %s file\n", wfname); + + exit0(EXIT_FAILURE); + } + } + } + } else { + wfd = STDOUT_FILENO; + + if (fstat(wfd, &stat_buf)) { + fprintf(stderr, + "[ERROR/cat (3)] could not get information about stdout\n"); + exit0(EXIT_FAILURE); + } + } + + exit_code = cat_files(fnames); + + if (wfd == STDOUT_FILENO) { + if (fclose(stdout)) { + fprintf(stderr, "[ERROR/cat] could not close stdout\n"); + exit_code = EXIT_FAILURE; + } + } else { + if (close(wfd)) { + fprintf(stderr, "[ERROR/cat] could not close %s\n", wfname); + exit_code = EXIT_FAILURE; + } + } + + exit0(exit_code); } -int -cat_files(char **fnames) +int cat_files(char **fnames) { - int rfd, i; - int failure = 0; - - rfd = STDIN_FILENO; - - rfname = "stdin"; - - if(fnumber) - { - - for(i = 0; i < fnumber && !failure; i++) - { - if (!strcmp(fnames[i], "-")) - rfd = fileno(stdin); - else if ((rfd = open(fnames[i], O_RDONLY, 0)) < 0) - { - fprintf(stderr, "[WARN/cat] could not open %s file", fnames[i]); - exit_code = EXIT_FAILURE; - continue; - } - - rfname = fnames[i]; - - failure = cat(rfd); - - close(rfd); - - } - } - else - failure = cat(rfd); - - return failure ? 1 : 0; + int rfd, i; + int failure = 0; + + rfd = STDIN_FILENO; + + rfname = "stdin"; + + if (fnumber) { + + for (i = 0; i < fnumber && !failure; i++) { + if (!strcmp(fnames[i], "-")) + rfd = fileno(stdin); + else if ((rfd = open(fnames[i], O_RDONLY, 0)) < 0) { + fprintf(stderr, "[WARN/cat] could not open %s file", fnames[i]); + exit_code = EXIT_FAILURE; + continue; + } + + rfname = fnames[i]; + + failure = cat(rfd); + + close(rfd); + + } + } else + failure = cat(rfd); + + return failure ? 1 : 0; } -int -cat(int rfd) +int cat(int rfd) { - #ifndef _MSC_VER - size_t bytes_readed_nb; - #else - int bytes_readed_nb; - #endif - int bytes_written_nb, pos; - - while ((bytes_readed_nb = read(rfd, buf, bsize)) != -1 && bytes_readed_nb != 0) - { - for (pos = 0; bytes_readed_nb; bytes_readed_nb -= bytes_written_nb, pos += bytes_written_nb) - { - if ((bytes_written_nb = write(wfd, buf + pos, bytes_readed_nb)) == 0 || bytes_written_nb == -1) - { - fprintf(stderr, "[ERROR/cat] could not write to %s\n", wfd == fileno(stdout) ? "stdout" : wfname); - return 1; - } - } - } - - if(bytes_readed_nb < 0) - { - fprintf(stderr, "[WARN/cat] could not read %s file", rfname); - return 1; - } - - return 0; +#ifndef _MSC_VER + size_t bytes_readed_nb; +#else + int bytes_readed_nb; +#endif + int bytes_written_nb, pos; + + while ((bytes_readed_nb = read(rfd, buf, bsize)) != -1 + && bytes_readed_nb != 0) { + for (pos = 0; bytes_readed_nb; + bytes_readed_nb -= bytes_written_nb, pos += bytes_written_nb) { + if ((bytes_written_nb = write(wfd, buf + pos, bytes_readed_nb)) == 0 + || bytes_written_nb == -1) { + fprintf(stderr, "[ERROR/cat] could not write to %s\n", + wfd == fileno(stdout) ? "stdout" : wfname); + return 1; + } + } + } + + if (bytes_readed_nb < 0) { + fprintf(stderr, "[WARN/cat] could not read %s file", rfname); + return 1; + } + + return 0; } diff --git a/tools/tesh2/w32/src/dirent.c b/tools/tesh2/w32/src/dirent.c index b80b33656b..317dbbae41 100644 --- a/tools/tesh2/w32/src/dirent.c +++ b/tools/tesh2/w32/src/dirent.c @@ -3,148 +3,122 @@ #include #include #include + DIR * opendir(const char *directory_name) +{ + struct stat sb; + DIR * dir; + if (NULL == directory_name) + { + errno = EINVAL; + return NULL; + } + if (0 != stat(directory_name, &sb)) + { + + /* directory not found */ + errno = ENOENT; + return NULL; + } + if (0 == S_ISDIR(sb.st_mode)) + { + + /* it's not a directory */ + errno = ENOTDIR; + return NULL; + } + dir = (DIR *) calloc(1, sizeof(DIR)); + if (NULL == dir) + { + errno = ENOMEM; + return NULL; + } + if ('\\' != dir->directory_name[strlen(directory_name) - 1]) + sprintf(dir->directory_name, "%s\\*", directory_name); + + else + sprintf(dir->directory_name, "%s*", directory_name); + dir->file_handle = INVALID_HANDLE_VALUE; + return dir; + } + + int closedir(DIR * dir) +{ + if (NULL == dir) + return EINVAL; + if (INVALID_HANDLE_VALUE != dir->file_handle) + FindClose(dir->file_handle); + + else + return EBADF; + free(dir); + return 0; + } + + struct dirent * readdir(DIR * dir) +{ + WIN32_FIND_DATA wfd = { + 0}; + if (!dir) + { + errno = EINVAL; + return NULL; + } + if (!dir->pos) + dir->file_handle = FindFirstFile(dir->directory_name, &wfd); + if (!FindNextFile(dir->file_handle, &wfd)) + return NULL; + dir->pos++; + strcpy(dir->entry.d_name, wfd.cFileName); + return &(dir->entry); + } + + void rewinddir(DIR * dir) +{ + if (NULL == dir) + { + errno = EINVAL; + return; + } + if (INVALID_HANDLE_VALUE != dir->file_handle) + { + FindClose(dir->file_handle); + dir->file_handle = INVALID_HANDLE_VALUE; + dir->pos = 0; + } + } + + off_t telldir(DIR * dir) +{ + if (NULL == dir) + { + errno = EINVAL; + return -1; + } + return dir->pos; + } + + void seekdir(DIR * dir, off_t offset) +{ + WIN32_FIND_DATA wfd = { + 0}; + if (NULL == dir) + { + errno = EINVAL; + return; + } + if (INVALID_HANDLE_VALUE != dir->file_handle) + { + FindClose(dir->file_handle); + dir->file_handle = INVALID_HANDLE_VALUE; + dir->pos = 0; + } + dir->file_handle = FindFirstFile(dir->directory_name, &wfd); + dir->pos += offset; + while (--offset) + { + if (!FindNextFile(dir->file_handle, &wfd)) + errno = EINVAL; + } + } + - -DIR* -opendir(const char* directory_name) -{ - struct stat sb; - DIR* dir; - - if(NULL == directory_name) - { - errno = EINVAL; - return NULL; - } - - if(0 != stat(directory_name, &sb)) - { - /* directory not found */ - errno = ENOENT; - return NULL; - } - - if(0 == S_ISDIR(sb.st_mode)) - { - /* it's not a directory */ - errno = ENOTDIR; - return NULL; - } - - - dir = (DIR *)calloc(1,sizeof(DIR)); - - if (NULL == dir) - { - errno = ENOMEM; - return NULL; - } - - if('\\' != dir->directory_name[strlen(directory_name) - 1]) - sprintf(dir->directory_name,"%s\\*",directory_name); - else - sprintf(dir->directory_name,"%s*",directory_name); - - dir->file_handle = INVALID_HANDLE_VALUE; - - return dir; -} - -int -closedir(DIR* dir) -{ - if(NULL == dir) - return EINVAL; - - if(INVALID_HANDLE_VALUE != dir->file_handle) - FindClose(dir->file_handle); - else - return EBADF; - - free(dir); - - return 0; - -} - -struct dirent* -readdir(DIR* dir) -{ - WIN32_FIND_DATA wfd = {0}; - - if(!dir) - { - errno = EINVAL; - return NULL; - } - - if(!dir->pos) - dir->file_handle = FindFirstFile(dir->directory_name, &wfd); - - if(!FindNextFile(dir->file_handle, &wfd)) - return NULL; - - dir->pos++; - - strcpy(dir->entry.d_name, wfd.cFileName); - - return &(dir->entry); -} - -void -rewinddir(DIR* dir) -{ - if(NULL == dir) - { - errno = EINVAL; - return; - } - - if(INVALID_HANDLE_VALUE != dir->file_handle) - { - FindClose(dir->file_handle); - dir->file_handle = INVALID_HANDLE_VALUE; - dir->pos = 0; - } -} - -off_t -telldir(DIR* dir) -{ - if(NULL == dir) - { - errno = EINVAL; - return -1; - } - - return dir->pos; -} - -void -seekdir(DIR* dir, off_t offset) -{ - WIN32_FIND_DATA wfd = {0}; - - if(NULL == dir) - { - errno = EINVAL; - return; - } - - if(INVALID_HANDLE_VALUE != dir->file_handle) - { - FindClose(dir->file_handle); - dir->file_handle = INVALID_HANDLE_VALUE; - dir->pos = 0; - } - - dir->file_handle = FindFirstFile(dir->directory_name, &wfd); - - dir->pos += offset; - - while(--offset) - { - if(!FindNextFile(dir->file_handle, &wfd)) - errno = EINVAL; - } -} diff --git a/tools/tesh2/w32/src/getopt.c b/tools/tesh2/w32/src/getopt.c index 45251446d4..0a1c4a5bdb 100644 --- a/tools/tesh2/w32/src/getopt.c +++ b/tools/tesh2/w32/src/getopt.c @@ -2,453 +2,445 @@ #include #include - -char* -optarg = NULL; - -int -optind = 0; - -int -optopt = '?'; - -int -opterr = 1; - -static char* -nextchar; - -static -int first_nonopt; - -static int -last_nonopt; - - -static enum -{ - REQUIRE_ORDER, - PERMUTE, - RETURN_IN_ORDER -}ordering; - - -static const char * -__getopt_initialize (const char *optstring); - -static int -__getopt_internal (int argc, char *const *argv, const char* optstring, const struct option *longopts, int* longind, int long_only); - -static void -__exchange (char **argv); - -int -getopt (int argc, char * const argv[], const char *optstring) -{ - return __getopt_internal(argc, argv, optstring,(const struct option *) 0,(int *) 0,0); -} - -static const char * -__getopt_initialize (const char *optstring) -{ - /* Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ - - first_nonopt = last_nonopt = optind = 1; - nextchar = NULL; - - /* Determine how to handle the ordering of options and nonoptions. */ - - if (optstring[0] == '-') - { - ordering = RETURN_IN_ORDER; - ++optstring; - } - /* si la chaîne d'options commence par un + alors la fonction getopt() s'arrête - * dès qu'un argument de la ligne de commande n'est pas une option - */ - else if (optstring[0] == '+') - { - ordering = REQUIRE_ORDER; - ++optstring; - } - else - { - ordering = PERMUTE; - } - - return optstring; -} - -int -__getopt_internal (int argc, char *const *argv, const char* optstring, const struct option *longopts, int* longind, int long_only) -{ - optarg = NULL; - - if (optind == 0) - optstring = __getopt_initialize (optstring); - - if (nextchar == NULL || *nextchar == '\0') - { - /* Advance to the next ARGV-element. */ - - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - __exchange them so that the options come first. */ - - if (first_nonopt != last_nonopt && last_nonopt != optind) - __exchange ((char **) argv); - else if (last_nonopt != optind) - first_nonopt = optind; - - /* Skip any additional non-options - and extend the range of non-options previously skipped. */ - - while (optind < argc && (argv[optind][0] != '-' || argv[optind][1] == '\0')) - optind++; - - last_nonopt = optind; - } - - /* The special ARGV-element `--' means premature end of options. - Skip it like a null option, - then __exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ - - if (optind != argc && !strcmp (argv[optind], "--")) - { - optind++; - - if (first_nonopt != last_nonopt && last_nonopt != optind) - __exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = optind; - - last_nonopt = argc; - - optind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - optind = first_nonopt; - - return EOF; - } - - /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ - - if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) - { - if (ordering == REQUIRE_ORDER) - return EOF; - optarg = argv[optind++]; - return 1; - } - - /* We have found another option-ARGV-element. - Skip the initial punctuation. */ - - nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-')); - } - - /* Decode the current option-ARGV-element. */ - - /* Check whether the ARGV-element is a long option. - - If long_only and the ARGV-element has the form "-f", where f is - a valid short option, don't consider it an abbreviated form of - a long option that starts with f. Otherwise there would be no - way to give the -f short option. - - On the other hand, if there's a long option "fubar" and - the ARGV-element is "-fu", do consider that an abbreviation of - the long option, just like "--fu", and not "-f" with arg "u". - - This distinction seems to be the most useful approach. */ - - if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2] || !strchr (optstring, argv[optind][1]))))) - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = 0; - int option_index; - - for (nameend = nextchar; *nameend !='\0' && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - { - if(!strncmp (p->name, nextchar, nameend - nextchar)) - { - - if (nameend - nextchar == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - exact = 0; - /* begin change - pfound = p; - indfound = option_index; - end change */ - break; - } - else - { - - /* Second or later nonexact match found. */ - ambig = 1; - } - } - } - - if (ambig && !exact) - { - if (opterr) - fprintf (stderr, "error : %s: option `%s' is ambiguous\n",argv[0], argv[optind]); - - nextchar += strlen (nextchar); - optind++; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - optind++; - - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { - if (opterr) - { - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr,"error : %s: option `--%s' doesn't allow an argument\n",argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr,"error : %s: option `%c%s' doesn't allow an argument\n",argv[0], argv[optind - 1][0], pfound->name); - } - - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (opterr) - fprintf (stderr, "error : %s: option `%s' requires an argument\n",argv[0], argv[optind - 1]); - - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - - nextchar += strlen (nextchar); - - if (longind != NULL) - *longind = option_index; - - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - - return pfound->val; - } - - /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[optind][1] == '-'|| strchr (optstring, *nextchar) == NULL) - { - if (opterr) - { - if (argv[optind][1] == '-') - /* --option */ - fprintf (stderr, "error : %s: unrecognized option `--%s'\n",argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, "error : %s: unrecognized option `%c%s'\n",argv[0], argv[optind][0], nextchar); - } - - nextchar = (char *) ""; - optind++; - return '?'; - } - } - - /* Look at and handle the next short option-character. */ - - { - char c = *nextchar++; - char *temp = strchr (optstring, c); - - /* Increment `optind' when we start to process its last character. */ - if (*nextchar == '\0') - ++optind; - - if (temp == NULL || c == ':') - { - if (opterr) - fprintf (stderr, "error : %s: invalid option -- %c\n", argv[0], c); - - optopt = c; - return '?'; - } - - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - optarg = nextchar; - optind++; - } - else - optarg = NULL; - - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, "error : %s: option requires an argument -- %c\n",argv[0], c); - } - optopt = c; - - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - - nextchar = NULL; - } - } - return c; - - } -} - - -static void -__exchange (char **argv) -{ - int bottom = first_nonopt; - int middle = last_nonopt; - int top = optind; - char *tem; - - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ - - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - first_nonopt += (optind - last_nonopt); - last_nonopt = optind; -} - -int -getopt_long (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index) -{ - return __getopt_internal (argc, argv, options, long_options, opt_index, 0); -} - - -int -getopt_long_only(int argc, char *const *argv, const char *options, const struct option *long_options,int *opt_index) -{ - return __getopt_internal (argc, argv, options, long_options, opt_index, 1); -} - - + char * optarg = NULL; + int optind = 0; + int optopt = '?'; + int opterr = 1; + static char * nextchar; + static int first_nonopt; + static int last_nonopt; + static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER +} ordering; + static const char * __getopt_initialize(const char *optstring); + static int +__getopt_internal(int argc, char *const *argv, const char *optstring, + const struct option *longopts, int *longind, + int long_only); + static void __exchange(char **argv); + int getopt(int argc, char *const argv[], const char *optstring) +{ + return __getopt_internal(argc, argv, optstring, + (const struct option *) 0, (int *) 0, 0); + } static const char * __getopt_initialize(const char *optstring) +{ + + /* Start processing options with ARGV-element 1 (since ARGV-element 0 + is the program name); the sequence of previously skipped + non-option ARGV-elements is empty. */ + first_nonopt = last_nonopt = optind = 1; + nextchar = NULL; + + /* Determine how to handle the ordering of options and nonoptions. */ + if (optstring[0] == '-') + { + ordering = RETURN_IN_ORDER; + ++optstring; + } + + /* si la chaîne d'options commence par un + alors la fonction getopt() s'arrête + * dès qu'un argument de la ligne de commande n'est pas une option + */ + else if (optstring[0] == '+') + { + ordering = REQUIRE_ORDER; + ++optstring; + } + + else + { + ordering = PERMUTE; + } + return optstring; + } + + int +__getopt_internal(int argc, char *const *argv, const char *optstring, + const struct option *longopts, int *longind, + int long_only) +{ + optarg = NULL; + if (optind == 0) + optstring = __getopt_initialize(optstring); + if (nextchar == NULL || *nextchar == '\0') + { + + /* Advance to the next ARGV-element. */ + if (ordering == PERMUTE) + { + + /* If we have just processed some options following some non-options, + __exchange them so that the options come first. */ + if (first_nonopt != last_nonopt && last_nonopt != optind) + __exchange((char **) argv); + + else if (last_nonopt != optind) + first_nonopt = optind; + + /* Skip any additional non-options + and extend the range of non-options previously skipped. */ + while (optind < argc + && (argv[optind][0] != '-' || argv[optind][1] == '\0')) + optind++; + last_nonopt = optind; + } + + /* The special ARGV-element `--' means premature end of options. + Skip it like a null option, + then __exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ + if (optind != argc && !strcmp(argv[optind], "--")) + { + optind++; + if (first_nonopt != last_nonopt && last_nonopt != optind) + __exchange((char **) argv); + + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; + optind = argc; + } + + /* If we have done all the ARGV-elements, stop the scan + and back over any non-options that we skipped and permuted. */ + if (optind == argc) + { + + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return EOF; + } + + /* If we have come to a non-option and did not permute it, + either stop the scan or describe it to the caller and pass it by. */ + if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) + { + if (ordering == REQUIRE_ORDER) + return EOF; + optarg = argv[optind++]; + return 1; + } + + /* We have found another option-ARGV-element. + Skip the initial punctuation. */ + nextchar = + (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-')); + } + + /* Decode the current option-ARGV-element. */ + + /* Check whether the ARGV-element is a long option. + + If long_only and the ARGV-element has the form "-f", where f is + a valid short option, don't consider it an abbreviated form of + a long option that starts with f. Otherwise there would be no + way to give the -f short option. + + On the other hand, if there's a long option "fubar" and + the ARGV-element is "-fu", do consider that an abbreviation of + the long option, just like "--fu", and not "-f" with arg "u". + + This distinction seems to be the most useful approach. */ + if (longopts != NULL + && (argv[optind][1] == '-' + || (long_only + && (argv[optind][2] + || !strchr(optstring, argv[optind][1]))))) + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = 0; + int option_index; + for (nameend = nextchar; *nameend != '\0' && *nameend != '='; + nameend++) + + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + { + if (!strncmp(p->name, nextchar, nameend - nextchar)) + { + if (nameend - nextchar == strlen(p->name)) + { + + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + + else if (pfound == NULL) + { + + /* First nonexact match found. */ + exact = 0; + + /* begin change + pfound = p; + indfound = option_index; + end change */ + break; + } + + else + { + + /* Second or later nonexact match found. */ + ambig = 1; + } + } + } + if (ambig && !exact) + { + if (opterr) + fprintf(stderr, "error : %s: option `%s' is ambiguous\n", + argv[0], argv[optind]); + nextchar += strlen(nextchar); + optind++; + return '?'; + } + if (pfound != NULL) + { + option_index = indfound; + optind++; + if (*nameend) + { + + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + + else + { + if (opterr) + { + if (argv[optind - 1][1] == '-') + + /* --option */ + fprintf(stderr, + "error : %s: option `--%s' doesn't allow an argument\n", + argv[0], pfound->name); + + else + + /* +option or -option */ + fprintf(stderr, + "error : %s: option `%c%s' doesn't allow an argument\n", + argv[0], argv[optind - 1][0], pfound->name); + } + nextchar += strlen(nextchar); + return '?'; + } + } + + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + + else + { + if (opterr) + fprintf(stderr, + "error : %s: option `%s' requires an argument\n", + argv[0], argv[optind - 1]); + nextchar += strlen(nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen(nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + + /* Can't find it as a long option. If this is not getopt_long_only, + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[optind][1] == '-' + || strchr(optstring, *nextchar) == NULL) + { + if (opterr) + { + if (argv[optind][1] == '-') + + /* --option */ + fprintf(stderr, "error : %s: unrecognized option `--%s'\n", + argv[0], nextchar); + + else + + /* +option or -option */ + fprintf(stderr, "error : %s: unrecognized option `%c%s'\n", + argv[0], argv[optind][0], nextchar); + } + nextchar = (char *) ""; + optind++; + return '?'; + } + } + + /* Look at and handle the next short option-character. */ + { + char c = *nextchar++; + char *temp = strchr(optstring, c); + + /* Increment `optind' when we start to process its last character. */ + if (*nextchar == '\0') + ++optind; + if (temp == NULL || c == ':') + { + if (opterr) + fprintf(stderr, "error : %s: invalid option -- %c\n", argv[0], + c); + optopt = c; + return '?'; + } + if (temp[1] == ':') + { + if (temp[2] == ':') + { + + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + + else + optarg = NULL; + nextchar = NULL; + } + + else + { + + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + + else if (optind == argc) + { + if (opterr) + { + + /* 1003.2 specifies the format of this message. */ + fprintf(stderr, + "error : %s: option requires an argument -- %c\n", + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + + else + c = '?'; + } + + else + + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } + } + return c; + } + } + + static void __exchange(char **argv) +{ + int bottom = first_nonopt; + int middle = last_nonopt; + int top = optind; + char *tem; + + /* Exchange the shorter segment with the far end of the longer segment. + That puts the shorter segment into the right place. + It leaves the longer segment in the right place overall, + but it consists of two parts that need to be swapped next. */ + while (top > middle && middle > bottom) + { + if (top - middle > middle - bottom) + { + + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + } + + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } + + else + { + + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + } + + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } + } + + /* Update records for the slots the non-options now occupy. */ + first_nonopt += (optind - last_nonopt); + last_nonopt = optind; + } + + int +getopt_long(int argc, char *const *argv, const char *options, + const struct option *long_options, int *opt_index) +{ + return __getopt_internal(argc, argv, options, long_options, opt_index, + 0); + } + + int +getopt_long_only(int argc, char *const *argv, const char *options, + const struct option *long_options, int *opt_index) +{ + return __getopt_internal(argc, argv, options, long_options, opt_index, + 1); + } + + diff --git a/win32_test_app/include/TBuffer.h b/win32_test_app/include/TBuffer.h index a7262c45be..c5166e3479 100644 --- a/win32_test_app/include/TBuffer.h +++ b/win32_test_app/include/TBuffer.h @@ -6,12 +6,11 @@ #include /* struct s_Buffer declaration. */ -typedef struct s_Buffer -{ - char* data; /* the buffer data. */ - size_t size; /* the buffer size (in bytes). */ - size_t capacity; /* the buffer capacity (in bytes). */ -}s_Buffer_t,* Buffer_t; +typedef struct s_Buffer { + char *data; /* the buffer data. */ + size_t size; /* the buffer size (in bytes). */ + size_t capacity; /* the buffer capacity (in bytes). */ +} s_Buffer_t, *Buffer_t; /* Asserts that a s_Buffer is valid. */ #define ASSERT_VALID_Buffer(p) ( ASSERT_NOT_NULL((p)) /*&& ASSERT_NOT_NULL((p)->data)*/ ) @@ -30,14 +29,14 @@ Buffer_t Buffer_new(void); /* Clears the buffer (this function don't destroy it, * see Buffer_free function). - */ + */ void Buffer_clear(Buffer_t buffer); /* Appends a string in the buffer. If successful, * the function returns true. Otherwise the function * returns false. */ -bool Buffer_append(Buffer_t buffer,char* str); +bool Buffer_append(Buffer_t buffer, char *str); /* * Removes all the linefeed from the buffer. @@ -58,4 +57,4 @@ bool Buffer_empty(Buffer_t buffer); -#endif /* #ifndef __BUFFER_H__ */ \ No newline at end of file +#endif /* #ifndef __BUFFER_H__ */ diff --git a/win32_test_app/include/TDefs.h b/win32_test_app/include/TDefs.h index c88c444f4b..e0852f0fa9 100644 --- a/win32_test_app/include/TDefs.h +++ b/win32_test_app/include/TDefs.h @@ -10,25 +10,25 @@ #else #define NULL ((void *)0) #endif -#endif /* #ifndef NULL*/ +#endif /* #ifndef NULL */ #if !defined(__cplusplus) && !defined(__BOOL_TYPE_DEFINED) typedef int bool; #define __BOOL_TYPE_DEFINED -#endif /* #ifndef __cplusplus*/ +#endif /* #ifndef __cplusplus */ #ifndef __SSIZE_TYPE_DEFINED typedef int ssize_t; #define __SSIZE_TYPE_DEFINED -#endif /* #ifndef __SSIZE_TYPE_DEFINED */ +#endif /* #ifndef __SSIZE_TYPE_DEFINED */ #ifndef true #define true 1 -#endif /* #ifndef true*/ +#endif /* #ifndef true */ #ifndef false #define false 0 -#endif /* #ifndef false*/ +#endif /* #ifndef false */ /* Asserts that a condition is true.*/ #define ASSERT(c) assert(c) @@ -39,9 +39,9 @@ typedef int ssize_t; #ifndef __ERRNO_TYPE_DEFINED typedef int errno_t; #define __ERRNO_TYPE_DEFINED -#endif /* #ifndef __ERRNO_TYPE_DEFINED */ +#endif /* #ifndef __ERRNO_TYPE_DEFINED */ /* comment this line if you don't want activate the verbose mode. */ -#define __VERBOSE +#define __VERBOSE -#endif /* #ifndef __DEFS_H__ */ +#endif /* #ifndef __DEFS_H__ */ diff --git a/win32_test_app/include/TErrno.h b/win32_test_app/include/TErrno.h index b7f8c5ecda..16e359ddb2 100644 --- a/win32_test_app/include/TErrno.h +++ b/win32_test_app/include/TErrno.h @@ -5,108 +5,107 @@ #include #include -#define E_SUCCESS ((errno_t)0) /* Success */ -#define E_TEST_RUNNER_ALLOCATION_FAILED ((errno_t)1) /* Test runner allocation failed */ -#define E_TEST_CASE_CONTEXT_ALLOCATION_FAILED ((errno_t)2) /* Test case context allocation failed */ -#define E_BUFFER_ALLOCATION_FAILED ((errno_t)3) /* Buffer allocation failed */ -#define E_BUFFER_DATA_ALLOCATION_FAILED ((errno_t)4) /* Buffer data allocation failed */ -#define E_TEST_SUITE_ALLOCATION_FAILED ((errno_t)5) /* Test suite allocation failed */ -#define E_FILE_NOT_FOUND ((errno_t)6) /* Ffile not found */ -#define E_BAD_USAGE ((errno_t)7) /* Bad usage */ -#define E_INVALID_FILE_Stream ((errno_t)8) /* Invalid file stream */ -#define E_STREAM_ALLOCATION_FAILED ((errno_t)9) /* Stream allocation failed */ -#define E_Buffer_DATA_REALLOCATION_FAILED ((errno_t)10) /* Buffer data reallocation failed */ -#define E_STREAM_LINE_ALLOCATION_FAILED ((errno_t)11) /* Stream line allocation failed */ -#define E_STREAM_LINE_REALLOCATION_FAILED ((errno_t)12) /* Stream line reallocation failed */ -#define E_STREAM_EMPTY ((errno_t)13) /* File empty */ -#define E_STREAM_ERROR ((errno_t)14) /* File error */ -#define E_UNKWN_META_COMMAND ((errno_t)15) /* Unknown meta command detected */ -#define E_INVALID_TIMEOUT_VALUE ((errno_t)16) /* Invalid timeout value */ -#define E_INVALID_EXIT_CODE_VALUE ((errno_t)17) /* Invalid exit code */ -#define E_INVALID_EXPORT ((errno_t)18) /* Invalid export meta command */ -#define E_INVALID_UNSET ((errno_t)19) /* Invalid unset meta command */ -#define E_EXPORT_FAILED ((errno_t)20) /* Export failed*/ -#define E_UNSET_FAILED ((errno_t)21) /* Unset failed*/ -#define E_SYNC_TEST_CASE_ALLOCATION_FAILED ((errno_t)22) /* Synchrone test case allocation failed */ -#define E_CANNOT_CREATE_CHILD_STDOUT_READ_HANDLE ((errno_t)23) /* Can't create the child std output read handle */ -#define E_CANNOT_CREATE_CHILD_STDERR_READ_HANDLE ((errno_t)24) /* Can't create the child std error read handle */ -#define E_CANNOT_CREATE_CHILD_STDIN_WRITE_HANDLE ((errno_t)25) /* Can't create the child std input write handle*/ -#define E_CANNOT_CREATE_STDOUT_READ_HANDLE ((errno_t)26) /* Can't create the std output handle */ -#define E_CANNOT_CREATE_STDIN_WRITE_HANDLE ((errno_t)27) /* Can't create the std input handle */ -#define E_CANNOT_CLOSE_CHILD_STDIN_TEMPORY_HANDLE ((errno_t)28) /* Can't close the tempory child std input handle*/ -#define E_CANNOT_CLOSE_CHILD_STDOUT_TEMPORY_HANDLE ((errno_t)29) /* Can't close the tempory child std output handle*/ -#define E_CANNOT_CREATE_CHILD_PROCESS ((errno_t)30) /* Can't create the child process */ -#define E_CANNOT_CLOSE_PROCESS_THREAD_HANDLE ((errno_t)31) /* Can't close the child process handle */ -#define E_CANNOT_CLOSE_CHILD_STDOUT_HANDLE ((errno_t)32) /* Can't close the child std output handle */ -#define E_CANNOT_CLOSE_CHILD_STDIN_HANDLE ((errno_t)33) /* Can't close the child std input handle */ -#define E_CANNOT_CLOSE_CHILD_STDERR_HANDLE ((errno_t)34) /* Can't close the child std error handle */ -#define E_CANNOT_WRITE_ON_CHILD_STDIN ((errno_t)35) /* Can't write on child std output */ -#define E_CANNOT_CREATE_READ_CHILD_OUTPUT_THREAD ((errno_t)36) /* Can't create the read child output thread */ -#define E_WAIT_THREAD_FAILED ((errno_t)37) /* Wait thread failed */ -#define E_CANNOT_CLOSE_THREAD_HANDLE ((errno_t)38) /* Can't close thread handle */ -#define E_CANNOT_CLOSE_READ_HANDLE ((errno_t)39) /* Can't close the read handle */ -#define E_CANNOT_CLOSE_WRITE_HANDLE ((errno_t)40) /* Can't close the write handle */ -#define E_WAIT_FAILURE ((errno_t)41) /* Wait failure */ -#define E_CANNOT_CLOSE_PROCESS_HANDLE ((errno_t)42) /* Can't close the process handle */ -#define E_OUTPUT_DONT_MATCH ((errno_t)43) /* Output don't match */ -#define E_OPEN_FILE_FAILED ((errno_t)44) /* Open file failed*/ -#define E_INVALID_TOKEN ((errno_t)45) /* Invalid token*/ -#define E_WAIT_TIMEOUT ((errno_t)46) /* Wait timeout detected */ -#define E_EXIT_CODE_DONT_MATCH ((errno_t)47) /* Exit code don't match */ -#define E_CHANGE_DIRECTORY_FAILED ((errno_t)48) /* Change directory failed */ +#define E_SUCCESS ((errno_t)0) /* Success */ +#define E_TEST_RUNNER_ALLOCATION_FAILED ((errno_t)1) /* Test runner allocation failed */ +#define E_TEST_CASE_CONTEXT_ALLOCATION_FAILED ((errno_t)2) /* Test case context allocation failed */ +#define E_BUFFER_ALLOCATION_FAILED ((errno_t)3) /* Buffer allocation failed */ +#define E_BUFFER_DATA_ALLOCATION_FAILED ((errno_t)4) /* Buffer data allocation failed */ +#define E_TEST_SUITE_ALLOCATION_FAILED ((errno_t)5) /* Test suite allocation failed */ +#define E_FILE_NOT_FOUND ((errno_t)6) /* Ffile not found */ +#define E_BAD_USAGE ((errno_t)7) /* Bad usage */ +#define E_INVALID_FILE_Stream ((errno_t)8) /* Invalid file stream */ +#define E_STREAM_ALLOCATION_FAILED ((errno_t)9) /* Stream allocation failed */ +#define E_Buffer_DATA_REALLOCATION_FAILED ((errno_t)10) /* Buffer data reallocation failed */ +#define E_STREAM_LINE_ALLOCATION_FAILED ((errno_t)11) /* Stream line allocation failed */ +#define E_STREAM_LINE_REALLOCATION_FAILED ((errno_t)12) /* Stream line reallocation failed */ +#define E_STREAM_EMPTY ((errno_t)13) /* File empty */ +#define E_STREAM_ERROR ((errno_t)14) /* File error */ +#define E_UNKWN_META_COMMAND ((errno_t)15) /* Unknown meta command detected */ +#define E_INVALID_TIMEOUT_VALUE ((errno_t)16) /* Invalid timeout value */ +#define E_INVALID_EXIT_CODE_VALUE ((errno_t)17) /* Invalid exit code */ +#define E_INVALID_EXPORT ((errno_t)18) /* Invalid export meta command */ +#define E_INVALID_UNSET ((errno_t)19) /* Invalid unset meta command */ +#define E_EXPORT_FAILED ((errno_t)20) /* Export failed */ +#define E_UNSET_FAILED ((errno_t)21) /* Unset failed */ +#define E_SYNC_TEST_CASE_ALLOCATION_FAILED ((errno_t)22) /* Synchrone test case allocation failed */ +#define E_CANNOT_CREATE_CHILD_STDOUT_READ_HANDLE ((errno_t)23) /* Can't create the child std output read handle */ +#define E_CANNOT_CREATE_CHILD_STDERR_READ_HANDLE ((errno_t)24) /* Can't create the child std error read handle */ +#define E_CANNOT_CREATE_CHILD_STDIN_WRITE_HANDLE ((errno_t)25) /* Can't create the child std input write handle */ +#define E_CANNOT_CREATE_STDOUT_READ_HANDLE ((errno_t)26) /* Can't create the std output handle */ +#define E_CANNOT_CREATE_STDIN_WRITE_HANDLE ((errno_t)27) /* Can't create the std input handle */ +#define E_CANNOT_CLOSE_CHILD_STDIN_TEMPORY_HANDLE ((errno_t)28) /* Can't close the tempory child std input handle */ +#define E_CANNOT_CLOSE_CHILD_STDOUT_TEMPORY_HANDLE ((errno_t)29) /* Can't close the tempory child std output handle */ +#define E_CANNOT_CREATE_CHILD_PROCESS ((errno_t)30) /* Can't create the child process */ +#define E_CANNOT_CLOSE_PROCESS_THREAD_HANDLE ((errno_t)31) /* Can't close the child process handle */ +#define E_CANNOT_CLOSE_CHILD_STDOUT_HANDLE ((errno_t)32) /* Can't close the child std output handle */ +#define E_CANNOT_CLOSE_CHILD_STDIN_HANDLE ((errno_t)33) /* Can't close the child std input handle */ +#define E_CANNOT_CLOSE_CHILD_STDERR_HANDLE ((errno_t)34) /* Can't close the child std error handle */ +#define E_CANNOT_WRITE_ON_CHILD_STDIN ((errno_t)35) /* Can't write on child std output */ +#define E_CANNOT_CREATE_READ_CHILD_OUTPUT_THREAD ((errno_t)36) /* Can't create the read child output thread */ +#define E_WAIT_THREAD_FAILED ((errno_t)37) /* Wait thread failed */ +#define E_CANNOT_CLOSE_THREAD_HANDLE ((errno_t)38) /* Can't close thread handle */ +#define E_CANNOT_CLOSE_READ_HANDLE ((errno_t)39) /* Can't close the read handle */ +#define E_CANNOT_CLOSE_WRITE_HANDLE ((errno_t)40) /* Can't close the write handle */ +#define E_WAIT_FAILURE ((errno_t)41) /* Wait failure */ +#define E_CANNOT_CLOSE_PROCESS_HANDLE ((errno_t)42) /* Can't close the process handle */ +#define E_OUTPUT_DONT_MATCH ((errno_t)43) /* Output don't match */ +#define E_OPEN_FILE_FAILED ((errno_t)44) /* Open file failed */ +#define E_INVALID_TOKEN ((errno_t)45) /* Invalid token */ +#define E_WAIT_TIMEOUT ((errno_t)46) /* Wait timeout detected */ +#define E_EXIT_CODE_DONT_MATCH ((errno_t)47) /* Exit code don't match */ +#define E_CHANGE_DIRECTORY_FAILED ((errno_t)48) /* Change directory failed */ /* error message list */ -static const char * __errlist[ ] = -{ - "Success", - "Test runner allocation failed", - "Test case context allocation failed", - "Buffer allocation failed", - "Buffer data allocation failed", - "Test suite allocation failed", - "File not found", - "Bad usage", - "Invalid file stream", - "Stream allocation failed", - "Buffer data reallocation failed", - "Stream line allocation failed", - "Stream line reallocation failed", - "File empty", - "File error", - "Unknown meta command detected", - "Invalid timeout value", - "Invalid exit code", - "Invalid export meta command", - "Invalid unset meta command", - "Export failed", - "Unset failed", - "Synchrone test case allocation failed", - "Can't create the child std output read handle", - "Can't create the child std error read handle", - "Can't create the child std input write handle", - "Can't create the std output handle", - "Can't create the std input handle", - "Can't close the tempory child std input handle", - "Can't close the tempory child std output handle", - "Can't create the child process", - "Can't close the child process handle", - "Can't close the child std output handle", - "Can't close the child std input handle", - "Can't close the child std error handle", - "Can't write on child std output", - "Can't create the read child output thread", - "Wait thread failed", - "Can't close thread handle", - "Can't close the read handle", - "Can't close the write handle", - "Wait failure", - "Can't close the process handle", - "Output don't match", - "Open file failed", - "Invalid token", - "Wait timeout detected", - "Exit code don't match", - "Change directory failed" +static const char *__errlist[] = { + "Success", + "Test runner allocation failed", + "Test case context allocation failed", + "Buffer allocation failed", + "Buffer data allocation failed", + "Test suite allocation failed", + "File not found", + "Bad usage", + "Invalid file stream", + "Stream allocation failed", + "Buffer data reallocation failed", + "Stream line allocation failed", + "Stream line reallocation failed", + "File empty", + "File error", + "Unknown meta command detected", + "Invalid timeout value", + "Invalid exit code", + "Invalid export meta command", + "Invalid unset meta command", + "Export failed", + "Unset failed", + "Synchrone test case allocation failed", + "Can't create the child std output read handle", + "Can't create the child std error read handle", + "Can't create the child std input write handle", + "Can't create the std output handle", + "Can't create the std input handle", + "Can't close the tempory child std input handle", + "Can't close the tempory child std output handle", + "Can't create the child process", + "Can't close the child process handle", + "Can't close the child std output handle", + "Can't close the child std input handle", + "Can't close the child std error handle", + "Can't write on child std output", + "Can't create the read child output thread", + "Wait thread failed", + "Can't close thread handle", + "Can't close the read handle", + "Can't close the write handle", + "Wait failure", + "Can't close the process handle", + "Output don't match", + "Open file failed", + "Invalid token", + "Wait timeout detected", + "Exit code don't match", + "Change directory failed" }; extern void initializeErrno(void); @@ -117,4 +116,4 @@ extern void setErrno(errno_t e); extern errno_t getErrno(void); -#endif /* #ifndef __ERRNO_H__ */ \ No newline at end of file +#endif /* #ifndef __ERRNO_H__ */ diff --git a/win32_test_app/include/TStream.h b/win32_test_app/include/TStream.h index 6fd72b71cf..2d09f9dd16 100644 --- a/win32_test_app/include/TStream.h +++ b/win32_test_app/include/TStream.h @@ -12,41 +12,39 @@ * which represents a file stream. */ -typedef struct s_Stream -{ - FILE* file; /* the file stream. */ - char* line; /* the current text line */ - size_t line_number; /* line number in the testsuite file */ - CRITICAL_SECTION cs; /* std output managment */ -}s_Stream_t,* Stream_t; +typedef struct s_Stream { + FILE *file; /* the file stream. */ + char *line; /* the current text line */ + size_t line_number; /* line number in the testsuite file */ + CRITICAL_SECTION cs; /* std output managment */ +} s_Stream_t, *Stream_t; /* Line type. */ -typedef enum -{ - comment_line_type, /* the text line is a comment */ - invalid_token_line_type, /* the text line contains a invalid token */ - unknwn_meta_command_line_type, /* the text line contains a unknown macro command */ - invalid_timeout_value_line_type, /* the text line contains a invalid timeout value */ - timeout_value_line_type, /* the text line contains a valid timeout value */ - invalid_exit_code_line_type, /* the text line contains a invalid exit code value */ - exit_code_line_type, /* the text line contains a valid exit code value */ - invalid_export_line_type, /* the text line contains a invalid export meta command */ - export_line_type, /* the text line contains a valid export meta command */ - invalid_unset_line_type, /* the text line contains a invalid unset meta command */ - unset_line_type, /* the text line contains a valid unset meta command */ - enable_output_checking_line_type, /* the text line contains a enable output checking meta command */ - disable_output_checking_line_type, /* the text line contains a disable output checking meta command */ - enable_post_output_checking_line_type, /* the text line contains a enable post output checking meta command */ - disable_post_output_checking_line_type, /* the text line contains a disable post output checking meta command */ - export_failed_line_type, /* the text line contains a export meta command which failed */ - unset_failed_line_type, /* the text line contains a unset meta command which failed */ - create_console_line_type, /* the text line contains a create console meta command */ - create_no_console_line_type, /* the text line contains a create no console meta command */ - enable_exit_code_checking_line_type, /* the text line contains a enable exit code checking */ - disable_exit_code_checking_line_type, /* the text line contains a disable exit code checking */ - change_directory_line_type, /* the text line contains a change directory command */ - command_line_line_type /* the text line contains a command line */ - }line_type_t; +typedef enum { + comment_line_type, /* the text line is a comment */ + invalid_token_line_type, /* the text line contains a invalid token */ + unknwn_meta_command_line_type, /* the text line contains a unknown macro command */ + invalid_timeout_value_line_type, /* the text line contains a invalid timeout value */ + timeout_value_line_type, /* the text line contains a valid timeout value */ + invalid_exit_code_line_type, /* the text line contains a invalid exit code value */ + exit_code_line_type, /* the text line contains a valid exit code value */ + invalid_export_line_type, /* the text line contains a invalid export meta command */ + export_line_type, /* the text line contains a valid export meta command */ + invalid_unset_line_type, /* the text line contains a invalid unset meta command */ + unset_line_type, /* the text line contains a valid unset meta command */ + enable_output_checking_line_type, /* the text line contains a enable output checking meta command */ + disable_output_checking_line_type, /* the text line contains a disable output checking meta command */ + enable_post_output_checking_line_type, /* the text line contains a enable post output checking meta command */ + disable_post_output_checking_line_type, /* the text line contains a disable post output checking meta command */ + export_failed_line_type, /* the text line contains a export meta command which failed */ + unset_failed_line_type, /* the text line contains a unset meta command which failed */ + create_console_line_type, /* the text line contains a create console meta command */ + create_no_console_line_type, /* the text line contains a create no console meta command */ + enable_exit_code_checking_line_type, /* the text line contains a enable exit code checking */ + disable_exit_code_checking_line_type, /* the text line contains a disable exit code checking */ + change_directory_line_type, /* the text line contains a change directory command */ + command_line_line_type /* the text line contains a command line */ +} line_type_t; /* * Buffer size used in the getline function. @@ -56,7 +54,7 @@ typedef enum /* * s_Stream struct connected functions. */ - + /* * Create a new s_Stream struct and return * a pointer to self @@ -73,20 +71,20 @@ bool Stream_lineIsBlank(Stream_t stream); * Return true if the caracter is space or tab. */ bool Stream_isBlankChar(char ch); - + /* * Return E_SUCCESS if the file is valid. * Otherwise the fuction returns E_INVALID_FILE. */ -errno_t Stream_isValidFile(const char* file_name); +errno_t Stream_isValidFile(const char *file_name); /* * Return E_SUCCESS is the open file operation succeeded. * Otherwise the functions returns E_OPEN_FILE_FAILED. */ -errno_t Stream_openFile(Stream_t ptr,const char* file_name); +errno_t Stream_openFile(Stream_t ptr, const char *file_name); /* * This function reads an entire line, storing @@ -146,7 +144,7 @@ bool Stream_isInvalidUnset(Stream_t stream); * expected child output. Otherwhise the function * returns false. */ -bool Stream_lineIsExpectedChildOutput(Stream_t stream); +bool Stream_lineIsExpectedChildOutput(Stream_t stream); /* * Return true if the stream line contains a @@ -173,7 +171,7 @@ bool Stream_lineIsInvalidMetaCommand(Stream_t stream); /* * Print the file line. */ -void Stream_printLine(Stream_t stream,line_type_t line_type); +void Stream_printLine(Stream_t stream, line_type_t line_type); void Stream_lock(Stream_t ptr); void Stream_unlock(Stream_t ptr); @@ -185,8 +183,8 @@ extern CRITICAL_SECTION cs; /* * Free a s_Stream. */ - - void Stream_free(Stream_t ptr); + +void Stream_free(Stream_t ptr); -#endif /* #ifndef __STREAM_H__ */ \ No newline at end of file +#endif /* #ifndef __STREAM_H__ */ diff --git a/win32_test_app/include/TTestCaseContext.h b/win32_test_app/include/TTestCaseContext.h index df38103b7a..99c6a990f0 100644 --- a/win32_test_app/include/TTestCaseContext.h +++ b/win32_test_app/include/TTestCaseContext.h @@ -9,35 +9,34 @@ * which represents the context of a test case during his * execution. */ -typedef struct s_TestCaseContext -{ - char* name; /* the test case name */ - int timeoutValue; /* the timeout value */ - bool isOutputCheckingEnabled; /* if true, output checking is enable */ - bool isPostOutputCheckingEnabled; /* if true, the post output checking mode is enable */ - Buffer_t inputBuffer; /* buffer that contains child input */ - Buffer_t outputBuffer; /* the child output buffer */ - Buffer_t expectedOutputBuffer; /* buffer that contains child expected output */ - int expectedExitCode; /* the child expected exit code */ - int threadExitCode; /* the thread exit code */ - int exitCode; /* the child process exit code */ - bool runThread; /* false if the thread of the test case must terminate */ - HANDLE hThread; /* the handle of the thread */ - HANDLE hOutputRead; /* handle to the read pipe */ - HANDLE hInputWrite; /* handle to the write pipe */ - HANDLE hChildStdInRead; /* handle to the pipe used to read the child std input */ - HANDLE hChildStdOutWrite; /* handle to the pipe used to write to the chil std output */ - HANDLE hChildStderr; /* handle to the pipe used to read the child std error */ - PROCESS_INFORMATION pi; /* this structure contains child process informations */ - HANDLE hChildStdoutReadTmp; /* tempory handle */ - HANDLE hChildStdinWriteTmp; /* tempory handle */ - bool createConsole; /* true if we can create a console for the child process */ - bool exitCodeCheckingEnabled; /* true if we want to check the child exit code */ - HANDLE hConsole; /* handle to the console */ - bool started; /* true if the child process started */ - Buffer_t commandLineBuffer; /* command line buffer */ - -}s_TestCaseContext_t,* TestCaseContext_t; +typedef struct s_TestCaseContext { + char *name; /* the test case name */ + int timeoutValue; /* the timeout value */ + bool isOutputCheckingEnabled; /* if true, output checking is enable */ + bool isPostOutputCheckingEnabled; /* if true, the post output checking mode is enable */ + Buffer_t inputBuffer; /* buffer that contains child input */ + Buffer_t outputBuffer; /* the child output buffer */ + Buffer_t expectedOutputBuffer; /* buffer that contains child expected output */ + int expectedExitCode; /* the child expected exit code */ + int threadExitCode; /* the thread exit code */ + int exitCode; /* the child process exit code */ + bool runThread; /* false if the thread of the test case must terminate */ + HANDLE hThread; /* the handle of the thread */ + HANDLE hOutputRead; /* handle to the read pipe */ + HANDLE hInputWrite; /* handle to the write pipe */ + HANDLE hChildStdInRead; /* handle to the pipe used to read the child std input */ + HANDLE hChildStdOutWrite; /* handle to the pipe used to write to the chil std output */ + HANDLE hChildStderr; /* handle to the pipe used to read the child std error */ + PROCESS_INFORMATION pi; /* this structure contains child process informations */ + HANDLE hChildStdoutReadTmp; /* tempory handle */ + HANDLE hChildStdinWriteTmp; /* tempory handle */ + bool createConsole; /* true if we can create a console for the child process */ + bool exitCodeCheckingEnabled; /* true if we want to check the child exit code */ + HANDLE hConsole; /* handle to the console */ + bool started; /* true if the child process started */ + Buffer_t commandLineBuffer; /* command line buffer */ + +} s_TestCaseContext_t, *TestCaseContext_t; /* Output checking is disabled by default*/ #define DEFAULT_OUTPUT_CHECKING_MODE false @@ -46,8 +45,8 @@ typedef struct s_TestCaseContext #define DEFAULT_POST_OUTPUT_CHECKING_MODE false /* The default timeout value is 5 seconds*/ - #define DEFAULT_TIMEOUT_VALUE ((int)120000) - +#define DEFAULT_TIMEOUT_VALUE ((int)120000) + /* Invalid exit code value (default value)*/ #define INVALID_EXIT_CODE ((int)0xFFFFFF) @@ -73,7 +72,7 @@ void TestCaseContext_clear(TestCaseContext_t context); /* * Set the timeout of the test case context. */ -void TestCaseContext_setTimeout(TestCaseContext_t context,int timeout); +void TestCaseContext_setTimeout(TestCaseContext_t context, int timeout); /* * Enable the output checking of the test case context. @@ -88,7 +87,8 @@ void TestCaseContext_disableOutputChecking(TestCaseContext_t context); /* * Enable the post output checking of the test case context. */ -void TestCaseContext_enable_post_output_checking(TestCaseContext_t context); +void TestCaseContext_enable_post_output_checking(TestCaseContext_t + context); /* * Disable the post output checking of the test case context. @@ -98,7 +98,8 @@ void TestCaseContext_disablePostOutputChecking(TestCaseContext_t context); /* * Set the expected exit code of the test case context. */ -void TestCaseContext_setExpectedExitCode(TestCaseContext_t context,int expected_code); +void TestCaseContext_setExpectedExitCode(TestCaseContext_t context, + int expected_code); /* * Return true if the output checking mode is enabled for this @@ -110,18 +111,20 @@ bool TestCaseContext_isOutputCheckingEnabled(TestCaseContext_t context); * Append a child output to check in the * test case context. */ -void TestCaseContext_appendExpectedOutput(TestCaseContext_t context,char* expected_output); +void TestCaseContext_appendExpectedOutput(TestCaseContext_t context, + char *expected_output); /* * Append a child output to check in the * test case context. */ -void TestCaseContext_appendChildInput(TestCaseContext_t context,char* input); +void TestCaseContext_appendChildInput(TestCaseContext_t context, + char *input); /* * Set the name of the test case name. */ -void TestCaseContext_setName(TestCaseContext_t context,char* name); +void TestCaseContext_setName(TestCaseContext_t context, char *name); void TestCaseContext_createConsole(TestCaseContext_t context); @@ -132,9 +135,10 @@ void TestCaseContext_enableExitCodeChecking(TestCaseContext_t context); void TestCaseContext_disableExitCodeChecking(TestCaseContext_t context); -void TestCaseContext_setCommandLine(TestCaseContext_t context,char* cmdLine); +void TestCaseContext_setCommandLine(TestCaseContext_t context, + char *cmdLine); + - -#endif /* #ifndef __TestCaseContext_H__ */ \ No newline at end of file +#endif /* #ifndef __TestCaseContext_H__ */ diff --git a/win32_test_app/include/TTestRunner.h b/win32_test_app/include/TTestRunner.h index 17871d7423..ee61b015ee 100644 --- a/win32_test_app/include/TTestRunner.h +++ b/win32_test_app/include/TTestRunner.h @@ -8,18 +8,17 @@ * Declaration of the s_TestRunner structure, which represents * a test runner used to run suites of tests. */ -typedef struct s_TestRunner -{ - Buffer_t buffer; /* a single buffer */ - TestSuite_t testSuite; /* the test suite to run */ - -}s_TestRunner_t,*TestRunner_t; +typedef struct s_TestRunner { + Buffer_t buffer; /* a single buffer */ + TestSuite_t testSuite; /* the test suite to run */ + +} s_TestRunner_t, *TestRunner_t; /* * s_TestRunner structure connected functions. */ - + /* * Create an new s_TestRunner struct and * returns a pointer to self. @@ -29,7 +28,7 @@ TestRunner_t TestRunner_new(void); /* * Initialize the s_TestRunner struct. */ -errno_t TestRunner_initialize(TestRunner_t runner,int argc,char *argv[]); +errno_t TestRunner_initialize(TestRunner_t runner, int argc, char *argv[]); /* * Launch the test runner. @@ -47,4 +46,4 @@ void TestRunner_free(TestRunner_t runner); -#endif /* #ifndef __TestRunner_H__ */ \ No newline at end of file +#endif /* #ifndef __TestRunner_H__ */ diff --git a/win32_test_app/include/TTestSuite.h b/win32_test_app/include/TTestSuite.h index c1cf571975..25a7d8ed14 100644 --- a/win32_test_app/include/TTestSuite.h +++ b/win32_test_app/include/TTestSuite.h @@ -8,18 +8,17 @@ * Declaration of the s_TestSuite, which represents * a suite of tests. */ -typedef struct s_TestSuite -{ - TestCaseContext_t test_case_context; /* the context of the current test case */ - Stream_t stream; /* stdin or file stream */ - size_t testCaseCount; /* test case count */ - size_t successCount; /* test case success count */ - size_t failureCount; /* test case failure count */ - #ifdef __VERBOSE - char currentTime[30]; /* the current time */ - #endif /* #ifdef __VERBOSE */ - ThreadDynarray_t threads; -}s_TestSuite_t,* TestSuite_t; +typedef struct s_TestSuite { + TestCaseContext_t test_case_context; /* the context of the current test case */ + Stream_t stream; /* stdin or file stream */ + size_t testCaseCount; /* test case count */ + size_t successCount; /* test case success count */ + size_t failureCount; /* test case failure count */ +#ifdef __VERBOSE + char currentTime[30]; /* the current time */ +#endif /* #ifdef __VERBOSE */ + ThreadDynarray_t threads; +} s_TestSuite_t, *TestSuite_t; /* * s_TestSuite connected functions. @@ -33,12 +32,12 @@ TestSuite_t TestSuite_new(void); /* * Free the s_TestSuite pointed to by ptr. */ - void TestSuite_free(TestSuite_t ptr); - +void TestSuite_free(TestSuite_t ptr); + /* - * Initialize the s_TestSuite structure. - */ -errno_t TestSuite_initialize(TestSuite_t ptr,int argc,char *argv[]); + * Initialize the s_TestSuite structure. + */ +errno_t TestSuite_initialize(TestSuite_t ptr, int argc, char *argv[]); /* @@ -46,7 +45,7 @@ errno_t TestSuite_initialize(TestSuite_t ptr,int argc,char *argv[]); * the address of the buffer containing the text into * s_TestSuite.current_line. */ -ssize_t TestSuite_getline(TestSuite_t ptr,size_t* len); +ssize_t TestSuite_getline(TestSuite_t ptr, size_t * len); /* * Launch the test suite. @@ -112,11 +111,11 @@ errno_t TestSuite_checkChildOutput(TestCaseContext_t context); /* * Print message */ -void TestSuite_print(const char* str); +void TestSuite_print(const char *str); /* * Check the child process exit code. - */ + */ errno_t TestSuite_checkChildExitCode(TestCaseContext_t context); errno_t TestSuite_unset(TestSuite_t testSuite); @@ -129,16 +128,16 @@ void TestSuite_enableExitCodeChecking(TestSuite_t testSuite); void TestSuite_disableExitCodeChecking(TestSuite_t testSuite); -unsigned long WINAPI TestSuite_runSyncTestCase(void* param); +unsigned long WINAPI TestSuite_runSyncTestCase(void *param); -errno_t TestSuite_runAsyncTestCase(TestSuite_t testSuite); +errno_t TestSuite_runAsyncTestCase(TestSuite_t testSuite); /* * Terminate the test suite. */ void TestSuite_terminate(TestSuite_t testSuite); -unsigned long WINAPI TestSuite_asyncReadChildOutput(void* param); +unsigned long WINAPI TestSuite_asyncReadChildOutput(void *param); bool TestSuite_iSPostOutputCheckingEnabled(TestCaseContext_t context); @@ -154,8 +153,8 @@ void TestSuite_setCommandLine(TestSuite_t testSuite); * Update the current time. */ void TestSuite_update_current_time(TestSuite_t ptr); -#endif /* #ifdef __VERBOSE */ +#endif /* #ifdef __VERBOSE */ -#endif /* #ifndef __TestSuite_H__ */ \ No newline at end of file +#endif /* #ifndef __TestSuite_H__ */ diff --git a/win32_test_app/include/TThreadDynarray.h b/win32_test_app/include/TThreadDynarray.h index 96eabc8fe5..e7bb219c20 100644 --- a/win32_test_app/include/TThreadDynarray.h +++ b/win32_test_app/include/TThreadDynarray.h @@ -1,62 +1,63 @@ #ifndef __THREAD_DYNARRAY_H__ #define __THREAD_DYNARRAY_H__ -#include -#include -#include +#include +#include +#include #include #include -typedef struct s_ThreadEntry -{ - HANDLE hThread; - DWORD threadId; - TestCaseContext_t context; -}s_ThreadEntry_t,* ThreadEntry_t; +typedef struct s_ThreadEntry { + HANDLE hThread; + DWORD threadId; + TestCaseContext_t context; +} s_ThreadEntry_t, *ThreadEntry_t; /* * s_ThreadDynarray struct declaration. */ - -typedef struct s_ThreadDynarray -{ - /* threads */ - ThreadEntry_t threads; - /* thread count */ - unsigned long count; - /* Storage capacity */ - unsigned long capacity; - CRITICAL_SECTION cs; - bool is_locked; -}s_ThreadDynarray_t,* ThreadDynarray_t; +typedef struct s_ThreadDynarray { + /* threads */ + ThreadEntry_t threads; + /* thread count */ + unsigned long count; + /* Storage capacity */ + unsigned long capacity; + CRITICAL_SECTION cs; + bool is_locked; + +} s_ThreadDynarray_t, *ThreadDynarray_t; /* * Constructs a ThreadDynarray with the specified capacity. */ - ThreadDynarray_t ThreadDynarray_new(unsigned long capacity); +ThreadDynarray_t ThreadDynarray_new(unsigned long capacity); /* * Destroy the ThreadDynarray */ - void ThreadDynarray_destroy(ThreadDynarray_t ptr); +void ThreadDynarray_destroy(ThreadDynarray_t ptr); /* * Returns an const pointer THREAD_entry pointed to by index. */ - ThreadEntry_t const ThreadDynarray_at(ThreadDynarray_t ptr, unsigned long index); +ThreadEntry_t const ThreadDynarray_at(ThreadDynarray_t ptr, + unsigned long index); /* * Fill the content of the entry addressed by the __entry with the content * of the entry pointed to by index. */ - void ThreadDynarray_get(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t const __entry); +void ThreadDynarray_get(ThreadDynarray_t ptr, unsigned long index, + ThreadEntry_t const __entry); /* * Fill the content of the entry pointed to by index with the content of * the entry addressed by __entry. */ - void ThreadDynarray_set(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t const __entry); +void ThreadDynarray_set(ThreadDynarray_t ptr, unsigned long index, + ThreadEntry_t const __entry); /* * Returns a const pointer to the first entry. @@ -66,142 +67,155 @@ ThreadEntry_t const ThreadDynarray_getFront(ThreadDynarray_t ptr); /* * Returns a const pointer to the last entry. */ - ThreadEntry_t const ThreadDynarray_getBack(ThreadDynarray_t ptr); +ThreadEntry_t const ThreadDynarray_getBack(ThreadDynarray_t ptr); /* * Inserts a copy of __entry at the front */ - void ThreadDynarray_pushFront(ThreadDynarray_t ptr, ThreadEntry_t const __entry); +void ThreadDynarray_pushFront(ThreadDynarray_t ptr, + ThreadEntry_t const __entry); /* * Appends a copy of __entry to the end. */ - void ThreadDynarray_pushBack(ThreadDynarray_t ptr, ThreadEntry_t const __entry); +void ThreadDynarray_pushBack(ThreadDynarray_t ptr, + ThreadEntry_t const __entry); /* * Inserts __entry at the position pointed to by index. */ - void ThreadDynarray_insert(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t const __entry); +void ThreadDynarray_insert(ThreadDynarray_t ptr, unsigned long index, + ThreadEntry_t const __entry); /* * Deletes the entry pointed to by index. If __entry is not NULL the * fuction saves the entry threads at this address before. */ - void ThreadDynarray_erase(ThreadDynarray_t ptr, unsigned long index,ThreadEntry_t const __entry); +void ThreadDynarray_erase(ThreadDynarray_t ptr, unsigned long index, + ThreadEntry_t const __entry); /* * Find the first entry with the same content of the entry addressed by * __entry.The function returns the index of the founded entry, -1 if * no entry is founded. */ - long ThreadDynarray_getIndex(ThreadDynarray_t ptr, ThreadEntry_t const __entry); +long ThreadDynarray_getIndex(ThreadDynarray_t ptr, + ThreadEntry_t const __entry); /* * Returns true if the entry exist. */ - bool ThreadDynarray_exist(ThreadDynarray_t ptr, ThreadEntry_t const __entry); +bool ThreadDynarray_exist(ThreadDynarray_t ptr, + ThreadEntry_t const __entry); /* Deletes the first entry with the same content of the entry addressed * by __entry.The function returns true if the entry is deleted, false * if no entry is founded. */ - bool ThreadDynarray_remove(ThreadDynarray_t ptr, ThreadEntry_t const __entry); +bool ThreadDynarray_remove(ThreadDynarray_t ptr, + ThreadEntry_t const __entry); /* * Erase all elements of the self. */ - void ThreadDynarray_clear(ThreadDynarray_t ptr); +void ThreadDynarray_clear(ThreadDynarray_t ptr); /* * Resets entry count to zero. */ - void ThreadDynarray_reset(ThreadDynarray_t ptr); +void ThreadDynarray_reset(ThreadDynarray_t ptr); /* * Moves count elements from src index to dst index. */ - void ThreadDynarray_move(ThreadDynarray_t ptr, const unsigned long dst,const unsigned long src,unsigned long count); +void ThreadDynarray_move(ThreadDynarray_t ptr, const unsigned long dst, + const unsigned long src, unsigned long count); /* Compare the content of the entry pointed to by index with the content of * the entry addressed by __entry. The function returns true if the contents * are same. */ - bool ThreadDynarray_compare(ThreadDynarray_t ptr, const unsigned long index,ThreadEntry_t const __entry); +bool ThreadDynarray_compare(ThreadDynarray_t ptr, + const unsigned long index, + ThreadEntry_t const __entry); /* * Returns a reference to a new ThreadDynarray new set is a clone of the self. */ - ThreadDynarray_t ThreadDynarray_clone(ThreadDynarray_t ptr); +ThreadDynarray_t ThreadDynarray_clone(ThreadDynarray_t ptr); /* * Extends the capacity when the container is full. */ - void ThreadDynarray_resize(ThreadDynarray_t ptr); +void ThreadDynarray_resize(ThreadDynarray_t ptr); /* * Returns the number of elements. */ - unsigned long ThreadDynarray_getCount(ThreadDynarray_t ptr); +unsigned long ThreadDynarray_getCount(ThreadDynarray_t ptr); /* * Returns the current storage capacity of the ThreadDynarray. This is guaranteed * to be at least as large as count(). */ - unsigned long ThreadDynarray_getCapacity(ThreadDynarray_t ptr); +unsigned long ThreadDynarray_getCapacity(ThreadDynarray_t ptr); /* * Returns upper bound of self (max index). */ - unsigned long ThreadDynarray_getUpperBound(ThreadDynarray_t ptr); +unsigned long ThreadDynarray_getUpperBound(ThreadDynarray_t ptr); /* * Returns lower bound of self (always zero). */ - unsigned long ThreadDynarray_getLowerBound(ThreadDynarray_t ptr); +unsigned long ThreadDynarray_getLowerBound(ThreadDynarray_t ptr); /* * Returns the size of the elements. */ - unsigned long ThreadDynarray_getElementSize(ThreadDynarray_t ptr); +unsigned long ThreadDynarray_getElementSize(ThreadDynarray_t ptr); /* * Returns true if the size of self is zero. */ - bool ThreadDynarray_isEmpty(ThreadDynarray_t ptr); +bool ThreadDynarray_isEmpty(ThreadDynarray_t ptr); /* * Returns true if capacity available. */ - bool ThreadDynarray(ThreadDynarray_t ptr); +bool ThreadDynarray(ThreadDynarray_t ptr); /* * Returns true if the container is full. */ - bool ThreadDynarray_is_full(ThreadDynarray_t ptr); +bool ThreadDynarray_is_full(ThreadDynarray_t ptr); /* - * Returns true if capacity available. - */ + * Returns true if capacity available. + */ bool ThreadDynarray_getCapacityAvailable(ThreadDynarray_t ptr); /* * Assignement. */ -ThreadDynarray_t ThreadDynarray_assign(ThreadDynarray_t src,ThreadDynarray_t dst); +ThreadDynarray_t ThreadDynarray_assign(ThreadDynarray_t src, + ThreadDynarray_t dst); /* * Returns true if the dynamic arrays are equal. - */ - bool ThreadDynarray_areEquals(ThreadDynarray_t ptr1,ThreadDynarray_t ptr2); + */ +bool ThreadDynarray_areEquals(ThreadDynarray_t ptr1, + ThreadDynarray_t ptr2); /* * Returns true if the dynamic arrays are not equal. - */ -bool ThreadDynarray_areNotEquals(ThreadDynarray_t ptr1,ThreadDynarray_t ptr2); - + */ +bool ThreadDynarray_areNotEquals(ThreadDynarray_t ptr1, + ThreadDynarray_t ptr2); + void ThreadDynarray_lock(ThreadDynarray_t ptr); void ThreadDynarray_unlock(ThreadDynarray_t ptr); -#endif /* #ifndef __THREAD_DYNARRAY_H__ */ +#endif /* #ifndef __THREAD_DYNARRAY_H__ */ diff --git a/win32_test_app/include/TTime.h b/win32_test_app/include/TTime.h index 3a179e098b..b82bcbdfcf 100644 --- a/win32_test_app/include/TTime.h +++ b/win32_test_app/include/TTime.h @@ -6,7 +6,7 @@ #include -void __time(char* t); +void __time(char *t); -#endif /* #ifndef __TIME_H__ */ \ No newline at end of file +#endif /* #ifndef __TIME_H__ */ diff --git a/win32_test_app/src/TBuffer.c b/win32_test_app/src/TBuffer.c index d7a6ccef26..787b3f9527 100644 --- a/win32_test_app/src/TBuffer.c +++ b/win32_test_app/src/TBuffer.c @@ -9,74 +9,70 @@ */ Buffer_t Buffer_new(void) { - Buffer_t buffer = (Buffer_t)calloc(1,sizeof(s_Buffer_t)); - - if(NULL == buffer) - { - setErrno(E_BUFFER_ALLOCATION_FAILED); - return NULL; - } - - buffer->data = (char*)calloc(1,DEFAULT_Buffer_CAPACITY); - - - if(NULL == buffer->data) - { - Buffer_free(buffer); - setErrno(E_BUFFER_DATA_ALLOCATION_FAILED); - return NULL; - } - - buffer->capacity = DEFAULT_Buffer_CAPACITY; - Buffer_clear(buffer); - return buffer; + Buffer_t buffer = (Buffer_t) calloc(1, sizeof(s_Buffer_t)); + + if (NULL == buffer) { + setErrno(E_BUFFER_ALLOCATION_FAILED); + return NULL; + } + + buffer->data = (char *) calloc(1, DEFAULT_Buffer_CAPACITY); + + + if (NULL == buffer->data) { + Buffer_free(buffer); + setErrno(E_BUFFER_DATA_ALLOCATION_FAILED); + return NULL; + } + + buffer->capacity = DEFAULT_Buffer_CAPACITY; + Buffer_clear(buffer); + return buffer; } /* Clears the buffer (this function don't destroy it, * see Buffer_free function.). - */ + */ void Buffer_clear(Buffer_t buffer) { - /* must be a valid buffer. */ - ASSERT_VALID_Buffer(buffer); - - buffer->size = 0; - buffer->data[0]='\n'; - buffer->data[1]='\0'; + /* must be a valid buffer. */ + ASSERT_VALID_Buffer(buffer); + + buffer->size = 0; + buffer->data[0] = '\n'; + buffer->data[1] = '\0'; } /* Appends a string in the buffer. If successful, * the function returns true. Otherwise the function * returns false. */ -bool Buffer_append(Buffer_t buffer,char* str) +bool Buffer_append(Buffer_t buffer, char *str) { - size_t len= strlen(str); - size_t capacity_needed = buffer->size + len + 1; - size_t capacity_available = buffer->capacity - buffer->size; - - /* must be a valid buffer. */ - ASSERT_VALID_Buffer(buffer); - /* must be a valid string. */ - ASSERT_NOT_NULL(str); - - if(capacity_available < capacity_needed) - { - buffer->data = (char*)realloc(buffer->data, capacity_needed); - - if(NULL == buffer->data) - { - setErrno(E_Buffer_DATA_REALLOCATION_FAILED); - return false; - } - - buffer->capacity = capacity_needed; - } - - strcpy(buffer->data + buffer->size,str); - buffer->size += len;/* + 1*/ ; - - return true; + size_t len = strlen(str); + size_t capacity_needed = buffer->size + len + 1; + size_t capacity_available = buffer->capacity - buffer->size; + + /* must be a valid buffer. */ + ASSERT_VALID_Buffer(buffer); + /* must be a valid string. */ + ASSERT_NOT_NULL(str); + + if (capacity_available < capacity_needed) { + buffer->data = (char *) realloc(buffer->data, capacity_needed); + + if (NULL == buffer->data) { + setErrno(E_Buffer_DATA_REALLOCATION_FAILED); + return false; + } + + buffer->capacity = capacity_needed; + } + + strcpy(buffer->data + buffer->size, str); + buffer->size += len; /* + 1 */ ; + + return true; } /* @@ -84,16 +80,16 @@ bool Buffer_append(Buffer_t buffer,char* str) */ void Buffer_chomp(Buffer_t buffer) { - /* must be a valid buffer. */ - ASSERT_VALID_Buffer(buffer); - - while ((buffer->data[buffer->size-1] == '\n') || (buffer->data[buffer->size-1] == '\r')) - { - buffer->data[buffer->size-1] = '\0'; - - if(buffer->size) - (buffer->size)--; - } + /* must be a valid buffer. */ + ASSERT_VALID_Buffer(buffer); + + while ((buffer->data[buffer->size - 1] == '\n') + || (buffer->data[buffer->size - 1] == '\r')) { + buffer->data[buffer->size - 1] = '\0'; + + if (buffer->size) + (buffer->size)--; + } } /* @@ -101,23 +97,23 @@ void Buffer_chomp(Buffer_t buffer) */ void Buffer_free(Buffer_t buffer) { - if(NULL == buffer) - return; - - if(NULL != buffer->data) - free(buffer->data); - - if(NULL != buffer) - free(buffer); + if (NULL == buffer) + return; + + if (NULL != buffer->data) + free(buffer->data); + + if (NULL != buffer) + free(buffer); } /* * This function returns true is the buffer is empty. * Otherwrise the function returns false. */ -bool Buffer_empty(Buffer_t buffer) +bool Buffer_empty(Buffer_t buffer) { - /* must be a valid buffer. */ - ASSERT_VALID_Buffer(buffer); - return (buffer->size) == 0; + /* must be a valid buffer. */ + ASSERT_VALID_Buffer(buffer); + return (buffer->size) == 0; } diff --git a/win32_test_app/src/TErrno.c b/win32_test_app/src/TErrno.c index 6fc7c01bfb..59b51fcba6 100644 --- a/win32_test_app/src/TErrno.c +++ b/win32_test_app/src/TErrno.c @@ -8,42 +8,39 @@ static is_last_errno = false; void initializeErrno(void) { - if(!errno_cs_initialized) - { - memset(&errno_cs,0,sizeof(CRITICAL_SECTION)) ; - InitializeCriticalSection(&errno_cs); - errno_cs_initialized = true; - } + if (!errno_cs_initialized) { + memset(&errno_cs, 0, sizeof(CRITICAL_SECTION)); + InitializeCriticalSection(&errno_cs); + errno_cs_initialized = true; + } } void terminateErrno(void) { - if(errno_cs_initialized) - { - DeleteCriticalSection(&errno_cs); - } + if (errno_cs_initialized) { + DeleteCriticalSection(&errno_cs); + } } void setErrno(errno_t e) { - EnterCriticalSection(&errno_cs); - - if((E_SUCCESS != e) && !is_last_errno) - { - __errno = e; - is_last_errno = true; - } - - LeaveCriticalSection(&errno_cs); + EnterCriticalSection(&errno_cs); + + if ((E_SUCCESS != e) && !is_last_errno) { + __errno = e; + is_last_errno = true; + } + + LeaveCriticalSection(&errno_cs); } errno_t getErrno(void) { - errno_t e; - EnterCriticalSection(&errno_cs); - e = __errno; - LeaveCriticalSection(&errno_cs); - - return e; -} \ No newline at end of file + errno_t e; + EnterCriticalSection(&errno_cs); + e = __errno; + LeaveCriticalSection(&errno_cs); + + return e; +} diff --git a/win32_test_app/src/TStream.c b/win32_test_app/src/TStream.c index a395c03776..d2517ff183 100644 --- a/win32_test_app/src/TStream.c +++ b/win32_test_app/src/TStream.c @@ -1,25 +1,24 @@ #include -extern const char* TOKENS = "$<>#!p&"; +extern const char *TOKENS = "$<>#!p&"; CRITICAL_SECTION cs; -const char * __metacommandlist[ ] = -{ - "set timeout ", - "enable output checking", - "disable output checking", - "enable post output checking", - "disable post output checking", - "expect exit code ", - "export ", - "unset ", - "create console", - "create no console", - "enable exit code checking", - "disable exit code checking", - "command line ", - NULL +const char *__metacommandlist[] = { + "set timeout ", + "enable output checking", + "disable output checking", + "enable post output checking", + "disable post output checking", + "expect exit code ", + "export ", + "unset ", + "create console", + "create no console", + "enable exit code checking", + "disable exit code checking", + "command line ", + NULL }; /* @@ -29,21 +28,20 @@ const char * __metacommandlist[ ] = Stream_t Stream_new(void) { - Stream_t ptr = (Stream_t)calloc(1,sizeof(s_Stream_t)); - - if(NULL == ptr) - { - setErrno(E_STREAM_ALLOCATION_FAILED); - Stream_free(ptr); - } - - memset(&cs,0,sizeof(CRITICAL_SECTION)) ; - InitializeCriticalSection(&cs); - - ptr->line = NULL; - ptr->line_number = 0; - - return ptr; + Stream_t ptr = (Stream_t) calloc(1, sizeof(s_Stream_t)); + + if (NULL == ptr) { + setErrno(E_STREAM_ALLOCATION_FAILED); + Stream_free(ptr); + } + + memset(&cs, 0, sizeof(CRITICAL_SECTION)); + InitializeCriticalSection(&cs); + + ptr->line = NULL; + ptr->line_number = 0; + + return ptr; } /* @@ -51,18 +49,17 @@ Stream_t Stream_new(void) */ bool Stream_lineIsBlank(Stream_t stream) { - size_t i = 0; - char* p = (char*)stream->line; - - while(p[i] != '\n') - { - if(!Stream_isBlankChar(p[i])) - return false; - i++; - - } - - return true; + size_t i = 0; + char *p = (char *) stream->line; + + while (p[i] != '\n') { + if (!Stream_isBlankChar(p[i])) + return false; + i++; + + } + + return true; } /* @@ -70,40 +67,39 @@ bool Stream_lineIsBlank(Stream_t stream) */ bool Stream_isBlankChar(char ch) { - return ((ch ==' ') || ch == ('\t')); + return ((ch == ' ') || ch == ('\t')); } /* * Return E_SUCCESS if the file is valid. * Otherwise the fuction returns E_INVALID_FILE. */ -errno_t Stream_isValidFile(const char* file_name) +errno_t Stream_isValidFile(const char *file_name) { - WIN32_FIND_DATA wfd ={0}; - HANDLE hFile = FindFirstFile(file_name,&wfd); - - if(INVALID_HANDLE_VALUE == hFile) - return E_FILE_NOT_FOUND; - - FindClose(hFile); - return E_SUCCESS; + WIN32_FIND_DATA wfd = { 0 }; + HANDLE hFile = FindFirstFile(file_name, &wfd); + + if (INVALID_HANDLE_VALUE == hFile) + return E_FILE_NOT_FOUND; + + FindClose(hFile); + return E_SUCCESS; } /* * Return E_SUCCESS is the open file operation succeeded. * Otherwise the functions returns E_OPEN_FILE_FAILED. */ -errno_t Stream_openFile(Stream_t ptr,const char* file_name) +errno_t Stream_openFile(Stream_t ptr, const char *file_name) { - ptr->file = fopen(file_name,"r"); - - if(NULL == ptr->file) - { - setErrno(E_OPEN_FILE_FAILED); - return getErrno(); - } - - return E_SUCCESS; + ptr->file = fopen(file_name, "r"); + + if (NULL == ptr->file) { + setErrno(E_OPEN_FILE_FAILED); + return getErrno(); + } + + return E_SUCCESS; } /* @@ -113,124 +109,112 @@ errno_t Stream_openFile(Stream_t ptr,const char* file_name) */ ssize_t Stream_getLine(Stream_t stream) { - size_t capacity_available; /* capacity available in the buffer */ - char* pos; /* read operation position */ - ssize_t size; /* the size of the text line (minus the 0 terminal */ - static size_t len = 0; - register int ch; /* the current character */ - FILE* file = stream->file; - - if(NULL == file) - { - setErrno(E_INVALID_FILE_Stream); - return -1; - } - - if(NULL == stream->line) - { - len = DEFAULT_ALLOC_SIZE; - stream->line = (char*)calloc(1,len); - - if (NULL == stream->line) - { - setErrno(E_STREAM_LINE_ALLOCATION_FAILED); - return -1; - } - } - else - { - memset(stream->line,0,len); - } - - capacity_available = len ; - pos = stream->line; - - while(true) - { - ch = getc(file); - - /* un byte for the next char and one byte for the zero terminal. */ - if (capacity_available < 2) - { - if (len > DEFAULT_ALLOC_SIZE) - len = len << 1; - else - len += DEFAULT_ALLOC_SIZE; - - capacity_available =stream->line + len - pos; - stream->line = realloc (stream->line,len); - - if (NULL ==stream->line) - { - setErrno(E_STREAM_LINE_REALLOCATION_FAILED); - return -1; - } - - pos = stream->line + len - capacity_available ; - } - - if(ferror(file)) - { - /* file error exit on error*/ - setErrno(E_STREAM_ERROR); - return -1; - } - - if((EOF == ch)) - { - /* Empty file */ - if(!strlen(stream->line) && !stream->line_number) - { - setErrno(E_STREAM_EMPTY); - return -1; - } - /* end of file */ - else if(!strlen(stream->line) && stream->line_number) - { - return -1; - } - - break; - } - - *pos++ = ch; - capacity_available--; - - /* we have a line, exit loop */ - if (ch == '\n') - break; - } - - /* append the zero terminal */ - - *pos = '\0'; - size = pos - stream->line; - - stream->line_number++; - - /* size of texte line without zero terminal */ - return size; + size_t capacity_available; /* capacity available in the buffer */ + char *pos; /* read operation position */ + ssize_t size; /* the size of the text line (minus the 0 terminal */ + static size_t len = 0; + register int ch; /* the current character */ + FILE *file = stream->file; + + if (NULL == file) { + setErrno(E_INVALID_FILE_Stream); + return -1; + } + + if (NULL == stream->line) { + len = DEFAULT_ALLOC_SIZE; + stream->line = (char *) calloc(1, len); + + if (NULL == stream->line) { + setErrno(E_STREAM_LINE_ALLOCATION_FAILED); + return -1; + } + } else { + memset(stream->line, 0, len); + } + + capacity_available = len; + pos = stream->line; + + while (true) { + ch = getc(file); + + /* un byte for the next char and one byte for the zero terminal. */ + if (capacity_available < 2) { + if (len > DEFAULT_ALLOC_SIZE) + len = len << 1; + else + len += DEFAULT_ALLOC_SIZE; + + capacity_available = stream->line + len - pos; + stream->line = realloc(stream->line, len); + + if (NULL == stream->line) { + setErrno(E_STREAM_LINE_REALLOCATION_FAILED); + return -1; + } + + pos = stream->line + len - capacity_available; + } + + if (ferror(file)) { + /* file error exit on error */ + setErrno(E_STREAM_ERROR); + return -1; + } + + if ((EOF == ch)) { + /* Empty file */ + if (!strlen(stream->line) && !stream->line_number) { + setErrno(E_STREAM_EMPTY); + return -1; + } + /* end of file */ + else if (!strlen(stream->line) && stream->line_number) { + return -1; + } + + break; + } + + *pos++ = ch; + capacity_available--; + + /* we have a line, exit loop */ + if (ch == '\n') + break; + } + + /* append the zero terminal */ + + *pos = '\0'; + size = pos - stream->line; + + stream->line_number++; + + /* size of texte line without zero terminal */ + return size; } /* * Free a s_Stream. */ - + void Stream_free(Stream_t ptr) { - if(NULL == ptr) - return; - - if((NULL !=ptr->file) && (stdin != ptr->file)) - fclose(ptr->file); - - if(NULL != ptr->line) - free(ptr->line); - - DeleteCriticalSection(&cs); - - free(ptr); + if (NULL == ptr) + return; + + if ((NULL != ptr->file) && (stdin != ptr->file)) + fclose(ptr->file); + + if (NULL != ptr->line) + free(ptr->line); + + DeleteCriticalSection(&cs); + + free(ptr); } /* @@ -239,7 +223,7 @@ void Stream_free(Stream_t ptr) */ bool Stream_lineIsComment(Stream_t stream) { - return stream->line[0] == '#'; + return stream->line[0] == '#'; } /* Return true if the current line contains a invalide token. @@ -247,14 +231,13 @@ bool Stream_lineIsComment(Stream_t stream) */ bool Stream_lineContainsInvalidToken(Stream_t stream) { - if(strchr(TOKENS,stream->line[0]) == NULL) - { - Stream_printLine(stream,invalid_token_line_type); - setErrno(E_INVALID_TOKEN); - return true; - } - - return false; + if (strchr(TOKENS, stream->line[0]) == NULL) { + Stream_printLine(stream, invalid_token_line_type); + setErrno(E_INVALID_TOKEN); + return true; + } + + return false; } /* @@ -263,7 +246,7 @@ bool Stream_lineContainsInvalidToken(Stream_t stream) */ bool Stream_lineIsMetacommand(Stream_t stream) { - return stream->line[0] == '!'; + return stream->line[0] == '!'; } /* Retun true if the text line contains a unknown meta command. @@ -271,18 +254,19 @@ bool Stream_lineIsMetacommand(Stream_t stream) */ bool Stream_lineIsUnknwnMetaCommand(Stream_t stream) { - size_t i = 0; - while(__metacommandlist[i]) - { - if(!strncmp(__metacommandlist[i],stream->line + 2,strlen(__metacommandlist[i]))) - return false; - i++; - } - - Stream_printLine(stream,unknwn_meta_command_line_type); - - setErrno(E_UNKWN_META_COMMAND); - return true; + size_t i = 0; + while (__metacommandlist[i]) { + if (!strncmp + (__metacommandlist[i], stream->line + 2, + strlen(__metacommandlist[i]))) + return false; + i++; + } + + Stream_printLine(stream, unknwn_meta_command_line_type); + + setErrno(E_UNKWN_META_COMMAND); + return true; } /* @@ -291,65 +275,66 @@ bool Stream_lineIsUnknwnMetaCommand(Stream_t stream) */ bool Stream_lineIsInvalidMetaCommand(Stream_t stream) { - if(!strncmp("set timeout ",stream->line + 2,strlen("set timeout "))) - { - return Stream_isInvalidTimeout(stream); - } - else if(!strncmp("command line ",stream->line + 2,strlen("command line "))) - { - Stream_printLine(stream,command_line_line_type); - } - else if(!strncmp("enable output checking",stream->line + 2,strlen("enable output checking"))) - { - Stream_printLine(stream,enable_output_checking_line_type); - } - else if(!strncmp("disable output checking",stream->line + 2,strlen("disable output checking"))) - { - Stream_printLine(stream,disable_output_checking_line_type); - } - else if(!strncmp("enable post output checking",stream->line + 2,strlen("enable post output checking"))) - { - Stream_printLine(stream,enable_post_output_checking_line_type); - } - else if(!strncmp("disable post output checking",stream->line + 2,strlen("disable post output checking"))) - { - Stream_printLine(stream,disable_post_output_checking_line_type); - } - else if(!strncmp("expect exit code ",stream->line + 2,strlen("expect exit code "))) - { - return Stream_isInvalidExpectedCode(stream); - } - else if(!strncmp("export ",stream->line + 2,strlen("export "))) - { - return Stream_isInvalidExport(stream); - } - else if(!strncmp("unset ",stream->line + 2,strlen("unset "))) - { - return Stream_isInvalidUnset(stream); - } - else if(!strncmp("create console",stream->line + 2,strlen("create console"))) - { - Stream_printLine(stream,create_console_line_type); - } - else if(!strncmp("create no console",stream->line + 2,strlen("create no console"))) - { - Stream_printLine(stream,create_no_console_line_type); - } - else if(!strncmp("enable exit code checking",stream->line + 2,strlen("enable exit code checking"))) - { - Stream_printLine(stream,enable_exit_code_checking_line_type); - } - else if(!strncmp("disable exit code checking",stream->line + 2,strlen("disaable exit code checking"))) - { - Stream_printLine(stream,disable_exit_code_checking_line_type); - } - else - { - return true; - } + if (!strncmp("set timeout ", stream->line + 2, strlen("set timeout "))) { + return Stream_isInvalidTimeout(stream); + } else + if (!strncmp + ("command line ", stream->line + 2, strlen("command line "))) { + Stream_printLine(stream, command_line_line_type); + } else + if (!strncmp + ("enable output checking", stream->line + 2, + strlen("enable output checking"))) { + Stream_printLine(stream, enable_output_checking_line_type); + } else + if (!strncmp + ("disable output checking", stream->line + 2, + strlen("disable output checking"))) { + Stream_printLine(stream, disable_output_checking_line_type); + } else + if (!strncmp + ("enable post output checking", stream->line + 2, + strlen("enable post output checking"))) { + Stream_printLine(stream, enable_post_output_checking_line_type); + } else + if (!strncmp + ("disable post output checking", stream->line + 2, + strlen("disable post output checking"))) { + Stream_printLine(stream, disable_post_output_checking_line_type); + } else + if (!strncmp + ("expect exit code ", stream->line + 2, + strlen("expect exit code "))) { + return Stream_isInvalidExpectedCode(stream); + } else if (!strncmp("export ", stream->line + 2, strlen("export "))) { + return Stream_isInvalidExport(stream); + } else if (!strncmp("unset ", stream->line + 2, strlen("unset "))) { + return Stream_isInvalidUnset(stream); + } else + if (!strncmp + ("create console", stream->line + 2, strlen("create console"))) { + Stream_printLine(stream, create_console_line_type); + } else + if (!strncmp + ("create no console", stream->line + 2, + strlen("create no console"))) { + Stream_printLine(stream, create_no_console_line_type); + } else + if (!strncmp + ("enable exit code checking", stream->line + 2, + strlen("enable exit code checking"))) { + Stream_printLine(stream, enable_exit_code_checking_line_type); + } else + if (!strncmp + ("disable exit code checking", stream->line + 2, + strlen("disaable exit code checking"))) { + Stream_printLine(stream, disable_exit_code_checking_line_type); + } else { + return true; + } + + return false; - return false; - } @@ -357,127 +342,151 @@ bool Stream_lineIsInvalidMetaCommand(Stream_t stream) /* * Print the file line. */ -void Stream_printLine(Stream_t stream,line_type_t line_type) +void Stream_printLine(Stream_t stream, line_type_t line_type) { - char* __date = NULL; - __date = (char*)calloc(1,30); - - __time(__date); - - - Stream_lock(stream); - - switch(line_type) - { - #ifdef __VERBOSE - case comment_line_type: - - if(*(stream->line+2) != '\0') - printf("%s %3d %s",__date,stream->line_number,stream->line + 2); - else - /* empty comment */ - printf("%s %3d %s",__date,stream->line_number," \n"); - break; - - case timeout_value_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line + 2 + strlen("set timeout ")); - break; - - case exit_code_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line + 2 + strlen("expect exit code ")); - break; - - case export_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line + 2); - break; - - case unset_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line + 2); - break; - - case enable_output_checking_line_type: - printf("%s %3d\n",__date,stream->line_number); - break; - - case disable_output_checking_line_type: - printf("%s %3d\n",__date,stream->line_number); - break; - - case enable_post_output_checking_line_type: - printf("%s %3d\n",__date,stream->line_number); - break; - - case disable_post_output_checking_line_type: - printf("%s %3d\n",__date,stream->line_number); - break; - - case create_console_line_type: - printf("%s %3d\n",__date,stream->line_number); - break; - - case create_no_console_line_type: - printf("%s %3d\n",__date,stream->line_number); - break; - - case enable_exit_code_checking_line_type: - printf("%s %3d\n",__date,stream->line_number); - break; - - case disable_exit_code_checking_line_type: - printf("%s %3d\n",__date,stream->line_number); - break; - - case change_directory_line_type: - printf("%s %3d %s\n",__date,stream->line_number,stream->line + 5); - break; - - case command_line_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line + 2); - break; - - #endif /* #ifdef __VERBOSE */ - - case invalid_token_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line); - break; - - case unknwn_meta_command_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line); - break; - - case invalid_timeout_value_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line); - break; - - case invalid_exit_code_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line); - break; - - case invalid_export_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line); - break; - - case invalid_unset_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line); - break; - - case export_failed_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line); - break; - - case unset_failed_line_type: - printf("%s %3d %s",__date,stream->line_number,stream->line); - break; - - /* default: - ASSERT(false); - */ - } - - if(__date) - free(__date); - - Stream_unlock(stream); + char *__date = NULL; + __date = (char *) calloc(1, 30); + + __time(__date); + + + Stream_lock(stream); + + switch (line_type) { +#ifdef __VERBOSE + case comment_line_type: + + if (*(stream->line + 2) != '\0') + printf("%s %3d %s", __date, + stream->line_number, stream->line + 2); + else + /* empty comment */ + printf("%s %3d %s", __date, + stream->line_number, " \n"); + break; + + case timeout_value_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line + 2 + strlen("set timeout ")); + break; + + case exit_code_line_type: + printf("%s %3d %s", __date, + stream->line_number, + stream->line + 2 + strlen("expect exit code ")); + break; + + case export_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line + 2); + break; + + case unset_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line + 2); + break; + + case enable_output_checking_line_type: + printf("%s %3d\n", __date, + stream->line_number); + break; + + case disable_output_checking_line_type: + printf("%s %3d\n", __date, + stream->line_number); + break; + + case enable_post_output_checking_line_type: + printf("%s %3d\n", __date, + stream->line_number); + break; + + case disable_post_output_checking_line_type: + printf("%s %3d\n", __date, + stream->line_number); + break; + + case create_console_line_type: + printf("%s %3d\n", __date, + stream->line_number); + break; + + case create_no_console_line_type: + printf("%s %3d\n", __date, + stream->line_number); + break; + + case enable_exit_code_checking_line_type: + printf("%s %3d\n", __date, + stream->line_number); + break; + + case disable_exit_code_checking_line_type: + printf("%s %3d\n", __date, + stream->line_number); + break; + + case change_directory_line_type: + printf("%s %3d %s\n", __date, + stream->line_number, stream->line + 5); + break; + + case command_line_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line + 2); + break; + +#endif /* #ifdef __VERBOSE */ + + case invalid_token_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line); + break; + + case unknwn_meta_command_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line); + break; + + case invalid_timeout_value_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line); + break; + + case invalid_exit_code_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line); + break; + + case invalid_export_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line); + break; + + case invalid_unset_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line); + break; + + case export_failed_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line); + break; + + case unset_failed_line_type: + printf("%s %3d %s", __date, + stream->line_number, stream->line); + break; + + /* default: + ASSERT(false); + */ + } + + if (__date) + free(__date); + + Stream_unlock(stream); } @@ -485,25 +494,23 @@ void Stream_printLine(Stream_t stream,line_type_t line_type) * Returns true if the timeout value is invalid. * Otherwise the function returns false. */ -bool Stream_isInvalidTimeout(Stream_t stream) +bool Stream_isInvalidTimeout(Stream_t stream) { -size_t i = 0; - char* p = stream->line + 2 + strlen("set timeout "); - - while(p[i] != '\n') - { - if(!isdigit(p[i])) - { - setErrno(E_INVALID_TIMEOUT_VALUE); - Stream_printLine(stream,invalid_timeout_value_line_type); - return true; - } - - i++; - } - - Stream_printLine(stream,timeout_value_line_type); - return false; + size_t i = 0; + char *p = stream->line + 2 + strlen("set timeout "); + + while (p[i] != '\n') { + if (!isdigit(p[i])) { + setErrno(E_INVALID_TIMEOUT_VALUE); + Stream_printLine(stream, invalid_timeout_value_line_type); + return true; + } + + i++; + } + + Stream_printLine(stream, timeout_value_line_type); + return false; } @@ -511,24 +518,22 @@ size_t i = 0; * Returns true if the expected code value is invalid. * Otherwise the function returns false. */ -bool Stream_isInvalidExpectedCode(Stream_t stream) +bool Stream_isInvalidExpectedCode(Stream_t stream) { - size_t i = 0; - char* p = stream->line + 2 + strlen("expect exit code "); - - while(p[i] != '\n') - { - if(!isdigit(p[i])) - { - setErrno(E_INVALID_EXIT_CODE_VALUE); - Stream_printLine(stream,invalid_exit_code_line_type); - return true; - } - i++; - } - - Stream_printLine(stream,exit_code_line_type); - return false; + size_t i = 0; + char *p = stream->line + 2 + strlen("expect exit code "); + + while (p[i] != '\n') { + if (!isdigit(p[i])) { + setErrno(E_INVALID_EXIT_CODE_VALUE); + Stream_printLine(stream, invalid_exit_code_line_type); + return true; + } + i++; + } + + Stream_printLine(stream, exit_code_line_type); + return false; } @@ -538,18 +543,17 @@ bool Stream_isInvalidExpectedCode(Stream_t stream) */ bool Stream_isInvalidExport(Stream_t stream) { - /* todo trim*/ - const char* ptr = strchr(stream->line,'='); - - if(ptr && (*(++ptr) != '\n')) - { - Stream_printLine(stream,export_line_type); - return false; - } - - setErrno(E_INVALID_EXPORT); - Stream_printLine(stream,invalid_export_line_type); - return true; + /* todo trim */ + const char *ptr = strchr(stream->line, '='); + + if (ptr && (*(++ptr) != '\n')) { + Stream_printLine(stream, export_line_type); + return false; + } + + setErrno(E_INVALID_EXPORT); + Stream_printLine(stream, invalid_export_line_type); + return true; } /* @@ -558,20 +562,19 @@ bool Stream_isInvalidExport(Stream_t stream) */ bool Stream_isInvalidUnset(Stream_t stream) { - /* todo trim */ - const char* ptr = strchr(stream->line,' '); - - if((*(++ptr) != '\n')) - { - Stream_printLine(stream,unset_line_type); - return false; - } - - setErrno(E_INVALID_UNSET); - Stream_printLine(stream,invalid_unset_line_type); - - - return true; + /* todo trim */ + const char *ptr = strchr(stream->line, ' '); + + if ((*(++ptr) != '\n')) { + Stream_printLine(stream, unset_line_type); + return false; + } + + setErrno(E_INVALID_UNSET); + Stream_printLine(stream, invalid_unset_line_type); + + + return true; } @@ -583,7 +586,7 @@ bool Stream_isInvalidUnset(Stream_t stream) bool Stream_lineIsExpectedChildOutput(Stream_t stream) { - return stream->line[0] == '>'; + return stream->line[0] == '>'; } /* @@ -593,7 +596,7 @@ bool Stream_lineIsExpectedChildOutput(Stream_t stream) */ bool Stream_lineIsChildInput(Stream_t stream) { - return stream->line[0] == '<'; + return stream->line[0] == '<'; } @@ -605,25 +608,26 @@ bool Stream_lineIsChildInput(Stream_t stream) */ bool Stream_lineIsSyncTestCase(Stream_t stream) { - return stream->line[0] == '$'; + return stream->line[0] == '$'; } bool Stream_lineIsAsyncTestCase(Stream_t stream) { - return stream->line[0] == '&'; + return stream->line[0] == '&'; } bool Stream_lineIsChangeDir(Stream_t stream) { - return ((stream->line[0] == '$') && (!strncmp(stream->line+2,"cd ",strlen("cd ")))); + return ((stream->line[0] == '$') + && (!strncmp(stream->line + 2, "cd ", strlen("cd ")))); } void Stream_lock(Stream_t ptr) { - EnterCriticalSection(&cs); + EnterCriticalSection(&cs); } void Stream_unlock(Stream_t ptr) { - LeaveCriticalSection(&cs); + LeaveCriticalSection(&cs); } diff --git a/win32_test_app/src/TTestCaseContext.c b/win32_test_app/src/TTestCaseContext.c index f2ce0f7d4c..1682238110 100644 --- a/win32_test_app/src/TTestCaseContext.c +++ b/win32_test_app/src/TTestCaseContext.c @@ -9,73 +9,68 @@ */ TestCaseContext_t TestCaseContext_new(void) { - TestCaseContext_t context = calloc(1,sizeof(s_TestCaseContext_t)); - - if(NULL == context) - { - setErrno(E_TEST_CASE_CONTEXT_ALLOCATION_FAILED); - return NULL; - } - - context->inputBuffer = Buffer_new(); - - if(NULL == context->inputBuffer) - { - TestCaseContext_free(context); - return NULL; - } - - context->outputBuffer = Buffer_new(); - - if(NULL == context->outputBuffer) - { - TestCaseContext_free(context); - return NULL; - } - - context->expectedOutputBuffer = Buffer_new(); - - if(NULL == context->expectedOutputBuffer) - { - TestCaseContext_free(context); - return NULL; - } - - context->commandLineBuffer = Buffer_new(); - - if(NULL == context->commandLineBuffer) - { - TestCaseContext_free(context); - return NULL; - } - - - context->isOutputCheckingEnabled = DEFAULT_OUTPUT_CHECKING_MODE; - context->isPostOutputCheckingEnabled = DEFAULT_POST_OUTPUT_CHECKING_MODE; - context->timeoutValue = DEFAULT_TIMEOUT_VALUE; - context->expectedExitCode = INVALID_EXIT_CODE; - context->exitCode = INVALID_EXIT_CODE; - context->name = NULL; - - context->runThread = true; - context->hThread = NULL; - context->hOutputRead = NULL; - context->hInputWrite = NULL; - context->hChildStdInRead = NULL; - context->hChildStdOutWrite = NULL; - context->hChildStderr = NULL; - context->hChildStdoutReadTmp = NULL; - context->hChildStdinWriteTmp = NULL; - context->hConsole = NULL; - - context->createConsole = false; - context->exitCodeCheckingEnabled = false; - - context->started = false; - - memset(&(context->pi),0,sizeof(PROCESS_INFORMATION)); - - return context; + TestCaseContext_t context = calloc(1, sizeof(s_TestCaseContext_t)); + + if (NULL == context) { + setErrno(E_TEST_CASE_CONTEXT_ALLOCATION_FAILED); + return NULL; + } + + context->inputBuffer = Buffer_new(); + + if (NULL == context->inputBuffer) { + TestCaseContext_free(context); + return NULL; + } + + context->outputBuffer = Buffer_new(); + + if (NULL == context->outputBuffer) { + TestCaseContext_free(context); + return NULL; + } + + context->expectedOutputBuffer = Buffer_new(); + + if (NULL == context->expectedOutputBuffer) { + TestCaseContext_free(context); + return NULL; + } + + context->commandLineBuffer = Buffer_new(); + + if (NULL == context->commandLineBuffer) { + TestCaseContext_free(context); + return NULL; + } + + + context->isOutputCheckingEnabled = DEFAULT_OUTPUT_CHECKING_MODE; + context->isPostOutputCheckingEnabled = DEFAULT_POST_OUTPUT_CHECKING_MODE; + context->timeoutValue = DEFAULT_TIMEOUT_VALUE; + context->expectedExitCode = INVALID_EXIT_CODE; + context->exitCode = INVALID_EXIT_CODE; + context->name = NULL; + + context->runThread = true; + context->hThread = NULL; + context->hOutputRead = NULL; + context->hInputWrite = NULL; + context->hChildStdInRead = NULL; + context->hChildStdOutWrite = NULL; + context->hChildStderr = NULL; + context->hChildStdoutReadTmp = NULL; + context->hChildStdinWriteTmp = NULL; + context->hConsole = NULL; + + context->createConsole = false; + context->exitCodeCheckingEnabled = false; + + context->started = false; + + memset(&(context->pi), 0, sizeof(PROCESS_INFORMATION)); + + return context; } /* @@ -83,73 +78,71 @@ TestCaseContext_t TestCaseContext_new(void) */ void TestCaseContext_free(TestCaseContext_t context) { - if(NULL == context) - return; - - if(NULL !=context->inputBuffer) - Buffer_free(context->inputBuffer); - - if(NULL !=context->outputBuffer) - Buffer_free(context->outputBuffer); - - if(NULL !=context->expectedOutputBuffer) - Buffer_free(context->expectedOutputBuffer); - - if(NULL !=context->commandLineBuffer) - Buffer_free(context->commandLineBuffer); - - if(NULL == context->name) - free(context->name); - - - /* Close all pipe handles. */ - if(context->hChildStdoutReadTmp) - CloseHandle(context->hChildStdoutReadTmp); - - if(context->hChildStdInRead) - CloseHandle(context->hChildStdInRead); - - if(context->hChildStdinWriteTmp) - CloseHandle(context->hChildStdinWriteTmp); - - if(context->hChildStdOutWrite) - CloseHandle(context->hChildStdOutWrite); - - if(context->hOutputRead) - CloseHandle(context->hOutputRead); - - if(context->pi.hThread) - CloseHandle(context->pi.hThread); - - /* Use some violence, no choice. */ - if(context->pi.hProcess) - { - /* Kill the child process. */ - TerminateProcess(context->pi.hProcess,0); - } - - if(context->hThread) - { - /* Terminate the thread */ - TerminateThread(context->hThread,0); - } - - if(context->hInputWrite) - CloseHandle(context->hInputWrite); - - if(context->hChildStderr) - CloseHandle(context->hChildStderr); - - free(context); - context = NULL; + if (NULL == context) + return; + + if (NULL != context->inputBuffer) + Buffer_free(context->inputBuffer); + + if (NULL != context->outputBuffer) + Buffer_free(context->outputBuffer); + + if (NULL != context->expectedOutputBuffer) + Buffer_free(context->expectedOutputBuffer); + + if (NULL != context->commandLineBuffer) + Buffer_free(context->commandLineBuffer); + + if (NULL == context->name) + free(context->name); + + + /* Close all pipe handles. */ + if (context->hChildStdoutReadTmp) + CloseHandle(context->hChildStdoutReadTmp); + + if (context->hChildStdInRead) + CloseHandle(context->hChildStdInRead); + + if (context->hChildStdinWriteTmp) + CloseHandle(context->hChildStdinWriteTmp); + + if (context->hChildStdOutWrite) + CloseHandle(context->hChildStdOutWrite); + + if (context->hOutputRead) + CloseHandle(context->hOutputRead); + + if (context->pi.hThread) + CloseHandle(context->pi.hThread); + + /* Use some violence, no choice. */ + if (context->pi.hProcess) { + /* Kill the child process. */ + TerminateProcess(context->pi.hProcess, 0); + } + + if (context->hThread) { + /* Terminate the thread */ + TerminateThread(context->hThread, 0); + } + + if (context->hInputWrite) + CloseHandle(context->hInputWrite); + + if (context->hChildStderr) + CloseHandle(context->hChildStderr); + + free(context); + context = NULL; } /* * Set the timeout of the test case context. */ -void TestCaseContext_setTimeout(TestCaseContext_t context,int timeout) +void TestCaseContext_setTimeout(TestCaseContext_t context, int timeout) { - context->timeoutValue = timeout; + context->timeoutValue = timeout; } /* @@ -157,7 +150,7 @@ void TestCaseContext_setTimeout(TestCaseContext_t context,int timeout) */ void TestCaseContext_enableOutputChecking(TestCaseContext_t context) { - context->isOutputCheckingEnabled = true; + context->isOutputCheckingEnabled = true; } /* @@ -165,9 +158,9 @@ void TestCaseContext_enableOutputChecking(TestCaseContext_t context) */ void TestCaseContext_disableOutputChecking(TestCaseContext_t context) { - /* If the post output checking mode is enable, disable it*/ - context->isPostOutputCheckingEnabled = false; - context->isOutputCheckingEnabled = false; + /* If the post output checking mode is enable, disable it */ + context->isPostOutputCheckingEnabled = false; + context->isOutputCheckingEnabled = false; } /* @@ -175,9 +168,9 @@ void TestCaseContext_disableOutputChecking(TestCaseContext_t context) */ void TestCaseContext_enable_post_output_checking(TestCaseContext_t context) { - /* enable the post output checking mode if the output checking mode is enabled*/ - if(context->isOutputCheckingEnabled) - context->isPostOutputCheckingEnabled = true; + /* enable the post output checking mode if the output checking mode is enabled */ + if (context->isOutputCheckingEnabled) + context->isPostOutputCheckingEnabled = true; } /* @@ -185,25 +178,26 @@ void TestCaseContext_enable_post_output_checking(TestCaseContext_t context) */ void TestCaseContext_disablePostOutputChecking(TestCaseContext_t context) { - context->isPostOutputCheckingEnabled = false; + context->isPostOutputCheckingEnabled = false; } void TestCaseContext_createConsole(TestCaseContext_t context) { - context->createConsole = true; + context->createConsole = true; } void TestCaseContext_createNoConsole(TestCaseContext_t context) { - context->createConsole = false; + context->createConsole = false; } /* * Set the expected exit code of the test case context. */ -void TestCaseContext_setExpectedExitCode(TestCaseContext_t context,int expected_code) +void TestCaseContext_setExpectedExitCode(TestCaseContext_t context, + int expected_code) { - context->expectedExitCode = expected_code; + context->expectedExitCode = expected_code; } /* @@ -212,22 +206,23 @@ void TestCaseContext_setExpectedExitCode(TestCaseContext_t context,int expected_ */ bool TestCaseContext_isOutputCheckingEnabled(TestCaseContext_t context) { - return context->isOutputCheckingEnabled; + return context->isOutputCheckingEnabled; } void TestCaseContext_enableExitCodeChecking(TestCaseContext_t context) { - context->exitCodeCheckingEnabled = true; + context->exitCodeCheckingEnabled = true; } void TestCaseContext_disableExitCodeChecking(TestCaseContext_t context) { - context->exitCodeCheckingEnabled = false; + context->exitCodeCheckingEnabled = false; } -void TestCaseContext_setCommandLine(TestCaseContext_t context,char* cmdLine) +void TestCaseContext_setCommandLine(TestCaseContext_t context, + char *cmdLine) { - Buffer_append(context->commandLineBuffer,cmdLine); + Buffer_append(context->commandLineBuffer, cmdLine); } @@ -235,44 +230,45 @@ void TestCaseContext_setCommandLine(TestCaseContext_t context,char* cmdLine) * Append a child output to check in the * test case context. */ -void TestCaseContext_appendExpectedOutput(TestCaseContext_t context,char* expected_output) +void TestCaseContext_appendExpectedOutput(TestCaseContext_t context, + char *expected_output) { - Buffer_append(context->expectedOutputBuffer,expected_output); + Buffer_append(context->expectedOutputBuffer, expected_output); } /* * Append a child output to check in the * test case context. */ -void TestCaseContext_appendChildInput(TestCaseContext_t context,char* input) +void TestCaseContext_appendChildInput(TestCaseContext_t context, + char *input) { - Buffer_append(context->inputBuffer,input); + Buffer_append(context->inputBuffer, input); } /* * Set the name of the test case name. */ -void TestCaseContext_setName(TestCaseContext_t context,char* name) +void TestCaseContext_setName(TestCaseContext_t context, char *name) { - size_t size; - - if(NULL != context->name) - { - free(context->name); - } - - context->name = strdup(name); - size = strlen(name); - - while ((context->name[size-1] == '\n') || (context->name[size-1] == '\r')) - { - context->name[size-1] = '\0'; - - if(size) - size--; - } - - /*context->name[strlen(context->name) - 1] ='\0';*/ + size_t size; + + if (NULL != context->name) { + free(context->name); + } + + context->name = strdup(name); + size = strlen(name); + + while ((context->name[size - 1] == '\n') + || (context->name[size - 1] == '\r')) { + context->name[size - 1] = '\0'; + + if (size) + size--; + } + + /*context->name[strlen(context->name) - 1] ='\0'; */ } /* @@ -280,27 +276,26 @@ void TestCaseContext_setName(TestCaseContext_t context,char* name) */ void TestCaseContext_clear(TestCaseContext_t context) { - if(!Buffer_empty(context->inputBuffer)) - Buffer_clear(context->inputBuffer); - - if(!Buffer_empty(context->outputBuffer)) - Buffer_clear(context->outputBuffer); - - if(!Buffer_empty(context->expectedOutputBuffer)) - Buffer_clear(context->expectedOutputBuffer); - - if(!Buffer_empty(context->commandLineBuffer)) - Buffer_clear(context->commandLineBuffer); - - if(NULL == context->name) - { - free(context->name); - context->name = NULL; - } - - context->isOutputCheckingEnabled = DEFAULT_OUTPUT_CHECKING_MODE; - context->isPostOutputCheckingEnabled = DEFAULT_POST_OUTPUT_CHECKING_MODE; - context->timeoutValue = DEFAULT_TIMEOUT_VALUE; - context->expectedExitCode = INVALID_EXIT_CODE; - context->exitCode = INVALID_EXIT_CODE; -} \ No newline at end of file + if (!Buffer_empty(context->inputBuffer)) + Buffer_clear(context->inputBuffer); + + if (!Buffer_empty(context->outputBuffer)) + Buffer_clear(context->outputBuffer); + + if (!Buffer_empty(context->expectedOutputBuffer)) + Buffer_clear(context->expectedOutputBuffer); + + if (!Buffer_empty(context->commandLineBuffer)) + Buffer_clear(context->commandLineBuffer); + + if (NULL == context->name) { + free(context->name); + context->name = NULL; + } + + context->isOutputCheckingEnabled = DEFAULT_OUTPUT_CHECKING_MODE; + context->isPostOutputCheckingEnabled = DEFAULT_POST_OUTPUT_CHECKING_MODE; + context->timeoutValue = DEFAULT_TIMEOUT_VALUE; + context->expectedExitCode = INVALID_EXIT_CODE; + context->exitCode = INVALID_EXIT_CODE; +} diff --git a/win32_test_app/src/TTestRunner.c b/win32_test_app/src/TTestRunner.c index f27a2d3045..3855f96430 100644 --- a/win32_test_app/src/TTestRunner.c +++ b/win32_test_app/src/TTestRunner.c @@ -7,41 +7,41 @@ */ TestRunner_t TestRunner_new(void) { - TestRunner_t ptr = calloc(1,sizeof(s_TestRunner_t)); - - if(NULL == ptr){ - setErrno(E_TEST_RUNNER_ALLOCATION_FAILED); - return NULL; - } - - ptr->buffer = Buffer_new(); - - if(NULL == ptr->buffer){ - TestRunner_free(ptr); - return NULL; - } - - ptr->testSuite = TestSuite_new(); - - if(NULL == ptr->testSuite){ - TestRunner_free(ptr); - return NULL; - } - - setErrno(E_SUCCESS); - return ptr; + TestRunner_t ptr = calloc(1, sizeof(s_TestRunner_t)); + + if (NULL == ptr) { + setErrno(E_TEST_RUNNER_ALLOCATION_FAILED); + return NULL; + } + + ptr->buffer = Buffer_new(); + + if (NULL == ptr->buffer) { + TestRunner_free(ptr); + return NULL; + } + + ptr->testSuite = TestSuite_new(); + + if (NULL == ptr->testSuite) { + TestRunner_free(ptr); + return NULL; + } + + setErrno(E_SUCCESS); + return ptr; } /* * Initialize the s_TestRunner struct * by processing the command line. */ -errno_t TestRunner_initialize(TestRunner_t runner,int argc,char *argv[]) +errno_t TestRunner_initialize(TestRunner_t runner, int argc, char *argv[]) { - if(E_SUCCESS != TestSuite_initialize(runner->testSuite,argc,argv)) - return getErrno(); - - return E_SUCCESS; + if (E_SUCCESS != TestSuite_initialize(runner->testSuite, argc, argv)) + return getErrno(); + + return E_SUCCESS; } /* @@ -49,7 +49,7 @@ errno_t TestRunner_initialize(TestRunner_t runner,int argc,char *argv[]) */ void TestRunner_run(TestRunner_t runner) { - TestSuite_run(runner->testSuite); + TestSuite_run(runner->testSuite); } /* @@ -57,14 +57,12 @@ void TestRunner_run(TestRunner_t runner) */ void TestRunner_free(TestRunner_t runner) { - if(NULL == runner) - return; - - if(NULL != runner->buffer) - Buffer_free(runner->buffer); - - if(NULL != runner->testSuite) - TestSuite_free(runner->testSuite); -} + if (NULL == runner) + return; + if (NULL != runner->buffer) + Buffer_free(runner->buffer); + if (NULL != runner->testSuite) + TestSuite_free(runner->testSuite); +} diff --git a/win32_test_app/src/TTestSuite.c b/win32_test_app/src/TTestSuite.c index 854b222f48..e2c49bea32 100644 --- a/win32_test_app/src/TTestSuite.c +++ b/win32_test_app/src/TTestSuite.c @@ -6,74 +6,73 @@ */ TestSuite_t TestSuite_new(void) { - TestSuite_t testSuite = calloc(1,sizeof(s_TestSuite_t)); - - if(NULL == testSuite){ - setErrno(E_TEST_SUITE_ALLOCATION_FAILED); - TestSuite_free(testSuite); - return NULL; - } - - testSuite->stream = Stream_new(); - - if(NULL == testSuite->stream){ - TestSuite_free(testSuite); - return NULL; - } - - testSuite->test_case_context = TestCaseContext_new(); - - if(NULL == testSuite->test_case_context){ - TestSuite_free(testSuite); - return NULL; - } - - testSuite->test_case_context->hConsole = GetStdHandle(STD_OUTPUT_HANDLE); - - testSuite->threads = ThreadDynarray_new(15); - - if(NULL == testSuite->threads){ - TestSuite_free(testSuite); - return NULL; - } + TestSuite_t testSuite = calloc(1, sizeof(s_TestSuite_t)); + + if (NULL == testSuite) { + setErrno(E_TEST_SUITE_ALLOCATION_FAILED); + TestSuite_free(testSuite); + return NULL; + } + + testSuite->stream = Stream_new(); + + if (NULL == testSuite->stream) { + TestSuite_free(testSuite); + return NULL; + } + + testSuite->test_case_context = TestCaseContext_new(); + + if (NULL == testSuite->test_case_context) { + TestSuite_free(testSuite); + return NULL; + } - testSuite->successCount = 0; - testSuite->failureCount = 0; - - return testSuite; + testSuite->test_case_context->hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + + testSuite->threads = ThreadDynarray_new(15); + + if (NULL == testSuite->threads) { + TestSuite_free(testSuite); + return NULL; + } + + testSuite->successCount = 0; + testSuite->failureCount = 0; + + return testSuite; } /* * Initialize the s_TestSuite structure. */ -errno_t TestSuite_initialize(TestSuite_t ptr,int argc,char *argv[]) +errno_t TestSuite_initialize(TestSuite_t ptr, int argc, char *argv[]) { - switch(argc) - { - case 1: - TestSuite_print("Run the test case from the console.\n"); - - ptr->stream->file = stdin; - return E_SUCCESS; - - case 2: - - if(E_SUCCESS != Stream_isValidFile(argv[1])) - return getErrno(); - - printf("\n\n Test runner : %s\n\n",argv[1]); - - if(E_SUCCESS != Stream_openFile(ptr->stream,argv[1])) - return getErrno(); - - return E_SUCCESS; - - default: - { - setErrno(E_BAD_USAGE); - return getErrno(); - } - } + switch (argc) { + case 1: + TestSuite_print("Run the test case from the console.\n"); + + ptr->stream->file = stdin; + return E_SUCCESS; + + case 2: + + if (E_SUCCESS != Stream_isValidFile(argv[1])) + return getErrno(); + + printf("\n\n Test runner : %s\n\n", argv[1]); + + if (E_SUCCESS != Stream_openFile(ptr->stream, argv[1])) + return getErrno(); + + return E_SUCCESS; + + default: + { + setErrno(E_BAD_USAGE); + return getErrno(); + } + } } /* @@ -81,171 +80,174 @@ errno_t TestSuite_initialize(TestSuite_t ptr,int argc,char *argv[]) */ void TestSuite_run(TestSuite_t testSuite) { - Stream_t stream = testSuite->stream; - - /* Handle all lines in the testsuite file (or from stdin) */ - while((Stream_getLine(stream) != -1) && (E_SUCCESS == getErrno())) - { - /* Don't process blank lines. */ - if (Stream_lineIsBlank(stream)) - continue; - - /* Check if the current text line contains a invalid token. */ - if(Stream_lineContainsInvalidToken(stream)) - return; - - /* Check if the text line contains a meta command. */ - if(Stream_lineIsMetaCommand(stream)){ - /* Check if the current text line contains a unknown meta command. */ - if(Stream_lineIsUnknwnMetaCommand(stream)) - return; - - /* Check the meta command validity.*/ - if(Stream_lineIsInvalidMetaCommand(stream)) - return; - - /* We have a valid meta command, process it */ - if(E_SUCCESS != TestSuite_processMetaCommand(testSuite)) - return; - - continue; - } - - /* Handle the comment. */ - if(Stream_lineIsComment(stream)){ - Stream_printLine(testSuite->stream,comment_line_type); - continue; - } - - /* Handle expected child output. */ - if(Stream_lineIsExpectedChildOutput(stream)){ - if(E_SUCCESS != TestSuite_processExpectedChildOutput(testSuite)) - return; - - continue; - } - - /* Handle expected child input. */ - if(Stream_lineIsChildInput(stream)){ - if(E_SUCCESS != TestSuite_processChildInput(testSuite)) - return; - - continue; - } - - if(Stream_lineIsChangeDir(stream)){ - if(E_SUCCESS != TestSuite_changeDir(testSuite)) - return; - - continue; - } - - /* Handle synchrone synchrone test case. */ - if(Stream_lineIsSyncTestCase(stream)){ - TestCaseContext_setName(testSuite->test_case_context,stream->line + 2); - - TestSuite_runSyncTestCase(testSuite->test_case_context); - - - if(TestSuite_iSPostOutputCheckingEnabled(testSuite->test_case_context)){ - TestSuite_checkChildOutput(testSuite->test_case_context); - } - - if(TestSuite_iSExitCodeCheckingEnabled(testSuite->test_case_context)){ - if(E_SUCCESS != TestSuite_checkChildExitCode(testSuite->test_case_context)) - return; - } - - - if(E_SUCCESS != getErrno()) - return; - } - /* Handle asynchrone synchrone test case. */ - else if(Stream_lineIsAsyncTestCase(stream)) - { - TestCaseContext_setName(testSuite->test_case_context,stream->line + 2); - - if(E_SUCCESS != TestSuite_runAsyncTestCase(testSuite)) - return; - } - else - { - ASSERT(false); - } - - /* Clear the child input stream. */ - Buffer_clear(testSuite->test_case_context->inputBuffer); - /* Clear the command line buffer. */ - Buffer_clear(testSuite->test_case_context->commandLineBuffer); - } + Stream_t stream = testSuite->stream; + + /* Handle all lines in the testsuite file (or from stdin) */ + while ((Stream_getLine(stream) != -1) && (E_SUCCESS == getErrno())) { + /* Don't process blank lines. */ + if (Stream_lineIsBlank(stream)) + continue; + + /* Check if the current text line contains a invalid token. */ + if (Stream_lineContainsInvalidToken(stream)) + return; + + /* Check if the text line contains a meta command. */ + if (Stream_lineIsMetaCommand(stream)) { + /* Check if the current text line contains a unknown meta command. */ + if (Stream_lineIsUnknwnMetaCommand(stream)) + return; + + /* Check the meta command validity. */ + if (Stream_lineIsInvalidMetaCommand(stream)) + return; + + /* We have a valid meta command, process it */ + if (E_SUCCESS != TestSuite_processMetaCommand(testSuite)) + return; + + continue; + } + + /* Handle the comment. */ + if (Stream_lineIsComment(stream)) { + Stream_printLine(testSuite->stream, comment_line_type); + continue; + } + + /* Handle expected child output. */ + if (Stream_lineIsExpectedChildOutput(stream)) { + if (E_SUCCESS != TestSuite_processExpectedChildOutput(testSuite)) + return; + + continue; + } + + /* Handle expected child input. */ + if (Stream_lineIsChildInput(stream)) { + if (E_SUCCESS != TestSuite_processChildInput(testSuite)) + return; + + continue; + } + + if (Stream_lineIsChangeDir(stream)) { + if (E_SUCCESS != TestSuite_changeDir(testSuite)) + return; + + continue; + } + + /* Handle synchrone synchrone test case. */ + if (Stream_lineIsSyncTestCase(stream)) { + TestCaseContext_setName(testSuite->test_case_context, + stream->line + 2); + + TestSuite_runSyncTestCase(testSuite->test_case_context); + + + if (TestSuite_iSPostOutputCheckingEnabled + (testSuite->test_case_context)) { + TestSuite_checkChildOutput(testSuite->test_case_context); + } + + if (TestSuite_iSExitCodeCheckingEnabled + (testSuite->test_case_context)) { + if (E_SUCCESS != + TestSuite_checkChildExitCode(testSuite->test_case_context)) + return; + } + + + if (E_SUCCESS != getErrno()) + return; + } + /* Handle asynchrone synchrone test case. */ + else if (Stream_lineIsAsyncTestCase(stream)) { + TestCaseContext_setName(testSuite->test_case_context, + stream->line + 2); + + if (E_SUCCESS != TestSuite_runAsyncTestCase(testSuite)) + return; + } else { + ASSERT(false); + } + + /* Clear the child input stream. */ + Buffer_clear(testSuite->test_case_context->inputBuffer); + /* Clear the command line buffer. */ + Buffer_clear(testSuite->test_case_context->commandLineBuffer); + } } + /* * Meta command processing. */ errno_t TestSuite_processMetaCommand(TestSuite_t testSuite) { - Stream_t stream = testSuite->stream; - - if(!strncmp("set timeout ",stream->line + 2,strlen("set timeout "))) - { - TestSuite_setTimeout(testSuite); - } - else if(!strncmp("command line ",stream->line + 2,strlen("command line"))) - { - TestSuite_setCommandLine(testSuite); - } - else if(!strncmp("enable output checking",stream->line + 2,strlen("enable output checking"))) - { - TestSuite_enableOutputChecking(testSuite); - } - else if(!strncmp("disable output checking",stream->line + 2,strlen("disable output checking"))) - { - TestSuite_disableOutputChecking(testSuite); - } - else if(!strncmp("enable post output checking",stream->line + 2,strlen("enable post output checking"))) - { - TestSuite_enablePostOutputChecking(testSuite); - } - else if(!strncmp("disable post output checking",stream->line + 2,strlen("disable post output checking"))) - { - TestSuite_disablePostOutputChecking(testSuite); - } - else if(!strncmp("expect exit code ",stream->line + 2,strlen("expect exit code "))) - { - TestSuite_setExpectedExitCode(testSuite); - } - else if(!strncmp("export ",stream->line + 2,strlen("export "))) - { - TestSuite_export(testSuite); - } - else if(!strncmp("unset ",stream->line + 2,strlen("unset "))) - { - TestSuite_unset(testSuite); - } - else if(!strncmp("create console",stream->line + 2,strlen("create console"))) - { - TestSuite_createConsole(testSuite); - } - else if(!strncmp("create no console",stream->line + 2,strlen("create no console"))) - { - TestSuite_createNoConsole(testSuite); - } - else if(!strncmp("enable exit code checking",stream->line + 2,strlen("enable exit code checking"))) - { - TestSuite_enableExitCodeChecking(testSuite); - } - else if(!strncmp("disable exit code checking",stream->line + 2,strlen("disable exit code checking"))) - { - TestSuite_disableExitCodeChecking(testSuite); - } - else - { - /* TODO */ - ASSERT(false); - } - - return E_SUCCESS; - + Stream_t stream = testSuite->stream; + + if (!strncmp("set timeout ", stream->line + 2, strlen("set timeout "))) { + TestSuite_setTimeout(testSuite); + } else + if (!strncmp + ("command line ", stream->line + 2, strlen("command line"))) { + TestSuite_setCommandLine(testSuite); + } else + if (!strncmp + ("enable output checking", stream->line + 2, + strlen("enable output checking"))) { + TestSuite_enableOutputChecking(testSuite); + } else + if (!strncmp + ("disable output checking", stream->line + 2, + strlen("disable output checking"))) { + TestSuite_disableOutputChecking(testSuite); + } else + if (!strncmp + ("enable post output checking", stream->line + 2, + strlen("enable post output checking"))) { + TestSuite_enablePostOutputChecking(testSuite); + } else + if (!strncmp + ("disable post output checking", stream->line + 2, + strlen("disable post output checking"))) { + TestSuite_disablePostOutputChecking(testSuite); + } else + if (!strncmp + ("expect exit code ", stream->line + 2, + strlen("expect exit code "))) { + TestSuite_setExpectedExitCode(testSuite); + } else if (!strncmp("export ", stream->line + 2, strlen("export "))) { + TestSuite_export(testSuite); + } else if (!strncmp("unset ", stream->line + 2, strlen("unset "))) { + TestSuite_unset(testSuite); + } else + if (!strncmp + ("create console", stream->line + 2, strlen("create console"))) { + TestSuite_createConsole(testSuite); + } else + if (!strncmp + ("create no console", stream->line + 2, + strlen("create no console"))) { + TestSuite_createNoConsole(testSuite); + } else + if (!strncmp + ("enable exit code checking", stream->line + 2, + strlen("enable exit code checking"))) { + TestSuite_enableExitCodeChecking(testSuite); + } else + if (!strncmp + ("disable exit code checking", stream->line + 2, + strlen("disable exit code checking"))) { + TestSuite_disableExitCodeChecking(testSuite); + } else { + /* TODO */ + ASSERT(false); + } + + return E_SUCCESS; + } /* @@ -254,9 +256,9 @@ errno_t TestSuite_processMetaCommand(TestSuite_t testSuite) */ void TestSuite_setTimeout(TestSuite_t testSuite) { - - int timeout = atoi(testSuite->stream->line + 2 + strlen("set timeout ")); - TestCaseContext_setTimeout(testSuite->test_case_context,timeout); + + int timeout = atoi(testSuite->stream->line + 2 + strlen("set timeout ")); + TestCaseContext_setTimeout(testSuite->test_case_context, timeout); } /* @@ -264,12 +266,14 @@ void TestSuite_setTimeout(TestSuite_t testSuite) */ void TestSuite_enableOutputChecking(TestSuite_t testSuite) { - TestCaseContext_enableOutputChecking(testSuite->test_case_context); + TestCaseContext_enableOutputChecking(testSuite->test_case_context); } void TestSuite_setCommandLine(TestSuite_t testSuite) { - TestCaseContext_setCommandLine(testSuite->test_case_context,testSuite->stream->line + 2 + strlen("command line ")); + TestCaseContext_setCommandLine(testSuite->test_case_context, + testSuite->stream->line + 2 + + strlen("command line ")); } /* @@ -277,7 +281,7 @@ void TestSuite_setCommandLine(TestSuite_t testSuite) */ void TestSuite_disableOutputChecking(TestSuite_t testSuite) { - TestCaseContext_disableOutputChecking(testSuite->test_case_context); + TestCaseContext_disableOutputChecking(testSuite->test_case_context); } /* @@ -285,17 +289,18 @@ void TestSuite_disableOutputChecking(TestSuite_t testSuite) */ void TestSuite_enablePostOutputChecking(TestSuite_t testSuite) { - TestCaseContext_enable_post_output_checking(testSuite->test_case_context); + TestCaseContext_enable_post_output_checking(testSuite-> + test_case_context); } void TestSuite_createConsole(TestSuite_t testSuite) { - TestCaseContext_createConsole(testSuite->test_case_context); + TestCaseContext_createConsole(testSuite->test_case_context); } void TestSuite_createNoConsole(TestSuite_t testSuite) { - TestCaseContext_createNoConsole(testSuite->test_case_context); + TestCaseContext_createNoConsole(testSuite->test_case_context); } /* @@ -303,7 +308,7 @@ void TestSuite_createNoConsole(TestSuite_t testSuite) */ void TestSuite_disablePostOutputChecking(TestSuite_t testSuite) { - TestCaseContext_disablePostOutputChecking(testSuite->test_case_context); + TestCaseContext_disablePostOutputChecking(testSuite->test_case_context); } /* @@ -311,18 +316,20 @@ void TestSuite_disablePostOutputChecking(TestSuite_t testSuite) */ void TestSuite_setExpectedExitCode(TestSuite_t testSuite) { - int expectedExitCode = atoi(testSuite->stream->line + 2 + strlen("expect exit code ")); - TestCaseContext_setExpectedExitCode(testSuite->test_case_context,expectedExitCode); + int expectedExitCode = + atoi(testSuite->stream->line + 2 + strlen("expect exit code ")); + TestCaseContext_setExpectedExitCode(testSuite->test_case_context, + expectedExitCode); } void TestSuite_enableExitCodeChecking(TestSuite_t testSuite) { - TestCaseContext_enableExitCodeChecking(testSuite->test_case_context); + TestCaseContext_enableExitCodeChecking(testSuite->test_case_context); } void TestSuite_disableExitCodeChecking(TestSuite_t testSuite) { - TestCaseContext_disableExitCodeChecking(testSuite->test_case_context); + TestCaseContext_disableExitCodeChecking(testSuite->test_case_context); } @@ -331,46 +338,44 @@ void TestSuite_disableExitCodeChecking(TestSuite_t testSuite) */ errno_t TestSuite_export(TestSuite_t testSuite) { - /* TODO trim */ - const char* ptr; - const char* pos; - char __buffer[50] = {0}; - char* line = testSuite->stream->line + strlen("export "); - - line[strlen(line) -1] = '\0'; - - ptr = strchr(line,' '); - pos= ++ptr; - ptr = strchr(line,'='); - strncpy(__buffer,pos,ptr - pos); - if(!SetEnvironmentVariable(__buffer,++ptr)) - { - setErrno(E_EXPORT_FAILED); - Stream_printLine(testSuite->stream,export_failed_line_type); - return getErrno(); - - } - - return E_SUCCESS; + /* TODO trim */ + const char *ptr; + const char *pos; + char __buffer[50] = { 0 }; + char *line = testSuite->stream->line + strlen("export "); + + line[strlen(line) - 1] = '\0'; + + ptr = strchr(line, ' '); + pos = ++ptr; + ptr = strchr(line, '='); + strncpy(__buffer, pos, ptr - pos); + if (!SetEnvironmentVariable(__buffer, ++ptr)) { + setErrno(E_EXPORT_FAILED); + Stream_printLine(testSuite->stream, export_failed_line_type); + return getErrno(); + + } + + return E_SUCCESS; } errno_t TestSuite_unset(TestSuite_t testSuite) { - char line[128] = {0}; - const char* ptr; - strcpy(line,testSuite->stream->line +2); - ptr = strchr(line,' '); - line[strlen(line) -1] = '\0'; - - if(!SetEnvironmentVariable(++ptr,NULL)) - { - - setErrno(E_UNSET_FAILED); - Stream_printLine(testSuite->stream,unset_failed_line_type); - return getErrno(); - } - - return E_SUCCESS; + char line[128] = { 0 }; + const char *ptr; + strcpy(line, testSuite->stream->line + 2); + ptr = strchr(line, ' '); + line[strlen(line) - 1] = '\0'; + + if (!SetEnvironmentVariable(++ptr, NULL)) { + + setErrno(E_UNSET_FAILED); + Stream_printLine(testSuite->stream, unset_failed_line_type); + return getErrno(); + } + + return E_SUCCESS; } /* @@ -378,14 +383,16 @@ errno_t TestSuite_unset(TestSuite_t testSuite) */ errno_t TestSuite_processExpectedChildOutput(TestSuite_t testSuite) { - /* TODO : logic error*/ - if(!TestCaseContext_isOutputCheckingEnabled(testSuite->test_case_context)) - return E_SUCCESS; - - /* TODO : trim */ - TestCaseContext_appendExpectedOutput(testSuite->test_case_context,testSuite->stream->line + 2); - - return E_SUCCESS; + /* TODO : logic error */ + if (!TestCaseContext_isOutputCheckingEnabled + (testSuite->test_case_context)) + return E_SUCCESS; + + /* TODO : trim */ + TestCaseContext_appendExpectedOutput(testSuite->test_case_context, + testSuite->stream->line + 2); + + return E_SUCCESS; } /* @@ -393,10 +400,11 @@ errno_t TestSuite_processExpectedChildOutput(TestSuite_t testSuite) */ errno_t TestSuite_processChildInput(TestSuite_t testSuite) { - /* TODO : trim */ - TestCaseContext_appendChildInput(testSuite->test_case_context,testSuite->stream->line + 2); + /* TODO : trim */ + TestCaseContext_appendChildInput(testSuite->test_case_context, + testSuite->stream->line + 2); - return E_SUCCESS; + return E_SUCCESS; } /* @@ -404,87 +412,79 @@ errno_t TestSuite_processChildInput(TestSuite_t testSuite) */ void TestSuite_free(TestSuite_t testSuite) { - ThreadEntry_t entry; - unsigned long count; - unsigned long i; - DWORD dwWaitResult; - bool steel_running; - bool last_async_process_error = false; - DWORD ExitCode = 0; - errno_t e = getErrno(); - - if(NULL == testSuite) - return; - - count = ThreadDynarray_getCount(testSuite->threads); - - /* Wait for all asynchrone process */ - if(NULL != testSuite->threads && count) - { - while(true) - { - steel_running = false; - - for(i = 0;i < count ; i++) - { - entry = ThreadDynarray_at(testSuite->threads,i); - - GetExitCodeThread(entry->hThread,&ExitCode); - - if(STILL_ACTIVE == ExitCode) - { - Sleep(0); - steel_running = true; - } - } - - if(!steel_running) - break; + ThreadEntry_t entry; + unsigned long count; + unsigned long i; + DWORD dwWaitResult; + bool steel_running; + bool last_async_process_error = false; + DWORD ExitCode = 0; + errno_t e = getErrno(); + + if (NULL == testSuite) + return; + + count = ThreadDynarray_getCount(testSuite->threads); + + /* Wait for all asynchrone process */ + if (NULL != testSuite->threads && count) { + while (true) { + steel_running = false; + + for (i = 0; i < count; i++) { + entry = ThreadDynarray_at(testSuite->threads, i); + + GetExitCodeThread(entry->hThread, &ExitCode); + + if (STILL_ACTIVE == ExitCode) { + Sleep(0); + steel_running = true; } + } + + if (!steel_running) + break; + } - for(i = 0;i threads,i); - - if(entry->context->pi.hProcess) - { - dwWaitResult=WaitForSingleObject(entry->hThread,INFINITE); - - if((WAIT_FAILED == dwWaitResult)) - TerminateThread(entry->hThread,0); - else - CloseHandle(entry->hThread); - } - - /*if(((E_SUCCESS == e) || (E_EXIT_CODE_DONT_MATCH == e) || (E_OUTPUT_DONT_MATCH == e)) && !last_async_process_error) - {*/ - /* Child output and exit code checking */ - if(TestSuite_iSPostOutputCheckingEnabled(entry->context)) - { - if(E_SUCCESS != TestSuite_checkChildOutput(entry->context)) - last_async_process_error = true; - } - - if(TestSuite_iSExitCodeCheckingEnabled(entry->context)) - { - if(E_SUCCESS != TestSuite_checkChildExitCode(entry->context)) - last_async_process_error = true; - } - } - - TestCaseContext_free(entry->context); - /*}*/ - - ThreadDynarray_destroy(testSuite->threads); + for (i = 0; i < count; i++) { + entry = ThreadDynarray_at(testSuite->threads, i); + + if (entry->context->pi.hProcess) { + dwWaitResult = WaitForSingleObject(entry->hThread, INFINITE); + + if ((WAIT_FAILED == dwWaitResult)) + TerminateThread(entry->hThread, 0); + else + CloseHandle(entry->hThread); + } + + /*if(((E_SUCCESS == e) || (E_EXIT_CODE_DONT_MATCH == e) || (E_OUTPUT_DONT_MATCH == e)) && !last_async_process_error) + { */ + /* Child output and exit code checking */ + if (TestSuite_iSPostOutputCheckingEnabled(entry->context)) { + if (E_SUCCESS != TestSuite_checkChildOutput(entry->context)) + last_async_process_error = true; + } + + if (TestSuite_iSExitCodeCheckingEnabled(entry->context)) { + if (E_SUCCESS != TestSuite_checkChildExitCode(entry->context)) + last_async_process_error = true; + } } - if(NULL != testSuite->test_case_context) - TestCaseContext_free(testSuite->test_case_context); - - if(NULL != testSuite->stream) - Stream_free(testSuite->stream); - - free(testSuite); + TestCaseContext_free(entry->context); + /*} */ + + ThreadDynarray_destroy(testSuite->threads); + } + + if (NULL != testSuite->test_case_context) + TestCaseContext_free(testSuite->test_case_context); + + if (NULL != testSuite->stream) + Stream_free(testSuite->stream); + + free(testSuite); } /* @@ -492,114 +492,114 @@ void TestSuite_free(TestSuite_t testSuite) */ errno_t TestSuite_checkChildOutput(TestCaseContext_t context) { - bool are_equals = false; - char str[256] = {0}; - - - if (context->expectedOutputBuffer->size==0 && context->outputBuffer->size==0) - return E_SUCCESS; - - Buffer_chomp(context->outputBuffer); - Buffer_chomp(context->expectedOutputBuffer); - - - if (context->outputBuffer->size != context->expectedOutputBuffer->size || strcmp(context->outputBuffer->data, context->expectedOutputBuffer->data)) - { - strcpy(str," \n"); - TestSuite_print(str); - - } - else - { - are_equals = true; - strcpy(str," \n"); - TestSuite_print(str); - - - } - - memset(str,0,256); - - if(context->expectedOutputBuffer->size) - { - sprintf(str," SIZE (%4d) DATA (%s)\n",context->expectedOutputBuffer->size,context->expectedOutputBuffer->data); - TestSuite_print(str); - } - else - { - scanf(str," SIZE (%4d) DATA (%s)\n",context->expectedOutputBuffer->size,"empty"); - TestSuite_print(str); - } - - memset(str,0,256); - - if(context->outputBuffer->size) - { - sprintf(str," SIZE (%4d) DATA (%s)\n",context->outputBuffer->size,context->outputBuffer->data); - TestSuite_print(str); - } - else - { - sprintf(str," SIZE (%4d) DATA (%s)\n",context->outputBuffer->size,"empty"); - TestSuite_print(str); - } - - Buffer_clear(context->expectedOutputBuffer); - Buffer_clear(context->outputBuffer); - - if(!are_equals) - { - setErrno(E_OUTPUT_DONT_MATCH); - return getErrno(); - } - - return E_SUCCESS; + bool are_equals = false; + char str[256] = { 0 }; + + + if (context->expectedOutputBuffer->size == 0 + && context->outputBuffer->size == 0) + return E_SUCCESS; + + Buffer_chomp(context->outputBuffer); + Buffer_chomp(context->expectedOutputBuffer); + + + if (context->outputBuffer->size != context->expectedOutputBuffer->size + || strcmp(context->outputBuffer->data, + context->expectedOutputBuffer->data)) { + strcpy(str, " \n"); + TestSuite_print(str); + + } else { + are_equals = true; + strcpy(str, " \n"); + TestSuite_print(str); + + + } + + memset(str, 0, 256); + + if (context->expectedOutputBuffer->size) { + sprintf(str, + " SIZE (%4d) DATA (%s)\n", + context->expectedOutputBuffer->size, + context->expectedOutputBuffer->data); + TestSuite_print(str); + } else { + scanf(str, + " SIZE (%4d) DATA (%s)\n", + context->expectedOutputBuffer->size, "empty"); + TestSuite_print(str); + } + + memset(str, 0, 256); + + if (context->outputBuffer->size) { + sprintf(str, + " SIZE (%4d) DATA (%s)\n", + context->outputBuffer->size, context->outputBuffer->data); + TestSuite_print(str); + } else { + sprintf(str, + " SIZE (%4d) DATA (%s)\n", + context->outputBuffer->size, "empty"); + TestSuite_print(str); + } + + Buffer_clear(context->expectedOutputBuffer); + Buffer_clear(context->outputBuffer); + + if (!are_equals) { + setErrno(E_OUTPUT_DONT_MATCH); + return getErrno(); + } + + return E_SUCCESS; } /* * Check the child process exit code. - */ + */ errno_t TestSuite_checkChildExitCode(TestCaseContext_t context) { - bool __success = false; - char str[256] = {0}; - - sprintf(str," %s %3ld\n",context->name,context->exitCode); - TestSuite_print(str); - - memset(str,0,256); - - /* if a expected exit code was signaled, compare it with the real. */ - if(context->expectedExitCode != INVALID_EXIT_CODE) - { - if(context->expectedExitCode != context->exitCode ) - { - - TestSuite_print("\n"); - } - else - { - __success = true; - TestSuite_print("\n"); - } - sprintf(str," (%3d)\n",context->expectedExitCode); - TestSuite_print(str); - - memset(str,0,256); - - sprintf(str," (%3d)\n",context->exitCode); - TestSuite_print(str); - - context->expectedExitCode = INVALID_EXIT_CODE; - } - - if(!__success) - { - setErrno(E_EXIT_CODE_DONT_MATCH); - return getErrno(); - } + bool __success = false; + char str[256] = { 0 }; + + sprintf(str, " %s %3ld\n", + context->name, context->exitCode); + TestSuite_print(str); + + memset(str, 0, 256); - return E_SUCCESS; + /* if a expected exit code was signaled, compare it with the real. */ + if (context->expectedExitCode != INVALID_EXIT_CODE) { + if (context->expectedExitCode != context->exitCode) { + + TestSuite_print("\n"); + } else { + __success = true; + TestSuite_print("\n"); + } + sprintf(str, " (%3d)\n", + context->expectedExitCode); + TestSuite_print(str); + + memset(str, 0, 256); + + sprintf(str, " (%3d)\n", + context->exitCode); + TestSuite_print(str); + + context->expectedExitCode = INVALID_EXIT_CODE; + } + + if (!__success) { + setErrno(E_EXIT_CODE_DONT_MATCH); + return getErrno(); + } + + return E_SUCCESS; } /* @@ -607,453 +607,474 @@ errno_t TestSuite_checkChildExitCode(TestCaseContext_t context) */ void TestSuite_terminate(TestSuite_t testSuite) { - TestCaseContext_t context = testSuite->test_case_context; - - /* cleanup the child_input_stream/output buffers. */ - if(NULL != context->inputBuffer) - Buffer_free(context->inputBuffer); - - if(NULL != context->outputBuffer) - Buffer_free(context->outputBuffer); - - if(NULL != context->expectedOutputBuffer) - Buffer_free(context->expectedOutputBuffer); - - /* close the file stream. */ - if(NULL != testSuite->stream) - Stream_free(testSuite->stream); - - + TestCaseContext_t context = testSuite->test_case_context; + + /* cleanup the child_input_stream/output buffers. */ + if (NULL != context->inputBuffer) + Buffer_free(context->inputBuffer); + + if (NULL != context->outputBuffer) + Buffer_free(context->outputBuffer); + + if (NULL != context->expectedOutputBuffer) + Buffer_free(context->expectedOutputBuffer); + + /* close the file stream. */ + if (NULL != testSuite->stream) + Stream_free(testSuite->stream); + + } /* * Print message */ -void TestSuite_print(const char* str) +void TestSuite_print(const char *str) { - char* t = (char*)calloc(1,20); - - __time(t); + char *t = (char *) calloc(1, 20); - EnterCriticalSection(&cs); - printf("%s %s",t,str); - LeaveCriticalSection(&cs); + __time(t); - free(t); + EnterCriticalSection(&cs); + printf("%s %s", t, str); + LeaveCriticalSection(&cs); + + free(t); } -unsigned long WINAPI TestSuite_asyncReadChildOutput(void* param) +unsigned long WINAPI TestSuite_asyncReadChildOutput(void *param) { - char str[1024] = {0}; - char __buffer[1024] = {0}; - + char str[1024] = { 0 }; + char __buffer[1024] = { 0 }; + DWORD nBytesRead; DWORD nCharsWritten; - TestCaseContext_t context = (TestCaseContext_t)param; + TestCaseContext_t context = (TestCaseContext_t) param; HANDLE hPipeRead = context->hOutputRead; - - while (context->runThread) - { - if (!ReadFile(hPipeRead,str,sizeof(str),&nBytesRead,NULL) || !nBytesRead){ - if (GetLastError() == ERROR_BROKEN_PIPE){ - break; - } - else{ - /* TODO */ - context->threadExitCode = 1; - exit(1); - } - } - - if(nBytesRead){ - if(context->isOutputCheckingEnabled){ - if(!Buffer_empty(context->outputBuffer)) - Buffer_clear(context->outputBuffer); - TestSuite_print(str); + while (context->runThread) { + if (!ReadFile(hPipeRead, str, sizeof(str), &nBytesRead, NULL) + || !nBytesRead) { + if (GetLastError() == ERROR_BROKEN_PIPE) { + break; + } else { + /* TODO */ + context->threadExitCode = 1; + exit(1); + } + } + + if (nBytesRead) { + if (context->isOutputCheckingEnabled) { + if (!Buffer_empty(context->outputBuffer)) + Buffer_clear(context->outputBuffer); + + TestSuite_print(str); + + Buffer_append(context->outputBuffer, str); + } - Buffer_append(context->outputBuffer,str); - } - - memset(str,0,1024); - memset(__buffer,0,1024); + memset(str, 0, 1024); + memset(__buffer, 0, 1024); } - + } - context->threadExitCode = 0; - return 0; + context->threadExitCode = 0; + return 0; } errno_t TestSuite_runAsyncTestCase(TestSuite_t testSuite) { - DWORD ThreadId; - s_ThreadEntry_t entry; - /* = (ThreadEntry_t)calloc(1,sizeof(s_ThreadEntry_t));*/ - - TestCaseContext_t context = testSuite->test_case_context; - memset(&entry,0,sizeof(s_ThreadEntry_t)); - entry.context = TestCaseContext_new(); - - Buffer_append(entry.context->inputBuffer,context->inputBuffer->data); - Buffer_append(entry.context->outputBuffer,context->outputBuffer->data); - Buffer_append(entry.context->expectedOutputBuffer,context->expectedOutputBuffer->data); - Buffer_append(entry.context->commandLineBuffer,context->commandLineBuffer->data); - entry.context->name = strdup(context->name); - entry.context->timeoutValue = context->timeoutValue; - entry.context->isOutputCheckingEnabled = context->isOutputCheckingEnabled; - entry.context->isPostOutputCheckingEnabled = context->isPostOutputCheckingEnabled; - entry.context->expectedExitCode = context->expectedExitCode; - entry.context->createConsole = context->createConsole; - entry.context->exitCodeCheckingEnabled = context->exitCodeCheckingEnabled; - entry.context->hConsole = context->hConsole; - Buffer_clear(context->inputBuffer); - Buffer_clear(context->outputBuffer); - Buffer_clear(context->expectedOutputBuffer); - memset(&(entry.context->pi),0,sizeof(PROCESS_INFORMATION)); - entry.context->runThread = true; - - entry.hThread = CreateThread(NULL,0,TestSuite_runSyncTestCase,(LPVOID)entry.context,CREATE_SUSPENDED,&ThreadId); - entry.threadId = ThreadId; - ThreadDynarray_pushBack(testSuite->threads,&entry); - ResumeThread(entry.hThread); - Sleep(0); - setErrno(E_SUCCESS); - - return getErrno(); + DWORD ThreadId; + s_ThreadEntry_t entry; + /* = (ThreadEntry_t)calloc(1,sizeof(s_ThreadEntry_t)); */ + + TestCaseContext_t context = testSuite->test_case_context; + memset(&entry, 0, sizeof(s_ThreadEntry_t)); + entry.context = TestCaseContext_new(); + + Buffer_append(entry.context->inputBuffer, context->inputBuffer->data); + Buffer_append(entry.context->outputBuffer, context->outputBuffer->data); + Buffer_append(entry.context->expectedOutputBuffer, + context->expectedOutputBuffer->data); + Buffer_append(entry.context->commandLineBuffer, + context->commandLineBuffer->data); + entry.context->name = strdup(context->name); + entry.context->timeoutValue = context->timeoutValue; + entry.context->isOutputCheckingEnabled = + context->isOutputCheckingEnabled; + entry.context->isPostOutputCheckingEnabled = + context->isPostOutputCheckingEnabled; + entry.context->expectedExitCode = context->expectedExitCode; + entry.context->createConsole = context->createConsole; + entry.context->exitCodeCheckingEnabled = + context->exitCodeCheckingEnabled; + entry.context->hConsole = context->hConsole; + Buffer_clear(context->inputBuffer); + Buffer_clear(context->outputBuffer); + Buffer_clear(context->expectedOutputBuffer); + memset(&(entry.context->pi), 0, sizeof(PROCESS_INFORMATION)); + entry.context->runThread = true; + + entry.hThread = + CreateThread(NULL, 0, TestSuite_runSyncTestCase, + (LPVOID) entry.context, CREATE_SUSPENDED, &ThreadId); + entry.threadId = ThreadId; + ThreadDynarray_pushBack(testSuite->threads, &entry); + ResumeThread(entry.hThread); + Sleep(0); + setErrno(E_SUCCESS); + + return getErrno(); } -unsigned long WINAPI TestSuite_runSyncTestCase( void* param) +unsigned long WINAPI TestSuite_runSyncTestCase(void *param) { - STARTUPINFO si = {0}; - SECURITY_ATTRIBUTES sa = {0}; - DWORD dwWaitResult = 0; - DWORD dwExitCode = 0; - DWORD ThreadId; - DWORD nBytes = 0; - DWORD dwCreationMode = CREATE_NO_WINDOW; - char cmdLine[4098] = {0}; - - TestCaseContext_t context = (TestCaseContext_t)param; - context->started = true; - - - sa.nLength = sizeof(SECURITY_ATTRIBUTES); - sa.lpSecurityDescriptor = NULL; - /* The pipe handes can be inherited by the child. */ - sa.bInheritHandle = TRUE; - - /* Create a write pipe handle for the child std output */ - if(!CreatePipe(&(context->hChildStdoutReadTmp),&(context->hChildStdOutWrite),&sa,0)) - { - setErrno(E_CANNOT_CREATE_CHILD_STDOUT_READ_HANDLE); - return getErrno(); - } - - /* - * Create a duplicate of the output write handle for the std error - * write handle. This is necessary in case the child application closes - * one of its std output handles. - */ - if(!DuplicateHandle(GetCurrentProcess(),(context->hChildStdOutWrite),GetCurrentProcess(),&(context->hChildStderr),0,TRUE,DUPLICATE_SAME_ACCESS)) - { - setErrno(E_CANNOT_CREATE_CHILD_STDERR_READ_HANDLE); - return getErrno(); - } - - /* Create a read pipe handle for the child std input */ - if(!CreatePipe(&(context->hChildStdInRead),&(context->hChildStdinWriteTmp),&sa,0)) - { - setErrno(E_CANNOT_CREATE_CHILD_STDIN_WRITE_HANDLE); - return getErrno(); - } - - - /* Create new output read handle and the input write handle use by - * the parent process to communicate with his child. Set the Properties - * to FALSE. Otherwise, the child inherits the properties and, as a - * result, non-closeable handles to the pipes are created. - */ - - /* Read handle for read operations on the child std output. */ - if(!DuplicateHandle(GetCurrentProcess(),(context->hChildStdoutReadTmp),GetCurrentProcess(),&(context->hOutputRead),0,FALSE, DUPLICATE_SAME_ACCESS)) - { - setErrno(E_CANNOT_CREATE_STDOUT_READ_HANDLE); - return getErrno(); - } - - - /* Write handle for write operations on the child std input. */ - if(!DuplicateHandle(GetCurrentProcess(),(context->hChildStdinWriteTmp),GetCurrentProcess(),&(context->hInputWrite), 0,FALSE,DUPLICATE_SAME_ACCESS)) - { - setErrno(E_CANNOT_CREATE_STDIN_WRITE_HANDLE); - return getErrno(); - } - - - /* Close inheritable copies of the handles you do not want to be inherited. */ - if(!CloseHandle((context->hChildStdoutReadTmp))) - { - setErrno(E_CANNOT_CLOSE_CHILD_STDIN_TEMPORY_HANDLE); - return getErrno(); - } + STARTUPINFO si = { 0 }; + SECURITY_ATTRIBUTES sa = { 0 }; + DWORD dwWaitResult = 0; + DWORD dwExitCode = 0; + DWORD ThreadId; + DWORD nBytes = 0; + DWORD dwCreationMode = CREATE_NO_WINDOW; + char cmdLine[4098] = { 0 }; + + TestCaseContext_t context = (TestCaseContext_t) param; + context->started = true; + + + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.lpSecurityDescriptor = NULL; + /* The pipe handes can be inherited by the child. */ + sa.bInheritHandle = TRUE; + + /* Create a write pipe handle for the child std output */ + if (!CreatePipe + (&(context->hChildStdoutReadTmp), &(context->hChildStdOutWrite), &sa, + 0)) { + setErrno(E_CANNOT_CREATE_CHILD_STDOUT_READ_HANDLE); + return getErrno(); + } - context->hChildStdoutReadTmp = NULL; - - if(!CloseHandle((context->hChildStdinWriteTmp))) - { - setErrno(E_CANNOT_CLOSE_CHILD_STDOUT_TEMPORY_HANDLE); - return getErrno(); - } - - - context->hChildStdinWriteTmp = NULL; - - si.cb = sizeof(STARTUPINFO); - /* Set the child std handles. */ - si.dwFlags = STARTF_USESTDHANDLES; - si.hStdOutput = context->hChildStdOutWrite; - si.hStdInput = context->hChildStdInRead; - si.hStdError = context->hChildStderr; - - if(context->createConsole) - dwCreationMode = CREATE_NEW_CONSOLE; - - if(!Buffer_empty(context->commandLineBuffer)){ - Buffer_chomp(context->commandLineBuffer); - sprintf(cmdLine,"%s %s",context->name,context->commandLineBuffer->data); - } - else - strcpy(cmdLine,context->name); + /* + * Create a duplicate of the output write handle for the std error + * write handle. This is necessary in case the child application closes + * one of its std output handles. + */ + if (!DuplicateHandle + (GetCurrentProcess(), (context->hChildStdOutWrite), + GetCurrentProcess(), &(context->hChildStderr), 0, TRUE, + DUPLICATE_SAME_ACCESS)) { + setErrno(E_CANNOT_CREATE_CHILD_STDERR_READ_HANDLE); + return getErrno(); + } + /* Create a read pipe handle for the child std input */ + if (!CreatePipe + (&(context->hChildStdInRead), &(context->hChildStdinWriteTmp), &sa, + 0)) { + setErrno(E_CANNOT_CREATE_CHILD_STDIN_WRITE_HANDLE); + return getErrno(); + } - /* Create the child process. */ - if(!CreateProcess(NULL,cmdLine,NULL,NULL,TRUE,dwCreationMode,NULL,NULL,&si,&(context->pi))){ - setErrno(E_CANNOT_CREATE_CHILD_PROCESS); - return getErrno(); - } - - if(!CloseHandle(context->pi.hThread)){ - setErrno(E_CANNOT_CLOSE_PROCESS_THREAD_HANDLE); - return getErrno(); - } - - - context->pi.hThread = NULL; - - /* close unnessary pipe handles. */ - if(!CloseHandle(context->hChildStdOutWrite)){ - setErrno(E_CANNOT_CLOSE_CHILD_STDOUT_HANDLE); - return getErrno(); - } - - context->hChildStdOutWrite = NULL; - - if(!CloseHandle(context->hChildStdInRead)){ - setErrno(E_CANNOT_CLOSE_CHILD_STDIN_HANDLE); - return getErrno(); - } - context->hChildStdInRead = NULL; + /* Create new output read handle and the input write handle use by + * the parent process to communicate with his child. Set the Properties + * to FALSE. Otherwise, the child inherits the properties and, as a + * result, non-closeable handles to the pipes are created. + */ - if(!CloseHandle(context->hChildStderr)){ - setErrno(E_CANNOT_CLOSE_CHILD_STDERR_HANDLE); - return getErrno(); - } + /* Read handle for read operations on the child std output. */ + if (!DuplicateHandle + (GetCurrentProcess(), (context->hChildStdoutReadTmp), + GetCurrentProcess(), &(context->hOutputRead), 0, FALSE, + DUPLICATE_SAME_ACCESS)) { + setErrno(E_CANNOT_CREATE_STDOUT_READ_HANDLE); + return getErrno(); + } - context->hChildStderr = NULL; - if(!Buffer_empty(context->inputBuffer)){ - if(!WriteFile(context->hInputWrite,context->inputBuffer->data,context->inputBuffer->size,&nBytes,NULL)){ - setErrno(E_CANNOT_WRITE_ON_CHILD_STDIN); - return getErrno(); - } - } - - context->hThread = CreateThread(&sa,0,TestSuite_asyncReadChildOutput,(LPVOID)context,0,&ThreadId); - Sleep(0); - - if(NULL == context->hThread){ - setErrno(E_CANNOT_CREATE_READ_CHILD_OUTPUT_THREAD); - return getErrno(); - } - + /* Write handle for write operations on the child std input. */ + if (!DuplicateHandle + (GetCurrentProcess(), (context->hChildStdinWriteTmp), + GetCurrentProcess(), &(context->hInputWrite), 0, FALSE, + DUPLICATE_SAME_ACCESS)) { + setErrno(E_CANNOT_CREATE_STDIN_WRITE_HANDLE); + return getErrno(); + } - dwWaitResult = WaitForSingleObject(context->pi.hProcess,context->timeoutValue); - if(WAIT_FAILED == dwWaitResult) - { - TerminateProcess(context->pi.hProcess,0); - context->pi.hProcess = NULL; - context->runThread = false; + /* Close inheritable copies of the handles you do not want to be inherited. */ + if (!CloseHandle((context->hChildStdoutReadTmp))) { + setErrno(E_CANNOT_CLOSE_CHILD_STDIN_TEMPORY_HANDLE); + return getErrno(); + } - if(WAIT_FAILED == WaitForSingleObject(context->hThread,INFINITE)){ - setErrno(E_WAIT_THREAD_FAILED); - return getErrno(); - } + context->hChildStdoutReadTmp = NULL; - if(!CloseHandle(context->hThread)){ - setErrno(E_CANNOT_CLOSE_THREAD_HANDLE); - return getErrno(); - } + if (!CloseHandle((context->hChildStdinWriteTmp))) { + setErrno(E_CANNOT_CLOSE_CHILD_STDOUT_TEMPORY_HANDLE); + return getErrno(); + } - context->hThread = NULL; - if(!CloseHandle(context->hOutputRead)){ - setErrno(E_CANNOT_CLOSE_READ_HANDLE); - return getErrno(); - } + context->hChildStdinWriteTmp = NULL; - context->hOutputRead = NULL; + si.cb = sizeof(STARTUPINFO); + /* Set the child std handles. */ + si.dwFlags = STARTF_USESTDHANDLES; + si.hStdOutput = context->hChildStdOutWrite; + si.hStdInput = context->hChildStdInRead; + si.hStdError = context->hChildStderr; - if(!CloseHandle(context->hInputWrite)){ - setErrno(E_CANNOT_CLOSE_WRITE_HANDLE); - return getErrno(); - } + if (context->createConsole) + dwCreationMode = CREATE_NEW_CONSOLE; - context->hInputWrite = NULL; - setErrno(E_WAIT_FAILURE); - return getErrno(); - } + if (!Buffer_empty(context->commandLineBuffer)) { + Buffer_chomp(context->commandLineBuffer); + sprintf(cmdLine, "%s %s", context->name, + context->commandLineBuffer->data); + } else + strcpy(cmdLine, context->name); - if(WAIT_TIMEOUT == dwWaitResult) - { - TerminateProcess(context->pi.hProcess,0); - context->pi.hProcess = NULL; - context->runThread = false; - if(WAIT_FAILED == WaitForSingleObject(context->hThread,INFINITE)){ - setErrno(E_WAIT_THREAD_FAILED); - return getErrno(); - } + /* Create the child process. */ + if (!CreateProcess + (NULL, cmdLine, NULL, NULL, TRUE, dwCreationMode, NULL, NULL, &si, + &(context->pi))) { + setErrno(E_CANNOT_CREATE_CHILD_PROCESS); + return getErrno(); + } + + if (!CloseHandle(context->pi.hThread)) { + setErrno(E_CANNOT_CLOSE_PROCESS_THREAD_HANDLE); + return getErrno(); + } + - if(!CloseHandle(context->hThread)){ - setErrno(E_CANNOT_CLOSE_THREAD_HANDLE); - return getErrno(); - } + context->pi.hThread = NULL; + + /* close unnessary pipe handles. */ + if (!CloseHandle(context->hChildStdOutWrite)) { + setErrno(E_CANNOT_CLOSE_CHILD_STDOUT_HANDLE); + return getErrno(); + } - context->hThread = NULL; + context->hChildStdOutWrite = NULL; - if(!CloseHandle(context->hOutputRead)){ - setErrno(E_CANNOT_CLOSE_READ_HANDLE); - return getErrno(); - } + if (!CloseHandle(context->hChildStdInRead)) { + setErrno(E_CANNOT_CLOSE_CHILD_STDIN_HANDLE); + return getErrno(); + } + context->hChildStdInRead = NULL; - context->hOutputRead = NULL; + if (!CloseHandle(context->hChildStderr)) { + setErrno(E_CANNOT_CLOSE_CHILD_STDERR_HANDLE); + return getErrno(); + } - if(!CloseHandle(context->hInputWrite)){ - setErrno(E_CANNOT_CLOSE_WRITE_HANDLE); - return getErrno(); - } + context->hChildStderr = NULL; - context->hInputWrite = NULL; - setErrno(E_WAIT_TIMEOUT); - return getErrno(); + if (!Buffer_empty(context->inputBuffer)) { + if (!WriteFile + (context->hInputWrite, context->inputBuffer->data, + context->inputBuffer->size, &nBytes, NULL)) { + setErrno(E_CANNOT_WRITE_ON_CHILD_STDIN); + return getErrno(); } + } + + context->hThread = + CreateThread(&sa, 0, TestSuite_asyncReadChildOutput, + (LPVOID) context, 0, &ThreadId); + Sleep(0); + + if (NULL == context->hThread) { + setErrno(E_CANNOT_CREATE_READ_CHILD_OUTPUT_THREAD); + return getErrno(); + } + - /* all is ok . */ + dwWaitResult = + WaitForSingleObject(context->pi.hProcess, context->timeoutValue); + if (WAIT_FAILED == dwWaitResult) { + TerminateProcess(context->pi.hProcess, 0); + context->pi.hProcess = NULL; context->runThread = false; - if(WAIT_FAILED == WaitForSingleObject(context->hThread,INFINITE)){ - setErrno(E_WAIT_THREAD_FAILED); - return getErrno(); + if (WAIT_FAILED == WaitForSingleObject(context->hThread, INFINITE)) { + setErrno(E_WAIT_THREAD_FAILED); + return getErrno(); } - if(!CloseHandle(context->hThread)){ - setErrno(E_CANNOT_CLOSE_THREAD_HANDLE); - return getErrno(); + if (!CloseHandle(context->hThread)) { + setErrno(E_CANNOT_CLOSE_THREAD_HANDLE); + return getErrno(); } context->hThread = NULL; - if(!CloseHandle(context->hOutputRead)){ - setErrno(E_CANNOT_CLOSE_READ_HANDLE); - return getErrno(); + if (!CloseHandle(context->hOutputRead)) { + setErrno(E_CANNOT_CLOSE_READ_HANDLE); + return getErrno(); } context->hOutputRead = NULL; - if(!CloseHandle(context->hInputWrite)){ - setErrno(E_CANNOT_CLOSE_WRITE_HANDLE); - return getErrno(); + if (!CloseHandle(context->hInputWrite)) { + setErrno(E_CANNOT_CLOSE_WRITE_HANDLE); + return getErrno(); } context->hInputWrite = NULL; - - - /* Get the child exit code before close it. */ - GetExitCodeProcess(context->pi.hProcess,&dwExitCode); - - context->exitCode = (int)dwExitCode; - - if(!CloseHandle(context->pi.hProcess)){ - setErrno(E_CANNOT_CLOSE_PROCESS_HANDLE); - return getErrno(); + setErrno(E_WAIT_FAILURE); + return getErrno(); + } + + if (WAIT_TIMEOUT == dwWaitResult) { + TerminateProcess(context->pi.hProcess, 0); + context->pi.hProcess = NULL; + context->runThread = false; + + if (WAIT_FAILED == WaitForSingleObject(context->hThread, INFINITE)) { + setErrno(E_WAIT_THREAD_FAILED); + return getErrno(); } - context->runThread = true; + if (!CloseHandle(context->hThread)) { + setErrno(E_CANNOT_CLOSE_THREAD_HANDLE); + return getErrno(); + } - if(TestSuite_iSPostOutputCheckingEnabled(context)){ - if (context->expectedOutputBuffer->size !=0 || context->outputBuffer->size !=0){ - Buffer_chomp(context->outputBuffer); - Buffer_chomp(context->expectedOutputBuffer); + context->hThread = NULL; - if (context->outputBuffer->size != context->expectedOutputBuffer->size || strcmp(context->outputBuffer->data, context->expectedOutputBuffer->data)){ - setErrno(E_OUTPUT_DONT_MATCH); - } - } - } + if (!CloseHandle(context->hOutputRead)) { + setErrno(E_CANNOT_CLOSE_READ_HANDLE); + return getErrno(); + } - if(TestSuite_iSExitCodeCheckingEnabled(context)){ - if(context->expectedExitCode != INVALID_EXIT_CODE){ - if(context->expectedExitCode != context->exitCode ){ - setErrno(E_EXIT_CODE_DONT_MATCH); - } - } - } - - context->pi.hProcess = NULL; - return getErrno(); + + context->hOutputRead = NULL; + + if (!CloseHandle(context->hInputWrite)) { + setErrno(E_CANNOT_CLOSE_WRITE_HANDLE); + return getErrno(); + } + + context->hInputWrite = NULL; + setErrno(E_WAIT_TIMEOUT); + return getErrno(); + } + + /* all is ok . */ + + context->runThread = false; + + if (WAIT_FAILED == WaitForSingleObject(context->hThread, INFINITE)) { + setErrno(E_WAIT_THREAD_FAILED); + return getErrno(); + } + + if (!CloseHandle(context->hThread)) { + setErrno(E_CANNOT_CLOSE_THREAD_HANDLE); + return getErrno(); + } + + context->hThread = NULL; + + if (!CloseHandle(context->hOutputRead)) { + setErrno(E_CANNOT_CLOSE_READ_HANDLE); + return getErrno(); + } + + context->hOutputRead = NULL; + + if (!CloseHandle(context->hInputWrite)) { + setErrno(E_CANNOT_CLOSE_WRITE_HANDLE); + return getErrno(); + } + + context->hInputWrite = NULL; + + + /* Get the child exit code before close it. */ + GetExitCodeProcess(context->pi.hProcess, &dwExitCode); + + context->exitCode = (int) dwExitCode; + + if (!CloseHandle(context->pi.hProcess)) { + setErrno(E_CANNOT_CLOSE_PROCESS_HANDLE); + return getErrno(); + } + + context->runThread = true; + + if (TestSuite_iSPostOutputCheckingEnabled(context)) { + if (context->expectedOutputBuffer->size != 0 + || context->outputBuffer->size != 0) { + Buffer_chomp(context->outputBuffer); + Buffer_chomp(context->expectedOutputBuffer); + + if (context->outputBuffer->size != + context->expectedOutputBuffer->size + || strcmp(context->outputBuffer->data, + context->expectedOutputBuffer->data)) { + setErrno(E_OUTPUT_DONT_MATCH); + } + } + } + + if (TestSuite_iSExitCodeCheckingEnabled(context)) { + if (context->expectedExitCode != INVALID_EXIT_CODE) { + if (context->expectedExitCode != context->exitCode) { + setErrno(E_EXIT_CODE_DONT_MATCH); + } + } + } + + context->pi.hProcess = NULL; + return getErrno(); } bool TestSuite_iSPostOutputCheckingEnabled(TestCaseContext_t context) { - if(!context->isPostOutputCheckingEnabled && context->isOutputCheckingEnabled){ - return true; - } + if (!context->isPostOutputCheckingEnabled + && context->isOutputCheckingEnabled) { + return true; + } - return false; + return false; } bool TestSuite_iSExitCodeCheckingEnabled(TestCaseContext_t context) { - return context->exitCodeCheckingEnabled; + return context->exitCodeCheckingEnabled; } errno_t TestSuite_changeDir(TestSuite_t testSuite) { - char* line = testSuite->stream->line + 5; - size_t size = strlen(line); - - while ((line[size-1] == '\n') || (line[size-1] == '\r')){ - line[size-1] = '\0'; - - if(size) - (size)--; - } - - if(!SetCurrentDirectory(line)){ - setErrno(E_CHANGE_DIRECTORY_FAILED); - return E_CHANGE_DIRECTORY_FAILED; - } + char *line = testSuite->stream->line + 5; + size_t size = strlen(line); - Stream_printLine(testSuite->stream,change_directory_line_type); + while ((line[size - 1] == '\n') || (line[size - 1] == '\r')) { + line[size - 1] = '\0'; - return E_SUCCESS; -} + if (size) + (size)--; + } + if (!SetCurrentDirectory(line)) { + setErrno(E_CHANGE_DIRECTORY_FAILED); + return E_CHANGE_DIRECTORY_FAILED; + } + + Stream_printLine(testSuite->stream, change_directory_line_type); + + return E_SUCCESS; +} diff --git a/win32_test_app/src/TThreadDynarray.c b/win32_test_app/src/TThreadDynarray.c index 7c51b40340..73f75437d5 100644 --- a/win32_test_app/src/TThreadDynarray.c +++ b/win32_test_app/src/TThreadDynarray.c @@ -6,21 +6,22 @@ */ ThreadDynarray_t ThreadDynarray_new(unsigned long capacity) { - ThreadDynarray_t ptr = calloc(1,sizeof(s_ThreadDynarray_t)); + ThreadDynarray_t ptr = calloc(1, sizeof(s_ThreadDynarray_t)); - ptr->count = 0; - ptr->capacity = capacity; - - memset(&(ptr->cs),0,sizeof(CRITICAL_SECTION)) ; - InitializeCriticalSection(&(ptr->cs)); - ptr->is_locked = false; + ptr->count = 0; + ptr->capacity = capacity; - if(capacity) - ptr->threads = (ThreadEntry_t)calloc(capacity,sizeof(s_ThreadEntry_t)); - else - ptr->threads = NULL; + memset(&(ptr->cs), 0, sizeof(CRITICAL_SECTION)); + InitializeCriticalSection(&(ptr->cs)); + ptr->is_locked = false; - return ptr; + if (capacity) + ptr->threads = + (ThreadEntry_t) calloc(capacity, sizeof(s_ThreadEntry_t)); + else + ptr->threads = NULL; + + return ptr; } /* @@ -28,45 +29,49 @@ ThreadDynarray_t ThreadDynarray_new(unsigned long capacity) */ void ThreadDynarray_destroy(ThreadDynarray_t ptr) { - ThreadDynarray_clear(ptr); - DeleteCriticalSection(&(ptr->cs)); - free(ptr); - ptr = NULL; + ThreadDynarray_clear(ptr); + DeleteCriticalSection(&(ptr->cs)); + free(ptr); + ptr = NULL; } /* * Returns an const pointer to entry pointed to by index. */ -ThreadEntry_t const ThreadDynarray_at(ThreadDynarray_t ptr, unsigned long index) +ThreadEntry_t const ThreadDynarray_at(ThreadDynarray_t ptr, + unsigned long index) { - ThreadEntry_t __entry; - ThreadDynarray_lock(ptr); - __entry = &(ptr->threads)[index]; - ThreadDynarray_unlock(ptr); - return __entry; + ThreadEntry_t __entry; + ThreadDynarray_lock(ptr); + __entry = &(ptr->threads)[index]; + ThreadDynarray_unlock(ptr); + return __entry; } /* * Fill the content of the entry addressed by __entry with the content * of the entry pointed to by index. */ -void ThreadDynarray_get(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t const __entry) +void ThreadDynarray_get(ThreadDynarray_t ptr, unsigned long index, + ThreadEntry_t const __entry) { - ThreadDynarray_lock(ptr); - ::memcpy(__entry,ThreadDynarray_at(ptr,index),sizeof(s_ThreadEntry_t)); - ThreadDynarray_unlock(ptr); + ThreadDynarray_lock(ptr); + ::memcpy(__entry, ThreadDynarray_at(ptr, index), + sizeof(s_ThreadEntry_t)); + ThreadDynarray_unlock(ptr); } /* * Fill the content of the entry pointed to by index with the content of * the entry addressed by __entry. */ -void ThreadDynarray_set(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t const __entry) +void ThreadDynarray_set(ThreadDynarray_t ptr, unsigned long index, + ThreadEntry_t const __entry) { - ThreadDynarray_lock(ptr); - memcpy(ThreadDynarray_at(ptr,index),__entry,sizeof(s_ThreadEntry_t)); - ThreadDynarray_unlock(ptr); + ThreadDynarray_lock(ptr); + memcpy(ThreadDynarray_at(ptr, index), __entry, sizeof(s_ThreadEntry_t)); + ThreadDynarray_unlock(ptr); } /* @@ -74,11 +79,11 @@ void ThreadDynarray_set(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t */ ThreadEntry_t const ThreadDynarray_getFront(ThreadDynarray_t ptr) { - ThreadEntry_t __entry; - ThreadDynarray_lock(ptr); - __entry = ThreadDynarray_at(ptr,0); - ThreadDynarray_unlock(ptr); - return __entry; + ThreadEntry_t __entry; + ThreadDynarray_lock(ptr); + __entry = ThreadDynarray_at(ptr, 0); + ThreadDynarray_unlock(ptr); + return __entry; } /* @@ -86,82 +91,87 @@ ThreadEntry_t const ThreadDynarray_getFront(ThreadDynarray_t ptr) */ ThreadEntry_t const ThreadDynarray_getBack(ThreadDynarray_t ptr) { - ThreadEntry_t __entry; - ThreadDynarray_lock(ptr); - __entry = ThreadDynarray_at(ptr,ptr->count - 1);; - ThreadDynarray_unlock(ptr); - return __entry; + ThreadEntry_t __entry; + ThreadDynarray_lock(ptr); + __entry = ThreadDynarray_at(ptr, ptr->count - 1);; + ThreadDynarray_unlock(ptr); + return __entry; } /* * Inserts a copy of __entry at the front */ -void ThreadDynarray_pushFront(ThreadDynarray_t ptr, ThreadEntry_t const __entry) +void ThreadDynarray_pushFront(ThreadDynarray_t ptr, + ThreadEntry_t const __entry) { - ThreadDynarray_lock(ptr); + ThreadDynarray_lock(ptr); + + if (!ThreadDynarray_getCapacityAvailable(ptr)) + ThreadDynarray_resize(ptr); - if(!ThreadDynarray_getCapacityAvailable(ptr)) - ThreadDynarray_resize(ptr); - - ptr->count++; - ThreadDynarray_move(ptr,1,ThreadDynarray_getLowerBound(ptr),ThreadDynarray_getUpperBound(ptr)); - ThreadDynarray_set(ptr,ThreadDynarray_getLowerBound(ptr),__entry); + ptr->count++; + ThreadDynarray_move(ptr, 1, ThreadDynarray_getLowerBound(ptr), + ThreadDynarray_getUpperBound(ptr)); + ThreadDynarray_set(ptr, ThreadDynarray_getLowerBound(ptr), __entry); - ThreadDynarray_unlock(ptr); + ThreadDynarray_unlock(ptr); } /* * Appends a copy of __entry to the end. */ -void ThreadDynarray_pushBack(ThreadDynarray_t ptr, ThreadEntry_t const __entry) +void ThreadDynarray_pushBack(ThreadDynarray_t ptr, + ThreadEntry_t const __entry) { - ThreadDynarray_lock(ptr); + ThreadDynarray_lock(ptr); + + if (!ThreadDynarray_getCapacityAvailable(ptr)) + ThreadDynarray_resize(ptr); - if(!ThreadDynarray_getCapacityAvailable(ptr)) - ThreadDynarray_resize(ptr); - - ptr->count++; - ThreadDynarray_set(ptr,ThreadDynarray_getUpperBound(ptr),__entry); + ptr->count++; + ThreadDynarray_set(ptr, ThreadDynarray_getUpperBound(ptr), __entry); - ThreadDynarray_unlock(ptr); + ThreadDynarray_unlock(ptr); } /* * Inserts __entry at the position pointed to by index. */ -void ThreadDynarray_insert(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t const __entry) +void ThreadDynarray_insert(ThreadDynarray_t ptr, unsigned long index, + ThreadEntry_t const __entry) { - ThreadDynarray_lock(ptr); + ThreadDynarray_lock(ptr); - if(!ThreadDynarray_getCapacityAvailable(ptr)) - ThreadDynarray_resize(ptr); - - ThreadDynarray_move(ptr,index + 1,index,ptr->count - index); - ptr->count++; - ThreadDynarray_set(ptr,index,__entry); + if (!ThreadDynarray_getCapacityAvailable(ptr)) + ThreadDynarray_resize(ptr); - ThreadDynarray_unlock(ptr); + ThreadDynarray_move(ptr, index + 1, index, ptr->count - index); + ptr->count++; + ThreadDynarray_set(ptr, index, __entry); + + ThreadDynarray_unlock(ptr); } /* * Deletes the entry pointed to by index. If __entry is not NULL the * fuction saves the entry threads at this address before. */ -void ThreadDynarray_erase(ThreadDynarray_t ptr, unsigned long index,ThreadEntry_t const __entry) +void ThreadDynarray_erase(ThreadDynarray_t ptr, unsigned long index, + ThreadEntry_t const __entry) { - - ThreadDynarray_lock(ptr); - if(__entry) - ThreadDynarray_set(ptr,index,__entry); - - if(index != ThreadDynarray_getUpperBound(ptr)) - ThreadDynarray_move(ptr,index,index + 1,(ptr->count - (index + 1))); - - ptr->count--; + ThreadDynarray_lock(ptr); + + if (__entry) + ThreadDynarray_set(ptr, index, __entry); + + if (index != ThreadDynarray_getUpperBound(ptr)) + ThreadDynarray_move(ptr, index, index + 1, (ptr->count - (index + 1))); - ThreadDynarray_unlock(ptr); + ptr->count--; + + ThreadDynarray_unlock(ptr); } /* @@ -169,56 +179,59 @@ void ThreadDynarray_erase(ThreadDynarray_t ptr, unsigned long index,ThreadEntry_ * __entry.The function returns the index of the founded entry, -1 if * no entry is founded. */ -long ThreadDynarray_getIndex(ThreadDynarray_t ptr, ThreadEntry_t const __entry) +long ThreadDynarray_getIndex(ThreadDynarray_t ptr, + ThreadEntry_t const __entry) { - - unsigned long i ; - ThreadDynarray_lock(ptr); - for(i = 0; i < ptr->count; i++){ - if(ThreadDynarray_compare(ptr,i,__entry)){ - ThreadDynarray_unlock(ptr); - return i; - } - } + unsigned long i; + ThreadDynarray_lock(ptr); + + for (i = 0; i < ptr->count; i++) { + if (ThreadDynarray_compare(ptr, i, __entry)) { + ThreadDynarray_unlock(ptr); + return i; + } + } - ThreadDynarray_unlock(ptr); - return -1; + ThreadDynarray_unlock(ptr); + return -1; } /* * Returns true if the entry exist. */ -bool ThreadDynarray_exist(ThreadDynarray_t ptr, ThreadEntry_t const __entry) +bool ThreadDynarray_exist(ThreadDynarray_t ptr, + ThreadEntry_t const __entry) { - bool exist; - - ThreadDynarray_lock(ptr); - exist = (-1 != ThreadDynarray_getIndex(ptr,__entry)); - ThreadDynarray_unlock(ptr); - return exist; + bool exist; + + ThreadDynarray_lock(ptr); + exist = (-1 != ThreadDynarray_getIndex(ptr, __entry)); + ThreadDynarray_unlock(ptr); + return exist; } /* Deletes the first entry with the same content of the entry addressed * by __entry.The function returns true if the entry is deleted, false * if no entry is founded. */ -bool ThreadDynarray_remove(ThreadDynarray_t ptr, ThreadEntry_t const __entry) -{ - /* assert(!empty(ptr)); */ - - long __index; - ThreadDynarray_lock(ptr); - __index = ThreadDynarray_getIndex(ptr,__entry); - - if(__index == -1){ - ThreadDynarray_unlock(ptr); - return false; - } - - ThreadDynarray_set(ptr,(unsigned long)__index,NULL); - ThreadDynarray_unlock(ptr); - return true; +bool ThreadDynarray_remove(ThreadDynarray_t ptr, + ThreadEntry_t const __entry) +{ + /* assert(!empty(ptr)); */ + + long __index; + ThreadDynarray_lock(ptr); + __index = ThreadDynarray_getIndex(ptr, __entry); + + if (__index == -1) { + ThreadDynarray_unlock(ptr); + return false; + } + + ThreadDynarray_set(ptr, (unsigned long) __index, NULL); + ThreadDynarray_unlock(ptr); + return true; } /* @@ -226,16 +239,16 @@ bool ThreadDynarray_remove(ThreadDynarray_t ptr, ThreadEntry_t const __entry) */ void ThreadDynarray_clear(ThreadDynarray_t ptr) { - ThreadDynarray_lock(ptr); + ThreadDynarray_lock(ptr); - if(ptr->threads){ - free(ptr->threads); - ptr->threads = NULL; - } + if (ptr->threads) { + free(ptr->threads); + ptr->threads = NULL; + } - ptr->count = 0; - ptr->capacity = 0; - ThreadDynarray_unlock(ptr); + ptr->count = 0; + ptr->capacity = 0; + ThreadDynarray_unlock(ptr); } /* @@ -243,35 +256,41 @@ void ThreadDynarray_clear(ThreadDynarray_t ptr) */ void ThreadDynarray_reset(ThreadDynarray_t ptr) { - ThreadDynarray_lock(ptr); - ptr->count = 0; - ThreadDynarray_unlock(ptr); + ThreadDynarray_lock(ptr); + ptr->count = 0; + ThreadDynarray_unlock(ptr); } /* * Moves count elements from src index to dst index. */ -void ThreadDynarray_move(ThreadDynarray_t ptr, const unsigned long dst,const unsigned long src,unsigned long count) +void ThreadDynarray_move(ThreadDynarray_t ptr, const unsigned long dst, + const unsigned long src, unsigned long count) { - ThreadDynarray_lock(ptr); + ThreadDynarray_lock(ptr); - if(ptr->count) - memmove(ThreadDynarray_at(ptr,dst),ThreadDynarray_at(ptr,src),count * sizeof(s_ThreadEntry_t)); + if (ptr->count) + memmove(ThreadDynarray_at(ptr, dst), ThreadDynarray_at(ptr, src), + count * sizeof(s_ThreadEntry_t)); - ThreadDynarray_unlock(ptr); + ThreadDynarray_unlock(ptr); } /* Compare the content of the entry pointed to by index with the content of * the entry addressed by __entry. The function returns true if the contents * are same. */ -bool ThreadDynarray_compare(ThreadDynarray_t ptr, const unsigned long index,ThreadEntry_t const __entry) +bool ThreadDynarray_compare(ThreadDynarray_t ptr, + const unsigned long index, + ThreadEntry_t const __entry) { - bool are_equals; - ThreadDynarray_lock(ptr); - are_equals = (!memcmp(ThreadDynarray_at(ptr,index),__entry,sizeof(s_ThreadEntry_t))); - ThreadDynarray_unlock(ptr); - return are_equals; + bool are_equals; + ThreadDynarray_lock(ptr); + are_equals = + (!memcmp + (ThreadDynarray_at(ptr, index), __entry, sizeof(s_ThreadEntry_t))); + ThreadDynarray_unlock(ptr); + return are_equals; } /* @@ -279,16 +298,17 @@ bool ThreadDynarray_compare(ThreadDynarray_t ptr, const unsigned long index,Thre */ ThreadDynarray_t ThreadDynarray_clone(ThreadDynarray_t ptr) { - ThreadDynarray_t new_ptr; - ThreadDynarray_lock(ptr); - ptr = ThreadDynarray_new(ptr->capacity); - - if(ptr->count){ - memcpy(new_ptr->threads,ptr->threads,ptr->count * sizeof(s_ThreadEntry_t)); - new_ptr->count=ThreadDynarray_getCount(ptr); - } - ThreadDynarray_unlock(ptr); - return new_ptr; + ThreadDynarray_t new_ptr; + ThreadDynarray_lock(ptr); + ptr = ThreadDynarray_new(ptr->capacity); + + if (ptr->count) { + memcpy(new_ptr->threads, ptr->threads, + ptr->count * sizeof(s_ThreadEntry_t)); + new_ptr->count = ThreadDynarray_getCount(ptr); + } + ThreadDynarray_unlock(ptr); + return new_ptr; } /* @@ -296,12 +316,14 @@ ThreadDynarray_t ThreadDynarray_clone(ThreadDynarray_t ptr) */ void ThreadDynarray_resize(ThreadDynarray_t ptr) { - ThreadDynarray_lock(ptr); - - ptr->capacity = (!ptr->capacity) ? 1 : (ptr->count << 1); - ptr->threads = (ThreadEntry_t)realloc(ptr->threads, ptr->capacity * sizeof(s_ThreadEntry_t)); - - ThreadDynarray_unlock(ptr); + ThreadDynarray_lock(ptr); + + ptr->capacity = (!ptr->capacity) ? 1 : (ptr->count << 1); + ptr->threads = + (ThreadEntry_t) realloc(ptr->threads, + ptr->capacity * sizeof(s_ThreadEntry_t)); + + ThreadDynarray_unlock(ptr); } @@ -310,11 +332,11 @@ void ThreadDynarray_resize(ThreadDynarray_t ptr) */ unsigned long ThreadDynarray_getCount(ThreadDynarray_t ptr) { - unsigned count; - ThreadDynarray_lock(ptr); - count = ptr->count; - ThreadDynarray_unlock(ptr); - return count; + unsigned count; + ThreadDynarray_lock(ptr); + count = ptr->count; + ThreadDynarray_unlock(ptr); + return count; } /* @@ -323,11 +345,11 @@ unsigned long ThreadDynarray_getCount(ThreadDynarray_t ptr) */ unsigned long ThreadDynarray_getCapacity(ThreadDynarray_t ptr) { - unsigned capacity; - ThreadDynarray_lock(ptr); - capacity = ptr->capacity; - ThreadDynarray_unlock(ptr); - return capacity; + unsigned capacity; + ThreadDynarray_lock(ptr); + capacity = ptr->capacity; + ThreadDynarray_unlock(ptr); + return capacity; } @@ -336,11 +358,11 @@ unsigned long ThreadDynarray_getCapacity(ThreadDynarray_t ptr) */ unsigned long ThreadDynarray_getUpperBound(ThreadDynarray_t ptr) { - unsigned long upper_bound; - ThreadDynarray_lock(ptr); - upper_bound = (ptr->count - 1); - ThreadDynarray_unlock(ptr); - return upper_bound; + unsigned long upper_bound; + ThreadDynarray_lock(ptr); + upper_bound = (ptr->count - 1); + ThreadDynarray_unlock(ptr); + return upper_bound; } /* @@ -348,7 +370,7 @@ unsigned long ThreadDynarray_getUpperBound(ThreadDynarray_t ptr) */ unsigned long ThreadDynarray_getLowerBound(ThreadDynarray_t ptr) { - return 0; + return 0; } /* @@ -356,7 +378,7 @@ unsigned long ThreadDynarray_getLowerBound(ThreadDynarray_t ptr) */ unsigned long ThreadDynarray_getElementSize(ThreadDynarray_t ptr) { - return sizeof(s_ThreadEntry_t); + return sizeof(s_ThreadEntry_t); } /* @@ -364,11 +386,11 @@ unsigned long ThreadDynarray_getElementSize(ThreadDynarray_t ptr) */ bool ThreadDynarray_isEmpty(ThreadDynarray_t ptr) { - bool is_empty; - ThreadDynarray_lock(ptr); - is_empty = (ptr->count == 0); - ThreadDynarray_unlock(ptr); - return is_empty; + bool is_empty; + ThreadDynarray_lock(ptr); + is_empty = (ptr->count == 0); + ThreadDynarray_unlock(ptr); + return is_empty; } /* @@ -376,11 +398,11 @@ bool ThreadDynarray_isEmpty(ThreadDynarray_t ptr) */ bool ThreadDynarray_getCapacityAvailable(ThreadDynarray_t ptr) { - bool capacity_available; - ThreadDynarray_lock(ptr); - capacity_available = (ptr->capacity > ptr->count); - ThreadDynarray_unlock(ptr); - return capacity_available; + bool capacity_available; + ThreadDynarray_lock(ptr); + capacity_available = (ptr->capacity > ptr->count); + ThreadDynarray_unlock(ptr); + return capacity_available; } /* @@ -388,81 +410,82 @@ bool ThreadDynarray_getCapacityAvailable(ThreadDynarray_t ptr) */ bool ThreadDynarray_is_full(ThreadDynarray_t ptr) { - bool is_full; - ThreadDynarray_lock(ptr); - is_full = (!ThreadDynarray_isEmpty(ptr) && !ThreadDynarray_getCapacityAvailable(ptr)); - ThreadDynarray_unlock(ptr); - return is_full; + bool is_full; + ThreadDynarray_lock(ptr); + is_full = (!ThreadDynarray_isEmpty(ptr) + && !ThreadDynarray_getCapacityAvailable(ptr)); + ThreadDynarray_unlock(ptr); + return is_full; } /* * Assignement. */ -ThreadDynarray_t ThreadDynarray_assign(ThreadDynarray_t src,ThreadDynarray_t dst) -{ - ThreadDynarray_lock(src); - ThreadDynarray_lock(dst); - - if(src != dst) - { - ThreadDynarray_clear(dst); - - if(src->count) - { - dst->count = src->count; - dst->capacity = src->capacity; - dst->threads = (ThreadEntry_t)malloc(src->capacity * sizeof(s_ThreadEntry_t)); - memcpy(dst->threads,src->threads,src->count * sizeof(s_ThreadEntry_t)); - } - } - ThreadDynarray_unlock(src); - ThreadDynarray_unlock(dst); - - return dst; +ThreadDynarray_t ThreadDynarray_assign(ThreadDynarray_t src, + ThreadDynarray_t dst) +{ + ThreadDynarray_lock(src); + ThreadDynarray_lock(dst); + + if (src != dst) { + ThreadDynarray_clear(dst); + + if (src->count) { + dst->count = src->count; + dst->capacity = src->capacity; + dst->threads = + (ThreadEntry_t) malloc(src->capacity * sizeof(s_ThreadEntry_t)); + memcpy(dst->threads, src->threads, + src->count * sizeof(s_ThreadEntry_t)); + } + } + ThreadDynarray_unlock(src); + ThreadDynarray_unlock(dst); + + return dst; } /* * Returns true if the dynamic arrays are equal. - */ -bool ThreadDynarray_areEquals(ThreadDynarray_t ptr1,ThreadDynarray_t ptr2) + */ +bool ThreadDynarray_areEquals(ThreadDynarray_t ptr1, ThreadDynarray_t ptr2) { - bool are_equals; - - ThreadDynarray_lock(ptr1); - ThreadDynarray_lock(ptr2); + bool are_equals; - are_equals = ( - ptr1->count == ptr2->count && - ptr1->capacity == ptr2->capacity && - !memcmp(ptr2->threads,ptr1->threads,ptr1->capacity) - ); + ThreadDynarray_lock(ptr1); + ThreadDynarray_lock(ptr2); - ThreadDynarray_unlock(ptr1); - ThreadDynarray_unlock(ptr2); - - return are_equals; + are_equals = (ptr1->count == ptr2->count && + ptr1->capacity == ptr2->capacity && + !memcmp(ptr2->threads, ptr1->threads, ptr1->capacity) + ); + + ThreadDynarray_unlock(ptr1); + ThreadDynarray_unlock(ptr2); + + return are_equals; } /* * Returns true if the dynamic arrays are not equal. - */ -ThreadDynarray_areNotEquals(ThreadDynarray_t ptr1,ThreadDynarray_t ptr2) + */ +ThreadDynarray_areNotEquals(ThreadDynarray_t ptr1, ThreadDynarray_t ptr2) { - return !ThreadDynarray_areEquals(ptr1,ptr2); + return !ThreadDynarray_areEquals(ptr1, ptr2); } void ThreadDynarray_lock(ThreadDynarray_t ptr) { - if(!ptr->is_locked){ - EnterCriticalSection(&(ptr->cs)); - ptr->is_locked = true; - } + if (!ptr->is_locked) { + EnterCriticalSection(&(ptr->cs)); + ptr->is_locked = true; + } } void ThreadDynarray_unlock(ThreadDynarray_t ptr) { - if(ptr->is_locked){ - LeaveCriticalSection(&(ptr->cs)); - ptr->is_locked = false; - } + if (ptr->is_locked) { + LeaveCriticalSection(&(ptr->cs)); + ptr->is_locked = false; + } } diff --git a/win32_test_app/src/TTime.c b/win32_test_app/src/TTime.c index 97511a8f45..1094d22d07 100644 --- a/win32_test_app/src/TTime.c +++ b/win32_test_app/src/TTime.c @@ -1,12 +1,13 @@ #include -void __time(char* t) +void __time(char *t) { - time_t timer; - struct tm *tblock; - timer = time(NULL); - tblock = localtime(&timer); - - sprintf(t,"%02d/%02d/%d %02d:%02d",tblock->tm_mday,tblock->tm_mon,tblock->tm_year + 1900,tblock->tm_hour,tblock->tm_min); -} \ No newline at end of file + time_t timer; + struct tm *tblock; + timer = time(NULL); + tblock = localtime(&timer); + + sprintf(t, "%02d/%02d/%d %02d:%02d", tblock->tm_mday, tblock->tm_mon, + tblock->tm_year + 1900, tblock->tm_hour, tblock->tm_min); +} diff --git a/win32_test_app/src/Test.c b/win32_test_app/src/Test.c index c7c73b0e3c..590437bd89 100644 --- a/win32_test_app/src/Test.c +++ b/win32_test_app/src/Test.c @@ -9,48 +9,43 @@ void terminate(void); #pragma argsused -int main(int argc,char *argv[]) +int main(int argc, char *argv[]) { - errno_t e; - initializeErrno(); + errno_t e; + initializeErrno(); - /* Create a test runner. */ - test_runner = TestRunner_new(); + /* Create a test runner. */ + test_runner = TestRunner_new(); - if(NULL == test_runner) - terminate(); + if (NULL == test_runner) + terminate(); - /* Initialize the test runner. */ - if(E_SUCCESS != TestRunner_initialize(test_runner,argc,argv)) - terminate(); + /* Initialize the test runner. */ + if (E_SUCCESS != TestRunner_initialize(test_runner, argc, argv)) + terminate(); - /* Launch the test runner. */ - TestRunner_run(test_runner); + /* Launch the test runner. */ + TestRunner_run(test_runner); - e = getErrno(); + e = getErrno(); - terminate(); + terminate(); - return e; + return e; } void terminate(void) { - errno_t e = getErrno(); - - if(NULL != test_runner) - TestRunner_free(test_runner); - - printf("\n Program terminated with the exit code : %3d (%s)\n",getErrno(),__errlist[getErrno()]); - - terminateErrno(); - - exit(e); -} + errno_t e = getErrno(); + if (NULL != test_runner) + TestRunner_free(test_runner); + printf("\n Program terminated with the exit code : %3d (%s)\n", + getErrno(), __errlist[getErrno()]); + terminateErrno(); - - + exit(e); +} diff --git a/win32_testsuite/borland/builder6/realistic/gras/datadesc_usage/datadesc_structs.c b/win32_testsuite/borland/builder6/realistic/gras/datadesc_usage/datadesc_structs.c index 23da4a6eff..e214ace0f4 100644 --- a/win32_testsuite/borland/builder6/realistic/gras/datadesc_usage/datadesc_structs.c +++ b/win32_testsuite/borland/builder6/realistic/gras/datadesc_usage/datadesc_structs.c @@ -2,7 +2,8 @@ #include "gras.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(structs,test,"Logs about the gigantic struct test"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(structs, test, + "Logs about the gigantic struct test"); #define READ 0 @@ -18,550 +19,1091 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(structs,test,"Logs about the gigantic struct tes */ -void write_read(gras_datadesc_type_t type,void *src, void *dst, gras_socket_t *sock, int direction); - -GRAS_DEFINE_TYPE(cccc,struct cccc { char a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(ccsc,struct ccsc { char a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(ccic,struct ccic { char a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(cclc,struct cclc { char a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(ccLc,struct ccLc { char a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(ccfc,struct ccfc { char a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(ccdc,struct ccdc { char a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(sccc,struct sccc { short int a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(scsc,struct scsc { short int a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(scic,struct scic { short int a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(sclc,struct sclc { short int a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(scLc,struct scLc { short int a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(scfc,struct scfc { short int a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(scdc,struct scdc { short int a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(iccc,struct iccc { int a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(icsc,struct icsc { int a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(icic,struct icic { int a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(iclc,struct iclc { int a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(icLc,struct icLc { int a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(icfc,struct icfc { int a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(icdc,struct icdc { int a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(lccc,struct lccc { long int a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(lcsc,struct lcsc { long int a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(lcic,struct lcic { long int a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(lclc,struct lclc { long int a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(lcLc,struct lcLc { long int a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(lcfc,struct lcfc { long int a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(lcdc,struct lcdc { long int a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(Lccc,struct Lccc { long long int a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(Lcsc,struct Lcsc { long long int a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(Lcic,struct Lcic { long long int a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(Lclc,struct Lclc { long long int a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(LcLc,struct LcLc { long long int a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(Lcfc,struct Lcfc { long long int a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(Lcdc,struct Lcdc { long long int a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(fccc,struct fccc { float a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(fcsc,struct fcsc { float a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(fcic,struct fcic { float a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(fclc,struct fclc { float a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(fcLc,struct fcLc { float a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(fcfc,struct fcfc { float a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(fcdc,struct fcdc { float a; char b; double c;char d;};) -GRAS_DEFINE_TYPE(dccc,struct dccc { double a; char b; char c;char d;};) -GRAS_DEFINE_TYPE(dcsc,struct dcsc { double a; char b; short int c;char d;};) -GRAS_DEFINE_TYPE(dcic,struct dcic { double a; char b; int c;char d;};) -GRAS_DEFINE_TYPE(dclc,struct dclc { double a; char b; long int c;char d;};) -GRAS_DEFINE_TYPE(dcLc,struct dcLc { double a; char b; long long int c;char d;};) -GRAS_DEFINE_TYPE(dcfc,struct dcfc { double a; char b; float c;char d;};) -GRAS_DEFINE_TYPE(dcdc,struct dcdc { double a; char b; double c;char d;};) +void write_read(gras_datadesc_type_t type, void *src, void *dst, + gras_socket_t * sock, int direction); +GRAS_DEFINE_TYPE(cccc, struct cccc { + char a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccsc, struct ccsc { + char a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccic, struct ccic { + char a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(cclc, struct cclc { + char a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccLc, struct ccLc { + char a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccfc, struct ccfc { + char a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(ccdc, struct ccdc { + char a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(sccc, struct sccc { + short int a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scsc, struct scsc { + short int a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scic, struct scic { + short int a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(sclc, struct sclc { + short int a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scLc, struct scLc { + short int a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scfc, struct scfc { + short int a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(scdc, struct scdc { + short int a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(iccc, struct iccc { + int a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icsc, struct icsc { + int a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icic, struct icic { + int a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(iclc, struct iclc { + int a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icLc, struct icLc { + int a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icfc, struct icfc { + int a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(icdc, struct icdc { + int a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lccc, struct lccc { + long int a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcsc, struct lcsc { + long int a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcic, struct lcic { + long int a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lclc, struct lclc { + long int a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcLc, struct lcLc { + long int a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcfc, struct lcfc { + long int a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(lcdc, struct lcdc { + long int a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lccc, struct Lccc { + long long int a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lcsc, struct Lcsc { + long long int a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lcic, struct Lcic { + long long int a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lclc, struct Lclc { + long long int a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(LcLc, struct LcLc { + long long int a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lcfc, struct Lcfc { + long long int a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(Lcdc, struct Lcdc { + long long int a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fccc, struct fccc { + float a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcsc, struct fcsc { + float a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcic, struct fcic { + float a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fclc, struct fclc { + float a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcLc, struct fcLc { + float a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcfc, struct fcfc { + float a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(fcdc, struct fcdc { + float a; + char b; + double c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dccc, struct dccc { + double a; + char b; + char c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcsc, struct dcsc { + double a; + char b; + short int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcic, struct dcic { + double a; + char b; + int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dclc, struct dclc { + double a; + char b; + long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcLc, struct dcLc { + double a; + char b; + long long int c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcfc, struct dcfc { + double a; + char b; + float c; + char d; + }; + + ) + GRAS_DEFINE_TYPE(dcdc, struct dcdc { + double a; + char b; + double c; + char d; + }; + + ) #define test(a) xbt_assert(a) -void test_structures(gras_socket_t *sock, int direction); -void test_structures(gras_socket_t *sock, int direction) { - struct cccc my_cccc = {'w'+(char)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_cccc2; - struct ccsc my_ccsc = {'w'+(char)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_ccsc2; - struct ccic my_ccic = {'w'+(char)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_ccic2; - struct cclc my_cclc = {'w'+(char)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_cclc2; - struct ccLc my_ccLc = {'w'+(char)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_ccLc2; - struct ccfc my_ccfc = {'w'+(char)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_ccfc2; - struct ccdc my_ccdc = {'w'+(char)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_ccdc2; - struct sccc my_sccc = {134+(short int)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_sccc2; - struct scsc my_scsc = {134+(short int)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_scsc2; - struct scic my_scic = {134+(short int)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_scic2; - struct sclc my_sclc = {134+(short int)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_sclc2; - struct scLc my_scLc = {134+(short int)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_scLc2; - struct scfc my_scfc = {134+(short int)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_scfc2; - struct scdc my_scdc = {134+(short int)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_scdc2; - struct iccc my_iccc = {-11249+(int)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_iccc2; - struct icsc my_icsc = {-11249+(int)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_icsc2; - struct icic my_icic = {-11249+(int)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_icic2; - struct iclc my_iclc = {-11249+(int)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_iclc2; - struct icLc my_icLc = {-11249+(int)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_icLc2; - struct icfc my_icfc = {-11249+(int)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_icfc2; - struct icdc my_icdc = {-11249+(int)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_icdc2; - struct lccc my_lccc = {31319919+(long int)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_lccc2; - struct lcsc my_lcsc = {31319919+(long int)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_lcsc2; - struct lcic my_lcic = {31319919+(long int)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_lcic2; - struct lclc my_lclc = {31319919+(long int)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_lclc2; - struct lcLc my_lcLc = {31319919+(long int)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_lcLc2; - struct lcfc my_lcfc = {31319919+(long int)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_lcfc2; - struct lcdc my_lcdc = {31319919+(long int)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_lcdc2; - struct Lccc my_Lccc = {-232130010+(long long int)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_Lccc2; - struct Lcsc my_Lcsc = {-232130010+(long long int)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_Lcsc2; - struct Lcic my_Lcic = {-232130010+(long long int)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_Lcic2; - struct Lclc my_Lclc = {-232130010+(long long int)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_Lclc2; - struct LcLc my_LcLc = {-232130010+(long long int)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_LcLc2; - struct Lcfc my_Lcfc = {-232130010+(long long int)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_Lcfc2; - struct Lcdc my_Lcdc = {-232130010+(long long int)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_Lcdc2; - struct fccc my_fccc = {-11313.1135+(float)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_fccc2; - struct fcsc my_fcsc = {-11313.1135+(float)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_fcsc2; - struct fcic my_fcic = {-11313.1135+(float)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_fcic2; - struct fclc my_fclc = {-11313.1135+(float)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_fclc2; - struct fcLc my_fcLc = {-11313.1135+(float)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_fcLc2; - struct fcfc my_fcfc = {-11313.1135+(float)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_fcfc2; - struct fcdc my_fcdc = {-11313.1135+(float)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_fcdc2; - struct dccc my_dccc = {1424420.11331+(double)1,'w'+(char)2,'w'+(char)3,'w'+(char)4}, my_dccc2; - struct dcsc my_dcsc = {1424420.11331+(double)1,'w'+(char)2,134+(short int)3,'w'+(char)4}, my_dcsc2; - struct dcic my_dcic = {1424420.11331+(double)1,'w'+(char)2,-11249+(int)3,'w'+(char)4}, my_dcic2; - struct dclc my_dclc = {1424420.11331+(double)1,'w'+(char)2,31319919+(long int)3,'w'+(char)4}, my_dclc2; - struct dcLc my_dcLc = {1424420.11331+(double)1,'w'+(char)2,-232130010+(long long int)3,'w'+(char)4}, my_dcLc2; - struct dcfc my_dcfc = {1424420.11331+(double)1,'w'+(char)2,-11313.1135+(float)3,'w'+(char)4}, my_dcfc2; - struct dcdc my_dcdc = {1424420.11331+(double)1,'w'+(char)2,1424420.11331+(double)3,'w'+(char)4}, my_dcdc2; - INFO0("---- Test on all possible struct having 3 fields (49 structs) ----"); - write_read(gras_datadesc_by_symbol(cccc), &my_cccc, &my_cccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_cccc.a == my_cccc2.a); - test(my_cccc.b == my_cccc2.b); - test(my_cccc.c == my_cccc2.c); - test(my_cccc.d == my_cccc2.d); - if (!failed) VERB0("Passed cccc"); - } - write_read(gras_datadesc_by_symbol(ccsc), &my_ccsc, &my_ccsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccsc.a == my_ccsc2.a); - test(my_ccsc.b == my_ccsc2.b); - test(my_ccsc.c == my_ccsc2.c); - test(my_ccsc.d == my_ccsc2.d); - if (!failed) VERB0("Passed ccsc"); - } - write_read(gras_datadesc_by_symbol(ccic), &my_ccic, &my_ccic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccic.a == my_ccic2.a); - test(my_ccic.b == my_ccic2.b); - test(my_ccic.c == my_ccic2.c); - test(my_ccic.d == my_ccic2.d); - if (!failed) VERB0("Passed ccic"); - } - write_read(gras_datadesc_by_symbol(cclc), &my_cclc, &my_cclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_cclc.a == my_cclc2.a); - test(my_cclc.b == my_cclc2.b); - test(my_cclc.c == my_cclc2.c); - test(my_cclc.d == my_cclc2.d); - if (!failed) VERB0("Passed cclc"); - } - write_read(gras_datadesc_by_symbol(ccLc), &my_ccLc, &my_ccLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccLc.a == my_ccLc2.a); - test(my_ccLc.b == my_ccLc2.b); - test(my_ccLc.c == my_ccLc2.c); - test(my_ccLc.d == my_ccLc2.d); - if (!failed) VERB0("Passed ccLc"); - } - write_read(gras_datadesc_by_symbol(ccfc), &my_ccfc, &my_ccfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccfc.a == my_ccfc2.a); - test(my_ccfc.b == my_ccfc2.b); - test(my_ccfc.c == my_ccfc2.c); - test(my_ccfc.d == my_ccfc2.d); - if (!failed) VERB0("Passed ccfc"); - } - write_read(gras_datadesc_by_symbol(ccdc), &my_ccdc, &my_ccdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_ccdc.a == my_ccdc2.a); - test(my_ccdc.b == my_ccdc2.b); - test(my_ccdc.c == my_ccdc2.c); - test(my_ccdc.d == my_ccdc2.d); - if (!failed) VERB0("Passed ccdc"); - } - write_read(gras_datadesc_by_symbol(sccc), &my_sccc, &my_sccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_sccc.a == my_sccc2.a); - test(my_sccc.b == my_sccc2.b); - test(my_sccc.c == my_sccc2.c); - test(my_sccc.d == my_sccc2.d); - if (!failed) VERB0("Passed sccc"); - } - write_read(gras_datadesc_by_symbol(scsc), &my_scsc, &my_scsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scsc.a == my_scsc2.a); - test(my_scsc.b == my_scsc2.b); - test(my_scsc.c == my_scsc2.c); - test(my_scsc.d == my_scsc2.d); - if (!failed) VERB0("Passed scsc"); - } - write_read(gras_datadesc_by_symbol(scic), &my_scic, &my_scic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scic.a == my_scic2.a); - test(my_scic.b == my_scic2.b); - test(my_scic.c == my_scic2.c); - test(my_scic.d == my_scic2.d); - if (!failed) VERB0("Passed scic"); - } - write_read(gras_datadesc_by_symbol(sclc), &my_sclc, &my_sclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_sclc.a == my_sclc2.a); - test(my_sclc.b == my_sclc2.b); - test(my_sclc.c == my_sclc2.c); - test(my_sclc.d == my_sclc2.d); - if (!failed) VERB0("Passed sclc"); - } - write_read(gras_datadesc_by_symbol(scLc), &my_scLc, &my_scLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scLc.a == my_scLc2.a); - test(my_scLc.b == my_scLc2.b); - test(my_scLc.c == my_scLc2.c); - test(my_scLc.d == my_scLc2.d); - if (!failed) VERB0("Passed scLc"); - } - write_read(gras_datadesc_by_symbol(scfc), &my_scfc, &my_scfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scfc.a == my_scfc2.a); - test(my_scfc.b == my_scfc2.b); - test(my_scfc.c == my_scfc2.c); - test(my_scfc.d == my_scfc2.d); - if (!failed) VERB0("Passed scfc"); - } - write_read(gras_datadesc_by_symbol(scdc), &my_scdc, &my_scdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_scdc.a == my_scdc2.a); - test(my_scdc.b == my_scdc2.b); - test(my_scdc.c == my_scdc2.c); - test(my_scdc.d == my_scdc2.d); - if (!failed) VERB0("Passed scdc"); - } - write_read(gras_datadesc_by_symbol(iccc), &my_iccc, &my_iccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_iccc.a == my_iccc2.a); - test(my_iccc.b == my_iccc2.b); - test(my_iccc.c == my_iccc2.c); - test(my_iccc.d == my_iccc2.d); - if (!failed) VERB0("Passed iccc"); - } - write_read(gras_datadesc_by_symbol(icsc), &my_icsc, &my_icsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icsc.a == my_icsc2.a); - test(my_icsc.b == my_icsc2.b); - test(my_icsc.c == my_icsc2.c); - test(my_icsc.d == my_icsc2.d); - if (!failed) VERB0("Passed icsc"); - } - write_read(gras_datadesc_by_symbol(icic), &my_icic, &my_icic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icic.a == my_icic2.a); - test(my_icic.b == my_icic2.b); - test(my_icic.c == my_icic2.c); - test(my_icic.d == my_icic2.d); - if (!failed) VERB0("Passed icic"); - } - write_read(gras_datadesc_by_symbol(iclc), &my_iclc, &my_iclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_iclc.a == my_iclc2.a); - test(my_iclc.b == my_iclc2.b); - test(my_iclc.c == my_iclc2.c); - test(my_iclc.d == my_iclc2.d); - if (!failed) VERB0("Passed iclc"); - } - write_read(gras_datadesc_by_symbol(icLc), &my_icLc, &my_icLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icLc.a == my_icLc2.a); - test(my_icLc.b == my_icLc2.b); - test(my_icLc.c == my_icLc2.c); - test(my_icLc.d == my_icLc2.d); - if (!failed) VERB0("Passed icLc"); - } - write_read(gras_datadesc_by_symbol(icfc), &my_icfc, &my_icfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icfc.a == my_icfc2.a); - test(my_icfc.b == my_icfc2.b); - test(my_icfc.c == my_icfc2.c); - test(my_icfc.d == my_icfc2.d); - if (!failed) VERB0("Passed icfc"); - } - write_read(gras_datadesc_by_symbol(icdc), &my_icdc, &my_icdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_icdc.a == my_icdc2.a); - test(my_icdc.b == my_icdc2.b); - test(my_icdc.c == my_icdc2.c); - test(my_icdc.d == my_icdc2.d); - if (!failed) VERB0("Passed icdc"); - } - write_read(gras_datadesc_by_symbol(lccc), &my_lccc, &my_lccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lccc.a == my_lccc2.a); - test(my_lccc.b == my_lccc2.b); - test(my_lccc.c == my_lccc2.c); - test(my_lccc.d == my_lccc2.d); - if (!failed) VERB0("Passed lccc"); - } - write_read(gras_datadesc_by_symbol(lcsc), &my_lcsc, &my_lcsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcsc.a == my_lcsc2.a); - test(my_lcsc.b == my_lcsc2.b); - test(my_lcsc.c == my_lcsc2.c); - test(my_lcsc.d == my_lcsc2.d); - if (!failed) VERB0("Passed lcsc"); - } - write_read(gras_datadesc_by_symbol(lcic), &my_lcic, &my_lcic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcic.a == my_lcic2.a); - test(my_lcic.b == my_lcic2.b); - test(my_lcic.c == my_lcic2.c); - test(my_lcic.d == my_lcic2.d); - if (!failed) VERB0("Passed lcic"); - } - write_read(gras_datadesc_by_symbol(lclc), &my_lclc, &my_lclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lclc.a == my_lclc2.a); - test(my_lclc.b == my_lclc2.b); - test(my_lclc.c == my_lclc2.c); - test(my_lclc.d == my_lclc2.d); - if (!failed) VERB0("Passed lclc"); - } - write_read(gras_datadesc_by_symbol(lcLc), &my_lcLc, &my_lcLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcLc.a == my_lcLc2.a); - test(my_lcLc.b == my_lcLc2.b); - test(my_lcLc.c == my_lcLc2.c); - test(my_lcLc.d == my_lcLc2.d); - if (!failed) VERB0("Passed lcLc"); - } - write_read(gras_datadesc_by_symbol(lcfc), &my_lcfc, &my_lcfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcfc.a == my_lcfc2.a); - test(my_lcfc.b == my_lcfc2.b); - test(my_lcfc.c == my_lcfc2.c); - test(my_lcfc.d == my_lcfc2.d); - if (!failed) VERB0("Passed lcfc"); - } - write_read(gras_datadesc_by_symbol(lcdc), &my_lcdc, &my_lcdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_lcdc.a == my_lcdc2.a); - test(my_lcdc.b == my_lcdc2.b); - test(my_lcdc.c == my_lcdc2.c); - test(my_lcdc.d == my_lcdc2.d); - if (!failed) VERB0("Passed lcdc"); - } - write_read(gras_datadesc_by_symbol(Lccc), &my_Lccc, &my_Lccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lccc.a == my_Lccc2.a); - test(my_Lccc.b == my_Lccc2.b); - test(my_Lccc.c == my_Lccc2.c); - test(my_Lccc.d == my_Lccc2.d); - if (!failed) VERB0("Passed Lccc"); - } - write_read(gras_datadesc_by_symbol(Lcsc), &my_Lcsc, &my_Lcsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lcsc.a == my_Lcsc2.a); - test(my_Lcsc.b == my_Lcsc2.b); - test(my_Lcsc.c == my_Lcsc2.c); - test(my_Lcsc.d == my_Lcsc2.d); - if (!failed) VERB0("Passed Lcsc"); - } - write_read(gras_datadesc_by_symbol(Lcic), &my_Lcic, &my_Lcic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lcic.a == my_Lcic2.a); - test(my_Lcic.b == my_Lcic2.b); - test(my_Lcic.c == my_Lcic2.c); - test(my_Lcic.d == my_Lcic2.d); - if (!failed) VERB0("Passed Lcic"); - } - write_read(gras_datadesc_by_symbol(Lclc), &my_Lclc, &my_Lclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lclc.a == my_Lclc2.a); - test(my_Lclc.b == my_Lclc2.b); - test(my_Lclc.c == my_Lclc2.c); - test(my_Lclc.d == my_Lclc2.d); - if (!failed) VERB0("Passed Lclc"); - } - write_read(gras_datadesc_by_symbol(LcLc), &my_LcLc, &my_LcLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_LcLc.a == my_LcLc2.a); - test(my_LcLc.b == my_LcLc2.b); - test(my_LcLc.c == my_LcLc2.c); - test(my_LcLc.d == my_LcLc2.d); - if (!failed) VERB0("Passed LcLc"); - } - write_read(gras_datadesc_by_symbol(Lcfc), &my_Lcfc, &my_Lcfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lcfc.a == my_Lcfc2.a); - test(my_Lcfc.b == my_Lcfc2.b); - test(my_Lcfc.c == my_Lcfc2.c); - test(my_Lcfc.d == my_Lcfc2.d); - if (!failed) VERB0("Passed Lcfc"); - } - write_read(gras_datadesc_by_symbol(Lcdc), &my_Lcdc, &my_Lcdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_Lcdc.a == my_Lcdc2.a); - test(my_Lcdc.b == my_Lcdc2.b); - test(my_Lcdc.c == my_Lcdc2.c); - test(my_Lcdc.d == my_Lcdc2.d); - if (!failed) VERB0("Passed Lcdc"); - } - write_read(gras_datadesc_by_symbol(fccc), &my_fccc, &my_fccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fccc.a == my_fccc2.a); - test(my_fccc.b == my_fccc2.b); - test(my_fccc.c == my_fccc2.c); - test(my_fccc.d == my_fccc2.d); - if (!failed) VERB0("Passed fccc"); - } - write_read(gras_datadesc_by_symbol(fcsc), &my_fcsc, &my_fcsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcsc.a == my_fcsc2.a); - test(my_fcsc.b == my_fcsc2.b); - test(my_fcsc.c == my_fcsc2.c); - test(my_fcsc.d == my_fcsc2.d); - if (!failed) VERB0("Passed fcsc"); - } - write_read(gras_datadesc_by_symbol(fcic), &my_fcic, &my_fcic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcic.a == my_fcic2.a); - test(my_fcic.b == my_fcic2.b); - test(my_fcic.c == my_fcic2.c); - test(my_fcic.d == my_fcic2.d); - if (!failed) VERB0("Passed fcic"); - } - write_read(gras_datadesc_by_symbol(fclc), &my_fclc, &my_fclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fclc.a == my_fclc2.a); - test(my_fclc.b == my_fclc2.b); - test(my_fclc.c == my_fclc2.c); - test(my_fclc.d == my_fclc2.d); - if (!failed) VERB0("Passed fclc"); - } - write_read(gras_datadesc_by_symbol(fcLc), &my_fcLc, &my_fcLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcLc.a == my_fcLc2.a); - test(my_fcLc.b == my_fcLc2.b); - test(my_fcLc.c == my_fcLc2.c); - test(my_fcLc.d == my_fcLc2.d); - if (!failed) VERB0("Passed fcLc"); - } - write_read(gras_datadesc_by_symbol(fcfc), &my_fcfc, &my_fcfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcfc.a == my_fcfc2.a); - test(my_fcfc.b == my_fcfc2.b); - test(my_fcfc.c == my_fcfc2.c); - test(my_fcfc.d == my_fcfc2.d); - if (!failed) VERB0("Passed fcfc"); - } - write_read(gras_datadesc_by_symbol(fcdc), &my_fcdc, &my_fcdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_fcdc.a == my_fcdc2.a); - test(my_fcdc.b == my_fcdc2.b); - test(my_fcdc.c == my_fcdc2.c); - test(my_fcdc.d == my_fcdc2.d); - if (!failed) VERB0("Passed fcdc"); - } - write_read(gras_datadesc_by_symbol(dccc), &my_dccc, &my_dccc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dccc.a == my_dccc2.a); - test(my_dccc.b == my_dccc2.b); - test(my_dccc.c == my_dccc2.c); - test(my_dccc.d == my_dccc2.d); - if (!failed) VERB0("Passed dccc"); - } - write_read(gras_datadesc_by_symbol(dcsc), &my_dcsc, &my_dcsc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcsc.a == my_dcsc2.a); - test(my_dcsc.b == my_dcsc2.b); - test(my_dcsc.c == my_dcsc2.c); - test(my_dcsc.d == my_dcsc2.d); - if (!failed) VERB0("Passed dcsc"); - } - write_read(gras_datadesc_by_symbol(dcic), &my_dcic, &my_dcic2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcic.a == my_dcic2.a); - test(my_dcic.b == my_dcic2.b); - test(my_dcic.c == my_dcic2.c); - test(my_dcic.d == my_dcic2.d); - if (!failed) VERB0("Passed dcic"); - } - write_read(gras_datadesc_by_symbol(dclc), &my_dclc, &my_dclc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dclc.a == my_dclc2.a); - test(my_dclc.b == my_dclc2.b); - test(my_dclc.c == my_dclc2.c); - test(my_dclc.d == my_dclc2.d); - if (!failed) VERB0("Passed dclc"); - } - write_read(gras_datadesc_by_symbol(dcLc), &my_dcLc, &my_dcLc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcLc.a == my_dcLc2.a); - test(my_dcLc.b == my_dcLc2.b); - test(my_dcLc.c == my_dcLc2.c); - test(my_dcLc.d == my_dcLc2.d); - if (!failed) VERB0("Passed dcLc"); - } - write_read(gras_datadesc_by_symbol(dcfc), &my_dcfc, &my_dcfc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcfc.a == my_dcfc2.a); - test(my_dcfc.b == my_dcfc2.b); - test(my_dcfc.c == my_dcfc2.c); - test(my_dcfc.d == my_dcfc2.d); - if (!failed) VERB0("Passed dcfc"); - } - write_read(gras_datadesc_by_symbol(dcdc), &my_dcdc, &my_dcdc2, sock,direction); - if (direction == READ || direction == RW) { - int failed = 0; - test(my_dcdc.a == my_dcdc2.a); - test(my_dcdc.b == my_dcdc2.b); - test(my_dcdc.c == my_dcdc2.c); - test(my_dcdc.d == my_dcdc2.d); - if (!failed) VERB0("Passed dcdc"); +void test_structures(gras_socket_t * sock, int direction); +void test_structures(gras_socket_t * sock, int direction) +{ + struct cccc my_cccc = + { 'w' + (char) 1, 'w' + (char) 2, 'w' + (char) 3, 'w' + (char) 4 }, + my_cccc2; + struct ccsc my_ccsc = + { 'w' + (char) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_ccsc2; + struct ccic my_ccic = + { 'w' + (char) 1, 'w' + (char) 2, -11249 + (int) 3, 'w' + (char) 4 }, + my_ccic2; + struct cclc my_cclc = + { 'w' + (char) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_cclc2; + struct ccLc my_ccLc = + { 'w' + (char) 1, 'w' + (char) 2, -232130010 + (long long int) 3, +'w' + (char) 4 }, my_ccLc2; + struct ccfc my_ccfc = + { 'w' + (char) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_ccfc2; + struct ccdc my_ccdc = + { 'w' + (char) 1, 'w' + (char) 2, 1424420.11331 + (double) 3, +'w' + (char) 4 }, my_ccdc2; + struct sccc my_sccc = + { 134 + (short int) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_sccc2; + struct scsc my_scsc = + { 134 + (short int) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_scsc2; + struct scic my_scic = + { 134 + (short int) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_scic2; + struct sclc my_sclc = + { 134 + (short int) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_sclc2; + struct scLc my_scLc = + { 134 + (short int) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_scLc2; + struct scfc my_scfc = + { 134 + (short int) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_scfc2; + struct scdc my_scdc = + { 134 + (short int) 1, 'w' + (char) 2, 1424420.11331 + (double) 3, +'w' + (char) 4 }, my_scdc2; + struct iccc my_iccc = + { -11249 + (int) 1, 'w' + (char) 2, 'w' + (char) 3, 'w' + (char) 4 }, + my_iccc2; + struct icsc my_icsc = + { -11249 + (int) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_icsc2; + struct icic my_icic = + { -11249 + (int) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_icic2; + struct iclc my_iclc = + { -11249 + (int) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_iclc2; + struct icLc my_icLc = + { -11249 + (int) 1, 'w' + (char) 2, -232130010 + (long long int) 3, +'w' + (char) 4 }, my_icLc2; + struct icfc my_icfc = + { -11249 + (int) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_icfc2; + struct icdc my_icdc = + { -11249 + (int) 1, 'w' + (char) 2, 1424420.11331 + (double) 3, +'w' + (char) 4 }, my_icdc2; + struct lccc my_lccc = + { 31319919 + (long int) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_lccc2; + struct lcsc my_lcsc = + { 31319919 + (long int) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_lcsc2; + struct lcic my_lcic = + { 31319919 + (long int) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_lcic2; + struct lclc my_lclc = + { 31319919 + (long int) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_lclc2; + struct lcLc my_lcLc = + { 31319919 + (long int) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_lcLc2; + struct lcfc my_lcfc = + { 31319919 + (long int) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_lcfc2; + struct lcdc my_lcdc = + { 31319919 + (long int) 1, 'w' + (char) 2, +1424420.11331 + (double) 3, 'w' + (char) 4 }, my_lcdc2; + struct Lccc my_Lccc = + { -232130010 + (long long int) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_Lccc2; + struct Lcsc my_Lcsc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +134 + (short int) 3, 'w' + (char) 4 }, my_Lcsc2; + struct Lcic my_Lcic = + { -232130010 + (long long int) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_Lcic2; + struct Lclc my_Lclc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +31319919 + (long int) 3, 'w' + (char) 4 }, my_Lclc2; + struct LcLc my_LcLc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_LcLc2; + struct Lcfc my_Lcfc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +-11313.1135 + (float) 3, 'w' + (char) 4 }, my_Lcfc2; + struct Lcdc my_Lcdc = + { -232130010 + (long long int) 1, 'w' + (char) 2, +1424420.11331 + (double) 3, 'w' + (char) 4 }, my_Lcdc2; + struct fccc my_fccc = + { -11313.1135 + (float) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_fccc2; + struct fcsc my_fcsc = + { -11313.1135 + (float) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_fcsc2; + struct fcic my_fcic = + { -11313.1135 + (float) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_fcic2; + struct fclc my_fclc = + { -11313.1135 + (float) 1, 'w' + (char) 2, 31319919 + (long int) 3, +'w' + (char) 4 }, my_fclc2; + struct fcLc my_fcLc = + { -11313.1135 + (float) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_fcLc2; + struct fcfc my_fcfc = + { -11313.1135 + (float) 1, 'w' + (char) 2, -11313.1135 + (float) 3, +'w' + (char) 4 }, my_fcfc2; + struct fcdc my_fcdc = + { -11313.1135 + (float) 1, 'w' + (char) 2, +1424420.11331 + (double) 3, 'w' + (char) 4 }, my_fcdc2; + struct dccc my_dccc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, 'w' + (char) 3, +'w' + (char) 4 }, my_dccc2; + struct dcsc my_dcsc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, 134 + (short int) 3, +'w' + (char) 4 }, my_dcsc2; + struct dcic my_dcic = + { 1424420.11331 + (double) 1, 'w' + (char) 2, -11249 + (int) 3, +'w' + (char) 4 }, my_dcic2; + struct dclc my_dclc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, +31319919 + (long int) 3, 'w' + (char) 4 }, my_dclc2; + struct dcLc my_dcLc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, +-232130010 + (long long int) 3, 'w' + (char) 4 }, my_dcLc2; + struct dcfc my_dcfc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, +-11313.1135 + (float) 3, 'w' + (char) 4 }, my_dcfc2; + struct dcdc my_dcdc = + { 1424420.11331 + (double) 1, 'w' + (char) 2, +1424420.11331 + (double) 3, 'w' + (char) 4 }, my_dcdc2; + INFO0 + ("---- Test on all possible struct having 3 fields (49 structs) ----"); + write_read(gras_datadesc_by_symbol(cccc), &my_cccc, &my_cccc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_cccc.a == my_cccc2.a); + test(my_cccc.b == my_cccc2.b); + test(my_cccc.c == my_cccc2.c); + test(my_cccc.d == my_cccc2.d); + if (!failed) + VERB0("Passed cccc"); + } + write_read(gras_datadesc_by_symbol(ccsc), &my_ccsc, &my_ccsc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccsc.a == my_ccsc2.a); + test(my_ccsc.b == my_ccsc2.b); + test(my_ccsc.c == my_ccsc2.c); + test(my_ccsc.d == my_ccsc2.d); + if (!failed) + VERB0("Passed ccsc"); + } + write_read(gras_datadesc_by_symbol(ccic), &my_ccic, &my_ccic2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccic.a == my_ccic2.a); + test(my_ccic.b == my_ccic2.b); + test(my_ccic.c == my_ccic2.c); + test(my_ccic.d == my_ccic2.d); + if (!failed) + VERB0("Passed ccic"); + } + write_read(gras_datadesc_by_symbol(cclc), &my_cclc, &my_cclc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_cclc.a == my_cclc2.a); + test(my_cclc.b == my_cclc2.b); + test(my_cclc.c == my_cclc2.c); + test(my_cclc.d == my_cclc2.d); + if (!failed) + VERB0("Passed cclc"); + } + write_read(gras_datadesc_by_symbol(ccLc), &my_ccLc, &my_ccLc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccLc.a == my_ccLc2.a); + test(my_ccLc.b == my_ccLc2.b); + test(my_ccLc.c == my_ccLc2.c); + test(my_ccLc.d == my_ccLc2.d); + if (!failed) + VERB0("Passed ccLc"); + } + write_read(gras_datadesc_by_symbol(ccfc), &my_ccfc, &my_ccfc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccfc.a == my_ccfc2.a); + test(my_ccfc.b == my_ccfc2.b); + test(my_ccfc.c == my_ccfc2.c); + test(my_ccfc.d == my_ccfc2.d); + if (!failed) + VERB0("Passed ccfc"); + } + write_read(gras_datadesc_by_symbol(ccdc), &my_ccdc, &my_ccdc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_ccdc.a == my_ccdc2.a); + test(my_ccdc.b == my_ccdc2.b); + test(my_ccdc.c == my_ccdc2.c); + test(my_ccdc.d == my_ccdc2.d); + if (!failed) + VERB0("Passed ccdc"); + } + write_read(gras_datadesc_by_symbol(sccc), &my_sccc, &my_sccc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_sccc.a == my_sccc2.a); + test(my_sccc.b == my_sccc2.b); + test(my_sccc.c == my_sccc2.c); + test(my_sccc.d == my_sccc2.d); + if (!failed) + VERB0("Passed sccc"); + } + write_read(gras_datadesc_by_symbol(scsc), &my_scsc, &my_scsc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scsc.a == my_scsc2.a); + test(my_scsc.b == my_scsc2.b); + test(my_scsc.c == my_scsc2.c); + test(my_scsc.d == my_scsc2.d); + if (!failed) + VERB0("Passed scsc"); + } + write_read(gras_datadesc_by_symbol(scic), &my_scic, &my_scic2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scic.a == my_scic2.a); + test(my_scic.b == my_scic2.b); + test(my_scic.c == my_scic2.c); + test(my_scic.d == my_scic2.d); + if (!failed) + VERB0("Passed scic"); + } + write_read(gras_datadesc_by_symbol(sclc), &my_sclc, &my_sclc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_sclc.a == my_sclc2.a); + test(my_sclc.b == my_sclc2.b); + test(my_sclc.c == my_sclc2.c); + test(my_sclc.d == my_sclc2.d); + if (!failed) + VERB0("Passed sclc"); + } + write_read(gras_datadesc_by_symbol(scLc), &my_scLc, &my_scLc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scLc.a == my_scLc2.a); + test(my_scLc.b == my_scLc2.b); + test(my_scLc.c == my_scLc2.c); + test(my_scLc.d == my_scLc2.d); + if (!failed) + VERB0("Passed scLc"); + } + write_read(gras_datadesc_by_symbol(scfc), &my_scfc, &my_scfc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scfc.a == my_scfc2.a); + test(my_scfc.b == my_scfc2.b); + test(my_scfc.c == my_scfc2.c); + test(my_scfc.d == my_scfc2.d); + if (!failed) + VERB0("Passed scfc"); + } + write_read(gras_datadesc_by_symbol(scdc), &my_scdc, &my_scdc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_scdc.a == my_scdc2.a); + test(my_scdc.b == my_scdc2.b); + test(my_scdc.c == my_scdc2.c); + test(my_scdc.d == my_scdc2.d); + if (!failed) + VERB0("Passed scdc"); + } + write_read(gras_datadesc_by_symbol(iccc), &my_iccc, &my_iccc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_iccc.a == my_iccc2.a); + test(my_iccc.b == my_iccc2.b); + test(my_iccc.c == my_iccc2.c); + test(my_iccc.d == my_iccc2.d); + if (!failed) + VERB0("Passed iccc"); + } + write_read(gras_datadesc_by_symbol(icsc), &my_icsc, &my_icsc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icsc.a == my_icsc2.a); + test(my_icsc.b == my_icsc2.b); + test(my_icsc.c == my_icsc2.c); + test(my_icsc.d == my_icsc2.d); + if (!failed) + VERB0("Passed icsc"); + } + write_read(gras_datadesc_by_symbol(icic), &my_icic, &my_icic2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icic.a == my_icic2.a); + test(my_icic.b == my_icic2.b); + test(my_icic.c == my_icic2.c); + test(my_icic.d == my_icic2.d); + if (!failed) + VERB0("Passed icic"); + } + write_read(gras_datadesc_by_symbol(iclc), &my_iclc, &my_iclc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_iclc.a == my_iclc2.a); + test(my_iclc.b == my_iclc2.b); + test(my_iclc.c == my_iclc2.c); + test(my_iclc.d == my_iclc2.d); + if (!failed) + VERB0("Passed iclc"); + } + write_read(gras_datadesc_by_symbol(icLc), &my_icLc, &my_icLc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icLc.a == my_icLc2.a); + test(my_icLc.b == my_icLc2.b); + test(my_icLc.c == my_icLc2.c); + test(my_icLc.d == my_icLc2.d); + if (!failed) + VERB0("Passed icLc"); + } + write_read(gras_datadesc_by_symbol(icfc), &my_icfc, &my_icfc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icfc.a == my_icfc2.a); + test(my_icfc.b == my_icfc2.b); + test(my_icfc.c == my_icfc2.c); + test(my_icfc.d == my_icfc2.d); + if (!failed) + VERB0("Passed icfc"); + } + write_read(gras_datadesc_by_symbol(icdc), &my_icdc, &my_icdc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_icdc.a == my_icdc2.a); + test(my_icdc.b == my_icdc2.b); + test(my_icdc.c == my_icdc2.c); + test(my_icdc.d == my_icdc2.d); + if (!failed) + VERB0("Passed icdc"); + } + write_read(gras_datadesc_by_symbol(lccc), &my_lccc, &my_lccc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lccc.a == my_lccc2.a); + test(my_lccc.b == my_lccc2.b); + test(my_lccc.c == my_lccc2.c); + test(my_lccc.d == my_lccc2.d); + if (!failed) + VERB0("Passed lccc"); + } + write_read(gras_datadesc_by_symbol(lcsc), &my_lcsc, &my_lcsc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcsc.a == my_lcsc2.a); + test(my_lcsc.b == my_lcsc2.b); + test(my_lcsc.c == my_lcsc2.c); + test(my_lcsc.d == my_lcsc2.d); + if (!failed) + VERB0("Passed lcsc"); + } + write_read(gras_datadesc_by_symbol(lcic), &my_lcic, &my_lcic2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcic.a == my_lcic2.a); + test(my_lcic.b == my_lcic2.b); + test(my_lcic.c == my_lcic2.c); + test(my_lcic.d == my_lcic2.d); + if (!failed) + VERB0("Passed lcic"); + } + write_read(gras_datadesc_by_symbol(lclc), &my_lclc, &my_lclc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lclc.a == my_lclc2.a); + test(my_lclc.b == my_lclc2.b); + test(my_lclc.c == my_lclc2.c); + test(my_lclc.d == my_lclc2.d); + if (!failed) + VERB0("Passed lclc"); + } + write_read(gras_datadesc_by_symbol(lcLc), &my_lcLc, &my_lcLc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcLc.a == my_lcLc2.a); + test(my_lcLc.b == my_lcLc2.b); + test(my_lcLc.c == my_lcLc2.c); + test(my_lcLc.d == my_lcLc2.d); + if (!failed) + VERB0("Passed lcLc"); + } + write_read(gras_datadesc_by_symbol(lcfc), &my_lcfc, &my_lcfc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcfc.a == my_lcfc2.a); + test(my_lcfc.b == my_lcfc2.b); + test(my_lcfc.c == my_lcfc2.c); + test(my_lcfc.d == my_lcfc2.d); + if (!failed) + VERB0("Passed lcfc"); + } + write_read(gras_datadesc_by_symbol(lcdc), &my_lcdc, &my_lcdc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_lcdc.a == my_lcdc2.a); + test(my_lcdc.b == my_lcdc2.b); + test(my_lcdc.c == my_lcdc2.c); + test(my_lcdc.d == my_lcdc2.d); + if (!failed) + VERB0("Passed lcdc"); + } + write_read(gras_datadesc_by_symbol(Lccc), &my_Lccc, &my_Lccc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lccc.a == my_Lccc2.a); + test(my_Lccc.b == my_Lccc2.b); + test(my_Lccc.c == my_Lccc2.c); + test(my_Lccc.d == my_Lccc2.d); + if (!failed) + VERB0("Passed Lccc"); + } + write_read(gras_datadesc_by_symbol(Lcsc), &my_Lcsc, &my_Lcsc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lcsc.a == my_Lcsc2.a); + test(my_Lcsc.b == my_Lcsc2.b); + test(my_Lcsc.c == my_Lcsc2.c); + test(my_Lcsc.d == my_Lcsc2.d); + if (!failed) + VERB0("Passed Lcsc"); + } + write_read(gras_datadesc_by_symbol(Lcic), &my_Lcic, &my_Lcic2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lcic.a == my_Lcic2.a); + test(my_Lcic.b == my_Lcic2.b); + test(my_Lcic.c == my_Lcic2.c); + test(my_Lcic.d == my_Lcic2.d); + if (!failed) + VERB0("Passed Lcic"); + } + write_read(gras_datadesc_by_symbol(Lclc), &my_Lclc, &my_Lclc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lclc.a == my_Lclc2.a); + test(my_Lclc.b == my_Lclc2.b); + test(my_Lclc.c == my_Lclc2.c); + test(my_Lclc.d == my_Lclc2.d); + if (!failed) + VERB0("Passed Lclc"); + } + write_read(gras_datadesc_by_symbol(LcLc), &my_LcLc, &my_LcLc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_LcLc.a == my_LcLc2.a); + test(my_LcLc.b == my_LcLc2.b); + test(my_LcLc.c == my_LcLc2.c); + test(my_LcLc.d == my_LcLc2.d); + if (!failed) + VERB0("Passed LcLc"); + } + write_read(gras_datadesc_by_symbol(Lcfc), &my_Lcfc, &my_Lcfc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lcfc.a == my_Lcfc2.a); + test(my_Lcfc.b == my_Lcfc2.b); + test(my_Lcfc.c == my_Lcfc2.c); + test(my_Lcfc.d == my_Lcfc2.d); + if (!failed) + VERB0("Passed Lcfc"); + } + write_read(gras_datadesc_by_symbol(Lcdc), &my_Lcdc, &my_Lcdc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_Lcdc.a == my_Lcdc2.a); + test(my_Lcdc.b == my_Lcdc2.b); + test(my_Lcdc.c == my_Lcdc2.c); + test(my_Lcdc.d == my_Lcdc2.d); + if (!failed) + VERB0("Passed Lcdc"); + } + write_read(gras_datadesc_by_symbol(fccc), &my_fccc, &my_fccc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fccc.a == my_fccc2.a); + test(my_fccc.b == my_fccc2.b); + test(my_fccc.c == my_fccc2.c); + test(my_fccc.d == my_fccc2.d); + if (!failed) + VERB0("Passed fccc"); + } + write_read(gras_datadesc_by_symbol(fcsc), &my_fcsc, &my_fcsc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcsc.a == my_fcsc2.a); + test(my_fcsc.b == my_fcsc2.b); + test(my_fcsc.c == my_fcsc2.c); + test(my_fcsc.d == my_fcsc2.d); + if (!failed) + VERB0("Passed fcsc"); + } + write_read(gras_datadesc_by_symbol(fcic), &my_fcic, &my_fcic2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcic.a == my_fcic2.a); + test(my_fcic.b == my_fcic2.b); + test(my_fcic.c == my_fcic2.c); + test(my_fcic.d == my_fcic2.d); + if (!failed) + VERB0("Passed fcic"); + } + write_read(gras_datadesc_by_symbol(fclc), &my_fclc, &my_fclc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fclc.a == my_fclc2.a); + test(my_fclc.b == my_fclc2.b); + test(my_fclc.c == my_fclc2.c); + test(my_fclc.d == my_fclc2.d); + if (!failed) + VERB0("Passed fclc"); + } + write_read(gras_datadesc_by_symbol(fcLc), &my_fcLc, &my_fcLc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcLc.a == my_fcLc2.a); + test(my_fcLc.b == my_fcLc2.b); + test(my_fcLc.c == my_fcLc2.c); + test(my_fcLc.d == my_fcLc2.d); + if (!failed) + VERB0("Passed fcLc"); + } + write_read(gras_datadesc_by_symbol(fcfc), &my_fcfc, &my_fcfc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcfc.a == my_fcfc2.a); + test(my_fcfc.b == my_fcfc2.b); + test(my_fcfc.c == my_fcfc2.c); + test(my_fcfc.d == my_fcfc2.d); + if (!failed) + VERB0("Passed fcfc"); + } + write_read(gras_datadesc_by_symbol(fcdc), &my_fcdc, &my_fcdc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_fcdc.a == my_fcdc2.a); + test(my_fcdc.b == my_fcdc2.b); + test(my_fcdc.c == my_fcdc2.c); + test(my_fcdc.d == my_fcdc2.d); + if (!failed) + VERB0("Passed fcdc"); + } + write_read(gras_datadesc_by_symbol(dccc), &my_dccc, &my_dccc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dccc.a == my_dccc2.a); + test(my_dccc.b == my_dccc2.b); + test(my_dccc.c == my_dccc2.c); + test(my_dccc.d == my_dccc2.d); + if (!failed) + VERB0("Passed dccc"); + } + write_read(gras_datadesc_by_symbol(dcsc), &my_dcsc, &my_dcsc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcsc.a == my_dcsc2.a); + test(my_dcsc.b == my_dcsc2.b); + test(my_dcsc.c == my_dcsc2.c); + test(my_dcsc.d == my_dcsc2.d); + if (!failed) + VERB0("Passed dcsc"); + } + write_read(gras_datadesc_by_symbol(dcic), &my_dcic, &my_dcic2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcic.a == my_dcic2.a); + test(my_dcic.b == my_dcic2.b); + test(my_dcic.c == my_dcic2.c); + test(my_dcic.d == my_dcic2.d); + if (!failed) + VERB0("Passed dcic"); + } + write_read(gras_datadesc_by_symbol(dclc), &my_dclc, &my_dclc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dclc.a == my_dclc2.a); + test(my_dclc.b == my_dclc2.b); + test(my_dclc.c == my_dclc2.c); + test(my_dclc.d == my_dclc2.d); + if (!failed) + VERB0("Passed dclc"); + } + write_read(gras_datadesc_by_symbol(dcLc), &my_dcLc, &my_dcLc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcLc.a == my_dcLc2.a); + test(my_dcLc.b == my_dcLc2.b); + test(my_dcLc.c == my_dcLc2.c); + test(my_dcLc.d == my_dcLc2.d); + if (!failed) + VERB0("Passed dcLc"); + } + write_read(gras_datadesc_by_symbol(dcfc), &my_dcfc, &my_dcfc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcfc.a == my_dcfc2.a); + test(my_dcfc.b == my_dcfc2.b); + test(my_dcfc.c == my_dcfc2.c); + test(my_dcfc.d == my_dcfc2.d); + if (!failed) + VERB0("Passed dcfc"); + } + write_read(gras_datadesc_by_symbol(dcdc), &my_dcdc, &my_dcdc2, sock, + direction); + if (direction == READ || direction == RW) { + int failed = 0; + test(my_dcdc.a == my_dcdc2.a); + test(my_dcdc.b == my_dcdc2.b); + test(my_dcdc.c == my_dcdc2.c); + test(my_dcdc.d == my_dcdc2.d); + if (!failed) + VERB0("Passed dcdc"); } } diff --git a/win32_testsuite/borland/builder6/realistic/gras/datadesc_usage/datadesc_usage.c b/win32_testsuite/borland/builder6/realistic/gras/datadesc_usage/datadesc_usage.c index e133fbf80e..b5027f620d 100644 --- a/win32_testsuite/borland/builder6/realistic/gras/datadesc_usage/datadesc_usage.c +++ b/win32_testsuite/borland/builder6/realistic/gras/datadesc_usage/datadesc_usage.c @@ -15,7 +15,7 @@ #include "..\..\..\..\include\gras\datadesc.h" #include "gras/DataDesc/datadesc_interface.h" -XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); +XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this test"); #define READ 0 #define WRITE 1 @@ -23,37 +23,39 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test"); #define RW 3 int r_arch; -const char *filename = "datadesc_usage.out"; +const char *filename = "datadesc_usage.out"; void -write_read(gras_datadesc_type_t type,void *src, void *dst, gras_socket_t sock, int direction); +write_read(gras_datadesc_type_t type, void *src, void *dst, + gras_socket_t sock, int direction); void -write_read(gras_datadesc_type_t type,void *src, void *dst, gras_socket_t sock, int direction) +write_read(gras_datadesc_type_t type, void *src, void *dst, + gras_socket_t sock, int direction) { - - /* write */ - if (direction == RW) - sock = gras_socket_client_from_file(filename); - - if (direction == WRITE || direction == RW) - gras_datadesc_send(sock, type, src); - - if (direction == RW) - gras_socket_close(sock); - - /* read */ - if (direction == RW) - sock = gras_socket_server_from_file(filename); - - if (direction == READ || direction == RW) - gras_datadesc_recv(sock, type, r_arch, dst); - - if (direction == RW) - gras_socket_close(sock); - - if (direction == COPY) - gras_datadesc_copy(type, src, dst); + + /* write */ + if (direction == RW) + sock = gras_socket_client_from_file(filename); + + if (direction == WRITE || direction == RW) + gras_datadesc_send(sock, type, src); + + if (direction == RW) + gras_socket_close(sock); + + /* read */ + if (direction == RW) + sock = gras_socket_server_from_file(filename); + + if (direction == READ || direction == RW) + gras_datadesc_recv(sock, type, r_arch, dst); + + if (direction == RW) + gras_socket_close(sock); + + if (direction == COPY) + gras_datadesc_copy(type, src, dst); } void test_int(gras_socket_t sock, int direction); @@ -75,190 +77,188 @@ 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 */ -void test_structures(gras_socket_t sock, int direction); +void test_structures(gras_socket_t sock, int direction); -void test_int(gras_socket_t sock, int direction) +void test_int(gras_socket_t sock, int direction) { - int i=5,j; - - INFO0("---- Test on integer ----"); + int i = 5, j; + + INFO0("---- Test on integer ----"); - write_read(gras_datadesc_by_name("int"), &i,&j, sock,direction); + write_read(gras_datadesc_by_name("int"), &i, &j, sock, direction); - if (direction == READ || direction == RW || direction == COPY) - xbt_assert(i == j); + if (direction == READ || direction == RW || direction == COPY) + xbt_assert(i == j); } -void test_float(gras_socket_t sock, int direction) + +void test_float(gras_socket_t sock, int direction) { - float i=5.0,j; - - INFO0("---- Test on float ----"); - 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); + float i = 5.0, j; + + INFO0("---- Test on float ----"); + 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); } -void test_double(gras_socket_t sock, int direction) + +void test_double(gras_socket_t sock, int direction) { - double i=-3252355.1234,j; - - INFO0("---- Test on double ----"); - 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); + double i = -3252355.1234, j; + + INFO0("---- Test on double ----"); + 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); } #define SIZE 5 typedef int array[SIZE]; -void test_array(gras_socket_t sock, int direction) +void test_array(gras_socket_t sock, int direction) { - gras_datadesc_type_t my_type; - - array i = { 35212,-6226,74337,11414,7733}; - array j; - int cpt; - - INFO0("---- Test on fixed array ----"); - - my_type=gras_datadesc_array_fixed("fixed int array", gras_datadesc_by_name("int"),SIZE); - - 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; + /* 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(my_type, &i,&j, sock,direction); + 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_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); @@ -269,42 +269,48 @@ void test_homostruct(gras_socket_t sock, int direction) /*** *** heterogeneous struct - ***/ + ***/ typedef struct { unsigned char c1; unsigned long int l1; unsigned char c2; unsigned long int l2; } hetestruct; -void test_hetestruct(gras_socket_t sock, int direction) { +void test_hetestruct(gras_socket_t sock, int direction) +{ gras_datadesc_type_t my_type; - hetestruct *i, *j; + hetestruct *i, *j; INFO0("---- Test on heterogeneous structure ----"); /* create descriptor */ - 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")); + 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")); + my_type = + gras_datadesc_ref("hetestruct*", + gras_datadesc_by_name("hetestruct")); - /* 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; + /* 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(my_type, &i,&j, sock,direction); + 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); + xbt_assert2(i->l1 == j->l1, "i->l1(=%ld) != j->l1(=%ld)", i->l1, + j->l1); xbt_assert(i->l2 == j->l2); free(j); } @@ -313,34 +319,41 @@ void test_hetestruct(gras_socket_t sock, int direction) { /*** *** nested struct - ***/ + ***/ typedef struct { hetestruct hete; homostruct homo; } nestedstruct; -void test_nestedstruct(gras_socket_t sock, int direction) { +void test_nestedstruct(gras_socket_t sock, int direction) +{ gras_datadesc_type_t my_type; - nestedstruct *i, *j; + nestedstruct *i, *j; INFO0("---- Test on nested structures ----"); /* create descriptor */ - my_type=gras_datadesc_struct("nestedstruct"); + 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_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")); - - /* 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(my_type, &i,&j, sock,direction); + my_type = + gras_datadesc_ref("nestedstruct*", + gras_datadesc_by_name("nestedstruct")); + + /* 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(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); @@ -357,182 +370,193 @@ void test_nestedstruct(gras_socket_t sock, int direction) { /*** *** chained list - ***/ + ***/ typedef struct s_chained_list chained_list_t; struct s_chained_list { - int v; + int v; chained_list_t *l; }; 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); +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); -void declare_chained_list_type(void) { - gras_datadesc_type_t my_type,ref_my_type; +void declare_chained_list_type(void) +{ + gras_datadesc_type_t my_type, ref_my_type; - my_type=gras_datadesc_struct("chained_list_t"); - ref_my_type=gras_datadesc_ref("chained_list_t*",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_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); } -chained_list_t * cons(int v, chained_list_t *l) { - chained_list_t *nl = xbt_new(chained_list_t,1); - +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; } -void list_free(chained_list_t*l) { + +void list_free(chained_list_t * 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; + +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); + return list_eq(i->l, j->l); } -void test_chain_list(gras_socket_t sock, int direction) { - chained_list_t *i, *j; + +void test_chain_list(gras_socket_t sock, int direction) +{ + chained_list_t *i, *j; INFO0("---- Test on chained list ----"); - /* init a value, exchange it and check its validity*/ - i = cons( 12355, cons( 246264 , cons( 23263, NULL))); + /* init a value, exchange it and check its validity */ + i = cons(12355, cons(246264, cons(23263, NULL))); j = NULL; write_read(gras_datadesc_by_name("chained_list_t*"), - &i,&j, sock,direction); + &i, &j, sock, direction); if (direction == READ || direction == RW || direction == COPY) { - xbt_assert(list_eq(i,j)); + xbt_assert(list_eq(i, j)); list_free(j); } list_free(i); } + /*** *** graph ***/ -void test_graph(gras_socket_t sock, int direction) { - chained_list_t *i, *j; +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))); + /* 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*")); write_read(gras_datadesc_by_name("chained_list_t*"), - &i,&j, sock,direction); + &i, &j, sock, direction); if (direction == READ || direction == RW || 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); + + 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); + "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)); + xbt_assert(list_eq(i, j)); list_free(j); } - i->l->l->l = NULL; /* do this even in WRITE mode */ + 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); +static void free_string(void *d) +{ /* used to free the data in dynar */ + free(*(void **) d); } -void test_dynar_ref(gras_socket_t sock, int direction){ + +void test_dynar_ref(gras_socket_t sock, int direction) +{ gras_datadesc_type_t my_type; - xbt_dynar_t i,j; + xbt_dynar_t i, j; char buf[1024]; - char *s1,*s2; + char *s1, *s2; int cpt; - - INFO0("---- Test on dynar containing integers ----"); - my_type = gras_datadesc_dynar(gras_datadesc_by_name("string"),&free_string); - 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); + INFO0("---- Test on dynar containing integers ----"); + my_type = + gras_datadesc_dynar(gras_datadesc_by_name("string"), &free_string); + + 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(my_type, &i,&j, sock, direction); + 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); - 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); + 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]; -}; - ) +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];};) typedef struct s_pbio pbio_t; -void test_pbio(gras_socket_t sock, int direction) { +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) ----"); + 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++) + for (cpt = 0; cpt < 12; cpt++) i.Cstatev[cpt] = ((double) cpt) * -2361.11; i.Cnprops = -37373; - for (cpt=0; cpt<110; cpt++) + for (cpt = 0; cpt < 110; cpt++) i.Cprops[cpt] = cpt * 100.0; - for (cpt=0; cpt<4; cpt++) + for (cpt = 0; cpt < 4; cpt++) i.Cndi[cpt] = cpt * 23262; i.Cnshr = -4634; i.Cnpt = 114142; @@ -540,31 +564,30 @@ void test_pbio(gras_socket_t sock, int direction) { 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 < 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); + 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(gras_datadesc_by_symbol(s_pbio), - &i,&j, sock,direction); + 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++) + 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]); + "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++) + for (cpt = 0; cpt < 110; cpt++) xbt_assert(i.Cprops[cpt] == j.Cprops[cpt]); - for (cpt=0; cpt<4; 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); @@ -572,58 +595,60 @@ void test_pbio(gras_socket_t sock, int direction) { 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 < 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++) { + 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]); + 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 */ -};) +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 */ + }; + + ) typedef struct s_clause Clause; -void test_clause(gras_socket_t sock, int direction) { +void test_clause(gras_socket_t sock, int direction) +{ gras_datadesc_type_t ddt; - Clause *i,*j; + Clause *i, *j; int cpt; - - INFO0("---- Test on struct containing dynamic array and its size (cbps test) ----"); + + INFO0 + ("---- Test on struct containing dynamic array and its size (cbps test) ----"); /* create and fill the struct */ - i=xbt_new(Clause,1); + i = xbt_new(Clause, 1); i->num_lits = 5432; i->literals = xbt_new(int, i->num_lits); - for (cpt=0; cptnum_lits; cpt++) + for (cpt = 0; cpt < i->num_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); + DEBUG3("created data=%p (within %p @%p)", &(i->num_lits), i, &i); + DEBUG1("created count=%d", i->num_lits); /* create the damn type descriptor */ ddt = gras_datadesc_by_symbol(s_clause); /* gras_datadesc_type_dump(ddt); */ - ddt=gras_datadesc_ref("Clause*",ddt); + ddt = gras_datadesc_ref("Clause*", ddt); - write_read(ddt, &i,&j, sock,direction); + 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++) + for (cpt = 0; cpt < i->num_lits; cpt++) xbt_assert(i->literals[cpt] == j->literals[cpt]); - + free(j->literals); free(j); } @@ -633,87 +658,79 @@ void test_clause(gras_socket_t sock, int direction) { #pragma argsused -int main(int argc,char *argv[]) +int main(int argc, char *argv[]) { - gras_socket_t sock=NULL; - int direction =WRITE ; /* RW; */ - int cpt; - char r_arch_char = gras_arch_selfid(); - - gras_init(&argc,argv); - - for (cpt=1; cpt 1000) - break; - } - - tmgr_history_free(history); - free(host_B); - free(host_A); + tmgr_history_t history = tmgr_history_new(); + tmgr_trace_t trace_A = tmgr_trace_new("trace_A.txt"); + tmgr_trace_t trace_B = tmgr_trace_new("trace_B.txt"); + double next_event_date = -1.0; + double value = -1.0; + char *resource = NULL; + char *host_A = strdup("Host A"); + char *host_B = strdup("Host B"); + + tmgr_history_add_trace(history, trace_A, 1.0, 2, host_A); + tmgr_history_add_trace(history, trace_B, 0.0, 0, host_B); + + while ((next_event_date = tmgr_history_next_date(history)) != -1.0) { + DEBUG1("%g" " : \n", next_event_date); + while (tmgr_history_get_next_event_leq + (history, next_event_date, &value, (void **) &resource)) { + DEBUG2("\t %s : " "%g" "\n", resource, value); + } + + if (next_event_date > 1000) + break; + } + + tmgr_history_free(history); + free(host_B); + free(host_A); } #pragma argsused -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - surf_init(&argc,argv); - test(); - surf_exit(); + surf_init(&argc, argv); + test(); + surf_exit(); - return 0; + return 0; } + //--------------------------------------------------------------------------- diff --git a/win32_testsuite/borland/builder6/simulation/xbt/context_usage/context_usage.c b/win32_testsuite/borland/builder6/simulation/xbt/context_usage/context_usage.c index 8b24c42e48..f8b3ed7a92 100644 --- a/win32_testsuite/borland/builder6/simulation/xbt/context_usage/context_usage.c +++ b/win32_testsuite/borland/builder6/simulation/xbt/context_usage/context_usage.c @@ -18,99 +18,103 @@ xbt_context_t cB = NULL; xbt_context_t cC = NULL; xbt_fifo_t fifo = NULL; -void print_args(int argc, char** argv); -void print_args(int argc, char** argv) +void print_args(int argc, char **argv); +void print_args(int argc, char **argv) { - int i ; - - printf("args=<"); - - for(i=0; i\n"); + int i; + + printf("args=<"); + + for (i = 0; i < argc; i++) + printf("%s ", argv[i]); + + printf(">\n"); } -int fA(int argc, char** argv); -int fA(int argc, char** argv) +int fA(int argc, char **argv); +int fA(int argc, char **argv) { - printf("Here is fA: "); - print_args(argc,argv); - - printf("\tContext A: Yield\n"); - xbt_context_yield(); - - xbt_fifo_push(fifo,cB); - printf("\tPush context B from context A\n"); - - printf("\tContext A: Yield\n"); - xbt_context_yield(); - printf("\tContext A : bye\n"); - - return 0; + printf("Here is fA: "); + print_args(argc, argv); + + printf("\tContext A: Yield\n"); + xbt_context_yield(); + + xbt_fifo_push(fifo, cB); + printf("\tPush context B from context A\n"); + + printf("\tContext A: Yield\n"); + xbt_context_yield(); + printf("\tContext A : bye\n"); + + return 0; } -int fB(int argc, char** argv); -int fB(int argc, char** argv) +int fB(int argc, char **argv); +int fB(int argc, char **argv) { - printf("Here is fB: "); - print_args(argc,argv); - xbt_fifo_push(fifo,cA); - printf("\tPush context A from context B\n"); - printf("\tContext B: Yield\n"); - xbt_context_yield(); - printf("\tContext B : bye\n"); - return 0; + printf("Here is fB: "); + print_args(argc, argv); + xbt_fifo_push(fifo, cA); + printf("\tPush context A from context B\n"); + printf("\tContext B: Yield\n"); + xbt_context_yield(); + printf("\tContext B : bye\n"); + return 0; } -int fC(int argc, char** argv); -int fC(int argc, char** argv) +int fC(int argc, char **argv); +int fC(int argc, char **argv) { - printf("Here is fC: "); - print_args(argc,argv); - - - printf("\tContext C: Yield (and exit)\n"); - xbt_context_yield(); - - - return 0; + printf("Here is fC: "); + print_args(argc, argv); + + + printf("\tContext C: Yield (and exit)\n"); + xbt_context_yield(); + + + return 0; } + #pragma argsused int main(int argc, char **argv) { - xbt_context_t context = NULL; - - printf("XXX Test the simgrid context API\n"); - printf(" If it fails, try another context backend.\n For example, to force the pthread backend, use:\n ./configure --with-context=pthread\n\n"); - - xbt_context_init(); - - cA = xbt_context_new(fA, NULL, NULL, NULL, NULL, 0, NULL); - cB = xbt_context_new(fB, NULL, NULL, NULL, NULL, 0, NULL); - cC = xbt_context_new(fC, NULL, NULL, NULL, NULL, 0, NULL); - - fifo = xbt_fifo_new(); - - printf("Here is context 'main'\n"); - xbt_context_start(cA); - printf("\tPush context 'A' from context 'main'\n");xbt_fifo_push(fifo,cA); - xbt_context_start(cB); - printf("\tPush context 'B' from context 'main'\n");xbt_fifo_push(fifo,cB); - xbt_context_start(cC);xbt_fifo_push(fifo,cC); - printf("\tPush context 'C' from context 'main'\n");xbt_fifo_push(fifo,cC); - - while((context=xbt_fifo_shift(fifo))) - { - printf("Context main: Yield\n"); - xbt_context_schedule(context); - } - - xbt_fifo_free(fifo); - xbt_context_exit(); - - cA=cB=cC=NULL; - return 0; -} + xbt_context_t context = NULL; + + printf("XXX Test the simgrid context API\n"); + printf + (" If it fails, try another context backend.\n For example, to force the pthread backend, use:\n ./configure --with-context=pthread\n\n"); + + xbt_context_init(); + + cA = xbt_context_new(fA, NULL, NULL, NULL, NULL, 0, NULL); + cB = xbt_context_new(fB, NULL, NULL, NULL, NULL, 0, NULL); + cC = xbt_context_new(fC, NULL, NULL, NULL, NULL, 0, NULL); + fifo = xbt_fifo_new(); + + printf("Here is context 'main'\n"); + xbt_context_start(cA); + printf("\tPush context 'A' from context 'main'\n"); + xbt_fifo_push(fifo, cA); + xbt_context_start(cB); + printf("\tPush context 'B' from context 'main'\n"); + xbt_fifo_push(fifo, cB); + xbt_context_start(cC); + xbt_fifo_push(fifo, cC); + printf("\tPush context 'C' from context 'main'\n"); + xbt_fifo_push(fifo, cC); + + while ((context = xbt_fifo_shift(fifo))) { + printf("Context main: Yield\n"); + xbt_context_schedule(context); + } + + xbt_fifo_free(fifo); + xbt_context_exit(); + + cA = cB = cC = NULL; + return 0; +} diff --git a/win32_testsuite/borland/builder6/simulation/xbt/graphxml_usage/graphxml_usage.c b/win32_testsuite/borland/builder6/simulation/xbt/graphxml_usage/graphxml_usage.c index 0e56806170..241df8b54f 100644 --- a/win32_testsuite/borland/builder6/simulation/xbt/graphxml_usage/graphxml_usage.c +++ b/win32_testsuite/borland/builder6/simulation/xbt/graphxml_usage/graphxml_usage.c @@ -18,166 +18,160 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to graphxml test"); -static void *node_label_and_data(xbt_node_t node, const char *label,const char *data) +static void *node_label_and_data(xbt_node_t node, const char *label, + const char *data) { - char *lbl = xbt_strdup(label); - return lbl; + char *lbl = xbt_strdup(label); + return lbl; } #define free_label free static const char *node_name(xbt_node_t n) { - return xbt_graph_node_get_data(n); + return xbt_graph_node_get_data(n); } void test(char *graph_file); void test(char *graph_file) { - int test_node_deletion = 0; - int test_edge_deletion = 0; - int test_export_xml = 1; - int test_export_dot = 1; - int test_export_length = 1; - int test_shortest_paths = 1; - int test_topo_sort = 1; - - int i, j; - unsigned long n; - - xbt_dynar_t edges = NULL; - xbt_dynar_t nodes = NULL; - - xbt_graph_t graph = - xbt_graph_read(graph_file, &node_label_and_data, NULL); - - n = xbt_dynar_length(xbt_graph_get_nodes(graph)); - - if (test_export_xml) - { - INFO0("---- Testing XML export. Exporting to testgraph.xml ----"); - xbt_graph_export_graphxml(graph, "testgraph.xml", NULL, NULL, NULL,NULL); - } - - if (test_export_dot) - { - INFO0("---- Testing GraphViz export. Exporting to testgraph.dot ----"); - xbt_graph_export_graphviz(graph, "testgraph.dot", node_name, NULL); - } - - if (test_export_length) - { - char *buf = NULL; - double *adj = NULL; - - INFO0("---- Dumping Edge lengths ----"); - adj = xbt_graph_get_length_matrix(graph); - buf = calloc(n * 20, sizeof(char)); - - for (i = 0; i < n; i++) - { - for (j = 0; j < n; j++) - { - sprintf(buf + strlen(buf), "%le\t", adj[i * n + j]); - } - - INFO1("%s", buf); - buf[0] = '\000'; - } - - free(buf); - free(adj); - } - - if (test_shortest_paths) - { - char *buf = NULL; - xbt_node_t *route = NULL; - - INFO0("---- Testing Shortest Paths ----"); - route = xbt_graph_shortest_paths(graph); - buf = calloc(n * 40, sizeof(char)); - - for (i = 0; i < n; i++) - { - for (j = 0; j < n; j++) - { - if (route[i * n + j]) - snprintf(buf+strlen(buf), 40, "%s\t", node_name(route[i * n + j])); - } - - INFO1("%s", buf); - buf[0] = '\000'; - } - - free(buf); - free(route); - } - - if(test_topo_sort) - { - xbt_node_t *sorted = NULL; - - INFO0("---- Testing Topological Sort ----"); - sorted = xbt_graph_topo_sort(graph); - - for (i = 0; i < n; i++) - { - if (sorted[i]) - { - INFO3("sorted[%d] = %s (%p)", i, node_name(sorted[i]), sorted[i]); - } - } - - free(sorted); - } - - - if (test_node_deletion) - { - INFO0("---- Testing Node Deletion ----"); - nodes = xbt_graph_get_nodes(graph); - edges = xbt_graph_get_edges(graph); - INFO2("Before Node deletion: %lu nodes, %lu edges",xbt_dynar_length(nodes), xbt_dynar_length(edges)); - - while (xbt_dynar_length(nodes)) - xbt_graph_free_node(graph,*((xbt_node_t *) xbt_dynar_get_ptr(nodes, 0)),free_label, NULL); - - INFO2("After Node deletion: %lu nodes, %lu edges", - xbt_dynar_length(nodes), xbt_dynar_length(edges)); - } - - if (test_edge_deletion) - { - INFO0("---- Testing Edge Deletion ----"); - nodes = xbt_graph_get_nodes(graph); - edges = xbt_graph_get_edges(graph); - INFO2("Before Edge deletion: %lu nodes, %lu edges", - xbt_dynar_length(nodes), xbt_dynar_length(edges)); - - while (xbt_dynar_length(edges)) - xbt_graph_free_edge(graph,*((xbt_edge_t *) xbt_dynar_get_ptr(edges, 0)),NULL); - - INFO2("After Edge deletion: %lu nodes, %lu edges",xbt_dynar_length(nodes), xbt_dynar_length(edges)); - } - - xbt_graph_free_graph(graph, free_label, NULL, NULL); + int test_node_deletion = 0; + int test_edge_deletion = 0; + int test_export_xml = 1; + int test_export_dot = 1; + int test_export_length = 1; + int test_shortest_paths = 1; + int test_topo_sort = 1; + + int i, j; + unsigned long n; + + xbt_dynar_t edges = NULL; + xbt_dynar_t nodes = NULL; + + xbt_graph_t graph = + xbt_graph_read(graph_file, &node_label_and_data, NULL); + + n = xbt_dynar_length(xbt_graph_get_nodes(graph)); + + if (test_export_xml) { + INFO0("---- Testing XML export. Exporting to testgraph.xml ----"); + xbt_graph_export_graphxml(graph, "testgraph.xml", NULL, NULL, NULL, + NULL); + } + + if (test_export_dot) { + INFO0("---- Testing GraphViz export. Exporting to testgraph.dot ----"); + xbt_graph_export_graphviz(graph, "testgraph.dot", node_name, NULL); + } + + if (test_export_length) { + char *buf = NULL; + double *adj = NULL; + + INFO0("---- Dumping Edge lengths ----"); + adj = xbt_graph_get_length_matrix(graph); + buf = calloc(n * 20, sizeof(char)); + + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + sprintf(buf + strlen(buf), "%le\t", adj[i * n + j]); + } + + INFO1("%s", buf); + buf[0] = '\000'; + } + + free(buf); + free(adj); + } + + if (test_shortest_paths) { + char *buf = NULL; + xbt_node_t *route = NULL; + + INFO0("---- Testing Shortest Paths ----"); + route = xbt_graph_shortest_paths(graph); + buf = calloc(n * 40, sizeof(char)); + + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (route[i * n + j]) + snprintf(buf + strlen(buf), 40, "%s\t", + node_name(route[i * n + j])); + } + + INFO1("%s", buf); + buf[0] = '\000'; + } + + free(buf); + free(route); + } + + if (test_topo_sort) { + xbt_node_t *sorted = NULL; + + INFO0("---- Testing Topological Sort ----"); + sorted = xbt_graph_topo_sort(graph); + + for (i = 0; i < n; i++) { + if (sorted[i]) { + INFO3("sorted[%d] = %s (%p)", i, node_name(sorted[i]), sorted[i]); + } + } + + free(sorted); + } + + + if (test_node_deletion) { + INFO0("---- Testing Node Deletion ----"); + nodes = xbt_graph_get_nodes(graph); + edges = xbt_graph_get_edges(graph); + INFO2("Before Node deletion: %lu nodes, %lu edges", + xbt_dynar_length(nodes), xbt_dynar_length(edges)); + + while (xbt_dynar_length(nodes)) + xbt_graph_free_node(graph, + *((xbt_node_t *) xbt_dynar_get_ptr(nodes, 0)), + free_label, NULL); + + INFO2("After Node deletion: %lu nodes, %lu edges", + xbt_dynar_length(nodes), xbt_dynar_length(edges)); + } + + if (test_edge_deletion) { + INFO0("---- Testing Edge Deletion ----"); + nodes = xbt_graph_get_nodes(graph); + edges = xbt_graph_get_edges(graph); + INFO2("Before Edge deletion: %lu nodes, %lu edges", + xbt_dynar_length(nodes), xbt_dynar_length(edges)); + + while (xbt_dynar_length(edges)) + xbt_graph_free_edge(graph, + *((xbt_edge_t *) xbt_dynar_get_ptr(edges, 0)), + NULL); + + INFO2("After Edge deletion: %lu nodes, %lu edges", + xbt_dynar_length(nodes), xbt_dynar_length(edges)); + } + + xbt_graph_free_graph(graph, free_label, NULL, NULL); } #pragma argsused int main(int argc, char **argv) { - xbt_init(&argc, argv); - - if (argc == 1) - { - fprintf(stderr, "Usage : %s graph.xml\n", argv[0]); - return 1; - } - - test(argv[1]); - - return 0; -} + xbt_init(&argc, argv); + + if (argc == 1) { + fprintf(stderr, "Usage : %s graph.xml\n", argv[0]); + return 1; + } + test(argv[1]); + + return 0; +} diff --git a/win32_testsuite/borland/builder6/simulation/xbt/heap_bench/heap_bench.c b/win32_testsuite/borland/builder6/simulation/xbt/heap_bench/heap_bench.c index 571105daa8..b5e5997d14 100644 --- a/win32_testsuite/borland/builder6/simulation/xbt/heap_bench/heap_bench.c +++ b/win32_testsuite/borland/builder6/simulation/xbt/heap_bench/heap_bench.c @@ -16,108 +16,104 @@ #include #include "xbt/heap.h" -#include "gras/virtu.h" /* time manipulation in bench */ +#include "gras/virtu.h" /* time manipulation in bench */ #define MAX_TEST 1000000 int _XBT_CALL compare_double(const void *a, const void *b); void test_heap_validity(int size); void test_heap_mean_operation(int size); -void test_reset_heap(xbt_heap_t heap,int size); +void test_reset_heap(xbt_heap_t heap, int size); int _XBT_CALL compare_double(const void *a, const void *b) { - double pa, pb; - - pa = *((double *) a); - pb = *((double *) b); - - if (pa > pb) - return 1; - - if (pa == pb) - return 0; - - return -1; + double pa, pb; + + pa = *((double *) a); + pb = *((double *) b); + + if (pa > pb) + return 1; + + if (pa == pb) + return 0; + + return -1; } void test_heap_validity(int size) { - xbt_heap_t heap = xbt_heap_new(size, NULL); - double *tab = calloc(size, sizeof(double)); - int i; - - for (i = 0; i < size; i++) - { - tab[i] = (10.0 * rand() / (RAND_MAX + 1.0)); - xbt_heap_push(heap, NULL, tab[i]); - } - - qsort(tab, size, sizeof(double), compare_double); - - for (i = 0; i < size; i++) - { - /* printf("%lg" " ", xbt_heap_maxkey(heap)); */ - if (xbt_heap_maxkey(heap) != tab[i]) - { - fprintf(stderr, "Problem !\n"); - exit(1); - } - - xbt_heap_pop(heap); - } - - xbt_heap_free(heap); - free(tab); - printf("Validity test complete!\n"); + xbt_heap_t heap = xbt_heap_new(size, NULL); + double *tab = calloc(size, sizeof(double)); + int i; + + for (i = 0; i < size; i++) { + tab[i] = (10.0 * rand() / (RAND_MAX + 1.0)); + xbt_heap_push(heap, NULL, tab[i]); + } + + qsort(tab, size, sizeof(double), compare_double); + + for (i = 0; i < size; i++) { + /* printf("%lg" " ", xbt_heap_maxkey(heap)); */ + if (xbt_heap_maxkey(heap) != tab[i]) { + fprintf(stderr, "Problem !\n"); + exit(1); + } + + xbt_heap_pop(heap); + } + + xbt_heap_free(heap); + free(tab); + printf("Validity test complete!\n"); } void test_heap_mean_operation(int size) { - xbt_heap_t heap = xbt_heap_new(size, NULL); - double val; - double date = 0; - int i, j; - - date = gras_os_time() * 1000000; - - for (i = 0; i < size; i++) - xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0))); - - date = gras_os_time() * 1000000 - date; - - printf("Creation time %d size heap : %g\n", size, date); - - date = gras_os_time() * 1000000; - - for (j = 0; j < MAX_TEST; j++) - { - - if(!(j%size) && j) - test_reset_heap(heap,size); - - val = xbt_heap_maxkey(heap); - xbt_heap_pop(heap); - xbt_heap_push(heap, NULL, 3.0 * val); - } - - date = gras_os_time() * 1000000 - date; - printf("Mean access time for a %d size heap : %g\n", size,date * 1.0 / (MAX_TEST + 0.0)); - - xbt_heap_free(heap); + xbt_heap_t heap = xbt_heap_new(size, NULL); + double val; + double date = 0; + int i, j; + + date = gras_os_time() * 1000000; + + for (i = 0; i < size; i++) + xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0))); + + date = gras_os_time() * 1000000 - date; + + printf("Creation time %d size heap : %g\n", size, date); + + date = gras_os_time() * 1000000; + + for (j = 0; j < MAX_TEST; j++) { + + if (!(j % size) && j) + test_reset_heap(heap, size); + + val = xbt_heap_maxkey(heap); + xbt_heap_pop(heap); + xbt_heap_push(heap, NULL, 3.0 * val); + } + + date = gras_os_time() * 1000000 - date; + printf("Mean access time for a %d size heap : %g\n", size, + date * 1.0 / (MAX_TEST + 0.0)); + + xbt_heap_free(heap); } -void test_reset_heap(xbt_heap_t heap,int size) +void test_reset_heap(xbt_heap_t heap, int size) { - int i; - xbt_heap_free(heap); - heap = xbt_heap_new(size, NULL); - - for (i = 0; i < size; i++) - { - xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0))); - } + int i; + xbt_heap_free(heap); + heap = xbt_heap_new(size, NULL); + + for (i = 0; i < size; i++) { + xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0))); + } } @@ -125,13 +121,13 @@ void test_reset_heap(xbt_heap_t heap,int size) int main(int argc, char **argv) { - int size; - - for (size = 100; size < 10000; size *= 10) - { - test_heap_validity(size); - test_heap_mean_operation(size); - } - return 0; + int size; + + for (size = 100; size < 10000; size *= 10) { + test_heap_validity(size); + test_heap_mean_operation(size); + } + return 0; } + //--------------------------------------------------------------------------- diff --git a/win32_testsuite/borland/builder6/simulation/xbt/log_usage/log_usage.c b/win32_testsuite/borland/builder6/simulation/xbt/log_usage/log_usage.c index e5922d164c..7cd1afc001 100644 --- a/win32_testsuite/borland/builder6/simulation/xbt/log_usage/log_usage.c +++ b/win32_testsuite/borland/builder6/simulation/xbt/log_usage/log_usage.c @@ -10,20 +10,20 @@ #include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(test, top,"Logging specific to this test"); -XBT_LOG_NEW_CATEGORY(top,"Useless test channel"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(test, top, + "Logging specific to this test"); +XBT_LOG_NEW_CATEGORY(top, "Useless test channel"); #pragma argsused int main(int argc, char **argv) { - xbt_init(&argc,argv); - - DEBUG1("val=%d", 1); - WARN1("val=%d", 2); - CDEBUG2(top, "val=%d%s", 3, "!"); - CRITICAL6("false alarm%s%s%s%s%s%s", "","","","","","!"); - - return 0; -} + xbt_init(&argc, argv); + + DEBUG1("val=%d", 1); + WARN1("val=%d", 2); + CDEBUG2(top, "val=%d%s", 3, "!"); + CRITICAL6("false alarm%s%s%s%s%s%s", "", "", "", "", "", "!"); + return 0; +}