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