Fix: on-event condition: don't abort() on invalid event expression type
[lttng-tools.git] / tests / regression / tools / trigger / test_list_triggers_cli
CommitLineData
0de2479d
SM
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
b203b4b0 26plan_tests 44
0de2479d
SM
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
0de2479d
SM
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
70c766ac
FD
65 lttng_add_trigger_ok "hello" --condition on-event -u test-id --action notify
66 lttng_add_trigger_ok "T0" --fire-once-after 123 --condition on-event -u test-fire-once-after --action notify
67 lttng_add_trigger_ok "T1" --fire-every 124 --condition on-event -u test-fire-every --action notify
0de2479d
SM
68
69 cat > "${tmp_expected_stdout}" <<- EOF
70 - id: T0
71 user id: ${uid}
72 firing policy: once after 123 occurences
73 condition: event rule hit
74 rule: test-fire-once-after (type: tracepoint, domain: ust)
75 actions:
76 notify
77 - id: T1
78 user id: ${uid}
79 firing policy: after every 124 occurences
80 condition: event rule hit
81 rule: test-fire-every (type: tracepoint, domain: ust)
82 actions:
83 notify
84 - id: hello
85 user id: ${uid}
86 condition: event rule hit
87 rule: test-id (type: tracepoint, domain: ust)
88 actions:
89 notify
90 EOF
91
92 list_triggers "top level options" "${tmp_expected_stdout}"
93
94 stop_lttng_sessiond_notap
95}
96
97test_on_event_tracepoint ()
98{
99 # shellcheck disable=SC2119
100 start_lttng_sessiond_notap
101
70c766ac
FD
102 lttng_add_trigger_ok "C" --condition on-event -u -a --action notify
103 lttng_add_trigger_ok "A" --condition on-event aaa -u --filter 'p == 2' --action notify
104 lttng_add_trigger_ok "D" --condition on-event 'hello*' -u -x 'hello2,hello3,hello4' --action notify
105 lttng_add_trigger_ok "B" --condition on-event -u gerboise --loglevel INFO --action notify
106 lttng_add_trigger_ok "E" --condition on-event -u lemming --loglevel-only WARNING --action notify
107 lttng_add_trigger_ok "F" --condition on-event -u capture-payload-field --capture a --action notify
108 lttng_add_trigger_ok "G" --condition on-event -u capture-array --capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
109 lttng_add_trigger_ok "H" --condition on-event -u capture-chan-ctx --capture '$ctx.vpid' --action notify
110 lttng_add_trigger_ok "I" --condition on-event -u capture-app-ctx --capture '$app.iga:active_clients' --action notify
b203b4b0 111
0de2479d
SM
112
113 cat > "${tmp_expected_stdout}" <<- EOF
70c766ac 114 - id: A
0de2479d
SM
115 user id: ${uid}
116 condition: event rule hit
117 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
118 actions:
119 notify
70c766ac 120 - id: B
0de2479d
SM
121 user id: ${uid}
122 condition: event rule hit
1b859ae2 123 rule: gerboise (type: tracepoint, domain: ust, log level at least INFO)
0de2479d
SM
124 actions:
125 notify
70c766ac 126 - id: C
0de2479d
SM
127 user id: ${uid}
128 condition: event rule hit
129 rule: * (type: tracepoint, domain: ust)
130 actions:
131 notify
70c766ac 132 - id: D
0de2479d
SM
133 user id: ${uid}
134 condition: event rule hit
135 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
136 actions:
137 notify
70c766ac 138 - id: E
0de2479d
SM
139 user id: ${uid}
140 condition: event rule hit
1b859ae2 141 rule: lemming (type: tracepoint, domain: ust, log level is WARNING)
0de2479d
SM
142 actions:
143 notify
70c766ac 144 - id: F
b203b4b0
SM
145 user id: ${uid}
146 condition: event rule hit
147 rule: capture-payload-field (type: tracepoint, domain: ust)
148 captures:
149 - a
150 actions:
151 notify
70c766ac 152 - id: G
b203b4b0
SM
153 user id: ${uid}
154 condition: event rule hit
155 rule: capture-array (type: tracepoint, domain: ust)
156 captures:
157 - a[2]
158 - \$ctx.tourlou[18]
159 actions:
160 notify
70c766ac 161 - id: H
b203b4b0
SM
162 user id: ${uid}
163 condition: event rule hit
164 rule: capture-chan-ctx (type: tracepoint, domain: ust)
165 captures:
166 - \$ctx.vpid
167 actions:
168 notify
70c766ac 169 - id: I
b203b4b0
SM
170 user id: ${uid}
171 condition: event rule hit
172 rule: capture-app-ctx (type: tracepoint, domain: ust)
173 captures:
174 - \$app.iga:active_clients
175 actions:
176 notify
0de2479d
SM
177 EOF
178
179 list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"
180
181 stop_lttng_sessiond_notap
182}
183
184test_on_event_probe ()
185{
186 local channel_enable_addr
187 local channel_disable_addr
188
189 # shellcheck disable=SC2119
190 start_lttng_sessiond_notap
191
192 channel_enable_addr=$(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
193 channel_disable_addr=$(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc/kallsyms | cut -f 1 -d ' ')
194
195 # We need to find a valid offset.
196 base_symbol=""
197 offset=0
198 if [[ 0x$channel_enable_addr -lt 0x$channel_disable_addr ]]; then
199 base_symbol="lttng_channel_enable"
200 offset=$(( 0x$channel_disable_addr - 0x$channel_enable_addr ))
201 else
202 base_symbol="lttng_channel_disable"
203 offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
204 fi
205
206 offset_hex="0x$(printf '%x' $offset)"
207
70c766ac
FD
208 lttng_add_trigger_ok "T0" --condition on-event -k --probe=lttng_channel_enable my_channel_enable --action notify
209 lttng_add_trigger_ok "T1" --condition on-event -k --probe="${base_symbol}+${offset_hex}" my_channel_enable --action notify
210 lttng_add_trigger_ok "T2" --condition on-event -k --probe="0x${channel_enable_addr}" my_channel_enable --action notify
0de2479d
SM
211
212 cat > "${tmp_expected_stdout}" <<- EOF
213 - id: T0
214 user id: ${uid}
215 condition: event rule hit
216 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
217 actions:
218 notify
219 - id: T1
220 user id: ${uid}
221 condition: event rule hit
222 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
223 actions:
224 notify
225 - id: T2
226 user id: ${uid}
227 condition: event rule hit
228 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
229 actions:
230 notify
231 EOF
232
233 list_triggers "on-event, probe event rule" "${tmp_expected_stdout}"
234
235 stop_lttng_sessiond_notap
236}
237
238test_on_event_userspace_probe ()
239{
240 # shellcheck disable=SC2119
241 start_lttng_sessiond_notap
242
70c766ac 243 lttng_add_trigger_ok "T0" --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify
0de2479d
SM
244
245 cat > "${tmp_expected_stdout}" <<- EOF
246 - id: T0
247 user id: ${uid}
248 condition: event rule hit
249 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
250 actions:
251 notify
252 EOF
253
254 list_triggers "on-event, userspace-probe event rule" "${tmp_expected_stdout}"
255
256 stop_lttng_sessiond_notap
257}
258
259test_on_event_syscall ()
260{
261 # shellcheck disable=SC2119
262 start_lttng_sessiond_notap
263
70c766ac
FD
264 lttng_add_trigger_ok "T0" --condition on-event -k --syscall open --action notify
265 lttng_add_trigger_ok "T1" --condition on-event -k --syscall ptrace --filter 'a > 2' --action notify
0de2479d
SM
266
267 cat > "${tmp_expected_stdout}" <<- EOF
268 - id: T0
269 user id: ${uid}
270 condition: event rule hit
271 rule: open (type: syscall)
272 actions:
273 notify
274 - id: T1
275 user id: ${uid}
276 condition: event rule hit
277 rule: ptrace (type: syscall, filter: a > 2)
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
70c766ac
FD
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
0de2479d
SM
299
300
301 cat > "${tmp_expected_stdout}" <<- EOF
302 - id: T0
303 user id: ${uid}
304 condition: event rule hit
305 rule: some-event (type: tracepoint, domain: ust)
306 actions:
307 snapshot session \`ze-session\`
308 - id: T1
309 user id: ${uid}
310 condition: event rule hit
311 rule: some-event (type: tracepoint, domain: ust)
312 actions:
313 snapshot session \`ze-session\`, path: /some/path
314 - id: T2
315 user id: ${uid}
316 condition: event rule hit
317 rule: some-event (type: tracepoint, domain: ust)
318 actions:
319 snapshot session \`ze-session\`, path: /some/other/path
320 - id: T3
321 user id: ${uid}
322 condition: event rule hit
323 rule: some-event (type: tracepoint, domain: ust)
324 actions:
325 snapshot session \`ze-session\`, url: net://1.2.3.4
326 - id: T4
327 user id: ${uid}
328 condition: event rule hit
329 rule: some-event (type: tracepoint, domain: ust)
330 actions:
331 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
332 - id: T5
333 user id: ${uid}
334 condition: event rule hit
335 rule: some-event (type: tracepoint, domain: ust)
336 actions:
337 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
338 - id: T6
339 user id: ${uid}
340 condition: event rule hit
341 rule: some-event (type: tracepoint, domain: ust)
342 actions:
343 snapshot session \`ze-session\`, path: /some/path, max size: 1234
344 - id: T7
345 user id: ${uid}
346 condition: event rule hit
347 rule: some-event (type: tracepoint, domain: ust)
348 actions:
349 snapshot session \`ze-session\`, path: /some/path, name: meh
350 EOF
351
352 list_triggers "snapshot action" "${tmp_expected_stdout}"
353
354 stop_lttng_sessiond_notap
355}
356
357test_top_level_options
358test_on_event_tracepoint
359skip $ist_root "non-root user: skipping kprobe tests" 6 || test_on_event_probe
360skip $ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
361skip $ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
362test_snapshot_action
363
364# Cleanup
365rm -f "${tmp_stdout}"
366rm -f "${tmp_stderr}"
367rm -f "${tmp_expected_stdout}"
This page took 0.037615 seconds and 4 git commands to generate.