Commit | Line | Data |
---|---|---|
d946d662 CB |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com> |
1f3d1fcc | 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 | |
8 | TEST_DESC="Tracefile count limits" | |
9 | ||
1f3d1fcc | 10 | CURDIR=$(dirname "$0")/ |
d946d662 CB |
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" | |
d7ee608c | 18 | NUM_TESTS=74 |
d40d4ff6 | 19 | |
1f3d1fcc | 20 | NUM_CPUS=$(nproc) |
3b0246b4 | 21 | PAGE_SIZE=$(getconf PAGE_SIZE) |
1f3d1fcc | 22 | TRACEFILE_SIZE=$PAGE_SIZE |
d946d662 | 23 | |
1f3d1fcc | 24 | source "$TESTDIR"/utils/utils.sh |
d946d662 CB |
25 | |
26 | if [ ! -x "$TESTAPP_BIN" ]; then | |
27 | BAIL_OUT "No UST events binary detected." | |
28 | fi | |
29 | ||
d946d662 CB |
30 | function enable_lttng_channel_count_limit () |
31 | { | |
32 | sess_name="$1" | |
33 | channel_name="$2" | |
34 | tracefile_count_limit="$3" | |
35 | ||
1f3d1fcc JG |
36 | test_name="Enable channel \`$channel_name\` " |
37 | test_name+="for session \`$sess_name\`: " | |
d946d662 CB |
38 | test_name+="$tracefile_count_limit tracefiles" |
39 | ||
1f3d1fcc JG |
40 | "$TESTDIR"/../src/bin/lttng/"$LTTNG_BIN" enable-channel \ |
41 | -u "$channel_name" -s "$sess_name" \ | |
42 | --subbuf-size "$PAGE_SIZE" \ | |
43 | --tracefile-size "$TRACEFILE_SIZE" \ | |
44 | --tracefile-count "$tracefile_count_limit" >/dev/null 2>&1 | |
d946d662 CB |
45 | |
46 | ok $? "$test_name" | |
47 | } | |
48 | ||
1f3d1fcc | 49 | function validate_min_max () |
d946d662 CB |
50 | { |
51 | stats="$1" | |
52 | field="$2" | |
53 | expected_min="$3" | |
54 | expected_max="$4" | |
55 | ||
56 | echo $stats | grep -q -E "$field $expected_min $expected_max" | |
57 | return $? | |
58 | } | |
59 | ||
1f3d1fcc | 60 | function get_total_stream_file_size () |
d946d662 | 61 | { |
1f3d1fcc JG |
62 | local trace_path="$1" |
63 | local stream_name_pattern="$2" | |
64 | local size | |
65 | ||
66 | size=$(find "$trace_path" -type f -regex "$stream_name_pattern" -exec du -b -c {} + | tail -n1 | cut -f 1) | |
67 | echo "$size" | |
d946d662 CB |
68 | } |
69 | ||
1f3d1fcc | 70 | function get_stream_file_count () |
d946d662 | 71 | { |
1f3d1fcc JG |
72 | local trace_path="$1" |
73 | local stream_name_pattern="$2" | |
74 | local count | |
d946d662 | 75 | |
1f3d1fcc JG |
76 | count=$(find "$trace_path" -type f -regex "$stream_name_pattern" | wc -l) |
77 | echo "$count" | |
78 | } | |
d946d662 | 79 | |
1f3d1fcc JG |
80 | function test_tracefile_count_limit () |
81 | { | |
82 | local count_limit="$1" | |
83 | ||
84 | local channel_name="channel" | |
85 | local cpuno=$((RANDOM % NUM_CPUS)) | |
86 | local event_name="tp:tptest" | |
87 | local expected_size=$((count_limit * TRACEFILE_SIZE)) | |
88 | local num_iter=100000 | |
89 | local previous_stream_size=-1 | |
90 | local session_name | |
91 | local stream_pattern=".*${channel_name}_${cpuno}_[0-9]*" | |
92 | local stream_size=0 | |
93 | local trace_path | |
d946d662 | 94 | |
1f3d1fcc JG |
95 | session_name=$(randstring 16 0) |
96 | trace_path=$(mktemp -d) | |
d946d662 | 97 | |
1f3d1fcc | 98 | diag "Test tracefile count limit : CPU $cpuno, $count_limit tracefiles, expecting a maximum of $expected_size bytes per CPU" |
d946d662 | 99 | |
1f3d1fcc | 100 | create_lttng_session_ok "$session_name" "$trace_path" |
d946d662 | 101 | |
1f3d1fcc JG |
102 | enable_lttng_channel_count_limit \ |
103 | "$session_name" "$channel_name" "$count_limit" | |
104 | ||
105 | enable_ust_lttng_event_ok \ | |
106 | "$session_name" "$event_name" "$channel_name" | |
107 | ||
108 | # Run the test app until the total stream size stops changing the | |
109 | # expected size is exceeded (error). | |
110 | # | |
111 | # The `$stream_size` will not stabilize until the trace file count | |
112 | # limit is reached. This is guaranteed by the use of start/produce/stop | |
113 | # cycles forcing the consumption of buffers, preventing unwanted stall | |
114 | # in stream size. | |
115 | while [ "$stream_size" -ne "$previous_stream_size" ]; do | |
116 | start_lttng_tracing_notap "$session_name" | |
117 | taskset -c "$cpuno" "$TESTAPP_BIN" -i "$num_iter" >/dev/null 2>&1 | |
118 | stop_lttng_tracing_notap "$session_name" | |
119 | ||
120 | previous_stream_size="$stream_size" | |
121 | stream_size=$(get_total_stream_file_size "$trace_path" "$stream_pattern") | |
122 | diag "Completed an iteration: previous size = $previous_stream_size bytes, new size = $stream_size bytes" | |
123 | ||
124 | if [ "$stream_size" -gt "$expected_size" ]; then | |
125 | diag "Total size for CPU $cpuno exceeds expected size: stream size = $stream_size bytes, expected size = $expected_size" | |
126 | break | |
127 | fi | |
128 | done | |
d946d662 | 129 | |
1f3d1fcc | 130 | destroy_lttng_session_ok "$session_name" |
d946d662 | 131 | |
1f3d1fcc JG |
132 | [ "$expected_size" -eq "$stream_size" ] |
133 | ok $? "Total stream size of CPU $cpuno is $expected_size" | |
d946d662 | 134 | |
1f3d1fcc JG |
135 | [ "$(get_stream_file_count "$trace_path" "$stream_pattern")" -eq "$count_limit" ] |
136 | ok $? "Stream meets the trace file limit of $count_limit" | |
d946d662 CB |
137 | |
138 | stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name` | |
139 | ||
140 | validate_min_max "$stats" "intfield" "[0-9]+" "$expected_max" | |
141 | ok $? "Trace validation - intfield" | |
142 | ||
143 | validate_min_max "$stats" "netintfield" "[0-9]+" "$expected_max" | |
144 | ok $? "Trace validation - netintfield" | |
145 | ||
146 | validate_min_max "$stats" "longfield" "[0-9]+" "$expected_max" | |
147 | ok $? "Trace validation - longfield" | |
148 | ||
1f3d1fcc | 149 | rm -rf "$trace_path" |
d946d662 CB |
150 | } |
151 | ||
d40d4ff6 CB |
152 | LIMITS=("1" "2" "4" "8" "10" "16" "32" "64") |
153 | ||
1f3d1fcc | 154 | plan_tests $NUM_TESTS |
d946d662 CB |
155 | |
156 | print_test_banner "$TEST_DESC" | |
157 | ||
158 | start_lttng_sessiond | |
159 | ||
1f3d1fcc | 160 | for limit in "${LIMITS[@]}"; |
d946d662 | 161 | do |
1f3d1fcc | 162 | test_tracefile_count_limit "$limit" |
d946d662 CB |
163 | done |
164 | ||
165 | stop_lttng_sessiond |