/* Skeleton for test programs.
- Copyright (C) 1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1998,2000-2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <errno.h>
#include <getopt.h>
+#include <malloc.h>
#include <search.h>
#include <signal.h>
#include <stdio.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <sys/param.h>
+#include <time.h>
/* The test function is normally called `do_test' and it is called
with argc and argv as the arguments. We nevertheless provide the
kill (pid, SIGKILL);
/* Wait for it to terminate. */
- killed = waitpid (pid, &status, WNOHANG|WUNTRACED);
+ int i;
+ for (i = 0; i < 5; ++i)
+ {
+ killed = waitpid (pid, &status, WNOHANG|WUNTRACED);
+ if (killed != 0)
+ break;
+
+ /* Delay, give the system time to process the kill. If the
+ nanosleep() call return prematurely, all the better. We
+ won't restart it since this probably means the child process
+ finally died. */
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 100000000;
+ nanosleep (&ts, NULL);
+ }
if (killed != 0 && killed != pid)
{
- perror ("Failed to killed test process");
+ perror ("Failed to kill test process");
exit (1);
}
exit (0);
#endif
- if (WIFSIGNALED (status) && WTERMSIG (status) == SIGKILL)
+ if (killed == 0 || (WIFSIGNALED (status) && WTERMSIG (status) == SIGKILL))
fputs ("Timed out: killed the child process\n", stderr);
else if (WIFSTOPPED (status))
fprintf (stderr, "Timed out: the child process was %s\n",
int direct = 0; /* Directly call the test function? */
int status;
int opt;
+ unsigned int timeoutfactor = 1;
pid_t termpid;
+ /* Make uses of freed and uninitialized memory known. */
+ mallopt (M_PERTURB, 42);
+
#ifdef STDOUT_UNBUFFERED
setbuf (stdout, NULL);
#endif
#endif
}
+ /* If set, read the test TIMEOUTFACTOR value from the environment.
+ This value is used to scale the default test timeout values. */
+ char *envstr_timeoutfactor = getenv ("TIMEOUTFACTOR");
+ if (envstr_timeoutfactor != NULL)
+ {
+ char *envstr_conv = envstr_timeoutfactor;
+ unsigned long int env_fact;
+
+ env_fact = strtoul (envstr_timeoutfactor, &envstr_conv, 0);
+ if (*envstr_conv == '\0' && envstr_conv != envstr_timeoutfactor)
+ timeoutfactor = MAX (env_fact, 1);
+ }
+
/* Set TMPDIR to specified test directory. */
if (test_dir != NULL)
{
# define TIMEOUT 2
#endif
signal (SIGALRM, timeout_handler);
- alarm (TIMEOUT);
+ alarm (TIMEOUT * timeoutfactor);
/* Wait for the regular termination. */
termpid = TEMP_FAILURE_RETRY (waitpid (pid, &status, 0));
}
/* Simply exit with the return value of the test. */
+#ifndef EXPECTED_STATUS
return WEXITSTATUS (status);
+#else
+ if (WEXITSTATUS (status) != EXPECTED_STATUS)
+ {
+ fprintf (stderr, "Expected status %d, got %d\n",
+ EXPECTED_STATUS, WEXITSTATUS (status));
+ exit (1);
+ }
+
+ return 0;
+#endif
}