Tests: Add the tracefile size test
[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
25TESTAPP_PATH="$TESTDIR/utils/testapp"
26TESTAPP_NAME="gen-ust-events"
27TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
28
29NUM_TESTS=47
30
31source $TESTDIR/utils/utils.sh
32
33if [ ! -x "$TESTAPP_BIN" ]; then
34 BAIL_OUT "No UST events binary detected."
35fi
36
37function wait_apps
38{
39 while [ -n "$(pidof $TESTAPP_NAME)" ]; do
40 sleep 0.5
41 done
42 pass "Wait for applications to end"
43}
44
45function enable_lttng_channel_size_limit ()
46{
47 sess_name="$1"
48 channel_name="$2"
49 tracefile_size_limit="$3"
50
51 test_name="Enable channel $channel_name "
52 test_name+="for session $sess_name: "
53 test_name+="$tracefile_size_limit bytes tracefile limit"
54
55 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel \
56 -u $channel_name -s $sess_name \
57 -C $tracefile_size_limit >/dev/null 2>&1
58
59 ok $? "$test_name"
60}
61
62function enable_ust_lttng_event_per_channel ()
63{
64 sess_name="$1"
65 event_name="$2"
66 channel_name="$3"
67
68 test_name="Enable event $event_name "
69 test_name+="for session $sess_name "
70 test_name+="in channel $channel_name"
71
72 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" \
73 -s $sess_name -u -c $channel_name >/dev/null 2>&1
74
75 ok $? "$test_name"
76}
77
78function check_file_size ()
79{
80 path="$1"
81 file_pattern="$2"
82 expected_max_size="$3"
83
84 find $path -name "$file_pattern" -exec stat -c '%n %s' {} \; \
85 | while read file_info;
86 do
87 name=$(echo $file_info | cut -f1 -d ' ')
88 size=$(echo $file_info | cut -f2 -d ' ')
89
90 if [ "$size" -gt "$expected_max_size" ]; then
91 diag_msg="file: $name size: $size"
92 diag_msg+="expected maximum size: $expected_max_size"
93 diag "$diag_msg"
94 exit 1
95 fi
96 done
97
98 ok $? "File size validation"
99}
100
101function test_tracefile_size_limit ()
102{
103 size_limit="$1"
104 trace_path=$(mktemp -d)
105 session_name=$(randstring 16 0)
106 channel_name="channel"
107 event_name="tp:tptest"
108
109 diag "Test tracefile size limit : $size_limit bytes"
110
111 create_lttng_session $session_name $trace_path
112
113 enable_lttng_channel_size_limit \
114 $session_name $channel_name $size_limit
115
116 enable_ust_lttng_event_per_channel \
117 $session_name $event_name $channel_name
118
119 start_lttng_tracing $session_name
120
121 $TESTAPP_BIN $NR_ITER >/dev/null 2>&1 &
122
123 wait_apps
124
125 stop_lttng_tracing $session_name
126
127 destroy_lttng_session $session_name
128
129 # Validate file size, each one shall be no larger than the
130 # specified size limit
131
132 check_file_size $trace_path "${channel_name}_*" $size_limit
133
134 # Validate tracing data, we should at least have some events
135
136 validate_trace $event_name $trace_path
137
138 rm -rf $trace_path
139}
140
141plan_tests $NUM_TESTS
142
143print_test_banner "$TEST_DESC"
144
145start_lttng_sessiond
146
147LIMITS=("4096" "8192" "16384" "32768" "65536")
148
149for limit in ${LIMITS[@]};
150do
151 test_tracefile_size_limit $limit
152done
153
154stop_lttng_sessiond
This page took 0.042775 seconds and 5 git commands to generate.