Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/gen Add one more naive unit test.



details:   https://anonhg.NetBSD.org/src/rev/88828e163bd2
branches:  trunk
changeset: 764853:88828e163bd2
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Mon May 09 09:27:37 2011 +0000

description:
Add one more naive unit test.

diffstat:

 tests/lib/libc/gen/t_raise.c |  48 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 43 insertions(+), 5 deletions(-)

diffs (100 lines):

diff -r 37d3d7844df2 -r 88828e163bd2 tests/lib/libc/gen/t_raise.c
--- a/tests/lib/libc/gen/t_raise.c      Mon May 09 09:06:28 2011 +0000
+++ b/tests/lib/libc/gen/t_raise.c      Mon May 09 09:27:37 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_raise.c,v 1.3 2011/04/05 14:04:42 jruoho Exp $ */
+/*     $NetBSD: t_raise.c,v 1.4 2011/05/09 09:27:37 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_raise.c,v 1.3 2011/04/05 14:04:42 jruoho Exp $");
+__RCSID("$NetBSD: t_raise.c,v 1.4 2011/05/09 09:27:37 jruoho Exp $");
 
 #include <atf-c.h>
 
@@ -39,11 +39,12 @@
 #include <unistd.h>
 
 static bool    fail;
-static void    handler(int);
+static void    handler_err(int);
+static void    handler_ret(int);
 static int     sig[] = { SIGALRM, SIGIO, SIGUSR1, SIGUSR2, SIGPWR };
 
 static void
-handler(int signo)
+handler_err(int signo)
 {
        size_t i;
 
@@ -56,6 +57,15 @@
        }
 }
 
+static void
+handler_ret(int signo)
+{
+
+       (void)sleep(1);
+
+       fail = false;
+}
+
 ATF_TC(raise_err);
 ATF_TC_HEAD(raise_err, tc)
 {
@@ -74,6 +84,33 @@
        }
 }
 
+ATF_TC(raise_ret);
+ATF_TC_HEAD(raise_ret, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test return order of raise(3)");
+}
+
+ATF_TC_BODY(raise_ret, tc)
+{
+       struct sigaction sa;
+
+       fail = true;
+
+       sa.sa_flags = 0;
+       sa.sa_handler = handler_ret;
+
+       /*
+        * Verify that raise(3) does not return
+        * before the signal handler returns.
+        */
+       ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0);
+       ATF_REQUIRE(sigaction(SIGUSR1, &sa, 0) == 0);
+       ATF_REQUIRE(raise(SIGUSR1) == 0);
+
+       if (fail != false)
+               atf_tc_fail("raise(3) returned before signal handler");
+}
+
 ATF_TC(raise_sig);
 ATF_TC_HEAD(raise_sig, tc)
 {
@@ -96,7 +133,7 @@
                tv.tv_nsec = 2;
 
                sa.sa_flags = 0;
-               sa.sa_handler = handler;
+               sa.sa_handler = handler_err;
 
                ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0);
                ATF_REQUIRE(sigaction(sig[i], &sa, 0) == 0);
@@ -112,6 +149,7 @@
 ATF_TP_ADD_TCS(tp)
 {
        ATF_TP_ADD_TC(tp, raise_err);
+       ATF_TP_ADD_TC(tp, raise_ret);
        ATF_TP_ADD_TC(tp, raise_sig);
 
        return atf_no_error();



Home | Main Index | Thread Index | Old Index