Module Name: src Committed By: martin Date: Tue Jun 5 08:44:22 UTC 2012
Modified Files: src/tests/lib/libc/sys: Makefile t_mincore.c Log Message: Try to estimate the number of locked pages the mincore() test will need and check it against resource limits, skipping the tests if it probably is too low. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/tests/lib/libc/sys/Makefile cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/sys/t_mincore.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libc/sys/Makefile diff -u src/tests/lib/libc/sys/Makefile:1.23 src/tests/lib/libc/sys/Makefile:1.24 --- src/tests/lib/libc/sys/Makefile:1.23 Mon May 21 14:15:19 2012 +++ src/tests/lib/libc/sys/Makefile Tue Jun 5 08:44:21 2012 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.23 2012/05/21 14:15:19 martin Exp $ +# $NetBSD: Makefile,v 1.24 2012/06/05 08:44:21 martin Exp $ MKMAN= no @@ -66,6 +66,7 @@ SRCS.t_mprotect= t_mprotect.c ${SRCS_EXE LDADD.t_getpid+= -lpthread LDADD.t_posix_fadvise+= -lrumpvfs -lrump -lrumpuser -lpthread +LDADD.t_mincore+= -lkvm WARNS= 4 Index: src/tests/lib/libc/sys/t_mincore.c diff -u src/tests/lib/libc/sys/t_mincore.c:1.5 src/tests/lib/libc/sys/t_mincore.c:1.6 --- src/tests/lib/libc/sys/t_mincore.c:1.5 Wed May 23 16:08:32 2012 +++ src/tests/lib/libc/sys/t_mincore.c Tue Jun 5 08:44:21 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: t_mincore.c,v 1.5 2012/05/23 16:08:32 martin Exp $ */ +/* $NetBSD: t_mincore.c,v 1.6 2012/06/05 08:44:21 martin Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_mincore.c,v 1.5 2012/05/23 16:08:32 martin Exp $"); +__RCSID("$NetBSD: t_mincore.c,v 1.6 2012/06/05 08:44:21 martin Exp $"); #include <sys/mman.h> #include <sys/shm.h> @@ -67,10 +67,13 @@ __RCSID("$NetBSD: t_mincore.c,v 1.5 2012 #include <atf-c.h> #include <errno.h> #include <fcntl.h> +#include <kvm.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <sys/resource.h> +#include <sys/sysctl.h> static long page = 0; static const char path[] = "mincore"; @@ -101,6 +104,28 @@ check_residency(void *addr, size_t npgs) return resident; } +/* + * Get an estimate of the current VM size + */ +static size_t +vm_cur_pages(void) +{ + size_t res = 0; + kvm_t *kvm; + struct kinfo_proc2 *pi; + int cnt; + + kvm = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, getprogname()); + if (kvm == NULL) + return 0; + pi = kvm_getproc2(kvm, KERN_PROC_PID, getpid(), sizeof(*pi), &cnt); + if (pi && cnt >= 1) + res = pi[0].p_vm_vsize; + kvm_close(kvm); + + return res; +} + ATF_TC(mincore_err); ATF_TC_HEAD(mincore_err, tc) { @@ -142,6 +167,25 @@ ATF_TC_BODY(mincore_resid, tc) size_t npgs = 0; struct stat st; int fd, rv; + struct rlimit rlim; + size_t needed_pages, limit_pages; + + ATF_REQUIRE(getrlimit(RLIMIT_MEMLOCK, &rlim) == 0); + limit_pages = rlim.rlim_cur / page; + /* + * We can not exactly predict the number of pages resulting from + * the test and the mlockall() call below. + * Get a safe upper bound instead... + */ + needed_pages = vm_cur_pages(); + /* we certainly will gow by 128 pages */ + needed_pages += 128; + /* add a bit of safety room */ + needed_pages += 12; + + if (needed_pages >= limit_pages) + atf_tc_skip("too low limits on locked memory (may need %zu " + "pages, limit is %zu pages)", needed_pages, limit_pages); (void)memset(&st, 0, sizeof(struct stat));