From owner-svn-src-all@freebsd.org Tue Oct 8 13:43:05 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B3BF8128F23; Tue, 8 Oct 2019 13:43:05 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46ndpK498cz3xZh; Tue, 8 Oct 2019 13:43:05 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6B7AACFE; Tue, 8 Oct 2019 13:43:05 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x98Dh5Xm006906; Tue, 8 Oct 2019 13:43:05 GMT (envelope-from vangyzen@FreeBSD.org) Received: (from vangyzen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x98Dh5bW006905; Tue, 8 Oct 2019 13:43:05 GMT (envelope-from vangyzen@FreeBSD.org) Message-Id: <201910081343.x98Dh5bW006905@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vangyzen set sender to vangyzen@FreeBSD.org using -f From: Eric van Gyzen Date: Tue, 8 Oct 2019 13:43:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353305 - head/tests/sys/kern X-SVN-Group: head X-SVN-Commit-Author: vangyzen X-SVN-Commit-Paths: head/tests/sys/kern X-SVN-Commit-Revision: 353305 X-SVN-Commit-Repository: base 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.29 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, 08 Oct 2019 13:43:05 -0000 Author: vangyzen Date: Tue Oct 8 13:43:05 2019 New Revision: 353305 URL: https://svnweb.freebsd.org/changeset/base/353305 Log: Fix problems in the kern_maxfiles__increase test ATF functions such as ATF_REQUIRE do not work correctly in child processes. Use plain C functions to report errors instead. In the parent, check for the untimely demise of children. Without this, the test hung until the framework's timeout. Raise the resource limit on the number of open files. If this was too low, the test hit the two problems above. Restore the kern.maxfiles sysctl OID in the cleanup function. The body prematurely removed the symlink in which the old value was saved. Make the test more robust by opening more files. In fact, due to the integer division by 4, this was necessary to make the test valid with some initial values of maxfiles. Thanks, asomers@. wait() for children instead of sleeping. Clean up a temporary file created by the test ("afile"). Reviewed by: asomers MFC after: 1 week Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D21900 Modified: head/tests/sys/kern/kern_descrip_test.c Modified: head/tests/sys/kern/kern_descrip_test.c ============================================================================== --- head/tests/sys/kern/kern_descrip_test.c Tue Oct 8 11:27:48 2019 (r353304) +++ head/tests/sys/kern/kern_descrip_test.c Tue Oct 8 13:43:05 2019 (r353305) @@ -28,16 +28,22 @@ __FBSDID("$FreeBSD$"); #include +#include +#include +#include +#include +#include +#include + #include #include #include #include #include +#include #include -#include -#include -#include #include + #include static volatile sig_atomic_t done; @@ -92,8 +98,13 @@ openfiles2(size_t n) int r; errno = 0; - for (i = 0; i < n; i++) - ATF_REQUIRE((r = open(AFILE, O_RDONLY)) != -1); + for (i = 0; i < n; i++) { + r = open(AFILE, O_RDONLY); + if (r < 0) { + fprintf(stderr, "open: %s\n", strerror(errno)); + _exit(1); + } + } kill(getppid(), SIGUSR1); for (;;) { @@ -118,10 +129,14 @@ openfiles(size_t n) for (i = 0; i < PARALLEL; i++) if (fork() == 0) openfiles2(n / PARALLEL); - while (done != PARALLEL) + while (done != PARALLEL) { usleep(1000); + ATF_REQUIRE_EQ_MSG(0, waitpid(-1, NULL, WNOHANG), + "a child exited unexpectedly"); + } unlink(RENDEZVOUS); - usleep(40000); + for (i = 0; i < PARALLEL; i++) + ATF_CHECK_MSG(wait(NULL) > 0, "wait: %s", strerror(errno)); } ATF_TC_WITH_CLEANUP(kern_maxfiles__increase); @@ -138,6 +153,7 @@ ATF_TC_BODY(kern_maxfiles__increase, tc) size_t oldlen; int maxfiles, oldmaxfiles, current; char buf[80]; + struct rlimit rl; oldlen = sizeof(maxfiles); if (sysctlbyname("kern.maxfiles", &maxfiles, &oldlen, NULL, 0) == -1) @@ -160,8 +176,11 @@ ATF_TC_BODY(kern_maxfiles__increase, tc) atf_tc_fail("getsysctlbyname(%s): %s", "kern.maxfiles", strerror(errno)); - openfiles(oldmaxfiles - current + 1); - (void)unlink(VALUE); + rl.rlim_cur = rl.rlim_max = maxfiles; + ATF_REQUIRE_EQ_MSG(0, setrlimit(RLIMIT_NOFILE, &rl), + "setrlimit(RLIMIT_NOFILE, %d): %s", maxfiles, strerror(errno)); + + openfiles(oldmaxfiles - current + EXPANDBY / 2); } ATF_TC_CLEANUP(kern_maxfiles__increase, tc) @@ -178,6 +197,8 @@ ATF_TC_CLEANUP(kern_maxfiles__increase, tc) &oldmaxfiles, oldlen); } } + (void)unlink(VALUE); + (void)unlink(AFILE); } ATF_TP_ADD_TCS(tp)