Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Few basic tests for getitimer(2) and setitimer(2).
details: https://anonhg.NetBSD.org/src/rev/0072eeb36732
branches: trunk
changeset: 764746:0072eeb36732
user: jruoho <jruoho%NetBSD.org@localhost>
date: Mon May 02 17:26:23 2011 +0000
description:
Few basic tests for getitimer(2) and setitimer(2).
diffstat:
distrib/sets/lists/tests/mi | 4 +-
tests/syscall/Makefile | 4 +-
tests/syscall/t_itimer.c | 215 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 220 insertions(+), 3 deletions(-)
diffs (262 lines):
diff -r ac8becedff3d -r 0072eeb36732 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Mon May 02 17:14:20 2011 +0000
+++ b/distrib/sets/lists/tests/mi Mon May 02 17:26:23 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.319 2011/05/02 08:32:21 pgoyette Exp $
+# $NetBSD: mi,v 1.320 2011/05/02 17:26:23 jruoho Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -604,6 +604,7 @@
./usr/libdata/debug/usr/tests/syscall/t_getrusage.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_getsid.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_gettimeofday.debug tests-syscall-debug debug,atf
+./usr/libdata/debug/usr/tests/syscall/t_itimer.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_kill.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_mmap.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_mprotect.debug tests-syscall-debug debug,atf
@@ -2285,6 +2286,7 @@
./usr/tests/syscall/t_getrusage tests-syscall-tests atf
./usr/tests/syscall/t_getsid tests-syscall-tests atf
./usr/tests/syscall/t_gettimeofday tests-syscall-tests atf
+./usr/tests/syscall/t_itimer tests-syscall-tests atf
./usr/tests/syscall/t_kill tests-syscall-tests atf
./usr/tests/syscall/t_mmap tests-syscall-tests atf
./usr/tests/syscall/t_mprotect tests-syscall-tests atf
diff -r ac8becedff3d -r 0072eeb36732 tests/syscall/Makefile
--- a/tests/syscall/Makefile Mon May 02 17:14:20 2011 +0000
+++ b/tests/syscall/Makefile Mon May 02 17:26:23 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.25 2011/05/01 09:09:35 jruoho Exp $
+# $NetBSD: Makefile,v 1.26 2011/05/02 17:26:23 jruoho Exp $
.include <bsd.own.mk>
@@ -6,7 +6,7 @@
TESTS_C+= t_access t_cmsg t_dup t_fsync
TESTS_C+= t_getgroups t_getpid t_getrusage t_getsid t_gettimeofday
-TESTS_C+= t_kill t_mmap t_mprotect t_msync t_nanosleep
+TESTS_C+= t_itimer t_kill t_mmap t_mprotect t_msync t_nanosleep
TESTS_C+= t_setrlimit t_setuid t_timer t_umask
LDADD.t_getpid+= -lpthread
diff -r ac8becedff3d -r 0072eeb36732 tests/syscall/t_itimer.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/syscall/t_itimer.c Mon May 02 17:26:23 2011 +0000
@@ -0,0 +1,215 @@
+/* $NetBSD: t_itimer.c,v 1.1 2011/05/02 17:26:23 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jukka Ruohonen.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_itimer.c,v 1.1 2011/05/02 17:26:23 jruoho Exp $");
+
+#include <sys/time.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <limits.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+
+static bool fail;
+static void sighandler(int);
+
+static void
+sighandler(int signo)
+{
+
+ if (signo == SIGALRM || signo == SIGVTALRM)
+ fail = false;
+}
+
+ATF_TC(getitimer_empty);
+ATF_TC_HEAD(getitimer_empty, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "getitimer(2) before setitimer(2)");
+}
+
+ATF_TC_BODY(getitimer_empty, tc)
+{
+ struct itimerval it;
+
+ /*
+ * Verify that the passed structure remains
+ * empty after calling getitimer(2) but before
+ * actually arming the timer with setitimer(2).
+ */
+ (void)memset(&it, 0, sizeof(struct itimerval));
+
+ ATF_REQUIRE(getitimer(ITIMER_REAL, &it) == 0);
+
+ if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0)
+ goto fail;
+
+ ATF_REQUIRE(getitimer(ITIMER_VIRTUAL, &it) == 0);
+
+ if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0)
+ goto fail;
+
+ ATF_REQUIRE(getitimer(ITIMER_PROF, &it) == 0);
+
+ if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0)
+ goto fail;
+
+ return;
+
+fail:
+ atf_tc_fail("getitimer(2) modfied the timer before it was armed");
+}
+
+ATF_TC(getitimer_err);
+ATF_TC_HEAD(getitimer_err, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test errors from getitimer(2)");
+}
+
+ATF_TC_BODY(getitimer_err, tc)
+{
+ struct itimerval it;
+
+ errno = 0;
+ ATF_REQUIRE_ERRNO(EINVAL, getitimer(-1, &it) == -1);
+
+ errno = 0;
+ ATF_REQUIRE_ERRNO(EINVAL, getitimer(INT_MAX, &it) == -1);
+
+ errno = 0;
+ ATF_REQUIRE_ERRNO(EFAULT, getitimer(ITIMER_REAL, (void *)-1) == -1);
+}
+
+ATF_TC(setitimer_basic);
+ATF_TC_HEAD(setitimer_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A basic test of setitimer(2)");
+}
+
+ATF_TC_BODY(setitimer_basic, tc)
+{
+ struct itimerval it;
+
+ it.it_value.tv_sec = 0;
+ it.it_value.tv_usec = 100;
+
+ it.it_interval.tv_sec = 0;
+ it.it_interval.tv_usec = 0;
+
+ fail = true;
+
+ ATF_REQUIRE(signal(SIGALRM, sighandler) != SIG_ERR);
+ ATF_REQUIRE(setitimer(ITIMER_REAL, &it, NULL) == 0);
+
+ /*
+ * Although the interaction between
+ * setitimer(2) and sleep(3) can be
+ * unspecified, it is assumed that one
+ * second suspension will be enough for
+ * the timer to fire.
+ */
+ (void)sleep(1);
+
+ if (fail != false)
+ atf_tc_fail("timer did not fire");
+}
+
+ATF_TC(setitimer_err);
+ATF_TC_HEAD(setitimer_err, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test errors from setitimer(2)");
+}
+
+ATF_TC_BODY(setitimer_err, tc)
+{
+ struct itimerval it, ot;
+
+ errno = 0;
+ ATF_REQUIRE_ERRNO(EINVAL, setitimer(-1, &it, &ot) == -1);
+
+ errno = 0;
+ ATF_REQUIRE_ERRNO(EINVAL, setitimer(INT_MAX, &it, &ot) == -1);
+
+ /*
+ * This fails incorrectly with EPERM.
+ */
+ atf_tc_expect_fail("PR standards/44927");
+
+ errno = 0;
+ ATF_REQUIRE_ERRNO(EFAULT, setitimer(ITIMER_REAL,(void*)-1, &ot) == -1);
+}
+
+ATF_TC(setitimer_old);
+ATF_TC_HEAD(setitimer_old, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Test old values from setitimer(2)");
+}
+
+ATF_TC_BODY(setitimer_old, tc)
+{
+ struct itimerval it, ot;
+
+ /*
+ * Make two calls; the second one
+ * should store the old values.
+ */
+ it.it_value.tv_sec = 4;
+ it.it_value.tv_usec = 3;
+
+ it.it_interval.tv_sec = 0;
+ it.it_interval.tv_usec = 0;
+
+ ATF_REQUIRE(setitimer(ITIMER_REAL, &it, &ot) == 0);
+
+ it.it_value.tv_sec = 2;
+ it.it_value.tv_usec = 1;
+
+ it.it_interval.tv_sec = 0;
+ it.it_interval.tv_usec = 0;
+
+ ATF_REQUIRE(setitimer(ITIMER_REAL, &it, &ot) == 0);
+
+ if (ot.it_value.tv_sec != 4 || ot.it_value.tv_usec != 3)
+ atf_tc_fail("setitimer(2) did not store old values");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, getitimer_empty);
+ ATF_TP_ADD_TC(tp, getitimer_err);
+ ATF_TP_ADD_TC(tp, setitimer_basic);
+ ATF_TP_ADD_TC(tp, setitimer_err);
+ ATF_TP_ADD_TC(tp, setitimer_old);
+
+ return atf_no_error();
+}
Home |
Main Index |
Thread Index |
Old Index