Module Name:    src
Committed By:   jruoho
Date:           Sun Apr 17 06:18:23 UTC 2011

Modified Files:
        src/tests/lib/libc/gen: Makefile t_nice.c

Log Message:
Test nice(3) also with threads.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/tests/lib/libc/gen/Makefile
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/gen/t_nice.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/gen/Makefile
diff -u src/tests/lib/libc/gen/Makefile:1.18 src/tests/lib/libc/gen/Makefile:1.19
--- src/tests/lib/libc/gen/Makefile:1.18	Sun Apr 10 06:27:21 2011
+++ src/tests/lib/libc/gen/Makefile	Sun Apr 17 06:18:23 2011
@@ -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>

Index: src/tests/lib/libc/gen/t_nice.c
diff -u src/tests/lib/libc/gen/t_nice.c:1.4 src/tests/lib/libc/gen/t_nice.c:1.5
--- src/tests/lib/libc/gen/t_nice.c:1.4	Sun Apr 10 10:59:13 2011
+++ src/tests/lib/libc/gen/t_nice.c	Sun Apr 17 06:18:23 2011
@@ -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();
 }

Reply via email to