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