Fix: tests: don't assume sequential cpuids
[lttng-tools.git] / tests / regression / tools / tracefile-limits / test_tracefile_count
1 #!/bin/bash
2 #
3 # Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 #
6 # SPDX-License-Identifier: LGPL-2.1-only
7
8 TEST_DESC="Tracefile count limits"
9
10 CURDIR=$(dirname "$0")/
11 TESTDIR=$CURDIR/../../..
12
13 TESTAPP_PATH="$TESTDIR/utils/testapp"
14 TESTAPP_NAME="gen-ust-events"
15 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
16
17 STATS_BIN="$TESTDIR/utils/babelstats.pl"
18 NUM_TESTS=74
19
20 PAGE_SIZE=$(getconf PAGE_SIZE)
21 TRACEFILE_SIZE=$PAGE_SIZE
22
23 source "$TESTDIR"/utils/utils.sh
24
25 NUM_CPUS=$(conf_proc_count)
26
27 if [ ! -x "$TESTAPP_BIN" ]; then
28 BAIL_OUT "No UST events binary detected."
29 fi
30
31 function pick_random_cpuid ()
32 {
33 local cpuid=0
34
35 # On Linux pick a random available cpuid from sysfs
36 if [ -d "/sys/devices/system/cpu" ]; then
37 local cpuids=()
38
39 for i in /sys/devices/system/cpu/cpu[0-9]*; do
40 cpuids+=("${i#/sys/devices/system/cpu/cpu}")
41 done
42
43 cpuid=${cpuids[ $RANDOM % ${#cpuids[@]} ]}
44 else
45 cpuid=$((RANDOM % NUM_CPUS))
46 fi
47
48 echo $cpuid
49 }
50
51 function enable_lttng_channel_count_limit ()
52 {
53 sess_name="$1"
54 channel_name="$2"
55 tracefile_count_limit="$3"
56
57 test_name="Enable channel \`$channel_name\` "
58 test_name+="for session \`$sess_name\`: "
59 test_name+="$tracefile_count_limit tracefiles"
60
61 "$TESTDIR"/../src/bin/lttng/"$LTTNG_BIN" enable-channel \
62 -u "$channel_name" -s "$sess_name" \
63 --subbuf-size "$PAGE_SIZE" \
64 --tracefile-size "$TRACEFILE_SIZE" \
65 --tracefile-count "$tracefile_count_limit" >/dev/null 2>&1
66
67 ok $? "$test_name"
68 }
69
70 function validate_min_max ()
71 {
72 stats="$1"
73 field="$2"
74 expected_min="$3"
75 expected_max="$4"
76
77 echo $stats | grep -q -E "$field $expected_min $expected_max"
78 return $?
79 }
80
81 function get_total_stream_file_size ()
82 {
83 local trace_path="$1"
84 local stream_name_pattern="$2"
85 local size
86
87 size=$(find "$trace_path" -type f -regex "$stream_name_pattern" -exec du -b -c {} + | tail -n1 | cut -f 1)
88 echo "$size"
89 }
90
91 function get_stream_file_count ()
92 {
93 local trace_path="$1"
94 local stream_name_pattern="$2"
95 local count
96
97 count=$(find "$trace_path" -type f -regex "$stream_name_pattern" | wc -l)
98 echo "$count"
99 }
100
101 function test_tracefile_count_limit ()
102 {
103 local count_limit="$1"
104
105 local channel_name="channel"
106 local cpuno=$(pick_random_cpuid)
107 local event_name="tp:tptest"
108 local expected_size=$((count_limit * TRACEFILE_SIZE))
109 local num_iter=100000
110 local previous_stream_size=-1
111 local session_name
112 local stream_pattern=".*${channel_name}_${cpuno}_[0-9]*"
113 local stream_size=0
114 local trace_path=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
115
116 session_name=$(randstring 16 0)
117
118 diag "Test tracefile count limit : CPU $cpuno, $count_limit tracefiles, expecting a maximum of $expected_size bytes per CPU"
119
120 create_lttng_session_ok "$session_name" "$trace_path"
121
122 enable_lttng_channel_count_limit \
123 "$session_name" "$channel_name" "$count_limit"
124
125 enable_ust_lttng_event_ok \
126 "$session_name" "$event_name" "$channel_name"
127
128 # Run the test app until the total stream size stops changing the
129 # expected size is exceeded (error).
130 #
131 # The `$stream_size` will not stabilize until the trace file count
132 # limit is reached. This is guaranteed by the use of start/produce/stop
133 # cycles forcing the consumption of buffers, preventing unwanted stall
134 # in stream size.
135 while [ "$stream_size" -ne "$previous_stream_size" ]; do
136 start_lttng_tracing_notap "$session_name"
137 taskset -c "$cpuno" "$TESTAPP_BIN" -i "$num_iter" >/dev/null 2>&1
138 stop_lttng_tracing_notap "$session_name"
139
140 previous_stream_size="$stream_size"
141 stream_size=$(get_total_stream_file_size "$trace_path" "$stream_pattern")
142 diag "Completed an iteration: previous size = $previous_stream_size bytes, new size = $stream_size bytes"
143
144 if [ "$stream_size" -gt "$expected_size" ]; then
145 diag "Total size for CPU $cpuno exceeds expected size: stream size = $stream_size bytes, expected size = $expected_size"
146 break
147 fi
148 done
149
150 destroy_lttng_session_ok "$session_name"
151
152 [ "$expected_size" -eq "$stream_size" ]
153 ok $? "Total stream size of CPU $cpuno is $expected_size"
154
155 [ "$(get_stream_file_count "$trace_path" "$stream_pattern")" -eq "$count_limit" ]
156 ok $? "Stream meets the trace file limit of $count_limit"
157
158 stats=`"$BABELTRACE_BIN" $trace_path | $STATS_BIN --tracepoint $event_name`
159
160 validate_min_max "$stats" "intfield" "[0-9]+" "$expected_max"
161 ok $? "Trace validation - intfield"
162
163 validate_min_max "$stats" "netintfield" "[0-9]+" "$expected_max"
164 ok $? "Trace validation - netintfield"
165
166 validate_min_max "$stats" "longfield" "[0-9]+" "$expected_max"
167 ok $? "Trace validation - longfield"
168
169 rm -rf "$trace_path"
170 }
171
172 LIMITS=("1" "2" "4" "8" "10" "16" "32" "64")
173
174 plan_tests $NUM_TESTS
175
176 print_test_banner "$TEST_DESC"
177
178 bail_out_if_no_babeltrace
179
180 start_lttng_sessiond
181
182 for limit in "${LIMITS[@]}";
183 do
184 test_tracefile_count_limit "$limit"
185 done
186
187 stop_lttng_sessiond
This page took 0.034064 seconds and 5 git commands to generate.