Tests: getcpu: no events shall be emitted at the same timestamp
[lttng-tools.git] / tests / regression / ust / getcpu-override / test_getcpu_override
CommitLineData
568d7e2d
JR
1#!/bin/bash
2#
3# Copyright (C) - 2015 Jonathan Rajotte <jonathan.rajotte-julien@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
17TEST_DESC="UST - Getcpu override plugin"
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../../..
21SESSION_NAME="sequence-cpu"
22
23TESTAPP_PATH="$TESTDIR/utils/testapp"
24TESTAPP_NAME="gen-ust-events"
25TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
26TESTAPP_WRAPPER="run-getcpu-override"
27NUM_EVENT=256
28EVENT_NAME="tp:tptest"
29
30NUM_TESTS=20
31
32SEQUENCE_SEED=(
33100 57 232 236 42 193 224 184 216 150 92 91 108 118 55 243 65 101 209 0 147 36
3429 34 49 188 174 105 253 245 227 238 112 20 222 201 102 175 119 19 132 41 78 90
35114 64 138 14 48 18 162 85 204 124 133 73 172 106 241 126 28 104 111 21 127 219
369 244 237 189 59 214 52 141 107 26 25 199 3 157 117 234 33 44 46 84 69 155 122
37250 231 86 239 76 190 120 1 94 206 8 148 159 167 215 164 31 217 61 71 125 68 109
38195 177 95 82 142 182 129 87 37 140 134 186 173 39 116 143 254 229 131 67 121
39192 240 15 221 30 242 185 80 170 135 51 187 194 246 12 225 181 137 211 228 88
40218 27 233 161 77 252 123 93 220 248 205 223 144 128 196 70 247 210 178 203 154
4124 169 149 163 35 7 151 103 197 139 165 158 207 72 113 145 45 183 11 198 43 81
42230 97 96 2 66 213 146 179 22 58 54 38 160 200 235 226 156 56 208 249 32 176 168
43110 191 79 152 115 10 74 60 251 17 83 180 171 202 40 166 255 53 212 98 5 50 99 4
4489 13 63 6 136 153 23 16 47 130 75 62
45)
46
47# Equivalent to the syconf(_SC_NPROCESSORS_CONF) call.
48NPROC=`nproc --all`
49
50source $TESTDIR/utils/utils.sh
51
52if [ ! -x "$CURDIR/.libs/lttng-ust-getcpu-override-test.so" ]; then
53 BAIL_OUT "No shared object generated"
54fi
55
56# MUST set TESTDIR before calling those functions
57
58run_app()
59{
60 diag "Launching app without getcpu-plugin wrapper"
46ed3fd7 61 $TESTAPP_BIN $NUM_EVENT 1
568d7e2d
JR
62 ok $? "Application without wrapper done"
63}
64
65run_getcpu_plugin_app()
66{
67 diag "Launching app with getcpu-plugin wrapper"
68 $CURDIR/$TESTAPP_WRAPPER $TESTAPP_BIN $NUM_EVENT
69 ok $? "Application with wrapper done"
70}
71
72compare_ok()
73{
74 compare 0 "$@"
75}
76
77compare_fail()
78{
79 compare 1 "$@"
80}
81
82compare()
83{
84 local expected_to_fail=$1
85 declare -a array_to_compare=("${!2}")
86 local valid=0
87
88 test ${#array_to_compare[*]} -eq ${#SEQUENCE_SEED[*]}
0a44ce80 89 ok $? "Sequence seed and cpuid sequence have the same size ${#SEQUENCE_SEED[*]}/${#array_to_compare[*]}"
568d7e2d
JR
90
91 for (( i = 0; i < ${#SEQUENCE_SEED[*]}; i++ )); do
92 if [ "${array_to_compare[$i]}" -ne "$(( ${SEQUENCE_SEED[$i]} % $NPROC))" ]; then
93 valid=1
94 break
95 fi
96 done
97
98 if [[ $expected_to_fail -eq "1" ]]; then
99 test $valid -ne "0"
0a44ce80 100 ok $? "Cpuid extraction and seed sequence comparison fails as expected"
568d7e2d
JR
101 else
102 ok $valid "Cpuid extraction and seed sequence comparison"
0a44ce80
JG
103 if [[ $valid -ne "0" ]]; then
104 diag "Dumping arrays after failed comparison"
105 for (( i = 0; i < ${#SEQUENCE_SEED[*]}; i++ )); do
106 echo -n "# array value is "
107 echo -n "${array_to_compare[$i]}"
108 echo -n " expected "
109 echo "$(( ${SEQUENCE_SEED[$i]} % $NPROC))"
110 done
111 diag "Dumping trace"
112 $BABELTRACE_BIN $TRACE_PATH | awk '{print "# " $0}'
113 fi
568d7e2d
JR
114 fi
115}
116
0a44ce80 117test_getcpu_override_fail()
568d7e2d 118{
0a44ce80 119 diag "Getcpu plugin - no preloaded plugin"
568d7e2d
JR
120
121 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
122 enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
123 start_lttng_tracing_ok $SESSION_NAME
124 run_app
125 stop_lttng_tracing_ok $SESSION_NAME
126 destroy_lttng_session_ok $SESSION_NAME
127
128 # Move output to an array by using =($())
0a44ce80
JG
129 local cpuid_events=($($BABELTRACE_BIN $TRACE_PATH | sed -n 's/.*cpu_id = \([0-9]*\).*/\1/p'))
130 local num_events=${#cpuid_events[*]}
568d7e2d
JR
131 test $num_events -eq $NUM_EVENT
132 ok $? "Extraction without getcpu plugin have $num_events/$NUM_EVENT"
133 compare_fail cpuid_events[@]
134
0a44ce80
JG
135 return $?
136}
137
138test_getcpu_override()
139{
140 diag "Getcpu plugin - with plugin preloaded"
141
568d7e2d
JR
142 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
143 enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
144 start_lttng_tracing_ok $SESSION_NAME
145 run_getcpu_plugin_app
146 stop_lttng_tracing_ok $SESSION_NAME
147 destroy_lttng_session_ok $SESSION_NAME
148
0a44ce80
JG
149 local cpuid_events=($($BABELTRACE_BIN $TRACE_PATH | sed -n 's/.*cpu_id = \([0-9]*\).*/\1/p'))
150 local num_events=${#cpuid_events[*]}
568d7e2d 151 test $num_events -eq $NUM_EVENT
0a44ce80 152 ok $? "Extraction with getcpu plugin have $num_events/$NUM_EVENT"
568d7e2d
JR
153
154 compare_ok cpuid_events[@]
155
156 return $?
157}
158
159plan_tests $NUM_TESTS
160
161print_test_banner "$TEST_DESC"
162
163TESTS=(
0a44ce80
JG
164 test_getcpu_override_fail
165 test_getcpu_override
568d7e2d
JR
166)
167
168TEST_COUNT=${#TESTS[@]}
169i=0
170
171start_lttng_sessiond
172
0a44ce80
JG
173for fct_test in ${TESTS[@]};
174do
568d7e2d
JR
175 TRACE_PATH=$(mktemp -d)
176
0a44ce80
JG
177 ${fct_test}
178 if [ $? -ne 0 ]; then
179 break;
180 fi
568d7e2d
JR
181
182 rm -rf $TRACE_PATH
568d7e2d
JR
183done
184
185stop_lttng_sessiond
This page took 0.033037 seconds and 5 git commands to generate.