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