mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Vincent Donnefort <vdonnefort@google.com>
Cc: rostedt@goodmis.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,
	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,
	Shuah Khan <skhan@linuxfoundation.org>,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v6 12/24] tracing: selftests: Add trace remote tests
Date: Wed, 3 Sep 2025 13:58:14 +0900	[thread overview]
Message-ID: <20250903135814.57c4ec19de536032c640b755@kernel.org> (raw)
In-Reply-To: <20250821081412.1008261-13-vdonnefort@google.com>

On Thu, 21 Aug 2025 09:14:00 +0100
Vincent Donnefort <vdonnefort@google.com> wrote:

> 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)
> 
> 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..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

I think this test requires `remotes/`. If so, please add

# requires: remotes

Then this test will be skipped if it is not enabled.

> +
> +. $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

Ditto.

> +
> +. $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)

For the test-local temporary working directory, can you use $TMPDIR
instead of /tmp ? That directory is removed after running each test.

> +    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

Ditto.

> +
> +. $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'

This fails checkbashisms test. Can you use printf for this?

IFS=$(printf "\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..99f97e100fde
> --- /dev/null
> +++ b/tools/testing/selftests/ftrace/test.d/remotes/unloading.tc
> @@ -0,0 +1,40 @@
> +#!/bin/sh
> +# SPDX-License-Identifier: GPL-2.0
> +# description: Test trace remote unloading

Here, please add "requires: remotes" line.

Thank you,


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  reply	other threads:[~2025-09-03  4:58 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21  8:13 [PATCH v6 00/24] Tracefs support for pKVM Vincent Donnefort
2025-08-21  8:13 ` [PATCH v6 01/24] ring-buffer: Add page statistics to the meta-page Vincent Donnefort
2025-08-21  8:13 ` [PATCH v6 02/24] ring-buffer: Introduce ring-buffer remotes Vincent Donnefort
2025-09-08 23:13   ` Steven Rostedt
2025-08-21  8:13 ` [PATCH v6 03/24] tracing: Introduce trace remotes Vincent Donnefort
2025-09-08 23:36   ` Steven Rostedt
2025-09-09 12:08     ` Vincent Donnefort
2025-09-09 13:38       ` Steven Rostedt
2025-09-09 16:10         ` Vincent Donnefort
2025-09-09 18:19           ` Steven Rostedt
2025-08-21  8:13 ` [PATCH v6 04/24] tracing: Add reset to " Vincent Donnefort
2025-09-08 23:37   ` Steven Rostedt
2025-09-09 12:10     ` Vincent Donnefort
2025-09-09 13:40       ` Steven Rostedt
2025-09-09 16:14         ` Vincent Donnefort
2025-09-09 18:39           ` Steven Rostedt
2025-09-09 18:52             ` Steven Rostedt
2025-09-10  9:45               ` Vincent Donnefort
2025-09-10 16:45                 ` Steven Rostedt
2025-08-21  8:13 ` [PATCH v6 05/24] tracing: Add init callback " Vincent Donnefort
2025-08-21  8:13 ` [PATCH v6 06/24] tracing: Add events " Vincent Donnefort
2025-09-09 21:47   ` Steven Rostedt
2025-09-09 22:24     ` Steven Rostedt
2025-08-21  8:13 ` [PATCH v6 07/24] tracing: Add events/ root files " Vincent Donnefort
2025-09-09 21:52   ` Steven Rostedt
2025-08-21  8:13 ` [PATCH v6 08/24] tracing: Add helpers to create trace remote events Vincent Donnefort
2025-08-21  8:13 ` [PATCH v6 09/24] ring-buffer: Export buffer_data_page and macros Vincent Donnefort
2025-08-21  8:13 ` [PATCH v6 10/24] tracing: Introduce simple_ring_buffer Vincent Donnefort
2025-09-09 22:26   ` Steven Rostedt
2025-09-10  9:47     ` Vincent Donnefort
2025-08-21  8:13 ` [PATCH v6 11/24] tracing: Add a trace remote module for testing Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 12/24] tracing: selftests: Add trace remote tests Vincent Donnefort
2025-09-03  4:58   ` Masami Hiramatsu [this message]
2025-08-21  8:14 ` [PATCH v6 13/24] tracing: load/unload page callbacks for simple_ring_buffer Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 14/24] tracing: Check for undefined symbols in simple_ring_buffer Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 15/24] KVM: arm64: Support unaligned fixmap in the pKVM hyp Vincent Donnefort
2025-09-10 16:47   ` Steven Rostedt
2025-09-10 17:06     ` Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 16/24] KVM: arm64: Add clock support for " Vincent Donnefort
2025-09-12 13:48   ` Will Deacon
2025-08-21  8:14 ` [PATCH v6 17/24] KVM: arm64: Add tracing capability " Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 18/24] KVM: arm64: Add trace remote " Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 19/24] KVM: arm64: Sync boot clock with " Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 20/24] KVM: arm64: Add trace reset to " Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 21/24] KVM: arm64: Add event support to the pKVM hyp and trace remote Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 22/24] KVM: arm64: Add hyp_enter/hyp_exit events to pKVM hyp Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 23/24] KVM: arm64: Add selftest event support " Vincent Donnefort
2025-08-21  8:14 ` [PATCH v6 24/24] tracing: selftests: Add pKVM trace remote tests 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=20250903135814.57c4ec19de536032c640b755@kernel.org \
    --to=mhiramat@kernel.org \
    --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=oliver.upton@linux.dev \
    --cc=qperret@google.com \
    --cc=rostedt@goodmis.org \
    --cc=skhan@linuxfoundation.org \
    --cc=suzuki.poulose@arm.com \
    --cc=vdonnefort@google.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

all inboxes | Powered by JetHome®