From 9b26d7af29e26792abd27a8a354b7b3f30b58357 Mon Sep 17 00:00:00 2001
From: Utz-Uwe Haus <uhaus@cray.com>
Date: Fri, 20 Nov 2020 22:01:42 +0100
Subject: [PATCH] add test for overlapping memlocks

---
 tests/check_memlock.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tests/check_memlock.c b/tests/check_memlock.c
index 0f1ae7d1..cc8e4f84 100644
--- a/tests/check_memlock.c
+++ b/tests/check_memlock.c
@@ -43,6 +43,8 @@
 
 #include "maestro.h"
 #include "maestro/i_memlock.h"
+#include <unistd.h>
+
 
 CHEAT_TEST(lock_unlock,
            {
@@ -77,3 +79,35 @@ CHEAT_TEST(lock_unlock_multi,
 
              free(x);
            })
+
+CHEAT_TEST(lock_overlapping,
+           {
+             long pagesize = sysconf(_SC_PAGESIZE);
+             void *x = malloc(3*pagesize);
+             cheat_assert(x!=NULL);
+             cheat_assert(pagesize>4);
+
+             cheat_assert(MSTRO_OK==mstro_memlock_init(4*pagesize));
+
+             /* one on the first page */
+             void *start1 = x;
+             size_t  len1 = pagesize/2;
+             /* one on the same page */
+             void *start2 = (void*)((uintptr_t)x+len1);
+             size_t  len2 = pagesize/4;
+             /* one extending into the third page */
+             void *start3 = (void*)((uintptr_t)x+len1+len2);
+             size_t  len3 = 2*pagesize;
+
+             cheat_assert(MSTRO_OK==mstro_memlock(start1, len1));
+             cheat_assert(MSTRO_OK==mstro_memlock(start2, len2));
+             cheat_assert(MSTRO_OK==mstro_memlock(start3, len3));
+
+             cheat_assert(MSTRO_OK==mstro_memunlock(start2, len2));
+             cheat_assert(MSTRO_OK==mstro_memunlock(start1, len1));
+             cheat_assert(MSTRO_OK==mstro_memunlock(start3, len3));
+
+             free(x);
+
+             
+           })
-- 
GitLab