bug-hurd
[Top][All Lists]
Advanced

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

[PATCH 07/14] add basic vm tests


From: Luca Dariz
Subject: [PATCH 07/14] add basic vm tests
Date: Thu, 28 Dec 2023 20:42:54 +0100

---
 tests/test-vm.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 tests/test-vm.c

diff --git a/tests/test-vm.c b/tests/test-vm.c
new file mode 100644
index 00000000..ba52876b
--- /dev/null
+++ b/tests/test-vm.c
@@ -0,0 +1,52 @@
+
+#include <syscalls.h>
+#include <testlib.h>
+
+#include <mach/machine/vm_param.h>
+#include <mach/std_types.h>
+#include <mach/mach_types.h>
+#include <mach/vm_wire.h>
+#include <mach/vm_param.h>
+
+#include <device.user.h>
+#include <gnumach.user.h>
+#include <mach.user.h>
+#include <mach_port.user.h>
+
+
+static void test_memobj()
+{
+  // this emulates maptime()
+  struct mapped_time_value *mtime;
+  mach_port_t device, memobj;
+  int err = device_open (device_priv(), 0, "time", &device);
+  ASSERT_RET(err, "device_open");
+  err = device_map (device, VM_PROT_READ, 0, sizeof(*mtime), &memobj, 0);
+  ASSERT_RET(err, "device_map");
+  err = mach_port_deallocate (mach_task_self (), device);
+  ASSERT_RET(err, "mach_port_deallocate");
+  mtime = 0;
+  err =
+    vm_map (mach_task_self (), (vm_address_t *)&mtime, sizeof *mtime, 0, 1,
+            memobj, 0, 0, VM_PROT_READ, VM_PROT_READ, VM_INHERIT_NONE);
+  ASSERT_RET(err, "vm_map");
+  err = mach_port_deallocate (mach_task_self (), memobj);
+  ASSERT_RET(err, "mach_port_deallocate");
+  err = vm_deallocate(mach_task_self(), (vm_address_t)mtime, sizeof(*mtime));
+  ASSERT_RET(err, "vm_deallocate");
+}
+
+static void test_wire()
+{
+  int err = vm_wire_all(host_priv(), mach_task_self(), VM_WIRE_ALL);
+  ASSERT_RET(err, "vm_wire_all");
+}
+
+int main(int argc, char *argv[], int envc, char *envp[])
+{
+  printf("VM_MIN_ADDRESS=0x%p\n", VM_MIN_ADDRESS);
+  printf("VM_MAX_ADDRESS=0x%p\n", VM_MAX_ADDRESS);
+  test_wire();
+  test_memobj();
+  return 0;
+}
-- 
2.39.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]