lttng: Add list-triggers command
[lttng-tools.git] / tests / regression / tools / trigger / test_list_triggers_cli
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 list-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 40
27
28 FULL_LTTNG_BIN="${TESTDIR}/../src/bin/lttng/${LTTNG_BIN}"
29
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")
34
35 uid=$(id --user)
36 gid=$(id --group)
37
38 if [ "$uid" == "0" ]; then
39 ist_root=1
40 else
41 ist_root=0
42 fi
43
44 function add_trigger ()
45 {
46 "${FULL_LTTNG_BIN}" add-trigger "$@"
47 ok $? "add trigger \`$*\`: exit code is 0"
48 }
49
50 function list_triggers ()
51 {
52 local test_name="$1"
53 local expected_stdout_file="$2"
54
55 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
56 ok $? "${test_name}: exit code is 0"
57
58 diff -u "${expected_stdout_file}" "${tmp_stdout}"
59 ok $? "${test_name}: expected stdout"
60
61 diff -u /dev/null "${tmp_stderr}"
62 ok $? "${test_name}: expected stderr"
63 }
64
65 test_top_level_options ()
66 {
67 # shellcheck disable=SC2119
68 start_lttng_sessiond_notap
69
70
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
74
75 cat > "${tmp_expected_stdout}" <<- EOF
76 - id: T0
77 user id: ${uid}
78 firing policy: once after 123 occurences
79 condition: event rule hit
80 rule: test-fire-once-after (type: tracepoint, domain: ust)
81 actions:
82 notify
83 - id: T1
84 user id: ${uid}
85 firing policy: after every 124 occurences
86 condition: event rule hit
87 rule: test-fire-every (type: tracepoint, domain: ust)
88 actions:
89 notify
90 - id: hello
91 user id: ${uid}
92 condition: event rule hit
93 rule: test-id (type: tracepoint, domain: ust)
94 actions:
95 notify
96 EOF
97
98 list_triggers "top level options" "${tmp_expected_stdout}"
99
100 stop_lttng_sessiond_notap
101 }
102
103 test_on_event_tracepoint ()
104 {
105 # shellcheck disable=SC2119
106 start_lttng_sessiond_notap
107
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
113
114 cat > "${tmp_expected_stdout}" <<- EOF
115 - id: ABC
116 user id: ${uid}
117 condition: event rule hit
118 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
119 actions:
120 notify
121 - id: BCD
122 user id: ${uid}
123 condition: event rule hit
124 rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
125 actions:
126 notify
127 - id: T0
128 user id: ${uid}
129 condition: event rule hit
130 rule: * (type: tracepoint, domain: ust)
131 actions:
132 notify
133 - id: T1
134 user id: ${uid}
135 condition: event rule hit
136 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
137 actions:
138 notify
139 - id: T2
140 user id: ${uid}
141 condition: event rule hit
142 rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
143 actions:
144 notify
145 EOF
146
147 list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"
148
149 stop_lttng_sessiond_notap
150 }
151
152 test_on_event_probe ()
153 {
154 local channel_enable_addr
155 local channel_disable_addr
156
157 # shellcheck disable=SC2119
158 start_lttng_sessiond_notap
159
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 ' ')
162
163 # We need to find a valid offset.
164 base_symbol=""
165 offset=0
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 ))
169 else
170 base_symbol="lttng_channel_disable"
171 offset=$(( 0x$channel_enable_addr - 0x$channel_disable_addr ))
172 fi
173
174 offset_hex="0x$(printf '%x' $offset)"
175
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
179
180 cat > "${tmp_expected_stdout}" <<- EOF
181 - id: T0
182 user id: ${uid}
183 condition: event rule hit
184 rule: my_channel_enable (type: probe, location: lttng_channel_enable)
185 actions:
186 notify
187 - id: T1
188 user id: ${uid}
189 condition: event rule hit
190 rule: my_channel_enable (type: probe, location: ${base_symbol}+${offset_hex})
191 actions:
192 notify
193 - id: T2
194 user id: ${uid}
195 condition: event rule hit
196 rule: my_channel_enable (type: probe, location: 0x${channel_enable_addr})
197 actions:
198 notify
199 EOF
200
201 list_triggers "on-event, probe event rule" "${tmp_expected_stdout}"
202
203 stop_lttng_sessiond_notap
204 }
205
206 test_on_event_userspace_probe ()
207 {
208 # shellcheck disable=SC2119
209 start_lttng_sessiond_notap
210
211 add_trigger --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify
212
213 cat > "${tmp_expected_stdout}" <<- EOF
214 - id: T0
215 user id: ${uid}
216 condition: event rule hit
217 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
218 actions:
219 notify
220 EOF
221
222 list_triggers "on-event, userspace-probe event rule" "${tmp_expected_stdout}"
223
224 stop_lttng_sessiond_notap
225 }
226
227 test_on_event_syscall ()
228 {
229 # shellcheck disable=SC2119
230 start_lttng_sessiond_notap
231
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
234
235 cat > "${tmp_expected_stdout}" <<- EOF
236 - id: T0
237 user id: ${uid}
238 condition: event rule hit
239 rule: open (type: syscall)
240 actions:
241 notify
242 - id: T1
243 user id: ${uid}
244 condition: event rule hit
245 rule: ptrace (type: syscall, filter: a > 2)
246 actions:
247 notify
248 EOF
249
250 list_triggers "on-event, syscall event rule" "${tmp_expected_stdout}"
251
252 stop_lttng_sessiond_notap
253 }
254
255 test_snapshot_action ()
256 {
257 start_lttng_sessiond_notap
258
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
267
268
269 cat > "${tmp_expected_stdout}" <<- EOF
270 - id: T0
271 user id: ${uid}
272 condition: event rule hit
273 rule: some-event (type: tracepoint, domain: ust)
274 actions:
275 snapshot session \`ze-session\`
276 - id: T1
277 user id: ${uid}
278 condition: event rule hit
279 rule: some-event (type: tracepoint, domain: ust)
280 actions:
281 snapshot session \`ze-session\`, path: /some/path
282 - id: T2
283 user id: ${uid}
284 condition: event rule hit
285 rule: some-event (type: tracepoint, domain: ust)
286 actions:
287 snapshot session \`ze-session\`, path: /some/other/path
288 - id: T3
289 user id: ${uid}
290 condition: event rule hit
291 rule: some-event (type: tracepoint, domain: ust)
292 actions:
293 snapshot session \`ze-session\`, url: net://1.2.3.4
294 - id: T4
295 user id: ${uid}
296 condition: event rule hit
297 rule: some-event (type: tracepoint, domain: ust)
298 actions:
299 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
300 - id: T5
301 user id: ${uid}
302 condition: event rule hit
303 rule: some-event (type: tracepoint, domain: ust)
304 actions:
305 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
306 - id: T6
307 user id: ${uid}
308 condition: event rule hit
309 rule: some-event (type: tracepoint, domain: ust)
310 actions:
311 snapshot session \`ze-session\`, path: /some/path, max size: 1234
312 - id: T7
313 user id: ${uid}
314 condition: event rule hit
315 rule: some-event (type: tracepoint, domain: ust)
316 actions:
317 snapshot session \`ze-session\`, path: /some/path, name: meh
318 EOF
319
320 list_triggers "snapshot action" "${tmp_expected_stdout}"
321
322 stop_lttng_sessiond_notap
323 }
324
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
330 test_snapshot_action
331
332 # Cleanup
333 rm -f "${tmp_stdout}"
334 rm -f "${tmp_stderr}"
335 rm -f "${tmp_expected_stdout}"
This page took 0.037732 seconds and 5 git commands to generate.