Refactor: test: wrapper for start_lttng_tracing
[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"
d7ee608c 28NUM_TESTS=74
d40d4ff6
CB
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
d946d662
CB
38function enable_lttng_channel_count_limit ()
39{
40 sess_name="$1"
41 channel_name="$2"
42 tracefile_count_limit="$3"
43
44 test_name="Enable channel $channel_name "
45 test_name+="for session $sess_name: "
46 test_name+="$tracefile_count_limit tracefiles"
47
48 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel \
49 -u $channel_name -s $sess_name \
50 -C 4096 -W $tracefile_count_limit \
51 --overwrite >/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 validate_min_max
73{
74 stats="$1"
75 field="$2"
76 expected_min="$3"
77 expected_max="$4"
78
79 echo $stats | grep -q -E "$field $expected_min $expected_max"
80 return $?
81}
82
83function validate_file_count
84{
85 path="$1"
86 file_pattern="$2"
87 expected_max_count="$3"
88
d3e2ba59 89 count=`find $path -name "$file_pattern" -type f \( ! -iname "*.idx" \) | wc -l`
d946d662
CB
90
91 if [ "$count" -gt "$expected_max_count" ]; then
92 fail "Validate file count: $file_pattern"
93 diag "File count: $count expected: $expected_max_count"
94 else
95 pass "Validate file count: $file_pattern"
96 fi
97}
98
99function test_tracefile_count_limit ()
100{
101 count_limit="$1"
102 trace_path=$(mktemp -d)
103 session_name=$(randstring 16 0)
104 channel_name="channel"
105 event_name="tp:tptest"
106 num_iter=1000
107 expected_max=$(($num_iter - 1))
108
109 diag "Test tracefile count limit : $count_limit tracefiles"
110
bf6ae429 111 create_lttng_session_ok $session_name $trace_path
d946d662
CB
112
113 enable_lttng_channel_count_limit \
114 $session_name $channel_name $count_limit
115
116 enable_ust_lttng_event_per_channel \
117 $session_name $event_name $channel_name
118
e563bbdb 119 start_lttng_tracing_ok $session_name
d946d662 120
d7ee608c 121 $TESTAPP_BIN $num_iter >/dev/null 2>&1
d946d662
CB
122
123 stop_lttng_tracing $session_name
124
125 destroy_lttng_session $session_name
126
127 # Validate tracing dir
128
d40d4ff6 129 for cpuno in $(seq 0 $(($NUM_CPUS - 1)))
d946d662
CB
130 do
131 validate_file_count \
132 $trace_path "${channel_name}_${cpuno}_*" $count_limit
133 done
134
135 # Validate tracing data
136
137 stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
138
139 validate_min_max "$stats" "intfield" "[0-9]+" "$expected_max"
140 ok $? "Trace validation - intfield"
141
142 validate_min_max "$stats" "netintfield" "[0-9]+" "$expected_max"
143 ok $? "Trace validation - netintfield"
144
145 validate_min_max "$stats" "longfield" "[0-9]+" "$expected_max"
146 ok $? "Trace validation - longfield"
147
148 rm -rf $trace_path
149}
150
d40d4ff6
CB
151LIMITS=("1" "2" "4" "8" "10" "16" "32" "64")
152
153# The file count validation depends on the number of streams (1 per cpu)
154TOTAL_TESTS=$(($NUM_TESTS + (${#LIMITS[@]} * $NUM_CPUS)))
155
156plan_tests $TOTAL_TESTS
d946d662
CB
157
158print_test_banner "$TEST_DESC"
159
160start_lttng_sessiond
161
d946d662
CB
162for limit in ${LIMITS[@]};
163do
164 test_tracefile_count_limit $limit
165done
166
167stop_lttng_sessiond
This page took 0.032761 seconds and 4 git commands to generate.