xref: /linux/tools/testing/selftests/ftrace/test.d/remotes/trace.tc (revision 5ea5880764cbb164afb17a62e76ca75dc371409d)
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
8test_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    reload_remote
62
63    # Ensure ring-buffer overflow by emitting events from the same CPU
64    for cpu in $(get_cpu_ids); do
65        break
66    done
67
68    events_per_page=$(($(get_page_size) / $(get_selftest_event_size))) # Approx: does not take TS into account
69    nr_events=$(($events_per_page * 2))
70    for i in $(seq 1 $nr_events); do
71        taskset -c $cpu echo $i > write_event
72    done
73
74    id=$(sed -n -e '1s/\[[0-9]*\]\s*[0-9]*.[0-9]*: [a-z]* id=\([0-9]*\)/\1/p' trace)
75    test $id -ne 1
76
77    check_trace $id $nr_events trace
78
79    #
80    # Test per-CPU interface
81    #
82    echo 0 > trace
83
84    for cpu in $(get_cpu_ids) ; do
85        taskset -c $cpu echo $cpu > write_event
86    done
87
88    for cpu in $(get_cpu_ids); do
89        cd per_cpu/cpu$cpu/
90
91        check_trace $cpu $cpu trace
92
93        cd - > /dev/null
94    done
95}
96
97if [ -z "$SOURCE_REMOTE_TEST" ]; then
98    set -e
99
100    setup_remote_test
101    test_trace
102fi
103