summaryrefslogtreecommitdiff
path: root/tests/pidns-cache.c
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 /tests/pidns-cache.c
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.
Diffstat (limited to 'tests/pidns-cache.c')
-rw-r--r--tests/pidns-cache.c62
1 files changed, 62 insertions, 0 deletions
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