809490c097500fcac471c831c76a516e7e8cc6b1
[lttng-tools.git] / tests / regression / tools / tracefile-limits / test_tracefile_size
1 #!/bin/bash
2 #
3 # Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
4 #
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18 TEST_DESC="Tracefile size limits"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../..
22
23 NR_ITER=1000
24
25 PAGE_SIZE=$(getconf PAGE_SIZE)
26
27 TESTAPP_PATH="$TESTDIR/utils/testapp"
28 TESTAPP_NAME="gen-ust-events"
29 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
30
31 NUM_TESTS=58
32
33 source $TESTDIR/utils/utils.sh
34
35 if [ ! -x "$TESTAPP_BIN" ]; then
36 BAIL_OUT "No UST events binary detected."
37 fi
38
39 function enable_lttng_channel_size_limit ()
40 {
41 sess_name="$1"
42 channel_name="$2"
43 tracefile_size_limit="$3"
44
45 test_name="Enable channel $channel_name "
46 test_name+="for session $sess_name: "
47 test_name+="$tracefile_size_limit bytes tracefile limit"
48
49 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel \
50 -u $channel_name -s $sess_name --buffers-pid \
51 -C $tracefile_size_limit >/dev/null 2>&1
52
53 ok $? "$test_name"
54 }
55
56 function enable_ust_lttng_event_per_channel ()
57 {
58 sess_name="$1"
59 event_name="$2"
60 channel_name="$3"
61
62 test_name="Enable event $event_name "
63 test_name+="for session $sess_name "
64 test_name+="in channel $channel_name"
65
66 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" \
67 -s $sess_name -u -c $channel_name >/dev/null 2>&1
68
69 ok $? "$test_name"
70 }
71
72 function check_file_size ()
73 {
74 path="$1"
75 file_pattern="$2"
76 expected_max_size="$3"
77
78 find $path -name "$file_pattern" -exec stat -c '%n %s' {} \; \
79 | while read file_info;
80 do
81 name=$(echo $file_info | cut -f1 -d ' ')
82 size=$(echo $file_info | cut -f2 -d ' ')
83
84 if [ "$size" -gt "$expected_max_size" ]; then
85 diag_msg="file: $name size: $size"
86 diag_msg+="expected maximum size: $expected_max_size"
87 diag "$diag_msg"
88 exit 1
89 fi
90 done
91
92 ok $? "File size validation"
93 }
94
95 function test_tracefile_size_limit ()
96 {
97 size_limit="$1"
98 trace_path=$(mktemp -d)
99 session_name=$(randstring 16 0)
100 channel_name="channel"
101 event_name="tp:tptest"
102
103 diag "Test tracefile size limit : $size_limit bytes"
104
105 create_lttng_session_ok $session_name $trace_path
106
107 enable_lttng_channel_size_limit \
108 $session_name $channel_name $size_limit
109
110 enable_ust_lttng_event_per_channel \
111 $session_name $event_name $channel_name
112
113 start_lttng_tracing_ok $session_name
114
115 $TESTAPP_BIN $NR_ITER >/dev/null 2>&1
116
117 stop_lttng_tracing_ok $session_name
118
119 destroy_lttng_session_ok $session_name
120
121 # Validate file size, each one shall be no larger than the
122 # specified size limit
123
124 check_file_size $trace_path "${channel_name}_*" $size_limit
125
126 # Validate tracing data, we should at least have some events
127
128 validate_trace $event_name $trace_path
129
130 rm -rf $trace_path
131 }
132
133 function test_tracefile_size_limit_pagesize ()
134 {
135 # Set a size limit lower than the page_size
136 size_limit="$(($PAGE_SIZE-2))"
137 trace_path=$(mktemp -d)
138 session_name=$(randstring 16 0)
139 channel_name="channel"
140 event_name="tp:tptest"
141
142 diag "Test tracefile size limit lower than PAGE_SIZE : $size_limit bytes"
143
144 create_lttng_session_ok $session_name $trace_path
145
146 enable_lttng_channel_size_limit \
147 $session_name $channel_name $size_limit
148
149 enable_ust_lttng_event_per_channel \
150 $session_name $event_name $channel_name
151
152 start_lttng_tracing_ok $session_name
153
154 $TESTAPP_BIN $NR_ITER >/dev/null 2>&1
155
156 stop_lttng_tracing_ok $session_name
157
158 destroy_lttng_session_ok $session_name
159
160 # Validate file size, expect file size to be equal to the page size
161
162 check_file_size $trace_path "${channel_name}_*" $PAGE_SIZE
163
164 # Validate tracing data, we should at least have some events
165
166 validate_trace $event_name $trace_path
167
168 rm -rf $trace_path
169 }
170
171 plan_tests $NUM_TESTS
172
173 print_test_banner "$TEST_DESC"
174
175 start_lttng_sessiond
176
177 # Test with multiples of PAGE_SIZE
178 LIMITS=("$(($PAGE_SIZE))"
179 "$(($PAGE_SIZE*2))"
180 "$(($PAGE_SIZE*4))"
181 "$(($PAGE_SIZE*8))"
182 "$(($PAGE_SIZE*16))"
183 "$(($PAGE_SIZE*32))")
184
185 for limit in ${LIMITS[@]};
186 do
187 test_tracefile_size_limit $limit
188 done
189
190 # Test with a value that is not a multiple of PAGE_SIZE
191 test_tracefile_size_limit "$(($PAGE_SIZE+1024))"
192
193 # Test that a value lower than the PAGE_SIZE is rounded to it
194 test_tracefile_size_limit_pagesize
195
196 stop_lttng_sessiond
This page took 0.03459 seconds and 4 git commands to generate.