From 4c3b7c16c7eec62818c2b8789e08fa43d3673452 Mon Sep 17 00:00:00 2001
From: h2-addad <hamza2.addad@live.uwe.ac.uk>
Date: Sun, 16 Jul 2023 15:19:31 +0000
Subject: [PATCH] Upload New File

---
 src/tests/vm/mmap-twice.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 src/tests/vm/mmap-twice.c

diff --git a/src/tests/vm/mmap-twice.c b/src/tests/vm/mmap-twice.c
new file mode 100644
index 0000000..d277a37
--- /dev/null
+++ b/src/tests/vm/mmap-twice.c
@@ -0,0 +1,28 @@
+/* Maps the same file into memory twice and verifies that the
+   same data is readable in both. */
+
+#include <string.h>
+#include <syscall.h>
+#include "tests/vm/sample.inc"
+#include "tests/lib.h"
+#include "tests/main.h"
+
+void
+test_main (void)
+{
+  char *actual[2] = {(char *) 0x10000000, (char *) 0x20000000};
+  size_t i;
+  int handle[2];
+
+  for (i = 0; i < 2; i++) 
+    {
+      CHECK ((handle[i] = open ("sample.txt")) > 1,
+             "open \"sample.txt\" #%zu", i);
+      CHECK (mmap (handle[i], actual[i]) != MAP_FAILED,
+             "mmap \"sample.txt\" #%zu at %p", i, (void *) actual[i]);
+    }
+
+  for (i = 0; i < 2; i++)
+    CHECK (!memcmp (actual[i], sample, strlen (sample)),
+           "compare mmap'd file %zu against data", i);
+}
-- 
GitLab