Fix: There is more tests than the plan
[lttng-tools.git] / tests / regression / tools / tracefile-limits / test_tracefile_size
CommitLineData
34497a63
CB
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
18TEST_DESC="Tracefile size limits"
19
20CURDIR=$(dirname $0)/
21TESTDIR=$CURDIR/../../..
22
23NR_ITER=1000
24
034a7848
MJ
25PAGE_SIZE=$(getconf PAGE_SIZE)
26
34497a63
CB
27TESTAPP_PATH="$TESTDIR/utils/testapp"
28TESTAPP_NAME="gen-ust-events"
29TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
30
ea263060 31NUM_TESTS=66
34497a63
CB
32
33source $TESTDIR/utils/utils.sh
34
35if [ ! -x "$TESTAPP_BIN" ]; then
36 BAIL_OUT "No UST events binary detected."
37fi
38
34497a63
CB
39function 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 \
c1b8e6f8 50 -u $channel_name -s $sess_name --buffers-pid \
34497a63
CB
51 -C $tracefile_size_limit >/dev/null 2>&1
52
53 ok $? "$test_name"
54}
55
56function 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
72function 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
95function 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
bf6ae429 105 create_lttng_session_ok $session_name $trace_path
34497a63
CB
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
e563bbdb 113 start_lttng_tracing_ok $session_name
34497a63 114
d7ee608c 115 $TESTAPP_BIN $NR_ITER >/dev/null 2>&1
34497a63 116
96340a01 117 stop_lttng_tracing_ok $session_name
34497a63 118
67b4c664 119 destroy_lttng_session_ok $session_name
34497a63
CB
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
034a7848
MJ
133function 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
34497a63
CB
171plan_tests $NUM_TESTS
172
173print_test_banner "$TEST_DESC"
174
175start_lttng_sessiond
176
034a7848
MJ
177# Test with multiples of PAGE_SIZE
178LIMITS=("$(($PAGE_SIZE))"
179 "$(($PAGE_SIZE*2))"
180 "$(($PAGE_SIZE*4))"
181 "$(($PAGE_SIZE*8))"
182 "$(($PAGE_SIZE*16))"
183 "$(($PAGE_SIZE*32))")
34497a63
CB
184
185for limit in ${LIMITS[@]};
186do
187 test_tracefile_size_limit $limit
188done
189
034a7848
MJ
190# Test with a value that is not a multiple of PAGE_SIZE
191test_tracefile_size_limit "$(($PAGE_SIZE+1024))"
192
193# Test that a value lower than the PAGE_SIZE is rounded to it
194test_tracefile_size_limit_pagesize
195
34497a63 196stop_lttng_sessiond
This page took 0.052578 seconds and 4 git commands to generate.