All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [for-next][PATCH 06/15] selftests/ftrace: Add test case for overriding trace_instance parameter
Date: Thu, 26 Nov 2026 11:24:29 -0500	[thread overview]
Message-ID: <20261126162445.073021208@kernel.org> (raw)
In-Reply-To: 20261126162423.442922469@kernel.org

From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>

Add a boot-time tracing test case to verify that specifying multiple
trace_instance= parameters with the same instance name overrides earlier
definitions:

   - Verifies that a kernel command-line trace_instance= parameter
     overrides an earlier trace instance defined via bootconfig
     (kernel.trace_instance).
   - Verifies that a later kernel command-line trace_instance=
     parameter overrides an earlier trace_instance= on the same
     command line.
   - Verifies overriding a memory-mapped trace instance (@trace).
   - Verifies overriding a backup trace instance (=source).
   - Verifies parsing parameters containing multiple tabs and
     gracefully handling empty strings.
   - Confirms that the overridden instance has its previous events
     disabled, new events enabled, and flags (such as traceoff)
     properly applied.

Link: https://patch.msgid.link/179094975229.609715.3664484413379599809.stgit@devnote2
Assisted-by: LLM
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 .../cmdline-07-trace-instance-override.bconf  |   4 +
 ...cmdline-07-trace-instance-override.cmdline |   1 +
 .../ftrace/boottime/run_boottime_test.sh      |   2 +
 .../cmdline-07-trace-instance-override.sh     | 148 ++++++++++++++++++
 4 files changed, 155 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf
 create mode 100644 tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline
 create mode 100755 tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh

diff --git a/tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf b/tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf
new file mode 100644
index 000000000000..74d8be54a798
--- /dev/null
+++ b/tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf
@@ -0,0 +1,4 @@
+kernel.trace_instance = "boot_map@trace,sched:sched_switch",
+			"bak_to_norm=boot_map",
+			"bak_from_norm,sched:sched_switch",
+			"foo,sched:sched_switch"
diff --git a/tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline b/tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline
new file mode 100644
index 000000000000..3c16bb0f3545
--- /dev/null
+++ b/tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline
@@ -0,0 +1 @@
+reserve_mem=12M:32M:trace trace_instance=foo^traceoff,sched:sched_waking trace_instance=bar,sched:sched_switch trace_instance=bar^traceoff,irq:irq_handler_entry trace_instance=boot_map^traceoff@trace,sched:sched_waking trace_instance=bak_to_norm^traceoff,irq:irq_handler_entry trace_instance=bak_from_norm=boot_map trace_instance="tab1,sched:sched_switch		tab2,sched:sched_switch" trace_instance=tab1^traceoff,sched:sched_waking trace_instance= trace_instance="" trace_instance=,
diff --git a/tools/testing/selftests/ftrace/boottime/run_boottime_test.sh b/tools/testing/selftests/ftrace/boottime/run_boottime_test.sh
index 6e8593d5a2c5..1d30adc388a6 100755
--- a/tools/testing/selftests/ftrace/boottime/run_boottime_test.sh
+++ b/tools/testing/selftests/ftrace/boottime/run_boottime_test.sh
@@ -46,6 +46,8 @@ BUSYBOX_APPLETS=(
 	grep
 	sleep
 	sed
+	dmesg
+	basename
 )
 
 usage() {
diff --git a/tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh b/tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh
new file mode 100755
index 000000000000..960a3cf54d97
--- /dev/null
+++ b/tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh
@@ -0,0 +1,148 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2026, Google LLC.
+# Check trace_instance= override with bootconfig and kernel command-line
+TRACEDIR="/sys/kernel/tracing"
+
+if [ -f /proc/bootconfig ] && \
+   grep -q "dump_bconf" /proc/cmdline 2>/dev/null; then
+	echo "=== /proc/bootconfig ==="
+	cat /proc/bootconfig
+	echo "========================"
+fi
+
+check_instance() {
+	instance="$1"
+	old_event="$2"
+	new_event="$3"
+
+	if [ ! -d "$TRACEDIR/instances/$instance" ]; then
+		echo "FAIL: trace instance $instance does not exist"
+		exit 1
+	fi
+
+	if [ -n "$old_event" ] && \
+	   [ -f "$TRACEDIR/instances/$instance/events/$old_event/enable" ]; then
+		ENABLE=$(cat "$TRACEDIR/instances/$instance/events/$old_event/enable")
+		if [ "$ENABLE" = "1" ]; then
+			echo "FAIL: overridden event $old_event" \
+				"is still enabled in instance $instance"
+			exit 1
+		fi
+	fi
+
+	if [ -n "$new_event" ]; then
+		if [ ! -d "$TRACEDIR/instances/$instance/events/$new_event" ]; then
+			echo "FAIL: event $new_event does not exist in instance $instance"
+			exit 1
+		fi
+
+		ENABLE=$(cat "$TRACEDIR/instances/$instance/events/$new_event/enable")
+		if [ "$ENABLE" != "1" ]; then
+			echo "FAIL: event $new_event is not enabled in instance $instance ($ENABLE)"
+			exit 1
+		fi
+	fi
+
+	TRACING_ON=$(cat "$TRACEDIR/instances/$instance/tracing_on")
+	if [ "$TRACING_ON" != "0" ]; then
+		echo "FAIL: tracing_on is not 0 in instance $instance ($TRACING_ON)"
+		exit 1
+	fi
+}
+
+check_backup_instance() {
+	instance="$1"
+
+	if [ ! -d "$TRACEDIR/instances/$instance" ]; then
+		echo "FAIL: trace instance $instance does not exist"
+		exit 1
+	fi
+
+	# Backup instances have a trace buffer file
+	if [ ! -f "$TRACEDIR/instances/$instance/trace" ]; then
+		echo "FAIL: backup instance $instance has no trace file"
+		exit 1
+	fi
+
+	# Backup instances are read-only and do not have tracing_on
+	if [ -f "$TRACEDIR/instances/$instance/tracing_on" ]; then
+		echo "FAIL: backup instance $instance unexpectedly has tracing_on"
+		exit 1
+	fi
+
+	# Backup instances do not support enabling events
+	if [ -f \
+	   "$TRACEDIR/instances/$instance/events/sched/sched_switch/enable" ]; then
+		echo "FAIL: backup instance $instance unexpectedly has enabled events"
+		exit 1
+	fi
+}
+
+check_mapped_instance() {
+	instance="$1"
+	old_event="$2"
+	new_event="$3"
+
+	check_instance "$instance" "$old_event" "$new_event"
+
+	# Check dmesg to confirm physical mapping occurred
+	if ! dmesg | grep -q "mapped boot instance $instance"; then
+		echo "FAIL: memory-mapped instance $instance was not mapped at boot"
+		exit 1
+	fi
+}
+
+# Test 1: bootconfig trace_instance overridden by cmdline parameter
+check_instance "foo" "sched/sched_switch" "sched/sched_waking"
+
+# Test 2: cmdline trace_instance overridden by subsequent cmdline parameter
+check_instance "bar" "sched/sched_switch" "irq/irq_handler_entry"
+
+# Test 3: memory-mapped (@trace) instance in bootconfig overridden by cmdline
+check_mapped_instance "boot_map" "sched/sched_switch" "sched/sched_waking"
+
+# Test 4a: backup instance in bootconfig overridden by normal
+# instance in cmdline
+check_instance "bak_to_norm" "" "irq/irq_handler_entry"
+
+# Test 4b: normal instance in bootconfig overridden by backup
+# instance in cmdline
+check_backup_instance "bak_from_norm"
+
+# Test 5: instances separated by multiple tabs, where first is overridden
+check_instance "tab1" "sched/sched_switch" "sched/sched_waking"
+# tab2 was not overridden, so its original event should remain enabled
+if [ ! -d "$TRACEDIR/instances/tab2/events/sched/sched_switch" ]; then
+	echo "FAIL: instance tab2 event sched/sched_switch does not exist"
+	exit 1
+fi
+ENABLE=$(cat "$TRACEDIR/instances/tab2/events/sched/sched_switch/enable")
+if [ "$ENABLE" != "1" ]; then
+	echo "FAIL: instance tab2 event sched/sched_switch is not enabled ($ENABLE)"
+	exit 1
+fi
+
+# Test 6: Verify empty strings and malformed entries did not create
+# bogus directories
+for dir in "$TRACEDIR/instances"/*; do
+	[ -d "$dir" ] || continue
+	bname=$(basename "$dir")
+	case "$bname" in
+		foo|bar|boot_map|bak_to_norm|bak_from_norm|tab1|tab2)
+			;;
+		*)
+			echo "FAIL: unexpected trace instance directory found: $bname"
+			exit 1
+			;;
+	esac
+done
+
+# Test 7: Verify no kernel warnings or assertion failures were triggered
+if dmesg | grep -q "WARNING: CPU:"; then
+	echo "FAIL: kernel warning triggered during boot"
+	exit 1
+fi
+
+echo "PASS: cmdline-07-trace-instance-override"
+exit 0
-- 
2.53.0

  parent reply	other threads:[~2026-11-26 16:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 16:24 [for-next][PATCH 00/15] tracing: Updates for 7.5 Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 01/15] tracing: Do not clean up hiter in mmiotrace read function Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 02/15] lockdep: Add #include <linux/instruction_pointer.h> to lockdep.h Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 03/15] tracing: Move non-trace_printk prototypes into trace_controls.h Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 04/15] tracing: Remove trace_printk.h from kernel.h Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 05/15] tracing: Override the same name trace_instance= by latter one Steven Rostedt
2026-11-26 16:24 ` Steven Rostedt [this message]
2026-11-26 16:24 ` [for-next][PATCH 07/15] tracing/scripts: Check the section end before reading a string in tracing-update Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 08/15] tracing/scripts: Do not reuse section pointers from a previous file " Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 09/15] tracing/filters: Report parse error on all -EINVAL paths in filter parsing Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 10/15] tracing/filters: Fix quoted operand parsing in function event filter Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 11/15] tracing/filters: Reject empty unquoted operand " Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 12/15] tracing/filters: Reject unsupported field sizes in parse_pred() Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 13/15] tracing/filters: Check for trailing characters after newline in filter string Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 14/15] tracing/filters: Reject stray quotes and parentheses in unquoted function event operand Steven Rostedt
2026-11-26 16:24 ` [for-next][PATCH 15/15] tracing: Export live module tracepoint strings in printk_formats 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=20261126162445.073021208@kernel.org \
    --to=rostedt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.