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