[RFC PATCH 3/4] Test pidns translation cache

Ákos Uzonyi uzonyi.akos at gmail.com
Thu Aug 13 15:32:41 UTC 2020


---
 tests/.gitignore       |  1 +
 tests/Makefile.am      |  2 ++
 tests/pidns-cache.c    | 29 +++++++++++++++++++++++++++++
 tests/pidns-cache.test | 23 +++++++++++++++++++++++
 4 files changed, 55 insertions(+)
 create mode 100644 tests/pidns-cache.c
 create mode 100755 tests/pidns-cache.test

diff --git a/tests/.gitignore b/tests/.gitignore
index 4d1153fc..fc512ad2 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -525,6 +525,7 @@ pidfd_open-yy
 pidfd_open--pidns-translation
 pidfd_send_signal
 pidfd_send_signal--pidns-translation
+pidns-performance
 pipe
 pipe2
 pkey_alloc
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f2c5da83..8aaa0cae 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -190,6 +190,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
 	perf_event_open_unabbrev \
 	pidfd_open--pidns-translation \
 	pidfd_send_signal--pidns-translation \
+	pidns-cache \
 	poll-P \
 	ppoll-P \
 	ppoll-v \
@@ -425,6 +426,7 @@ MISC_TESTS = \
 	opipe.test \
 	options-syntax.test \
 	pc.test \
+	pidns-cache.test \
 	printpath-umovestr-legacy.test \
 	printstrn-umoven-legacy.test \
 	qual_fault-syntax.test \
diff --git a/tests/pidns-cache.c b/tests/pidns-cache.c
new file mode 100644
index 00000000..989f7db3
--- /dev/null
+++ b/tests/pidns-cache.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2020 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include "pidns.h"
+
+#include <stdio.h>
+#include <unistd.h>
+
+/**
+ * There is a 1 sec timeout for this test. With pidns caching more than 1000
+ * syscalls can be executed, without caching only a few tens.
+ */
+#define SYSCALL_COUNT 200
+
+int
+main(void)
+{
+	pidns_test_init();
+
+        for (int i = 0; i < SYSCALL_COUNT; i++)
+                getpid();
+
+	return 0;
+}
diff --git a/tests/pidns-cache.test b/tests/pidns-cache.test
new file mode 100755
index 00000000..8c126f91
--- /dev/null
+++ b/tests/pidns-cache.test
@@ -0,0 +1,23 @@
+#!/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"
+
+require_min_kernel_version_or_skip 4.9
+check_prog timeout
+
+run_prog > /dev/null
+timeout 1 $STRACE -o /dev/null --pidns-translation -f -e trace=getpid $args || {
+        rc=$?
+        if [ $rc -eq 124 ]; then
+                fail_ "pidns translation took too long"
+        else
+                fail_ "$args failed with code $rc"
+        fi
+}
-- 
2.28.0



More information about the Strace-devel mailing list