3 # Copyright (C) - 2020 EfficiOS, inc
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.
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
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
18 # Test the `lttng list-trigger` command line interface.
20 CURDIR
="$(dirname "$0")"
21 TESTDIR
="$CURDIR/../../.."
23 # shellcheck source=../../../utils/utils.sh
24 source "$TESTDIR/utils/utils.sh"
28 FULL_LTTNG_BIN
="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
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/userspace-probe-elf-binary")
35 if [ "$(id -u)" == "0" ]; then
41 function add_trigger
()
43 "${FULL_LTTNG_BIN}" add-trigger
"$@"
44 ok $?
"add trigger \`$*\`: exit code is 0"
47 function list_triggers
()
50 local expected_stdout_file
="$2"
52 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
53 ok $?
"${test_name}: exit code is 0"
55 diff -u "${expected_stdout_file}" "${tmp_stdout}"
56 ok $?
"${test_name}: expected stdout"
58 diff -u /dev
/null
"${tmp_stderr}"
59 ok $?
"${test_name}: expected stderr"
62 test_top_level_options
()
64 # shellcheck disable=SC2119
65 start_lttng_sessiond_notap
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
72 cat > "${tmp_expected_stdout}" <<- EOF
74 firing policy: once after 123 occurences
75 condition: event rule hit
76 rule: test-fire-once-after (type: tracepoint, domain: ust)
80 firing policy: after every 124 occurences
81 condition: event rule hit
82 rule: test-fire-every (type: tracepoint, domain: ust)
86 condition: event rule hit
87 rule: test-id (type: tracepoint, domain: ust)
92 list_triggers
"top level options" "${tmp_expected_stdout}"
94 stop_lttng_sessiond_notap
97 test_on_event_tracepoint
()
99 # shellcheck disable=SC2119
100 start_lttng_sessiond_notap
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
113 cat > "${tmp_expected_stdout}" <<- EOF
115 condition: event rule hit
116 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
120 condition: event rule hit
121 rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
125 condition: event rule hit
126 rule: * (type: tracepoint, domain: ust)
130 condition: event rule hit
131 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
135 condition: event rule hit
136 rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
140 condition: event rule hit
141 rule: capture-payload-field (type: tracepoint, domain: ust)
147 condition: event rule hit
148 rule: capture-array (type: tracepoint, domain: ust)
155 condition: event rule hit
156 rule: capture-chan-ctx (type: tracepoint, domain: ust)
162 condition: event rule hit
163 rule: capture-app-ctx (type: tracepoint, domain: ust)
165 - \$app.iga:active_clients
170 list_triggers
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
172 stop_lttng_sessiond_notap
175 test_on_event_probe
()
179 # shellcheck disable=SC2119
180 start_lttng_sessiond_notap
182 sys_open_addr
=$
(grep ' T do_sys_open$' /proc
/kallsyms | cut
-f 1 -d ' ')
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
189 cat > "${tmp_expected_stdout}" <<- EOF
191 condition: event rule hit
192 rule: my_sys_open (type: probe, location: do_sys_open)
196 condition: event rule hit
197 rule: my_sys_open (type: probe, location: do_sys_open+10)
201 condition: event rule hit
202 rule: my_sys_open (type: probe, location: ${sys_open_addr})
206 condition: event rule hit
207 rule: my_sys_open (type: probe, location: ${sys_open_addr}+10)
212 list_triggers
"on-event, probe event rule" "${tmp_expected_stdout}"
214 stop_lttng_sessiond_notap
217 test_on_event_userspace_probe
()
219 # shellcheck disable=SC2119
220 start_lttng_sessiond_notap
222 add_trigger
--condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe
--action notify
224 cat > "${tmp_expected_stdout}" <<- EOF
226 condition: event rule hit
227 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
232 list_triggers
"on-event, userspace-probe event rule" "${tmp_expected_stdout}"
234 stop_lttng_sessiond_notap
237 test_on_event_syscall
()
239 # shellcheck disable=SC2119
240 start_lttng_sessiond_notap
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
245 cat > "${tmp_expected_stdout}" <<- EOF
247 condition: event rule hit
248 - rule: open (type: syscall)
252 condition: event rule hit
253 - rule: ptrace (type: syscall, filter: a > 2)
258 list_triggers
"on-event, syscall event rule" "${tmp_expected_stdout}"
260 stop_lttng_sessiond_notap
263 test_snapshot_action
()
265 start_lttng_sessiond_notap
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
277 cat > "${tmp_expected_stdout}" <<- EOF
279 condition: event rule hit
280 rule: some-event (type: tracepoint, domain: ust)
282 snapshot session \`ze-session\`
284 condition: event rule hit
285 rule: some-event (type: tracepoint, domain: ust)
287 snapshot session \`ze-session\`, path: /some/path
289 condition: event rule hit
290 rule: some-event (type: tracepoint, domain: ust)
292 snapshot session \`ze-session\`, path: /some/other/path
294 condition: event rule hit
295 rule: some-event (type: tracepoint, domain: ust)
297 snapshot session \`ze-session\`, url: net://1.2.3.4
299 condition: event rule hit
300 rule: some-event (type: tracepoint, domain: ust)
302 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
304 condition: event rule hit
305 rule: some-event (type: tracepoint, domain: ust)
307 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
309 condition: event rule hit
310 rule: some-event (type: tracepoint, domain: ust)
312 snapshot session \`ze-session\`, path: /some/path, max size: 1234
314 condition: event rule hit
315 rule: some-event (type: tracepoint, domain: ust)
317 snapshot session \`ze-session\`, path: /some/path, name: meh
320 list_triggers
"snapshot action" "${tmp_expected_stdout}"
322 stop_lttng_sessiond_notap
325 test_top_level_options
326 test_on_event_tracepoint
327 skip
$ist_root "non-root user: skipping kprobe tests" 7 || test_on_event_probe
328 skip
$ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
329 skip
$ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
333 rm -f "${tmp_stdout}"
334 rm -f "${tmp_stderr}"
335 rm -f "${tmp_expected_stdout}"