[PATCH 3/4] tests: add swap.test
Fei Jie
feij.fnst at cn.fujitsu.com
Wed Apr 6 06:18:50 UTC 2016
* tests/swap.c: New file.
* tests/swap.test: New test.
* tests/.gitignore: Add swap.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add swap.test.
---
tests/.gitignore | 1 +
tests/Makefile.am | 2 ++
tests/swap.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
tests/swap.test | 6 ++++++
4 files changed, 57 insertions(+)
create mode 100644 tests/swap.c
create mode 100755 tests/swap.test
diff --git a/tests/.gitignore b/tests/.gitignore
index 9ebab08..c488409 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -137,6 +137,7 @@ stack-fcall
stat
stat64
statfs
+swap
sync_file_range
sync_file_range2
sysinfo
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 651ebb0..c2bb592 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -186,6 +186,7 @@ check_PROGRAMS = \
stat \
stat64 \
statfs \
+ swap \
sync_file_range \
sync_file_range2 \
sysinfo \
@@ -374,6 +375,7 @@ DECODER_TESTS = \
stat64.test \
statfs.test \
sun_path.test \
+ swap.test \
sync_file_range.test \
sync_file_range2.test \
sysinfo.test \
diff --git a/tests/swap.c b/tests/swap.c
new file mode 100644
index 0000000..7ef0bc1
--- /dev/null
+++ b/tests/swap.c
@@ -0,0 +1,48 @@
+#include "tests.h"
+#include <sys/syscall.h>
+
+#if defined __NR_swapon && defined __NR_swapoff
+
+# include <errno.h>
+# include <stdio.h>
+# include <sys/swap.h>
+# include <unistd.h>
+
+static const char *
+error_msg(int error_num)
+{
+ const char *errno_text;
+ switch (error_num) {
+ case ENOSYS:
+ errno_text = "ENOSYS";
+ break;
+ case EPERM:
+ errno_text = "EPERM";
+ break;
+ default:
+ errno_text = "ENOENT";
+ }
+ return errno_text;
+}
+
+int
+main(void)
+{
+ static const char sample[] = "swap.sample";
+ int rc = syscall(__NR_swapon, sample, 0);
+ printf("swapon(\"%s\", 0) = %d %s (%m)\n",
+ sample, rc, error_msg(errno));
+
+ rc = syscall(__NR_swapoff, sample);
+ printf("swapoff(\"%s\") = %d %s (%m)\n",
+ sample, rc, error_msg(errno));
+
+ puts("+++ exited with 0 +++");
+ return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_swapon && __NR_swapoff")
+
+#endif
diff --git a/tests/swap.test b/tests/swap.test
new file mode 100755
index 0000000..a30e1fd
--- /dev/null
+++ b/tests/swap.test
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check swapon and swapoff syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -a23 -e trace=swapon,swapoff
--
1.8.3.1
More information about the Strace-devel
mailing list