libunwind-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Libunwind-devel] [patch] tests/: libunwind sanity checks


From: Jan Kratochvil
Subject: [Libunwind-devel] [patch] tests/: libunwind sanity checks
Date: Thu, 10 May 2007 22:48:25 +0200
User-agent: Mutt/1.4.2.2i

Hi,

during PPC port development the library had too invalid results causing the
testsuite to lock up.  It should safely FAIL instead.

As there are no automatic testsuite timeouts various limitations have been
implemented into the each specific testcase.


2007-04-05  Jan Kratochvil  <address@hidden>

        * tests/test-ptrace.c (target_pid_kill): New function.
        (target_pid, main): TARGET_PID made static, for target_pid_kill ().
        (main): Register target_pid_kill () for atexit(3).

2007-04-04  Jan Kratochvil  <address@hidden>

        * tests/Gtest-dyn1.c, tests/test-async-sig.c, tests/test-ptrace.c:
        Fixed lockups on broken libunwind (as ppc64 is).

2007-03-07  Jan Kratochvil  <address@hidden>

        * tests/test-async-sig.c (do_backtrace): Limit maximum backtrace depth
        to 100 iterations; it workarounds FC6 DWARF-broken glibc.

2006-12-10  Jan Kratochvil  <address@hidden>

        * tests/test-ptrace.c (main): Check for too many unexpected child
        signals, such as the common `SIGSEGV'.

--- libunwind-git-clean/tests/Gtest-dyn1.c      2007-03-08 21:26:26.000000000 
+0100
+++ libunwind-clean/tests/Gtest-dyn1.c  2007-04-04 22:22:59.000000000 +0200
@@ -87,7 +87,7 @@ sighandler (int signal)
   char name[128], off[32];
   unw_word_t ip, offset;
   unw_context_t uc;
-  int count = 0;
+  int count;
 
   if (verbose)
     printf ("caught signal %d\n", signal);
@@ -95,11 +95,21 @@ sighandler (int signal)
   unw_getcontext (&uc);
   unw_init_local (&cursor, &uc);
 
+  count = 0;
   while (!unw_is_signal_frame (&cursor))
-    if (unw_step (&cursor) < 0)
-      panic ("failed to find signal frame!\n");
+    {
+      if (unw_step (&cursor) < 0)
+       panic ("failed to find signal frame!\n");
+
+      if (count++ > 20)
+       {
+         panic ("Too many steps to the signal frame (%d)\n", count);
+         break;
+       }
+    }
   unw_step (&cursor);
 
+  count = 0;
   do
     {
       unw_get_reg (&cursor, UNW_REG_IP, &ip);
@@ -111,6 +121,13 @@ sighandler (int signal)
       if (verbose)
        printf ("ip = %lx <%s%s>\n", (long) ip, name, off);
       ++count;
+
+      if (count > 20)
+       {
+         panic ("Too many steps (%d)\n", count);
+         break;
+       }
+
     }
   while (unw_step (&cursor) > 0);
 
--- libunwind-git-clean/tests/test-async-sig.c  2007-03-08 21:26:26.000000000 
+0100
+++ libunwind-clean/tests/test-async-sig.c      2007-04-04 22:22:59.000000000 
+0200
@@ -41,6 +41,7 @@ struct itimerval interval =
 
 int verbose;
 int nerrors;
+static const int nerrors_max = 100;
 int sigcount;
 
 #define panic(args...)                                 \
@@ -54,6 +55,7 @@ do_backtrace (int may_print, int get_pro
   unw_word_t ip, sp, off;
   unw_context_t uc;
   int ret;
+  int depth = 0;
 
   unw_getcontext (&uc);
   if (unw_init_local (&cursor, &uc) < 0)
@@ -92,6 +94,11 @@ do_backtrace (int may_print, int get_pro
          panic ("FAILURE: unw_step() returned %d for ip=%lx\n",
                 ret, (long) ip);
        }
+      if (depth++ > 100)
+        {
+         panic ("FAILURE: unw_step() looping over %d iterations\n", depth);
+         break;
+        }
     }
   while (ret > 0);
 }
@@ -110,8 +117,10 @@ sighandler (int signal)
     unw_set_caching_policy (unw_local_addr_space, UNW_CACHE_GLOBAL);
   else if (sigcount == 200)
     unw_set_caching_policy (unw_local_addr_space, UNW_CACHE_PER_THREAD);
-  else if (sigcount == 300)
+  else if (sigcount == 300 || nerrors > nerrors_max)
     {
+      if (nerrors > nerrors_max)
+        panic ("Too many errors (%d)\n", nerrors);
       if (nerrors)
        {
          fprintf (stderr, "FAILURE: detected %d errors\n", nerrors);
@@ -147,5 +156,10 @@ main (int argc, char **argv)
       if (0 && verbose)
        printf ("%s: starting backtrace\n", __FUNCTION__);
       do_backtrace (0, (i++ % 100) == 0);
+      if (nerrors > nerrors_max)
+        {
+         panic ("Too many errors (%d)\n", nerrors);
+         exit (-1);
+        }
     }
 }
--- libunwind-git-clean/tests/test-ptrace.c     2007-03-08 21:26:26.000000000 
+0100
+++ libunwind-clean/tests/test-ptrace.c 2007-04-05 16:41:01.000000000 +0200
@@ -48,6 +48,7 @@ main (int argc, char **argv)
 #include <sys/wait.h>
 
 int nerrors;
+static const int nerrors_max = 100;
 int verbose;
 int print_names = 1;
 
@@ -59,6 +60,8 @@ enum
 static unw_addr_space_t as;
 static struct UPT_info *ui;
 
+static int killed;
+
 void
 do_backtrace (pid_t target_pid)
 {
@@ -99,7 +139,7 @@ do_backtrace (pid_t target_pid)
              len = strlen (buf);
              if (len >= sizeof (buf) - 32)
                len = sizeof (buf) - 32;
-             sprintf (buf + len, "+0x%lx", off);
+             sprintf (buf + len, "+0x%lx", (unsigned long) off);
            }
          printf ("%016lx %-32s (sp=%016lx)\n", (long) ip, buf, (long) sp);
        }
@@ -139,6 +179,11 @@ do_backtrace (pid_t target_pid)
                 (long) start_ip);
          break;
        }
+      if (nerrors > nerrors_max)
+        {
+         panic ("Too many errors (%d)!\n", nerrors);
+         break;
+       }
     }
   while (ret > 0);
 
@@ -147,13 +192,18 @@ do_backtrace (pid_t target_pid)
 
   if (verbose)
     printf ("================\n\n");
+}
+
+static pid_t target_pid;
+static void target_pid_kill (void)
+{
+  kill (target_pid, SIGKILL);
 }
 
 int
 main (int argc, char **argv)
 {
   int status, pid, pending_sig, optind = 1, state = 1;
-  pid_t target_pid;
 
   as = unw_create_addr_space (&_UPT_accessors, 0);
   if (!as)
@@ -199,10 +294,11 @@ main (int argc, char **argv)
       execve (argv[optind], argv + optind, environ);
       _exit (-1);
     }
+  atexit (target_pid_kill);
 
   ui = _UPT_create (target_pid);
 
-  while (1)
+  while (nerrors <= nerrors_max)
     {
       pid = wait4 (-1, &status,  0, 0);
       if (pid == -1)
@@ -224,12 +320,16 @@ main (int argc, char **argv)
            }
          else if (WIFSIGNALED (status))
            {
-             panic ("child terminated by signal %d\n", WTERMSIG (status));
+             if (!killed)
+               panic ("child terminated by signal %d\n", WTERMSIG (status));
              break;
            }
          else
            {
              pending_sig = WSTOPSIG (status);
+             /* Avoid deadlock:  */
+             if (WSTOPSIG (status) == SIGKILL)
+               break;
              if (trace_mode == TRIGGER)
                {
                  if (WSTOPSIG (status) == SIGUSR1)
@@ -237,6 +337,17 @@ main (int argc, char **argv)
                  else if  (WSTOPSIG (status) == SIGUSR2)
                    state = 1;
                }
+             if (WSTOPSIG (status) != SIGUSR1 && WSTOPSIG (status) != SIGUSR2)
+               {
+                 static int count = 0;
+
+                 if (count++ > 100)
+                   {
+                     panic ("Too many child unexpected signals (now %d)\n",
+                            WSTOPSIG (status));
+                       killed = 1;
+                   }
+               }
            }
        }
 
@@ -264,6 +375,8 @@ main (int argc, char **argv)
          ptrace (PTRACE_SINGLESTEP, target_pid, 0, pending_sig);
          break;
        }
+      if (killed)
+        kill (target_pid, SIGKILL);
     }
 
   _UPT_destroy (ui);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]