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 add-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 # shellcheck disable=SC2119
31 start_lttng_sessiond_notap
33 tmp_stdout
=$
(mktemp
-t test_parse_cli_trigger_stdout.XXXXXX
)
34 tmp_stderr
=$
(mktemp
-t test_parse_cli_trigger_stderr.XXXXXX
)
35 uprobe_elf_binary
="${TESTDIR}/utils/testapp/userspace-probe-elf-binary/userspace-probe-elf-binary"
37 if [ "$(id -u)" == "0" ]; then
43 function test_success
()
48 diag
"${FULL_LTTNG_BIN} add-trigger $*"
49 "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}"
50 ok $?
"${test_name}: exit code is 0"
52 diff -u "${tmp_stdout}" <(echo "Trigger registered successfully.")
53 ok $?
"${test_name}: expected stdout"
55 diff -u "${tmp_stderr}" /dev
/null
56 ok $?
"${test_name}: expected stderr"
59 function test_failure
()
66 diag
"${FULL_LTTNG_BIN} add-trigger $*"
67 "${FULL_LTTNG_BIN}" add-trigger "$@" > "${tmp_stdout}" 2> "${tmp_stderr}"
68 isnt $?
0 "${test_name}: exit code is not 0"
70 diff -u "${tmp_stdout}" /dev
/null
71 ok $?
"${test_name}: expected stdout"
73 diff -u "${tmp_stderr}" <(echo "${error_msg}")
74 ok $?
"${test_name}: expected stderr"
78 test_success
"explicit id" \
80 --condition on-event some-event-id
-u \
83 # `--condition on-event` successes
84 test_success
"--condition on-event some-event -u" \
85 --condition on-event some-event
-u \
88 test_success
"--condition on-event -a -u" \
89 --condition on-event
-a -u \
92 test_success
"--fire-once-after" \
93 --condition on-event
-u test-fire-once-after \
97 test_success
"--fire-every" \
98 --condition on-event
-u test-fire-every \
102 skip
$ist_root "non-root user: skipping kprobe tests" 12 ||
{
103 test_success
"--condition on-event probe by symbol" \
104 --condition on-event
-k --probe=do_sys_open my_sys_open \
107 test_success
"--condition on-event probe by symbol with offset" \
108 --condition on-event
-k --probe=do_sys_open
+10 my_sys_open \
111 sys_open_addr
=$
(grep ' T do_sys_open$' /proc
/kallsyms | cut
-f 1 -d ' ')
113 test_success
"--condition on-event probe by address" \
114 --condition on-event
-k "--probe=${sys_open_addr}" my_sys_open \
117 test_success
"--condition on-event probe by address with offset" \
118 --condition on-event
-k "--probe=${sys_open_addr}+10" my_sys_open \
122 skip
$ist_root "non-root user: skipping uprobe tests" 6 ||
{
123 test_success
"--condition on-event uprobe" \
124 --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe \
127 test_success
"--condition on-event uprobe with elf prefix" \
128 --condition on-event
-k --userspace-probe=elf
:${uprobe_elf_binary}:test_function ma-probe-2 \
132 skip
$ist_root "non-root user: skipping syscall tests" 9 ||
{
133 test_success
"--condition on-event syscall" \
134 --condition on-event
-k --syscall open \
137 test_success
"--condition on-event syscall -a" \
138 --condition on-event
-k --syscall -a \
141 test_success
"--condition on-event syscall with filter" \
142 --condition on-event
-k --syscall --filter 'a > 2' open \
146 # `--action notify` successes
147 test_success
"--action notify" \
148 --condition on-event some-event-notify
-u \
151 # `--action start-session` successes
152 test_success
"--action start-session" \
153 --condition on-event some-event-start-session
-u \
154 --action start-session ze-session
156 # `--action stop-session` successes
157 test_success
"--action stop-session foo" \
158 --condition on-event some-event-stop-session
-u \
159 --action stop-session ze-session
161 # `--action rotate-session` successes
162 test_success
"--action rotate-session foo" \
163 --condition on-event some-event-rotate-session
-u \
164 --action rotate-session ze-session
166 # `--action snapshot-session` successes
167 test_success
"--action snapshot-session foo" \
168 --condition on-event some-event-snapshot-session
-u \
169 --action snapshot-session ze-session
171 test_success
"--action snapshot-session with file URI" \
172 --condition on-event some-event-snapshot-session2
-u \
173 --action snapshot-session ze-session
/hello
175 test_success
"--action snapshot-session with net URI" \
176 --condition on-event some-event-snapshot-session3
-u \
177 --action snapshot-session ze-session net
://1.2.3.4
179 test_success
"--action snapshot-session with ctrl/data URIs" \
180 --condition on-event some-event-snapshot-session4
-u \
181 --action snapshot-session ze-session
--ctrl-url=tcp
://1.2.3.4:1234 --data-url=tcp
://1.2.3.4:1235
184 test_failure
"no args" "Missing --condition."
186 test_failure
"unknown option" \
187 "Unknown option \`--hello\`" \
190 test_failure
"missing --action" \
191 "Need at least one --action." \
192 --condition on-event hello
-u
194 test_failure
"two --condition" \
195 "A --condition was already given." \
196 --condition on-event aaa
-u \
197 --condition on-event bbb
-u \
200 test_failure
"missing argument to --id" \
201 "Error: While parsing argument #1 (\`--id\`): Missing required argument for option \`--id\`" \
204 for cmd
in fire-once-after fire-every
; do
205 test_failure
"missing argument to --${cmd}" \
206 "Error: While parsing argument #1 (\`--${cmd}\`): Missing required argument for option \`--${cmd}\`" \
207 --condition on-event
-u -a --action notify \
210 test_failure
"invalid argument to --${cmd}: non-digit character" \
211 "Failed to parse \`123bob\` as an integer." \
212 --condition on-event
-u -a --action notify \
215 test_failure
"invalid argument to --${cmd}: empty string" \
216 "Failed to parse \`\` as an integer." \
217 --condition on-event
-u -a --action notify \
221 # `--condition` failures
222 test_failure
"missing args after --condition" \
223 "Missing condition name." \
225 test_failure
"unknown --condition" \
226 "Unknown condition name: zoofest" \
229 # `--condition on-event` failures
230 test_failure
"missing args after --condition on-event" \
231 "Error: Need to provide either a tracepoint name or -a/--all." \
233 test_failure
"missing domain in --condition on-event" \
234 "Error: Please specify a domain (-k/-u/-j)." \
235 --condition on-event
-a
236 test_failure
"extra args after --condition on-event" \
237 "Error: Unexpected argument: bozo" \
238 --condition on-event foo
-u bozo
239 test_failure
"--condition on-event: --all with --probe" \
240 "Error: Can't use -a/--all with event rule of type probe." \
241 --condition on-event
--probe=do_sys_open
--all
242 test_failure
"--condition on-event: missing tracepoint name with --probe" \
243 "Error: Need to provide either a tracepoint name or -a/--all." \
244 --condition on-event
-k --probe do_sys_open
246 test_failure
"--condition on-event: missing tracepoint name with --userspace-probe" \
247 "Error: Need to provide either a tracepoint name or -a/--all." \
248 --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_function
250 test_failure
"--condition on-event: extra argument with --userspace-probe" \
251 "Error: Unexpected argument: world" \
252 --condition on-event
-k --userspace-probe=${uprobe_elf_binary}:test_failure hello world
254 test_failure
"--condition on-event: missing tracepoint name with --syscall" \
255 "Error: Need to provide either a tracepoint name or -a/--all." \
256 --condition on-event
-k --syscall
258 test_failure
"--condition on-event: extra argument with --syscall" \
259 "Error: Unexpected argument: open" \
260 --condition on-event
-k --syscall open open
262 test_failure
"--condition on-event: both -a and a tracepoint name with --syscall" \
263 "Error: Can't provide a tracepoint name with -a/--all." \
264 --condition on-event
-k --syscall -a open
266 # `--action` failures
267 test_failure
"missing args after --action" \
268 "Missing action name." \
269 --condition on-event
-u -a \
272 # `--action notify` failures
273 test_failure
"extra arg after --action notify" \
274 "Unexpected argument \`bob\`." \
275 --condition on-event
-u -a \
278 # `--action start-session` failures
279 test_failure
"missing arg after --action start-session" \
280 "Missing session name." \
281 --condition on-event some-event-start-session
-u \
282 --action start-session
283 test_failure
"extra arg after --action start-session" \
284 "Unexpected argument \`bob\`." \
285 --condition on-event some-event-start-session
-u \
286 --action start-session ze-session bob
288 # `--action stop-session` failures
289 test_failure
"missing arg after --action stop-session" \
290 "Missing session name." \
291 --condition on-event some-event-stop-session
-u \
292 --action stop-session
293 test_failure
"extra arg after --action stop-session" \
294 "Unexpected argument \`bob\`." \
295 --condition on-event some-event-stop-session
-u \
296 --action stop-session ze-session bob
298 # `--action rotate-session` failures
299 test_failure
"missing arg after --action rotate-session" \
300 "Missing session name." \
301 --condition on-event some-event-rotate-session
-u \
302 --action rotate-session
303 test_failure
"extra arg after --action rotate-session" \
304 "Unexpected argument \`bob\`." \
305 --condition on-event some-event-rotate-session
-u \
306 --action rotate-session ze-session bob
308 # `--action snapshot-session` failures
309 test_failure
"missing arg after --action snapshot-session" \
310 "Missing session name." \
311 --condition on-event some-event-snapshot-session
-u \
312 --action snapshot-session
313 test_failure
"extra arg after --action snapshot-session" \
314 "Unexpected argument \`bob\`." \
315 --condition on-event some-event-snapshot-session
-u \
316 --action snapshot-session ze-session
/dest bob
317 test_failure
"snapshot-session action, --max-size without destination" \
318 "Can't provide a snapshot output max size without a snapshot output destination." \
319 --condition on-event some-event-snapshot-session
-u \
320 --action snapshot-session ze-session
--max-size 10M
321 test_failure
"snapshot-session action, --name without destination" \
322 "Can't provide a snapshot output name without a snapshot output destination." \
323 --condition on-event some-event-snapshot-session
-u \
324 --action snapshot-session ze-session
--name hallo
328 stop_lttng_sessiond_notap
329 rm -f "${tmp_stdout}"
330 rm -f "${tmp_stderr}"