Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/gen Test nice(3) also with threads.



details:   https://anonhg.NetBSD.org/src/rev/bd77ac538b51
branches:  trunk
changeset: 764340:bd77ac538b51
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sun Apr 17 06:18:23 2011 +0000

description:
Test nice(3) also with threads.

diffstat:

 tests/lib/libc/gen/Makefile |   3 +-
 tests/lib/libc/gen/t_nice.c |  54 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 3 deletions(-)

diffs (108 lines):

diff -r f5ea142147fc -r bd77ac538b51 tests/lib/libc/gen/Makefile
--- a/tests/lib/libc/gen/Makefile       Sun Apr 17 05:16:28 2011 +0000
+++ b/tests/lib/libc/gen/Makefile       Sun Apr 17 06:18:23 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.18 2011/04/10 06:27:21 jruoho Exp $
+# $NetBSD: Makefile,v 1.19 2011/04/17 06:18:23 jruoho Exp $
 
 .include <bsd.own.mk>
 
@@ -22,6 +22,7 @@
 TESTS_C+=      t_vis
 
 LDADD.t_ldexp+=                -lm
+LDADD.t_nice+=         -lpthread
 LDADD.t_syslog_pthread+=-lpthread
 
 .include <bsd.test.mk>
diff -r f5ea142147fc -r bd77ac538b51 tests/lib/libc/gen/t_nice.c
--- a/tests/lib/libc/gen/t_nice.c       Sun Apr 17 05:16:28 2011 +0000
+++ b/tests/lib/libc/gen/t_nice.c       Sun Apr 17 06:18:23 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_nice.c,v 1.4 2011/04/10 10:59:13 jruoho Exp $ */
+/*     $NetBSD: t_nice.c,v 1.5 2011/04/17 06:18:23 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_nice.c,v 1.4 2011/04/10 10:59:13 jruoho Exp $");
+__RCSID("$NetBSD: t_nice.c,v 1.5 2011/04/17 06:18:23 jruoho Exp $");
 
 #include <sys/resource.h>
 #include <sys/wait.h>
@@ -37,9 +37,29 @@
 #include <atf-c.h>
 #include <errno.h>
 #include <limits.h>
+#include <pthread.h>
 #include <stdlib.h>
 #include <unistd.h>
 
+static void    *threadfunc(void *);
+
+static void *
+threadfunc(void *arg)
+{
+       int pri, val;
+
+       val = *(int *)arg;
+
+       errno = 0;
+       pri = getpriority(PRIO_PROCESS, 0);
+       ATF_REQUIRE(errno == 0);
+
+       if (pri != val)
+               atf_tc_fail("nice(3) value was not propagated to threads");
+
+       return NULL;
+}
+
 ATF_TC(nice_err);
 ATF_TC_HEAD(nice_err, tc)
 {
@@ -137,12 +157,42 @@
        }
 }
 
+ATF_TC(nice_thread);
+ATF_TC_HEAD(nice_thread, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test nice(3) with threads");
+}
+
+ATF_TC_BODY(nice_thread, tc)
+{
+       pthread_t tid[5];
+       int rv, val;
+       size_t i;
+
+       /*
+        * Test that the scheduling priority is
+        * propagated to all system scope threads.
+        */
+       for (i = 0; i < __arraycount(tid); i++) {
+
+               val = nice(i);
+               ATF_REQUIRE(val != -1);
+
+               rv = pthread_create(&tid[i], NULL, threadfunc, &val);
+               ATF_REQUIRE(rv == 0);
+
+               rv = pthread_join(tid[i], NULL);
+               ATF_REQUIRE(rv == 0);
+       }
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
        ATF_TP_ADD_TC(tp, nice_err);
        ATF_TP_ADD_TC(tp, nice_priority);
        ATF_TP_ADD_TC(tp, nice_root);
+       ATF_TP_ADD_TC(tp, nice_thread);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index