SoW-2019-0002: Dynamic Snapshot
[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 41
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/userspace-probe-elf-binary")
34
35 if [ "$(id -u)" == "0" ]; then
36 ist_root=1
37 else
38 ist_root=0
39 fi
40
41 function add_trigger ()
42 {
43 "${FULL_LTTNG_BIN}" add-trigger "$@"
44 ok $? "add trigger \`$*\`: exit code is 0"
45 }
46
47 function list_triggers ()
48 {
49 local test_name="$1"
50 local expected_stdout_file="$2"
51
52 "${FULL_LTTNG_BIN}" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}"
53 ok $? "${test_name}: exit code is 0"
54
55 diff -u "${expected_stdout_file}" "${tmp_stdout}"
56 ok $? "${test_name}: expected stdout"
57
58 diff -u /dev/null "${tmp_stderr}"
59 ok $? "${test_name}: expected stderr"
60 }
61
62 test_top_level_options ()
63 {
64 # shellcheck disable=SC2119
65 start_lttng_sessiond_notap
66
67
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
71
72 cat > "${tmp_expected_stdout}" <<- EOF
73 - id: T2
74 firing policy: once after 123 occurences
75 condition: event rule hit
76 rule: test-fire-once-after (type: tracepoint, domain: ust)
77 actions:
78 notify
79 - id: T3
80 firing policy: after every 124 occurences
81 condition: event rule hit
82 rule: test-fire-every (type: tracepoint, domain: ust)
83 actions:
84 notify
85 - id: hello
86 condition: event rule hit
87 rule: test-id (type: tracepoint, domain: ust)
88 actions:
89 notify
90 EOF
91
92 list_triggers "top level options" "${tmp_expected_stdout}"
93
94 stop_lttng_sessiond_notap
95 }
96
97 test_on_event_tracepoint ()
98 {
99 # shellcheck disable=SC2119
100 start_lttng_sessiond_notap
101
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
107
108 cat > "${tmp_expected_stdout}" <<- EOF
109 - id: ABC
110 condition: event rule hit
111 rule: aaa (type: tracepoint, domain: ust, filter: p == 2)
112 actions:
113 notify
114 - id: BCD
115 condition: event rule hit
116 rule: gerboise (type: tracepoint, domain: ust, log level <= TRACE_INFO)
117 actions:
118 notify
119 - id: T1
120 condition: event rule hit
121 rule: * (type: tracepoint, domain: ust)
122 actions:
123 notify
124 - id: T3
125 condition: event rule hit
126 rule: hello* (type: tracepoint, domain: ust, exclusions: hello2,hello3,hello4)
127 actions:
128 notify
129 - id: T5
130 condition: event rule hit
131 rule: lemming (type: tracepoint, domain: ust, log level == TRACE_WARNING)
132 actions:
133 notify
134 EOF
135
136 list_triggers "on-event, tracepoint event rule" "${tmp_expected_stdout}"
137
138 stop_lttng_sessiond_notap
139 }
140
141 test_on_event_probe ()
142 {
143 local sys_open_addr
144
145 # shellcheck disable=SC2119
146 start_lttng_sessiond_notap
147
148 sys_open_addr=$(grep ' T do_sys_open$' /proc/kallsyms | cut -f 1 -d ' ')
149
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
154
155 cat > "${tmp_expected_stdout}" <<- EOF
156 - id: T1
157 condition: event rule hit
158 rule: my_sys_open (type: probe, location: do_sys_open)
159 actions:
160 notify
161 - id: T2
162 condition: event rule hit
163 rule: my_sys_open (type: probe, location: do_sys_open+10)
164 actions:
165 notify
166 - id: T3
167 condition: event rule hit
168 rule: my_sys_open (type: probe, location: ${sys_open_addr})
169 actions:
170 notify
171 - id: T4
172 condition: event rule hit
173 rule: my_sys_open (type: probe, location: ${sys_open_addr}+10)
174 actions:
175 notify
176 EOF
177
178 list_triggers "on-event, probe event rule" "${tmp_expected_stdout}"
179
180 stop_lttng_sessiond_notap
181 }
182
183 test_on_event_userspace_probe ()
184 {
185 # shellcheck disable=SC2119
186 start_lttng_sessiond_notap
187
188 add_trigger --condition on-event -k --userspace-probe=${uprobe_elf_binary}:test_function ma-probe --action notify
189
190 cat > "${tmp_expected_stdout}" <<- EOF
191 - id: T1
192 condition: event rule hit
193 rule: ma-probe (type: userspace probe, location: ${uprobe_elf_binary}:test_function)
194 actions:
195 notify
196 EOF
197
198 list_triggers "on-event, userspace-probe event rule" "${tmp_expected_stdout}"
199
200 stop_lttng_sessiond_notap
201 }
202
203 test_on_event_syscall ()
204 {
205 # shellcheck disable=SC2119
206 start_lttng_sessiond_notap
207
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
210
211 cat > "${tmp_expected_stdout}" <<- EOF
212 - id: T1
213 condition: event rule hit
214 - rule: open (type: syscall)
215 actions:
216 notify
217 - id: T2
218 condition: event rule hit
219 - rule: ptrace (type: syscall, filter: a > 2)
220 actions:
221 notify
222 EOF
223
224 list_triggers "on-event, syscall event rule" "${tmp_expected_stdout}"
225
226 stop_lttng_sessiond_notap
227 }
228
229 test_snapshot_action ()
230 {
231 start_lttng_sessiond_notap
232
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
241
242
243 cat > "${tmp_expected_stdout}" <<- EOF
244 - id: T1
245 condition: event rule hit
246 rule: some-event (type: tracepoint, domain: ust)
247 actions:
248 snapshot session \`ze-session\`
249 - id: T2
250 condition: event rule hit
251 rule: some-event (type: tracepoint, domain: ust)
252 actions:
253 snapshot session \`ze-session\`, path: /some/path
254 - id: T3
255 condition: event rule hit
256 rule: some-event (type: tracepoint, domain: ust)
257 actions:
258 snapshot session \`ze-session\`, path: /some/other/path
259 - id: T4
260 condition: event rule hit
261 rule: some-event (type: tracepoint, domain: ust)
262 actions:
263 snapshot session \`ze-session\`, url: net://1.2.3.4
264 - id: T5
265 condition: event rule hit
266 rule: some-event (type: tracepoint, domain: ust)
267 actions:
268 snapshot session \`ze-session\`, url: net://1.2.3.4:1234:1235
269 - id: T6
270 condition: event rule hit
271 rule: some-event (type: tracepoint, domain: ust)
272 actions:
273 snapshot session \`ze-session\`, control url: tcp://1.2.3.4:1111, data url: tcp://1.2.3.4:1112
274 - id: T7
275 condition: event rule hit
276 rule: some-event (type: tracepoint, domain: ust)
277 actions:
278 snapshot session \`ze-session\`, path: /some/path, max size: 1234
279 - id: T8
280 condition: event rule hit
281 rule: some-event (type: tracepoint, domain: ust)
282 actions:
283 snapshot session \`ze-session\`, path: /some/path, name: meh
284 EOF
285
286 list_triggers "snapshot action" "${tmp_expected_stdout}"
287
288 stop_lttng_sessiond_notap
289 }
290
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
296 test_snapshot_action
297
298 # Cleanup
299 rm -f "${tmp_stdout}"
300 rm -f "${tmp_stderr}"
301 rm -f "${tmp_expected_stdout}"
This page took 0.037975 seconds and 5 git commands to generate.