[PATCH] Add test for mincore syscall
Fei Jie
feij.fnst at cn.fujitsu.com
Tue Jan 26 05:51:10 UTC 2016
Check how mincore syscall is traced.
* tests/mincore.c: New file.
* tests/mincore.test: New test.
* tests/Makefile.am: (check_PROGRAMS): Add mincore.
(TESTS): Add mincore.test.
* tests/.gitignore: Add mincore.
---
tests/.gitignore | 1 +
tests/Makefile.am | 2 ++
tests/mincore.c | 43 +++++++++++++++++++++++++++++++++++++++++++
tests/mincore.test | 13 +++++++++++++
4 files changed, 59 insertions(+)
create mode 100644 tests/mincore.c
create mode 100755 tests/mincore.test
diff --git a/tests/.gitignore b/tests/.gitignore
index 207a9b2..10214d3 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -50,6 +50,7 @@ lstat
lstat64
membarrier
memfd_create
+mincore
mlock2
mmap
mmap64
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f634583..e31be34 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -96,6 +96,7 @@ check_PROGRAMS = \
lstat64 \
membarrier \
memfd_create \
+ mincore \
mlock2 \
mmap \
mmap64 \
@@ -235,6 +236,7 @@ TESTS = \
lstat64.test \
membarrier.test \
memfd_create.test \
+ mincore.test \
mlock2.test \
mmap.test \
mmap64.test \
diff --git a/tests/mincore.c b/tests/mincore.c
new file mode 100644
index 0000000..e116ed7
--- /dev/null
+++ b/tests/mincore.c
@@ -0,0 +1,43 @@
+#include "tests.h"
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+int main()
+{
+ char file_name[] = "mincore_XXXXXX";
+ int PAGESIZE = getpagesize();
+ int global_len = PAGESIZE*2;
+ char *buf;
+ buf = (char*)malloc(global_len);
+ char *global_pointer = NULL;
+ int file_desc, res;
+ memset(buf, 42, global_len);
+ if ((file_desc = mkstemp(file_name)) == -1) {
+ perror_msg_and_fail("Error while creating temporary file");
+ }
+
+ if (write(file_desc,buf,global_len) == -1) {
+ perror_msg_and_fail("Error while writing to temporary file");
+ }
+ free(buf);
+
+ if( MAP_FAILED == (global_pointer = (char *)mmap(NULL,global_len,\
+ PROT_READ|PROT_WRITE|PROT_EXEC,MAP_SHARED,file_desc,0)) ) {
+ perror_msg_and_fail("Temporary file could not be mmapped");
+ }
+
+ unsigned char* global_vec = NULL;
+ global_vec = malloc( (global_len+PAGESIZE-1) / PAGESIZE );
+ if ((res =mincore(global_pointer, global_len, global_vec)) == -1) {
+ perror_msg_and_fail("mincore fail!\n");
+ }
+ printf("mincore\\(%p, %d, \[[0-1]*\\.\\.\\.]\\) = %d\n",
+ global_pointer, global_len, res);
+ free(global_vec);
+ return 0;
+}
diff --git a/tests/mincore.test b/tests/mincore.test
new file mode 100755
index 0000000..29e2177
--- /dev/null
+++ b/tests/mincore.test
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# Check how mincore syscall is traced.
+
+. "${srcdir=.}/init.sh"
+
+OUT="$LOG.out"
+run_prog
+run_strace -emincore -qq $args > "$OUT"
+match_grep "$LOG" "$OUT"
+rm -f "$OUT" mincore_*
+
+exit 0
--
1.8.3.1
More information about the Strace-devel
mailing list