From: Fei Jie Date: Wed, 6 Apr 2016 06:18:50 +0000 (+0800) Subject: tests: add swap.test X-Git-Tag: v4.12~446 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=93faa4cc88370a4fdefc8daa4b2793da831807b5;p=strace tests: add swap.test * 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. --- diff --git a/tests/.gitignore b/tests/.gitignore index 9ebab080..c488409d 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 651ebb01..c2bb592e 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 00000000..a2fd1ff4 --- /dev/null +++ b/tests/swap.c @@ -0,0 +1,42 @@ +#include "tests.h" +#include + +#if defined __NR_swapon && defined __NR_swapoff + +# include +# include +# include +# include + +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 index 00000000..a30e1fd8 --- /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