From 6e9ad2bb0356da85a7ca8283acd3558b39e2138e Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Tue, 15 Dec 2009 08:44:46 -0800 Subject: [PATCH] Allow per-test timeout overrides. Give hardlinks more time. --- runtests.sh | 8 +++++++- testrun.c | 15 +++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/runtests.sh b/runtests.sh index db95d8f7..43732cea 100755 --- a/runtests.sh +++ b/runtests.sh @@ -229,8 +229,9 @@ echo " scratchbase=$scratchbase" [ -d "$scratchbase" ] || mkdir "$scratchbase" suitedir="$srcdir/testsuite" +TESTRUN_TIMEOUT=300 -export scratchdir suitedir +export scratchdir suitedir TESTRUN_TIMEOUT prep_scratch() { [ -d "$scratchdir" ] && chmod -R u+rwX "$scratchdir" && rm -rf "$scratchdir" @@ -261,6 +262,11 @@ do prep_scratch + case "$testscript" in + *hardlinks*) TESTRUN_TIMEOUT=600 ;; + *) TESTRUN_TIMEOUT=300 ;; + esac + set +e "$TOOLDIR/"testrun $RUNSHFLAGS "$testscript" >"$scratchdir/test.log" 2>&1 result=$? diff --git a/testrun.c b/testrun.c index 46c59e89..ddf596d3 100644 --- a/testrun.c +++ b/testrun.c @@ -2,18 +2,25 @@ #include "rsync.h" -#define MAX_TEST_SECONDS (5*60) +#define DEFAULT_TIMEOUT_SECS (5*60) +#define TIMEOUT_ENV "TESTRUN_TIMEOUT" int main(int argc, char *argv[]) { pid_t pid; - int status, slept = 0; + char *timeout_env; + int status, timeout_secs, slept = 0; if (argc < 2) { fprintf(stderr, "Usage: testrun [SHELL_OPTIONS] TESTSUITE_SCRIPT [ARGS]\n"); exit(1); } + if ((timeout_env = getenv(TIMEOUT_ENV)) != NULL) + timeout_secs = atoi(timeout_env); + else + timeout_secs = DEFAULT_TIMEOUT_SECS; + if ((pid = fork()) < 0) { fprintf(stderr, "TESTRUN ERROR: fork failed: %s\n", strerror(errno)); exit(1); @@ -36,8 +43,8 @@ fprintf(stderr, "TESTRUN ERROR: waitpid failed: %s\n", strerror(errno)); exit(1); } - if (slept++ > MAX_TEST_SECONDS) { - fprintf(stderr, "TESTRUN TIMEOUT: test took over %d seconds.\n", MAX_TEST_SECONDS); + if (slept++ > timeout_secs) { + fprintf(stderr, "TESTRUN TIMEOUT: test took over %d seconds.\n", timeout_secs); if (kill(pid, SIGTERM) < 0) fprintf(stderr, "TESTRUN ERROR: failed to kill pid %ld: %s\n", (long)pid, strerror(errno)); else -- 2.34.1