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/.libs/userspace-probe-elf-binary")
38 if [ "$uid" == "0" ]; then
44 function add_trigger
()
46 "${FULL_LTTNG_BIN}" add-trigger
"$@"
47 ok $?
"add trigger \`$*\`: exit code is 0"
50 function list_triggers
()
53 local expected_stdout_file
="$2"
55 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
56 ok $?
"${test_name}: exit code is 0"
58 diff -u "${expected_stdout_file}" "${tmp_stdout}"
59 ok $?
"${test_name}: expected stdout"
61 diff -u /dev
/null
"${tmp_stderr}"
62 ok $?
"${test_name}: expected stderr"
65 test_top_level_options
()
67 # shellcheck disable=SC2119
68 start_lttng_sessiond_notap
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
75 cat > "${tmp_expected_stdout}" <<- EOF
78 firing policy: once after 123 occurences
79 condition: event rule hit
80 rule: test-fire-once-after (type: tracepoint, domain: ust)
85 firing policy: after every 124 occurences
86 condition: event rule hit
87 rule: test-fire-every (type: tracepoint, domain: ust)
92 condition: event rule hit
93 rule: test-id (type: tracepoint, domain: ust)
98 list_triggers
"top level options" "${tmp_expected_stdout}"
100 stop_lttng_sessiond_notap
103 test_on_event_tracepoint
()
105 # shellcheck disable=SC2119
106 start_lttng_sessiond_notap
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
114 cat > "${tmp_expected_stdout}" <<- EOF
117 condition: event rule hit
118 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
123 condition: event rule hit
124 rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
129 condition: event rule hit
130 rule: * (type: tracepoint, domain: ust)
135 condition: event rule hit
136 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
141 condition: event rule hit
142 rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
147 list_triggers
"on-event, tracepoint event rule" "${tmp_expected_stdout}"
149 stop_lttng_sessiond_notap
152 test_on_event_probe
()
154 local channel_enable_addr
155 local channel_disable_addr
157 # shellcheck disable=SC2119
158 start_lttng_sessiond_notap
160 channel_enable_addr
=$
(grep ' t lttng_channel_enable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
161 channel_disable_addr
=$
(grep ' t lttng_channel_disable\s\[lttng_tracer\]$' /proc
/kallsyms | cut
-f 1 -d ' ')
163 # We need to find a valid offset.
166 if [[ 0x
$channel_enable_addr -lt 0x
$channel_disable_addr ]]; then
167 base_symbol
="lttng_channel_enable"
168 offset
=$
(( 0x
$channel_disable_addr - 0x
$channel_enable_addr ))
170 base_symbol
="lttng_channel_disable"
171 offset
=$
(( 0x
$channel_enable_addr - 0x
$channel_disable_addr ))
174 offset_hex
="0x$(printf '%x' $offset)"
176 add_trigger
--condition on-event
-k --probe=lttng_channel_enable my_channel_enable
--action notify
177 add_trigger
--condition on-event
-k --probe="${base_symbol}+${offset_hex}" my_channel_enable
--action notify
178 add_trigger
--condition on-event
-k --probe="0x${channel_enable_addr}" my_channel_enable
--action notify
180 cat > "${tmp_expected_stdout}" <<- EOF
183 condition: event rule hit
184 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
189 condition: event rule hit
190 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
195 condition: event rule hit
196 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
201 list_triggers
"on-event, probe event rule" "${tmp_expected_stdout}"
203 stop_lttng_sessiond_notap
206 test_on_event_userspace_probe
()
208 # shellcheck disable=SC2119
209 start_lttng_sessiond_notap
211 add_trigger
--condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe
--action notify
213 cat > "${tmp_expected_stdout}" <<- EOF
216 condition: event rule hit
217 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
222 list_triggers
"on-event, userspace-probe event rule" "${tmp_expected_stdout}"
224 stop_lttng_sessiond_notap
227 test_on_event_syscall
()
229 # shellcheck disable=SC2119
230 start_lttng_sessiond_notap
232 add_trigger
--condition on-event
-k --syscall open
--action notify
233 add_trigger
--condition on-event
-k --syscall ptrace
--filter 'a > 2' --action notify
235 cat > "${tmp_expected_stdout}" <<- EOF
238 condition: event rule hit
239 rule: open (type: syscall)
244 condition: event rule hit
245 rule: ptrace (type: syscall, filter: a > 2)
250 list_triggers
"on-event, syscall event rule" "${tmp_expected_stdout}"
252 stop_lttng_sessiond_notap
255 test_snapshot_action
()
257 start_lttng_sessiond_notap
259 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
260 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
261 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--url file:///some
/other
/path
262 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4
263 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--url net
://1.2.3.4:1234:1235
264 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
265 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--max-size=1234
266 add_trigger
--condition on-event
-u some-event
--action snapshot-session ze-session
--path /some
/path
--name=meh
269 cat > "${tmp_expected_stdout}" <<- EOF
272 condition: event rule hit
273 rule: some-event (type: tracepoint, domain: ust)
275 snapshot session \`ze-session\`
278 condition: event rule hit
279 rule: some-event (type: tracepoint, domain: ust)
281 snapshot session \`ze-session\`, path: /some/path
284 condition: event rule hit
285 rule: some-event (type: tracepoint, domain: ust)
287 snapshot session \`ze-session\`, path: /some/other/path
290 condition: event rule hit
291 rule: some-event (type: tracepoint, domain: ust)
293 snapshot session \`ze-session\`, url: net://1.2.3.4
296 condition: event rule hit
297 rule: some-event (type: tracepoint, domain: ust)
299 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
302 condition: event rule hit
303 rule: some-event (type: tracepoint, domain: ust)
305 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
308 condition: event rule hit
309 rule: some-event (type: tracepoint, domain: ust)
311 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" 6 || 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}"