From owner-svn-src-head@freebsd.org Tue Oct 8 15:04:47 2019 Return-Path: <owner-svn-src-head@freebsd.org> Delivered-To: svn-src-head@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 3A3F812C3FF; Tue, 8 Oct 2019 15:04:47 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 46ngcZ6H43z44d6; Tue, 8 Oct 2019 15:04:46 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id x98F4cXn017440 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 8 Oct 2019 18:04:41 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua x98F4cXn017440 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id x98F4c2H017439; Tue, 8 Oct 2019 18:04:38 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 8 Oct 2019 18:04:38 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Eric van Gyzen <vangyzen@FreeBSD.org> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r353305 - head/tests/sys/kern Message-ID: <20191008150438.GE44691@kib.kiev.ua> References: <201910081343.x98Dh5bW006905@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201910081343.x98Dh5bW006905@repo.freebsd.org> User-Agent: Mutt/1.12.2 (2019-09-21) X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home X-Rspamd-Queue-Id: 46ngcZ6H43z44d6 X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-5.99 / 15.00]; NEURAL_HAM_MEDIUM(-0.99)[-0.993,0]; REPLY(-4.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current <svn-src-head.freebsd.org> List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-head>, <mailto:svn-src-head-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head/> List-Post: <mailto:svn-src-head@freebsd.org> List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help> List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-head>, <mailto:svn-src-head-request@freebsd.org?subject=subscribe> X-List-Received-Date: Tue, 08 Oct 2019 15:04:47 -0000 On Tue, Oct 08, 2019 at 01:43:05PM +0000, Eric van Gyzen wrote: > 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. There are much more tests that fork and use ATF_ in children. Look e.g. at most ptrace(2) tests. > > 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 <sys/param.h> > +#include <sys/limits.h> > +#include <sys/resource.h> > +#include <sys/stat.h> > +#include <sys/sysctl.h> > +#include <sys/time.h> > +#include <sys/wait.h> > + > #include <errno.h> > #include <fcntl.h> > #include <signal.h> > #include <stdio.h> > #include <stdlib.h> > +#include <string.h> > #include <strings.h> > -#include <sys/limits.h> > -#include <sys/stat.h> > -#include <sys/sysctl.h> > #include <unistd.h> > + > #include <atf-c.h> > > 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)