mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 18:13:01 +00:00
mmap/munmap exerciser test
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2134
This commit is contained in:
parent
48dfac5b73
commit
4623bc042c
@ -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
|
||||
|
||||
70
none/tests/map_unmap.c
Normal file
70
none/tests/map_unmap.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
||||
2
none/tests/map_unmap.stderr.exp
Normal file
2
none/tests/map_unmap.stderr.exp
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
1
none/tests/map_unmap.stdout.exp
Normal file
1
none/tests/map_unmap.stdout.exp
Normal file
@ -0,0 +1 @@
|
||||
PASS
|
||||
1
none/tests/map_unmap.vgtest
Normal file
1
none/tests/map_unmap.vgtest
Normal file
@ -0,0 +1 @@
|
||||
prog: map_unmap
|
||||
Loading…
x
Reference in New Issue
Block a user