SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / tests / regression / tools / trigger / test_list_triggers_cli
CommitLineData
2463b787
JR
1#!/bin/bash
2#
3# Copyright (C) - 2020 EfficiOS, inc
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 the `lttng list-trigger` command line interface.
19
20CURDIR="$(dirname "$0")"
21TESTDIR="$CURDIR/../../.."
22
23# shellcheck source=../../../utils/utils.sh
24source "$TESTDIR/utils/utils.sh"
25
26plan_tests 44
27
28FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
29
30tmp_stdout=$(mktemp -t test_list_triggers_cli_stdout.XXXXXX)
31tmp_stderr=$(mktemp -t test_list_triggers_cli_stderr.XXXXXX)
32tmp_expected_stdout=$(mktemp -t test_list_triggers_cli_expected_stdout.XXXXXX)
33uprobe_elf_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary")
34
35uid=$(id --user)
36gid=$(id --group)
37
38if [ "$uid" == "0" ]; then
39 ist_root=1
40else
41 ist_root=0
42fi
43
44function add_trigger ()
45{
46 "${FULL_LTTNG_BIN}" add-trigger "$@"
47 ok $? "add trigger \`$*\`: exit code is 0"
48}
49
50function list_triggers ()
51{
52 local test_name="$1"
53 local expected_stdout_file="$2"
54
55 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
56 ok $? "${test_name}: exit code is 0"
57
58 diff -u "${expected_stdout_file}" "${tmp_stdout}"
59 ok $? "${test_name}: expected stdout"
60
61 diff -u /dev/null "${tmp_stderr}"
62 ok $? "${test_name}: expected stderr"
63}
64
65test_top_level_options ()
66{
67 # shellcheck disable=SC2119
68 start_lttng_sessiond_notap
69
70
71 add_trigger --id hello --condition on-event -u test-id --action notify
72 add_trigger --fire-once-after 123 --condition on-event -u test-fire-once-after --action notify
73 add_trigger --fire-every 124 --condition on-event -u test-fire-every --action notify
74
75 cat > "${tmp_expected_stdout}" <<- EOF
76 - id: T0
77 user id: ${uid}
78 firing policy: once after 123 occurences
79 tracer notifications discarded: 0
80 condition: event rule hit
81 rule: test-fire-once-after (type: tracepoint, domain: ust)
82 actions:
83 notify
84 - id: T1
85 user id: ${uid}
86 firing policy: after every 124 occurences
87 tracer notifications discarded: 0
88 condition: event rule hit
89 rule: test-fire-every (type: tracepoint, domain: ust)
90 actions:
91 notify
92 - id: hello
93 user id: ${uid}
94 tracer notifications discarded: 0
95 condition: event rule hit
96 rule: test-id (type: tracepoint, domain: ust)
97 actions:
98 notify
99 EOF
100
101 list_triggers "top level options" "${tmp_expected_stdout}"
102
103 stop_lttng_sessiond_notap
104}
105
106test_on_event_tracepoint ()
107{
108 # shellcheck disable=SC2119
109 start_lttng_sessiond_notap
110
111 add_trigger --condition on-event -u -a --action notify
112 add_trigger --id ABC --condition on-event aaa -u --filter 'p == 2' --action notify
113 add_trigger --condition on-event 'hello*' -u -x 'hello2,hello3,hello4' --action notify
114 add_trigger --id BCD --condition on-event -u gerboise --loglevel INFO --action notify
115 add_trigger --condition on-event -u lemming --loglevel-only WARNING --action notify
116 add_trigger --condition on-event -u capture-payload-field --capture a --action notify
117 add_trigger --condition on-event -u capture-array --capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
118 add_trigger --condition on-event -u capture-chan-ctx --capture '$ctx.vpid' --action notify
119 add_trigger --condition on-event -u capture-app-ctx --capture '$app.iga:active_clients' --action notify
120
121
122 cat > "${tmp_expected_stdout}" <<- EOF
123 - id: ABC
124 user id: ${uid}
125 tracer notifications discarded: 0
126 condition: event rule hit
127 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
128 actions:
129 notify
130 - id: BCD
131 user id: ${uid}
132 tracer notifications discarded: 0
133 condition: event rule hit
134 rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
135 actions:
136 notify
137 - id: T0
138 user id: ${uid}
139 tracer notifications discarded: 0
140 condition: event rule hit
141 rule: * (type: tracepoint, domain: ust)
142 actions:
143 notify
144 - id: T1
145 user id: ${uid}
146 tracer notifications discarded: 0
147 condition: event rule hit
148 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
149 actions:
150 notify
151 - id: T2
152 user id: ${uid}
153 tracer notifications discarded: 0
154 condition: event rule hit
155 rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
156 actions:
157 notify
158 - id: T3
159 user id: ${uid}
160 tracer notifications discarded: 0
161 condition: event rule hit
162 rule: capture-payload-field (type: tracepoint, domain: ust)
163 captures:
164 - a
165 actions:
166 notify
167 - id: T4
168 user id: ${uid}
169 tracer notifications discarded: 0
170 condition: event rule hit
171 rule: capture-array (type: tracepoint, domain: ust)
172 captures:
173 - a[2]
174 - \$ctx.tourlou[18]
175 actions:
176 notify
177 - id: T5
178 user id: ${uid}
179 tracer notifications discarded: 0
180 condition: event rule hit
181 rule: capture-chan-ctx (type: tracepoint, domain: ust)
182 captures:
183 - \$ctx.vpid
184 actions:
185 notify
186 - id: T6
187 user id: ${uid}
188 tracer notifications discarded: 0
189 condition: event rule hit
190 rule: capture-app-ctx (type: tracepoint, domain: ust)
191 captures:
192 - \$app.iga:active_clients
193 actions:
194 notify
195 EOF
196
197 list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"
198
199 stop_lttng_sessiond_notap
200}
201
202test_on_event_probe ()
203{
204 local channel_enable_addr
205 local channel_disable_addr
206
207 # shellcheck disable=SC2119
208 start_lttng_sessiond_notap
209
210 channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
211 channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
212
213 # We need to find a valid offset.
214 base_symbol=""
215 offset=0
216 if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
217 base_symbol="lttng_channel_enable"
218 offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
219 else
220 base_symbol="lttng_channel_disable"
221 offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
222 fi
223
224 offset_hex="0x$(printf '%x' $offset)"
225
226 add_trigger --condition on-event -k --probe=lttng_channel_enable my_channel_enable --action notify
227 add_trigger --condition on-event -k --probe="${base_symbol}+${offset_hex}" my_channel_enable --action notify
228 add_trigger --condition on-event -k --probe="0x${channel_enable_addr}" my_channel_enable --action notify
229
230 cat > "${tmp_expected_stdout}" <<- EOF
231 - id: T0
232 user id: ${uid}
233 tracer notifications discarded: 0
234 condition: event rule hit
235 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
236 actions:
237 notify
238 - id: T1
239 user id: ${uid}
240 tracer notifications discarded: 0
241 condition: event rule hit
242 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
243 actions:
244 notify
245 - id: T2
246 user id: ${uid}
247 tracer notifications discarded: 0
248 condition: event rule hit
249 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
250 actions:
251 notify
252 EOF
253
254 list_triggers "on-event, probe event rule" "${tmp_expected_stdout}"
255
256 stop_lttng_sessiond_notap
257}
258
259test_on_event_userspace_probe ()
260{
261 # shellcheck disable=SC2119
262 start_lttng_sessiond_notap
263
264 add_trigger --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify
265
266 cat > "${tmp_expected_stdout}" <<- EOF
267 - id: T0
268 user id: ${uid}
269 tracer notifications discarded: 0
270 condition: event rule hit
271 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
272 actions:
273 notify
274 EOF
275
276 list_triggers "on-event, userspace-probe event rule" "${tmp_expected_stdout}"
277
278 stop_lttng_sessiond_notap
279}
280
281test_on_event_syscall ()
282{
283 # shellcheck disable=SC2119
284 start_lttng_sessiond_notap
285
286 add_trigger --condition on-event -k --syscall open --action notify
287 add_trigger --condition on-event -k --syscall ptrace --filter 'a > 2' --action notify
288
289 cat > "${tmp_expected_stdout}" <<- EOF
290 - id: T0
291 user id: ${uid}
292 tracer notifications discarded: 0
293 condition: event rule hit
294 - rule: open (type: syscall)
295 actions:
296 notify
297 - id: T1
298 user id: ${uid}
299 tracer notifications discarded: 0
300 condition: event rule hit
301 - rule: ptrace (type: syscall, filter: a > 2)
302 actions:
303 notify
304 EOF
305
306 list_triggers "on-event, syscall event rule" "${tmp_expected_stdout}"
307
308 stop_lttng_sessiond_notap
309}
310
311test_snapshot_action ()
312{
313 start_lttng_sessiond_notap
314
315 add_trigger --condition on-event -u some-event --action snapshot-session ze-session
316 add_trigger --condition on-event -u some-event --action snapshot-session ze-session /some/path
317 add_trigger --condition on-event -u some-event --action snapshot-session ze-session file:///some/other/path
318 add_trigger --condition on-event -u some-event --action snapshot-session ze-session net://1.2.3.4
319 add_trigger --condition on-event -u some-event --action snapshot-session ze-session net://1.2.3.4:1234:1235
320 add_trigger --condition on-event -u some-event --action snapshot-session ze-session --ctrl-url=tcp://1.2.3.4:1111 --data-url=tcp://1.2.3.4:1112
321 add_trigger --condition on-event -u some-event --action snapshot-session ze-session /some/path --max-size=1234
322 add_trigger --condition on-event -u some-event --action snapshot-session ze-session /some/path --name=meh
323
324
325 cat > "${tmp_expected_stdout}" <<- EOF
326 - id: T0
327 user id: ${uid}
328 tracer notifications discarded: 0
329 condition: event rule hit
330 rule: some-event (type: tracepoint, domain: ust)
331 actions:
332 snapshot session \`ze-session\`
333 - id: T1
334 user id: ${uid}
335 tracer notifications discarded: 0
336 condition: event rule hit
337 rule: some-event (type: tracepoint, domain: ust)
338 actions:
339 snapshot session \`ze-session\`, path: /some/path
340 - id: T2
341 user id: ${uid}
342 tracer notifications discarded: 0
343 condition: event rule hit
344 rule: some-event (type: tracepoint, domain: ust)
345 actions:
346 snapshot session \`ze-session\`, path: /some/other/path
347 - id: T3
348 user id: ${uid}
349 tracer notifications discarded: 0
350 condition: event rule hit
351 rule: some-event (type: tracepoint, domain: ust)
352 actions:
353 snapshot session \`ze-session\`, url: net://1.2.3.4
354 - id: T4
355 user id: ${uid}
356 tracer notifications discarded: 0
357 condition: event rule hit
358 rule: some-event (type: tracepoint, domain: ust)
359 actions:
360 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
361 - id: T5
362 user id: ${uid}
363 tracer notifications discarded: 0
364 condition: event rule hit
365 rule: some-event (type: tracepoint, domain: ust)
366 actions:
367 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
368 - id: T6
369 user id: ${uid}
370 tracer notifications discarded: 0
371 condition: event rule hit
372 rule: some-event (type: tracepoint, domain: ust)
373 actions:
374 snapshot session \`ze-session\`, path: /some/path, max size: 1234
375 - id: T7
376 user id: ${uid}
377 tracer notifications discarded: 0
378 condition: event rule hit
379 rule: some-event (type: tracepoint, domain: ust)
380 actions:
381 snapshot session \`ze-session\`, path: /some/path, name: meh
382 EOF
383
384 list_triggers "snapshot action" "${tmp_expected_stdout}"
385
386 stop_lttng_sessiond_notap
387}
388
389test_top_level_options
390test_on_event_tracepoint
391skip $ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
392skip $ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
393skip $ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
394test_snapshot_action
395
396# Cleanup
397rm -f "${tmp_stdout}"
398rm -f "${tmp_stderr}"
399rm -f "${tmp_expected_stdout}"
This page took 0.038659 seconds and 5 git commands to generate.