aboutsummaryrefslogtreecommitdiff
path: root/tests/shmem
diff options
context:
space:
mode:
Diffstat (limited to 'tests/shmem')
-rw-r--r--tests/shmem/init.c36
-rw-r--r--tests/shmem/source.mk2
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/shmem/init.c b/tests/shmem/init.c
new file mode 100644
index 0000000..13e1667
--- /dev/null
+++ b/tests/shmem/init.c
@@ -0,0 +1,36 @@
+#include <common/test.h>
+
+START(pid, tid, d0, d1, d2, d3)
+{
+ UNUSED(pid);
+ UNUSED(tid);
+ UNUSED(d0);
+ UNUSED(d1);
+ UNUSED(d2);
+ UNUSED(d3);
+
+ printf("allocating shared memory\n");
+ volatile char *shmem = sys_req_sharedmem(1, VM_R | VM_W);
+ check(shmem, "no shared memory?\n");
+
+ *shmem = 'p';
+
+ printf("sharing memory to ourselves\n");
+ volatile char *refmem = sys_ref_sharedmem(1, (uintptr_t)shmem, VM_R | VM_W);
+ check(refmem[0] == 'p', "wrong mapping?\n");
+
+ printf("freeing shared memory (should fail)\n");
+ enum sys_status r = sys_free_mem((uintptr_t)shmem);
+ check(r != OK, "illegal freeing succeeded?\n");
+
+ printf("freeing referenced memory\n");
+ r = sys_free_mem((uintptr_t)refmem);
+ check(r == OK, "legal ref freeing failed?\n");
+ check(shmem[0] == 'p', "freeing ref freed owned memory?\n");
+
+ printf("freeing recently nonshared memory\n");
+ r = sys_free_mem((uintptr_t)shmem);
+ check(r == OK, "legal freeing failed?\n");
+
+ ok();
+}
diff --git a/tests/shmem/source.mk b/tests/shmem/source.mk
new file mode 100644
index 0000000..da84808
--- /dev/null
+++ b/tests/shmem/source.mk
@@ -0,0 +1,2 @@
+DO != ./scripts/gen-prog -n shmem -p init init.c
+DO != ./scripts/gen-simple -n shmem -p init