Commit | Line | Data |
---|---|---|
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 | ||
18 | TEST_DESC="Tracefile count limits" | |
19 | ||
20 | CURDIR=$(dirname $0)/ | |
21 | TESTDIR=$CURDIR/../../.. | |
22 | ||
23 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
24 | TESTAPP_NAME="gen-ust-events" | |
25 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
26 | ||
27 | STATS_BIN="$TESTDIR/utils/babelstats.pl" | |
28 | NUM_TESTS=146 | |
29 | ||
30 | source $TESTDIR/utils/utils.sh | |
31 | ||
32 | if [ ! -x "$TESTAPP_BIN" ]; then | |
33 | BAIL_OUT "No UST events binary detected." | |
34 | fi | |
35 | ||
36 | function wait_apps | |
37 | { | |
38 | while [ -n "$(pidof $TESTAPP_NAME)" ]; do | |
39 | sleep 0.5 | |
40 | done | |
41 | pass "Wait for applications to end" | |
42 | } | |
43 | ||
44 | function enable_lttng_channel_count_limit () | |
45 | { | |
46 | sess_name="$1" | |
47 | channel_name="$2" | |
48 | tracefile_count_limit="$3" | |
49 | ||
50 | test_name="Enable channel $channel_name " | |
51 | test_name+="for session $sess_name: " | |
52 | test_name+="$tracefile_count_limit tracefiles" | |
53 | ||
54 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel \ | |
55 | -u $channel_name -s $sess_name \ | |
56 | -C 4096 -W $tracefile_count_limit \ | |
57 | --overwrite >/dev/null 2>&1 | |
58 | ||
59 | ok $? "$test_name" | |
60 | } | |
61 | ||
62 | function 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 | ||
78 | function validate_min_max | |
79 | { | |
80 | stats="$1" | |
81 | field="$2" | |
82 | expected_min="$3" | |
83 | expected_max="$4" | |
84 | ||
85 | echo $stats | grep -q -E "$field $expected_min $expected_max" | |
86 | return $? | |
87 | } | |
88 | ||
89 | function validate_file_count | |
90 | { | |
91 | path="$1" | |
92 | file_pattern="$2" | |
93 | expected_max_count="$3" | |
94 | ||
95 | count=`find $path -name "$file_pattern" -type f | wc -l` | |
96 | ||
97 | if [ "$count" -gt "$expected_max_count" ]; then | |
98 | fail "Validate file count: $file_pattern" | |
99 | diag "File count: $count expected: $expected_max_count" | |
100 | else | |
101 | pass "Validate file count: $file_pattern" | |
102 | fi | |
103 | } | |
104 | ||
105 | function test_tracefile_count_limit () | |
106 | { | |
107 | count_limit="$1" | |
108 | trace_path=$(mktemp -d) | |
109 | session_name=$(randstring 16 0) | |
110 | channel_name="channel" | |
111 | event_name="tp:tptest" | |
112 | num_iter=1000 | |
113 | expected_max=$(($num_iter - 1)) | |
114 | ||
115 | diag "Test tracefile count limit : $count_limit tracefiles" | |
116 | ||
117 | create_lttng_session $session_name $trace_path | |
118 | ||
119 | enable_lttng_channel_count_limit \ | |
120 | $session_name $channel_name $count_limit | |
121 | ||
122 | enable_ust_lttng_event_per_channel \ | |
123 | $session_name $event_name $channel_name | |
124 | ||
125 | start_lttng_tracing $session_name | |
126 | ||
127 | $TESTAPP_BIN $num_iter >/dev/null 2>&1 & | |
128 | ||
129 | wait_apps | |
130 | ||
131 | stop_lttng_tracing $session_name | |
132 | ||
133 | destroy_lttng_session $session_name | |
134 | ||
135 | # Validate tracing dir | |
136 | ||
137 | num_cpu=`nproc` | |
138 | ||
139 | for cpuno in $(seq 0 $(($num_cpu - 1))) | |
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 | ||
161 | plan_tests $NUM_TESTS | |
162 | ||
163 | print_test_banner "$TEST_DESC" | |
164 | ||
165 | start_lttng_sessiond | |
166 | ||
167 | LIMITS=("1" "2" "4" "8" "10" "16" "32" "64") | |
168 | ||
169 | for limit in ${LIMITS[@]}; | |
170 | do | |
171 | test_tracefile_count_limit $limit | |
172 | done | |
173 | ||
174 | stop_lttng_sessiond |