When testcase is killed by unexpected signal, usually it just prints
signal's value.
        fcntl30     1  TBROK  :  unexpected signal 2 received (pid = 6714).
        fcntl30     2  TBROK  :  Remaining cases broken

Here we also print signal's name to output more informative message.
        fcntl30     1  TBROK  :  unexpected signal SIGINT(2) received (pid = 
9872).
        fcntl30     2  TBROK  :  Remaining cases broken

Signed-off-by: Xiaoguang Wang <[email protected]>
---
 lib/errnos.h  |  2 +-
 lib/signame.h | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/tst_res.c |  3 ++
 lib/tst_sig.c |  4 ++-
 4 files changed, 99 insertions(+), 2 deletions(-)
 create mode 100644 lib/signame.h

diff --git a/lib/errnos.h b/lib/errnos.h
index 8e80e07..bb42233 100644
--- a/lib/errnos.h
+++ b/lib/errnos.h
@@ -27,7 +27,7 @@
 
 static const char *strerrnodef(int err)
 {
-       struct pair errno_pairs[] = {
+       static struct pair errno_pairs[] = {
                {.name = "SUCCESS", .val = 0},
                /* asm-generic/errno-base.h */
                PAIR(EPERM)
diff --git a/lib/signame.h b/lib/signame.h
new file mode 100644
index 0000000..77eabc1
--- /dev/null
+++ b/lib/signame.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+const char *strsignaldef(int sig)
+{
+       static const struct pair signal_pairs[] = {
+               PAIR(SIGHUP)
+               PAIR(SIGINT)
+               PAIR(SIGQUIT)
+               PAIR(SIGILL)
+       #ifdef SIGTRAP
+               PAIR(SIGTRAP)
+       #endif
+               /* SIGIOT same as SIGABRT, skipped */
+               PAIR(SIGABRT)
+       #ifdef SIGEMT
+               PAIR(SIGEMT)
+       #endif
+       #ifdef SIGBUS
+               PAIR(SIGBUS)
+       #endif
+               PAIR(SIGFPE)
+               PAIR(SIGKILL)
+               PAIR(SIGUSR1)
+               PAIR(SIGSEGV)
+               PAIR(SIGUSR2)
+               PAIR(SIGPIPE)
+               PAIR(SIGALRM)
+               PAIR(SIGTERM)
+       #ifdef SIGSTKFLT
+               PAIR(SIGSTKFLT)
+       #endif
+               /* SIGCLD same as SIGCHLD, skipped */
+               PAIR(SIGCHLD)
+               PAIR(SIGCONT)
+               PAIR(SIGSTOP)
+               PAIR(SIGTSTP)
+               PAIR(SIGTTIN)
+               PAIR(SIGTTOU)
+       #ifdef SIGURG
+               PAIR(SIGURG)
+       #endif
+       #ifdef SIGXCPU
+               PAIR(SIGXCPU)
+       #endif
+       #ifdef SIGXFSZ
+               PAIR(SIGXFSZ)
+       #endif
+       #ifdef SIGVTALRM
+               PAIR(SIGVTALRM)
+       #endif
+       #ifdef SIGPROF
+               PAIR(SIGPROF)
+       #endif
+       #ifdef SIGWINCH
+               PAIR(SIGWINCH)
+       #endif
+       #if defined(SIGIO) || defined(SIGPOLL)
+               /* SIGPOLL same as SIGIO, skipped */
+               PAIR(SIGIO)
+       #endif
+       #ifdef SIGINFO
+               PAIR(SIGINFO)
+       #endif
+       #ifdef SIGLOST
+               PAIR(SIGLOST)
+       #endif
+       #ifdef SIGPWR
+               PAIR(SIGPWR)
+       #endif
+       #if defined(SIGUNUSED) || defined(SIGSYS)
+               /* SIGUNUSED same as SIGSYS, skipped */
+               PAIR(SIGSYS)
+       #endif
+       };
+
+       PAIR_LOOKUP(signal_pairs, sig);
+};
diff --git a/lib/tst_res.c b/lib/tst_res.c
index 8faa5a9..f19e5ab 100644
--- a/lib/tst_res.c
+++ b/lib/tst_res.c
@@ -220,6 +220,9 @@ const char *strttype(int ttype)
  */
 #include "errnos.h"
 
+/* Include table of signals and strsignaldef() function*/
+#include "signame.h"
+
 /*
  * tst_res() - Main result reporting function.  Handle test information
  *             appropriately depending on output display mode.  Call
diff --git a/lib/tst_sig.c b/lib/tst_sig.c
index 2ffe610..58ab4b3 100644
--- a/lib/tst_sig.c
+++ b/lib/tst_sig.c
@@ -235,6 +235,7 @@ void tst_sig(int fork_flag, void (*handler) (), void 
(*cleanup) ())
        }                       /* endfor */
 }
 
+const char *strsignaldef(int sig);
 /****************************************************************************
  * def_handler() : default signal handler that is invoked when
  *      an unexpected signal is caught.
@@ -246,7 +247,8 @@ static void def_handler(int sig)
         * Break remaining test cases, do any cleanup, then exit
         */
        tst_brkm(TBROK, T_cleanup,
-                "unexpected signal %d received (pid = %d).", sig, getpid());
+                "unexpected signal %s(%d) received (pid = %d).",
+                strsignaldef(sig), sig, getpid());
 }
 
 /*
-- 
1.8.2.1


------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to