[RFC PATCH v9 8/8] [squash] Add tests for tkill, tgkill

Ákos Uzonyi uzonyi.akos at gmail.com
Sun Aug 16 22:18:51 UTC 2020


---
 tests/.gitignore                  |  2 ++
 tests/Makefile.am                 |  2 ++
 tests/gen_tests.in                |  2 ++
 tests/tgkill--pidns-translation.c |  2 ++
 tests/tgkill.c                    | 51 +++++++++++++++++++++----------
 tests/tkill--pidns-translation.c  |  2 ++
 tests/tkill.c                     | 19 +++++++++---
 7 files changed, 59 insertions(+), 21 deletions(-)
 create mode 100644 tests/tgkill--pidns-translation.c
 create mode 100644 tests/tkill--pidns-translation.c

diff --git a/tests/.gitignore b/tests/.gitignore
index 237d2d03..a75b3deb 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -759,6 +759,7 @@ syslog
 syslog-success
 tee
 tgkill
+tgkill--pidns-translation
 threads-execve
 threads-execve--quiet-thread-execve
 threads-execve-q
@@ -771,6 +772,7 @@ timerfd_xettime
 times
 times-fail
 tkill
+tkill--pidns-translation
 tracer_ppid_pgid_sid
 trie
 truncate
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8ed6933f..379b9851 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -241,11 +241,13 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
 	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 \
 	unblock_reset_raise \
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 1138c6af..d272031e 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -688,6 +688,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
@@ -699,6 +700,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
diff --git a/tests/tgkill--pidns-translation.c b/tests/tgkill--pidns-translation.c
new file mode 100644
index 00000000..c3ac2d0a
--- /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 901be376..10816a61 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 00000000..70a64f57
--- /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 5f67c9f5..89466e1a 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;
 }
-- 
2.28.0



More information about the Strace-devel mailing list