Source-Changes-HG archive

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

[src/trunk]: src Add some basic POSIX conformance tests for sched(3).



details:   https://anonhg.NetBSD.org/src/rev/0717a226f3e6
branches:  trunk
changeset: 763560:0717a226f3e6
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Fri Mar 25 09:34:02 2011 +0000

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

diffstat:

 distrib/sets/lists/tests/mi |    4 +-
 tests/lib/librt/Makefile    |    7 +-
 tests/lib/librt/t_sched.c   |  256 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 263 insertions(+), 4 deletions(-)

diffs (truncated from 306 to 300 lines):

diff -r 2efd93991116 -r 0717a226f3e6 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Mar 25 04:26:41 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Mar 25 09:34:02 2011 +0000
@@ -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
diff -r 2efd93991116 -r 0717a226f3e6 tests/lib/librt/Makefile
--- a/tests/lib/librt/Makefile  Fri Mar 25 04:26:41 2011 +0000
+++ b/tests/lib/librt/Makefile  Fri Mar 25 09:34:02 2011 +0000
@@ -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>
diff -r 2efd93991116 -r 0717a226f3e6 tests/lib/librt/t_sched.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/librt/t_sched.c Fri Mar 25 09:34:02 2011 +0000
@@ -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);



Home | Main Index | Thread Index | Old Index