SoW-2019-0007-2: Dynamic Snapshot: Triggers send partial event payload with notifications
[lttng-tools.git] / tests / regression / tools / trigger / test_list_triggers_cli
CommitLineData
5024c2ac
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 45
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/userspace-probe-elf-binary")
34
35if [ "$(id -u)" == "0" ]; then
36 ist_root=1
37else
38 ist_root=0
39fi
40
41function add_trigger ()
42{
43 "${FULL_LTTNG_BIN}" add-trigger "$@"
44 ok $? "add trigger \`$*\`: exit code is 0"
45}
46
47function list_triggers ()
48{
49 local test_name="$1"
50 local expected_stdout_file="$2"
51
52 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
53 ok $? "${test_name}: exit code is 0"
54
55 diff -u "${expected_stdout_file}" "${tmp_stdout}"
56 ok $? "${test_name}: expected stdout"
57
58 diff -u /dev/null "${tmp_stderr}"
59 ok $? "${test_name}: expected stderr"
60}
61
62test_top_level_options ()
63{
64 # shellcheck disable=SC2119
65 start_lttng_sessiond_notap
66
67
68 add_trigger --id hello --condition on-event -u test-id --action notify
69 add_trigger --fire-once-after 123 --condition on-event -u test-fire-once-after --action notify
70 add_trigger --fire-every 124 --condition on-event -u test-fire-every --action notify
71
72 cat > "${tmp_expected_stdout}" <<- EOF
73 - id: T2
74 firing policy: once after 123 occurences
75 condition: event rule hit
76 rule: test-fire-once-after (type: tracepoint, domain: ust)
77 actions:
78 notify
79 - id: T3
80 firing policy: after every 124 occurences
81 condition: event rule hit
82 rule: test-fire-every (type: tracepoint, domain: ust)
83 actions:
84 notify
85 - id: hello
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
102 add_trigger --condition on-event -u -a --action notify
103 add_trigger --id ABC --condition on-event aaa -u --filter 'p == 2' --action notify
104 add_trigger --condition on-event 'hello*' -u -x 'hello2,hello3,hello4' --action notify
105 add_trigger --id BCD --condition on-event -u gerboise --loglevel INFO --action notify
106 add_trigger --condition on-event -u lemming --loglevel-only WARNING --action notify
107 add_trigger --condition on-event -u capture-payload-field --capture a --action notify
108 add_trigger --condition on-event -u capture-array --capture 'a[2]' --capture '$ctx.tourlou[18]' --action notify
109 add_trigger --condition on-event -u capture-chan-ctx --capture '$ctx.vpid' --action notify
110 add_trigger --condition on-event -u capture-app-ctx --capture '$app.iga:active_clients' --action notify
111
112
113 cat > "${tmp_expected_stdout}" <<- EOF
114 - id: ABC
115 condition: event rule hit
116 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
117 actions:
118 notify
119 - id: BCD
120 condition: event rule hit
121 rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
122 actions:
123 notify
124 - id: T1
125 condition: event rule hit
126 rule: * (type: tracepoint, domain: ust)
127 actions:
128 notify
129 - id: T3
130 condition: event rule hit
131 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
132 actions:
133 notify
134 - id: T5
135 condition: event rule hit
136 rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
137 actions:
138 notify
139 - id: T6
140 condition: event rule hit
141 rule: capture-payload-field (type: tracepoint, domain: ust)
142 captures:
143 - a
144 actions:
145 notify
146 - id: T7
147 condition: event rule hit
148 rule: capture-array (type: tracepoint, domain: ust)
149 captures:
150 - a[2]
151 - \$ctx.tourlou[18]
152 actions:
153 notify
154 - id: T8
155 condition: event rule hit
156 rule: capture-chan-ctx (type: tracepoint, domain: ust)
157 captures:
158 - \$ctx.vpid
159 actions:
160 notify
161 - id: T9
162 condition: event rule hit
163 rule: capture-app-ctx (type: tracepoint, domain: ust)
164 captures:
165 - \$app.iga:active_clients
166 actions:
167 notify
168 EOF
169
170 list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"
171
172 stop_lttng_sessiond_notap
173}
174
175test_on_event_probe ()
176{
177 local sys_open_addr
178
179 # shellcheck disable=SC2119
180 start_lttng_sessiond_notap
181
182 sys_open_addr=$(grep ' T do_sys_open$' /proc/kallsyms | cut -f 1 -d ' ')
183
184 add_trigger --condition on-event -k --probe=do_sys_open my_sys_open --action notify
185 add_trigger --condition on-event -k --probe=do_sys_open+10 my_sys_open --action notify
186 add_trigger --condition on-event -k --probe="${sys_open_addr}" my_sys_open --action notify
187 add_trigger --condition on-event -k --probe="${sys_open_addr}+10" my_sys_open --action notify
188
189 cat > "${tmp_expected_stdout}" <<- EOF
190 - id: T1
191 condition: event rule hit
192 rule: my_sys_open (type: probe, location: do_sys_open)
193 actions:
194 notify
195 - id: T2
196 condition: event rule hit
197 rule: my_sys_open (type: probe, location: do_sys_open+10)
198 actions:
199 notify
200 - id: T3
201 condition: event rule hit
202 rule: my_sys_open (type: probe, location: ${sys_open_addr})
203 actions:
204 notify
205 - id: T4
206 condition: event rule hit
207 rule: my_sys_open (type: probe, location: ${sys_open_addr}+10)
208 actions:
209 notify
210 EOF
211
212 list_triggers "on-event, probe event rule" "${tmp_expected_stdout}"
213
214 stop_lttng_sessiond_notap
215}
216
217test_on_event_userspace_probe ()
218{
219 # shellcheck disable=SC2119
220 start_lttng_sessiond_notap
221
222 add_trigger --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify
223
224 cat > "${tmp_expected_stdout}" <<- EOF
225 - id: T1
226 condition: event rule hit
227 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
228 actions:
229 notify
230 EOF
231
232 list_triggers "on-event, userspace-probe event rule" "${tmp_expected_stdout}"
233
234 stop_lttng_sessiond_notap
235}
236
237test_on_event_syscall ()
238{
239 # shellcheck disable=SC2119
240 start_lttng_sessiond_notap
241
242 add_trigger --condition on-event -k --syscall open --action notify
243 add_trigger --condition on-event -k --syscall ptrace --filter 'a > 2' --action notify
244
245 cat > "${tmp_expected_stdout}" <<- EOF
246 - id: T1
247 condition: event rule hit
248 - rule: open (type: syscall)
249 actions:
250 notify
251 - id: T2
252 condition: event rule hit
253 - rule: ptrace (type: syscall, filter: a > 2)
254 actions:
255 notify
256 EOF
257
258 list_triggers "on-event, syscall event rule" "${tmp_expected_stdout}"
259
260 stop_lttng_sessiond_notap
261}
262
263test_snapshot_action ()
264{
265 start_lttng_sessiond_notap
266
267 add_trigger --condition on-event -u some-event --action snapshot-session ze-session
268 add_trigger --condition on-event -u some-event --action snapshot-session ze-session /some/path
269 add_trigger --condition on-event -u some-event --action snapshot-session ze-session file:///some/other/path
270 add_trigger --condition on-event -u some-event --action snapshot-session ze-session net://1.2.3.4
271 add_trigger --condition on-event -u some-event --action snapshot-session ze-session net://1.2.3.4:1234:1235
272 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
273 add_trigger --condition on-event -u some-event --action snapshot-session ze-session /some/path --max-size=1234
274 add_trigger --condition on-event -u some-event --action snapshot-session ze-session /some/path --name=meh
275
276
277 cat > "${tmp_expected_stdout}" <<- EOF
278 - id: T1
279 condition: event rule hit
280 rule: some-event (type: tracepoint, domain: ust)
281 actions:
282 snapshot session \`ze-session\`
283 - id: T2
284 condition: event rule hit
285 rule: some-event (type: tracepoint, domain: ust)
286 actions:
287 snapshot session \`ze-session\`, path: /some/path
288 - id: T3
289 condition: event rule hit
290 rule: some-event (type: tracepoint, domain: ust)
291 actions:
292 snapshot session \`ze-session\`, path: /some/other/path
293 - id: T4
294 condition: event rule hit
295 rule: some-event (type: tracepoint, domain: ust)
296 actions:
297 snapshot session \`ze-session\`, url: net://1.2.3.4
298 - id: T5
299 condition: event rule hit
300 rule: some-event (type: tracepoint, domain: ust)
301 actions:
302 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
303 - id: T6
304 condition: event rule hit
305 rule: some-event (type: tracepoint, domain: ust)
306 actions:
307 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
308 - id: T7
309 condition: event rule hit
310 rule: some-event (type: tracepoint, domain: ust)
311 actions:
312 snapshot session \`ze-session\`, path: /some/path, max size: 1234
313 - id: T8
314 condition: event rule hit
315 rule: some-event (type: tracepoint, domain: ust)
316 actions:
317 snapshot session \`ze-session\`, path: /some/path, name: meh
318 EOF
319
320 list_triggers "snapshot action" "${tmp_expected_stdout}"
321
322 stop_lttng_sessiond_notap
323}
324
325test_top_level_options
326test_on_event_tracepoint
327skip $ist_root "non-root user: skipping kprobe tests" 7 || test_on_event_probe
328skip $ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
329skip $ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
330test_snapshot_action
331
332# Cleanup
333rm -f "${tmp_stdout}"
334rm -f "${tmp_stderr}"
335rm -f "${tmp_expected_stdout}"
This page took 0.036624 seconds and 5 git commands to generate.