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.
This commit is contained in:
Fei Jie 2016-04-06 14:18:50 +08:00 committed by Dmitry V. Levin
parent 41cd657930
commit 93faa4cc88
4 changed files with 51 additions and 0 deletions

1
tests/.gitignore vendored
View File

@ -137,6 +137,7 @@ stack-fcall
stat
stat64
statfs
swap
sync_file_range
sync_file_range2
sysinfo

View 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 \

42
tests/swap.c Normal file
View File

@ -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

6
tests/swap.test Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
# Check swapon and swapoff syscalls decoding.
. "${srcdir=.}/init.sh"
run_strace_match_diff -a23 -e trace=swapon,swapoff