summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÁkos Uzonyi <uzonyi.akos@gmail.com>2020-07-11 17:29:58 +0200
committerDmitry V. Levin <ldv@altlinux.org>2020-08-25 14:29:30 +0000
commitf350ce0ffa5e25179c8c782045a8462b2946ead4 (patch)
tree3dc7be840d264c14c9ade7dc76d60d51206bc91e
parent7ecee07bbcdc54e97a6ff8e8ea84e440f2872bea (diff)
downloadstrace-f350ce0ffa5e25179c8c782045a8462b2946ead4.tar.gz
Add tests for PID namespace translationAkosUzonyi/pidns
* Makefile.am (CODE_COVERAGE_IGNORE_PATTERN): Add test directories. * tests/.gitignore: Add new test executables. * tests/Makefile.am (check_PROGRAMS): Add new test executables. (DECODER_TESTS) Add new test files. (libtests_a_SOURCES): Add trie_for_tests.c, xmalloc_for_tests.c. * tests/gen_tests.in: Add new tests. * tests/trie_test.c: New file. * tests/trie_for_tests.c: New file. * tests/xmalloc_for_tests.c: New file. * tests/pidns-cache.c: New file. * tests/pidns-cache.test: New file. * tests/fcntl--pidns-translation.c: New file. * tests/fcntl64--pidns-translation.c: New file. * tests/fork--pidns-translation.awk: New file. * tests/fork--pidns-translation.c: New file. * tests/fork--pidns-translation.test: New file. * tests/getpgrp--pidns-translation.c: New file. * tests/getpid--pidns-translation.c: New file. * tests/getsid--pidns-translation.c: New file. * tests/gettid--pidns-translation.c: New file. * tests/gettid--pidns-translation.test: New file. * tests/ioctl_block--pidns-translation.c: New file. * tests/ioctl_block--pidns-translation.test: New file. * tests/ioprio--pidns-translation.c: New file. * tests/kill--pidns-translation.c: New file. * tests/migrate_pages--pidns-translation.c: New file. * tests/move_pages--pidns-translation.c: New file. * tests/net-sockaddr--pidns-translation.c: New file. * tests/netlink_audit--pidns-translation.c: New file. * tests/netlink_audit--pidns-translation.test: New file. * tests/pidfd_open--pidns-translation.c: New file. * tests/pidfd_send_signal--pidns-translation.c: New file. * tests/prlimit64--pidns-translation.c: New file. * tests/process_vm_readv--pidns-translation.c: New file. * tests/process_vm_writev--pidns-translation.c: New file. * tests/rt_sigqueueinfo--pidns-translation.c: New file. * tests/rt_tgsigqueueinfo--pidns-translation.c: New file. * tests/sched_xetaffinity--pidns-translation.c: New file. * tests/sched_xetattr--pidns-translation.c: New file. * tests/sched_xetparam--pidns-translation.c: New file. * tests/sched_xetscheduler--pidns-translation.c: New file. * tests/signal_receive--pidns-translation.c: New file. * tests/so_peercred--pidns-translation.c: New file. * tests/tkill--pidns-translation.c: New file. * tests/tgkill--pidns-translation.c: New file. * tests/xet_robust_list--pidns-translation.c: New file. * tests/xetpgid--pidns-translation.c: New file. * tests/xetpriority--pidns-translation.c: New file. * tests/fcntl-common.c: Print PID translation string after PIDs. * tests/fcntl.c: Likewise. * tests/fcntl64.c: Likewise. * tests/getpgrp.c: Likewise. * tests/getpid.c: Likewise. * tests/getsid.c: Likewise. * tests/gettid.c: Likewise. * tests/ioctl_block.c: Likewise. * tests/ioprio.c: Likewise. * tests/kcmp.c: Likewise. * tests/kill.c: Likewise. * tests/migrate_pages.c: Likewise. * tests/move_pages.c: Likewise. * tests/net-sockaddr.c: Likewise. * tests/netlink_audit.c: Likewise. * tests/pidfd_open.c: Likewise. * tests/pidfd_send_signal.c: Likewise. * tests/prlimit64.c: Likewise. * tests/process_vm_readv_writev.c: Likewise. * tests/rt_sigqueueinfo.c: Likewise. * tests/rt_tgsigqueueinfo.c: Likewise. * tests/sched_xetaffinity.c: Likewise. * tests/sched_xetattr.c: Likewise. * tests/sched_xetparam.c: Likewise. * tests/sched_xetscheduler.c: Likewise. * tests/signal_receive.c: Likewise. * tests/so_peercred.c: Likewise. * tests/tgkill.c: Likewise. * tests/tkill.c: Likewise. * tests/xet_robust_list.c: Likewise. * tests/xetpgid.c: Likewise. * tests/xetpriority.c: Likewise.
-rw-r--r--Makefile.am2
-rw-r--r--tests/.gitignore35
-rw-r--r--tests/Makefile.am47
-rw-r--r--tests/fcntl--pidns-translation.c2
-rw-r--r--tests/fcntl-common.c78
-rw-r--r--tests/fcntl.c1
-rw-r--r--tests/fcntl64--pidns-translation.c2
-rw-r--r--tests/fcntl64.c3
-rw-r--r--tests/fork--pidns-translation.awk15
-rw-r--r--tests/fork--pidns-translation.c78
-rwxr-xr-xtests/fork--pidns-translation.test14
-rw-r--r--tests/gen_tests.in32
-rw-r--r--tests/getpgrp--pidns-translation.c2
-rw-r--r--tests/getpgrp.c8
-rw-r--r--tests/getpid--pidns-translation.c2
-rw-r--r--tests/getpid.c8
-rw-r--r--tests/getsid--pidns-translation.c2
-rw-r--r--tests/getsid.c9
-rw-r--r--tests/gettid--pidns-translation.c2
-rwxr-xr-xtests/gettid--pidns-translation.test18
-rw-r--r--tests/gettid.c8
-rw-r--r--tests/ioctl_block--pidns-translation.c2
-rwxr-xr-xtests/ioctl_block--pidns-translation.test22
-rw-r--r--tests/ioctl_block.c24
-rw-r--r--tests/ioprio--pidns-translation.c2
-rw-r--r--tests/ioprio.c54
-rw-r--r--tests/kcmp-y--pidns-translation.c2
-rw-r--r--tests/kcmp.c11
-rw-r--r--tests/kill--pidns-translation.c2
-rw-r--r--tests/kill.c12
-rw-r--r--tests/migrate_pages--pidns-translation.c2
-rw-r--r--tests/migrate_pages.c17
-rw-r--r--tests/move_pages--pidns-translation.c2
-rw-r--r--tests/move_pages.c51
-rw-r--r--tests/net-sockaddr--pidns-translation.c2
-rw-r--r--tests/net-sockaddr.c60
-rw-r--r--tests/netlink_audit--pidns-translation.c2
-rwxr-xr-xtests/netlink_audit--pidns-translation.test13
-rw-r--r--tests/netlink_audit.c11
-rw-r--r--tests/pidfd_open--pidns-translation.c2
-rw-r--r--tests/pidfd_open.c21
-rw-r--r--tests/pidfd_send_signal--pidns-translation.c2
-rw-r--r--tests/pidfd_send_signal.c13
-rw-r--r--tests/pidns-cache.c62
-rwxr-xr-xtests/pidns-cache.test15
-rw-r--r--tests/prlimit64--pidns-translation.c2
-rw-r--r--tests/prlimit64.c17
-rw-r--r--tests/process_vm_readv--pidns-translation.c2
-rw-r--r--tests/process_vm_readv_writev.c27
-rw-r--r--tests/process_vm_writev--pidns-translation.c2
-rw-r--r--tests/rt_sigqueueinfo--pidns-translation.c2
-rw-r--r--tests/rt_sigqueueinfo.c15
-rw-r--r--tests/rt_tgsigqueueinfo--pidns-translation.c2
-rw-r--r--tests/rt_tgsigqueueinfo.c26
-rw-r--r--tests/sched_xetaffinity--pidns-translation.c2
-rw-r--r--tests/sched_xetaffinity.c31
-rw-r--r--tests/sched_xetattr--pidns-translation.c2
-rw-r--r--tests/sched_xetattr.c47
-rw-r--r--tests/sched_xetparam--pidns-translation.c2
-rw-r--r--tests/sched_xetparam.c20
-rw-r--r--tests/sched_xetscheduler--pidns-translation.c2
-rw-r--r--tests/sched_xetscheduler.c44
-rw-r--r--tests/signal_receive--pidns-translation.c2
-rw-r--r--tests/signal_receive.c22
-rw-r--r--tests/so_peercred--pidns-translation.c2
-rw-r--r--tests/so_peercred.c22
-rw-r--r--tests/tgkill--pidns-translation.c2
-rw-r--r--tests/tgkill.c51
-rw-r--r--tests/tkill--pidns-translation.c2
-rw-r--r--tests/tkill.c19
-rw-r--r--tests/trie_for_tests.c1
-rw-r--r--tests/trie_test.c121
-rw-r--r--tests/xet_robust_list--pidns-translation.c2
-rw-r--r--tests/xet_robust_list.c18
-rw-r--r--tests/xetpgid--pidns-translation.c2
-rw-r--r--tests/xetpgid.c21
-rw-r--r--tests/xetpriority--pidns-translation.c2
-rw-r--r--tests/xetpriority.c20
-rw-r--r--tests/xmalloc_for_tests.c2
79 files changed, 1143 insertions, 187 deletions
diff --git a/Makefile.am b/Makefile.am
index f4bd0e0d9..f79d93437 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -409,7 +409,7 @@ endif
CODE_COVERAGE_BRANCH_COVERAGE = 1
CODE_COVERAGE_GENHTML_OPTIONS = $(CODE_COVERAGE_GENHTML_OPTIONS_DEFAULT) \
--prefix $(shell cd $(abs_top_srcdir)/.. && pwd || echo .)
-CODE_COVERAGE_IGNORE_PATTERN = '/usr/include/*'
+CODE_COVERAGE_IGNORE_PATTERN = '/usr/include/*' '*/tests/*' '*/tests-m32/*' '*/tests-mx32/*'
strace_CPPFLAGS += $(CODE_COVERAGE_CPPFLAGS)
strace_CFLAGS += $(CODE_COVERAGE_CFLAGS)
strace_LDADD += $(CODE_COVERAGE_LIBS)
diff --git a/tests/.gitignore b/tests/.gitignore
index 34e98320d..990533c94 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -116,7 +116,9 @@ fchown
fchown32
fchownat
fcntl
+fcntl--pidns-translation
fcntl64
+fcntl64--pidns-translation
fdatasync
fflush
file_handle
@@ -126,6 +128,7 @@ filter-unavailable
finit_module
flock
fork-f
+fork--pidns-translation
fsconfig
fsconfig-P
fsmount
@@ -168,7 +171,9 @@ getgroups
getgroups32
getpeername
getpgrp
+getpgrp--pidns-translation
getpid
+getpid--pidns-translation
getppid
getrandom
getresgid
@@ -178,8 +183,10 @@ getresuid32
getrlimit
getrusage
getsid
+getsid--pidns-translation
getsockname
gettid
+gettid--pidns-translation
getuid
getuid32
getxgid
@@ -200,6 +207,7 @@ io_uring_register
io_uring_setup
ioctl
ioctl_block
+ioctl_block--pidns-translation
ioctl_dm
ioctl_dm-v
ioctl_evdev
@@ -275,6 +283,7 @@ ioctl_watchdog
ioperm
iopl
ioprio
+ioprio--pidns-translation
ioprio-Xabbrev
ioprio-Xraw
ioprio-Xverbose
@@ -299,6 +308,7 @@ ipc_shm-Xverbose
is_linux_mips_n64
kcmp
kcmp-y
+kcmp-y--pidns-translation
kern_features
kernel_version
kernel_version-Xabbrev
@@ -311,6 +321,7 @@ keyctl-Xabbrev
keyctl-Xraw
keyctl-Xverbose
kill
+kill--pidns-translation
kill_child
ksysent
ksysent.h
@@ -340,6 +351,7 @@ memfd_create-Xabbrev
memfd_create-Xraw
memfd_create-Xverbose
migrate_pages
+migrate_pages--pidns-translation
mincore
mkdir
mkdirat
@@ -371,6 +383,7 @@ move_pages
move_pages-Xabbrev
move_pages-Xraw
move_pages-Xverbose
+move_pages--pidns-translation
mq
mq_sendrecv
mq_sendrecv-read
@@ -391,6 +404,7 @@ net-packet_mreq-Xabbrev
net-packet_mreq-Xraw
net-packet_mreq-Xverbose
net-sockaddr
+net-sockaddr--pidns-translation
net-tpacket_req
net-tpacket_stats
net-tpacket_stats-success
@@ -400,6 +414,7 @@ net-yy-inet6
net-yy-netlink
net-yy-unix
netlink_audit
+netlink_audit--pidns-translation
netlink_crypto
netlink_generic
netlink_inet_diag
@@ -507,7 +522,10 @@ pidfd_open--decode-fd-socket
pidfd_open-P
pidfd_open-y
pidfd_open-yy
+pidfd_open--pidns-translation
pidfd_send_signal
+pidfd_send_signal--pidns-translation
+pidns-cache
pipe
pipe2
pkey_alloc
@@ -546,8 +564,11 @@ printstrn-umoven
printstrn-umoven-peekdata
printstrn-umoven-undumpable
prlimit64
+prlimit64--pidns-translation
process_vm_readv
+process_vm_readv--pidns-translation
process_vm_writev
+process_vm_writev--pidns-translation
pselect6
ptrace
ptrace_syscall_info
@@ -597,10 +618,12 @@ rt_sigaction
rt_sigpending
rt_sigprocmask
rt_sigqueueinfo
+rt_sigqueueinfo--pidns-translation
rt_sigreturn
rt_sigsuspend
rt_sigtimedwait
rt_tgsigqueueinfo
+rt_tgsigqueueinfo--pidns-translation
run_expect_termsig
s390_guarded_storage
s390_guarded_storage-v
@@ -611,9 +634,13 @@ s390_sthyi-v
sched_get_priority_mxx
sched_rr_get_interval
sched_xetaffinity
+sched_xetaffinity--pidns-translation
sched_xetattr
+sched_xetattr--pidns-translation
sched_xetparam
+sched_xetparam--pidns-translation
sched_xetscheduler
+sched_xetscheduler--pidns-translation
sched_yield
scm_rights
scno.h
@@ -669,6 +696,7 @@ sigaltstack
siginfo
signal
signal_receive
+signal_receive--pidns-translation
signalfd4
sigpending
sigprocmask
@@ -681,6 +709,7 @@ so_peercred
so_peercred-Xabbrev
so_peercred-Xraw
so_peercred-Xverbose
+so_peercred--pidns-translation
sock_filter-v
sock_filter-v-Xabbrev
sock_filter-v-Xraw
@@ -731,6 +760,7 @@ syslog
syslog-success
tee
tgkill
+tgkill--pidns-translation
threads-execve
threads-execve--quiet-thread-execve
threads-execve-q
@@ -743,7 +773,9 @@ timerfd_xettime
times
times-fail
tkill
+tkill--pidns-translation
tracer_ppid_pgid_sid
+trie_test
truncate
truncate64
ugetrlimit
@@ -784,9 +816,12 @@ waitpid
xattr
xattr-strings
xet_robust_list
+xet_robust_list--pidns-translation
xet_thread_area_x86
xetitimer
xetpgid
+xetpgid--pidns-translation
xetpriority
+xetpriority--pidns-translation
xettimeofday
zeroargc
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7a583a3a5..17f4b4245 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -66,6 +66,7 @@ libtests_a_SOURCES = \
test_ucopy.h \
tests.h \
tprintf.c \
+ xmalloc_for_tests.c \
# end of libtests_a_SOURCES
libtests_a_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
check_LIBRARIES = libtests.a
@@ -109,17 +110,25 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
delay \
execve-v \
execveat-v \
+ fcntl--pidns-translation \
+ fcntl64--pidns-translation \
filter_seccomp-flag \
filter_seccomp-perf \
filter-unavailable \
fork-f \
+ fork--pidns-translation \
fsync-y \
get_process_reaper \
+ getpgrp--pidns-translation \
getpid \
+ getpid--pidns-translation \
getppid \
+ getsid--pidns-translation \
gettid \
+ gettid--pidns-translation \
inject-nf \
int_0x80 \
+ ioctl_block--pidns-translation \
ioctl_dm-v \
ioctl_evdev-success \
ioctl_evdev-success-Xabbrev \
@@ -150,18 +159,25 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
ioctl_v4l2-success-v-Xabbrev \
ioctl_v4l2-success-v-Xraw \
ioctl_v4l2-success-v-Xverbose \
+ ioprio--pidns-translation \
is_linux_mips_n64 \
+ kcmp-y--pidns-translation \
kill_child \
+ kill--pidns-translation \
ksysent \
list_sigaction_signum \
localtime \
looping_threads \
+ migrate_pages--pidns-translation \
mmsg-silent \
mmsg_name-v \
+ move_pages--pidns-translation \
msg_control-v \
net-accept-connect \
+ net-sockaddr--pidns-translation \
net-tpacket_stats-success \
nlattr_ifla_xdp-y \
+ netlink_audit--pidns-translation \
netlink_inet_diag \
netlink_netlink_diag \
netlink_unix_diag \
@@ -173,14 +189,20 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
pc \
perf_event_open_nonverbose \
perf_event_open_unabbrev \
+ pidfd_open--pidns-translation \
+ pidfd_send_signal--pidns-translation \
+ pidns-cache \
poll-P \
ppoll-P \
ppoll-v \
+ prlimit64--pidns-translation \
prctl-seccomp-filter-v \
prctl-seccomp-strict \
prctl-spec-inject \
print_maxfd \
print_ppid_tracerpid \
+ process_vm_readv--pidns-translation \
+ process_vm_writev--pidns-translation \
qual_fault \
qual_inject-error-signal \
qual_inject-retval \
@@ -194,7 +216,13 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
quotactl-xfs-v \
redirect-fds \
restart_syscall \
+ rt_sigqueueinfo--pidns-translation \
+ rt_tgsigqueueinfo--pidns-translation \
run_expect_termsig \
+ sched_xetaffinity--pidns-translation \
+ sched_xetattr--pidns-translation \
+ sched_xetparam--pidns-translation \
+ sched_xetscheduler--pidns-translation \
scm_rights \
seccomp-filter-v \
seccomp-strict \
@@ -204,25 +232,33 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
set_sigign \
setpgrp-exec \
signal_receive \
+ signal_receive--pidns-translation \
sleep \
stack-fcall \
stack-fcall-attach \
stack-fcall-mangled \
status-none-threads \
status-unfinished-threads \
+ so_peercred--pidns-translation \
syslog-success \
+ tgkill--pidns-translation \
threads-execve \
threads-execve--quiet-thread-execve \
threads-execve-q \
threads-execve-qq \
threads-execve-qqq \
+ tkill--pidns-translation \
tracer_ppid_pgid_sid \
+ trie_test \
unblock_reset_raise \
unix-pair-send-recv \
unix-pair-sendto-recvfrom \
vfork-f \
wait4-v \
waitid-v \
+ xetpgid--pidns-translation \
+ xetpriority--pidns-translation \
+ xet_robust_list--pidns-translation \
zeroargc \
# end of check_PROGRAMS
@@ -272,6 +308,11 @@ stack_fcall_mangled_SOURCES = stack-fcall-mangled.c \
stack-fcall-mangled-0.c stack-fcall-mangled-1.c \
stack-fcall-mangled-2.c stack-fcall-mangled-3.c
+trie_test_SOURCES = trie_test.c trie_for_tests.c
+trie_test_CPPFLAGS = $(AM_CPPFLAGS) $(CODE_COVERAGE_CPPFLAGS)
+trie_test_CFLAGS = $(AM_CFLAGS) $(CODE_COVERAGE_CFLAGS)
+trie_test_LDADD = $(LDADD) $(CODE_COVERAGE_LIBS)
+
include gen_tests.am
if ENABLE_STACKTRACE
@@ -310,6 +351,7 @@ DECODER_TESTS = \
int_0x80.test \
inotify_init-y.test \
ioctl.test \
+ ioctl_block--pidns-translation.test \
ioctl_evdev-success.test \
ipc_msgbuf.test \
kern_features-fault.test \
@@ -381,15 +423,19 @@ MISC_TESTS = \
filtering_fd-syntax.test \
filtering_syscall-syntax.test \
first_exec_failure.test \
+ fork--pidns-translation.test \
get_regs.test \
+ gettid--pidns-translation.test \
inject-nf.test \
interactive_block.test \
kill_child.test \
localtime.test \
looping_threads.test \
+ netlink_audit--pidns-translation.test \
opipe.test \
options-syntax.test \
pc.test \
+ pidns-cache.test \
printpath-umovestr-legacy.test \
printstrn-umoven-legacy.test \
qual_fault-syntax.test \
@@ -467,6 +513,7 @@ EXTRA_DIST = \
filter_seccomp.in \
filter_seccomp.sh \
filter-unavailable.expected \
+ fork--pidns-translation.awk \
fstatat.c \
fstatx.c \
gen_pure_executables.sh \
diff --git a/tests/fcntl--pidns-translation.c b/tests/fcntl--pidns-translation.c
new file mode 100644
index 000000000..e249424a4
--- /dev/null
+++ b/tests/fcntl--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "fcntl.c"
diff --git a/tests/fcntl-common.c b/tests/fcntl-common.c
index 27694326d..ec18aa798 100644
--- a/tests/fcntl-common.c
+++ b/tests/fcntl-common.c
@@ -13,6 +13,8 @@
#include <unistd.h>
#include <assert.h>
#include "flock.h"
+#include "pidns.h"
+#include "scno.h"
#define FILE_LEN 4096
@@ -48,12 +50,14 @@ test_flock_einval(const int cmd, const char *name)
fl->l_len = (TYPEOF_FLOCK_OFF_T) 0xdefaced2cafef00dULL;
invoke_test_syscall(0, cmd, fl);
+ pidns_print_leader();
printf("%s(0, %s, {l_type=F_RDLCK, l_whence=SEEK_SET"
", l_start=%jd, l_len=%jd}) = %s\n", TEST_SYSCALL_STR, name,
(intmax_t) fl->l_start, (intmax_t) fl->l_len, errstr);
void *const bad_addr = (void *) fl + 1;
invoke_test_syscall(0, cmd, bad_addr);
+ pidns_print_leader();
printf("%s(0, %s, %p) = %s\n",
TEST_SYSCALL_STR, name, bad_addr, errstr);
}
@@ -72,12 +76,14 @@ test_flock64_einval(const int cmd, const char *name)
fl->l_len = (TYPEOF_FLOCK_OFF_T) 0xdefaced2cafef00dULL;
invoke_test_syscall(0, cmd, fl);
+ pidns_print_leader();
printf("%s(0, %s, {l_type=F_RDLCK, l_whence=SEEK_SET"
", l_start=%jd, l_len=%jd}) = %s\n", TEST_SYSCALL_STR, name,
(intmax_t) fl->l_start, (intmax_t) fl->l_len, errstr);
void *const bad_addr = (void *) fl + 1;
invoke_test_syscall(0, cmd, bad_addr);
+ pidns_print_leader();
printf("%s(0, %s, %p) = %s\n",
TEST_SYSCALL_STR, name, bad_addr, errstr);
}
@@ -94,6 +100,7 @@ test_flock(void)
fl->l_len = FILE_LEN;
long rc = invoke_test_syscall(0, F_SETLK, fl);
+ pidns_print_leader();
printf("%s(0, F_SETLK, {l_type=F_RDLCK, l_whence=SEEK_SET"
", l_start=0, l_len=%d}) = %s\n",
TEST_SYSCALL_STR, FILE_LEN, errstr);
@@ -101,11 +108,13 @@ test_flock(void)
return;
invoke_test_syscall(0, F_GETLK, fl);
+ pidns_print_leader();
printf("%s(0, F_GETLK, {l_type=F_UNLCK, l_whence=SEEK_SET"
", l_start=0, l_len=%d, l_pid=0}) = 0\n",
TEST_SYSCALL_STR, FILE_LEN);
invoke_test_syscall(0, F_SETLKW, fl);
+ pidns_print_leader();
printf("%s(0, F_SETLKW, {l_type=F_UNLCK, l_whence=SEEK_SET"
", l_start=0, l_len=%d}) = 0\n",
TEST_SYSCALL_STR, FILE_LEN);
@@ -124,6 +133,7 @@ test_flock64_ofd(void)
fl->l_len = FILE_LEN;
long rc = invoke_test_syscall(0, F_OFD_SETLK, fl);
+ pidns_print_leader();
printf("%s(0, F_OFD_SETLK, {l_type=F_RDLCK, l_whence=SEEK_SET"
", l_start=0, l_len=%d}) = %s\n",
TEST_SYSCALL_STR, FILE_LEN, errstr);
@@ -131,11 +141,13 @@ test_flock64_ofd(void)
return;
invoke_test_syscall(0, F_OFD_GETLK, fl);
+ pidns_print_leader();
printf("%s(0, F_OFD_GETLK, {l_type=F_UNLCK, l_whence=SEEK_SET"
", l_start=0, l_len=%d, l_pid=0}) = 0\n",
TEST_SYSCALL_STR, FILE_LEN);
invoke_test_syscall(0, F_OFD_SETLKW, fl);
+ pidns_print_leader();
printf("%s(0, F_OFD_SETLKW, {l_type=F_UNLCK, l_whence=SEEK_SET"
", l_start=0, l_len=%d}) = 0\n",
TEST_SYSCALL_STR, FILE_LEN);
@@ -167,18 +179,21 @@ test_flock64(void)
static long
test_f_owner_ex_type_pid(const int cmd, const char *const cmd_name,
const int type, const char *const type_name,
- pid_t pid)
+ enum pid_type pid_type, pid_t pid)
{
TAIL_ALLOC_OBJECT_CONST_PTR(struct_kernel_f_owner_ex, fo);
fo->type = type;
fo->pid = pid;
long rc = invoke_test_syscall(0, cmd, fo);
- printf("%s(0, %s, {type=%s, pid=%d}) = %s\n",
- TEST_SYSCALL_STR, cmd_name, type_name, fo->pid, errstr);
+ pidns_print_leader();
+ printf("%s(0, %s, {type=%s, pid=%d%s}) = %s\n",
+ TEST_SYSCALL_STR, cmd_name, type_name,
+ fo->pid, pidns_pid2str(pid_type), errstr);
void *bad_addr = (void *) fo + 1;
invoke_test_syscall(0, cmd, bad_addr);
+ pidns_print_leader();
printf("%s(0, %s, %p) = %s\n",
TEST_SYSCALL_STR, cmd_name, bad_addr, errstr);
@@ -187,35 +202,35 @@ test_f_owner_ex_type_pid(const int cmd, const char *const cmd_name,
static void
test_f_owner_ex_umove_or_printaddr(const int type, const char *const type_name,
- pid_t pid)
+ enum pid_type pid_type, pid_t pid)
{
long rc = test_f_owner_ex_type_pid(ARG_STR(F_SETOWN_EX),
- type, type_name, pid);
+ type, type_name, pid_type, pid);
if (!rc)
test_f_owner_ex_type_pid(ARG_STR(F_GETOWN_EX),
- type, type_name, pid);
+ type, type_name, pid_type, pid);
}
static void
test_f_owner_ex(void)
{
- static const struct {
+ struct {
int type;
const char *type_name;
- pid_t pid[2];
+ enum pid_type pid_type;
+ pid_t pid;
} a[] = {
- { ARG_STR(F_OWNER_TID), { 1234567890, 20 } },
- { ARG_STR(F_OWNER_PID), { 1298126790, 30 } },
- { ARG_STR(F_OWNER_PGRP), { 1294567890, 40 } }
+ { ARG_STR(F_OWNER_TID), PT_NONE, 1234567890 },
+ { ARG_STR(F_OWNER_PID), PT_NONE, 1234567890 },
+ { ARG_STR(F_OWNER_PGRP), PT_NONE, 1234567890 },
+ { ARG_STR(F_OWNER_TID), PT_TID, syscall(__NR_gettid) },
+ { ARG_STR(F_OWNER_PID), PT_TGID, getpid() },
+ { ARG_STR(F_OWNER_PGRP), PT_PGID, getpgid(0) },
};
- for (unsigned int i = 0; i < ARRAY_SIZE(a); i++) {
- for (unsigned int j = 0; j < ARRAY_SIZE(a[0].pid); j++) {
- test_f_owner_ex_umove_or_printaddr(a[i].type,
- a[i].type_name,
- a[i].pid[j]);
- }
- }
+ for (unsigned int i = 0; i < ARRAY_SIZE(a); i++)
+ test_f_owner_ex_umove_or_printaddr(a[i].type, a[i].type_name,
+ a[i].pid_type, a[i].pid);
}
#endif /* TEST_F_OWNER_EX */
@@ -229,6 +244,23 @@ struct fcntl_cmd_check {
};
static void
+test_xetown(void)
+{
+ const int pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
+
+ invoke_test_syscall(0, F_SETOWN, (void *) (intptr_t) pid);
+ pidns_print_leader();
+ printf("%s(0, F_SETOWN, %d%s) = %s\n",
+ TEST_SYSCALL_STR, pid, pid_str, errstr);
+
+ invoke_test_syscall(0, F_GETOWN, NULL);
+ pidns_print_leader();
+ printf("%s(0, F_GETOWN) = %d%s\n",
+ TEST_SYSCALL_STR, pid, pid_str);
+}
+
+static void
print_retval_flags(const struct fcntl_cmd_check *check, long rc)
{
if (check->print_flags) {
@@ -243,12 +275,14 @@ static void
test_other_set_cmd(const struct fcntl_cmd_check *check)
{
invoke_test_syscall(check->fd, check->cmd, (void *) check->arg);
+ pidns_print_leader();
printf("%s(%d, %s, %s) = %s\n",
TEST_SYSCALL_STR, check->fd,
check->cmd_str, check->arg_str, errstr);
/* bad file fd */
invoke_test_syscall(-1, check->cmd, (void *) check->arg);
+ pidns_print_leader();
printf("%s(-1, %s, %s) = %s\n",
TEST_SYSCALL_STR, check->cmd_str,
check->arg_str, errstr);
@@ -258,12 +292,14 @@ static void
test_other_get_cmd(const struct fcntl_cmd_check *check)
{
long rc = invoke_test_syscall(check->fd, check->cmd, NULL);
+ pidns_print_leader();
printf("%s(%d, %s) = ",
TEST_SYSCALL_STR, check->fd, check->cmd_str);
print_retval_flags(check, rc);
/* bad file fd */
invoke_test_syscall(-1, check->cmd, NULL);
+ pidns_print_leader();
printf("%s(-1, %s) = %s\n",
TEST_SYSCALL_STR, check->cmd_str, errstr);
}
@@ -315,7 +351,6 @@ test_fcntl_others(void)
{
static const struct fcntl_cmd_check set_checks[] = {
{ 0, ARG_STR(F_SETFD), ARG_STR(FD_CLOEXEC) },
- { 0, ARG_STR(F_SETOWN), ARG_STR(20) },
#ifdef F_SETPIPE_SZ
{ 0, ARG_STR(F_SETPIPE_SZ), ARG_STR(4097) },
#endif
@@ -336,7 +371,6 @@ test_fcntl_others(void)
static const struct fcntl_cmd_check get_checks[] = {
{ 0, ARG_STR(F_GETFD), .print_flags = print_flags_getfd },
{ 1, ARG_STR(F_GETFD), .print_flags = print_flags_getfd },
- { 0, ARG_STR(F_GETOWN) },
#ifdef F_GETPIPE_SZ
{ 0, ARG_STR(F_GETPIPE_SZ) },
#endif
@@ -360,6 +394,8 @@ create_sample(void)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
create_sample();
test_flock();
test_flock64();
@@ -367,7 +403,9 @@ main(void)
test_f_owner_ex();
#endif
test_fcntl_others();
+ test_xetown();
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/fcntl.c b/tests/fcntl.c
index f38b8afb7..673c06e44 100644
--- a/tests/fcntl.c
+++ b/tests/fcntl.c
@@ -24,6 +24,7 @@ test_flock64_undecoded(const int cmd, const char *name)
.l_len = 0xdefaced2cafef00dULL
};
invoke_test_syscall(0, cmd, &fl);
+ pidns_print_leader();
printf("%s(0, %s, %p) = %s\n",
TEST_SYSCALL_STR, name, &fl, errstr);
}
diff --git a/tests/fcntl64--pidns-translation.c b/tests/fcntl64--pidns-translation.c
new file mode 100644
index 000000000..c6fdadd14
--- /dev/null
+++ b/tests/fcntl64--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "fcntl64.c"
diff --git a/tests/fcntl64.c b/tests/fcntl64.c
index 78e53b0d7..f7b3f2fb9 100644
--- a/tests/fcntl64.c
+++ b/tests/fcntl64.c
@@ -27,6 +27,7 @@ test_flock64_lk64(void)
fl->l_len = FILE_LEN;
long rc = invoke_test_syscall(0, F_SETLK64, fl);
+ pidns_print_leader();
printf("%s(0, F_SETLK64, {l_type=F_RDLCK, l_whence=SEEK_SET"
", l_start=0, l_len=%d}) = %s\n",
TEST_SYSCALL_STR, FILE_LEN, errstr);
@@ -35,11 +36,13 @@ test_flock64_lk64(void)
return;
invoke_test_syscall(0, F_GETLK64, fl);
+ pidns_print_leader();
printf("%s(0, F_GETLK64, {l_type=F_UNLCK, l_whence=SEEK_SET"
", l_start=0, l_len=%d, l_pid=0}) = 0\n",
TEST_SYSCALL_STR, FILE_LEN);
invoke_test_syscall(0, F_SETLKW64, fl);
+ pidns_print_leader();
printf("%s(0, F_SETLKW64, {l_type=F_UNLCK, l_whence=SEEK_SET"
", l_start=0, l_len=%d}) = 0\n",
TEST_SYSCALL_STR, FILE_LEN);
diff --git a/tests/fork--pidns-translation.awk b/tests/fork--pidns-translation.awk
new file mode 100644
index 000000000..ef6858f46
--- /dev/null
+++ b/tests/fork--pidns-translation.awk
@@ -0,0 +1,15 @@
+/fork/ {
+ match($0, "([0-9]+) in strace\x27s PID NS", a);
+ if (a[1])
+ fork_pid = a[1]
+}
+
+/exited with 0/ {
+ if (!exit_pid)
+ exit_pid = $1
+}
+
+END {
+ if (!fork_pid || !exit_pid || fork_pid != exit_pid)
+ exit 1
+}
diff --git a/tests/fork--pidns-translation.c b/tests/fork--pidns-translation.c
new file mode 100644
index 000000000..1499a6030
--- /dev/null
+++ b/tests/fork--pidns-translation.c
@@ -0,0 +1,78 @@
+/*
+ * Test PID namespace translation
+ *
+ * Copyright (c) 2020 Ákos Uzonyi <uzonyi.akos@gmail.com>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "tests.h"
+#include "scno.h"
+#include "pidns.h"
+
+#ifdef __NR_fork
+
+#include <errno.h>
+#include <limits.h>
+#include <sched.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <linux/sched.h>
+#include "nsfs.h"
+
+#ifndef CLONE_NEWUSER
+# define CLONE_NEWUSER 0x10000000
+#endif
+
+#ifndef CLONE_NEWPID
+# define CLONE_NEWPID 0x20000000
+#endif
+
+static int
+fork_chain(int depth)
+{
+ if (!depth)
+ return 0;
+
+ int pid = syscall(__NR_fork);
+ if (pid < 0)
+ return errno;
+
+ if (!pid)
+ _exit(fork_chain(depth - 1));
+
+ int status;
+ if (wait(&status) < 0)
+ return errno;
+
+ if (!WIFEXITED(status))
+ return -1;
+
+ return WEXITSTATUS(status);
+}
+
+int main(void)
+{
+ check_ns_ioctl();
+
+ if (unshare(CLONE_NEWPID | CLONE_NEWUSER) < 0) {
+ if (errno == EPERM)
+ perror_msg_and_skip("unshare");
+
+ perror_msg_and_fail("unshare");
+ }
+
+ errno = fork_chain(2);
+ if (errno)
+ perror("fork_chain");
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_fork")
+
+#endif
diff --git a/tests/fork--pidns-translation.test b/tests/fork--pidns-translation.test
new file mode 100755
index 000000000..24cc59304
--- /dev/null
+++ b/tests/fork--pidns-translation.test
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# Check pidns translation of fork's return value.
+#
+# Copyright (c) 2020 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+. "${srcdir=.}/init.sh"
+
+run_prog
+run_strace -a6 --pidns-translation -f -e trace=fork $args
+match_awk
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 76e770ba9..1529f26d6 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -93,7 +93,9 @@ fchown -a16
fchown32 -a18
fchownat
fcntl -a8
+fcntl--pidns-translation test_pidns -a8 -e trace=fcntl
fcntl64 -a8
+fcntl64--pidns-translation test_pidns -a8 -e trace=fcntl64
fdatasync -a14
file_handle -e trace=name_to_handle_at,open_by_handle_at
file_ioctl +ioctl.test
@@ -147,7 +149,9 @@ getgroups -a17
getgroups32 -a19
getpeername -a27
getpgrp -a10
+getpgrp--pidns-translation test_pidns -e trace=getpgrp -a10
getpid -a9
+getpid--pidns-translation test_pidns -e trace=getpid -a9
getppid -a10
getrandom -a32 -s3
getresgid -a25
@@ -157,6 +161,7 @@ getresuid32 -a27
getrlimit -a27
getrusage -v
getsid -a10
+getsid--pidns-translation test_pidns -e trace=getsid -a10
getsockname -a27
gettid -a9
getuid-creds +getuid.test
@@ -250,6 +255,7 @@ ioctl_watchdog +ioctl.test
ioperm -a27
iopl -a8
ioprio -a18 -e trace=ioprio_get,ioprio_set
+ioprio--pidns-translation test_pidns -a18 -e trace=ioprio_get,ioprio_set
ioprio-Xabbrev -a18 -e trace=ioprio_get,ioprio_set -Xabbrev
ioprio-Xraw -a18 -e trace=ioprio_get,ioprio_set -Xraw
ioprio-Xverbose -a18 -e trace=ioprio_get,ioprio_set -Xverbose
@@ -272,6 +278,7 @@ ipc_shm-Xraw +ipc.sh -Xraw -a19
ipc_shm-Xverbose +ipc.sh -Xverbose -a34
kcmp -a22
kcmp-y -a22 -y -e trace=kcmp
+kcmp-y--pidns-translation test_pidns -a22 -y -e trace=kcmp
kern_features -a16
kernel_version -a16 -v -e trace=bpf
kernel_version-Xabbrev -a16 -Xabbrev -v -e trace=bpf
@@ -284,6 +291,7 @@ keyctl-Xabbrev -a31 -s10 -e trace=keyctl -Xabbrev
keyctl-Xraw -a13 -s10 -e trace=keyctl -Xraw
keyctl-Xverbose -a41 -s10 -e trace=keyctl -Xverbose
kill -a12 -esignal=none
+kill--pidns-translation test_pidns -a12 -e trace=kill -esignal=none
ksysent ../$NAME
lchown -a30
lchown32 -a32
@@ -305,6 +313,7 @@ memfd_create-Xabbrev -Xabbrev -e trace=memfd_create
memfd_create-Xraw -a30 -Xraw -e trace=memfd_create
memfd_create-Xverbose -Xverbose -e trace=memfd_create
migrate_pages -a33
+migrate_pages--pidns-translation test_pidns -a33 -e trace=migrate_pages
mincore -a22
mkdir -a20
mkdirat -a28
@@ -335,6 +344,7 @@ move_pages -s3
move_pages-Xabbrev -s3 -e trace=move_pages -Xabbrev
move_pages-Xraw -s3 -a36 -e trace=move_pages -Xraw
move_pages-Xverbose -s3 -e trace=move_pages -Xverbose
+move_pages--pidns-translation test_pidns -s3 -e trace=move_pages
mq -a32 -e trace=mq_getsetattr,mq_open,mq_unlink
mq_sendrecv -a14 -e trace=mq_open,mq_notify,mq_timedsend,mq_timedreceive,mq_unlink
mq_sendrecv-read -eread=0 -a14 -e trace=mq_open,mq_notify,mq_timedsend,mq_timedreceive,mq_unlink
@@ -354,6 +364,7 @@ net-packet_mreq-Xabbrev -e trace=setsockopt -Xabbrev
net-packet_mreq-Xraw -e trace=setsockopt -Xraw
net-packet_mreq-Xverbose -e trace=setsockopt -Xverbose
net-sockaddr -a24 -e trace=connect
+net-sockaddr--pidns-translation test_pidns -a24 -e trace=connect
net-tpacket_req -e trace=setsockopt
net-tpacket_stats -e trace=getsockopt
net-yy-inet6 +net-yy-inet.test
@@ -457,7 +468,9 @@ pidfd_open--decode-fd-socket -a17 -e decode-fd=socket -e trace=pidfd_open
pidfd_open-P -a17 -P /dev/full -e trace=pidfd_open
pidfd_open-y -a17 -y -e trace=pidfd_open
pidfd_open-yy -a17 -yy -e trace=pidfd_open
+pidfd_open--pidns-translation test_pidns -a17 -e trace=pidfd_open
pidfd_send_signal
+pidfd_send_signal--pidns-translation test_pidns -e trace=pidfd_send_signal
pipe2 -a15
pkey_alloc -a17
pkey_free -a13
@@ -480,8 +493,11 @@ printstrn-umoven -s4096 -e signal=none -e trace=add_key
printstrn-umoven-peekdata -e signal=none -e trace=add_key
printstrn-umoven-undumpable -e signal=none -e trace=add_key
prlimit64
+prlimit64--pidns-translation test_pidns -e trace=prlimit64
process_vm_readv -s5 -a37
+process_vm_readv--pidns-translation test_pidns -s5 -a37 -e trace=process_vm_readv
process_vm_writev -s5 -a38
+process_vm_writev--pidns-translation test_pidns -s5 -a38 -e trace=process_vm_writev
pselect6
ptrace -a23 -e signal=none
ptrace_syscall_info -a35 -e signal=none -e trace=ptrace
@@ -518,10 +534,12 @@ rmdir -a22
rt_sigpending -a20
rt_sigprocmask
rt_sigqueueinfo -esignal=none
+rt_sigqueueinfo--pidns-translation test_pidns -esignal=none -e trace=rt_sigqueueinfo
rt_sigreturn -esignal='!USR1'
rt_sigsuspend -a20 -esignal=none
rt_sigtimedwait -a38
rt_tgsigqueueinfo -esignal=none
+rt_tgsigqueueinfo--pidns-translation test_pidns -esignal=none -e trace=rt_tgsigqueueinfo
s390_guarded_storage -a32
s390_guarded_storage-v -e trace=s390_guarded_storage -a32 -v
s390_pci_mmio_read_write -e trace=s390_pci_mmio_read,s390_pci_mmio_write -a30
@@ -532,9 +550,13 @@ sched test_trace_expr times -e/sched
sched_get_priority_mxx -a33 -e trace=sched_get_priority_min,sched_get_priority_max
sched_rr_get_interval -a31
sched_xetaffinity -a28 -e trace=sched_getaffinity,sched_setaffinity
+sched_xetaffinity--pidns-translation test_pidns -a28 -e trace=sched_getaffinity,sched_setaffinity
sched_xetattr -a29 -e trace=sched_getattr,sched_setattr
+sched_xetattr--pidns-translation test_pidns -a29 -e trace=sched_getattr,sched_setattr
sched_xetparam -a23 -e trace=sched_getparam,sched_setparam
+sched_xetparam--pidns-translation test_pidns -a23 -e trace=sched_getparam,sched_setparam
sched_xetscheduler -a22 -e trace=sched_getscheduler,sched_setscheduler
+sched_xetscheduler--pidns-translation test_pidns -a22 -e trace=sched_getscheduler,sched_setscheduler
sched_yield -a14
seccomp-filter -e trace=seccomp
seccomp-filter-v -v -e trace=seccomp
@@ -581,6 +603,7 @@ sigaction -a31
siginfo -e trace=none
signal -a25 -e signal=none -e trace='/^signal$'
signal_receive -a16 -e trace=kill
+signal_receive--pidns-translation test_pidns -a16 -e trace=kill
signalfd4
sigpending -a15
sigprocmask -a34
@@ -592,6 +615,7 @@ so_peercred -e trace=getsockopt
so_peercred-Xabbrev -e trace=getsockopt -Xabbrev
so_peercred-Xraw -e trace=getsockopt -Xraw -a39
so_peercred-Xverbose -e trace=getsockopt -Xverbose
+so_peercred--pidns-translation test_pidns -e trace=getsockopt
sock_filter-v -v -e trace=getsockopt,setsockopt
sock_filter-v-Xabbrev -v -e trace=getsockopt,setsockopt -X abbrev
sock_filter-v-Xraw -a 37 -v -e trace=getsockopt,setsockopt -X raw
@@ -665,6 +689,7 @@ sysinfo -a14
syslog -a35
tee
tgkill -a15 --signal='!cont'
+tgkill--pidns-translation test_pidns -a15 --signal='!cont' -e trace=tgkill
threads-execve--quiet-thread-execve +threads-execve.test -s40 --quiet=personality,thread-execve
threads-execve-q +threads-execve.test -q
threads-execve-qq +threads-execve.test -qq
@@ -676,6 +701,7 @@ timerfd_xettime -e trace=timerfd_create,timerfd_settime,timerfd_gettime
times -esignal=none
times-fail -a12 -e trace=times
tkill -a12 --signal='!cont'
+tkill--pidns-translation test_pidns --signal='!cont' -a12 -e trace=tkill
trace_clock test_trace_expr 'clock_nanosleep|times' -e%clock
trace_creds test_trace_expr '([gs]et[^p]*([gu]id|groups)|caps|prctl|[fl]?chown|print(path-umovestr|strn-umoven)-undumpable|ptrace|quotactl|rt_sigtimedwait|rt_(tg)?sigqueueinfo).*' -e%creds
trace_fstat test_trace_expr '' -e%fstat -v -P stat.sample -P /dev/full
@@ -692,6 +718,7 @@ trace_stat test_trace_expr '' -e%stat -v -P stat.sample -P /dev/full
trace_stat_like test_trace_expr '' -e%%stat -v -P stat.sample -P /dev/full
trace_statfs test_trace_expr '' -e%statfs
trace_statfs_like test_trace_expr '' -e%%statfs
+trie_test run_prog
truncate
truncate64
ugetrlimit -a28
@@ -722,7 +749,10 @@ waitpid -a28
xattr -a22 -e trace=getxattr,fgetxattr,lgetxattr,setxattr,fsetxattr,lsetxattr,listxattr,flistxattr,llistxattr,removexattr,fremovexattr,lremovexattr
xattr-strings -a22 -s 4 -e trace=fsetxattr
xet_robust_list -a24 -e trace=get_robust_list,set_robust_list
+xet_robust_list--pidns-translation test_pidns -a24 -e trace=get_robust_list,set_robust_list
xetitimer -a29 -e trace=setitimer,getitimer
xetpgid -a11 -e trace=getpgid,setpgid
-xetpriority -a29 -e trace=getpriority,setpriority
+xetpgid--pidns-translation test_pidns -a11 -e trace=getpgid,setpgid
+xetpriority -a27 -e trace=getpriority,setpriority
+xetpriority--pidns-translation test_pidns -a27 -e trace=getpriority,setpriority
xettimeofday -a20 -e trace=gettimeofday,settimeofday
diff --git a/tests/getpgrp--pidns-translation.c b/tests/getpgrp--pidns-translation.c
new file mode 100644
index 000000000..de8ceb337
--- /dev/null
+++ b/tests/getpgrp--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "getpgrp.c"
diff --git a/tests/getpgrp.c b/tests/getpgrp.c
index 104f48118..3f0b9dd1a 100644
--- a/tests/getpgrp.c
+++ b/tests/getpgrp.c
@@ -7,6 +7,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#ifdef __NR_getpgrp
@@ -16,8 +17,13 @@
int
main(void)
{
- printf("getpgrp() = %ld\n", syscall(__NR_getpgrp));
+ PIDNS_TEST_INIT;
+ pidns_print_leader();
+ printf("getpgrp() = %d%s\n", (int) syscall(__NR_getpgrp),
+ pidns_pid2str(PT_PGID));
+
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/getpid--pidns-translation.c b/tests/getpid--pidns-translation.c
new file mode 100644
index 000000000..94b12a1aa
--- /dev/null
+++ b/tests/getpid--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "getpid.c"
diff --git a/tests/getpid.c b/tests/getpid.c
index 988f19d5b..7ec4e6e89 100644
--- a/tests/getpid.c
+++ b/tests/getpid.c
@@ -7,6 +7,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#if defined __NR_getpid && (!defined __NR_getxpid || __NR_getxpid != __NR_getpid)
@@ -16,7 +17,12 @@
int
main(void)
{
- printf("getpid() = %ld\n", syscall(__NR_getpid));
+ PIDNS_TEST_INIT;
+
+ pidns_print_leader();
+ printf("getpid() = %d%s\n", (int) syscall(__NR_getpid),
+ pidns_pid2str(PT_TGID));
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/getsid--pidns-translation.c b/tests/getsid--pidns-translation.c
new file mode 100644
index 000000000..7f983e87a
--- /dev/null
+++ b/tests/getsid--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "getsid.c"
diff --git a/tests/getsid.c b/tests/getsid.c
index 588ea4ab0..3bf747346 100644
--- a/tests/getsid.c
+++ b/tests/getsid.c
@@ -6,15 +6,22 @@
*/
#include "tests.h"
+#include "pidns.h"
+
#include <stdio.h>
#include <unistd.h>
int
main(void)
{
+ PIDNS_TEST_INIT;
+
pid_t pid = getpid();
- printf("getsid(%d) = %d\n", pid, getsid(pid));
+ pidns_print_leader();
+ printf("getsid(%d%s) = %d%s\n", pid, pidns_pid2str(PT_TGID),
+ getsid(pid), pidns_pid2str(PT_SID));
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/gettid--pidns-translation.c b/tests/gettid--pidns-translation.c
new file mode 100644
index 000000000..500c3213e
--- /dev/null
+++ b/tests/gettid--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "gettid.c"
diff --git a/tests/gettid--pidns-translation.test b/tests/gettid--pidns-translation.test
new file mode 100755
index 000000000..9624129ee
--- /dev/null
+++ b/tests/gettid--pidns-translation.test
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# Check pidns translation of gettid's return value.
+#
+# Copyright (c) 2020 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+run_strace -a9 --pidns-translation -f -e trace=gettid $args > "$EXP"
+parent_pid="$(tail -n 2 $LOG | head -n 1 | cut -d' ' -f1)"
+init_pid="$(tail -n 1 $LOG | cut -d' ' -f1)"
+# uniq: filter out extra gettid calls made by musl libc
+grep -E -v "^($parent_pid|$init_pid) |unfinished|resumed" "$LOG" | uniq > "$OUT"
+match_diff "$OUT" "$EXP"
diff --git a/tests/gettid.c b/tests/gettid.c
index d38918dd1..314d9c2c2 100644
--- a/tests/gettid.c
+++ b/tests/gettid.c
@@ -9,11 +9,17 @@
#include <stdio.h>
#include <unistd.h>
#include "scno.h"
+#include "pidns.h"
int
main(void)
{
- printf("gettid() = %ld\n", syscall(__NR_gettid));
+ PIDNS_TEST_INIT;
+
+ pidns_print_leader();
+ printf("gettid() = %d%s\n", (int) syscall(__NR_gettid),
+ pidns_pid2str(PT_TID));
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/ioctl_block--pidns-translation.c b/tests/ioctl_block--pidns-translation.c
new file mode 100644
index 000000000..5eed60762
--- /dev/null
+++ b/tests/ioctl_block--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "ioctl_block.c"
diff --git a/tests/ioctl_block--pidns-translation.test b/tests/ioctl_block--pidns-translation.test
new file mode 100755
index 000000000..d06855f92
--- /dev/null
+++ b/tests/ioctl_block--pidns-translation.test
@@ -0,0 +1,22 @@
+#!/bin/sh
+#
+# Check pidns translation of ioctl(BLK*) syscall decoding.
+#
+# Copyright (c) 2020 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+. "${srcdir=.}/init.sh"
+
+check_prog head
+check_prog tail
+check_prog cut
+check_prog grep
+
+run_prog > /dev/null
+run_strace --pidns-translation -f -a16 -e trace=ioctl $@ $args > "$EXP"
+parent_pid="$(tail -n 2 $LOG | head -n 1 | cut -d' ' -f1)"
+init_pid="$(tail -n 1 $LOG | cut -d' ' -f1)"
+grep -E -v "^($parent_pid|$init_pid) |ioctl\([0123][,<]" "$LOG" > "$OUT"
+match_diff "$OUT" "$EXP"
diff --git a/tests/ioctl_block.c b/tests/ioctl_block.c
index 0afe27f7d..8a345f4e1 100644
--- a/tests/ioctl_block.c
+++ b/tests/ioctl_block.c
@@ -9,7 +9,9 @@
*/
#include "tests.h"
+#include "pidns.h"
#include <errno.h>
+#include <unistd.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
@@ -41,12 +43,15 @@ static struct xlat_data block_argless[] = {
#define TEST_NULL_ARG(cmd) \
do { \
ioctl(-1, cmd, 0); \
+ pidns_print_leader(); \
printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd); \
} while (0)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
TEST_NULL_ARG(BLKBSZGET);
TEST_NULL_ARG(BLKBSZSET);
TEST_NULL_ARG(BLKFRAGET);
@@ -91,18 +96,22 @@ main(void)
#endif
ioctl(-1, BLKRASET, lmagic);
+ pidns_print_leader();
printf("ioctl(-1, BLKRASET, %lu) = -1 EBADF (%m)\n", lmagic);
ioctl(-1, BLKFRASET, lmagic);
+ pidns_print_leader();
printf("ioctl(-1, BLKFRASET, %lu) = -1 EBADF (%m)\n", lmagic);
TAIL_ALLOC_OBJECT_CONST_PTR(int, val_int);
*val_int = magic;
ioctl(-1, BLKROSET, val_int);
+ pidns_print_leader();
printf("ioctl(-1, BLKROSET, [%d]) = -1 EBADF (%m)\n", *val_int);
ioctl(-1, BLKBSZSET, val_int);
+ pidns_print_leader();
printf("ioctl(-1, BLKBSZSET, [%d]) = -1 EBADF (%m)\n", *val_int);
uint64_t *pair_int64 = tail_alloc(sizeof(*pair_int64) * 2);
@@ -111,18 +120,21 @@ main(void)
#ifdef BLKDISCARD
ioctl(-1, BLKDISCARD, pair_int64);
+ pidns_print_leader();
printf("ioctl(-1, BLKDISCARD, [%" PRIu64 ", %" PRIu64 "])"
" = -1 EBADF (%m)\n", pair_int64[0], pair_int64[1]);
#endif
#ifdef BLKSECDISCARD
ioctl(-1, BLKSECDISCARD, pair_int64);
+ pidns_print_leader();
printf("ioctl(-1, BLKSECDISCARD, [%" PRIu64 ", %" PRIu64 "])"
" = -1 EBADF (%m)\n", pair_int64[0], pair_int64[1]);
#endif
#ifdef BLKZEROOUT
ioctl(-1, BLKZEROOUT, pair_int64);
+ pidns_print_leader();
printf("ioctl(-1, BLKZEROOUT, [%" PRIu64 ", %" PRIu64 "])"
" = -1 EBADF (%m)\n", pair_int64[0], pair_int64[1]);
#endif
@@ -134,6 +146,7 @@ main(void)
blkpg->data = (void *) (unsigned long) 0xcafef00dfffffeedULL;
ioctl(-1, BLKPG, blkpg);
+ pidns_print_leader();
printf("ioctl(-1, BLKPG, {op=%s, flags=%d, datalen=%d"
", data=%#lx}) = -1 EBADF (%m)\n",
"BLKPG_RESIZE_PARTITION", blkpg->flags, blkpg->datalen,
@@ -149,6 +162,7 @@ main(void)
blkpg->data = bp;
ioctl(-1, BLKPG, blkpg);
+ pidns_print_leader();
printf("ioctl(-1, BLKPG, {op=%s, flags=%d, datalen=%d"
", data={start=%lld, length=%lld, pno=%d"
", devname=\"%.*s\"..., volname=\"%.*s\"...}})"
@@ -162,25 +176,31 @@ main(void)
#if defined BLKTRACESETUP && defined HAVE_STRUCT_BLK_USER_TRACE_SETUP
TAIL_ALLOC_OBJECT_CONST_PTR(struct blk_user_trace_setup, buts);
fill_memory(buts, sizeof(*buts));
+ buts->pid = getpid();
ioctl(-1, BLKTRACESETUP, buts);
+ pidns_print_leader();
printf("ioctl(-1, BLKTRACESETUP, {act_mask=%hu, buf_size=%u, buf_nr=%u"
- ", start_lba=%" PRI__u64 ", end_lba=%" PRI__u64 ", pid=%d})"
+ ", start_lba=%" PRI__u64 ", end_lba=%" PRI__u64 ", pid=%d%s})"
" = -1 EBADF (%m)\n",
buts->act_mask, buts->buf_size, buts->buf_nr,
- buts->start_lba, buts->end_lba, buts->pid);
+ buts->start_lba, buts->end_lba, buts->pid,
+ pidns_pid2str(PT_TGID));
#endif
unsigned int i;
for (i = 0; i < ARRAY_SIZE(block_argless); ++i) {
ioctl(-1, (unsigned long) block_argless[i].val, lmagic);
+ pidns_print_leader();
printf("ioctl(-1, %s) = -1 EBADF (%m)\n", block_argless[i].str);
}
ioctl(-1, _IOC(_IOC_READ, 0x12, 0xfe, 0xff), lmagic);
+ pidns_print_leader();
printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
"_IOC(_IOC_READ, 0x12, 0xfe, 0xff)", lmagic);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/ioprio--pidns-translation.c b/tests/ioprio--pidns-translation.c
new file mode 100644
index 000000000..bcb49a8b4
--- /dev/null
+++ b/tests/ioprio--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "ioprio.c"
diff --git a/tests/ioprio.c b/tests/ioprio.c
index 5e1e11947..110df0631 100644
--- a/tests/ioprio.c
+++ b/tests/ioprio.c
@@ -9,8 +9,8 @@
*/
#include "tests.h"
-
#include "scno.h"
+#include "pidns.h"
#if defined(__NR_ioprio_get) && defined(__NR_ioprio_set)
@@ -30,12 +30,18 @@ enum {
int
main(void)
{
+ PIDNS_TEST_INIT;
+
static const kernel_ulong_t bogus_which =
(kernel_ulong_t) 0xdeadfacefa57beefULL;
static const kernel_ulong_t bogus_who =
(kernel_ulong_t) 0xbadc0dedda7a1057ULL;
static const kernel_ulong_t bogus_ioprio =
(kernel_ulong_t) 0xdec0ded1facefeedULL;
+
+ const int pid = getpid();
+ const int pgid = getpgid(0);
+
# if !XLAT_RAW
static const char * const bogus_ioprio_str =
"IOPRIO_PRIO_VALUE(0x7d677 /* IOPRIO_CLASS_??? */, 7917)";
@@ -46,6 +52,7 @@ main(void)
rc = syscall(__NR_ioprio_get, bogus_which, bogus_who);
errstr = sprintrc(rc);
+ pidns_print_leader();
# if XLAT_RAW
printf("ioprio_get(%#x, %d) = %s\n",
(int) bogus_which, (int) bogus_who, errstr);
@@ -54,42 +61,52 @@ main(void)
(int) bogus_which, (int) bogus_who, errstr);
# endif
- rc = syscall(__NR_ioprio_get, 1, 0);
+ rc = syscall(__NR_ioprio_get, 1, pid);
errstr = sprintrc(rc);
+ pidns_print_leader();
+ printf("ioprio_get(");
# if XLAT_RAW
- printf("ioprio_get(0x1, 0) = %s\n", errstr);
+ printf("0x1, ");
+# elif XLAT_VERBOSE
+ printf("0x1 /* IOPRIO_WHO_PROCESS */, ");
# else /* XLAT_ABBREV */
-# if XLAT_VERBOSE
- printf("ioprio_get(0x1 /* IOPRIO_WHO_PROCESS */, 0) = %s", errstr);
-# else
- printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", errstr);
-# endif
+ printf("IOPRIO_WHO_PROCESS, ");
+# endif
+ printf("%d%s) = %s", pid, pidns_pid2str(PT_TGID), errstr);
+# if !XLAT_RAW
if (rc >= 0) {
printf(" (IOPRIO_PRIO_VALUE(");
printxval(ioprio_class, (unsigned int) rc >> 13,
"IOPRIO_CLASS_???");
printf(", %u))", (unsigned int) rc & 0x1fff);
}
- puts("");
# endif
+ puts("");
- rc = syscall(__NR_ioprio_set, 2, 0, 8191);
+ rc = syscall(__NR_ioprio_set, 2, pgid, 8191);
errstr = sprintrc(rc);
+ pidns_print_leader();
+ printf("ioprio_set(");
# if XLAT_RAW
- printf("ioprio_set(%#x, 0, 8191) = %s\n", 2, errstr);
+ printf("%#x", 2);
# elif XLAT_VERBOSE
- printf("ioprio_set(%#x /* IOPRIO_WHO_PGRP */, 0, 8191"
- " /* IOPRIO_PRIO_VALUE(0 /* IOPRIO_CLASS_NONE */, 8191) */)"
- " = %s\n",
- 2, errstr);
+ printf("%#x /* IOPRIO_WHO_PGRP */", 2);
# else /* XLAT_ABBREV */
- printf("ioprio_set(IOPRIO_WHO_PGRP, 0"
- ", IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191)) = %s\n",
- errstr);
+ printf("IOPRIO_WHO_PGRP");
+# endif
+ printf(", %d%s", pgid, pidns_pid2str(PT_PGID));
+# if XLAT_RAW
+ printf(", 8191)");
+# elif XLAT_VERBOSE
+ printf(", 8191 /* IOPRIO_PRIO_VALUE(0 /* IOPRIO_CLASS_NONE */, 8191) */)");
+# else /* XLAT_ABBREV */
+ printf(", IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191))");
# endif
+ printf(" = %s\n", errstr);
rc = syscall(__NR_ioprio_set, bogus_which, bogus_who, bogus_ioprio);
errstr = sprintrc(rc);
+ pidns_print_leader();
# if XLAT_RAW
printf("ioprio_set(%#x, %d, %d) = %s\n",
(int) bogus_which, (int) bogus_who, (int) bogus_ioprio,
@@ -104,6 +121,7 @@ main(void)
errstr);
# endif
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
diff --git a/tests/kcmp-y--pidns-translation.c b/tests/kcmp-y--pidns-translation.c
new file mode 100644
index 000000000..f54d94cce
--- /dev/null
+++ b/tests/kcmp-y--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "kcmp-y.c"
diff --git a/tests/kcmp.c b/tests/kcmp.c
index dc5ba9a46..ce705ad0d 100644
--- a/tests/kcmp.c
+++ b/tests/kcmp.c
@@ -9,8 +9,8 @@
*/
#include "tests.h"
-
#include "scno.h"
+#include "pidns.h"
#ifdef __NR_kcmp
@@ -101,7 +101,11 @@ do_kcmp(kernel_ulong_t pid1, kernel_ulong_t pid2, kernel_ulong_t type,
rc = syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
errstr = sprintrc(rc);
- printf("kcmp(%d, %d, ", (int) pid1, (int) pid2);
+ const char *pid_str = pidns_pid2str(PT_TGID);
+ pidns_print_leader();
+ printf("kcmp(%d%s, %d%s, ",
+ (int) pid1, (int) pid1 == getpid() ? pid_str : "",
+ (int) pid2, (int) pid2 == getpid() ? pid_str : "");
if (type_str)
printf("%s", type_str);
@@ -146,6 +150,8 @@ do_kcmp(kernel_ulong_t pid1, kernel_ulong_t pid2, kernel_ulong_t type,
int
main(void)
{
+ PIDNS_TEST_INIT;
+
static const kernel_ulong_t bogus_pid1 =
(kernel_ulong_t) 0xdeadca75face1057ULL;
static const kernel_ulong_t bogus_pid2 =
@@ -221,6 +227,7 @@ main(void)
(uintptr_t) slot, 1);
}
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
diff --git a/tests/kill--pidns-translation.c b/tests/kill--pidns-translation.c
new file mode 100644
index 000000000..4736ca142
--- /dev/null
+++ b/tests/kill--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "kill.c"
diff --git a/tests/kill.c b/tests/kill.c
index f7d9341e7..17de35dab 100644
--- a/tests/kill.c
+++ b/tests/kill.c
@@ -11,6 +11,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#ifdef __NR_kill
@@ -26,6 +27,8 @@ handler(int sig)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
const struct sigaction act = { .sa_handler = handler };
if (sigaction(SIGALRM, &act, NULL))
perror_msg_and_fail("sigaction");
@@ -37,18 +40,23 @@ main(void)
perror_msg_and_fail("sigprocmask");
const int pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
long rc = syscall(__NR_kill, pid, (long) 0xdefaced00000000ULL | SIGALRM);
- printf("kill(%d, SIGALRM) = %ld\n", pid, rc);
+ pidns_print_leader();
+ printf("kill(%d%s, SIGALRM) = %ld\n", pid, pid_str, rc);
const long big_pid = (long) 0xfacefeedbadc0dedULL;
const long big_sig = (long) 0xdeadbeefcafef00dULL;
rc = syscall(__NR_kill, big_pid, big_sig);
+ pidns_print_leader();
printf("kill(%d, %d) = %ld %s (%m)\n",
(int) big_pid, (int) big_sig, rc, errno2name());
rc = syscall(__NR_kill, (long) 0xdefaced00000000ULL | pid, 0);
- printf("kill(%d, 0) = %ld\n", pid, rc);
+ pidns_print_leader();
+ printf("kill(%d%s, 0) = %ld\n", pid, pid_str, rc);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/migrate_pages--pidns-translation.c b/tests/migrate_pages--pidns-translation.c
new file mode 100644
index 000000000..ec34938d2
--- /dev/null
+++ b/tests/migrate_pages--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "migrate_pages.c"
diff --git a/tests/migrate_pages.c b/tests/migrate_pages.c
index 2dfba49cd..390b490bb 100644
--- a/tests/migrate_pages.c
+++ b/tests/migrate_pages.c
@@ -10,6 +10,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#ifdef __NR_migrate_pages
@@ -19,11 +20,21 @@
int
main(void)
{
- const long pid = (long) 0xfacefeedffffffffULL;
+ PIDNS_TEST_INIT;
+
+ const long pid = (long) 0xfacefeed00000000ULL | getpid();
long rc = syscall(__NR_migrate_pages, pid, 0, 0, 0);
- printf("migrate_pages(%d, 0, NULL, NULL) = %ld %s (%m)\n",
- (int) pid, rc, errno2name());
+ pidns_print_leader();
+ printf("migrate_pages(%d%s, 0, NULL, NULL) = %ld",
+ (int) pid, pidns_pid2str(PT_TGID), rc);
+
+ if (rc < 0)
+ printf(" %s (%m)\n", errno2name());
+ else
+ printf("\n");
+
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/move_pages--pidns-translation.c b/tests/move_pages--pidns-translation.c
new file mode 100644
index 000000000..8498e399d
--- /dev/null
+++ b/tests/move_pages--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "move_pages.c"
diff --git a/tests/move_pages.c b/tests/move_pages.c
index e00fd1ac0..56843158e 100644
--- a/tests/move_pages.c
+++ b/tests/move_pages.c
@@ -10,6 +10,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#ifdef __NR_move_pages
@@ -122,15 +123,20 @@ print_status_array(const int *const status, const unsigned long count)
}
static void
-print_stat_pages(const unsigned long pid, const unsigned long count,
- const void **const pages, int *const status)
+print_stat_pages(const unsigned long pid,
+ const char *pid_str,
+ const unsigned long count,
+ const void **const pages,
+ int *const status)
{
const unsigned long flags = (unsigned long) 0xfacefeed00000002ULL;
long rc = syscall(__NR_move_pages,
pid, count, pages, NULL, status, flags);
const char *errstr = sprintrc(rc);
- printf("move_pages(%d, %lu, ", (int) pid, count);
+ pidns_print_leader();
+ printf("move_pages(%d%s, %lu, ", (int) pid, pid_str,
+ count);
print_page_array(pages, count, 0);
printf(", NULL, ");
if (rc) {
@@ -152,6 +158,7 @@ print_stat_pages(const unsigned long pid, const unsigned long count,
static void
print_move_pages(const unsigned long pid,
+ const char *pid_str,
unsigned long count,
const unsigned int offset,
const void **const pages,
@@ -164,7 +171,9 @@ print_move_pages(const unsigned long pid,
long rc = syscall(__NR_move_pages,
pid, count, pages, nodes, status, flags);
const char *errstr = sprintrc(rc);
- printf("move_pages(%d, %lu, ", (int) pid, count);
+ pidns_print_leader();
+ printf("move_pages(%d%s, %lu, ", (int) pid, pid_str,
+ count);
print_page_array(pages, count, offset);
printf(", ");
print_node_array(nodes, count, offset);
@@ -185,8 +194,11 @@ print_move_pages(const unsigned long pid,
int
main(void)
{
+ PIDNS_TEST_INIT;
+
const unsigned long pid =
(unsigned long) 0xfacefeed00000000ULL | getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
unsigned long count = 1;
const unsigned page_size = get_page_size();
const void *const page = tail_alloc(page_size);
@@ -195,40 +207,41 @@ main(void)
TAIL_ALLOC_OBJECT_VAR_PTR(int, nodes);
TAIL_ALLOC_OBJECT_VAR_PTR(int, status);
- print_stat_pages(pid, 0, pages, status);
- print_move_pages(pid, 0, 0, pages, nodes, status);
- print_move_pages(pid, 0, 1, pages + 1, nodes + 1, status + 1);
+ print_stat_pages(pid, pid_str, 0, pages, status);
+ print_move_pages(pid, pid_str, 0, 0, pages, nodes, status);
+ print_move_pages(pid, pid_str, 0, 1, pages + 1, nodes + 1, status + 1);
*pages = page;
- print_stat_pages(pid, count, pages, status);
+ print_stat_pages(pid, pid_str, count, pages, status);
*nodes = 0xdeadbee1;
- print_move_pages(pid, count, 0, pages, nodes, status);
- print_move_pages(pid, count, 1, pages, nodes, status);
+ print_move_pages(pid, pid_str, count, 0, pages, nodes, status);
+ print_move_pages(pid, pid_str, count, 1, pages, nodes, status);
++count;
--status;
*(--pages) = efault;
- print_stat_pages(pid, count, pages, status);
+ print_stat_pages(pid, pid_str, count, pages, status);
*(--nodes) = 0xdeadbee2;
- print_move_pages(pid, count, 0, pages, nodes, status);
- print_move_pages(pid, count, 1, pages, nodes, status);
+ print_move_pages(pid, pid_str, count, 0, pages, nodes, status);
+ print_move_pages(pid, pid_str, count, 1, pages, nodes, status);
++count;
--status;
*(--pages) = nodes;
- print_stat_pages(pid, count, pages, status);
+ print_stat_pages(pid, pid_str, count, pages, status);
*(--nodes) = 0xdeadbee3;
- print_move_pages(pid, count, 0, pages, nodes, status);
- print_move_pages(pid, count, 1, pages, nodes, status);
+ print_move_pages(pid, pid_str, count, 0, pages, nodes, status);
+ print_move_pages(pid, pid_str, count, 1, pages, nodes, status);
++count;
--status;
*(--pages) = status;
- print_stat_pages(pid, count, pages, status);
+ print_stat_pages(pid, pid_str, count, pages, status);
*(--nodes) = 0xdeadbee4;
- print_move_pages(pid, count, 0, pages, nodes, status);
- print_move_pages(pid, count, 1, pages, nodes, status);
+ print_move_pages(pid, pid_str, count, 0, pages, nodes, status);
+ print_move_pages(pid, pid_str, count, 1, pages, nodes, status);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/net-sockaddr--pidns-translation.c b/tests/net-sockaddr--pidns-translation.c
new file mode 100644
index 000000000..ff432bf43
--- /dev/null
+++ b/tests/net-sockaddr--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "net-sockaddr.c"
diff --git a/tests/net-sockaddr.c b/tests/net-sockaddr.c
index 4fc9da6e2..c7e9bde7d 100644
--- a/tests/net-sockaddr.c
+++ b/tests/net-sockaddr.c
@@ -9,6 +9,7 @@
*/
#include "tests.h"
+#include "pidns.h"
#include <stddef.h>
#include <stdio.h>
#include <string.h>
@@ -40,18 +41,21 @@ check_un(void)
memset(un->sun_path, '0', sizeof(un->sun_path));
unsigned int len = sizeof(*un);
int ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNIX, sun_path=\"%.*u\"}"
", %u) = %d EBADF (%m)\n",
(int) sizeof(un->sun_path), 0, len, ret);
un->sun_path[1] = 0;
ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNIX, sun_path=\"%u\"}, %u)"
" = %d EBADF (%m)\n", 0, len, ret);
un->sun_path[0] = 0;
un->sun_path[2] = 1;
ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNIX, sun_path=@\"\\0\\001%.*u\"}"
", %u) = %d EBADF (%m)\n",
(int) sizeof(un->sun_path) - 3, 0, len, ret);
@@ -61,12 +65,14 @@ check_un(void)
memset(un->sun_path, '0', sizeof(un->sun_path));
len = sizeof(*un) + 2;
ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNIX, sun_path=\"%.*u\"}"
", %u) = %d EBADF (%m)\n",
(int) sizeof(un->sun_path), 0, len, ret);
un->sun_path[0] = 0;
ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNIX, sun_path=@\"%.*u\"}"
", %u) = %d EBADF (%m)\n",
(int) sizeof(un->sun_path) - 1, 0, len, ret);
@@ -75,18 +81,21 @@ check_un(void)
un->sun_family = AF_UNIX;
len = sizeof(*un) - 2;
ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNIX, sun_path=\"%.*u\"}"
", %u) = %d EBADF (%m)\n",
(int) sizeof(un->sun_path) - 2, 0, len, ret);
un->sun_path[0] = 0;
ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNIX, sun_path=@\"%.*u\"}"
", %u) = %d EBADF (%m)\n",
(int) sizeof(un->sun_path) - 3, 0, len, ret);
len = sizeof(*un);
ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, %p, %u) = %d EBADF (%m)\n", un, len, ret);
un = tail_alloc(sizeof(struct sockaddr_storage));
@@ -94,12 +103,14 @@ check_un(void)
memset(un->sun_path, '0', sizeof(un->sun_path));
len = sizeof(struct sockaddr_storage) + 1;
ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNIX, sun_path=\"%.*u\"}"
", %u) = %d EBADF (%m)\n",
(int) sizeof(un->sun_path), 0, len, ret);
un->sun_path[0] = 0;
ret = connect(-1, (void *) un, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNIX, sun_path=@\"%.*u\"}"
", %u) = %d EBADF (%m)\n",
(int) sizeof(un->sun_path) - 1, 0, len, ret);
@@ -117,6 +128,7 @@ check_in(void)
in->sin_addr.s_addr = inet_addr(h_addr);
unsigned int len = sizeof(*in);
int ret = connect(-1, (void *) in, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_INET, sin_port=htons(%hu)"
", sin_addr=inet_addr(\"%s\")}, %u) = %d EBADF (%m)\n",
h_port, h_addr, len, ret);
@@ -127,6 +139,7 @@ check_in(void)
in->sin_addr.s_addr = inet_addr(h_addr);
len = sizeof(*in) + 4;
ret = connect(-1, (void *) in, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_INET, sin_port=htons(%hu)"
", sin_addr=inet_addr(\"%s\")}, %u) = %d EBADF (%m)\n",
h_port, h_addr, len, ret);
@@ -137,6 +150,7 @@ check_in(void)
in->sin_addr.s_addr = 0;
len = sizeof(*in) - 4;
ret = connect(-1, (void *) in, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_INET, sa_data=\"%s\"}, %u)"
" = %d EBADF (%m)\n",
"\\0\\0\\0\\0\\0\\0\\377\\377\\377\\377",
@@ -144,6 +158,7 @@ check_in(void)
len = sizeof(*in);
ret = connect(-1, (void *) in, len);
+ pidns_print_leader();
printf("connect(-1, %p, %u) = %d EBADF (%m)\n", in, len, ret);
}
@@ -155,6 +170,7 @@ check_in6_linklocal(struct sockaddr_in6 *const in6, const char *const h_addr)
in6->sin6_scope_id = 0xfacefeed;
unsigned int len = sizeof(*in6);
int ret = connect(-1, (void *) in6, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
", sin6_flowinfo=htonl(%u)"
", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
@@ -166,7 +182,8 @@ check_in6_linklocal(struct sockaddr_in6 *const in6, const char *const h_addr)
in6->sin6_scope_id = ifindex_lo();
if (in6->sin6_scope_id) {
ret = connect(-1, (void *) in6, len);
- printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
+ pidns_print_leader();
+ printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
", sin6_flowinfo=htonl(%u)"
", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
", sin6_scope_id=%s}, %u)"
@@ -191,6 +208,7 @@ check_in6(void)
in6->sin6_scope_id = 0xfacefeed;
unsigned int len = sizeof(*in6);
int ret = connect(-1, (void *) in6, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
", sin6_flowinfo=htonl(%u)"
", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
@@ -209,6 +227,7 @@ check_in6(void)
in6->sin6_scope_id = 0xfacefeed;
len = sizeof(*in6) + 4;
ret = connect(-1, (void *) in6, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
", sin6_flowinfo=htonl(%u)"
", inet_pton(AF_INET6, \"%s\", &sin6_addr)"
@@ -223,6 +242,7 @@ check_in6(void)
inet_pton(AF_INET6, h_addr, &in6->sin6_addr);
len = sizeof(*in6) - sizeof(in6->sin6_scope_id);
ret = connect(-1, (void *) in6, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_INET6, sin6_port=htons(%hu)"
", sin6_flowinfo=htonl(%u)"
", inet_pton(AF_INET6, \"%s\", &sin6_addr)}, %u)"
@@ -236,6 +256,7 @@ check_in6(void)
memset(&in6->sin6_addr, '0', sizeof(in6->sin6_addr) - 4);
len = sizeof(*in6) - sizeof(in6->sin6_scope_id) - 4;
ret = connect(-1, (void *) in6, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_INET6"
", sa_data=\"\\0\\0\\0\\0\\0\\000%.*u\"}, %u)"
" = %d EBADF (%m)\n",
@@ -244,6 +265,7 @@ check_in6(void)
len = sizeof(*in6) - sizeof(in6->sin6_scope_id);
ret = connect(-1, (void *) in6, len);
+ pidns_print_leader();
printf("connect(-1, %p, %u) = %d EBADF (%m)\n", in6, len, ret);
}
@@ -262,6 +284,7 @@ check_ipx(void)
void *ipx = tail_memdup(&c_ipx, sizeof(c_ipx));
unsigned int len = sizeof(c_ipx);
int ret = connect(-1, ipx, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_IPX, sipx_port=htons(%u)"
", sipx_network=htonl(%#x)"
", sipx_node=[%#02x, %#02x, %#02x, %#02x, %#02x, %#02x]"
@@ -316,18 +339,21 @@ check_ax25(void)
fill_memory(sax, size);
sax->fsa_ax25.sax25_family = AF_AX25;
rc = connect(-1, sax_void, sizeof(struct sockaddr_ax25) - 1);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_AX25, sa_data=\"\\202\\203\\204\\205"
"\\206\\207\\210\\211\\212\\213\\214\\215\\216\"}, %zu) = %s\n",
sizeof(struct sockaddr_ax25) - 1, sprintrc(rc));
memcpy(sax, &ax25, sizeof(ax25));
rc = connect(-1, sax_void, sizeof(struct sockaddr_ax25));
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_AX25, fsa_ax25={sax25_call=VALID-13"
", sax25_ndigis=8}, fsa_digipeater=[/* ??? */]}, %zu) = %s\n",
sizeof(struct sockaddr_ax25), sprintrc(rc));
sax->fsa_ax25.sax25_ndigis = 0;
rc = connect(-1, sax_void, sizeof(struct sockaddr_ax25));
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_AX25, sax25_call=VALID-13"
", sax25_ndigis=0}, %zu) = %s\n",
sizeof(struct sockaddr_ax25), sprintrc(rc));
@@ -335,6 +361,7 @@ check_ax25(void)
sax->fsa_ax25.sax25_ndigis = 8;
size = sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 3 + 1;
rc = connect(-1, sax_void, size);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_AX25, fsa_ax25={sax25_call=VALID-13"
", sax25_ndigis=8}, fsa_digipeater"
"=[{ax25_call=\"\\xa6\\xa0\\x82\\x40\\x86\\x8a\\x00\""
@@ -348,6 +375,7 @@ check_ax25(void)
sax->fsa_digipeater[2].ax25_call[6] = 0x4;
size = sizeof(struct sockaddr_ax25) + sizeof(ax25_address) * 4;
rc = connect(-1, sax_void, size);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_AX25, fsa_ax25={sax25_call=VALID-13"
", sax25_ndigis=8}, fsa_digipeater"
"=[{ax25_call=\"\\xa6\\xa0\\x82\\x40\\x86\\x8a\\x00\""
@@ -365,6 +393,7 @@ check_ax25(void)
for (size_t i = 0; i < 3; i++) {
size = sizeof(ax25) + sizeof(ax25_address) * (i / 2);
rc = connect(-1, sax_void, size);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_AX25"
", fsa_ax25={sax25_call=VALID-13, sax25_ndigis=%d}"
", fsa_digipeater=[VALID2-7, OK-15, %s /* FINE-2 */"
@@ -427,12 +456,14 @@ check_x25(void)
long rc;
rc = connect(-1, x25_void, sizeof(c_x25) - 1);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_X25"
", sa_data=\"0123456789abcde\"}, %zu) = %s\n",
sizeof(c_x25) - 1, sprintrc(rc));
for (size_t i = 0; i < 2; i++) {
rc = connect(-1, x25_void, sizeof(c_x25) + i);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_X25"
", sx25_addr={x25_addr=\"0123456789abcde\"...}"
"}, %zu) = %s\n",
@@ -442,6 +473,7 @@ check_x25(void)
struct sockaddr_x25 *const x25 = x25_void;
x25->sx25_addr.x25_addr[10] = '\0';
rc = connect(-1, x25_void, sizeof(c_x25));
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_X25"
", sx25_addr={x25_addr=\"0123456789\"}"
"}, %zu) = %s\n",
@@ -457,19 +489,21 @@ check_nl(void)
nl->nl_groups = 0xfacefeed;
unsigned int len = sizeof(*nl);
int ret = connect(-1, (void *) nl, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_NETLINK, nl_pid=%d"
", nl_groups=%#08x}, %u) = %d EBADF (%m)\n",
nl->nl_pid, nl->nl_groups, len, ret);
nl = ((void *) nl) - 4;
nl->nl_family = AF_NETLINK;
- nl->nl_pid = 1234567890;
+ nl->nl_pid = getpid();
nl->nl_groups = 0xfacefeed;
len = sizeof(*nl) + 4;
ret = connect(-1, (void *) nl, len);
- printf("connect(-1, {sa_family=AF_NETLINK, nl_pid=%d"
+ pidns_print_leader();
+ printf("connect(-1, {sa_family=AF_NETLINK, nl_pid=%d%s"
", nl_groups=%#08x}, %u) = %d EBADF (%m)\n",
- nl->nl_pid, nl->nl_groups, len, ret);
+ nl->nl_pid, pidns_pid2str(PT_TGID), nl->nl_groups, len, ret);
}
static void
@@ -487,6 +521,7 @@ check_ll(void)
void *ll = tail_memdup(&c_ll, sizeof(c_ll));
unsigned int len = sizeof(c_ll);
int ret = connect(-1, ll, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_PACKET"
", sll_protocol=htons(ETH_P_ALL)"
", sll_ifindex=%u, sll_hatype=ARPHRD_ETHER"
@@ -502,6 +537,7 @@ check_ll(void)
((struct sockaddr_ll *) ll)->sll_halen++;
ret = connect(-1, ll, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_PACKET"
", sll_protocol=htons(ETH_P_ALL)"
", sll_ifindex=%u, sll_hatype=ARPHRD_ETHER"
@@ -517,6 +553,7 @@ check_ll(void)
((struct sockaddr_ll *) ll)->sll_halen = 0;
ret = connect(-1, ll, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_PACKET"
", sll_protocol=htons(ETH_P_ALL)"
", sll_ifindex=%u, sll_hatype=ARPHRD_ETHER"
@@ -526,6 +563,7 @@ check_ll(void)
((struct sockaddr_ll *) ll)->sll_ifindex = ifindex_lo();
if (((struct sockaddr_ll *) ll)->sll_ifindex) {
ret = connect(-1, ll, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_PACKET"
", sll_protocol=htons(ETH_P_ALL)"
", sll_ifindex=%s"
@@ -549,11 +587,13 @@ check_hci(void)
unsigned int len = sizeof(*hci);
int ret = connect(-1, (void *) hci, 4);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_BLUETOOTH, hci_dev=htobs(%hu)"
"}, 4) = %d EBADF (%m)\n",
h_port, ret);
ret = connect(-1, (void *) hci, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_BLUETOOTH, hci_dev=htobs(%hu)"
# ifdef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
", hci_channel=HCI_CHANNEL_RAW"
@@ -572,6 +612,7 @@ check_sco(void)
void *sco = tail_memdup(&c_sco, sizeof(c_sco));
unsigned int len = sizeof(c_sco);
int ret = connect(-1, sco, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_BLUETOOTH"
", sco_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
"}, %u) = %d EBADF (%m)\n",
@@ -592,6 +633,7 @@ check_rc(void)
void *rc = tail_memdup(&c_rc, sizeof(c_rc));
unsigned int len = sizeof(c_rc);
int ret = connect(-1, rc, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_BLUETOOTH"
", rc_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
", rc_channel=%u}, %u) = %d EBADF (%m)\n",
@@ -619,6 +661,7 @@ check_l2(void)
unsigned int len = sizeof(c_l2);
int ret = connect(-1, l2, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_BLUETOOTH"
", l2_psm=htobs(L2CAP_PSM_DYN_START + %hu)"
", l2_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
@@ -640,6 +683,7 @@ check_l2(void)
# endif
memcpy(l2, &c_l2, sizeof(c_l2));
ret = connect(-1, l2, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_BLUETOOTH"
", l2_psm=htobs(L2CAP_PSM_SDP)"
", l2_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
@@ -660,6 +704,7 @@ check_l2(void)
# endif
memcpy(l2, &c_l2, sizeof(c_l2));
ret = connect(-1, l2, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_BLUETOOTH"
", l2_psm=htobs(0xbad /* L2CAP_PSM_??? */)"
", l2_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
@@ -677,6 +722,7 @@ check_l2(void)
c_l2.l2_cid = htobs(0xffff);
memcpy(l2, &c_l2, 12);
ret = connect(-1, l2, 12);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_BLUETOOTH"
", l2_psm=htobs(L2CAP_PSM_AUTO_END)"
", l2_bdaddr=%02x:%02x:%02x:%02x:%02x:%02x"
@@ -700,6 +746,7 @@ check_raw(void)
u.sa->sa_family = 0xff;
unsigned int len = sizeof(*u.st) + 8;
int ret = connect(-1, (void *) u.st, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=%#x /* AF_??? */, sa_data=\"%.*u\"}"
", %u) = %d EBADF (%m)\n", u.sa->sa_family,
(int) (sizeof(*u.st) - sizeof(u.sa->sa_family)), 0, len, ret);
@@ -707,11 +754,13 @@ check_raw(void)
u.sa->sa_family = 0;
len = sizeof(u.sa->sa_family) + 1;
ret = connect(-1, (void *) u.st, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_UNSPEC, sa_data=\"0\"}, %u)"
" = %d EBADF (%m)\n", len, ret);
u.sa->sa_family = AF_BLUETOOTH;
ret = connect(-1, (void *) u.st, len);
+ pidns_print_leader();
printf("connect(-1, {sa_family=AF_BLUETOOTH, sa_data=\"0\"}, %u)"
" = %d EBADF (%m)\n", len, ret);
}
@@ -719,6 +768,8 @@ check_raw(void)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
check_un();
check_in();
check_in6();
@@ -735,6 +786,7 @@ main(void)
#endif
check_raw();
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/netlink_audit--pidns-translation.c b/tests/netlink_audit--pidns-translation.c
new file mode 100644
index 000000000..e08f91680
--- /dev/null
+++ b/tests/netlink_audit--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "netlink_audit.c"
diff --git a/tests/netlink_audit--pidns-translation.test b/tests/netlink_audit--pidns-translation.test
new file mode 100755
index 000000000..1a39eadd9
--- /dev/null
+++ b/tests/netlink_audit--pidns-translation.test
@@ -0,0 +1,13 @@
+#!/bin/sh
+#
+# Check pidns translation of NETLINK_SOCK_DIAG protocol decoding
+#
+# Copyright (c) 2020 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+. "${srcdir=.}/init.sh"
+
+run_prog ../netlink_netlink_diag
+test_pidns -e trace=sendto "$@"
diff --git a/tests/netlink_audit.c b/tests/netlink_audit.c
index eba609a14..5dfcd7865 100644
--- a/tests/netlink_audit.c
+++ b/tests/netlink_audit.c
@@ -7,6 +7,7 @@
*/
#include "tests.h"
+#include "pidns.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -17,18 +18,23 @@
static void
test_nlmsg_type(const int fd)
{
+ PIDNS_TEST_INIT;
+
long rc;
struct nlmsghdr nlh = {
.nlmsg_len = sizeof(nlh),
.nlmsg_type = AUDIT_GET,
.nlmsg_flags = NLM_F_REQUEST,
+ .nlmsg_pid = getpid(),
};
rc = sendto(fd, &nlh, sizeof(nlh), MSG_DONTWAIT, NULL, 0);
+ pidns_print_leader();
printf("sendto(%d, {len=%u, type=AUDIT_GET"
- ", flags=NLM_F_REQUEST, seq=0, pid=0}"
+ ", flags=NLM_F_REQUEST, seq=0, pid=%d%s}"
", %u, MSG_DONTWAIT, NULL, 0) = %s\n",
- fd, nlh.nlmsg_len, (unsigned) sizeof(nlh), sprintrc(rc));
+ fd, nlh.nlmsg_len, nlh.nlmsg_pid, pidns_pid2str(PT_TGID),
+ (unsigned) sizeof(nlh), sprintrc(rc));
}
int main(void)
@@ -39,6 +45,7 @@ int main(void)
test_nlmsg_type(fd);
+ pidns_print_leader();
printf("+++ exited with 0 +++\n");
return 0;
diff --git a/tests/pidfd_open--pidns-translation.c b/tests/pidfd_open--pidns-translation.c
new file mode 100644
index 000000000..c38e37a86
--- /dev/null
+++ b/tests/pidfd_open--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "pidfd_open.c"
diff --git a/tests/pidfd_open.c b/tests/pidfd_open.c
index 5860adde1..e5d74a916 100644
--- a/tests/pidfd_open.c
+++ b/tests/pidfd_open.c
@@ -10,6 +10,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#ifdef __NR_pidfd_open
@@ -37,6 +38,8 @@ k_pidfd_open(const unsigned int pid, const unsigned int flags)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
# if defined PATH_TRACING || defined PRINT_PATHS
skip_if_unavailable("/proc/self/fd/");
# endif
@@ -50,16 +53,19 @@ main(void)
k_pidfd_open(0, 0);
# ifndef PATH_TRACING
+ pidns_print_leader();
printf("pidfd_open(0, 0) = %s\n", errstr);
# endif
k_pidfd_open(-1U, 0);
# ifndef PATH_TRACING
+ pidns_print_leader();
printf("pidfd_open(-1, 0) = %s\n", errstr);
# endif
k_pidfd_open(0, -1U);
# ifndef PATH_TRACING
+ pidns_print_leader();
printf("pidfd_open(0, %#x) = %s\n", -1U, errstr);
# endif
@@ -68,7 +74,10 @@ main(void)
k_pidfd_open(pid, flags);
# ifndef PATH_TRACING
- printf("pidfd_open(%d, %#x) = %s\n", pid, flags, errstr);
+ const char *pid_str = pidns_pid2str(PT_TGID);
+ pidns_print_leader();
+ printf("pidfd_open(%d%s, %#x) = %s\n",
+ pid, pid_str, flags, errstr);
# endif
# ifdef PRINT_PATHS
@@ -80,17 +89,19 @@ main(void)
# endif
# ifndef PATH_TRACING
- printf("pidfd_open(%d, 0) = "
+ pidns_print_leader();
+ printf("pidfd_open(%d%s, 0) = "
# if defined PRINT_PIDFD
- "%ld<pid:%d>\n", pid, rc, pid
+ "%ld<pid:%d>\n", pid, pid_str, rc, pid
# elif defined PRINT_PATHS
- "%ld<anon_inode:[pidfd]>\n", pid, rc
+ "%ld<anon_inode:[pidfd]>\n", pid, pid_str, rc
# else
- "%s\n", pid, errstr
+ "%s\n", pid, pid_str, errstr
# endif
);
# endif
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/pidfd_send_signal--pidns-translation.c b/tests/pidfd_send_signal--pidns-translation.c
new file mode 100644
index 000000000..b04f10f51
--- /dev/null
+++ b/tests/pidfd_send_signal--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "pidfd_send_signal.c"
diff --git a/tests/pidfd_send_signal.c b/tests/pidfd_send_signal.c
index 38b5bda1a..a6b2d28cc 100644
--- a/tests/pidfd_send_signal.c
+++ b/tests/pidfd_send_signal.c
@@ -10,6 +10,7 @@
#include "tests.h"
#include <unistd.h>
#include "scno.h"
+#include "pidns.h"
#ifdef __NR_pidfd_send_signal
@@ -36,6 +37,8 @@ sys_pidfd_send_signal(int pidfd, int sig, const void *info, int flags)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
static const char null_path[] = "/dev/null";
int fd = open(null_path, O_RDONLY);
@@ -46,19 +49,23 @@ main(void)
const void *esi = (const void *) si + 1;
sys_pidfd_send_signal(fd, SIGUSR1, esi, 0);
+ pidns_print_leader();
printf("pidfd_send_signal(%d, SIGUSR1, %p, 0) = %s\n",
fd, esi, errstr);
si->si_signo = SIGUSR1;
si->si_code = SI_QUEUE;
+ si->si_pid = getpid();
sys_pidfd_send_signal(fd, SIGUSR2, si, -1);
+ pidns_print_leader();
printf("pidfd_send_signal(%d, SIGUSR2, {si_signo=SIGUSR1"
- ", si_code=SI_QUEUE, si_errno=%u, si_pid=%d, si_uid=%d"
+ ", si_code=SI_QUEUE, si_errno=%u, si_pid=%d%s, si_uid=%d"
", si_value={int=%d, ptr=%p}}, %#x) = %s\n",
- fd, si->si_errno, si->si_pid, si->si_uid, si->si_int, si->si_ptr,
- -1U, errstr);
+ fd, si->si_errno, si->si_pid, pidns_pid2str(PT_TGID), si->si_uid,
+ si->si_int, si->si_ptr, -1U, errstr);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/pidns-cache.c b/tests/pidns-cache.c
new file mode 100644
index 000000000..6319a7fda
--- /dev/null
+++ b/tests/pidns-cache.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2020 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include "scno.h"
+#include "pidns.h"
+
+#if defined __NR_getpid && (!defined __NR_getxpid || __NR_getxpid != __NR_getpid)
+
+# include <stdio.h>
+# include <unistd.h>
+# include <sys/time.h>
+
+# define SYSCALL_COUNT 1000
+
+/**
+ * Max ratio of the execution time with and without pidns translation.
+ */
+# define MAX_TIME_RATIO 20
+
+static long
+execute_syscalls(void)
+{
+ /* Load our PID in the cache */
+ syscall(__NR_getpid);
+
+ struct timeval stop, start;
+ gettimeofday(&start, NULL);
+
+ for (int i = 0; i < SYSCALL_COUNT; i++)
+ syscall(__NR_getpid);
+
+ gettimeofday(&stop, NULL);
+
+ return (stop.tv_usec - start.tv_usec) +
+ (stop.tv_sec - start.tv_sec) * 1000000;
+}
+
+int
+main(void)
+{
+ long max_us = execute_syscalls() * MAX_TIME_RATIO;
+
+ pidns_test_init();
+
+ long us = execute_syscalls();
+ if (us > max_us)
+ error_msg_and_fail("pidns translation took too long: %ld us "
+ "(max: %ld us)", us, max_us);
+
+ return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_getpid")
+
+#endif
diff --git a/tests/pidns-cache.test b/tests/pidns-cache.test
new file mode 100755
index 000000000..e4df0821d
--- /dev/null
+++ b/tests/pidns-cache.test
@@ -0,0 +1,15 @@
+#!/bin/sh
+#
+# Test pidns translation cache.
+#
+# Copyright (c) 2020 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. "${srcdir=.}/init.sh"
+
+check_prog timeout
+
+run_prog > /dev/null
+run_strace --pidns-translation -f -e trace=getpid $args
diff --git a/tests/prlimit64--pidns-translation.c b/tests/prlimit64--pidns-translation.c
new file mode 100644
index 000000000..3972de661
--- /dev/null
+++ b/tests/prlimit64--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "prlimit64.c"
diff --git a/tests/prlimit64.c b/tests/prlimit64.c
index 34201a2b8..bc1a80b36 100644
--- a/tests/prlimit64.c
+++ b/tests/prlimit64.c
@@ -19,6 +19,7 @@
# include <sys/resource.h>
# include <unistd.h>
+# include "pidns.h"
# include "xlat.h"
# include "xlat/resources.h"
@@ -42,8 +43,11 @@ sprint_rlim(uint64_t lim)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
unsigned long pid =
(unsigned long) 0xdefaced00000000ULL | (unsigned) getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
uint64_t *const rlimit = tail_alloc(sizeof(*rlimit) * 2);
const struct xlat_data *xlat;
size_t i = 0;
@@ -54,18 +58,23 @@ main(void)
unsigned long res = 0xfacefeed00000000ULL | xlat->val;
long rc = syscall(__NR_prlimit64, pid, res, 0, rlimit);
+ pidns_print_leader();
if (rc)
- printf("prlimit64(%d, %s, NULL, %p) = %ld %s (%m)\n",
- (unsigned) pid, xlat->str, rlimit,
+ printf("prlimit64(%d%s, %s, NULL, %p) ="
+ " %ld %s (%m)\n",
+ (unsigned) pid, pid_str,
+ xlat->str, rlimit,
rc, errno2name());
else
- printf("prlimit64(%d, %s, NULL"
+ printf("prlimit64(%d%s, %s, NULL"
", {rlim_cur=%s, rlim_max=%s}) = 0\n",
- (unsigned) pid, xlat->str,
+ (unsigned) pid, pid_str,
+ xlat->str,
sprint_rlim(rlimit[0]),
sprint_rlim(rlimit[1]));
}
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/process_vm_readv--pidns-translation.c b/tests/process_vm_readv--pidns-translation.c
new file mode 100644
index 000000000..0db29ca2c
--- /dev/null
+++ b/tests/process_vm_readv--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "process_vm_readv.c"
diff --git a/tests/process_vm_readv_writev.c b/tests/process_vm_readv_writev.c
index 9309135a6..44e511ddc 100644
--- a/tests/process_vm_readv_writev.c
+++ b/tests/process_vm_readv_writev.c
@@ -12,6 +12,7 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/uio.h>
+#include "pidns.h"
#if OP_WR
# define in_iovec rmt_iovec
@@ -121,7 +122,7 @@ print_iov(const struct iovec *iov, const void *arg_ptr, long rc)
}
static void
-do_call(kernel_ulong_t pid,
+do_call(kernel_ulong_t pid, enum pid_type pid_type,
kernel_ulong_t local_iov, const char *local_arg,
kernel_ulong_t liovcnt,
kernel_ulong_t remote_iov, const char *remote_arg,
@@ -135,7 +136,8 @@ do_call(kernel_ulong_t pid,
flags);
errstr = sprintrc(rc);
- printf("%s(%d, ", OP_STR, (int) pid);
+ pidns_print_leader();
+ printf("%s(%d%s, ", OP_STR, (int) pid, pidns_pid2str(pid_type));
if (pr_iov)
pr_iov((const struct iovec *) (uintptr_t) local_iov, local_arg,
@@ -164,6 +166,8 @@ ptr_cast(void *ptr)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
enum {
SIZE_11 = 2,
SIZE_12 = 3,
@@ -243,18 +247,18 @@ main(void)
fill_memory_ex(data2_out, SIZE_2, SEGM2_BASE, SIZE_2);
- do_call(bogus_pid, (kernel_ulong_t) (uintptr_t) ARG_STR(NULL),
+ do_call(bogus_pid, PT_NONE, (kernel_ulong_t) (uintptr_t) ARG_STR(NULL),
bogus_iovcnt1, (kernel_ulong_t) (uintptr_t) ARG_STR(NULL),
bogus_iovcnt2, bogus_flags, NULL);
- do_call(my_pid, ptr_cast(bogus_iov + ARRAY_SIZE(bogus_iovec)),
+ do_call(my_pid, PT_TGID, ptr_cast(bogus_iov + ARRAY_SIZE(bogus_iovec)),
"[]", 0, ptr_cast(in_iov + ARRAY_SIZE(in_iovec)), "[]",
0, 0, NULL);
- do_call(my_pid, ptr_cast(bogus_iov + ARRAY_SIZE(bogus_iovec)), NULL,
- bogus_iovcnt1, ptr_cast(in_iov + ARRAY_SIZE(in_iovec)), NULL,
- bogus_iovcnt2, 0, print_iov);
+ do_call(my_pid, PT_TGID, ptr_cast(bogus_iov + ARRAY_SIZE(bogus_iovec)),
+ NULL, bogus_iovcnt1, ptr_cast(in_iov + ARRAY_SIZE(in_iovec)),
+ NULL, bogus_iovcnt2, 0, print_iov);
- do_call(my_pid, ptr_cast(bogus_iov), (char *) &bogus_arg,
+ do_call(my_pid, PT_TGID, ptr_cast(bogus_iov), (char *) &bogus_arg,
ARRAY_SIZE(bogus_iovec), ptr_cast(rmt_iov + 2),
(char *) &rmt_arg_cut, ARRAY_SIZE(rmt_iovec) - 2, 0, print_iov);
@@ -263,7 +267,7 @@ main(void)
lcl_arg_cut.check_rc = 1;
#endif
- do_call(my_pid, ptr_cast(lcl_iov + 2), (char *) &lcl_arg_cut,
+ do_call(my_pid, PT_TGID, ptr_cast(lcl_iov + 2), (char *) &lcl_arg_cut,
ARRAY_SIZE(lcl_iovec) - 1, ptr_cast(bogus_iov + 2),
(char *) &bogus_arg_cut, ARRAY_SIZE(bogus_iovec) - 1, 0,
print_iov);
@@ -273,15 +277,16 @@ main(void)
rmt_arg_cut.addr_term = 1;
rmt_arg_cut.count = 5;
- do_call(my_pid, ptr_cast(lcl_iov + 2), (char *) &lcl_arg_cut,
+ do_call(my_pid, PT_TGID, ptr_cast(lcl_iov + 2), (char *) &lcl_arg_cut,
ARRAY_SIZE(lcl_iovec) - 2, ptr_cast(rmt_iov + 1),
(char *) &rmt_arg_cut, ARRAY_SIZE(rmt_iovec), 0, print_iov);
/* Correct call */
- do_call(my_pid, ptr_cast(lcl_iov), (char *) &lcl_arg,
+ do_call(my_pid, PT_TGID, ptr_cast(lcl_iov), (char *) &lcl_arg,
ARRAY_SIZE(lcl_iovec), ptr_cast(rmt_iov), (char *) &rmt_arg,
ARRAY_SIZE(rmt_iovec), 0, print_iov);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
diff --git a/tests/process_vm_writev--pidns-translation.c b/tests/process_vm_writev--pidns-translation.c
new file mode 100644
index 000000000..9ba6a39be
--- /dev/null
+++ b/tests/process_vm_writev--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "process_vm_writev.c"
diff --git a/tests/rt_sigqueueinfo--pidns-translation.c b/tests/rt_sigqueueinfo--pidns-translation.c
new file mode 100644
index 000000000..74bfb464a
--- /dev/null
+++ b/tests/rt_sigqueueinfo--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "rt_sigqueueinfo.c"
diff --git a/tests/rt_sigqueueinfo.c b/tests/rt_sigqueueinfo.c
index c16938734..e22e46403 100644
--- a/tests/rt_sigqueueinfo.c
+++ b/tests/rt_sigqueueinfo.c
@@ -7,6 +7,7 @@
*/
#include "tests.h"
+#include "pidns.h"
#include <assert.h>
#include <stdio.h>
#include <signal.h>
@@ -15,6 +16,8 @@
int
main(void)
{
+ PIDNS_TEST_INIT;
+
struct sigaction sa = {
.sa_handler = SIG_IGN
};
@@ -22,15 +25,19 @@ main(void)
.sival_ptr = (void *) (unsigned long) 0xdeadbeefbadc0dedULL
};
pid_t pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
assert(sigaction(SIGUSR1, &sa, NULL) == 0);
if (sigqueue(pid, SIGUSR1, value))
perror_msg_and_skip("sigqueue");
- printf("rt_sigqueueinfo(%u, SIGUSR1, {si_signo=SIGUSR1, "
- "si_code=SI_QUEUE, si_pid=%d, si_uid=%d, "
+ pidns_print_leader();
+ printf("rt_sigqueueinfo(%d%s, SIGUSR1, {si_signo=SIGUSR1, "
+ "si_code=SI_QUEUE, si_pid=%d%s, si_uid=%u, "
"si_value={int=%d, ptr=%p}}) = 0\n",
- pid, pid, getuid(), value.sival_int, value.sival_ptr);
- printf("+++ exited with 0 +++\n");
+ pid, pid_str, pid, pid_str,
+ getuid(), value.sival_int, value.sival_ptr);
+ pidns_print_leader();
+ puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/rt_tgsigqueueinfo--pidns-translation.c b/tests/rt_tgsigqueueinfo--pidns-translation.c
new file mode 100644
index 000000000..94396f004
--- /dev/null
+++ b/tests/rt_tgsigqueueinfo--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "rt_tgsigqueueinfo.c"
diff --git a/tests/rt_tgsigqueueinfo.c b/tests/rt_tgsigqueueinfo.c
index 865c21f67..21d01cbb9 100644
--- a/tests/rt_tgsigqueueinfo.c
+++ b/tests/rt_tgsigqueueinfo.c
@@ -10,8 +10,9 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
-#ifdef __NR_rt_tgsigqueueinfo
+#if defined __NR_rt_tgsigqueueinfo && defined __NR_gettid
# include <errno.h>
# include <signal.h>
@@ -20,11 +21,11 @@
# include <unistd.h>
static long
-k_tgsigqueueinfo(const pid_t pid, const int sig, const void *const info)
+k_tgsigqueueinfo(const pid_t tgid, const int tid, const int sig, const void *const info)
{
return syscall(__NR_rt_tgsigqueueinfo,
- F8ILL_KULONG_MASK | pid,
- F8ILL_KULONG_MASK | pid,
+ F8ILL_KULONG_MASK | tgid,
+ F8ILL_KULONG_MASK | tid,
F8ILL_KULONG_MASK | sig,
info);
}
@@ -32,6 +33,8 @@ k_tgsigqueueinfo(const pid_t pid, const int sig, const void *const info)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
const struct sigaction sa = {
.sa_handler = SIG_IGN
};
@@ -48,17 +51,22 @@ main(void)
info->si_value.sival_ptr =
(void *) (unsigned long) 0xdeadbeeffacefeedULL;
- if (k_tgsigqueueinfo(info->si_pid, SIGUSR1, info))
+ if (k_tgsigqueueinfo(getpid(), syscall(__NR_gettid), SIGUSR1, info))
(errno == ENOSYS ? perror_msg_and_skip : perror_msg_and_fail)(
"rt_tgsigqueueinfo");
- printf("rt_tgsigqueueinfo(%u, %u, %s, {si_signo=%s"
- ", si_code=SI_QUEUE, si_errno=ENOENT, si_pid=%d"
+ pidns_print_leader();
+ printf("rt_tgsigqueueinfo(%d%s, %d%s, %s, {si_signo=%s"
+ ", si_code=SI_QUEUE, si_errno=ENOENT, si_pid=%d%s"
", si_uid=%d, si_value={int=%d, ptr=%p}}) = 0\n",
- info->si_pid, info->si_pid, "SIGUSR1", "SIGUSR1",
- info->si_pid, info->si_uid, info->si_value.sival_int,
+ info->si_pid, pidns_pid2str(PT_TGID),
+ info->si_pid, pidns_pid2str(PT_TID),
+ "SIGUSR1", "SIGUSR1",
+ info->si_pid, pidns_pid2str(PT_TGID),
+ info->si_uid, info->si_value.sival_int,
info->si_value.sival_ptr);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/sched_xetaffinity--pidns-translation.c b/tests/sched_xetaffinity--pidns-translation.c
new file mode 100644
index 000000000..814e39896
--- /dev/null
+++ b/tests/sched_xetaffinity--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "sched_xetaffinity.c"
diff --git a/tests/sched_xetaffinity.c b/tests/sched_xetaffinity.c
index cebff3ab5..2e508ca3c 100644
--- a/tests/sched_xetaffinity.c
+++ b/tests/sched_xetaffinity.c
@@ -10,6 +10,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#include <sched.h>
#if defined __NR_sched_getaffinity && defined __NR_sched_setaffinity \
@@ -41,8 +42,11 @@ setaffinity(unsigned long pid, unsigned long size, void *set)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
unsigned int cpuset_size = 1;
const pid_t pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
while (cpuset_size) {
assert(getaffinity(pid, cpuset_size, NULL) == -1);
@@ -50,18 +54,21 @@ main(void)
break;
if (EINVAL != errno)
perror_msg_and_skip("sched_getaffinity");
- printf("sched_getaffinity(%d, %u, NULL) = %s\n",
- pid, cpuset_size, errstr);
+ pidns_print_leader();
+ printf("sched_getaffinity(%d%s, %u, NULL) = %s\n",
+ pid, pid_str, cpuset_size, errstr);
cpuset_size <<= 1;
}
assert(cpuset_size);
- printf("sched_getaffinity(%d, %u, NULL) = %s\n",
- pid, cpuset_size, errstr);
+ pidns_print_leader();
+ printf("sched_getaffinity(%d%s, %u, NULL) = %s\n",
+ pid, pid_str, cpuset_size, errstr);
cpu_set_t *cpuset = tail_alloc(cpuset_size);
getaffinity(pid, cpuset_size, cpuset + 1);
- printf("sched_getaffinity(%d, %u, %p) = %s\n",
- pid, cpuset_size, cpuset + 1, errstr);
+ pidns_print_leader();
+ printf("sched_getaffinity(%d%s, %u, %p) = %s\n",
+ pid, pid_str, cpuset_size, cpuset + 1, errstr);
int ret_size = getaffinity(pid, cpuset_size, cpuset);
if (ret_size < 0)
@@ -69,7 +76,8 @@ main(void)
pid, (unsigned) cpuset_size, cpuset, errstr);
assert(ret_size <= (int) cpuset_size);
- printf("sched_getaffinity(%d, %u, [", pid, cpuset_size);
+ pidns_print_leader();
+ printf("sched_getaffinity(%d%s, %u, [", pid, pid_str, cpuset_size);
const char *sep;
unsigned int i, cpu;
for (i = 0, cpu = 0, sep = ""; i < (unsigned) ret_size * 8; ++i) {
@@ -85,8 +93,9 @@ main(void)
CPU_SET_S(cpu, cpuset_size, cpuset);
if (setaffinity(pid, cpuset_size, cpuset))
perror_msg_and_skip("sched_setaffinity");
- printf("sched_setaffinity(%d, %u, [%u]) = 0\n",
- pid, cpuset_size, cpu);
+ pidns_print_leader();
+ printf("sched_setaffinity(%d%s, %u, [%u]) = 0\n",
+ pid, pid_str, cpuset_size, cpu);
const unsigned int big_size = cpuset_size < 128 ? 128 : cpuset_size * 2;
cpuset = tail_alloc(big_size);
@@ -95,7 +104,8 @@ main(void)
perror_msg_and_fail("sched_getaffinity(%d, %u, %p) = %s\n",
pid, big_size, cpuset, errstr);
assert(ret_size <= (int) big_size);
- printf("sched_getaffinity(%d, %u, [", pid, big_size);
+ pidns_print_leader();
+ printf("sched_getaffinity(%d%s, %u, [", pid, pid_str, big_size);
for (i = 0, sep = ""; i < (unsigned) ret_size * 8; ++i) {
if (CPU_ISSET_S(i, (unsigned) ret_size, cpuset)) {
printf("%s%u", sep, i);
@@ -104,6 +114,7 @@ main(void)
}
printf("]) = %s\n", errstr);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/sched_xetattr--pidns-translation.c b/tests/sched_xetattr--pidns-translation.c
new file mode 100644
index 000000000..c152023dd
--- /dev/null
+++ b/tests/sched_xetattr--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "sched_xetattr.c"
diff --git a/tests/sched_xetattr.c b/tests/sched_xetattr.c
index c63d7a80b..4a76b2d65 100644
--- a/tests/sched_xetattr.c
+++ b/tests/sched_xetattr.c
@@ -15,6 +15,7 @@
# include <stdio.h>
# include <sched.h>
# include <unistd.h>
+# include "pidns.h"
# include "sched_attr.h"
# include "xlat.h"
# include "xlat/schedulers.h"
@@ -41,6 +42,8 @@ sys_sched_setattr(kernel_ulong_t pid, kernel_ulong_t attr, kernel_ulong_t flags)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
static const kernel_ulong_t bogus_pid =
(kernel_ulong_t) 0xdefacedfacefeedULL;
static const kernel_ulong_t bogus_size =
@@ -48,20 +51,28 @@ main(void)
static const kernel_ulong_t bogus_flags =
(kernel_ulong_t) 0xdefaceddeadc0deULL;
+ const int pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
+
TAIL_ALLOC_OBJECT_CONST_PTR(struct sched_attr, attr);
TAIL_ALLOC_OBJECT_CONST_PTR(unsigned int, psize);
void *const efault = attr + 1;
- sys_sched_getattr(0, 0, 0, 0);
- printf("sched_getattr(0, NULL, 0, 0) = %s\n", errstr);
+ sys_sched_getattr(pid, 0, 0, 0);
+ pidns_print_leader();
+ printf("sched_getattr(%d%s, NULL, 0, 0) = %s\n",
+ pid, pid_str, errstr);
sys_sched_getattr(0, (unsigned long) attr, 0, 0);
+ pidns_print_leader();
printf("sched_getattr(0, %p, 0, 0) = %s\n", attr, errstr);
sys_sched_getattr(bogus_pid, 0, 0, 0);
+ pidns_print_leader();
printf("sched_getattr(%d, NULL, 0, 0) = %s\n", (int) bogus_pid, errstr);
sys_sched_getattr(-1U, (unsigned long) attr, bogus_size, bogus_flags);
+ pidns_print_leader();
printf("sched_getattr(-1, %p, %s%u, %u) = %s\n",
attr,
# if defined __arm64__ || defined __aarch64__
@@ -72,11 +83,13 @@ main(void)
(unsigned) bogus_size, (unsigned) bogus_flags, errstr);
sys_sched_getattr(0, (unsigned long) efault, SCHED_ATTR_MIN_SIZE, 0);
+ pidns_print_leader();
printf("sched_getattr(0, %p, %u, 0) = %s\n",
efault, (unsigned) SCHED_ATTR_MIN_SIZE, errstr);
if (sys_sched_getattr(0, (unsigned long) attr, SCHED_ATTR_MIN_SIZE, 0))
perror_msg_and_skip("sched_getattr");
+ pidns_print_leader();
printf("sched_getattr(0, {size=%u, sched_policy=", attr->size);
printxval(schedulers, attr->sched_policy, NULL);
printf(", sched_flags=%s, sched_nice=%d, sched_priority=%u"
@@ -91,11 +104,13 @@ main(void)
(unsigned) SCHED_ATTR_MIN_SIZE);
sys_sched_getattr(0, (unsigned long) efault, sizeof(*attr), 0);
+ pidns_print_leader();
printf("sched_getattr(0, %p, %u, 0) = %s\n",
efault, (unsigned) sizeof(*attr), errstr);
if (sys_sched_getattr(0, (unsigned long) attr, sizeof(*attr), 0))
perror_msg_and_skip("sched_getattr");
+ pidns_print_leader();
printf("sched_getattr(0, {size=%u, sched_policy=", attr->size);
printxval(schedulers, attr->sched_policy, NULL);
printf(", sched_flags=%s, sched_nice=%d, sched_priority=%u"
@@ -121,11 +136,13 @@ main(void)
F8ILL_KULONG_MASK | sizeof(*attr), F8ILL_KULONG_MASK);
# if defined __arm64__ || defined __aarch64__
if (rc) {
+ pidns_print_leader();
printf("sched_getattr(0, %p, 0xffffffff<<32|%u, 0) = %s\n",
attr, (unsigned) sizeof(*attr), errstr);
} else
# endif
{
+ pidns_print_leader();
printf("sched_getattr(0, {size=%u, sched_policy=", attr->size);
printxval(schedulers, attr->sched_policy, NULL);
printf(", sched_flags=%s, sched_nice=%d, sched_priority=%u"
@@ -146,13 +163,16 @@ main(void)
}
sys_sched_setattr(bogus_pid, 0, 0);
+ pidns_print_leader();
printf("sched_setattr(%d, NULL, 0) = %s\n", (int) bogus_pid, errstr);
attr->sched_flags |= 1;
- if (sys_sched_setattr(0, (unsigned long) attr, 0))
+ if (sys_sched_setattr(pid, (unsigned long) attr, 0))
perror_msg_and_skip("sched_setattr");
- printf("sched_setattr(0, {size=%u, sched_policy=", attr->size);
+ pidns_print_leader();
+ printf("sched_setattr(%d%s, {size=%u, sched_policy=",
+ pid, pid_str, attr->size);
printxval(schedulers, attr->sched_policy, NULL);
printf(", sched_flags=%s, sched_nice=%d, sched_priority=%u"
", sched_runtime=%" PRIu64 ", sched_deadline=%" PRIu64
@@ -172,6 +192,7 @@ main(void)
sys_sched_setattr(F8ILL_KULONG_MASK, (unsigned long) attr,
F8ILL_KULONG_MASK);
+ pidns_print_leader();
printf("sched_setattr(0, {size=%u, sched_policy=", attr->size);
printxval(schedulers, attr->sched_policy, NULL);
printf(", sched_flags=%s, sched_nice=%d, sched_priority=%u"
@@ -193,11 +214,13 @@ main(void)
*psize = attr->size;
sys_sched_setattr(0, (unsigned long) psize, 0);
+ pidns_print_leader();
printf("sched_setattr(0, %p, 0) = %s\n", psize, errstr);
attr->size = 0;
sys_sched_setattr(0, (unsigned long) attr, 0);
+ pidns_print_leader();
printf("sched_setattr(0, {size=%u, sched_policy=", attr->size);
printxval(schedulers, attr->sched_policy, NULL);
printf(", sched_flags=%s, sched_nice=%d, sched_priority=%u"
@@ -213,12 +236,14 @@ main(void)
attr->size = 1;
sys_sched_setattr(0, (unsigned long) attr, 0);
+ pidns_print_leader();
printf("sched_setattr(0, {size=%u} => {size=%u}, 0) = %s\n",
1, attr->size, errstr);
attr->size = SCHED_ATTR_MIN_SIZE - 1;
sys_sched_setattr(0, (unsigned long) attr, 0);
+ pidns_print_leader();
printf("sched_setattr(0, {size=%u} => {size=%u}, 0) = %s\n",
SCHED_ATTR_MIN_SIZE - 1, attr->size, errstr);
@@ -232,6 +257,7 @@ main(void)
attr->sched_period = 0xded1ca7edda7aca7ULL;
sys_sched_setattr(bogus_pid, (unsigned long) attr, bogus_flags);
+ pidns_print_leader();
printf("sched_setattr(%d, {size=%u, sched_policy=%#x /* SCHED_??? */, "
"sched_flags=%#" PRIx64 " /* SCHED_FLAG_??? */, "
"sched_nice=%d, sched_priority=%u, sched_runtime=%" PRIu64 ", "
@@ -274,6 +300,7 @@ main(void)
attr->sched_period = 0xded1ca7edda7aca7ULL;
sys_sched_setattr(bogus_pid, (unsigned long) attr, bogus_flags);
+ pidns_print_leader();
printf("sched_setattr(%d, {size=%u, sched_policy=%#x /* SCHED_??? */, "
"sched_flags=SCHED_FLAG_RESET_ON_FORK|SCHED_FLAG_RECLAIM|"
"SCHED_FLAG_DL_OVERRUN|0x80, "
@@ -296,11 +323,13 @@ main(void)
const kernel_ulong_t ill = f8ill_ptr_to_kulong(attr);
sys_sched_getattr(0, ill, sizeof(*attr), 0);
+ pidns_print_leader();
printf("sched_getattr(0, %#llx, %u, 0) = %s\n",
(unsigned long long) ill, (unsigned) sizeof(*attr),
errstr);
sys_sched_setattr(0, ill, 0);
+ pidns_print_leader();
printf("sched_setattr(0, %#llx, 0) = %s\n",
(unsigned long long) ill, errstr);
}
@@ -310,6 +339,7 @@ main(void)
attr->sched_flags = 0x8fULL;
sys_sched_setattr(bogus_pid, (unsigned long) attr, bogus_flags);
+ pidns_print_leader();
printf("sched_setattr(%d, {size=%u, "
"sched_flags=SCHED_FLAG_RESET_ON_FORK|SCHED_FLAG_RECLAIM|"
"SCHED_FLAG_DL_OVERRUN|SCHED_FLAG_KEEP_POLICY|0x80, "
@@ -329,11 +359,13 @@ main(void)
const kernel_ulong_t ill = f8ill_ptr_to_kulong(attr);
sys_sched_getattr(0, ill, sizeof(*attr), 0);
+ pidns_print_leader();
printf("sched_getattr(0, %#llx, %u, 0) = %s\n",
(unsigned long long) ill, (unsigned) sizeof(*attr),
errstr);
sys_sched_setattr(0, ill, 0);
+ pidns_print_leader();
printf("sched_setattr(0, %#llx, 0) = %s\n",
(unsigned long long) ill, errstr);
}
@@ -342,6 +374,7 @@ main(void)
attr->sched_flags = 0xe7ULL;
sys_sched_setattr(bogus_pid, (unsigned long) attr, bogus_flags);
+ pidns_print_leader();
printf("sched_setattr(%d, {size=%u, sched_policy=%#x /* SCHED_??? */, "
"sched_flags=SCHED_FLAG_RESET_ON_FORK|SCHED_FLAG_RECLAIM|"
"SCHED_FLAG_DL_OVERRUN|SCHED_FLAG_UTIL_CLAMP_MIN"
@@ -365,11 +398,13 @@ main(void)
const kernel_ulong_t ill = f8ill_ptr_to_kulong(attr);
sys_sched_getattr(0, ill, sizeof(*attr), 0);
+ pidns_print_leader();
printf("sched_getattr(0, %#llx, %u, 0) = %s\n",
(unsigned long long) ill, (unsigned) sizeof(*attr),
errstr);
sys_sched_setattr(0, ill, 0);
+ pidns_print_leader();
printf("sched_setattr(0, %#llx, 0) = %s\n",
(unsigned long long) ill, errstr);
}
@@ -377,6 +412,7 @@ main(void)
attr->sched_flags = 0xcaffee90LL;
sys_sched_setattr(bogus_pid, (unsigned long) attr, bogus_flags);
+ pidns_print_leader();
printf("sched_setattr(%d, {size=%u, sched_flags=SCHED_FLAG_KEEP_PARAMS"
"|0xcaffee80, sched_util_min=%u, sched_util_max=%u}, %u) = %s\n",
(int) bogus_pid,
@@ -389,15 +425,18 @@ main(void)
const kernel_ulong_t ill = f8ill_ptr_to_kulong(attr);
sys_sched_getattr(0, ill, sizeof(*attr), 0);
+ pidns_print_leader();
printf("sched_getattr(0, %#llx, %u, 0) = %s\n",
(unsigned long long) ill, (unsigned) sizeof(*attr),
errstr);
sys_sched_setattr(0, ill, 0);
+ pidns_print_leader();
printf("sched_setattr(0, %#llx, 0) = %s\n",
(unsigned long long) ill, errstr);
}
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/sched_xetparam--pidns-translation.c b/tests/sched_xetparam--pidns-translation.c
new file mode 100644
index 000000000..9fb3e5794
--- /dev/null
+++ b/tests/sched_xetparam--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "sched_xetparam.c"
diff --git a/tests/sched_xetparam.c b/tests/sched_xetparam.c
index de3915b22..aa9c68cc2 100644
--- a/tests/sched_xetparam.c
+++ b/tests/sched_xetparam.c
@@ -7,6 +7,7 @@
#include "tests.h"
#include "scno.h"
+# include "pidns.h"
#if defined __NR_sched_getparam && defined __NR_sched_setparam
@@ -17,18 +18,27 @@
int
main(void)
{
+ PIDNS_TEST_INIT;
+
struct sched_param *const param =
tail_alloc(sizeof(struct sched_param));
- long rc = syscall(__NR_sched_getparam, 0, param);
- printf("sched_getparam(0, [%d]) = %ld\n",
- param->sched_priority, rc);
+ const int pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
+
+ long rc = syscall(__NR_sched_getparam, pid, param);
+ pidns_print_leader();
+ printf("sched_getparam(%d%s, [%d]) = %ld\n",
+ pid, pid_str, param->sched_priority, rc);
param->sched_priority = -1;
- rc = syscall(__NR_sched_setparam, 0, param);
- printf("sched_setparam(0, [%d]) = %ld %s (%m)\n",
+ rc = syscall(__NR_sched_setparam, pid, param);
+ pidns_print_leader();
+ printf("sched_setparam(%d%s, [%d]) = %ld %s (%m)\n",
+ pid, pid_str,
param->sched_priority, rc, errno2name());
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/sched_xetscheduler--pidns-translation.c b/tests/sched_xetscheduler--pidns-translation.c
new file mode 100644
index 000000000..78b794b27
--- /dev/null
+++ b/tests/sched_xetscheduler--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "sched_xetscheduler.c"
diff --git a/tests/sched_xetscheduler.c b/tests/sched_xetscheduler.c
index 047e86766..91b5e32d2 100644
--- a/tests/sched_xetscheduler.c
+++ b/tests/sched_xetscheduler.c
@@ -7,6 +7,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#if defined __NR_sched_getscheduler && defined __NR_sched_setscheduler
@@ -17,8 +18,13 @@
int
main(void)
{
+ PIDNS_TEST_INIT;
+
TAIL_ALLOC_OBJECT_CONST_PTR(struct sched_param, param);
- long rc = syscall(__NR_sched_getscheduler, 0);
+ const int pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
+
+ long rc = syscall(__NR_sched_getscheduler, pid);
const char *scheduler;
switch (rc) {
case SCHED_FIFO:
@@ -50,33 +56,43 @@ main(void)
default:
scheduler = "SCHED_OTHER";
}
- printf("sched_getscheduler(0) = %ld (%s)\n",
- rc, scheduler);
+ pidns_print_leader();
+ printf("sched_getscheduler(%d%s) = %ld (%s)\n",
+ pid, pid_str, rc, scheduler);
rc = syscall(__NR_sched_getscheduler, -1);
+ pidns_print_leader();
printf("sched_getscheduler(-1) = %s\n", sprintrc(rc));
param->sched_priority = -1;
- rc = syscall(__NR_sched_setscheduler, 0, SCHED_FIFO, NULL);
- printf("sched_setscheduler(0, SCHED_FIFO, NULL) = %s\n", sprintrc(rc));
+ rc = syscall(__NR_sched_setscheduler, pid, SCHED_FIFO, NULL);
+ pidns_print_leader();
+ printf("sched_setscheduler(%d%s, SCHED_FIFO, NULL) = %s\n",
+ pid, pid_str, sprintrc(rc));
- rc = syscall(__NR_sched_setscheduler, 0, SCHED_FIFO, param + 1);
- printf("sched_setscheduler(0, SCHED_FIFO, %p) = %s\n", param + 1,
- sprintrc(rc));
+ rc = syscall(__NR_sched_setscheduler, pid, SCHED_FIFO, param + 1);
+ pidns_print_leader();
+ printf("sched_setscheduler(%d%s, SCHED_FIFO, %p) = %s\n",
+ pid, pid_str, param + 1, sprintrc(rc));
- rc = syscall(__NR_sched_setscheduler, 0, 0xfaceda7a, param);
- printf("sched_setscheduler(0, %#x /* SCHED_??? */, [%d]) = %s\n",
- 0xfaceda7a, param->sched_priority, sprintrc(rc));
+ rc = syscall(__NR_sched_setscheduler, pid, 0xfaceda7a, param);
+ pidns_print_leader();
+ printf("sched_setscheduler(%d%s, %#x /* SCHED_??? */, [%d]) = %s\n",
+ pid, pid_str, 0xfaceda7a,
+ param->sched_priority, sprintrc(rc));
rc = syscall(__NR_sched_setscheduler, -1, SCHED_FIFO, param);
+ pidns_print_leader();
printf("sched_setscheduler(-1, SCHED_FIFO, [%d]) = %s\n",
param->sched_priority, sprintrc(rc));
- rc = syscall(__NR_sched_setscheduler, 0, SCHED_FIFO, param);
- printf("sched_setscheduler(0, SCHED_FIFO, [%d]) = %s\n",
- param->sched_priority, sprintrc(rc));
+ rc = syscall(__NR_sched_setscheduler, pid, SCHED_FIFO, param);
+ pidns_print_leader();
+ printf("sched_setscheduler(%d%s, SCHED_FIFO, [%d]) = %s\n",
+ pid, pid_str, param->sched_priority, sprintrc(rc));
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/signal_receive--pidns-translation.c b/tests/signal_receive--pidns-translation.c
new file mode 100644
index 000000000..b4e3b2f8a
--- /dev/null
+++ b/tests/signal_receive--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "signal_receive.c"
diff --git a/tests/signal_receive.c b/tests/signal_receive.c
index ad3b4ebd5..70441a9e1 100644
--- a/tests/signal_receive.c
+++ b/tests/signal_receive.c
@@ -8,6 +8,7 @@
*/
#include "tests.h"
+#include "pidns.h"
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
@@ -26,10 +27,13 @@ handler(int sig, siginfo_t *info, void *ucontext)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
static const char prefix[] = "KERNEL BUG";
int printed = 0;
const int pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
const int uid = geteuid();
for (int sig = 1; sig <= 31; ++sig) {
@@ -73,10 +77,13 @@ main(void)
const int e_pid = s_pid;
const int e_uid = s_uid;
#endif
- printf("kill(%d, %s) = 0\n", pid, signal2name(sig));
- printf("--- %s {si_signo=%s, si_code=SI_USER, si_pid=%d"
+ pidns_print_leader();
+ printf("kill(%d%s, %s) = 0\n", pid, pid_str, signal2name(sig));
+ pidns_print_leader();
+ printf("--- %s {si_signo=%s, si_code=SI_USER, si_pid=%d%s"
", si_uid=%d} ---\n",
- signal2name(sig), signal2name(e_sig), e_pid, e_uid);
+ signal2name(sig), signal2name(e_sig),
+ e_pid, pid_str, e_uid);
if (s_code || sig != s_sig || pid != s_pid || uid != s_uid) {
/*
@@ -91,11 +98,11 @@ main(void)
}
fprintf(stderr,
"%s: expected: si_signo=%d, si_code=%d"
- ", si_pid=%d, si_uid=%d\n"
+ ", si_pid=%d%s, si_uid=%d\n"
"%s: received: si_signo=%d, si_code=%d"
- ", si_pid=%d, si_uid=%d\n",
- prefix, sig, SI_USER, pid, uid,
- prefix, sig, s_code, s_pid, s_uid);
+ ", si_pid=%d%s, si_uid=%d\n",
+ prefix, sig, SI_USER, pid, pid_str, uid,
+ prefix, sig, s_code, s_pid, pid_str, s_uid);
}
}
@@ -104,6 +111,7 @@ main(void)
"*** PLEASE FIX THE KERNEL ***\n", prefix);
}
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/so_peercred--pidns-translation.c b/tests/so_peercred--pidns-translation.c
new file mode 100644
index 000000000..402bbcfe9
--- /dev/null
+++ b/tests/so_peercred--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "so_peercred.c"
diff --git a/tests/so_peercred.c b/tests/so_peercred.c
index 151bb1755..20188bdb1 100644
--- a/tests/so_peercred.c
+++ b/tests/so_peercred.c
@@ -9,6 +9,7 @@
*/
#include "tests.h"
+#include "pidns.h"
#include <stddef.h>
#include <stdio.h>
@@ -53,6 +54,8 @@ so_str(void)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
TAIL_ALLOC_OBJECT_CONST_PTR(struct ucred, peercred);
TAIL_ALLOC_OBJECT_CONST_PTR(socklen_t, len);
@@ -75,6 +78,8 @@ main(void)
struct ucred *const gid_truncated =
tail_alloc(sizeof_gid_truncated);
+ const char *pid_str = pidns_pid2str(PT_TGID);
+
int sv[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
perror_msg_and_skip("socketpair AF_UNIX SOCK_STREAM");
@@ -82,8 +87,10 @@ main(void)
/* classic getsockopt */
*len = sizeof(*peercred);
get_peercred(sv[0], peercred, len);
+ pidns_print_leader();
printf("getsockopt(%d, %s", sv[0], so_str());
PRINT_FIELD_D(", {", *peercred, pid);
+ printf("%s", pid_str);
PRINT_FIELD_UID(", ", *peercred, uid);
PRINT_FIELD_UID(", ", *peercred, gid);
printf("}, [%d]) = %s\n", *len, errstr);
@@ -91,14 +98,17 @@ main(void)
/* getsockopt with zero optlen */
*len = 0;
get_peercred(sv[0], peercred, len);
+ pidns_print_leader();
printf("getsockopt(%d, %s, %p, [0]) = %s\n",
sv[0], so_str(), peercred, errstr);
/* getsockopt with optlen larger than necessary - shortened */
*len = sizeof(*peercred) + 1;
get_peercred(sv[0], peercred, len);
+ pidns_print_leader();
printf("getsockopt(%d, %s", sv[0], so_str());
PRINT_FIELD_D(", {", *peercred, pid);
+ printf("%s", pid_str);
PRINT_FIELD_UID(", ", *peercred, uid);
PRINT_FIELD_UID(", ", *peercred, gid);
printf("}, [%u->%d]) = %s\n",
@@ -110,6 +120,7 @@ main(void)
*/
*len = sizeof_pid_truncated;
get_peercred(sv[0], pid_truncated, len);
+ pidns_print_leader();
printf("getsockopt(%d, %s, {pid=", sv[0], so_str());
print_quoted_hex(pid_truncated, *len);
printf("}, [%d]) = %s\n", *len, errstr);
@@ -120,8 +131,10 @@ main(void)
*/
*len = sizeof_pid;
get_peercred(sv[0], pid, len);
+ pidns_print_leader();
printf("getsockopt(%d, %s", sv[0], so_str());
PRINT_FIELD_D(", {", *pid, pid);
+ printf("%s", pid_str);
printf("}, [%d]) = %s\n", *len, errstr);
/*
@@ -136,8 +149,10 @@ main(void)
* to struct ucred.pid field.
*/
memcpy(uid, uid_truncated, sizeof_uid_truncated);
+ pidns_print_leader();
printf("getsockopt(%d, %s", sv[0], so_str());
PRINT_FIELD_D(", {", *uid, pid);
+ printf("%s", pid_str);
printf(", uid=");
print_quoted_hex(&uid->uid, sizeof_uid_truncated -
offsetof(struct ucred, uid));
@@ -149,8 +164,10 @@ main(void)
*/
*len = sizeof_uid;
get_peercred(sv[0], uid, len);
+ pidns_print_leader();
printf("getsockopt(%d, %s", sv[0], so_str());
PRINT_FIELD_D(", {", *uid, pid);
+ printf("%s", pid_str);
PRINT_FIELD_UID(", ", *uid, uid);
printf("}, [%d]) = %s\n", *len, errstr);
@@ -166,8 +183,10 @@ main(void)
* to struct ucred.pid and struct ucred.uid fields.
*/
memcpy(peercred, gid_truncated, sizeof_gid_truncated);
+ pidns_print_leader();
printf("getsockopt(%d, %s", sv[0], so_str());
PRINT_FIELD_D(", {", *peercred, pid);
+ printf("%s", pid_str);
PRINT_FIELD_UID(", ", *peercred, uid);
printf(", gid=");
print_quoted_hex(&peercred->gid, sizeof_gid_truncated -
@@ -177,14 +196,17 @@ main(void)
/* getsockopt optval EFAULT */
*len = sizeof(*peercred);
get_peercred(sv[0], &peercred->uid, len);
+ pidns_print_leader();
printf("getsockopt(%d, %s, %p, [%d]) = %s\n",
sv[0], so_str(), &peercred->uid, *len, errstr);
/* getsockopt optlen EFAULT */
get_peercred(sv[0], peercred, len + 1);
+ pidns_print_leader();
printf("getsockopt(%d, %s, %p, %p) = %s\n",
sv[0], so_str(), peercred, len + 1, errstr);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/tgkill--pidns-translation.c b/tests/tgkill--pidns-translation.c
new file mode 100644
index 000000000..c3ac2d0af
--- /dev/null
+++ b/tests/tgkill--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "tgkill.c"
diff --git a/tests/tgkill.c b/tests/tgkill.c
index 901be3764..10816a615 100644
--- a/tests/tgkill.c
+++ b/tests/tgkill.c
@@ -9,6 +9,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#ifdef __NR_tgkill
@@ -36,28 +37,46 @@ k_tgkill(const unsigned int tgid,
int
main(void)
{
+ PIDNS_TEST_INIT;
+
const int pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
+ const int tid = syscall(__NR_gettid);
+ const char *tid_str = pidns_pid2str(PT_TID);
const int bad_pid = -1;
const int bad_sig = 0xface;
- k_tgkill(pid, pid, 0);
- printf("tgkill(%d, %d, 0) = %s\n", pid, pid, errstr);
+ k_tgkill(pid, tid, 0);
+ pidns_print_leader();
+ printf("tgkill(%d%s, %d%s, 0) = %s\n",
+ pid, pid_str, tid, tid_str, errstr);
k_tgkill(pid, bad_pid, 0);
- printf("tgkill(%d, %d, 0) = %s\n", pid, bad_pid, errstr);
-
- k_tgkill(bad_pid, pid, 0);
- printf("tgkill(%d, %d, 0) = %s\n", bad_pid, pid, errstr);
-
- k_tgkill(pid, pid, SIGCONT);
- printf("tgkill(%d, %d, SIGCONT) = %s\n", pid, pid, errstr);
-
- k_tgkill(pid, pid, bad_sig);
- printf("tgkill(%d, %d, %d) = %s\n", pid, pid, bad_sig, errstr);
-
- k_tgkill(pid, pid, -bad_sig);
- printf("tgkill(%d, %d, %d) = %s\n", pid, pid, -bad_sig, errstr);
-
+ pidns_print_leader();
+ printf("tgkill(%d%s, %d, 0) = %s\n",
+ pid, pid_str, bad_pid, errstr);
+
+ k_tgkill(bad_pid, tid, 0);
+ pidns_print_leader();
+ printf("tgkill(%d, %d%s, 0) = %s\n",
+ bad_pid, tid, tid_str, errstr);
+
+ k_tgkill(pid, tid, SIGCONT);
+ pidns_print_leader();
+ printf("tgkill(%d%s, %d%s, SIGCONT) = %s\n",
+ pid, pid_str, tid, tid_str, errstr);
+
+ k_tgkill(pid, tid, bad_sig);
+ pidns_print_leader();
+ printf("tgkill(%d%s, %d%s, %d) = %s\n",
+ pid, pid_str, tid, tid_str, bad_sig, errstr);
+
+ k_tgkill(pid, tid, -bad_sig);
+ pidns_print_leader();
+ printf("tgkill(%d%s, %d%s, %d) = %s\n",
+ pid, pid_str, tid, tid_str, -bad_sig, errstr);
+
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/tkill--pidns-translation.c b/tests/tkill--pidns-translation.c
new file mode 100644
index 000000000..70a64f57d
--- /dev/null
+++ b/tests/tkill--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "tkill.c"
diff --git a/tests/tkill.c b/tests/tkill.c
index 5f67c9f5e..89466e1ae 100644
--- a/tests/tkill.c
+++ b/tests/tkill.c
@@ -9,6 +9,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#ifdef __NR_tkill
@@ -33,22 +34,30 @@ k_tkill(const unsigned int tid, const unsigned int sig)
int
main(void)
{
- const int pid = getpid();
+ PIDNS_TEST_INIT;
+
+ const int tid = syscall(__NR_gettid);
+ const char *tid_str = pidns_pid2str(PT_TID);
const int bad_pid = -1;
const int bad_sig = 0xface;
- k_tkill(pid, 0);
- printf("tkill(%d, 0) = %s\n", pid, errstr);
+ k_tkill(tid, 0);
+ pidns_print_leader();
+ printf("tkill(%d%s, 0) = %s\n", tid, tid_str, errstr);
- k_tkill(pid, SIGCONT);
- printf("tkill(%d, SIGCONT) = %s\n", pid, errstr);
+ k_tkill(tid, SIGCONT);
+ pidns_print_leader();
+ printf("tkill(%d%s, SIGCONT) = %s\n", tid, tid_str, errstr);
k_tkill(bad_pid, bad_sig);
+ pidns_print_leader();
printf("tkill(%d, %d) = %s\n", bad_pid, bad_sig, errstr);
k_tkill(bad_pid, -bad_sig);
+ pidns_print_leader();
printf("tkill(%d, %d) = %s\n", bad_pid, -bad_sig, errstr);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/trie_for_tests.c b/tests/trie_for_tests.c
new file mode 100644
index 000000000..13e564c4f
--- /dev/null
+++ b/tests/trie_for_tests.c
@@ -0,0 +1 @@
+#include "trie.c"
diff --git a/tests/trie_test.c b/tests/trie_test.c
new file mode 100644
index 000000000..21c9c11b5
--- /dev/null
+++ b/tests/trie_test.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2017-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include "trie.h"
+
+#include <stdio.h>
+#include <inttypes.h>
+
+static void
+assert_equals(const char *msg, uint64_t expected, uint64_t actual) {
+ if (actual != expected)
+ error_msg_and_fail("%s: expected: %" PRIu64
+ ", actual: %" PRIu64, msg, expected, actual);
+}
+
+static void
+iterate_fn(void *data, uint64_t key, uint64_t value)
+{
+ uint64_t expected = key < 256 && key % 10 == 0 ? key + 42 : -1ULL;
+ assert_equals("iterate_fn", expected, value);
+
+ int *count = (int *) data;
+ if (value != -1ULL)
+ (*count)++;
+}
+
+static void
+test_trie_iterate_fn(void)
+{
+ struct trie *t = trie_create(8, 6, 3, 3, -1);
+ for (int i = 0; i < 26; i++)
+ trie_set(t, i * 10, i * 10 + 42);
+
+ static const struct {
+ uint64_t start;
+ uint64_t end;
+ int expected_count;
+ } iterate_params[] = {
+ {0, 256, 26},
+ {0, UINT64_MAX, 26},
+ {20, 90, 8},
+ {99, 999, 16},
+ {10000, 100000, 0},
+ {200, 100, 0},
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(iterate_params); i++) {
+ int count = 0;
+ trie_iterate_keys(t, iterate_params[i].start, iterate_params[i].end, iterate_fn, &count);
+ assert_equals("iteration count", iterate_params[i].expected_count, count);
+ }
+}
+
+struct key_value_pair {
+ uint64_t key, value;
+};
+
+static void
+test_trie_get(void)
+{
+ static const struct {
+ uint8_t key_size;
+ uint8_t item_size_lg;
+ uint8_t node_key_bits;
+ uint8_t data_block_key_bits;
+ uint64_t empty_value;
+
+ struct key_value_pair set_values[3], get_values[3];
+ } params[] = {
+ {64, 6, 10, 10, 0,
+ {{300, 1}, {0xfacefeed, 0xabcdef123456}, {-1ULL, -1ULL}},
+ {{301, 0}, {0xfacefeed, 0xabcdef123456}, {-1ULL, -1ULL}}},
+ {8, 2, 4, 4, 10,
+ {{0xab, 0xcd}, {0xface, 2}, {0, 3}},
+ {{0xab, 0xd}, {0xface, 10}, {0, 3}}},
+ {30, 0, 6, 3, -1,
+ {{0xaaaa, 127}, {0xface, 0}, {0, 0}},
+ {{0xaaaa, 1}, {0xface, 0}, {1, 1}}},
+ {16, 4, 5, 11, 0xffffff,
+ {{0xabcdef, 42}, {0xabcd, 42}, {0xffff, 0}},
+ {{0xabcdef, 0xffff}, {0xabcd, 42}, {0xffff, 0}}},
+ {41, 5, 1, 1, -1,
+ {{0xabcdef01, 0x22222222}, {-1, 0x33333333}, {10, 10}},
+ {{0xabcdef01, 0x22222222}, {-1, 0xffffffff}, {10, 10}}},
+ };
+
+ for (size_t i = 0; i < ARRAY_SIZE(params); i++) {
+ struct trie *t = trie_create(params[i].key_size,
+ params[i].item_size_lg,
+ params[i].node_key_bits,
+ params[i].data_block_key_bits,
+ params[i].empty_value);
+
+ if (!t)
+ error_msg_and_fail("trie creation failed");
+
+ for (size_t j = 0; j < ARRAY_SIZE(params[i].set_values); j++) {
+ struct key_value_pair kv = params[i].set_values[j];
+ trie_set(t, kv.key, kv.value);
+ }
+ for (size_t j = 0; j < ARRAY_SIZE(params[i].get_values); j++) {
+ struct key_value_pair kv = params[i].get_values[j];
+ assert_equals("trie_get", kv.value, trie_get(t, kv.key));
+ }
+
+ trie_free(t);
+ }
+}
+
+int
+main(void)
+{
+ test_trie_get();
+ test_trie_iterate_fn();
+ return 0;
+}
diff --git a/tests/xet_robust_list--pidns-translation.c b/tests/xet_robust_list--pidns-translation.c
new file mode 100644
index 000000000..e04772675
--- /dev/null
+++ b/tests/xet_robust_list--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "xet_robust_list.c"
diff --git a/tests/xet_robust_list.c b/tests/xet_robust_list.c
index 43239c8b8..b5751b0ae 100644
--- a/tests/xet_robust_list.c
+++ b/tests/xet_robust_list.c
@@ -8,6 +8,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#if defined __NR_get_robust_list && defined __NR_set_robust_list
@@ -30,27 +31,36 @@ sprintaddr(void *addr)
int
main(void)
{
+ PIDNS_TEST_INIT;
+
const pid_t pid = getpid();
+ const char *pid_str = pidns_pid2str(PT_TGID);
const long long_pid = (unsigned long) (0xdeadbeef00000000LL | pid);
TAIL_ALLOC_OBJECT_CONST_PTR(void *, p_head);
TAIL_ALLOC_OBJECT_CONST_PTR(size_t, p_len);
if (syscall(__NR_get_robust_list, long_pid, p_head, p_len))
perror_msg_and_skip("get_robust_list");
- printf("get_robust_list(%d, [%s], [%lu]) = 0\n",
- (int) pid, sprintaddr(*p_head), (unsigned long) *p_len);
+ pidns_print_leader();
+ printf("get_robust_list(%d%s, [%s], [%lu]) = 0\n",
+ pid, pid_str, sprintaddr(*p_head),
+ (unsigned long) *p_len);
void *head = tail_alloc(*p_len);
if (syscall(__NR_set_robust_list, head, *p_len))
perror_msg_and_skip("set_robust_list");
+ pidns_print_leader();
printf("set_robust_list(%p, %lu) = 0\n",
head, (unsigned long) *p_len);
if (syscall(__NR_get_robust_list, long_pid, p_head, p_len))
perror_msg_and_skip("get_robust_list");
- printf("get_robust_list(%d, [%s], [%lu]) = 0\n",
- (int) pid, sprintaddr(*p_head), (unsigned long) *p_len);
+ pidns_print_leader();
+ printf("get_robust_list(%d%s, [%s], [%lu]) = 0\n",
+ pid, pid_str, sprintaddr(*p_head),
+ (unsigned long) *p_len);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/xetpgid--pidns-translation.c b/tests/xetpgid--pidns-translation.c
new file mode 100644
index 000000000..b64696282
--- /dev/null
+++ b/tests/xetpgid--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "xetpgid.c"
diff --git a/tests/xetpgid.c b/tests/xetpgid.c
index 9b070af2d..411edfc78 100644
--- a/tests/xetpgid.c
+++ b/tests/xetpgid.c
@@ -10,6 +10,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#if defined __NR_getpgid && defined __NR_setpgid
@@ -19,13 +20,21 @@
int
main(void)
{
- const int pid = getpid();
- long rc = syscall(__NR_getpgid, F8ILL_KULONG_MASK | pid);
- printf("getpgid(%d) = %ld\n", pid, rc);
-
- rc = syscall(__NR_setpgid, F8ILL_KULONG_MASK, F8ILL_KULONG_MASK | pid);
- printf("setpgid(0, %d) = %ld\n", pid, rc);
+ PIDNS_TEST_INIT;
+ const int pid = getpid();
+ long pgid = syscall(__NR_getpgid, F8ILL_KULONG_MASK | pid);
+ pidns_print_leader();
+ printf("getpgid(%d%s) = %ld%s\n", pid, pidns_pid2str(PT_TGID),
+ pgid, pidns_pid2str(PT_PGID));
+
+ long rc = syscall(__NR_setpgid, F8ILL_KULONG_MASK,
+ F8ILL_KULONG_MASK | pgid);
+ pidns_print_leader();
+ printf("setpgid(0, %ld%s) = %s\n", pgid, pidns_pid2str(PT_PGID),
+ sprintrc(rc));
+
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/xetpriority--pidns-translation.c b/tests/xetpriority--pidns-translation.c
new file mode 100644
index 000000000..c93669cb4
--- /dev/null
+++ b/tests/xetpriority--pidns-translation.c
@@ -0,0 +1,2 @@
+#define PIDNS_TRANSLATION
+#include "xetpriority.c"
diff --git a/tests/xetpriority.c b/tests/xetpriority.c
index 2d61bd10b..dd38217d7 100644
--- a/tests/xetpriority.c
+++ b/tests/xetpriority.c
@@ -7,6 +7,7 @@
#include "tests.h"
#include "scno.h"
+#include "pidns.h"
#if defined __NR_getpriority && defined __NR_setpriority
@@ -17,15 +18,30 @@
int
main(void)
{
+ PIDNS_TEST_INIT;
+
const int pid = getpid();
+ const int pgid = getpgid(0);
+
long rc = syscall(__NR_getpriority, PRIO_PROCESS,
F8ILL_KULONG_MASK | pid);
- printf("getpriority(PRIO_PROCESS, %d) = %ld\n", pid, rc);
+ pidns_print_leader();
+ printf("getpriority(PRIO_PROCESS, %d%s) = %ld\n",
+ pid, pidns_pid2str(PT_TGID), rc);
rc = syscall(__NR_setpriority, PRIO_PROCESS,
F8ILL_KULONG_MASK | pid, F8ILL_KULONG_MASK);
- printf("setpriority(PRIO_PROCESS, %d, 0) = %s\n", pid, sprintrc(rc));
+ pidns_print_leader();
+ printf("setpriority(PRIO_PROCESS, %d%s, 0) = %s\n",
+ pid, pidns_pid2str(PT_TGID), sprintrc(rc));
+
+ rc = syscall(__NR_getpriority, PRIO_PGRP,
+ F8ILL_KULONG_MASK | pgid);
+ pidns_print_leader();
+ printf("getpriority(PRIO_PGRP, %d%s) = %ld\n",
+ pgid, pidns_pid2str(PT_PGID), rc);
+ pidns_print_leader();
puts("+++ exited with 0 +++");
return 0;
}
diff --git a/tests/xmalloc_for_tests.c b/tests/xmalloc_for_tests.c
new file mode 100644
index 000000000..5c496adb5
--- /dev/null
+++ b/tests/xmalloc_for_tests.c
@@ -0,0 +1,2 @@
+#define error_msg_and_die error_msg_and_fail
+#include "xmalloc.c"