Fix: tests: don't assume sequential cpuids
[lttng-tools.git] / tests / regression / tools / tracefile-limits / test_tracefile_count
CommitLineData
d946d662
CB
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com>
fe03e789 4# Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
d946d662 5#
9d16b343 6# SPDX-License-Identifier: LGPL-2.1-only
d946d662
CB
7
8TEST_DESC="Tracefile count limits"
9
fe03e789 10CURDIR=$(dirname "$0")/
d946d662
CB
11TESTDIR=$CURDIR/../../..
12
13TESTAPP_PATH="$TESTDIR/utils/testapp"
14TESTAPP_NAME="gen-ust-events"
15TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
16
17STATS_BIN="$TESTDIR/utils/babelstats.pl"
d7ee608c 18NUM_TESTS=74
d40d4ff6 19
3b0246b4 20PAGE_SIZE=$(getconf PAGE_SIZE)
fe03e789 21TRACEFILE_SIZE=$PAGE_SIZE
d946d662 22
fe03e789 23source "$TESTDIR"/utils/utils.sh
d946d662 24
4e4e5114
MJ
25NUM_CPUS=$(conf_proc_count)
26
d946d662
CB
27if [ ! -x "$TESTAPP_BIN" ]; then
28 BAIL_OUT "No UST events binary detected."
29fi
30
4e4e5114
MJ
31function 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
d946d662
CB
51function enable_lttng_channel_count_limit ()
52{
53 sess_name="$1"
54 channel_name="$2"
55 tracefile_count_limit="$3"
56
fe03e789
JG
57 test_name="Enable channel \`$channel_name\` "
58 test_name+="for session \`$sess_name\`: "
d946d662
CB
59 test_name+="$tracefile_count_limit tracefiles"
60
fe03e789
JG
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
d946d662
CB
66
67 ok $? "$test_name"
68}
69
fe03e789 70function validate_min_max ()
d946d662
CB
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
fe03e789 81function get_total_stream_file_size ()
d946d662 82{
fe03e789
JG
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"
d946d662
CB
89}
90
fe03e789 91function get_stream_file_count ()
d946d662 92{
fe03e789
JG
93 local trace_path="$1"
94 local stream_name_pattern="$2"
95 local count
d946d662 96
fe03e789
JG
97 count=$(find "$trace_path" -type f -regex "$stream_name_pattern" | wc -l)
98 echo "$count"
99}
d946d662 100
fe03e789
JG
101function test_tracefile_count_limit ()
102{
103 local count_limit="$1"
104
105 local channel_name="channel"
4e4e5114 106 local cpuno=$(pick_random_cpuid)
fe03e789
JG
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
d946d662 115
fe03e789
JG
116 session_name=$(randstring 16 0)
117 trace_path=$(mktemp -d)
d946d662 118
fe03e789 119 diag "Test tracefile count limit : CPU $cpuno, $count_limit tracefiles, expecting a maximum of $expected_size bytes per CPU"
d946d662 120
fe03e789 121 create_lttng_session_ok "$session_name" "$trace_path"
d946d662 122
fe03e789
JG
123 enable_lttng_channel_count_limit \
124 "$session_name" "$channel_name" "$count_limit"
125
126 enable_ust_lttng_event_ok \
127 "$session_name" "$event_name" "$channel_name"
128
129 # Run the test app until the total stream size stops changing the
130 # expected size is exceeded (error).
131 #
132 # The `$stream_size` will not stabilize until the trace file count
133 # limit is reached. This is guaranteed by the use of start/produce/stop
134 # cycles forcing the consumption of buffers, preventing unwanted stall
135 # in stream size.
136 while [ "$stream_size" -ne "$previous_stream_size" ]; do
137 start_lttng_tracing_notap "$session_name"
138 taskset -c "$cpuno" "$TESTAPP_BIN" -i "$num_iter" >/dev/null 2>&1
139 stop_lttng_tracing_notap "$session_name"
140
141 previous_stream_size="$stream_size"
142 stream_size=$(get_total_stream_file_size "$trace_path" "$stream_pattern")
143 diag "Completed an iteration: previous size = $previous_stream_size bytes, new size = $stream_size bytes"
144
145 if [ "$stream_size" -gt "$expected_size" ]; then
146 diag "Total size for CPU $cpuno exceeds expected size: stream size = $stream_size bytes, expected size = $expected_size"
147 break
148 fi
149 done
d946d662 150
fe03e789 151 destroy_lttng_session_ok "$session_name"
d946d662 152
fe03e789
JG
153 [ "$expected_size" -eq "$stream_size" ]
154 ok $? "Total stream size of CPU $cpuno is $expected_size"
d946d662 155
fe03e789
JG
156 [ "$(get_stream_file_count "$trace_path" "$stream_pattern")" -eq "$count_limit" ]
157 ok $? "Stream meets the trace file limit of $count_limit"
d946d662
CB
158
159 stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
160
161 validate_min_max "$stats" "intfield" "[0-9]+" "$expected_max"
162 ok $? "Trace validation - intfield"
163
164 validate_min_max "$stats" "netintfield" "[0-9]+" "$expected_max"
165 ok $? "Trace validation - netintfield"
166
167 validate_min_max "$stats" "longfield" "[0-9]+" "$expected_max"
168 ok $? "Trace validation - longfield"
169
fe03e789 170 rm -rf "$trace_path"
d946d662
CB
171}
172
d40d4ff6
CB
173LIMITS=("1" "2" "4" "8" "10" "16" "32" "64")
174
fe03e789 175plan_tests $NUM_TESTS
d946d662
CB
176
177print_test_banner "$TEST_DESC"
178
179start_lttng_sessiond
180
fe03e789 181for limit in "${LIMITS[@]}";
d946d662 182do
fe03e789 183 test_tracefile_count_limit "$limit"
d946d662
CB
184done
185
186stop_lttng_sessiond
This page took 0.048987 seconds and 4 git commands to generate.