From owner-svn-src-all@freebsd.org Tue Sep 1 12:47:13 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2BD999C709A; Tue, 1 Sep 2015 12:47:13 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0FDD81606; Tue, 1 Sep 2015 12:47:13 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t81ClCq1092377; Tue, 1 Sep 2015 12:47:12 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t81ClCpZ092375; Tue, 1 Sep 2015 12:47:12 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201509011247.t81ClCpZ092375@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 1 Sep 2015 12:47:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287360 - in head: contrib/netbsd-tests/lib/libc/gen/posix_spawn lib/libc/tests/gen/posix_spawn X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Sep 2015 12:47:13 -0000 Author: kib Date: Tue Sep 1 12:47:11 2015 New Revision: 287360 URL: https://svnweb.freebsd.org/changeset/base/287360 Log: Fix t_spawnattr test for attributes handling by posix_spawn(3). Connect it to the build. The code assumed that SCHED_* constants form a contiguous set of numbers, remove the assumption by using schedulers[] array in get_different_scheduler(). This is no-op on FreeBSD, but improves code portability. The selection of different priority used the min/max priority range of the current scheduler class, instead of the priority to be changed to. The bug caused the test failure. Remove duplication of POSIX_SPAWN_SETSIGDEF flag and now unused duplications of MIN/MAX definitions. Reviewed by: jilles, pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D3533 Modified: head/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c head/lib/libc/tests/gen/posix_spawn/Makefile Modified: head/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c ============================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c Tue Sep 1 12:33:35 2015 (r287359) +++ head/contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_spawnattr.c Tue Sep 1 12:47:11 2015 (r287360) @@ -30,6 +30,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -42,51 +43,56 @@ #include #include -#define MAX(a, b) (a) > (b) ? (a) : (b) -#define MIN(a, b) (a) > (b) ? (b) : (a) - static int get_different_scheduler(void); -static int get_different_priority(void); +static int get_different_priority(int scheduler); + +static const int schedulers[] = { + SCHED_OTHER, + SCHED_FIFO, + SCHED_RR +}; static int -get_different_scheduler() +get_different_scheduler(void) { - int scheduler, max, min, new; - - max = MAX(MAX(SCHED_FIFO, SCHED_OTHER), SCHED_RR); - min = MIN(MIN(SCHED_FIFO, SCHED_OTHER), SCHED_RR); + u_int i; + int scheduler; /* get current schedule policy */ scheduler = sched_getscheduler(0); + for (i = 0; i < nitems(schedulers); i++) { + if (schedulers[i] == scheduler) + break; + } + ATF_REQUIRE_MSG(i < nitems(schedulers), + "Unknown current scheduler %d", scheduler); /* new scheduler */ - new = (scheduler + 1); - if (new > max) - new = min; - - return new; + i++; + if (i >= nitems(schedulers)) + i = 0; + return schedulers[i]; } static int -get_different_priority() +get_different_priority(int scheduler) { - int scheduler, max, min, new, priority; + int max, min, new, priority; struct sched_param param; - /* get current schedule policy */ - scheduler = sched_getscheduler(0); - max = sched_get_priority_max(scheduler); min = sched_get_priority_min(scheduler); sched_getparam(0, ¶m); priority = param.sched_priority; - /* new schedule policy */ - new = (priority + 1); + /* + * Change numerical value of the priority, to ensure that it + * was set for the spawned child. + */ + new = priority + 1; if (new > max) new = min; - return new; } @@ -119,16 +125,15 @@ ATF_TC_BODY(t_spawnattr, tc) posix_spawnattr_init(&attr); scheduler = get_different_scheduler(); - priority = get_different_priority(); + priority = get_different_priority(scheduler); sp.sched_priority = priority; sigemptyset(&sig); sigaddset(&sig, SIGUSR1); - posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDULER | - POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETPGROUP | - POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF | - POSIX_SPAWN_SETSIGDEF); + posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDULER | + POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETPGROUP | + POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF); posix_spawnattr_setpgroup(&attr, 0); posix_spawnattr_setschedparam(&attr, &sp); posix_spawnattr_setschedpolicy(&attr, scheduler); Modified: head/lib/libc/tests/gen/posix_spawn/Makefile ============================================================================== --- head/lib/libc/tests/gen/posix_spawn/Makefile Tue Sep 1 12:33:35 2015 (r287359) +++ head/lib/libc/tests/gen/posix_spawn/Makefile Tue Sep 1 12:47:11 2015 (r287360) @@ -10,9 +10,9 @@ TESTSDIR= ${TESTSBASE}/lib/libc/gen/posi BINDIR= ${TESTSDIR} -# TODO: t_spawnattr (fix from pho@ needs additional review) NETBSD_ATF_TESTS_C= fileactions_test NETBSD_ATF_TESTS_C+= spawn_test +NETBSD_ATF_TESTS_C+= spawnattr_test PROGS= h_fileactions PROGS+= h_spawn