Commit 45426a76 authored by Wayne Davison's avatar Wayne Davison

Run each testsuite test with a timeout.

parent dc2a0923
......@@ -28,6 +28,7 @@ config.status
/tests-dont-exist
/testtmp
/tls
/testrun
/trimslash
/t_unsafe
/wildtest
......
......@@ -47,12 +47,12 @@ TLS_OBJ = tls.o syscall.o lib/compat.o lib/snprintf.o lib/permstring.o lib/sysxa
# Programs we must have to run the test cases
CHECK_PROGS = rsync$(EXEEXT) tls$(EXEEXT) getgroups$(EXEEXT) getfsdev$(EXEEXT) \
trimslash$(EXEEXT) t_unsafe$(EXEEXT) wildtest$(EXEEXT)
testrun$(EXEEXT) trimslash$(EXEEXT) t_unsafe$(EXEEXT) wildtest$(EXEEXT)
CHECK_SYMLINKS = testsuite/chown-fake.test testsuite/devices-fake.test
# Objects for CHECK_PROGS to clean
CHECK_OBJS=tls.o getgroups.o getfsdev.o t_stub.o t_unsafe.o trimslash.o wildtest.o
CHECK_OBJS=tls.o testrun.o getgroups.o getfsdev.o t_stub.o t_unsafe.o trimslash.o wildtest.o
# note that the -I. is needed to handle config.h when using VPATH
.c.o:
......@@ -102,6 +102,9 @@ rounding.h: rounding.c rsync.h
tls$(EXEEXT): $(TLS_OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(TLS_OBJ) $(LIBS)
testrun$(EXEEXT): testrun.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ testrun.o
getgroups$(EXEEXT): getgroups.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ getgroups.o $(LIBS)
......
......@@ -262,7 +262,7 @@ do
prep_scratch
set +e
sh $RUNSHFLAGS "$testscript" >"$scratchdir/test.log" 2>&1
"$TOOLDIR/"testrun $RUNSHFLAGS "$testscript" >"$scratchdir/test.log" 2>&1
result=$?
set -e
......
/* Run a testsuite script with a timeout. */
#include "rsync.h"
#define MAX_TEST_SECONDS (3*60)
int main(int argc, char *argv[])
{
pid_t pid;
int status, slept = 0;
if (argc < 2) {
fprintf(stderr, "Usage: testrun [SHELL_OPTIONS] TESTSUITE_SCRIPT [ARGS]\n");
exit(1);
}
if ((pid = fork()) < 0) {
fprintf(stderr, "TESTRUN ERROR: fork failed: %s\n", strerror(errno));
exit(1);
}
if (pid == 0) {
argv[0] = "sh";
execvp(argv[0], argv);
fprintf(stderr, "TESTRUN ERROR: failed to exec %s: %s\n", argv[0], strerror(errno));
_exit(1);
}
while (1) {
int ret = waitpid(pid, &status, WNOHANG);
if (ret > 0)
break;
if (ret < 0) {
if (errno == EINTR)
continue;
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 (kill(pid, SIGTERM) < 0)
fprintf(stderr, "TESTRUN ERROR: failed to kill pid %ld: %s\n", (long)pid, strerror(errno));
else
fprintf(stderr, "TESTRUN INFO: killed pid %ld\n", (long)pid);
exit(1);
}
sleep(1);
}
if (!WIFEXITED(status))
exit(255);
return WEXITSTATUS(status);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment