From: Jeremy Fitzhardinge Date: Fri, 19 Dec 2003 21:56:04 +0000 (+0000) Subject: mmap/munmap exerciser test X-Git-Tag: svn/VALGRIND_2_1_1~168 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4623bc042cb7d02eb195175ac38411d2cb08874d;p=thirdparty%2Fvalgrind.git mmap/munmap exerciser test git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2134 --- diff --git a/none/tests/Makefile.am b/none/tests/Makefile.am index 42467a7a88..a36280e2d6 100644 --- a/none/tests/Makefile.am +++ b/none/tests/Makefile.am @@ -22,6 +22,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ fpu_lazy_eflags.vgtest \ fucomip.stderr.exp fucomip.vgtest \ gxx304.stderr.exp gxx304.vgtest \ + map_unmap.stdout.exp map_unmap.vgtest \ munmap_exe.stderr.exp munmap_exe.vgtest \ pth_blockedsig.stderr.exp \ pth_blockedsig.stdout.exp pth_blockedsig.vgtest \ @@ -41,7 +42,7 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ check_PROGRAMS = \ args bitfield1 bt_everything bt_literal coolo_strlen \ cpuid dastest discard floored fork fpu_lazy_eflags \ - fucomip munmap_exe rcl_assert \ + fucomip munmap_exe map_unmap rcl_assert \ rcrl readline1 resolv seg_override sha1_test shortpush shorts smc1 \ pth_blockedsig \ coolo_sigaction gxx304 yield @@ -63,6 +64,7 @@ floored_SOURCES = floored.c floored_LDADD = -lm fpu_lazy_eflags_SOURCES = fpu_lazy_eflags.c fucomip_SOURCES = fucomip.c +map_unmap_SOURCES = map_unmap.c munmap_exe_SOURCES = munmap_exe.c rcl_assert_SOURCES = rcl_assert.S rcrl_SOURCES = rcrl.c diff --git a/none/tests/map_unmap.c b/none/tests/map_unmap.c new file mode 100644 index 0000000000..16a6d11e57 --- /dev/null +++ b/none/tests/map_unmap.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +static unsigned int pagesize; + +#define PAGES 1024u +#define LEN (PAGES*pagesize) + +static void *domap(void) +{ + void *ret = mmap(0, LEN, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + + if (ret == (void *)-1) { + perror("mmap"); + exit(1); + } + + return ret; +} + +/* unmap in pieces to exercise munmap more */ +static void nibblemap(void *p) +{ + int off; + int i; + + off = (random() & ~0x1fff) % LEN; + + for(i = 0; i < PAGES; i++) { + munmap((char *)p + off, pagesize); + off += 619*pagesize; + off %= LEN; + } +} + +int main() +{ + int i; + void *expect1, *expect2; + + pagesize = getpagesize(); + + expect1 = domap(); + expect2 = domap(); + munmap(expect1, LEN); + munmap(expect2, LEN); + for(i = 0; i < 1000; i++) { + void *m1, *m2; + + m1 = domap(); + if (m1 != expect1) { + printf("FAIL: m=%p expect=%p\n", + m1, expect1); + return 1; + } + m2 = domap(); + if (m2 != expect2) { + printf("FAIL: m=%p expect=%p\n", + m2, expect2); + return 1; + } + nibblemap(m2); + munmap(m1, LEN); + } + + printf("PASS\n"); + return 0; +} diff --git a/none/tests/map_unmap.stderr.exp b/none/tests/map_unmap.stderr.exp new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/none/tests/map_unmap.stderr.exp @@ -0,0 +1,2 @@ + + diff --git a/none/tests/map_unmap.stdout.exp b/none/tests/map_unmap.stdout.exp new file mode 100644 index 0000000000..7ef22e9a43 --- /dev/null +++ b/none/tests/map_unmap.stdout.exp @@ -0,0 +1 @@ +PASS diff --git a/none/tests/map_unmap.vgtest b/none/tests/map_unmap.vgtest new file mode 100644 index 0000000000..c6b0f84038 --- /dev/null +++ b/none/tests/map_unmap.vgtest @@ -0,0 +1 @@ +prog: map_unmap