Tests: Fix the number of tests in test_tracefile_count
[lttng-tools.git] / tests / regression / tools / tracefile-limits / test_tracefile_count
CommitLineData
d946d662
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 count limits"
19
20CURDIR=$(dirname $0)/
21TESTDIR=$CURDIR/../../..
22
23TESTAPP_PATH="$TESTDIR/utils/testapp"
24TESTAPP_NAME="gen-ust-events"
25TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
26
27STATS_BIN="$TESTDIR/utils/babelstats.pl"
d40d4ff6
CB
28NUM_TESTS=82
29
30NUM_CPUS=`nproc`
d946d662
CB
31
32source $TESTDIR/utils/utils.sh
33
34if [ ! -x "$TESTAPP_BIN" ]; then
35 BAIL_OUT "No UST events binary detected."
36fi
37
38function wait_apps
39{
40 while [ -n "$(pidof $TESTAPP_NAME)" ]; do
41 sleep 0.5
42 done
43 pass "Wait for applications to end"
44}
45
46function enable_lttng_channel_count_limit ()
47{
48 sess_name="$1"
49 channel_name="$2"
50 tracefile_count_limit="$3"
51
52 test_name="Enable channel $channel_name "
53 test_name+="for session $sess_name: "
54 test_name+="$tracefile_count_limit tracefiles"
55
56 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel \
57 -u $channel_name -s $sess_name \
58 -C 4096 -W $tracefile_count_limit \
59 --overwrite >/dev/null 2>&1
60
61 ok $? "$test_name"
62}
63
64function enable_ust_lttng_event_per_channel ()
65{
66 sess_name="$1"
67 event_name="$2"
68 channel_name="$3"
69
70 test_name="Enable event $event_name "
71 test_name+="for session $sess_name "
72 test_name+="in channel $channel_name"
73
74 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" \
75 -s $sess_name -u -c $channel_name >/dev/null 2>&1
76
77 ok $? "$test_name"
78}
79
80function validate_min_max
81{
82 stats="$1"
83 field="$2"
84 expected_min="$3"
85 expected_max="$4"
86
87 echo $stats | grep -q -E "$field $expected_min $expected_max"
88 return $?
89}
90
91function validate_file_count
92{
93 path="$1"
94 file_pattern="$2"
95 expected_max_count="$3"
96
97 count=`find $path -name "$file_pattern" -type f | wc -l`
98
99 if [ "$count" -gt "$expected_max_count" ]; then
100 fail "Validate file count: $file_pattern"
101 diag "File count: $count expected: $expected_max_count"
102 else
103 pass "Validate file count: $file_pattern"
104 fi
105}
106
107function test_tracefile_count_limit ()
108{
109 count_limit="$1"
110 trace_path=$(mktemp -d)
111 session_name=$(randstring 16 0)
112 channel_name="channel"
113 event_name="tp:tptest"
114 num_iter=1000
115 expected_max=$(($num_iter - 1))
116
117 diag "Test tracefile count limit : $count_limit tracefiles"
118
119 create_lttng_session $session_name $trace_path
120
121 enable_lttng_channel_count_limit \
122 $session_name $channel_name $count_limit
123
124 enable_ust_lttng_event_per_channel \
125 $session_name $event_name $channel_name
126
127 start_lttng_tracing $session_name
128
129 $TESTAPP_BIN $num_iter >/dev/null 2>&1 &
130
131 wait_apps
132
133 stop_lttng_tracing $session_name
134
135 destroy_lttng_session $session_name
136
137 # Validate tracing dir
138
d40d4ff6 139 for cpuno in $(seq 0 $(($NUM_CPUS - 1)))
d946d662
CB
140 do
141 validate_file_count \
142 $trace_path "${channel_name}_${cpuno}_*" $count_limit
143 done
144
145 # Validate tracing data
146
147 stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
148
149 validate_min_max "$stats" "intfield" "[0-9]+" "$expected_max"
150 ok $? "Trace validation - intfield"
151
152 validate_min_max "$stats" "netintfield" "[0-9]+" "$expected_max"
153 ok $? "Trace validation - netintfield"
154
155 validate_min_max "$stats" "longfield" "[0-9]+" "$expected_max"
156 ok $? "Trace validation - longfield"
157
158 rm -rf $trace_path
159}
160
d40d4ff6
CB
161LIMITS=("1" "2" "4" "8" "10" "16" "32" "64")
162
163# The file count validation depends on the number of streams (1 per cpu)
164TOTAL_TESTS=$(($NUM_TESTS + (${#LIMITS[@]} * $NUM_CPUS)))
165
166plan_tests $TOTAL_TESTS
d946d662
CB
167
168print_test_banner "$TEST_DESC"
169
170start_lttng_sessiond
171
d946d662
CB
172for limit in ${LIMITS[@]};
173do
174 test_tracefile_count_limit $limit
175done
176
177stop_lttng_sessiond
This page took 0.029032 seconds and 4 git commands to generate.