[CRIU] [PATCH 5/5] test: add test that verifies proper intraction between lazy-pages and THP
Mike Rapoport
rppt at linux.vnet.ibm.com
Wed Jun 21 09:33:26 MSK 2017
Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
test/zdtm/transition/Makefile | 1 +
test/zdtm/transition/lazy-thp.c | 61 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
create mode 100644 test/zdtm/transition/lazy-thp.c
diff --git a/test/zdtm/transition/Makefile b/test/zdtm/transition/Makefile
index cd98921..f482a8a 100644
--- a/test/zdtm/transition/Makefile
+++ b/test/zdtm/transition/Makefile
@@ -20,6 +20,7 @@ TST_NOFILE = \
socket-tcp \
socket-tcp6 \
shmem \
+ lazy-thp \
TST_FILE = \
diff --git a/test/zdtm/transition/lazy-thp.c b/test/zdtm/transition/lazy-thp.c
new file mode 100644
index 0000000..4b48537
--- /dev/null
+++ b/test/zdtm/transition/lazy-thp.c
@@ -0,0 +1,61 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <linux/limits.h>
+#include "zdtmtst.h"
+
+#define N_PAGES 1024
+
+const char *test_doc = "Test interaction between THP and lazy-pages";
+
+/* The test is based on example by Adrian Reber <areber at redhat.com> */
+const char *test_author = "Mike Rapoport <rppt at linux.vnet.ibm.com>";
+
+int main(int argc, char ** argv)
+{
+ char *mem, *org, *m;
+ int count;
+
+ test_init(argc, argv);
+
+ /* we presume that malloc returns not page aliged address */
+ mem = malloc(PAGE_SIZE * N_PAGES);
+ org = malloc(PAGE_SIZE);
+ if (!mem || !org) {
+ pr_perror("malloc failedn");
+ return 1;
+ }
+
+ memset(mem, 0x42, PAGE_SIZE * N_PAGES);
+ memset(org, 0x42, PAGE_SIZE);
+
+ test_daemon();
+ while (test_go()) {
+ for (count = 0; count < N_PAGES; count += 2) {
+ m = mem + (count * PAGE_SIZE) + 128;
+ *m = count;
+ }
+
+ for (count = 0; count < N_PAGES; count++) {
+ m = mem+(count*PAGE_SIZE);
+ org[128] = (count % 2 == 0) ? count : 0x42;
+
+ if (memcmp(org, m, PAGE_SIZE)) {
+ fail("memory corruption\n");
+ return 1;
+ }
+ }
+
+ sleep(1);
+ }
+
+ pass();
+ return 0;
+}
--
2.7.4
More information about the CRIU
mailing list