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,
aneesh.kumar@kernel.org, kernel-team@android.com,
linux-kernel@vger.kernel.org,
Vincent Donnefort <vdonnefort@google.com>,
Shuah Khan <skhan@linuxfoundation.org>,
linux-kselftest@vger.kernel.org
Subject: [PATCH v12 15/30] tracing: selftests: Add trace remote tests
Date: Thu, 19 Feb 2026 15:02:52 +0000 [thread overview]
Message-ID: <20260219150307.14538-16-vdonnefort@google.com> (raw)
In-Reply-To: <20260219150307.14538-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)
* consuming read (trace_pipe.tc)
* non-consuming read (trace.tc)
Cc: Shuah Khan <skhan@linuxfoundation.org>
Cc: linux-kselftest@vger.kernel.org
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..1a43280ffa97
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/buffer_size.tc
@@ -0,0 +1,25 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote buffer size
+# requires: remotes/test
+
+. $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..97a09d564a34
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/functions
@@ -0,0 +1,88 @@
+# 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
+}
+
+dump_trace_pipe()
+{
+ output=$(mktemp $TMPDIR/remote_test.XXXXXX)
+ cat trace_pipe > $output &
+ pid=$!
+ sleep 1
+ kill -1 $pid
+
+ echo $output
+}
+
+check_trace()
+{
+ start_id="$1"
+ end_id="$2"
+ file="$3"
+
+ # Ensure the file is not empty
+ test -n "$(head $file)"
+
+ prev_ts=0
+ id=0
+
+ # Only keep <timestamp> <id>
+ tmp=$(mktemp $TMPDIR/remote_test.XXXXXX)
+ sed -e 's/\[[0-9]*\]\s*\([0-9]*.[0-9]*\): [a-z]* id=\([0-9]*\)/\1 \2/' $file > $tmp
+
+ while IFS= read -r line; 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 $start_id
+
+ prev_ts=$ts
+ start_id=$((start_id + 1))
+ done < $tmp
+
+ test $id -eq $end_id
+ rm $tmp
+}
+
+get_cpu_ids()
+{
+ sed -n 's/^processor\s*:\s*\([0-9]\+\).*/\1/p' /proc/cpuinfo
+}
+
+get_page_size() {
+ sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page
+}
+
+get_selftest_event_size() {
+ sed -ne 's/^.*field:.*;.*size:\([0-9][0-9]*\);.*/\1/p' events/*/selftest/format | awk '{s+=$1} END {print s}'
+}
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..4d176349b2bc
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/reset.tc
@@ -0,0 +1,90 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote reset
+# requires: remotes/test
+
+. $TEST_DIR/remotes/functions
+
+check_reset()
+{
+ write_event_path="write_event"
+ taskset=""
+
+ clear_trace
+
+ # Is the buffer empty?
+ output=$(dump_trace_pipe)
+ 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_pipe)
+ test $(wc -l $output | cut -d ' ' -f1) -eq 1
+ grep -q "id=7890" $output
+ rm $output
+}
+
+test_global_interface()
+{
+ output=$(mktemp $TMPDIR/remote_test.XXXXXX)
+
+ # Confidence check
+ echo 123456 > write_event
+ output=$(dump_trace_pipe)
+ 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_pipe)
+ 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.tc b/tools/testing/selftests/ftrace/test.d/remotes/trace.tc
new file mode 100644
index 000000000000..170f7648732a
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/trace.tc
@@ -0,0 +1,127 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote non-consuming read
+# requires: remotes/test
+
+. $TEST_DIR/remotes/functions
+
+test_trace()
+{
+ echo 0 > tracing_on
+ assert_unloaded
+
+ echo 7 > buffer_size_kb
+ echo 1 > tracing_on
+ assert_loaded
+
+ # Simple test: Emit few events and try to read them
+ for i in $(seq 1 8); do
+ echo $i > write_event
+ done
+
+ check_trace 1 8 trace
+
+ #
+ # Test interaction with consuming read
+ #
+
+ cat trace_pipe > /dev/null &
+ pid=$!
+
+ sleep 1
+ kill $pid
+
+ test $(wc -l < trace) -eq 0
+
+ for i in $(seq 16 32); do
+ echo $i > write_event
+ done
+
+ check_trace 16 32 trace
+
+ #
+ # Test interaction with reset
+ #
+
+ echo 0 > trace
+
+ test $(wc -l < trace) -eq 0
+
+ for i in $(seq 1 8); do
+ echo $i > write_event
+ done
+
+ check_trace 1 8 trace
+
+ #
+ # Test interaction with lost events
+ #
+
+ # Ensure the writer is not on the reader page by reloading the buffer
+ echo 0 > tracing_on
+ echo 0 > trace
+ assert_unloaded
+ echo 1 > tracing_on
+ assert_loaded
+
+ # Ensure ring-buffer overflow by emitting events from the same CPU
+ for cpu in $(get_cpu_ids); do
+ break
+ done
+
+ events_per_page=$(($(get_page_size) / $(get_selftest_event_size))) # Approx: does not take TS into account
+ nr_events=$(($events_per_page * 2))
+ for i in $(seq 1 $nr_events); do
+ taskset -c $cpu echo $i > write_event
+ done
+
+ id=$(sed -n -e '1s/\[[0-9]*\]\s*[0-9]*.[0-9]*: [a-z]* id=\([0-9]*\)/\1/p' trace)
+ test $id -ne 1
+
+ check_trace $id $nr_events trace
+
+ #
+ # Test per-CPU interface
+ #
+ echo 0 > trace
+
+ for cpu in $(get_cpu_ids) ; do
+ taskset -c $cpu echo $cpu > write_event
+ done
+
+ for cpu in $(get_cpu_ids); do
+ cd per_cpu/cpu$cpu/
+
+ check_trace $cpu $cpu trace
+
+ cd - > /dev/null
+ done
+
+ #
+ # Test with hotplug
+ #
+
+ [ "$(get_cpu_ids | wc -l)" -ge 2 ] || return 0
+
+ echo 0 > trace
+
+ for cpu in $(get_cpu_ids); do
+ echo 0 > /sys/devices/system/cpu/cpu$cpu/online || return 0
+ break
+ done
+
+ for i in $(seq 1 8); do
+ echo $i > write_event
+ done
+
+ check_trace 1 8 trace
+
+ echo 1 > /sys/devices/system/cpu/cpu$cpu/online
+}
+
+if [ -z "$SOURCE_REMOTE_TEST" ]; then
+ set -e
+
+ setup_remote_test
+ test_trace
+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..669a7288ed7c
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc
@@ -0,0 +1,127 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote consuming read
+# requires: remotes/test
+
+. $TEST_DIR/remotes/functions
+
+test_trace_pipe()
+{
+ echo 0 > tracing_on
+ assert_unloaded
+
+ # Emit events from the same CPU
+ for cpu in $(get_cpu_ids); do
+ break
+ done
+
+ #
+ # Simple test: Emit enough events to fill few pages
+ #
+
+ echo 1024 > buffer_size_kb
+ echo 1 > tracing_on
+ assert_loaded
+
+ events_per_page=$(($(get_page_size) / $(get_selftest_event_size)))
+ nr_events=$(($events_per_page * 4))
+
+ output=$(mktemp $TMPDIR/remote_test.XXXXXX)
+
+ cat trace_pipe > $output &
+ pid=$!
+
+ for i in $(seq 1 $nr_events); do
+ taskset -c $cpu echo $i > write_event
+ done
+
+ echo 0 > tracing_on
+ sleep 1
+ kill $pid
+
+ check_trace 1 $nr_events $output
+
+ rm $output
+
+ #
+ # Test interaction with lost events
+ #
+
+ assert_unloaded
+ echo 7 > buffer_size_kb
+ echo 1 > tracing_on
+ assert_loaded
+
+ nr_events=$((events_per_page * 2))
+ for i in $(seq 1 $nr_events); do
+ taskset -c $cpu echo $i > write_event
+ done
+
+ output=$(dump_trace_pipe)
+
+ lost_events=$(sed -n -e '1s/CPU:.*\[LOST \([0-9]*\) EVENTS\]/\1/p' $output)
+ test -n "$lost_events"
+
+ id=$(sed -n -e '2s/\[[0-9]*\]\s*[0-9]*.[0-9]*: [a-z]* id=\([0-9]*\)/\1/p' $output)
+ test "$id" -eq $(($lost_events + 1))
+
+ # Drop [LOST EVENTS] line
+ sed -i '1d' $output
+
+ check_trace $id $nr_events $output
+
+ rm $output
+
+ #
+ # Test per-CPU interface
+ #
+
+ echo 0 > trace
+ echo 1 > tracing_on
+
+ for cpu in $(get_cpu_ids); do
+ taskset -c $cpu echo $cpu > write_event
+ done
+
+ for cpu in $(get_cpu_ids); do
+ cd per_cpu/cpu$cpu/
+ output=$(dump_trace_pipe)
+
+ check_trace $cpu $cpu $output
+
+ rm $output
+ cd - > /dev/null
+ done
+
+ #
+ # Test interaction with hotplug
+ #
+
+ [ "$(get_cpu_ids | wc -l)" -ge 2 ] || return 0
+
+ echo 0 > trace
+
+ for cpu in $(get_cpu_ids); do
+ echo 0 > /sys/devices/system/cpu/cpu$cpu/online || return 0
+ break
+ done
+
+ for i in $(seq 1 8); do
+ echo $i > write_event
+ done
+
+ output=$(dump_trace_pipe)
+
+ check_trace 1 8 $output
+
+ rm $output
+
+ echo 1 > /sys/devices/system/cpu/cpu$cpu/online
+}
+
+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..cac2190183f6
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/remotes/unloading.tc
@@ -0,0 +1,41 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Test trace remote unloading
+# requires: remotes/test
+
+. $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
+
+ # Test reset
+ clear_trace
+ assert_unloaded
+}
+
+if [ -z "$SOURCE_REMOTE_TEST" ]; then
+ set -e
+
+ setup_remote_test
+ test_unloading
+fi
--
2.53.0.335.g19a08e0c02-goog
next prev parent reply other threads:[~2026-02-19 15:04 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 15:02 [PATCH v12 00/30] Tracefs support for pKVM Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 01/30] ring-buffer: Add page statistics to the meta-page Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 02/30] ring-buffer: Store bpage pointers into subbuf_ids Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 03/30] ring-buffer: Introduce ring-buffer remotes Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 04/30] ring-buffer: Add non-consuming read for " Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 05/30] tracing: Introduce trace remotes Vincent Donnefort
2026-02-19 17:55 ` Steven Rostedt
2026-02-19 15:02 ` [PATCH v12 06/30] tracing: Add reset to " Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 07/30] tracing: Add non-consuming read " Vincent Donnefort
2026-02-19 17:55 ` Steven Rostedt
2026-02-19 15:02 ` [PATCH v12 08/30] tracing: Add init callback " Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 09/30] tracing: Add events " Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 10/30] tracing: Add events/ root files " Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 11/30] tracing: Add helpers to create trace remote events Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 12/30] ring-buffer: Export buffer_data_page and macros Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 13/30] tracing: Introduce simple_ring_buffer Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 14/30] tracing: Add a trace remote module for testing Vincent Donnefort
2026-02-19 15:02 ` Vincent Donnefort [this message]
2026-02-19 17:56 ` [PATCH v12 15/30] tracing: selftests: Add trace remote tests Steven Rostedt
2026-02-19 15:02 ` [PATCH v12 16/30] Documentation: tracing: Add tracing remotes Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 17/30] tracing: load/unload page callbacks for simple_ring_buffer Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 18/30] tracing: Check for undefined symbols in simple_ring_buffer Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 19/30] KVM: arm64: Add PKVM_DISABLE_STAGE2_ON_PANIC Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 20/30] KVM: arm64: Add clock support to nVHE/pKVM hyp Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 21/30] KVM: arm64: Initialise hyp_nr_cpus for nVHE hyp Vincent Donnefort
2026-02-19 15:02 ` [PATCH v12 22/30] KVM: arm64: Support unaligned fixmap in the pKVM hyp Vincent Donnefort
2026-02-19 15:03 ` [PATCH v12 23/30] KVM: arm64: Add tracing capability for the nVHE/pKVM hyp Vincent Donnefort
2026-02-19 15:03 ` [PATCH v12 24/30] KVM: arm64: Add trace remote " Vincent Donnefort
2026-02-19 15:03 ` [PATCH v12 25/30] KVM: arm64: Sync boot clock with " Vincent Donnefort
2026-02-19 15:03 ` [PATCH v12 26/30] KVM: arm64: Add trace reset to " Vincent Donnefort
2026-02-19 15:03 ` [PATCH v12 27/30] KVM: arm64: Add event support to the nVHE/pKVM hyp and trace remote Vincent Donnefort
2026-02-19 15:03 ` [PATCH v12 28/30] KVM: arm64: Add hyp_enter/hyp_exit events to nVHE/pKVM hyp Vincent Donnefort
2026-02-19 15:03 ` [PATCH v12 29/30] KVM: arm64: Add selftest event support " Vincent Donnefort
2026-02-19 15:03 ` [PATCH v12 30/30] tracing: selftests: Add hypervisor trace remote tests Vincent Donnefort
2026-02-19 18:02 ` [PATCH v12 00/30] Tracefs support for pKVM Steven Rostedt
2026-02-19 19:11 ` Marc Zyngier
2026-03-05 16:17 ` Steven Rostedt
2026-03-05 18:35 ` Vincent Donnefort
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=20260219150307.14538-16-vdonnefort@google.com \
--to=vdonnefort@google.com \
--cc=aneesh.kumar@kernel.org \
--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-kselftest@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=skhan@linuxfoundation.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