summaryrefslogtreecommitdiff
path: root/regress/sys/uvm
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2005-05-03 18:26:55 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2005-05-03 18:26:55 +0000
commit092d727663fc84d6e0ee533d06faebae5fcc10e7 (patch)
tree41b0383fc7d316234d3f8eaafd477a9cbd322130 /regress/sys/uvm
parent7c044e9661f68aeae7ce2dc089ae43b225b906c6 (diff)
Test writing to a mmapped file around the 4GB offset.
Diffstat (limited to 'regress/sys/uvm')
-rw-r--r--regress/sys/uvm/Makefile4
-rw-r--r--regress/sys/uvm/mmap_4g/Makefile4
-rw-r--r--regress/sys/uvm/mmap_4g/mmap_4g.c77
3 files changed, 83 insertions, 2 deletions
diff --git a/regress/sys/uvm/Makefile b/regress/sys/uvm/Makefile
index 58d25f717fc..a8955c8f019 100644
--- a/regress/sys/uvm/Makefile
+++ b/regress/sys/uvm/Makefile
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile,v 1.3 2005/01/06 10:14:20 otto Exp $
+# $OpenBSD: Makefile,v 1.4 2005/05/03 18:26:54 otto Exp $
-SUBDIR=misc mmap_size
+SUBDIR=misc mmap_4g mmap_size
install:
diff --git a/regress/sys/uvm/mmap_4g/Makefile b/regress/sys/uvm/mmap_4g/Makefile
new file mode 100644
index 00000000000..95f2d7705ae
--- /dev/null
+++ b/regress/sys/uvm/mmap_4g/Makefile
@@ -0,0 +1,4 @@
+# $OpenBSD: Makefile,v 1.1 2005/05/03 18:26:54 otto Exp $
+PROG=mmap_4g
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/uvm/mmap_4g/mmap_4g.c b/regress/sys/uvm/mmap_4g/mmap_4g.c
new file mode 100644
index 00000000000..d6dbb17ee96
--- /dev/null
+++ b/regress/sys/uvm/mmap_4g/mmap_4g.c
@@ -0,0 +1,77 @@
+/* $OpenBSD: mmap_4g.c,v 1.1 2005/05/03 18:26:54 otto Exp $ */
+
+/*
+ * Public domain. 2005, Otto Moerbeek <otto@drijf.net>
+ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+/*
+ * Write near the 4g boundary using a mmaped file and check if the
+ * bytes do not wrap to offset 0.
+ */
+
+int
+main()
+{
+ int fd, i;
+ off_t offset;
+ size_t sz;
+ char *p, buf[100];
+ const char * file = "foo";
+
+ fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd == -1)
+ err(1, "open");
+
+ sz = sizeof(buf);;
+ offset = 4LL * 1024LL * 1024LL * 1024LL - sz/2;
+
+ if (lseek(fd, offset, SEEK_SET) != offset)
+ err(1, "lseek");
+ memset(buf, 0, sz);
+ if (write(fd, buf, sz) != sz)
+ err(1, "write");
+ close(fd);
+
+ fd = open(file, O_RDWR, 0);
+ if (fd == -1)
+ err(1, "open");
+ p = mmap(NULL, 100, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED,
+ fd, offset);
+ if (p == MAP_FAILED)
+ err(1, "mmap");
+ for (i = 0; i < sz; i++)
+ p[i] = i + 1;
+ if (munmap(p, sz) == -1)
+ err(1, "munmap");
+ close(fd);
+
+ fd = open(file, O_RDONLY, 0);
+ if (fd == -1)
+ err(1, "open");
+ if (read(fd, buf, sz) != sz)
+ err(1, "read");
+ for (i = 0; i < sz; i++)
+ if (buf[i])
+ errx(1, "nonzero byte 0x%02x found at offset %zu",
+ buf[i], i);
+
+ if (lseek(fd, offset, SEEK_SET) != offset)
+ err(1, "lseek");
+ if (read(fd, buf, sz) != sz)
+ err(1, "read");
+ for (i = 0; i < sz; i++)
+ if (buf[i] != i + 1)
+ err(1, "incorrect value 0x%02x at offset %llx",
+ p[i], offset + i);
+
+ close(fd);
+ unlink(file);
+ return 0;
+}