Tests: Add test to check shared-memory FD leaks after relayd dies
[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 BT2_PLUGINS_DIR="${TESTDIR}/utils/bt2_plugins"
13
14 TESTAPP_PATH="$TESTDIR/utils/testapp"
15 TESTAPP_NAME="gen-ust-events"
16 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
17
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 if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT "No UST events binary detected."
27 fi
28
29 function pick_random_cpuid ()
30 {
31 local cpuids
32 read -r -a cpuids <<< "$(get_online_cpus)"
33 echo "${cpuids[ $RANDOM % ${#cpuids[@]} ]}"
34 }
35
36 function enable_lttng_channel_count_limit ()
37 {
38 sess_name="$1"
39 channel_name="$2"
40 tracefile_count_limit="$3"
41
42 test_name="Enable channel \`$channel_name\` "
43 test_name+="for session \`$sess_name\`: "
44 test_name+="$tracefile_count_limit tracefiles"
45
46 "$TESTDIR"/../src/bin/lttng/"$LTTNG_BIN" enable-channel \
47 -u "$channel_name" -s "$sess_name" \
48 --subbuf-size "$PAGE_SIZE" \
49 --tracefile-size "$TRACEFILE_SIZE" \
50 --tracefile-count "$tracefile_count_limit" >/dev/null 2>&1
51
52 ok $? "$test_name"
53 }
54
55 function validate_min_max ()
56 {
57 stats="$1"
58 field="$2"
59 expected_min="$3"
60 expected_max="$4"
61
62 echo $stats | grep -q -E "$field $expected_min $expected_max"
63 return $?
64 }
65
66 function get_total_stream_file_size ()
67 {
68 local trace_path="$1"
69 local stream_name_pattern="$2"
70 local size
71
72 size=$(find "$trace_path" -type f -regex "$stream_name_pattern" -exec du -b -c {} + | tail -n1 | cut -f 1)
73 echo "$size"
74 }
75
76 function get_stream_file_count ()
77 {
78 local trace_path="$1"
79 local stream_name_pattern="$2"
80 local count
81
82 count=$(find "$trace_path" -type f -regex "$stream_name_pattern" | wc -l)
83 echo "$count"
84 }
85
86 function test_tracefile_count_limit ()
87 {
88 local count_limit="$1"
89
90 local channel_name="channel"
91 local cpuno=$(pick_random_cpuid)
92 local event_name="tp:tptest"
93 local expected_size=$((count_limit * TRACEFILE_SIZE))
94 local num_iter=100000
95 local previous_stream_size=-1
96 local session_name
97 local stream_pattern=".*${channel_name}_${cpuno}_[0-9]*"
98 local stream_size=0
99 local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
100
101 session_name=$(randstring 16 0)
102
103 diag "Test tracefile count limit : CPU $cpuno, $count_limit tracefiles, expecting a maximum of $expected_size bytes per CPU"
104
105 create_lttng_session_ok "$session_name" "$trace_path"
106
107 enable_lttng_channel_count_limit \
108 "$session_name" "$channel_name" "$count_limit"
109
110 enable_ust_lttng_event_ok \
111 "$session_name" "$event_name" "$channel_name"
112
113 # Run the test app until the total stream size stops changing the
114 # expected size is exceeded (error).
115 #
116 # The `$stream_size` will not stabilize until the trace file count
117 # limit is reached. This is guaranteed by the use of start/produce/stop
118 # cycles forcing the consumption of buffers, preventing unwanted stall
119 # in stream size.
120 while [ "$stream_size" -ne "$previous_stream_size" ]; do
121 start_lttng_tracing_notap "$session_name"
122 taskset -c "$cpuno" "$TESTAPP_BIN" -i "$num_iter" >/dev/null 2>&1
123 stop_lttng_tracing_notap "$session_name"
124
125 previous_stream_size="$stream_size"
126 stream_size=$(get_total_stream_file_size "$trace_path" "$stream_pattern")
127 diag "Completed an iteration: previous size = $previous_stream_size bytes, new size = $stream_size bytes"
128
129 if [ "$stream_size" -gt "$expected_size" ]; then
130 diag "Total size for CPU $cpuno exceeds expected size: stream size = $stream_size bytes, expected size = $expected_size"
131 break
132 fi
133 done
134
135 destroy_lttng_session_ok "$session_name"
136
137 [ "$expected_size" -eq "$stream_size" ]
138 ok $? "Total stream size of CPU $cpuno is $expected_size"
139
140 [ "$(get_stream_file_count "$trace_path" "$stream_pattern")" -eq "$count_limit" ]
141 ok $? "Stream meets the trace file limit of $count_limit"
142
143 stats=$("$BABELTRACE_BIN" --plugin-path "${BT2_PLUGINS_DIR}" convert $trace_path -c filter.lttngtest.event_name -p "names=[\"${event_name}\"]" -c sink.lttngtest.field_stats)
144
145 validate_min_max "$stats" "intfield" "[0-9]+" "$expected_max"
146 ok $? "Trace validation - intfield"
147
148 validate_min_max "$stats" "netintfield" "[0-9]+" "$expected_max"
149 ok $? "Trace validation - netintfield"
150
151 validate_min_max "$stats" "longfield" "[0-9]+" "$expected_max"
152 ok $? "Trace validation - longfield"
153
154 rm -rf "$trace_path"
155 }
156
157 LIMITS=("1" "2" "4" "8" "10" "16" "32" "64")
158
159 plan_tests $NUM_TESTS
160
161 print_test_banner "$TEST_DESC"
162
163 bail_out_if_no_babeltrace
164
165 start_lttng_sessiond
166
167 for limit in "${LIMITS[@]}";
168 do
169 test_tracefile_count_limit "$limit"
170 done
171
172 stop_lttng_sessiond
This page took 0.034727 seconds and 5 git commands to generate.