Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys Try to estimate the number of locked page...



details:   https://anonhg.NetBSD.org/src/rev/2c7249ac2415
branches:  trunk
changeset: 779608:2c7249ac2415
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Jun 05 08:44:21 2012 +0000

description:
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.

diffstat:

 tests/lib/libc/sys/Makefile    |   3 +-
 tests/lib/libc/sys/t_mincore.c |  48 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 3 deletions(-)

diffs (104 lines):

diff -r 4f7156e6a507 -r 2c7249ac2415 tests/lib/libc/sys/Makefile
--- a/tests/lib/libc/sys/Makefile       Tue Jun 05 08:44:07 2012 +0000
+++ b/tests/lib/libc/sys/Makefile       Tue Jun 05 08:44:21 2012 +0000
@@ -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 @@
 
 LDADD.t_getpid+=        -lpthread
 LDADD.t_posix_fadvise+= -lrumpvfs -lrump -lrumpuser -lpthread
+LDADD.t_mincore+=      -lkvm
 
 WARNS=                 4
 
diff -r 4f7156e6a507 -r 2c7249ac2415 tests/lib/libc/sys/t_mincore.c
--- a/tests/lib/libc/sys/t_mincore.c    Tue Jun 05 08:44:07 2012 +0000
+++ b/tests/lib/libc/sys/t_mincore.c    Tue Jun 05 08:44:21 2012 +0000
@@ -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 @@
 #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 @@
        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 @@
        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));
 



Home | Main Index | Thread Index | Old Index