OSDN Git Service

test/math: put scalbf test under susv3 legacy define
[uclinux-h8/uClibc.git] / test / test-skeleton.c
index 1b6ae12..7521584 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/wait.h>
 #include <sys/param.h>
 #include <time.h>
+#include <features.h>
 
 /* The test function is normally called `do_test' and it is called
    with argc and argv as the arguments.  We nevertheless provide the
@@ -134,16 +135,17 @@ static void
 __attribute__ ((noreturn))
 timeout_handler (int sig __attribute__ ((unused)))
 {
-  int killed;
+  int killed = 0;
   int status;
+  int i;
 
   /* Send signal.  */
   kill (pid, SIGKILL);
 
   /* Wait for it to terminate.  */
-  int i;
   for (i = 0; i < 5; ++i)
     {
+      struct timespec ts;
       killed = waitpid (pid, &status, WNOHANG|WUNTRACED);
       if (killed != 0)
        break;
@@ -152,7 +154,6 @@ timeout_handler (int sig __attribute__ ((unused)))
         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);
@@ -189,21 +190,38 @@ timeout_handler (int sig __attribute__ ((unused)))
   exit (1);
 }
 
+static void
+__attribute__ ((noreturn))
+handler_killpid(int sig)
+{
+       kill(pid, SIGKILL); /* kill test */
+       signal(sig, SIG_DFL);
+       raise(sig); /* kill ourself */
+       _exit(128 + sig); /* paranoia */
+}
+
 /* We provide the entry point here.  */
 int
 main (int argc, char *argv[])
 {
+#ifdef __ARCH_USE_MMU__
   int direct = 0;      /* Directly call the test function?  */
+#else
+  int direct = 1;
+#endif
   int status;
   int opt;
   unsigned int timeoutfactor = 1;
   pid_t termpid;
+  char *envstr_timeoutfactor;
 
   /* Make uses of freed and uninitialized memory known.  */
+#ifdef __MALLOC_STANDARD__
 #ifndef M_PERTURB
 # define M_PERTURB -6
 #endif
   mallopt (M_PERTURB, 42);
+#endif
 
 #ifdef STDOUT_UNBUFFERED
   setbuf (stdout, NULL);
@@ -227,7 +245,7 @@ main (int argc, char *argv[])
 
   /* 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");
+  envstr_timeoutfactor = getenv ("TIMEOUTFACTOR");
   if (envstr_timeoutfactor != NULL)
     {
       char *envstr_conv = envstr_timeoutfactor;
@@ -281,10 +299,14 @@ main (int argc, char *argv[])
      - set up the timer
      - fork and execute the function.  */
 
+#if defined __ARCH_USE_MMU__ || ! defined __UCLIBC__
   pid = fork ();
   if (pid == 0)
     {
       /* This is the child.  */
+#ifdef RLIMIT_DATA
+      struct rlimit data_limit;
+#endif
 #ifdef RLIMIT_CORE
       /* Try to avoid dumping core.  */
       struct rlimit core_limit;
@@ -295,7 +317,6 @@ main (int argc, char *argv[])
 
 #ifdef RLIMIT_DATA
       /* Try to avoid eating all memory if a test leaks.  */
-      struct rlimit data_limit;
       if (getrlimit (RLIMIT_DATA, &data_limit) == 0)
        {
          if (TEST_DATA_LIMIT == RLIM_INFINITY)
@@ -318,11 +339,16 @@ main (int argc, char *argv[])
       exit (TEST_FUNCTION);
     }
   else if (pid < 0)
+#endif
     {
       perror ("Cannot fork test program");
       exit (1);
     }
 
+  signal (SIGTERM, handler_killpid);
+  signal (SIGINT, handler_killpid);
+  signal (SIGQUIT, handler_killpid);
+
   /* Set timeout.  */
 #ifndef TIMEOUT
   /* Default timeout is two seconds.  */