Sun May 1 09:09:35 2011 UTC ()
Few basic tests for nanosleep(2).


(jruoho)
diff -r1.314 -r1.315 src/distrib/sets/lists/tests/mi
diff -r1.24 -r1.25 src/tests/syscall/Makefile
diff -r0 -r1.1 src/tests/syscall/t_nanosleep.c

cvs diff -r1.314 -r1.315 src/distrib/sets/lists/tests/mi (expand / switch to unified diff)

--- src/distrib/sets/lists/tests/mi 2011/05/01 07:22:40 1.314
+++ src/distrib/sets/lists/tests/mi 2011/05/01 09:09:35 1.315
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: mi,v 1.314 2011/05/01 07:22:40 jruoho Exp $ 1# $NetBSD: mi,v 1.315 2011/05/01 09:09:35 jruoho Exp $
2# 2#
3# Note: don't delete entries from here - mark them as "obsolete" instead. 3# Note: don't delete entries from here - mark them as "obsolete" instead.
4# 4#
5./etc/mtree/set.tests tests-sys-root 5./etc/mtree/set.tests tests-sys-root
6./usr/libdata/debug/usr/tests tests-base-debug 6./usr/libdata/debug/usr/tests tests-base-debug
7./usr/libdata/debug/usr/tests/atf tests-atf-debug 7./usr/libdata/debug/usr/tests/atf tests-atf-debug
8./usr/libdata/debug/usr/tests/atf/atf-c tests-atf-debug 8./usr/libdata/debug/usr/tests/atf/atf-c tests-atf-debug
9./usr/libdata/debug/usr/tests/atf/atf-c/atf_c_test.debug tests-atf-debug debug,atf 9./usr/libdata/debug/usr/tests/atf/atf-c/atf_c_test.debug tests-atf-debug debug,atf
10./usr/libdata/debug/usr/tests/atf/atf-c/build_test.debug tests-atf-debug debug,atf 10./usr/libdata/debug/usr/tests/atf/atf-c/build_test.debug tests-atf-debug debug,atf
11./usr/libdata/debug/usr/tests/atf/atf-c/check_test.debug tests-atf-debug debug,atf 11./usr/libdata/debug/usr/tests/atf/atf-c/check_test.debug tests-atf-debug debug,atf
12./usr/libdata/debug/usr/tests/atf/atf-c/config_test.debug tests-atf-debug debug,atf 12./usr/libdata/debug/usr/tests/atf/atf-c/config_test.debug tests-atf-debug debug,atf
13./usr/libdata/debug/usr/tests/atf/atf-c/detail tests-atf-debug 13./usr/libdata/debug/usr/tests/atf/atf-c/detail tests-atf-debug
14./usr/libdata/debug/usr/tests/atf/atf-c/detail/dynstr_test.debug tests-atf-debug debug,atf 14./usr/libdata/debug/usr/tests/atf/atf-c/detail/dynstr_test.debug tests-atf-debug debug,atf
@@ -594,26 +594,27 @@ @@ -594,26 +594,27 @@
594./usr/libdata/debug/usr/tests/syscall/t_access.debug tests-syscall-debug debug,atf 594./usr/libdata/debug/usr/tests/syscall/t_access.debug tests-syscall-debug debug,atf
595./usr/libdata/debug/usr/tests/syscall/t_cmsg.debug tests-syscall-debug debug,atf 595./usr/libdata/debug/usr/tests/syscall/t_cmsg.debug tests-syscall-debug debug,atf
596./usr/libdata/debug/usr/tests/syscall/t_dup.debug tests-syscall-debug debug,atf 596./usr/libdata/debug/usr/tests/syscall/t_dup.debug tests-syscall-debug debug,atf
597./usr/libdata/debug/usr/tests/syscall/t_fsync.debug tests-syscall-debug debug,atf 597./usr/libdata/debug/usr/tests/syscall/t_fsync.debug tests-syscall-debug debug,atf
598./usr/libdata/debug/usr/tests/syscall/t_getgroups.debug tests-syscall-debug debug,atf 598./usr/libdata/debug/usr/tests/syscall/t_getgroups.debug tests-syscall-debug debug,atf
599./usr/libdata/debug/usr/tests/syscall/t_getpid.debug tests-syscall-debug debug,atf 599./usr/libdata/debug/usr/tests/syscall/t_getpid.debug tests-syscall-debug debug,atf
600./usr/libdata/debug/usr/tests/syscall/t_getrusage.debug tests-syscall-debug debug,atf 600./usr/libdata/debug/usr/tests/syscall/t_getrusage.debug tests-syscall-debug debug,atf
601./usr/libdata/debug/usr/tests/syscall/t_getsid.debug tests-syscall-debug debug,atf 601./usr/libdata/debug/usr/tests/syscall/t_getsid.debug tests-syscall-debug debug,atf
602./usr/libdata/debug/usr/tests/syscall/t_gettimeofday.debug tests-syscall-debug debug,atf 602./usr/libdata/debug/usr/tests/syscall/t_gettimeofday.debug tests-syscall-debug debug,atf
603./usr/libdata/debug/usr/tests/syscall/t_kill.debug tests-syscall-debug debug,atf 603./usr/libdata/debug/usr/tests/syscall/t_kill.debug tests-syscall-debug debug,atf
604./usr/libdata/debug/usr/tests/syscall/t_mmap.debug tests-syscall-debug debug,atf 604./usr/libdata/debug/usr/tests/syscall/t_mmap.debug tests-syscall-debug debug,atf
605./usr/libdata/debug/usr/tests/syscall/t_mprotect.debug tests-syscall-debug debug,atf 605./usr/libdata/debug/usr/tests/syscall/t_mprotect.debug tests-syscall-debug debug,atf
606./usr/libdata/debug/usr/tests/syscall/t_msync.debug tests-syscall-debug debug,atf 606./usr/libdata/debug/usr/tests/syscall/t_msync.debug tests-syscall-debug debug,atf
 607./usr/libdata/debug/usr/tests/syscall/t_nanosleep.debug tests-syscall-debug debug,atf
607./usr/libdata/debug/usr/tests/syscall/t_setrlimit.debug tests-syscall-debug debug,atf 608./usr/libdata/debug/usr/tests/syscall/t_setrlimit.debug tests-syscall-debug debug,atf
608./usr/libdata/debug/usr/tests/syscall/t_setuid.debug tests-syscall-debug debug,atf 609./usr/libdata/debug/usr/tests/syscall/t_setuid.debug tests-syscall-debug debug,atf
609./usr/libdata/debug/usr/tests/syscall/t_timer.debug tests-syscall-debug debug,atf 610./usr/libdata/debug/usr/tests/syscall/t_timer.debug tests-syscall-debug debug,atf
610./usr/libdata/debug/usr/tests/syscall/t_umask.debug tests-syscall-debug debug,atf 611./usr/libdata/debug/usr/tests/syscall/t_umask.debug tests-syscall-debug debug,atf
611./usr/libdata/debug/usr/tests/usr.bin tests-sbin-tests 612./usr/libdata/debug/usr/tests/usr.bin tests-sbin-tests
612./usr/libdata/debug/usr/tests/usr.sbin tests-sbin-tests 613./usr/libdata/debug/usr/tests/usr.sbin tests-sbin-tests
613./usr/libdata/debug/usr/tests/util tests-util-debug 614./usr/libdata/debug/usr/tests/util tests-util-debug
614./usr/libdata/debug/usr/tests/util/df tests-util-debug 615./usr/libdata/debug/usr/tests/util/df tests-util-debug
615./usr/libdata/debug/usr/tests/util/df/h_df.debug tests-util-debug debug 616./usr/libdata/debug/usr/tests/util/df/h_df.debug tests-util-debug debug
616./usr/libdata/debug/usr/tests/util/id tests-util-debug 617./usr/libdata/debug/usr/tests/util/id tests-util-debug
617./usr/libdata/debug/usr/tests/util/id/h_id.debug tests-util-debug debug 618./usr/libdata/debug/usr/tests/util/id/h_id.debug tests-util-debug debug
618./usr/libdata/debug/usr/tests/util/systrace tests-obsolete obsolete 619./usr/libdata/debug/usr/tests/util/systrace tests-obsolete obsolete
619./usr/libdata/debug/usr/tests/util/systrace/h_have_systrace.debug tests-obsolete obsolete 620./usr/libdata/debug/usr/tests/util/systrace/h_have_systrace.debug tests-obsolete obsolete
@@ -2269,26 +2270,27 @@ @@ -2269,26 +2270,27 @@
2269./usr/tests/syscall/t_access tests-syscall-tests atf 2270./usr/tests/syscall/t_access tests-syscall-tests atf
2270./usr/tests/syscall/t_cmsg tests-syscall-tests atf 2271./usr/tests/syscall/t_cmsg tests-syscall-tests atf
2271./usr/tests/syscall/t_dup tests-syscall-tests atf 2272./usr/tests/syscall/t_dup tests-syscall-tests atf
2272./usr/tests/syscall/t_fsync tests-syscall-tests atf 2273./usr/tests/syscall/t_fsync tests-syscall-tests atf
2273./usr/tests/syscall/t_getgroups tests-syscall-tests atf 2274./usr/tests/syscall/t_getgroups tests-syscall-tests atf
2274./usr/tests/syscall/t_getpid tests-syscall-tests atf 2275./usr/tests/syscall/t_getpid tests-syscall-tests atf
2275./usr/tests/syscall/t_getrusage tests-syscall-tests atf 2276./usr/tests/syscall/t_getrusage tests-syscall-tests atf
2276./usr/tests/syscall/t_getsid tests-syscall-tests atf 2277./usr/tests/syscall/t_getsid tests-syscall-tests atf
2277./usr/tests/syscall/t_gettimeofday tests-syscall-tests atf 2278./usr/tests/syscall/t_gettimeofday tests-syscall-tests atf
2278./usr/tests/syscall/t_kill tests-syscall-tests atf 2279./usr/tests/syscall/t_kill tests-syscall-tests atf
2279./usr/tests/syscall/t_mmap tests-syscall-tests atf 2280./usr/tests/syscall/t_mmap tests-syscall-tests atf
2280./usr/tests/syscall/t_mprotect tests-syscall-tests atf 2281./usr/tests/syscall/t_mprotect tests-syscall-tests atf
2281./usr/tests/syscall/t_msync tests-syscall-tests atf 2282./usr/tests/syscall/t_msync tests-syscall-tests atf
 2283./usr/tests/syscall/t_nanosleep tests-syscall-tests atf
2282./usr/tests/syscall/t_setrlimit tests-syscall-tests atf 2284./usr/tests/syscall/t_setrlimit tests-syscall-tests atf
2283./usr/tests/syscall/t_setuid tests-syscall-tests atf 2285./usr/tests/syscall/t_setuid tests-syscall-tests atf
2284./usr/tests/syscall/t_timer tests-syscall-tests atf 2286./usr/tests/syscall/t_timer tests-syscall-tests atf
2285./usr/tests/syscall/t_umask tests-syscall-tests atf 2287./usr/tests/syscall/t_umask tests-syscall-tests atf
2286./usr/tests/toolchain tests-syscall-tests atf 2288./usr/tests/toolchain tests-syscall-tests atf
2287./usr/tests/toolchain/Atffile tests-syscall-tests atf 2289./usr/tests/toolchain/Atffile tests-syscall-tests atf
2288./usr/tests/toolchain/cc tests-syscall-tests atf 2290./usr/tests/toolchain/cc tests-syscall-tests atf
2289./usr/tests/toolchain/cc/Atffile tests-syscall-tests atf 2291./usr/tests/toolchain/cc/Atffile tests-syscall-tests atf
2290./usr/tests/toolchain/cc/t_hello tests-syscall-tests atf 2292./usr/tests/toolchain/cc/t_hello tests-syscall-tests atf
2291./usr/tests/usr.bin tests-util-tests 2293./usr/tests/usr.bin tests-util-tests
2292./usr/tests/usr.bin/Atffile tests-sbin-tests atf 2294./usr/tests/usr.bin/Atffile tests-sbin-tests atf
2293./usr/tests/usr.bin/rump_server tests-util-tests 2295./usr/tests/usr.bin/rump_server tests-util-tests
2294./usr/tests/usr.bin/rump_server/Atffile tests-util-tests atf 2296./usr/tests/usr.bin/rump_server/Atffile tests-util-tests atf

cvs diff -r1.24 -r1.25 src/tests/syscall/Attic/Makefile (expand / switch to unified diff)

--- src/tests/syscall/Attic/Makefile 2011/05/01 07:22:40 1.24
+++ src/tests/syscall/Attic/Makefile 2011/05/01 09:09:35 1.25
@@ -1,20 +1,20 @@ @@ -1,20 +1,20 @@
1# $NetBSD: Makefile,v 1.24 2011/05/01 07:22:40 jruoho Exp $ 1# $NetBSD: Makefile,v 1.25 2011/05/01 09:09:35 jruoho Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4 4
5TESTSDIR= ${TESTSBASE}/syscall 5TESTSDIR= ${TESTSBASE}/syscall
6 6
7TESTS_C+= t_access t_cmsg t_dup t_fsync 7TESTS_C+= t_access t_cmsg t_dup t_fsync
8TESTS_C+= t_getgroups t_getpid t_getrusage t_getsid t_gettimeofday 8TESTS_C+= t_getgroups t_getpid t_getrusage t_getsid t_gettimeofday
9TESTS_C+= t_kill t_mmap t_mprotect t_msync 9TESTS_C+= t_kill t_mmap t_mprotect t_msync t_nanosleep
10TESTS_C+= t_setrlimit t_setuid t_timer t_umask 10TESTS_C+= t_setrlimit t_setuid t_timer t_umask
11 11
12LDADD.t_getpid+= -lpthread 12LDADD.t_getpid+= -lpthread
13LDADD.t_timer+= -lpthread 13LDADD.t_timer+= -lpthread
14 14
15LDADD.t_cmsg+= -lrumpnet_local -lrumpnet_net -lrumpnet 15LDADD.t_cmsg+= -lrumpnet_local -lrumpnet_net -lrumpnet
16LDADD.t_cmsg+= -lrumpvfs -lrump -lrumpuser -lpthread 16LDADD.t_cmsg+= -lrumpvfs -lrump -lrumpuser -lpthread
17 17
18WARNS= 4 18WARNS= 4
19 19
20.include <bsd.test.mk> 20.include <bsd.test.mk>

File Added: src/tests/syscall/Attic/t_nanosleep.c
/* $NetBSD: t_nanosleep.c,v 1.1 2011/05/01 09:09:35 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_nanosleep.c,v 1.1 2011/05/01 09:09:35 jruoho Exp $");

#include <sys/time.h>
#include <sys/wait.h>

#include <atf-c.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>

static void
handler(int signo)
{
	/* Nothing. */
}

ATF_TC(nanosleep_basic);
ATF_TC_HEAD(nanosleep_basic, tc)
{
	atf_tc_set_md_var(tc, "descr", "Test that nanosleep(2) works");
}

ATF_TC_BODY(nanosleep_basic, tc)
{
	static const size_t maxiter = 1; /* XXX */
	struct timespec ts1, ts2, tsn;
	pid_t pid;
	size_t i;
	int sta;

	/*
	 * Fork a child, suspend the execution of it,
	 * and verify that it was actually suspended.
	 */
	for (i = 0; i < maxiter; i++) {

		pid = fork();
		ATF_REQUIRE(pid >= 0);

		if (pid == 0) {

			tsn.tv_sec = 1;
			tsn.tv_nsec = i * 10000;

			(void)memset(&ts1, 0, sizeof(struct timespec));
			(void)memset(&ts2, 0, sizeof(struct timespec));

			if (clock_gettime(CLOCK_MONOTONIC, &ts1) != 0)
				_exit(EX_OSERR);

			if (nanosleep(&tsn, NULL) != 0)
				_exit(EX_OSERR);

			if (clock_gettime(CLOCK_MONOTONIC, &ts2) != 0)
				_exit(EX_OSERR);

			(void)fprintf(stderr,
			    "tsn: sec = %lu, nsec = %lu\n\t"
			    "ts1: sec = %lu, nsec = %lu\n\t"
			    "ts2: sec = %lu, nsec = %lu\n",
			    tsn.tv_sec, tsn.tv_nsec,
			    ts1.tv_sec, ts1.tv_nsec,
			    ts2.tv_sec, ts2.tv_nsec);

			/*
			 * Assume accuracy of the resolution in seconds.
			 */
			if (ts2.tv_sec - tsn.tv_sec != ts1.tv_sec)
				_exit(EX_DATAERR);

			if (ts2.tv_nsec - tsn.tv_nsec < ts1.tv_nsec)
				_exit(EX_DATAERR);

			_exit(EXIT_SUCCESS);
		}

		(void)wait(&sta);

		if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) {

			if (WEXITSTATUS(sta) == EX_DATAERR)
				atf_tc_fail("inaccuracies in sleep time");

			atf_tc_fail("system call failed");
		}
	}
}

ATF_TC(nanosleep_err);
ATF_TC_HEAD(nanosleep_err, tc)
{
	atf_tc_set_md_var(tc, "descr", "Test errors from nanosleep(2)");
}

ATF_TC_BODY(nanosleep_err, tc)
{
	struct timespec ts;

	ts.tv_sec = -1;
	ts.tv_nsec = 1000;

	errno = 0;
	ATF_REQUIRE_ERRNO(EINVAL, nanosleep(&ts, NULL) == -1);

	errno = 0;
	ATF_REQUIRE_ERRNO(EFAULT, nanosleep((void *)-1, NULL) == -1);
}

ATF_TC(nanosleep_sig);
ATF_TC_HEAD(nanosleep_sig, tc)
{
	atf_tc_set_md_var(tc, "descr", "Test signal for nanosleep(2)");
}

ATF_TC_BODY(nanosleep_sig, tc)
{
	struct timespec tsn, tsr;
	pid_t pid;
	int sta;

	/*
	 * Test that a signal interrupts nanosleep(2).
	 *
	 * (In which case the return value should be -1 and the
	 * second parameter should contain the unslept time.)
	 */
	pid = fork();

	ATF_REQUIRE(pid >= 0);
	ATF_REQUIRE(signal(SIGINT, handler) == 0);

	if (pid == 0) {

		tsn.tv_sec = 10;
		tsn.tv_nsec = 0;

		tsr.tv_sec = 0;
		tsr.tv_nsec = 0;

		errno = 0;

		if (nanosleep(&tsn, &tsr) != -1)
			_exit(EXIT_FAILURE);

		if (errno != EINTR)
			_exit(EXIT_FAILURE);

		if (tsr.tv_sec == 0 && tsr.tv_nsec == 0)
			_exit(EXIT_FAILURE);

		_exit(EXIT_SUCCESS);
	}

	(void)sleep(1);
	(void)kill(pid, SIGINT);
	(void)wait(&sta);

	if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
		atf_tc_fail("signal did not interrupt nanosleep(2)");
}

ATF_TP_ADD_TCS(tp)
{

	ATF_TP_ADD_TC(tp, nanosleep_basic);
	ATF_TP_ADD_TC(tp, nanosleep_err);
	ATF_TP_ADD_TC(tp, nanosleep_sig);

	return atf_no_error();
}