Module Name: src
Committed By: jruoho
Date: Sat Oct 15 06:42:17 UTC 2011
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/kernel: Makefile
src/tests/lib/libc/sys: Makefile
Added Files:
src/tests/lib/libc/sys: t_clock_gettime.c
Removed Files:
src/tests/kernel: t_time.c
Log Message:
Move the clock_gettime(2) timer test to the right place.
To generate a diff of this commit:
cvs rdiff -u -r1.405 -r1.406 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.17 -r1.18 src/tests/kernel/Makefile
cvs rdiff -u -r1.2 -r0 src/tests/kernel/t_time.c
cvs rdiff -u -r1.12 -r1.13 src/tests/lib/libc/sys/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/sys/t_clock_gettime.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.405 src/distrib/sets/lists/tests/mi:1.406
--- src/distrib/sets/lists/tests/mi:1.405 Sat Oct 15 06:33:46 2011
+++ src/distrib/sets/lists/tests/mi Sat Oct 15 06:42:17 2011
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.405 2011/10/15 06:33:46 jruoho Exp $
+# $NetBSD: mi,v 1.406 2011/10/15 06:42:17 jruoho Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -332,7 +332,7 @@
./usr/libdata/debug/usr/tests/kernel/t_pty.debug tests-kernel-tests debug,atf
./usr/libdata/debug/usr/tests/kernel/t_rnd.debug tests-kernel-tests debug,atf
./usr/libdata/debug/usr/tests/kernel/t_sigaction.debug tests-kernel-tests debug,atf
-./usr/libdata/debug/usr/tests/kernel/t_time.debug tests-kernel-tests debug,atf
+./usr/libdata/debug/usr/tests/kernel/t_time.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/kernel/t_ucontext.debug tests-kernel-tests debug,atf
./usr/libdata/debug/usr/tests/kernel/t_writev.debug tests-kernel-tests debug,atf
./usr/libdata/debug/usr/tests/kernel/tty tests-kernel-tests
@@ -488,6 +488,7 @@
./usr/libdata/debug/usr/tests/lib/libc/sys/t_access.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/sys/t_cerror.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/lib/libc/sys/t_chroot.debug tests-lib-debug debug,atf
+./usr/libdata/debug/usr/tests/lib/libc/sys/t_clock_gettime.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/sys/t_clone.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libc/sys/t_context.debug tests-obsolete obsolete
./usr/libdata/debug/usr/tests/lib/libc/sys/t_dup.debug tests-lib-debug debug,atf
@@ -1859,7 +1860,7 @@
./usr/tests/kernel/t_pty tests-kernel-tests atf
./usr/tests/kernel/t_rnd tests-kernel-tests atf
./usr/tests/kernel/t_sigaction tests-kernel-tests atf
-./usr/tests/kernel/t_time tests-kernel-tests atf
+./usr/tests/kernel/t_time tests-obsolete obsolete
./usr/tests/kernel/t_ucontext tests-kernel-tests atf
./usr/tests/kernel/t_umount tests-kernel-tests atf
./usr/tests/kernel/t_writev tests-kernel-tests atf
@@ -2103,6 +2104,7 @@
./usr/tests/lib/libc/sys/t_access tests-lib-tests atf
./usr/tests/lib/libc/sys/t_cerror tests-obsolete obsolete
./usr/tests/lib/libc/sys/t_chroot tests-lib-tests atf
+./usr/tests/lib/libc/sys/t_clock_gettime tests-lib-tests atf
./usr/tests/lib/libc/sys/t_clone tests-lib-tests atf
./usr/tests/lib/libc/sys/t_context tests-obsolete obsolete
./usr/tests/lib/libc/sys/t_dup tests-lib-tests atf
Index: src/tests/kernel/Makefile
diff -u src/tests/kernel/Makefile:1.17 src/tests/kernel/Makefile:1.18
--- src/tests/kernel/Makefile:1.17 Sat Oct 15 06:33:45 2011
+++ src/tests/kernel/Makefile Sat Oct 15 06:42:16 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.17 2011/10/15 06:33:45 jruoho Exp $
+# $NetBSD: Makefile,v 1.18 2011/10/15 06:42:16 jruoho Exp $
NOMAN= # defined
@@ -12,7 +12,6 @@ TESTS_C= t_lock
TESTS_C+= t_lwpctl
TESTS_C+= t_pty
TESTS_C+= t_rnd
-TESTS_C+= t_time
TESTS_C+= t_ucontext
TESTS_C+= t_writev
TESTS_C+= t_extattrctl
Index: src/tests/lib/libc/sys/Makefile
diff -u src/tests/lib/libc/sys/Makefile:1.12 src/tests/lib/libc/sys/Makefile:1.13
--- src/tests/lib/libc/sys/Makefile:1.12 Sat Oct 15 06:26:34 2011
+++ src/tests/lib/libc/sys/Makefile Sat Oct 15 06:42:16 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.12 2011/10/15 06:26:34 jruoho Exp $
+# $NetBSD: Makefile,v 1.13 2011/10/15 06:42:16 jruoho Exp $
MKMAN= no
@@ -10,6 +10,7 @@ TESTSDIR= ${TESTSBASE}/lib/libc/sys
TESTS_C+= t_access
TESTS_C+= t_chroot
+TESTS_C+= t_clock_gettime
TESTS_C+= t_clone
TESTS_C+= t_dup
TESTS_C+= t_fsync
Added files:
Index: src/tests/lib/libc/sys/t_clock_gettime.c
diff -u /dev/null src/tests/lib/libc/sys/t_clock_gettime.c:1.1
--- /dev/null Sat Oct 15 06:42:17 2011
+++ src/tests/lib/libc/sys/t_clock_gettime.c Sat Oct 15 06:42:16 2011
@@ -0,0 +1,212 @@
+/* $NetBSD: t_clock_gettime.c,v 1.1 2011/10/15 06:42:16 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Frank Kardel.
+ *
+ * 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.
+ */
+
+/*-
+ * Copyright (c) 2006 Frank Kardel
+ * All rights reserved.
+ *
+ * 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>
+__COPYRIGHT("@(#) Copyright (c) 2008\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_clock_gettime.c,v 1.1 2011/10/15 06:42:16 jruoho Exp $");
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+#include <machine/int_limits.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "../../../h_macros.h"
+
+#define MINPOSDIFF 15000000 /* 15 ms for now */
+#define TIMEOUT 5
+
+#define TC_HARDWARE "kern.timecounter.hardware"
+#define TC_CHOICE "kern.timecounter.choice"
+
+static void
+check_timecounter(void)
+{
+ struct timespec tsa, tsb, tsl, res;
+ long long mindiff = INTMAX_MAX;
+ time_t endlimit;
+
+#define CL(x) \
+ do { \
+ if ((x) != -1) \
+ break; \
+ atf_tc_fail_nonfatal("%s: %s", #x, strerror(errno)); \
+ return; \
+ } while (0)
+
+ CL(clock_gettime(CLOCK_REALTIME, &tsa));
+ tsl = tsa;
+
+ CL(time(&endlimit));
+ endlimit += TIMEOUT + 1;
+
+ while ((time_t)tsa.tv_sec < endlimit) {
+ long long diff;
+
+ CL(clock_gettime(CLOCK_REALTIME, &tsb));
+ diff = 1000000000LL * (tsb.tv_sec - tsa.tv_sec)
+ + tsb.tv_nsec - tsa.tv_nsec;
+
+ if (diff > 0 && mindiff > diff)
+ mindiff = diff;
+
+ if (diff < 0 || diff > MINPOSDIFF) {
+ long long elapsed;
+ (void)printf("%stime TSA: 0x%jx.%08jx, TSB: 0x%jx.%08jx, "
+ "diff = %lld nsec, ", (diff < 0) ? "BAD " : "",
+ (uintmax_t)tsa.tv_sec, (uintmax_t)tsa.tv_nsec,
+ (uintmax_t)tsb.tv_sec, (uintmax_t)tsb.tv_nsec, diff);
+
+ elapsed = 1000000000LL * (tsb.tv_sec - tsl.tv_sec)
+ + tsb.tv_nsec - tsl.tv_nsec;
+
+
+ (void)printf("%lld nsec\n", elapsed);
+ tsl = tsb;
+
+ ATF_CHECK(diff >= 0);
+ if (diff < 0)
+ return;
+ }
+
+ tsa.tv_sec = tsb.tv_sec;
+ tsa.tv_nsec = tsb.tv_nsec;
+ }
+
+ if (clock_getres(CLOCK_REALTIME, &res) == 0) {
+ long long r = res.tv_sec * 1000000000 + res.tv_nsec;
+
+ (void)printf("Claimed resolution: %lld nsec (%f Hz) or "
+ "better\n", r, 1.0 / r * 1e9);
+ (void)printf("Observed minimum non zero delta: %lld "
+ "nsec\n", mindiff);
+ }
+
+#undef CL
+}
+
+ATF_TC(clock_gettime_real);
+ATF_TC_HEAD(clock_gettime_real, tc)
+{
+ atf_tc_set_md_var(tc, "require.user", "root");
+ atf_tc_set_md_var(tc, "descr",
+ "Checks the monotonicity of the CLOCK_REALTIME implementation");
+ atf_tc_set_md_var(tc, "timeout", "300");
+}
+
+ATF_TC_BODY(clock_gettime_real, tc)
+{
+ char name[128], cbuf[512], ctrbuf[10240];
+ size_t cbufsiz = sizeof(cbuf);
+ size_t ctrbufsiz = sizeof(ctrbuf);
+ const char *p;
+ char *save;
+ int quality, n;
+
+ if (sysctlbyname(TC_HARDWARE, cbuf, &cbufsiz, NULL, 0) != 0) {
+ (void)printf("\nChecking legacy time implementation "
+ "for %d seconds\n", TIMEOUT);
+ check_timecounter();
+ return;
+ /* NOTREACHED */
+ }
+ (void)printf("%s = %s\n", TC_HARDWARE, cbuf);
+ REQUIRE_LIBC(save = strdup(cbuf), NULL);
+
+ RL(sysctlbyname(TC_CHOICE, ctrbuf, &ctrbufsiz, NULL, 0));
+ (void)printf("%s = %s\n", TC_CHOICE, ctrbuf);
+
+ for (p = ctrbuf, n = 0; sscanf(p, "%127[^(](q=%d, f=%*u Hz)%*[ ]%n",
+ name, &quality, &n) == 2; p += n) {
+ struct timespec ts;
+ int ret;
+
+ if (quality < 0)
+ continue;
+
+ (void)printf("\nChecking %s for %d seconds\n", name, TIMEOUT);
+ CHECK_LIBC(ret = sysctlbyname(TC_HARDWARE, NULL, 0,
+ name, strlen(name)), -1);
+ if (ret == -1)
+ continue;
+
+ /* wait a bit to select new counter in clockinterrupt */
+ ts.tv_sec = 0;
+ ts.tv_nsec = 100000000;
+ (void)nanosleep(&ts, NULL);
+
+ check_timecounter();
+ }
+
+ RL(sysctlbyname(TC_HARDWARE, NULL, 0, save, strlen(save)));
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, clock_gettime_real);
+
+ return atf_no_error();
+}