Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/sys Simplify.



details:   https://anonhg.NetBSD.org/src/rev/afafd3e23598
branches:  trunk
changeset: 769674:afafd3e23598
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sat Sep 17 18:52:21 2011 +0000

description:
Simplify.

diffstat:

 tests/lib/libc/sys/Makefile         |    4 +-
 tests/lib/libc/sys/t_timer_create.c |  358 +++++++++--------------------------
 2 files changed, 95 insertions(+), 267 deletions(-)

diffs (truncated from 447 to 300 lines):

diff -r 6eee7a71b0bb -r afafd3e23598 tests/lib/libc/sys/Makefile
--- a/tests/lib/libc/sys/Makefile       Sat Sep 17 18:08:35 2011 +0000
+++ b/tests/lib/libc/sys/Makefile       Sat Sep 17 18:52:21 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.7 2011/07/18 23:16:11 jym Exp $
+# $NetBSD: Makefile,v 1.8 2011/09/17 18:52:21 jruoho Exp $
 
 MKMAN= no
 
@@ -32,6 +32,7 @@
 TESTS_C+=              t_msync
 TESTS_C+=              t_nanosleep
 TESTS_C+=              t_poll
+TESTS_C+=              t_ptrace
 TESTS_C+=              t_revoke
 TESTS_C+=              t_select
 TESTS_C+=              t_setrlimit
@@ -46,7 +47,6 @@
 SRCS.t_mprotect=       t_mprotect.c ${SRCS_EXEC_PROT}
 
 LDADD.t_getpid+=        -lpthread
-LDADD.t_timer_create+=  -lpthread
 
 WARNS=                 4
 
diff -r 6eee7a71b0bb -r afafd3e23598 tests/lib/libc/sys/t_timer_create.c
--- a/tests/lib/libc/sys/t_timer_create.c       Sat Sep 17 18:08:35 2011 +0000
+++ b/tests/lib/libc/sys/t_timer_create.c       Sat Sep 17 18:52:21 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_timer_create.c,v 1.1 2011/07/07 06:57:54 jruoho Exp $ */
+/*     $NetBSD: t_timer_create.c,v 1.2 2011/09/17 18:52:21 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -26,78 +26,116 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <atf-c.h>
 #include <errno.h>
-#include <pthread.h>
+#include <stdio.h>
 #include <signal.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
 
-#include <atf-c.h>
-
-#include "../../../h_macros.h"
+static timer_t t;
+static bool fail = true;
 
-static void    timer_signal_create(clockid_t, int);
 static void    timer_signal_handler(int, siginfo_t *, void *);
-static int     timer_wait(time_t);
+static void    timer_signal_create(clockid_t);
 
-#if 0
-/*
- * XXX: SIGEV_THREAD is not yet supported.
- */
-static void    timer_thread_create(clockid_t);
-static void    timer_thread_handler(sigval_t);
-#endif
+static void
+timer_signal_handler(int signo, siginfo_t *si, void *osi)
+{
+       timer_t *tp;
 
-static timer_t t;
-static bool error;
-static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
-static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
+       tp = si->si_value.sival_ptr;
 
-ATF_TC(timer_create_bogus);
-ATF_TC_HEAD(timer_create_bogus, tc)
-{
+       if (*tp == t && signo == SIGALRM)
+               fail = false;
 
-       /* Cf. PR lib/42434. */
-       atf_tc_set_md_var(tc, "descr",
-           "Checks timer_create(2)'s error checking");
+       (void)fprintf(stderr, "%s: %s\n", __func__, strsignal(signo));
 }
 
-ATF_TC_BODY(timer_create_bogus, tc)
+static void
+timer_signal_create(clockid_t cid)
 {
+       struct itimerspec tim;
+       struct sigaction act;
        struct sigevent evt;
+       sigset_t set;
+
+       t = 0;
+       fail = true;
 
        (void)memset(&evt, 0, sizeof(struct sigevent));
+       (void)memset(&act, 0, sizeof(struct sigaction));
+       (void)memset(&tim, 0, sizeof(struct itimerspec));
 
-       evt.sigev_signo = -1;
+       /*
+        * Set handler.
+        */
+       act.sa_flags = SA_SIGINFO;
+       act.sa_sigaction = timer_signal_handler;
+
+       ATF_REQUIRE(sigemptyset(&set) == 0);
+       ATF_REQUIRE(sigemptyset(&act.sa_mask) == 0);
+
+       /*
+        * Block SIGALRM while configuring the timer.
+        */
+       ATF_REQUIRE(sigaction(SIGALRM, &act, NULL) == 0);
+       ATF_REQUIRE(sigaddset(&set, SIGALRM) == 0);
+       ATF_REQUIRE(sigprocmask(SIG_SETMASK, &set, NULL) == 0);
+
+       /*
+        * Create the timer (SIGEV_SIGNAL).
+        */
+       evt.sigev_signo = SIGALRM;
+       evt.sigev_value.sival_ptr = &t;
        evt.sigev_notify = SIGEV_SIGNAL;
 
-       if (timer_create(CLOCK_REALTIME, &evt, &t) == 0)
-               goto fail;
+       ATF_REQUIRE(timer_create(cid, &evt, &t) == 0);
 
-       evt.sigev_signo = SIGUSR1;
-       evt.sigev_notify = SIGEV_THREAD + 100;
-
-       if (timer_create(CLOCK_REALTIME, &evt, &t) == 0)
-               goto fail;
+       /*
+        * Start the timer. After this, unblock the signal.
+        */
+       tim.it_value.tv_sec = 1;
+       tim.it_value.tv_nsec = 0;
 
-       evt.sigev_signo = SIGUSR1;
-       evt.sigev_value.sival_int = 0;
-       evt.sigev_notify = SIGEV_SIGNAL;
-
-       if (timer_create(CLOCK_REALTIME + 100, &evt, &t) == 0)
-               goto fail;
+       ATF_REQUIRE(timer_settime(t, 0, &tim, NULL) == 0);
 
-       t = 0;
+       (void)sigprocmask(SIG_UNBLOCK, &set, NULL);
+       (void)sleep(2);
 
-       return;
-
-fail:
-       atf_tc_fail("timer_create() successful with bogus values");
+       if (fail != false)
+               atf_tc_fail("timer failed to fire");
 }
 
-ATF_TC(timer_create_signal_realtime);
-ATF_TC_HEAD(timer_create_signal_realtime, tc)
+ATF_TC(timer_create_err);
+ATF_TC_HEAD(timer_create_err, tc)
+{
+       /* Cf. PR lib/42434. */
+       atf_tc_set_md_var(tc, "descr", "Check errors from timer_create(2)");
+}
+
+ATF_TC_BODY(timer_create_err, tc)
+{
+       struct sigevent ev;
+
+       (void)memset(&ev, 0, sizeof(struct sigevent));
+
+       errno = 0;
+       ev.sigev_signo = -1;
+       ev.sigev_notify = SIGEV_SIGNAL;
+
+       ATF_REQUIRE_ERRNO(EINVAL, timer_create(CLOCK_REALTIME, &ev, &t) == -1);
+
+       errno = 0;
+       ev.sigev_signo = SIGUSR1;
+       ev.sigev_notify = SIGEV_THREAD + 100;
+
+       ATF_REQUIRE_ERRNO(EINVAL, timer_create(CLOCK_REALTIME, &ev, &t) == -1);
+}
+
+ATF_TC(timer_create_real);
+ATF_TC_HEAD(timer_create_real, tc)
 {
 
        atf_tc_set_md_var(tc, "descr",
@@ -105,18 +143,13 @@
            "SIGEV_SIGNAL");
 }
 
-ATF_TC_BODY(timer_create_signal_realtime, tc)
+ATF_TC_BODY(timer_create_real, tc)
 {
-       int i, signals[6] = {
-               SIGALRM, SIGIO, SIGPROF, SIGUSR1, SIGUSR2, -1
-       };
-
-       for (i = 0; signals[i] > 0; i++)
-               timer_signal_create(CLOCK_REALTIME, signals[i]);
+       timer_signal_create(CLOCK_REALTIME);
 }
 
-ATF_TC(timer_create_signal_monotonic);
-ATF_TC_HEAD(timer_create_signal_monotonic, tc)
+ATF_TC(timer_create_mono);
+ATF_TC_HEAD(timer_create_mono, tc)
 {
 
        atf_tc_set_md_var(tc, "descr",
@@ -124,222 +157,17 @@
            "SIGEV_SIGNAL");
 }
 
-ATF_TC_BODY(timer_create_signal_monotonic, tc)
-{
-       int i, signals[6] = {
-               SIGALRM, SIGIO, SIGPROF, SIGUSR1, SIGUSR2, -1
-       };
-
-       for (i = 0; signals[i] > 0; i++)
-               timer_signal_create(CLOCK_MONOTONIC, signals[i]);
-}
-
-static void
-timer_signal_create(clockid_t cid, int sig)
-{
-       struct itimerspec tim;
-       struct sigaction act;
-       struct sigevent evt;
-       const char *errstr;
-       sigset_t set;
-
-       error = true;
-
-       (void)memset(&evt, 0, sizeof(struct sigevent));
-       (void)memset(&act, 0, sizeof(struct sigaction));
-       (void)memset(&tim, 0, sizeof(struct itimerspec));
-
-       act.sa_flags = SA_SIGINFO;
-       act.sa_sigaction = timer_signal_handler;
-
-       (void)sigemptyset(&act.sa_mask);
-
-       if (sigaction(sig, &act, NULL) != 0) {
-               errstr = "sigaction()";
-               goto fail;
-       }
-
-       (void)sigemptyset(&set);
-       (void)sigaddset(&set, sig);
-
-       if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) {
-               errstr = "sigprocmask()";
-               goto fail;
-       }
-
-       evt.sigev_signo = sig;
-       evt.sigev_value.sival_ptr = &t;
-       evt.sigev_notify = SIGEV_SIGNAL;
-
-       if (timer_create(cid, &evt, &t) != 0) {
-               errstr = "timer_create()";
-               goto fail;
-       }
-
-       tim.it_value.tv_sec = 0;
-       tim.it_value.tv_nsec = 1000 * 1000;
-
-       if (timer_settime(t, 0, &tim, NULL) != 0) {
-               errstr = "timer_settime()";
-               goto fail;
-       }
-
-       if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0) {
-               errstr = "sigprocmask()";
-               goto fail;
-       }
-
-       errno = timer_wait(1);
-
-       if (errno != 0) {
-               errstr = "timer_wait()";
-               goto fail;
-       }
-
-       return;
-
-fail:
-       atf_tc_fail_errno("%s failed (sig %d, clock %d)", errstr, sig, cid);
-}



Home | Main Index | Thread Index | Old Index