Module Name:    src
Committed By:   jruoho
Date:           Fri Mar 25 09:34:03 UTC 2011

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/lib/librt: Makefile
Added Files:
        src/tests/lib/librt: t_sched.c

Log Message:
Add some basic POSIX conformance tests for sched(3).


To generate a diff of this commit:
cvs rdiff -u -r1.277 -r1.278 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/librt/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/librt/t_sched.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.277 src/distrib/sets/lists/tests/mi:1.278
--- src/distrib/sets/lists/tests/mi:1.277	Thu Mar 24 16:56:37 2011
+++ src/distrib/sets/lists/tests/mi	Fri Mar 25 09:34:02 2011
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.277 2011/03/24 16:56:37 jruoho Exp $
+# $NetBSD: mi,v 1.278 2011/03/25 09:34:02 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -488,6 +488,7 @@
 ./usr/libdata/debug/usr/tests/lib/libpthread/t_sleep.debug		tests-lib-tests		debug,atf
 ./usr/libdata/debug/usr/tests/lib/libpthread/t_status.debug		tests-lib-tests		debug,atf
 ./usr/libdata/debug/usr/tests/lib/librt					tests-lib-debug
+./usr/libdata/debug/usr/tests/lib/librt/t_sched.debug			tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/librt/t_sem.debug			tests-lib-debug		debug,atf
 ./usr/libdata/debug/usr/tests/lib/librumpclient					tests-lib-debug
 ./usr/libdata/debug/usr/tests/lib/librumpclient/h_exec.debug			tests-lib-debug		debug,atf
@@ -1961,6 +1962,7 @@
 ./usr/tests/lib/libpthread/t_status		tests-lib-tests		atf
 ./usr/tests/lib/librt				tests-lib-tests		atf
 ./usr/tests/lib/librt/Atffile			tests-lib-tests		atf
+./usr/tests/lib/librt/t_sched			tests-lib-tests		atf
 ./usr/tests/lib/librt/t_sem			tests-lib-tests		atf
 ./usr/tests/lib/librumpclient				tests-lib-tests		atf
 ./usr/tests/lib/librumpclient/Atffile			tests-lib-tests		atf

Index: src/tests/lib/librt/Makefile
diff -u src/tests/lib/librt/Makefile:1.1 src/tests/lib/librt/Makefile:1.2
--- src/tests/lib/librt/Makefile:1.1	Fri Jul 16 13:56:32 2010
+++ src/tests/lib/librt/Makefile	Fri Mar 25 09:34:02 2011
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.1 2010/07/16 13:56:32 jmmv Exp $
+# $NetBSD: Makefile,v 1.2 2011/03/25 09:34:02 jruoho Exp $
 
-NOMAN=		# defined 
+NOMAN=		# defined
 
 .include <bsd.own.mk>
 
@@ -8,6 +8,7 @@
 
 LDADD+=		-lrt
 
-TESTS_C=	t_sem
+TESTS_C=	t_sched
+TESTS_C+=	t_sem
 
 .include <bsd.test.mk>

Added files:

Index: src/tests/lib/librt/t_sched.c
diff -u /dev/null src/tests/lib/librt/t_sched.c:1.1
--- /dev/null	Fri Mar 25 09:34:03 2011
+++ src/tests/lib/librt/t_sched.c	Fri Mar 25 09:34:02 2011
@@ -0,0 +1,256 @@
+/* $NetBSD: t_sched.c,v 1.1 2011/03/25 09:34:02 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_sched.c,v 1.1 2011/03/25 09:34:02 jruoho Exp $");
+
+#include <sched.h>
+#include <limits.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static void	 sched_priority_set(int, int);
+
+ATF_TC(sched_getparam);
+ATF_TC_HEAD(sched_getparam, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "A basic test of sched_getparam(3)");
+}
+
+ATF_TC_BODY(sched_getparam, tc)
+{
+	struct sched_param s1, s2;
+	pid_t p = getpid();
+
+	/*
+	 * IEEE Std 1003.1-2008: if the supplied pid is zero,
+	 * the parameters for the calling process are returned.
+	 */
+	ATF_REQUIRE(sched_getparam(0, &s1) == 0);
+	ATF_REQUIRE(sched_getparam(p, &s2) == 0);
+
+	ATF_REQUIRE(s1.sched_priority == s2.sched_priority);
+
+	/*
+	 * The behavior is undefined but should error
+	 * out in case the supplied PID is negative.
+	 */
+	ATF_REQUIRE(sched_getparam(-1, &s1) != 0);
+}
+
+ATF_TC(sched_priority);
+ATF_TC_HEAD(sched_priority, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test sched(3) priority ranges");
+}
+
+ATF_TC_BODY(sched_priority, tc)
+{
+	static const int pol[3] = { SCHED_OTHER, SCHED_FIFO, SCHED_RR };
+	int pmax, pmin;
+	size_t i;
+
+	/*
+	 * Test that bogus values error out.
+	 */
+	if (INT_MAX > SCHED_RR)
+		ATF_REQUIRE(sched_get_priority_max(INT_MAX) != 0);
+
+	if (-INT_MAX < SCHED_OTHER)
+		ATF_REQUIRE(sched_get_priority_max(-INT_MAX) != 0);
+
+	/*
+	 * Test that we have a valid range.
+	 */
+	for (i = 0; i < __arraycount(pol); i++) {
+
+		pmax = sched_get_priority_max(pol[i]);
+		pmin = sched_get_priority_min(pol[i]);
+
+		ATF_REQUIRE(pmax != -1);
+		ATF_REQUIRE(pmin != -1);
+		ATF_REQUIRE(pmax > pmin);
+	}
+}
+
+static void
+sched_priority_set(int pri, int pol)
+{
+	struct sched_param sched;
+
+	sched.sched_priority = pri;
+
+	ATF_REQUIRE(pri >= 0);
+	ATF_REQUIRE(sched_setscheduler(0, pol, &sched) == 0);
+
+	/*
+	 * Test that the policy was changed.
+	 */
+	ATF_REQUIRE(sched_getscheduler(0) == pol);
+
+	/*
+	 * And that sched_getparam(3) returns the new priority.
+	 */
+	sched.sched_priority = -1;
+
+	ATF_REQUIRE(sched_getparam(0, &sched) == 0);
+	ATF_REQUIRE(sched.sched_priority == pri);
+}
+
+ATF_TC(sched_setscheduler_1);
+ATF_TC_HEAD(sched_setscheduler_1, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "sched_setscheduler(3), max, RR");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(sched_setscheduler_1, tc)
+{
+	int pri;
+
+	pri = sched_get_priority_max(SCHED_RR);
+	sched_priority_set(pri, SCHED_RR);
+}
+
+ATF_TC(sched_setscheduler_2);
+ATF_TC_HEAD(sched_setscheduler_2, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "sched_setscheduler(3), min, RR");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(sched_setscheduler_2, tc)
+{
+	int pri;
+
+	pri = sched_get_priority_min(SCHED_RR);
+	sched_priority_set(pri, SCHED_RR);
+}
+
+ATF_TC(sched_setscheduler_3);
+ATF_TC_HEAD(sched_setscheduler_3, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "sched_setscheduler(3), max, FIFO");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(sched_setscheduler_3, tc)
+{
+	int pri;
+
+	pri = sched_get_priority_max(SCHED_FIFO);
+	sched_priority_set(pri, SCHED_FIFO);
+}
+
+ATF_TC(sched_setscheduler_4);
+ATF_TC_HEAD(sched_setscheduler_4, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "sched_setscheduler(3), min, FIFO");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(sched_setscheduler_4, tc)
+{
+	int pri;
+
+	pri = sched_get_priority_min(SCHED_FIFO);
+	sched_priority_set(pri, SCHED_FIFO);
+}
+
+ATF_TC(sched_rr_get_interval_1);
+ATF_TC_HEAD(sched_rr_get_interval_1, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test sched_rr_get_interval(3), #1");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(sched_rr_get_interval_1, tc)
+{
+	struct timespec tv;
+	int pri;
+
+	pri = sched_get_priority_min(SCHED_RR);
+	sched_priority_set(pri, SCHED_RR);
+
+	/*
+	 * This should fail with ESRCH for invalid PID.
+	 */
+	atf_tc_expect_fail("PR lib/44768");
+	ATF_REQUIRE(sched_rr_get_interval(-INT_MAX, &tv) != 0);
+}
+
+ATF_TC(sched_rr_get_interval_2);
+ATF_TC_HEAD(sched_rr_get_interval_2, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test sched_rr_get_interval(3), #2");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(sched_rr_get_interval_2, tc)
+{
+	struct timespec tv1, tv2;
+	int pri;
+
+	pri = sched_get_priority_min(SCHED_RR);
+	sched_priority_set(pri, SCHED_RR);
+
+	tv1.tv_sec = tv2.tv_sec = -1;
+	tv1.tv_nsec = tv2.tv_nsec -1;
+
+	ATF_REQUIRE(sched_rr_get_interval(0, &tv1) == 0);
+	ATF_REQUIRE(sched_rr_get_interval(getpid(), &tv2) == 0);
+
+	ATF_REQUIRE(tv1.tv_sec != -1);
+	ATF_REQUIRE(tv2.tv_sec != -1);
+
+	ATF_REQUIRE(tv1.tv_nsec != -1);
+	ATF_REQUIRE(tv2.tv_nsec != -1);
+
+	ATF_REQUIRE(tv1.tv_sec == tv2.tv_sec);
+	ATF_REQUIRE(tv1.tv_nsec == tv2.tv_nsec);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, sched_getparam);
+	ATF_TP_ADD_TC(tp, sched_priority);
+
+	ATF_TP_ADD_TC(tp, sched_setscheduler_1);
+	ATF_TP_ADD_TC(tp, sched_setscheduler_2);
+	ATF_TP_ADD_TC(tp, sched_setscheduler_3);
+	ATF_TP_ADD_TC(tp, sched_setscheduler_4);
+
+	ATF_TP_ADD_TC(tp, sched_rr_get_interval_1);
+	ATF_TP_ADD_TC(tp, sched_rr_get_interval_2);
+
+	return atf_no_error();
+}

Reply via email to