From owner-svn-src-head@freebsd.org Wed Jan 27 06:24:21 2016 Return-Path: Delivered-To: svn-src-head@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 090DAA6F932; Wed, 27 Jan 2016 06:24:21 +0000 (UTC) (envelope-from ngie@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 mx1.freebsd.org (Postfix) with ESMTPS id D730912E5; Wed, 27 Jan 2016 06:24:20 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0R6OJ79033209; Wed, 27 Jan 2016 06:24:19 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0R6OJxf033208; Wed, 27 Jan 2016 06:24:19 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201601270624.u0R6OJxf033208@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Wed, 27 Jan 2016 06:24:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294894 - head/contrib/netbsd-tests/lib/libc/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jan 2016 06:24:21 -0000 Author: ngie Date: Wed Jan 27 06:24:19 2016 New Revision: 294894 URL: https://svnweb.freebsd.org/changeset/base/294894 Log: Adjust vm.max_wired in order to avoid hitting EAGAIN artificially Set vm.max_wired to INT_MAX in :mlock_err, :mlock_mmap, and :mlock_nested to avoid hitting EAGAIN artificially on the system when running the tests Require root privileges in order to set the sysctl Add allow_sysctl_side_effects to require.config as this test is now adjusting sysctls that can affect the global system state Unlike the version submitted by cem in OneFS, this version uses a scratch file to save/restore the previous value of the sysctl. I _really_, _really_ wish there were better hooks in atf/kyua for per test suite setup/teardown -- using a file is kludgy, but it's the best I can do to avoid situations where (for instance), sysctl(3) may fail and drop a core outside the kyua sandbox. Based on a patch submitted by cem, but modified to take business logic out of ATF_TP_ADD_TCS(3). Differential Revision: https://reviews.freebsd.org/D4779 MFC after: 1 month Sponsored by: EMC / Isilon Storage Division Modified: head/contrib/netbsd-tests/lib/libc/sys/t_mlock.c Modified: head/contrib/netbsd-tests/lib/libc/sys/t_mlock.c ============================================================================== --- head/contrib/netbsd-tests/lib/libc/sys/t_mlock.c Wed Jan 27 06:21:35 2016 (r294893) +++ head/contrib/netbsd-tests/lib/libc/sys/t_mlock.c Wed Jan 27 06:24:19 2016 (r294894) @@ -47,12 +47,89 @@ __RCSID("$NetBSD: t_mlock.c,v 1.5 2014/0 #include #ifdef __FreeBSD__ +#include #define _KMEMUSER #include #endif static long page = 0; +#ifdef __FreeBSD__ +#define VM_MAX_WIRED "vm.max_wired" + +static void +vm_max_wired_sysctl(int *old_value, int *new_value) +{ + size_t old_len; + size_t new_len = (new_value == NULL ? 0 : sizeof(int)); + + if (old_value == NULL) + printf("Setting the new value to %d\n", *new_value); + else { + ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, NULL, &old_len, + new_value, new_len) == 0, + "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno)); + } + + ATF_REQUIRE_MSG(sysctlbyname(VM_MAX_WIRED, old_value, &old_len, + new_value, new_len) == 0, + "sysctlbyname(%s) failed: %s", VM_MAX_WIRED, strerror(errno)); + + if (old_value != NULL) + printf("Saved the old value (%d)\n", *old_value); +} + +static void +set_vm_max_wired(int new_value) +{ + FILE *fp; + int old_value; + + fp = fopen(VM_MAX_WIRED, "w"); + if (fp == NULL) { + atf_tc_skip("could not open %s for writing: %s", + VM_MAX_WIRED, strerror(errno)); + return; + } + + vm_max_wired_sysctl(&old_value, NULL); + + ATF_REQUIRE_MSG(fprintf(fp, "%d", old_value) > 0, + "saving %s failed", VM_MAX_WIRED); + + fclose(fp); + + vm_max_wired_sysctl(NULL, &new_value); +} + +static void +restore_vm_max_wired(void) +{ + FILE *fp; + int saved_max_wired; + + fp = fopen(VM_MAX_WIRED, "r"); + if (fp == NULL) { + perror("fopen failed\n"); + return; + } + + if (fscanf(fp, "%d", &saved_max_wired) != 1) { + perror("fscanf failed\n"); + fclose(fp); + return; + } + + fclose(fp); + printf("old value in %s: %d\n", VM_MAX_WIRED, saved_max_wired); + + if (saved_max_wired == 0) /* This will cripple the test host */ + return; + + vm_max_wired_sysctl(NULL, &saved_max_wired); +} +#endif + ATF_TC(mlock_clip); ATF_TC_HEAD(mlock_clip, tc) { @@ -78,11 +155,19 @@ ATF_TC_BODY(mlock_clip, tc) free(buf); } +#ifdef __FreeBSD__ +ATF_TC_WITH_CLEANUP(mlock_err); +#else ATF_TC(mlock_err); +#endif ATF_TC_HEAD(mlock_err, tc) { atf_tc_set_md_var(tc, "descr", "Test error conditions in mlock(2) and munlock(2)"); +#ifdef __FreeBSD__ + atf_tc_set_md_var(tc, "require.config", "allow_sysctl_side_effects"); + atf_tc_set_md_var(tc, "require.user", "root"); +#endif } ATF_TC_BODY(mlock_err, tc) @@ -99,6 +184,8 @@ ATF_TC_BODY(mlock_err, tc) if ((uintptr_t)VM_MIN_ADDRESS > 0) null_errno = EINVAL; /* NULL is not inside user VM */ #endif + /* Set max_wired really really high to avoid EAGAIN */ + set_vm_max_wired(INT_MAX); #else if (sysctlbyname("vm.minaddress", &vmin, &len, NULL, 0) != 0) atf_tc_fail("failed to read vm.minaddress"); @@ -139,6 +226,14 @@ ATF_TC_BODY(mlock_err, tc) ATF_REQUIRE_ERRNO(ENOMEM, munlock(invalid_ptr, page) == -1); } +#ifdef __FreeBSD__ +ATF_TC_CLEANUP(mlock_err, tc) +{ + + restore_vm_max_wired(); +} +#endif + ATF_TC(mlock_limits); ATF_TC_HEAD(mlock_limits, tc) { @@ -200,10 +295,18 @@ ATF_TC_BODY(mlock_limits, tc) free(buf); } +#ifdef __FreeBSD__ +ATF_TC_WITH_CLEANUP(mlock_mmap); +#else ATF_TC(mlock_mmap); +#endif ATF_TC_HEAD(mlock_mmap, tc) { atf_tc_set_md_var(tc, "descr", "Test mlock(2)-mmap(2) interaction"); +#ifdef __FreeBSD__ + atf_tc_set_md_var(tc, "require.config", "allow_sysctl_side_effects"); + atf_tc_set_md_var(tc, "require.user", "root"); +#endif } ATF_TC_BODY(mlock_mmap, tc) @@ -215,6 +318,11 @@ ATF_TC_BODY(mlock_mmap, tc) #endif void *buf; +#ifdef __FreeBSD__ + /* Set max_wired really really high to avoid EAGAIN */ + set_vm_max_wired(INT_MAX); +#endif + /* * Make a wired RW mapping and check that mlock(2) * does not fail for the (already locked) mapping. @@ -248,11 +356,27 @@ ATF_TC_BODY(mlock_mmap, tc) ATF_REQUIRE(munmap(buf, page) == 0); } +#ifdef __FreeBSD__ +ATF_TC_CLEANUP(mlock_mmap, tc) +{ + + restore_vm_max_wired(); +} +#endif + +#ifdef __FreeBSD__ +ATF_TC_WITH_CLEANUP(mlock_nested); +#else ATF_TC(mlock_nested); +#endif ATF_TC_HEAD(mlock_nested, tc) { atf_tc_set_md_var(tc, "descr", "Test that consecutive mlock(2) calls succeed"); +#ifdef __FreeBSD__ + atf_tc_set_md_var(tc, "require.config", "allow_sysctl_side_effects"); + atf_tc_set_md_var(tc, "require.user", "root"); +#endif } ATF_TC_BODY(mlock_nested, tc) @@ -260,6 +384,11 @@ ATF_TC_BODY(mlock_nested, tc) const size_t maxiter = 100; void *buf; +#ifdef __FreeBSD__ + /* Set max_wired really really high to avoid EAGAIN */ + set_vm_max_wired(INT_MAX); +#endif + buf = malloc(page); ATF_REQUIRE(buf != NULL); @@ -270,6 +399,14 @@ ATF_TC_BODY(mlock_nested, tc) free(buf); } +#ifdef __FreeBSD__ +ATF_TC_CLEANUP(mlock_nested, tc) +{ + + restore_vm_max_wired(); +} +#endif + ATF_TP_ADD_TCS(tp) {