Tests: use CPU ids from online ranges
[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
CB
24
25if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT "No UST events binary detected."
27fi
28
4e4e5114
MJ
29function pick_random_cpuid ()
30{
dae3e20b
KS
31 local cpuids
32 read -r -a cpuids <<< "$(get_online_cpus)"
33 echo "${cpuids[ $RANDOM % ${#cpuids[@]} ]}"
4e4e5114
MJ
34}
35
d946d662
CB
36function enable_lttng_channel_count_limit ()
37{
38 sess_name="$1"
39 channel_name="$2"
40 tracefile_count_limit="$3"
41
fe03e789
JG
42 test_name="Enable channel \`$channel_name\` "
43 test_name+="for session \`$sess_name\`: "
d946d662
CB
44 test_name+="$tracefile_count_limit tracefiles"
45
fe03e789
JG
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
d946d662
CB
51
52 ok $? "$test_name"
53}
54
fe03e789 55function validate_min_max ()
d946d662
CB
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
fe03e789 66function get_total_stream_file_size ()
d946d662 67{
fe03e789
JG
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"
d946d662
CB
74}
75
fe03e789 76function get_stream_file_count ()
d946d662 77{
fe03e789
JG
78 local trace_path="$1"
79 local stream_name_pattern="$2"
80 local count
d946d662 81
fe03e789
JG
82 count=$(find "$trace_path" -type f -regex "$stream_name_pattern" | wc -l)
83 echo "$count"
84}
d946d662 85
fe03e789
JG
86function test_tracefile_count_limit ()
87{
88 local count_limit="$1"
89
90 local channel_name="channel"
4e4e5114 91 local cpuno=$(pick_random_cpuid)
fe03e789
JG
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
d946d662 100
fe03e789
JG
101 session_name=$(randstring 16 0)
102 trace_path=$(mktemp -d)
d946d662 103
fe03e789 104 diag "Test tracefile count limit : CPU $cpuno, $count_limit tracefiles, expecting a maximum of $expected_size bytes per CPU"
d946d662 105
fe03e789 106 create_lttng_session_ok "$session_name" "$trace_path"
d946d662 107
fe03e789
JG
108 enable_lttng_channel_count_limit \
109 "$session_name" "$channel_name" "$count_limit"
110
111 enable_ust_lttng_event_ok \
112 "$session_name" "$event_name" "$channel_name"
113
114 # Run the test app until the total stream size stops changing the
115 # expected size is exceeded (error).
116 #
117 # The `$stream_size` will not stabilize until the trace file count
118 # limit is reached. This is guaranteed by the use of start/produce/stop
119 # cycles forcing the consumption of buffers, preventing unwanted stall
120 # in stream size.
121 while [ "$stream_size" -ne "$previous_stream_size" ]; do
122 start_lttng_tracing_notap "$session_name"
123 taskset -c "$cpuno" "$TESTAPP_BIN" -i "$num_iter" >/dev/null 2>&1
124 stop_lttng_tracing_notap "$session_name"
125
126 previous_stream_size="$stream_size"
127 stream_size=$(get_total_stream_file_size "$trace_path" "$stream_pattern")
128 diag "Completed an iteration: previous size = $previous_stream_size bytes, new size = $stream_size bytes"
129
130 if [ "$stream_size" -gt "$expected_size" ]; then
131 diag "Total size for CPU $cpuno exceeds expected size: stream size = $stream_size bytes, expected size = $expected_size"
132 break
133 fi
134 done
d946d662 135
fe03e789 136 destroy_lttng_session_ok "$session_name"
d946d662 137
fe03e789
JG
138 [ "$expected_size" -eq "$stream_size" ]
139 ok $? "Total stream size of CPU $cpuno is $expected_size"
d946d662 140
fe03e789
JG
141 [ "$(get_stream_file_count "$trace_path" "$stream_pattern")" -eq "$count_limit" ]
142 ok $? "Stream meets the trace file limit of $count_limit"
d946d662
CB
143
144 stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
145
146 validate_min_max "$stats" "intfield" "[0-9]+" "$expected_max"
147 ok $? "Trace validation - intfield"
148
149 validate_min_max "$stats" "netintfield" "[0-9]+" "$expected_max"
150 ok $? "Trace validation - netintfield"
151
152 validate_min_max "$stats" "longfield" "[0-9]+" "$expected_max"
153 ok $? "Trace validation - longfield"
154
fe03e789 155 rm -rf "$trace_path"
d946d662
CB
156}
157
d40d4ff6
CB
158LIMITS=("1" "2" "4" "8" "10" "16" "32" "64")
159
fe03e789 160plan_tests $NUM_TESTS
d946d662
CB
161
162print_test_banner "$TEST_DESC"
163
164start_lttng_sessiond
165
fe03e789 166for limit in "${LIMITS[@]}";
d946d662 167do
fe03e789 168 test_tracefile_count_limit "$limit"
d946d662
CB
169done
170
171stop_lttng_sessiond
This page took 0.05031 seconds and 4 git commands to generate.