tests: add a test for get_robust_list and set_robust_list decoding

* tests/xet_robust_list.c: New file.
* tests/xet_robust_list.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add xet_robust_list.
(TESTS): Add xet_robust_list.test.
* tests/.gitignore: Add xet_robust_list.
This commit is contained in:
Дмитрий Левин 2015-08-18 19:21:36 +00:00
parent fe50316d2c
commit 41b9facc2a
4 changed files with 73 additions and 1 deletions

1
tests/.gitignore vendored
View File

@ -49,6 +49,7 @@ umovestr2
unix-pair-send-recv
utime
xattr
xet_robust_list
*.log
*.log.*
*.o

View File

@ -59,7 +59,9 @@ check_PROGRAMS = \
umovestr2 \
unix-pair-send-recv \
utime \
xattr
xattr \
xet_robust_list \
# end of check_PROGRAMS
filter_unavailable_LDADD = -lpthread
mmap64_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
@ -126,6 +128,7 @@ TESTS = \
uio.test \
utime.test \
xattr.test \
xet_robust_list.test \
count.test \
detach-sleeping.test \
detach-stopped.test \

55
tests/xet_robust_list.c Normal file
View File

@ -0,0 +1,55 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#if defined __NR_get_robust_list && defined __NR_set_robust_list
int
main(void)
{
const size_t page_len = sysconf(_SC_PAGESIZE);
const pid_t pid = getpid();
const long long_pid = (unsigned long) (0xdeadbeef00000000LL | pid);
void *p = mmap(NULL, page_len * 4, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED ||
mprotect(p + page_len, page_len, PROT_NONE) ||
mprotect(p + page_len * 3, page_len, PROT_NONE))
return 77;
void **p_head = p + page_len - sizeof(void *);
size_t *p_len = p + page_len * 3 - sizeof(size_t);
if (syscall(__NR_get_robust_list, long_pid, p_head, p_len))
return 77;
printf("get_robust_list\\(%d, \\[%#lx\\], \\[%lu\\]\\) += 0\n",
(int) pid, (unsigned long) *p_head, (unsigned long) *p_len);
if (syscall(__NR_set_robust_list, p, *p_len))
return 77;
printf("set_robust_list\\(%#lx, %lu\\) += 0\n",
(unsigned long) p, (unsigned long) *p_len);
if (syscall(__NR_get_robust_list, long_pid, p_head, p_len))
return 77;
printf("get_robust_list\\(%d, \\[%#lx\\], \\[%lu\\]\\) += 0\n",
(int) pid, (unsigned long) *p_head, (unsigned long) *p_len);
return 0;
}
#else
int
main(void)
{
return 77;
}
#endif

13
tests/xet_robust_list.test Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
# Check get_robust_list and set_robust_list syscalls decoding.
. "${srcdir=.}/init.sh"
run_prog > /dev/null
OUT="$LOG.out"
run_strace -eget_robust_list,set_robust_list $args > "$OUT"
match_grep "$LOG" "$OUT"
rm -f "$OUT"
exit 0