]> granicus.if.org Git - strace/commitdiff
tests: add swap.test
authorFei Jie <feij.fnst@cn.fujitsu.com>
Wed, 6 Apr 2016 06:18:50 +0000 (14:18 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 6 Apr 2016 06:18:50 +0000 (06:18 +0000)
* 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
tests/Makefile.am
tests/swap.c [new file with mode: 0644]
tests/swap.test [new file with mode: 0755]

index 9ebab0804165e41b276f03415cbce48d6b2fc023..c488409d82ef8067a0683a793de2be574e4aa436 100644 (file)
@@ -137,6 +137,7 @@ stack-fcall
 stat
 stat64
 statfs
+swap
 sync_file_range
 sync_file_range2
 sysinfo
index 651ebb01cf5e887cd1ed6f139cc44981f90b9aa6..c2bb592e2da7de6f51bfac4e8447409e92239775 100644 (file)
@@ -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 (file)
index 0000000..a2fd1ff
--- /dev/null
@@ -0,0 +1,42 @@
+#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)
+{
+       switch (error_num) {
+               case ENOSYS: return "ENOSYS";
+               case EPERM: return "EPERM";
+               default: return "ENOENT";
+       }
+}
+
+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 (executable)
index 0000000..a30e1fd
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check swapon and swapoff syscalls decoding.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -a23 -e trace=swapon,swapoff