From: Vincent Donnefort <vdonnefort@google.com>
To: rostedt@goodmis.org, mhiramat@kernel.org,
mathieu.desnoyers@efficios.com,
linux-trace-kernel@vger.kernel.org, maz@kernel.org,
oliver.upton@linux.dev, joey.gouly@arm.com,
suzuki.poulose@arm.com, yuzenghui@huawei.com
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
jstultz@google.com, qperret@google.com, will@kernel.org,
kernel-team@android.com, linux-kernel@vger.kernel.org,
Vincent Donnefort <vdonnefort@google.com>
Subject: [PATCH v4 11/24] tracing: selftests: Add trace remote tests
Date: Tue, 6 May 2025 17:48:07 +0100 [thread overview]
Message-ID: <20250506164820.515876-12-vdonnefort@google.com> (raw)
In-Reply-To: <20250506164820.515876-1-vdonnefort@google.com>
Exercise the tracefs interface for trace remote with a set of tests to
check:
* loading/unloading (unloading.tc)
* reset (reset.tc)
* size changes (buffer_size.tc)
* event integrity (trace_pipe)
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
diff --git a/tools/testing/selftests/ftrace/test.d/remotes/buffer_size.tc b/tools/testing/selftests/ftrace/test.d/remotes/buffer_size.tc
new file mode 100644
index 000000000000..60bf431ccc91
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/buffer_size.tc
@@ -0,0 +1,24 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote buffer size
+
+. $TEST_DIR/remotes/functions
+
+test_buffer_size()
+{
+ echo 0 > tracing_on
+ assert_unloaded
+
+ echo 4096 > buffer_size_kb
+ echo 1 > tracing_on
+ assert_loaded
+
+ echo 0 > tracing_on
+ echo 7 > buffer_size_kb
+}
+
+if [ -z "$SOURCE_REMOTE_TEST" ]; then
+ set -e
+ setup_remote_test
+ test_buffer_size
+fi
diff --git a/tools/testing/selftests/ftrace/test.d/remotes/functions b/tools/testing/selftests/ftrace/test.d/remotes/functions
new file mode 100644
index 000000000000..504a495b3b1b
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/functions
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: GPL-2.0
+
+setup_remote()
+{
+ local name=$1
+
+ [ -e $TRACING_DIR/remotes/$name/write_event ] || exit_unresolved
+
+ cd remotes/$name/
+ echo 0 > tracing_on
+ clear_trace
+ echo 7 > buffer_size_kb
+ echo 0 > events/enable
+ echo 1 > events/$name/selftest/enable
+ echo 1 > tracing_on
+}
+
+setup_remote_test()
+{
+ [ -d $TRACING_DIR/remotes/test/ ] || modprobe remote_test || exit_unresolved
+
+ setup_remote "test"
+}
+
+assert_loaded()
+{
+ grep -q "(loaded)" buffer_size_kb
+}
+
+assert_unloaded()
+{
+ grep -q "(unloaded)" buffer_size_kb
+}
diff --git a/tools/testing/selftests/ftrace/test.d/remotes/reset.tc b/tools/testing/selftests/ftrace/test.d/remotes/reset.tc
new file mode 100644
index 000000000000..93d6eb2a807f
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/reset.tc
@@ -0,0 +1,105 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote reset
+
+. $TEST_DIR/remotes/functions
+
+get_cpu_ids()
+{
+ sed -n 's/^processor\s*:\s*\([0-9]\+\).*/\1/p' /proc/cpuinfo
+}
+
+dump_trace()
+{
+ output=$(mktemp /tmp/remote_test.XXXXXX)
+ cat trace_pipe > $output &
+ pid=$!
+ sleep 1
+ kill -1 $pid
+
+ echo $output
+}
+
+check_reset()
+{
+ write_event_path="write_event"
+ taskset=""
+
+ clear_trace
+
+ # Is the buffer empty?
+ output=$(dump_trace)
+ test $(wc -l $output | cut -d ' ' -f1) -eq 0
+
+ if $(echo $(pwd) | grep -q "per_cpu/cpu"); then
+ write_event_path="../../write_event"
+ cpu_id=$(echo $(pwd) | sed -e 's/.*per_cpu\/cpu//')
+ taskset="taskset -c $cpu_id"
+ fi
+ rm $output
+
+ # Can we properly write a new event?
+ $taskset echo 7890 > $write_event_path
+ output=$(dump_trace)
+ test $(wc -l $output | cut -d ' ' -f1) -eq 1
+ grep -q "id=7890" $output
+ rm $output
+}
+
+test_global_interface()
+{
+ output=$(mktemp /tmp/remote_test.XXXXXX)
+
+ # Confidence check
+ echo 123456 > write_event
+ output=$(dump_trace)
+ grep -q "id=123456" $output
+ rm $output
+
+ # Reset single event
+ echo 1 > write_event
+ check_reset
+
+ # Reset lost events
+ for i in $(seq 1 10000); do
+ echo 1 > write_event
+ done
+ check_reset
+}
+
+test_percpu_interface()
+{
+ [ "$(get_cpu_ids | wc -l)" -ge 2 ] || return 0
+
+ for cpu in $(get_cpu_ids); do
+ taskset -c $cpu echo 1 > write_event
+ done
+
+ check_non_empty=0
+ for cpu in $(get_cpu_ids); do
+ cd per_cpu/cpu$cpu/
+
+ if [ $check_non_empty -eq 0 ]; then
+ check_reset
+ check_non_empty=1
+ else
+ # Check we have only reset 1 CPU
+ output=$(dump_trace)
+ test $(wc -l $output | cut -d ' ' -f1) -eq 1
+ rm $output
+ fi
+ cd -
+ done
+}
+
+test_reset()
+{
+ test_global_interface
+ test_percpu_interface
+}
+
+if [ -z "$SOURCE_REMOTE_TEST" ]; then
+ set -e
+ setup_remote_test
+ test_reset
+fi
diff --git a/tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc b/tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc
new file mode 100644
index 000000000000..f4bd2b3655e0
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc
@@ -0,0 +1,57 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote trace_pipe
+
+. $TEST_DIR/remotes/functions
+
+test_trace_pipe()
+{
+ echo 0 > tracing_on
+ assert_unloaded
+
+ echo 1024 > buffer_size_kb
+ echo 1 > tracing_on
+ assert_loaded
+
+ output=$(mktemp /tmp/remote_test.XXXXXX)
+
+ cat trace_pipe > $output &
+ pid=$!
+
+ for i in $(seq 1 1000); do
+ echo $i > write_event
+ done
+
+ echo 0 > tracing_on
+ sleep 1
+ kill $pid
+
+ prev_ts=0 # TODO: Init with proper clock value
+ prev_id=0
+
+ # Only keep <timestamp> <id>
+ sed -i -e 's/\[[0-9]*\]\s*\([0-9]*.[0-9]*\): [a-z]* id=\([0-9]*\)/\1 \2/' $output
+
+ IFS=$'\n'
+ for line in $(cat $output); do
+ ts=$(echo $line | cut -d ' ' -f 1)
+ id=$(echo $line | cut -d ' ' -f 2)
+
+ test $(echo "$ts>$prev_ts" | bc) -eq 1
+ test $id -eq $((prev_id + 1))
+
+ prev_ts=$ts
+ prev_id=$id
+ done
+
+ test $prev_id -eq 1000
+
+ rm $output
+}
+
+if [ -z "$SOURCE_REMOTE_TEST" ]; then
+ set -e
+
+ setup_remote_test
+ test_trace_pipe
+fi
diff --git a/tools/testing/selftests/ftrace/test.d/remotes/unloading.tc b/tools/testing/selftests/ftrace/test.d/remotes/unloading.tc
new file mode 100644
index 000000000000..05bb21f80e34
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/unloading.tc
@@ -0,0 +1,36 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote unloading
+
+. $TEST_DIR/remotes/functions
+
+test_unloading()
+{
+ # No reader, writing
+ assert_loaded
+
+ # No reader, no writing
+ echo 0 > tracing_on
+ assert_unloaded
+
+ # 1 reader, no writing
+ cat trace_pipe &
+ pid=$!
+ sleep 1
+ assert_loaded
+ kill $pid
+ assert_unloaded
+
+ # No reader, no writing, events
+ echo 1 > tracing_on
+ echo 1 > write_event
+ echo 0 > tracing_on
+ assert_loaded
+}
+
+if [ -z "$SOURCE_REMOTE_TEST" ]; then
+ set -e
+
+ setup_remote_test
+ test_unloading
+fi
--
2.49.0.967.g6a0df3ecc3-goog
next prev parent reply other threads:[~2025-05-06 16:49 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 16:47 [PATCH v4 00/24] Tracefs support for pKVM Vincent Donnefort
2025-05-06 16:47 ` [PATCH v4 01/24] ring-buffer: Introduce ring-buffer remotes Vincent Donnefort
2025-05-07 23:47 ` Steven Rostedt
2025-05-08 9:10 ` Vincent Donnefort
2025-05-08 14:05 ` Steven Rostedt
2025-05-06 16:47 ` [PATCH v4 02/24] tracing: Introduce trace remotes Vincent Donnefort
2025-05-08 0:24 ` Steven Rostedt
2025-05-08 9:14 ` Vincent Donnefort
2025-05-06 16:47 ` [PATCH v4 03/24] tracing: Add reset to " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 04/24] tracing: Add init callback " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 05/24] tracing: Add events " Vincent Donnefort
2025-05-09 19:47 ` Steven Rostedt
2025-05-12 7:55 ` Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 06/24] tracing: Add events/ root files " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 07/24] tracing: Add helpers to create trace remote events Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 08/24] ring-buffer: Expose buffer_data_page material Vincent Donnefort
2025-05-09 19:54 ` Steven Rostedt
2025-05-06 16:48 ` [PATCH v4 09/24] tracing: Introduce simple_ring_buffer Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 10/24] tracing: Add a trace remote module for testing Vincent Donnefort
2025-05-06 16:48 ` Vincent Donnefort [this message]
2025-05-06 16:48 ` [PATCH v4 12/24] tracing: load/unload page callbacks for simple_ring_buffer Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 13/24] tracing: Check for undefined symbols in simple_ring_buffer Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 14/24] KVM: arm64: Support unaligned fixmap in the nVHE hyp Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 15/24] KVM: arm64: Add .hyp.data section Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 16/24] KVM: arm64: Add clock support for the pKVM hyp Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 17/24] KVM: arm64: Add tracing capability " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 18/24] KVM: arm64: Add trace remote " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 19/24] KVM: arm64: Sync boot clock with " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 20/24] KVM: arm64: Add trace reset to " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 21/24] KVM: arm64: Add event support to the pKVM hyp and trace remote Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 22/24] KVM: arm64: Add hyp_enter/hyp_exit events to pKVM hyp Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 23/24] KVM: arm64: Add selftest event support " Vincent Donnefort
2025-05-06 16:48 ` [PATCH v4 24/24] tracing: selftests: Add pKVM trace remote tests Vincent Donnefort
2025-05-14 17:38 ` [PATCH v4 00/24] Tracefs support for pKVM Steven Rostedt
2025-05-14 18:13 ` Vincent Donnefort
2025-05-14 18:28 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250506164820.515876-12-vdonnefort@google.com \
--to=vdonnefort@google.com \
--cc=joey.gouly@arm.com \
--cc=jstultz@google.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=maz@kernel.org \
--cc=mhiramat@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=rostedt@goodmis.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox