Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tracing: selftests: Add trace remote tests

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
Link: https://patch.msgid.link/20260309162516.2623589-16-vdonnefort@google.com
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Vincent Donnefort and committed by
Steven Rostedt (Google)
0a1b0325 ea908a2b

+498
+25
tools/testing/selftests/ftrace/test.d/remotes/buffer_size.tc
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # description: Test trace remote buffer size 4 + # requires: remotes/test 5 + 6 + . $TEST_DIR/remotes/functions 7 + 8 + test_buffer_size() 9 + { 10 + echo 0 > tracing_on 11 + assert_unloaded 12 + 13 + echo 4096 > buffer_size_kb 14 + echo 1 > tracing_on 15 + assert_loaded 16 + 17 + echo 0 > tracing_on 18 + echo 7 > buffer_size_kb 19 + } 20 + 21 + if [ -z "$SOURCE_REMOTE_TEST" ]; then 22 + set -e 23 + setup_remote_test 24 + test_buffer_size 25 + fi
+88
tools/testing/selftests/ftrace/test.d/remotes/functions
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + setup_remote() 4 + { 5 + local name=$1 6 + 7 + [ -e $TRACING_DIR/remotes/$name/write_event ] || exit_unresolved 8 + 9 + cd remotes/$name/ 10 + echo 0 > tracing_on 11 + clear_trace 12 + echo 7 > buffer_size_kb 13 + echo 0 > events/enable 14 + echo 1 > events/$name/selftest/enable 15 + echo 1 > tracing_on 16 + } 17 + 18 + setup_remote_test() 19 + { 20 + [ -d $TRACING_DIR/remotes/test/ ] || modprobe remote_test || exit_unresolved 21 + 22 + setup_remote "test" 23 + } 24 + 25 + assert_loaded() 26 + { 27 + grep -q "(loaded)" buffer_size_kb 28 + } 29 + 30 + assert_unloaded() 31 + { 32 + grep -q "(unloaded)" buffer_size_kb 33 + } 34 + 35 + dump_trace_pipe() 36 + { 37 + output=$(mktemp $TMPDIR/remote_test.XXXXXX) 38 + cat trace_pipe > $output & 39 + pid=$! 40 + sleep 1 41 + kill -1 $pid 42 + 43 + echo $output 44 + } 45 + 46 + check_trace() 47 + { 48 + start_id="$1" 49 + end_id="$2" 50 + file="$3" 51 + 52 + # Ensure the file is not empty 53 + test -n "$(head $file)" 54 + 55 + prev_ts=0 56 + id=0 57 + 58 + # Only keep <timestamp> <id> 59 + tmp=$(mktemp $TMPDIR/remote_test.XXXXXX) 60 + sed -e 's/\[[0-9]*\]\s*\([0-9]*.[0-9]*\): [a-z]* id=\([0-9]*\)/\1 \2/' $file > $tmp 61 + 62 + while IFS= read -r line; do 63 + ts=$(echo $line | cut -d ' ' -f 1) 64 + id=$(echo $line | cut -d ' ' -f 2) 65 + 66 + test $(echo "$ts>$prev_ts" | bc) -eq 1 67 + test $id -eq $start_id 68 + 69 + prev_ts=$ts 70 + start_id=$((start_id + 1)) 71 + done < $tmp 72 + 73 + test $id -eq $end_id 74 + rm $tmp 75 + } 76 + 77 + get_cpu_ids() 78 + { 79 + sed -n 's/^processor\s*:\s*\([0-9]\+\).*/\1/p' /proc/cpuinfo 80 + } 81 + 82 + get_page_size() { 83 + sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page 84 + } 85 + 86 + get_selftest_event_size() { 87 + sed -ne 's/^.*field:.*;.*size:\([0-9][0-9]*\);.*/\1/p' events/*/selftest/format | awk '{s+=$1} END {print s}' 88 + }
+90
tools/testing/selftests/ftrace/test.d/remotes/reset.tc
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # description: Test trace remote reset 4 + # requires: remotes/test 5 + 6 + . $TEST_DIR/remotes/functions 7 + 8 + check_reset() 9 + { 10 + write_event_path="write_event" 11 + taskset="" 12 + 13 + clear_trace 14 + 15 + # Is the buffer empty? 16 + output=$(dump_trace_pipe) 17 + test $(wc -l $output | cut -d ' ' -f1) -eq 0 18 + 19 + if $(echo $(pwd) | grep -q "per_cpu/cpu"); then 20 + write_event_path="../../write_event" 21 + cpu_id=$(echo $(pwd) | sed -e 's/.*per_cpu\/cpu//') 22 + taskset="taskset -c $cpu_id" 23 + fi 24 + rm $output 25 + 26 + # Can we properly write a new event? 27 + $taskset echo 7890 > $write_event_path 28 + output=$(dump_trace_pipe) 29 + test $(wc -l $output | cut -d ' ' -f1) -eq 1 30 + grep -q "id=7890" $output 31 + rm $output 32 + } 33 + 34 + test_global_interface() 35 + { 36 + output=$(mktemp $TMPDIR/remote_test.XXXXXX) 37 + 38 + # Confidence check 39 + echo 123456 > write_event 40 + output=$(dump_trace_pipe) 41 + grep -q "id=123456" $output 42 + rm $output 43 + 44 + # Reset single event 45 + echo 1 > write_event 46 + check_reset 47 + 48 + # Reset lost events 49 + for i in $(seq 1 10000); do 50 + echo 1 > write_event 51 + done 52 + check_reset 53 + } 54 + 55 + test_percpu_interface() 56 + { 57 + [ "$(get_cpu_ids | wc -l)" -ge 2 ] || return 0 58 + 59 + for cpu in $(get_cpu_ids); do 60 + taskset -c $cpu echo 1 > write_event 61 + done 62 + 63 + check_non_empty=0 64 + for cpu in $(get_cpu_ids); do 65 + cd per_cpu/cpu$cpu/ 66 + 67 + if [ $check_non_empty -eq 0 ]; then 68 + check_reset 69 + check_non_empty=1 70 + else 71 + # Check we have only reset 1 CPU 72 + output=$(dump_trace_pipe) 73 + test $(wc -l $output | cut -d ' ' -f1) -eq 1 74 + rm $output 75 + fi 76 + cd - 77 + done 78 + } 79 + 80 + test_reset() 81 + { 82 + test_global_interface 83 + test_percpu_interface 84 + } 85 + 86 + if [ -z "$SOURCE_REMOTE_TEST" ]; then 87 + set -e 88 + setup_remote_test 89 + test_reset 90 + fi
+127
tools/testing/selftests/ftrace/test.d/remotes/trace.tc
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # description: Test trace remote non-consuming read 4 + # requires: remotes/test 5 + 6 + . $TEST_DIR/remotes/functions 7 + 8 + test_trace() 9 + { 10 + echo 0 > tracing_on 11 + assert_unloaded 12 + 13 + echo 7 > buffer_size_kb 14 + echo 1 > tracing_on 15 + assert_loaded 16 + 17 + # Simple test: Emit few events and try to read them 18 + for i in $(seq 1 8); do 19 + echo $i > write_event 20 + done 21 + 22 + check_trace 1 8 trace 23 + 24 + # 25 + # Test interaction with consuming read 26 + # 27 + 28 + cat trace_pipe > /dev/null & 29 + pid=$! 30 + 31 + sleep 1 32 + kill $pid 33 + 34 + test $(wc -l < trace) -eq 0 35 + 36 + for i in $(seq 16 32); do 37 + echo $i > write_event 38 + done 39 + 40 + check_trace 16 32 trace 41 + 42 + # 43 + # Test interaction with reset 44 + # 45 + 46 + echo 0 > trace 47 + 48 + test $(wc -l < trace) -eq 0 49 + 50 + for i in $(seq 1 8); do 51 + echo $i > write_event 52 + done 53 + 54 + check_trace 1 8 trace 55 + 56 + # 57 + # Test interaction with lost events 58 + # 59 + 60 + # Ensure the writer is not on the reader page by reloading the buffer 61 + echo 0 > tracing_on 62 + echo 0 > trace 63 + assert_unloaded 64 + echo 1 > tracing_on 65 + assert_loaded 66 + 67 + # Ensure ring-buffer overflow by emitting events from the same CPU 68 + for cpu in $(get_cpu_ids); do 69 + break 70 + done 71 + 72 + events_per_page=$(($(get_page_size) / $(get_selftest_event_size))) # Approx: does not take TS into account 73 + nr_events=$(($events_per_page * 2)) 74 + for i in $(seq 1 $nr_events); do 75 + taskset -c $cpu echo $i > write_event 76 + done 77 + 78 + id=$(sed -n -e '1s/\[[0-9]*\]\s*[0-9]*.[0-9]*: [a-z]* id=\([0-9]*\)/\1/p' trace) 79 + test $id -ne 1 80 + 81 + check_trace $id $nr_events trace 82 + 83 + # 84 + # Test per-CPU interface 85 + # 86 + echo 0 > trace 87 + 88 + for cpu in $(get_cpu_ids) ; do 89 + taskset -c $cpu echo $cpu > write_event 90 + done 91 + 92 + for cpu in $(get_cpu_ids); do 93 + cd per_cpu/cpu$cpu/ 94 + 95 + check_trace $cpu $cpu trace 96 + 97 + cd - > /dev/null 98 + done 99 + 100 + # 101 + # Test with hotplug 102 + # 103 + 104 + [ "$(get_cpu_ids | wc -l)" -ge 2 ] || return 0 105 + 106 + echo 0 > trace 107 + 108 + for cpu in $(get_cpu_ids); do 109 + echo 0 > /sys/devices/system/cpu/cpu$cpu/online || return 0 110 + break 111 + done 112 + 113 + for i in $(seq 1 8); do 114 + echo $i > write_event 115 + done 116 + 117 + check_trace 1 8 trace 118 + 119 + echo 1 > /sys/devices/system/cpu/cpu$cpu/online 120 + } 121 + 122 + if [ -z "$SOURCE_REMOTE_TEST" ]; then 123 + set -e 124 + 125 + setup_remote_test 126 + test_trace 127 + fi
+127
tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # description: Test trace remote consuming read 4 + # requires: remotes/test 5 + 6 + . $TEST_DIR/remotes/functions 7 + 8 + test_trace_pipe() 9 + { 10 + echo 0 > tracing_on 11 + assert_unloaded 12 + 13 + # Emit events from the same CPU 14 + for cpu in $(get_cpu_ids); do 15 + break 16 + done 17 + 18 + # 19 + # Simple test: Emit enough events to fill few pages 20 + # 21 + 22 + echo 1024 > buffer_size_kb 23 + echo 1 > tracing_on 24 + assert_loaded 25 + 26 + events_per_page=$(($(get_page_size) / $(get_selftest_event_size))) 27 + nr_events=$(($events_per_page * 4)) 28 + 29 + output=$(mktemp $TMPDIR/remote_test.XXXXXX) 30 + 31 + cat trace_pipe > $output & 32 + pid=$! 33 + 34 + for i in $(seq 1 $nr_events); do 35 + taskset -c $cpu echo $i > write_event 36 + done 37 + 38 + echo 0 > tracing_on 39 + sleep 1 40 + kill $pid 41 + 42 + check_trace 1 $nr_events $output 43 + 44 + rm $output 45 + 46 + # 47 + # Test interaction with lost events 48 + # 49 + 50 + assert_unloaded 51 + echo 7 > buffer_size_kb 52 + echo 1 > tracing_on 53 + assert_loaded 54 + 55 + nr_events=$((events_per_page * 2)) 56 + for i in $(seq 1 $nr_events); do 57 + taskset -c $cpu echo $i > write_event 58 + done 59 + 60 + output=$(dump_trace_pipe) 61 + 62 + lost_events=$(sed -n -e '1s/CPU:.*\[LOST \([0-9]*\) EVENTS\]/\1/p' $output) 63 + test -n "$lost_events" 64 + 65 + id=$(sed -n -e '2s/\[[0-9]*\]\s*[0-9]*.[0-9]*: [a-z]* id=\([0-9]*\)/\1/p' $output) 66 + test "$id" -eq $(($lost_events + 1)) 67 + 68 + # Drop [LOST EVENTS] line 69 + sed -i '1d' $output 70 + 71 + check_trace $id $nr_events $output 72 + 73 + rm $output 74 + 75 + # 76 + # Test per-CPU interface 77 + # 78 + 79 + echo 0 > trace 80 + echo 1 > tracing_on 81 + 82 + for cpu in $(get_cpu_ids); do 83 + taskset -c $cpu echo $cpu > write_event 84 + done 85 + 86 + for cpu in $(get_cpu_ids); do 87 + cd per_cpu/cpu$cpu/ 88 + output=$(dump_trace_pipe) 89 + 90 + check_trace $cpu $cpu $output 91 + 92 + rm $output 93 + cd - > /dev/null 94 + done 95 + 96 + # 97 + # Test interaction with hotplug 98 + # 99 + 100 + [ "$(get_cpu_ids | wc -l)" -ge 2 ] || return 0 101 + 102 + echo 0 > trace 103 + 104 + for cpu in $(get_cpu_ids); do 105 + echo 0 > /sys/devices/system/cpu/cpu$cpu/online || return 0 106 + break 107 + done 108 + 109 + for i in $(seq 1 8); do 110 + echo $i > write_event 111 + done 112 + 113 + output=$(dump_trace_pipe) 114 + 115 + check_trace 1 8 $output 116 + 117 + rm $output 118 + 119 + echo 1 > /sys/devices/system/cpu/cpu$cpu/online 120 + } 121 + 122 + if [ -z "$SOURCE_REMOTE_TEST" ]; then 123 + set -e 124 + 125 + setup_remote_test 126 + test_trace_pipe 127 + fi
+41
tools/testing/selftests/ftrace/test.d/remotes/unloading.tc
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # description: Test trace remote unloading 4 + # requires: remotes/test 5 + 6 + . $TEST_DIR/remotes/functions 7 + 8 + test_unloading() 9 + { 10 + # No reader, writing 11 + assert_loaded 12 + 13 + # No reader, no writing 14 + echo 0 > tracing_on 15 + assert_unloaded 16 + 17 + # 1 reader, no writing 18 + cat trace_pipe & 19 + pid=$! 20 + sleep 1 21 + assert_loaded 22 + kill $pid 23 + assert_unloaded 24 + 25 + # No reader, no writing, events 26 + echo 1 > tracing_on 27 + echo 1 > write_event 28 + echo 0 > tracing_on 29 + assert_loaded 30 + 31 + # Test reset 32 + clear_trace 33 + assert_unloaded 34 + } 35 + 36 + if [ -z "$SOURCE_REMOTE_TEST" ]; then 37 + set -e 38 + 39 + setup_remote_test 40 + test_unloading 41 + fi