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
108 cat > "${tmp_expected_stdout}" <<- EOF
110 condition: event rule hit
111 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
115 condition: event rule hit
116 rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
120 condition: event rule hit
121 rule: * (type: tracepoint, domain: ust)
125 condition: event rule hit
126 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
130 condition: event rule hit
131 rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
136 list_triggers
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
138 stop_lttng_sessiond_notap
141 test_on_event_probe
()
145 # shellcheck disable=SC2119
146 start_lttng_sessiond_notap
148 sys_open_addr
=$
(grep ' T do_sys_open$' /proc
/kallsyms | cut
-f 1 -d ' ')
150 add_trigger
--condition on-event
-k --probe=do_sys_open my_sys_open
--action notify
151 add_trigger
--condition on-event
-k --probe=do_sys_open
+10 my_sys_open
--action notify
152 add_trigger
--condition on-event
-k --probe="${sys_open_addr}" my_sys_open
--action notify
153 add_trigger
--condition on-event
-k --probe="${sys_open_addr}+10" my_sys_open
--action notify
155 cat > "${tmp_expected_stdout}" <<- EOF
157 condition: event rule hit
158 rule: my_sys_open (type: probe, location: do_sys_open)
162 condition: event rule hit
163 rule: my_sys_open (type: probe, location: do_sys_open+10)
167 condition: event rule hit
168 rule: my_sys_open (type: probe, location: ${sys_open_addr})
172 condition: event rule hit
173 rule: my_sys_open (type: probe, location: ${sys_open_addr}+10)
178 list_triggers
"on-event, probe event rule" "${tmp_expected_stdout}"
180 stop_lttng_sessiond_notap
183 test_on_event_userspace_probe
()
185 # shellcheck disable=SC2119
186 start_lttng_sessiond_notap
188 add_trigger
--condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe
--action notify
190 cat > "${tmp_expected_stdout}" <<- EOF
192 condition: event rule hit
193 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
198 list_triggers
"on-event, userspace-probe event rule" "${tmp_expected_stdout}"
200 stop_lttng_sessiond_notap
203 test_on_event_syscall
()
205 # shellcheck disable=SC2119
206 start_lttng_sessiond_notap
208 add_trigger
--condition on-event
-k --syscall open
--action notify
209 add_trigger
--condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
211 cat > "${tmp_expected_stdout}" <<- EOF
213 condition: event rule hit
214 - rule: open (type: syscall)
218 condition: event rule hit
219 - rule: ptrace (type: syscall, filter: a > 2)
224 list_triggers
"on-event, syscall event rule" "${tmp_expected_stdout}"
226 stop_lttng_sessiond_notap
229 test_snapshot_action
()
231 start_lttng_sessiond_notap
233 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
234 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
/some
/path
235 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
file:///some
/other
/path
236 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session net
://1.2.3.4
237 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session net
://1.2.3.4:1234:1235
238 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
239 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
/some
/path
--max-size=1234
240 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
/some
/path
--name=meh
243 cat > "${tmp_expected_stdout}" <<- EOF
245 condition: event rule hit
246 rule: some-event (type: tracepoint, domain: ust)
248 snapshot session \`ze-session\`
250 condition: event rule hit
251 rule: some-event (type: tracepoint, domain: ust)
253 snapshot session \`ze-session\`, path: /some/path
255 condition: event rule hit
256 rule: some-event (type: tracepoint, domain: ust)
258 snapshot session \`ze-session\`, path: /some/other/path
260 condition: event rule hit
261 rule: some-event (type: tracepoint, domain: ust)
263 snapshot session \`ze-session\`, url: net://1.2.3.4
265 condition: event rule hit
266 rule: some-event (type: tracepoint, domain: ust)
268 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
270 condition: event rule hit
271 rule: some-event (type: tracepoint, domain: ust)
273 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
275 condition: event rule hit
276 rule: some-event (type: tracepoint, domain: ust)
278 snapshot session \`ze-session\`, path: /some/path, max size: 1234
280 condition: event rule hit
281 rule: some-event (type: tracepoint, domain: ust)
283 snapshot session \`ze-session\`, path: /some/path, name: meh
286 list_triggers
"snapshot action" "${tmp_expected_stdout}"
288 stop_lttng_sessiond_notap
291 test_top_level_options
292 test_on_event_tracepoint
293 skip
$ist_root "non-root user: skipping kprobe tests" 7 || test_on_event_probe
294 skip
$ist_root "non-root user: skipping uprobe tests" 4 || test_on_event_userspace_probe
295 skip
$ist_root "non-root user: skipping syscall tests" 5 || test_on_event_syscall
299 rm -f "${tmp_stdout}"
300 rm -f "${tmp_stderr}"
301 rm -f "${tmp_expected_stdout}"