Commit | Line | Data |
---|---|---|
1831ae68 FD |
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 add-trigger` command line interface. | |
19 | ||
20 | CURDIR="$(dirname "$0")" | |
21 | TESTDIR="$CURDIR/../../.." | |
22 | ||
23 | # shellcheck source=../../../utils/utils.sh | |
24 | source "$TESTDIR/utils/utils.sh" | |
25 | ||
26 | plan_tests 171 | |
27 | ||
28 | FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}" | |
29 | ||
30 | # shellcheck disable=SC2119 | |
31 | start_lttng_sessiond_notap | |
32 | ||
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" | |
36 | ||
37 | if [ "$(id -u)" == "0" ]; then | |
38 | ist_root=1 | |
39 | else | |
40 | ist_root=0 | |
41 | fi | |
42 | ||
43 | function test_success () | |
44 | { | |
45 | local test_name="$1" | |
46 | shift | |
47 | ||
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" | |
51 | ||
52 | diff -u "${tmp_stdout}" <(echo "Trigger registered successfully.") | |
53 | ok $? "${test_name}: expected stdout" | |
54 | ||
55 | diff -u "${tmp_stderr}" /dev/null | |
56 | ok $? "${test_name}: expected stderr" | |
57 | } | |
58 | ||
59 | function test_failure () | |
60 | { | |
61 | local test_name="$1" | |
62 | local error_msg="$2" | |
63 | ||
64 | shift 2 | |
65 | ||
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" | |
69 | ||
70 | diff -u "${tmp_stdout}" /dev/null | |
71 | ok $? "${test_name}: expected stdout" | |
72 | ||
73 | diff -u "${tmp_stderr}" <(echo "${error_msg}") | |
74 | ok $? "${test_name}: expected stderr" | |
75 | } | |
76 | ||
77 | # top-level options | |
78 | test_success "explicit id" \ | |
79 | --id hohoho \ | |
80 | --condition on-event some-event-id -u \ | |
81 | --action notify | |
82 | ||
83 | # `--condition on-event` successes | |
84 | test_success "--condition on-event some-event -u" \ | |
85 | --condition on-event some-event -u \ | |
86 | --action notify | |
87 | ||
88 | test_success "--condition on-event -a -u" \ | |
89 | --condition on-event -a -u \ | |
90 | --action notify | |
91 | ||
92 | test_success "--fire-once-after" \ | |
93 | --condition on-event -u test-fire-once-after \ | |
94 | --action notify \ | |
95 | --fire-once-after=55 | |
96 | ||
97 | test_success "--fire-every" \ | |
98 | --condition on-event -u test-fire-every \ | |
99 | --action notify \ | |
100 | --fire-every=55 | |
101 | ||
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 \ | |
105 | --action notify | |
106 | ||
107 | test_success "--condition on-event probe by symbol with offset" \ | |
108 | --condition on-event -k --probe=do_sys_open+10 my_sys_open \ | |
109 | --action notify | |
110 | ||
111 | sys_open_addr=$(grep ' T do_sys_open$' /proc/kallsyms | cut -f 1 -d ' ') | |
112 | ||
113 | test_success "--condition on-event probe by address" \ | |
114 | --condition on-event -k "--probe=${sys_open_addr}" my_sys_open \ | |
115 | --action notify | |
116 | ||
117 | test_success "--condition on-event probe by address with offset" \ | |
118 | --condition on-event -k "--probe=${sys_open_addr}+10" my_sys_open \ | |
119 | --action notify | |
120 | } | |
121 | ||
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 \ | |
125 | --action notify | |
126 | ||
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 \ | |
129 | --action notify | |
130 | } | |
131 | ||
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 \ | |
135 | --action notify | |
136 | ||
137 | test_success "--condition on-event syscall -a" \ | |
138 | --condition on-event -k --syscall -a \ | |
139 | --action notify | |
140 | ||
141 | test_success "--condition on-event syscall with filter" \ | |
142 | --condition on-event -k --syscall --filter 'a > 2' open \ | |
143 | --action notify | |
144 | } | |
145 | ||
146 | # `--action notify` successes | |
147 | test_success "--action notify" \ | |
148 | --condition on-event some-event-notify -u \ | |
149 | --action notify | |
150 | ||
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 | |
155 | ||
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 | |
160 | ||
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 | |
165 | ||
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 | |
170 | ||
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 | |
174 | ||
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 | |
178 | ||
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 | |
182 | ||
183 | # top-level failures | |
184 | test_failure "no args" "Missing --condition." | |
185 | ||
186 | test_failure "unknown option" \ | |
187 | "Unknown option \`--hello\`" \ | |
188 | --hello | |
189 | ||
190 | test_failure "missing --action" \ | |
191 | "Need at least one --action." \ | |
192 | --condition on-event hello -u | |
193 | ||
194 | test_failure "two --condition" \ | |
195 | "A --condition was already given." \ | |
196 | --condition on-event aaa -u \ | |
197 | --condition on-event bbb -u \ | |
198 | --action notify | |
199 | ||
200 | test_failure "missing argument to --id" \ | |
201 | "Error: While parsing argument #1 (\`--id\`): Missing required argument for option \`--id\`" \ | |
202 | --id | |
203 | ||
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 \ | |
208 | --${cmd} | |
209 | ||
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 \ | |
213 | --${cmd} 123bob | |
214 | ||
215 | test_failure "invalid argument to --${cmd}: empty string" \ | |
216 | "Failed to parse \`\` as an integer." \ | |
217 | --condition on-event -u -a --action notify \ | |
218 | --${cmd} "" | |
219 | done | |
220 | ||
221 | # `--condition` failures | |
222 | test_failure "missing args after --condition" \ | |
223 | "Missing condition name." \ | |
224 | --condition | |
225 | test_failure "unknown --condition" \ | |
226 | "Unknown condition name: zoofest" \ | |
227 | --condition zoofest | |
228 | ||
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." \ | |
232 | --condition on-event | |
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 | |
245 | ||
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 | |
249 | ||
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 | |
253 | ||
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 | |
257 | ||
258 | test_failure "--condition on-event: extra argument with --syscall" \ | |
259 | "Error: Unexpected argument: open" \ | |
260 | --condition on-event -k --syscall open open | |
261 | ||
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 | |
265 | ||
266 | # `--action` failures | |
267 | test_failure "missing args after --action" \ | |
268 | "Missing action name." \ | |
269 | --condition on-event -u -a \ | |
270 | --action | |
271 | ||
272 | # `--action notify` failures | |
273 | test_failure "extra arg after --action notify" \ | |
274 | "Unexpected argument \`bob\`." \ | |
275 | --condition on-event -u -a \ | |
276 | --action notify bob | |
277 | ||
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 | |
287 | ||
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 | |
297 | ||
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 | |
307 | ||
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 | |
325 | ||
326 | ||
327 | # Cleanup | |
328 | stop_lttng_sessiond_notap | |
329 | rm -f "${tmp_stdout}" | |
330 | rm -f "${tmp_stderr}" |