X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/06bae8eb4bc956a5ee70ec1d3cdbc5e7e782536f..6d14c1b85abceee6c22915a6d8e8c4d49e8f3b03:/tools/tesh/run_context.c diff --git a/tools/tesh/run_context.c b/tools/tesh/run_context.c index 26221267f8..6f046dfa49 100644 --- a/tools/tesh/run_context.c +++ b/tools/tesh/run_context.c @@ -1,6 +1,6 @@ /* run_context -- stuff in which TESH runs a command */ -/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team. +/* Copyright (c) 2007-2014. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -13,6 +13,7 @@ #include #include #include +#include /* floor */ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh); @@ -78,13 +79,13 @@ void rctx_init(void) struct sigaction newact; int i; fg_job = 0; - bg_jobs = xbt_dynar_new_sync(sizeof(rctx_t), kill_it); + bg_jobs = xbt_dynar_new(sizeof(rctx_t), kill_it); armageddon_mutex = xbt_os_mutex_init(); armageddon_initiator = NULL; sigwaiter_mutex = xbt_os_mutex_init(); sigwaiter_cond = xbt_os_cond_init(); xbt_os_mutex_acquire(sigwaiter_mutex); - sigwaiter_thread = xbt_os_thread_create("Armaggedon request waiter", + sigwaiter_thread = xbt_os_thread_create("Armageddon request waiter", armageddon_sigwaiter, NULL, NULL); /* Wait for thread to start... */ xbt_os_cond_wait(sigwaiter_cond, sigwaiter_mutex); @@ -133,7 +134,10 @@ static void rctx_armageddon_kill_one(rctx_t initiator, const char *filepos, if (!rctx->reader_done) { rctx->interrupted = 1; kill(rctx->pid, SIGTERM); - usleep(100); + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9; + nanosleep (&ts, NULL); kill(rctx->pid, SIGKILL); } xbt_os_mutex_release(rctx->interruption); @@ -169,7 +173,10 @@ void rctx_armageddon(rctx_t initiator, int exitcode) } /* Give runner threads a chance to acknowledge the processes deaths */ - usleep(10000); + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (10000e-6 - floor(10000e-6)) * 1e9; + nanosleep (&ts, NULL); /* Ensure that nobody is running rctx_wait on exit */ if (fg_job) xbt_os_mutex_acquire(rctx->interruption); @@ -318,6 +325,7 @@ void rctx_pushline(const char *filepos, char kind, char *line) rctx->is_empty = 0; xbt_strbuff_append(rctx->output_wanted, line); xbt_strbuff_append(rctx->output_wanted, "\n"); + XBT_DEBUG("wanted:%s",rctx->output_wanted->data); break; case '!': @@ -410,8 +418,12 @@ static void *thread_writer(void *r) } XBT_DEBUG("written %d chars so far", posw); - if (got <= 0) - usleep(100); + if (got <= 0){ + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9; + nanosleep (&ts, NULL); + } } rctx->input->data[0] = '\0'; rctx->input->used = 0; @@ -438,7 +450,10 @@ static void *thread_reader(void *r) buffout[posr] = '\0'; xbt_strbuff_append(rctx->output_got, buffout); } else { - usleep(100); + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9; + nanosleep (&ts, NULL); } } while (!rctx->timeout && posr != 0); free(buffout); @@ -697,7 +712,10 @@ void *rctx_wait(void *r) /* Wait for the child to die or the timeout to happen (or an armageddon to happen) */ while (!rctx->reader_done && (rctx->end_time < 0 || rctx->end_time >= now)) { - usleep(100); + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9; + nanosleep (&ts, NULL); now = time(NULL); } @@ -706,7 +724,10 @@ void *rctx_wait(void *r) XBT_INFO("<%s> timeouted. Kill the process.", rctx->filepos); rctx->timeout = 1; kill(rctx->pid, SIGTERM); - usleep(100); + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (100e-6 - floor(100e-6)) * 1e9; + nanosleep (&ts, NULL); kill(rctx->pid, SIGKILL); } @@ -721,7 +742,7 @@ void *rctx_wait(void *r) return NULL; xbt_os_mutex_acquire(rctx->interruption); */ - { + { // Sorting output got xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n"); xbt_dynar_t b = xbt_dynar_new(sizeof(char *), NULL); unsigned cpt; @@ -756,10 +777,24 @@ void *rctx_wait(void *r) xbt_dynar_free(&a); } + if (rctx->output_sort) { // Sorting output wanted + char *newbuf; + xbt_dynar_t a = xbt_str_split(rctx->output_wanted->data, "\n"); + + stable_sort(a); + /* If empty lines moved in first position, remove them */ + while (!xbt_dynar_is_empty(a) && *xbt_dynar_getfirst_as(a, char*) == '\0') + xbt_dynar_shift(a, NULL); + + newbuf = xbt_str_join(a, "\n"); + strcpy(rctx->output_wanted->data, newbuf); + rctx->output_wanted->used = strlen(newbuf); + xbt_free(newbuf); + + xbt_dynar_free(&a); + } xbt_strbuff_chomp(rctx->output_got); xbt_strbuff_chomp(rctx->output_wanted); - xbt_strbuff_trim(rctx->output_got); - xbt_strbuff_trim(rctx->output_wanted); /* Check for broken pipe */ if (rctx->brokenpipe) @@ -775,7 +810,7 @@ void *rctx_wait(void *r) XBT_INFO("<%s> No output before timeout", rctx->filepos); XBT_ERROR("Test suite `%s': NOK (<%s> timeout after %d sec)", testsuite_name, rctx->filepos, timeout_value); - XBT_DEBUG("<%s> Interrupted = %d", rctx->filepos, rctx->interrupted); + XBT_DEBUG("<%s> Interrupted = %d", rctx->filepos, (int)rctx->interrupted); if (!rctx->interrupted) { xbt_os_mutex_release(rctx->interruption); rctx_armageddon(rctx, 3); @@ -834,7 +869,7 @@ void *rctx_wait(void *r) xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n"); char *out = xbt_str_join(a, "\n||"); xbt_dynar_free(&a); - XBT_INFO("Output of <%s> so far: \n||%s", rctx->filepos, out); + XBT_INFO("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 @@ -856,7 +891,7 @@ void *rctx_wait(void *r) xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n"); char *out = xbt_str_join(a, "\n||"); xbt_dynar_free(&a); - XBT_INFO("Here is the (ignored) command output: \n||%s", out); + XBT_INFO("Here is the (ignored) command output:\n||%s", out); free(out); }