Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161513328
D8689.id22653.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D8689.id22653.diff
View Options
Index: contrib/netbsd-tests/lib/libc/sys/t_mlock.c
===================================================================
--- contrib/netbsd-tests/lib/libc/sys/t_mlock.c
+++ contrib/netbsd-tests/lib/libc/sys/t_mlock.c
@@ -50,86 +50,13 @@
#include <limits.h>
#define _KMEMUSER
#include <machine/vmparam.h>
+
+void set_vm_max_wired(int);
+void restore_vm_max_wired(void);
#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)
{
Index: contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c
===================================================================
--- contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c
+++ contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c
@@ -50,6 +50,11 @@
#include <ucontext.h>
#include <unistd.h>
+#ifdef __FreeBSD__
+void set_vm_max_wired(int);
+void restore_vm_max_wired(void);
+#endif
+
static void sighandler(int);
static const char path[] = "setrlimit";
@@ -235,10 +240,18 @@
_exit(EXIT_SUCCESS);
}
+#ifdef __FreeBSD__
+ATF_TC_WITH_CLEANUP(setrlimit_memlock);
+#else
ATF_TC(setrlimit_memlock);
+#endif
ATF_TC_HEAD(setrlimit_memlock, tc)
{
atf_tc_set_md_var(tc, "descr", "Test setrlimit(2), RLIMIT_MEMLOCK");
+#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(setrlimit_memlock, tc)
@@ -249,6 +262,11 @@
pid_t pid;
int sta;
+#ifdef __FreeBSD__
+ /* Set max_wired really really high to avoid EAGAIN */
+ set_vm_max_wired(INT_MAX);
+#endif
+
page = sysconf(_SC_PAGESIZE);
ATF_REQUIRE(page >= 0);
@@ -292,6 +310,14 @@
atf_tc_fail("RLIMIT_MEMLOCK not enforced");
}
+#ifdef __FreeBSD__
+ATF_TC_CLEANUP(setrlimit_memlock, tc)
+{
+
+ restore_vm_max_wired();
+}
+#endif
+
ATF_TC(setrlimit_nofile_1);
ATF_TC_HEAD(setrlimit_nofile_1, tc)
{
Index: lib/libc/tests/sys/Makefile
===================================================================
--- lib/libc/tests/sys/Makefile
+++ lib/libc/tests/sys/Makefile
@@ -68,6 +68,9 @@
.include "../Makefile.netbsd-tests"
+SRCS.mlock_test+= mlock_helper.c
+SRCS.setrlimit_test+= mlock_helper.c
+
.if ${COMPILER_TYPE} == "gcc"
WARNS?= 3
.else
Index: lib/libc/tests/sys/mlock_helper.c
===================================================================
--- /dev/null
+++ lib/libc/tests/sys/mlock_helper.c
@@ -0,0 +1,114 @@
+/*-
+ * Copyright (C) 2016 Bryan Drewery <bdrewery@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Helper for mlock(3) to avoid EAGAIN errors
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <stdio.h>
+#include <limits.h>
+
+#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);
+}
+
+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);
+}
+
+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);
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jul 5, 11:00 AM (10 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34706333
Default Alt Text
D8689.id22653.diff (7 KB)
Attached To
Mode
D8689: Fix setrlimit_test:setrlimit_memlock when the system has exceeded vm.max_wired.
Attached
Detach File
Event Timeline
Log In to Comment