xref: /linux/tools/testing/selftests/ftrace/test.d/remotes/trace_pipe.tc (revision 0fc8f6200d2313278fbf4539bbab74677c685531)
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
8test_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
97if [ -z "$SOURCE_REMOTE_TEST" ]; then
98    set -e
99
100    setup_remote_test
101    test_trace_pipe
102fi
103