Fix: never use 'no' in a command variable
[lttng-tools.git] / tests / regression / kernel / test_userspace_probe
CommitLineData
a9c2df2b
FD
1#!/bin/bash
2#
9d16b343
MJ
3# Copyright (C) 2017 Erica Bugden <erica.bugden@efficios.com>
4# Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
a9c2df2b 5#
9d16b343 6# SPDX-License-Identifier: LGPL-2.1-only
a9c2df2b 7#
a9c2df2b
FD
8
9TEST_DESC="Userspace probe - Testing userspace probe on ELF symbol"
10
11CURDIR=$(dirname "$0")/
12TESTDIR=$CURDIR/../..
13TESTAPP_DIR="$TESTDIR/utils/testapp/"
ef3dfe5d 14ELF_TEST_BIN_DIR="$TESTAPP_DIR/userspace-probe-elf-binary/.libs/"
a9c2df2b
FD
15ELF_TEST_BIN_NAME="userspace-probe-elf-binary"
16ELF_TEST_BIN="$ELF_TEST_BIN_DIR/$ELF_TEST_BIN_NAME"
17ELF_CXX_TEST_BIN_DIR="$TESTAPP_DIR/userspace-probe-elf-cxx-binary/"
18ELF_CXX_TEST_BIN_NAME="userspace-probe-elf-cxx-binary"
19ELF_CXX_TEST_BIN="$ELF_CXX_TEST_BIN_DIR/$ELF_CXX_TEST_BIN_NAME"
20SDT_TEST_BIN_DIR="$TESTAPP_DIR/userspace-probe-sdt-binary/.libs/"
21SDT_TEST_BIN_NAME="userspace-probe-sdt-binary"
22SDT_TEST_BIN="$SDT_TEST_BIN_DIR/$SDT_TEST_BIN_NAME"
23ELF_SYMBOL="test_function"
24PROBE_EVENT_NAME=userspace_probe_test_event
6a0a91e8 25NUM_TESTS=93
a9c2df2b
FD
26OUTPUT_DEST=/dev/null
27ERROR_OUTPUT_DEST=/dev/null
28
29source "$TESTDIR/utils/utils.sh"
30
31function validate_list()
32{
33 local session_name=$1
34 local event_name=$2
35
36 out=$("$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list "$session_name" | grep "$event_name")
37 if [ -z "$out" ]; then
38 fail "Validate userspace probe listing"
39 diag "$event_name not found when listing $session_name"
40 else
41 pass "Validate userspace probe listing. Found $event_name."
42 fi
43}
44
45function test_userspace_probe_enable_file_noexist ()
46{
7539dcec 47 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
48 SESSION_NAME="test_userspace_probe_enable_file_noexist"
49 ENABLE_EXPR="elf:/etc/file-not-exist:$ELF_SYMBOL"
50
51 diag "Userspace probe enable on non-existant file"
52
53 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
54
55 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME $ENABLE_EXPR $PROBE_EVENT_NAME
56
57 destroy_lttng_session_ok $SESSION_NAME
58
59 rm -rf "$TRACE_PATH"
60}
61
62function test_userspace_probe_enable_file_not_elf ()
63{
7539dcec 64 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
65 SESSION_NAME="test_userspace_probe_enable_file_not_elf"
66 ENABLE_EXPR="elf:/etc/passwd:$ELF_SYMBOL"
67
68 diag "Userspace probe enable on a non ELF file"
69
70 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
71
72 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME $ENABLE_EXPR $PROBE_EVENT_NAME
73
74 destroy_lttng_session_ok $SESSION_NAME
75
76 rm -rf "$TRACE_PATH"
77}
78
79function test_userspace_probe_enable_elf_missing_symbol_name ()
80{
7539dcec 81 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
82 SESSION_NAME="test_userspace_probe_enable_elf_missing_symbol"
83 ENABLE_EXPR="elf:$ELF_TEST_BIN:"
84
85 diag "Userspace probe enable with unspecified ELF symbol"
86
87 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
88
89 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
90
91 destroy_lttng_session_ok $SESSION_NAME
92
93 rm -rf "$TRACE_PATH"
94}
95
96function test_userspace_probe_enable_elf_nonexistant_symbol ()
97{
7539dcec 98 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
99 SESSION_NAME="test_userspace_probe_enable_elf_nonexistant_symbol"
100 ELF_SYMBOL_NO_EXIST="function_doesnt_exist"
101 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL_NO_EXIST"
102
103 diag "Userspace probe enable with nonexistant ELF symbol"
104
105 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
106
107 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
108
109 destroy_lttng_session_ok $SESSION_NAME
110
111 rm -rf "$TRACE_PATH"
112}
113
114function test_userspace_probe_enable_elf_symbol_not_function ()
115{
7539dcec 116 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
117 SESSION_NAME="test_userspace_probe_enable_elf_symbol_not_function"
118 ELF_SYMBOL_NO_FUNC="not_a_function"
119 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL_NO_FUNC"
120
121 diag "Userspace probe enable with non-function ELF symbol"
122
123 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
124
125 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
126
127 destroy_lttng_session_ok $SESSION_NAME
128
129 rm -rf "$TRACE_PATH"
130}
131
6a0a91e8
FD
132function test_userspace_probe_unsupported_types ()
133{
7539dcec 134 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
6a0a91e8
FD
135 SESSION_NAME="test_userspace_probe_unsupported_types"
136 # Userspace probe at an address or at an offset to a function
137 # instrumentation description types are not supported at the moment.
138 ENABLE_EXPR_1="elf:$ELF_TEST_BIN:0x400030"
139 ENABLE_EXPR_2="elf:$ELF_TEST_BIN:4194364"
140 ENABLE_EXPR_3="elf:$ELF_TEST_BIN:$ELF_SYMBOL+0x21"
141 ENABLE_EXPR_4="elf:$ELF_TEST_BIN:$ELF_SYMBOL+2"
142
143 diag "Userspace probe enable with unsupported instrumentation description type"
144
145 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
146
147 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR_1" $PROBE_EVENT_NAME
148 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR_2" $PROBE_EVENT_NAME
149 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR_3" $PROBE_EVENT_NAME
150 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR_4" $PROBE_EVENT_NAME
151
152 destroy_lttng_session_ok $SESSION_NAME
153
154 rm -rf "$TRACE_PATH"
155}
156
a9c2df2b
FD
157function test_userspace_probe_enable_implicit_probe_type ()
158{
7539dcec 159 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
160 SESSION_NAME="test_userspace_probe_enable_implicit_probe_type"
161 ENABLE_EXPR="$ELF_TEST_BIN:$ELF_SYMBOL"
162
163 diag "Userspace probe enabled successfully with implicit probe type"
164
165 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
166
167 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
168
07fc3859
FD
169 validate_list $SESSION_NAME $ELF_SYMBOL
170 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
171 validate_list $SESSION_NAME "ELF"
172 validate_list $SESSION_NAME "Function"
a9c2df2b
FD
173
174 destroy_lttng_session_ok $SESSION_NAME
175
176 rm -rf "$TRACE_PATH"
177}
178
179function test_userspace_probe_enable_elf_symbol_exists ()
180{
7539dcec 181 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
182 SESSION_NAME="test_userspace_probe_enable_elf_symbol_exists"
183 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
184
185 diag "Userspace probe enabled successfully"
186
187 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
188
189 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
190
07fc3859
FD
191 validate_list $SESSION_NAME $ELF_SYMBOL
192 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
193 validate_list $SESSION_NAME "ELF"
194 validate_list $SESSION_NAME "Function"
a9c2df2b
FD
195
196 destroy_lttng_session_ok $SESSION_NAME
197
198 rm -rf "$TRACE_PATH"
199}
200
201function test_userspace_probe_enable_in_path ()
202{
7539dcec 203 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
204 SESSION_NAME="test_userspace_probe_enable_in_path"
205 ENABLE_EXPR="elf:$ELF_TEST_BIN_NAME:$ELF_SYMBOL"
206
207 diag "Userspace probe on binary in PATH enabled successfully"
208
209 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
210
211 # Save old PATH and add the test directory to the PATH.
212 OLDPATH="$PATH"
213 export PATH="$PATH:$(realpath $ELF_TEST_BIN_DIR)"
214
215 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
216
07fc3859
FD
217 validate_list $SESSION_NAME $ELF_SYMBOL
218 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
219 validate_list $SESSION_NAME "ELF"
220 validate_list $SESSION_NAME "Function"
a9c2df2b
FD
221
222 # Reset the previously saved PATH.
223 export PATH="$OLDPATH"
224
225 destroy_lttng_session_ok $SESSION_NAME
226
227 rm -rf "$TRACE_PATH"
228}
229
230function test_userspace_probe_enable_full_path ()
231{
7539dcec 232 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
233 SESSION_NAME="test_userspace_probe_enable_full_path"
234 ENABLE_EXPR="elf:$(realpath $ELF_TEST_BIN):$ELF_SYMBOL"
235 diag "Userspace probe with full path enabled successfully"
236
237 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
238
239 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
240
07fc3859
FD
241 validate_list $SESSION_NAME $ELF_SYMBOL
242 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
243 validate_list $SESSION_NAME "ELF"
244 validate_list $SESSION_NAME "Function"
a9c2df2b
FD
245
246 destroy_lttng_session_ok $SESSION_NAME
247
248 rm -rf "$TRACE_PATH"
249}
250
251function test_userspace_probe_enable_colon_in_path ()
252{
7539dcec 253 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b 254 SESSION_NAME="test_userspace_probe_enable_colon_in_path"
7539dcec 255 COLON_FILE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
256 ELF_BIN_SYMLINK="$COLON_FILE_PATH/colon_:_in_name"
257 ELF_BIN_WITH_COLON_IN_NAME_ESCAPED="$COLON_FILE_PATH/colon_\:_in_name"
258 ENABLE_EXPR="elf:"$ELF_BIN_WITH_COLON_IN_NAME_ESCAPED":$ELF_SYMBOL"
259
260 ln -s $(realpath $ELF_TEST_BIN) $ELF_BIN_SYMLINK
261
262 diag "Userspace probe with binary with colon in name enabled successfully"
263
264 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
265
266 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
267
07fc3859
FD
268 validate_list $SESSION_NAME $ELF_SYMBOL
269 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
270 validate_list $SESSION_NAME "ELF"
271 validate_list $SESSION_NAME "Function"
a9c2df2b
FD
272
273 destroy_lttng_session_ok $SESSION_NAME
274
275 rm -rf "$TRACE_PATH"
276 rm -rf "$COLON_FILE_PATH"
277}
278
279function test_userspace_probe_elf ()
280{
7539dcec 281 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
282 SESSION_NAME="test_userprobe_elf"
283 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
284
285 diag "Userspace probe on Elf symbol enabled and traced"
286
287 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
288
289 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
290
291 start_lttng_tracing_ok $SESSION_NAME
07fc3859 292 eval "$ELF_TEST_BIN" > /dev/null
a9c2df2b
FD
293 stop_lttng_tracing_ok $SESSION_NAME
294
295 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
296
297 destroy_lttng_session_ok $SESSION_NAME
298
299 rm -rf "$TRACE_PATH"
300}
301
ef3dfe5d
FD
302function test_userspace_probe_elf_dynamic_symbol ()
303{
7539dcec 304 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
ef3dfe5d
FD
305 SESSION_NAME="test_userprobe_elf"
306 LIBFOO_PATH="$ELF_TEST_BIN_DIR/libfoo.so"
307 ENABLE_EXPR="elf:$LIBFOO_PATH:dynamic_symbol"
308
309 diag "Userspace probe on Elf dynamic symbol enabled and traced"
310
311 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
312
313 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
314
315 start_lttng_tracing_ok $SESSION_NAME
07fc3859 316 eval "$ELF_TEST_BIN" > /dev/null
ef3dfe5d
FD
317 stop_lttng_tracing_ok $SESSION_NAME
318
319 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
320
321 destroy_lttng_session_ok $SESSION_NAME
322
323 rm -rf "$TRACE_PATH"
324}
325
a9c2df2b
FD
326function test_userspace_probe_elf_cxx_function ()
327{
7539dcec 328 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
329 SESSION_NAME="test_userprobe_elf_cxx_function"
330 # Probing C++ mangled symbols should work the same way as regular Elf
331 # symbols
332 ELF_SYMBOL_CXX="_Z17test_cxx_functionv"
333 ENABLE_EXPR="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
334
335 diag "Userspace probe on C++ mangled function enabled and traced"
336
337 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
338
339 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
340
341 start_lttng_tracing_ok $SESSION_NAME
07fc3859 342 eval "$ELF_CXX_TEST_BIN" > /dev/null
a9c2df2b
FD
343 stop_lttng_tracing_ok $SESSION_NAME
344
345 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
346
347 destroy_lttng_session_ok $SESSION_NAME
348
349 rm -rf "$TRACE_PATH"
350}
351
352function test_userspace_probe_elf_cxx_method ()
353{
7539dcec 354 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
355 SESSION_NAME="test_userprobe_elf_cxx_method"
356 # Probing C++ mangled symbols should work the same way as regular Elf
357 # symbols
358 ELF_SYMBOL_CXX="_ZN10test_class11test_methodEv"
359 ENABLE_EXPR="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
360
361 diag "Userspace probe on C++ mangled method enabled and traced"
362
363 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
364
365 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
366
367 start_lttng_tracing_ok $SESSION_NAME
07fc3859 368 eval "$ELF_CXX_TEST_BIN" > /dev/null
a9c2df2b
FD
369 stop_lttng_tracing_ok $SESSION_NAME
370
371 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
372
373 destroy_lttng_session_ok $SESSION_NAME
374
375 rm -rf "$TRACE_PATH"
376}
377
378function test_userspace_probe_elf_disable ()
379{
7539dcec 380 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
381 SESSION_NAME="test_userprobe_elf_disable"
382 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
383
384 diag "Userspace probe on Elf symbol disabled and traced"
385
386 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
387
388 # Activate and disable event
389 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
390 disable_kernel_lttng_userspace_probe_event_ok $SESSION_NAME $PROBE_EVENT_NAME
391
392 start_lttng_tracing_ok $SESSION_NAME
07fc3859 393 eval "$ELF_TEST_BIN" > /dev/null
a9c2df2b
FD
394 stop_lttng_tracing_ok $SESSION_NAME
395
396 # Verify that the trace contains zero event.
397 validate_trace_empty "$TRACE_PATH"
398
399 destroy_lttng_session_ok $SESSION_NAME
400
401 rm -rf "$TRACE_PATH"
402}
403
404function test_userspace_probe_elf_list ()
405{
7539dcec 406 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
407 SESSION_NAME="test_userprobe_elf_list"
408 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
409
410 diag "Userspace probe ELF enabled and listed"
411
412 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
413
414 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
415
07fc3859
FD
416 validate_list $SESSION_NAME $PROBE_EVENT_NAME
417 validate_list $SESSION_NAME $ELF_SYMBOL
418 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
419 validate_list $SESSION_NAME "ELF"
420 validate_list $SESSION_NAME "Function"
a9c2df2b
FD
421
422 destroy_lttng_session_ok $SESSION_NAME
423
424 rm -rf "$TRACE_PATH"
425}
426
427function test_userspace_probe_save_load_elf()
428{
429 # Test that the load and save works for userspace probes AND that when
430 # a userspace probe is placed on a symlink by the user the save command
431 # saves the path to the link and not to the actual file. This is to
432 # support instrumentation of shared objects that are often accessed
433 # through symlinks and updated.
7539dcec
FD
434 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
435 TMP_LINK_DIR=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
436 TMP_SAVE_DIR=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
437
438 SESSION_NAME="test_userprobe_save_load_elf"
439
440 ELF_BIN_SYMLINK="$TMP_LINK_DIR"/bin_elf_symlink
441
442 ENABLE_EXPR_ELF="elf:$ELF_BIN_SYMLINK:$ELF_SYMBOL"
443 PROBE_EVENT_NAME_ELF="$PROBE_EVENT_NAME"_elf
444
445 # Create symlinks to the target binaries.
446 ln -s $(realpath $ELF_TEST_BIN) $ELF_BIN_SYMLINK
447
448 diag "Userspace probes Elf are saved and loaded"
449
450 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
451
452 # Enable userspace prove events.
453 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR_ELF" "$PROBE_EVENT_NAME_ELF"
454
455 # Confirm that the events were enabled.
456 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
457
458 # Save the session to a file.
459 lttng_save $SESSION_NAME "--output-path=$TMP_SAVE_DIR"
460
461 destroy_lttng_session_ok $SESSION_NAME
462
463 # Confirm that the userspace probe are save to the xml file.
464 local count=$(cat $TMP_SAVE_DIR/* | grep --count -E "$ELF_BIN_SYMLINK")
465 if [[ $count -eq "1" ]]; then
466 pass "Symlink found in saved session"
467 else
468 fail "Symlink to binary not found in saved session"
469 fi
470
471 # Load the saved session.
472 lttng_load_ok "--input-path=$TMP_SAVE_DIR"
473
474 # Confirm that the userspace probes event are enabled in the newly
475 # loaded session.
476 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
477
478 # Cleanup temp files and folders.
479 rm -rf "$TRACE_PATH"
480 rm -rf "$TMP_LINK_DIR"
481 rm -rf "$TMP_SAVE_DIR"
482}
483function test_userspace_probe_save_load_sdt()
484{
485 # Test that the load and save works for userspace probes AND that when
486 # a userspace probe is placed on a symlink by the user the save command
487 # saves the path to the link and not to the actual file. This is to
488 # support instrumentation of shared objects that are often accessed
489 # through symlinks and updated.
7539dcec
FD
490 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
491 TMP_LINK_DIR=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
492 TMP_SAVE_DIR=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
493
494 SESSION_NAME="test_userprobe_save_load_sdt"
495 PROVIDER="foobar"
496 PROBE="tp1"
497
498 SDT_BIN_SYMLINK="$TMP_LINK_DIR"/bin_sdt_symlink
499
500 ENABLE_EXPR_SDT="sdt:$SDT_BIN_SYMLINK:$PROVIDER:$PROBE"
501 PROBE_EVENT_NAME_SDT="$PROBE_EVENT_NAME"_sdt
502
503 # Create symlinks to the target binaries.
504 ln -s $(realpath $SDT_TEST_BIN) $SDT_BIN_SYMLINK
505
506 diag "Userspace probes SDT are saved and loaded"
507
508 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
509
510 # Enable userspace prove events.
511 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR_SDT" "$PROBE_EVENT_NAME_SDT"
512
513 # Confirm that the events were enabled.
514 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
515
516 # Save the session to a file.
517 lttng_save $SESSION_NAME "--output-path=$TMP_SAVE_DIR"
518
519 destroy_lttng_session_ok $SESSION_NAME
520
521 # Confirm that the userspace probe are save to the xml file.
522 local count=$(cat $TMP_SAVE_DIR/* | grep --count -E "$SDT_BIN_SYMLINK")
523 if [[ $count -eq "1" ]]; then
524 pass "Symlink found in saved session"
525 else
526 fail "Symlink to binary not found in saved session"
527 fi
528
529 # Load the saved session.
530 lttng_load_ok "--input-path=$TMP_SAVE_DIR"
531
532 # Confirm that the userspace probes event are enabled in the newly
533 # loaded session.
534 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
535
536 # Cleanup temp files and folders.
537 rm -rf "$TRACE_PATH"
538 rm -rf "$TMP_LINK_DIR"
539 rm -rf "$TMP_SAVE_DIR"
540}
541
542function test_userspace_probe_sdt ()
543{
7539dcec 544 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
545 PROVIDER="foobar"
546 PROBE="tp1"
547 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
548
549 diag "Userspace probe on SDT tracepoint enabled and traced"
550
551 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
552
553 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
554
555 start_lttng_tracing_ok $SESSION_NAME
07fc3859 556 eval "$SDT_TEST_BIN" > /dev/null
a9c2df2b
FD
557 stop_lttng_tracing_ok $SESSION_NAME
558
559 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
560
561 destroy_lttng_session_ok $SESSION_NAME
562
563 rm -rf "$TRACE_PATH"
564}
565
566function test_userspace_probe_sdt_list ()
567{
7539dcec 568 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
569 SESSION_NAME="test_userprobe_sdt_list"
570 PROVIDER="foobar"
571 PROBE="tp1"
572 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
573
574 diag "Userspace probe SDT enabled and listed"
575
576 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
577
578 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
579
07fc3859
FD
580 validate_list $SESSION_NAME $PROBE_EVENT_NAME
581 validate_list $SESSION_NAME $PROVIDER
582 validate_list $SESSION_NAME $PROBE
583 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
584 validate_list $SESSION_NAME "SDT"
585 validate_list $SESSION_NAME "Tracepoint"
a9c2df2b
FD
586
587 destroy_lttng_session_ok $SESSION_NAME
588
589 rm -rf "$TRACE_PATH"
590}
591
592function test_userspace_probe_enable_sdt_nonexistant_provider ()
593{
7539dcec 594 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
595 SESSION_NAME="test_userprobe_sdt_nonexistand_provider"
596 PROVIDER="not_provider"
597 PROBE="tp1"
598 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
599
600 diag "Userspace probe SDT on tracepoint non existant provider"
601
602 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
603
604 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
605
606 destroy_lttng_session_ok $SESSION_NAME
607
608 rm -rf "$TRACE_PATH"
609}
610
611function test_userspace_probe_enable_sdt_nonexistant_probe ()
612{
7539dcec 613 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
614 SESSION_NAME="test_userprobe_sdt_nonexistant_probe"
615 PROVIDER="foobar"
616 PROBE="not_a_tracepoint"
617 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
618
619 diag "Userspace probe SDT on non existant probe"
620
621 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
622
623 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
624
625 destroy_lttng_session_ok $SESSION_NAME
626
627 rm -rf "$TRACE_PATH"
628}
629
630function test_userspace_probe_enable_sdt_with_sema ()
631{
7539dcec 632 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
633 SESSION_NAME="test_userprobe_sdt_with_sema"
634 PROVIDER="foobar"
635 PROBE="tp_with_semaphore"
636 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
637
638 diag "Userspace probe SDT on non existant probe"
639
640 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
641
642 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
643
644 destroy_lttng_session_ok $SESSION_NAME
645
646 rm -rf "$TRACE_PATH"
647}
648
649function test_userspace_probe_sdt_one_probe ()
650{
7539dcec 651 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
652 SESSION_NAME="test_userprobe_sdt_one_probe"
653 PROVIDER="foobar"
654 PROBE="tp1"
655 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
656
657 diag "Userspace probe SDT on tracepoint with one callsite"
658
659 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
660
661 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
662
663 start_lttng_tracing_ok $SESSION_NAME
07fc3859 664 eval "$SDT_TEST_BIN" > /dev/null
a9c2df2b
FD
665 stop_lttng_tracing_ok $SESSION_NAME
666
667 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
668
669 destroy_lttng_session_ok $SESSION_NAME
670
671 rm -rf "$TRACE_PATH"
672}
673
674function test_userspace_probe_sdt_two_probes ()
675{
7539dcec 676 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
677 SESSION_NAME="test_userprobe_sdt_two_probes"
678 PROVIDER="foobar"
679 PROBE="tp2"
680 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
681
682 diag "Userspace probe SDT on tracepoint with two callsites"
683
684 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
685
686 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
687
688 start_lttng_tracing_ok $SESSION_NAME
07fc3859 689 eval "$SDT_TEST_BIN" > /dev/null
a9c2df2b
FD
690 stop_lttng_tracing_ok $SESSION_NAME
691
692 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
693
694 destroy_lttng_session_ok $SESSION_NAME
695
696 rm -rf "$TRACE_PATH"
697}
698
699function test_userspace_probe_sdt_in_shared_object ()
700{
7539dcec 701 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
702 SESSION_NAME="test_userprobe_sdt_shared_object"
703 PROVIDER="foobar"
704 PROBE="tp_in_shared_object"
705 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libfoo.so:$PROVIDER:$PROBE"
706
707 diag "Userspace probe SDT on tracepoint in shared object"
708
709 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
710
711 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
712
713 start_lttng_tracing_ok $SESSION_NAME
07fc3859 714 eval "$SDT_TEST_BIN" > /dev/null
a9c2df2b
FD
715 stop_lttng_tracing_ok $SESSION_NAME
716
717 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
718
719 destroy_lttng_session_ok $SESSION_NAME
720
721 rm -rf "$TRACE_PATH"
722}
723
724function test_userspace_probe_sdt_in_shared_object_dlopen ()
725{
7539dcec 726 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
727 SESSION_NAME="test_userprobe_sdt_shared_object_dlopen"
728 PROVIDER="foobar"
729 PROBE="tp_in_dlopen"
730 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libbar.so:$PROVIDER:$PROBE"
731
732 diag "Userspace probe SDT on tracepoint in dlopen()ed shared object"
733
734 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
735
736 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
737
738 start_lttng_tracing_ok $SESSION_NAME
07fc3859 739 eval "$SDT_TEST_BIN" > /dev/null
a9c2df2b
FD
740 stop_lttng_tracing_ok $SESSION_NAME
741
742 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
743
744 destroy_lttng_session_ok $SESSION_NAME
745
746 rm -rf "$TRACE_PATH"
747}
748
749function test_userspace_probe_sdt_in_shared_object_ldpreload ()
750{
7539dcec 751 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
752 SESSION_NAME="test_userprobe_sdt_shared_object_ldpreload"
753 PROVIDER="foobar"
754 PROBE="tp_in_ldpreload"
755 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libzzz.so:$PROVIDER:$PROBE"
756
757 diag "Userspace probe SDT on tracepoint in an LD_PRELOADed shared object"
758
759 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
760
761 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
762
763 start_lttng_tracing_ok $SESSION_NAME
07fc3859 764 LD_PRELOAD="$SDT_TEST_BIN_DIR/libzzz.so" eval "$SDT_TEST_BIN" > /dev/null
a9c2df2b
FD
765 stop_lttng_tracing_ok $SESSION_NAME
766
767 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
768
769 destroy_lttng_session_ok $SESSION_NAME
770
771 rm -rf "$TRACE_PATH"
772}
773
774function test_userspace_probe_sdt_with_arg ()
775{
7539dcec 776 TRACE_PATH=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
a9c2df2b
FD
777 SESSION_NAME="test_userprobe_sdt_arg"
778 PROVIDER="foobar"
779 PROBE="tp_with_arg"
780 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
781
782 diag "Userspace probe SDT on tracepoint with argument"
783
784 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
785
786 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
787
788 start_lttng_tracing_ok $SESSION_NAME
07fc3859 789 eval "$SDT_TEST_BIN" > /dev/null
a9c2df2b
FD
790 stop_lttng_tracing_ok $SESSION_NAME
791
792 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
793
794 destroy_lttng_session_ok $SESSION_NAME
795
796 rm -rf "$TRACE_PATH"
797}
798
799ls "$SDT_TEST_BIN" >/dev/null 2>&1
800if test $? == 0; then
801 NUM_TESTS=$((NUM_TESTS+68))
802 RUN_SDT_TESTS=1
803else
804 RUN_SDT_TESTS=0
805fi
806
807ls "$ELF_CXX_TEST_BIN" >/dev/null 2>&1
808if test $? == 0; then
809 NUM_TESTS=$((NUM_TESTS+12))
810 RUN_ELF_CXX_TESTS=1
811else
812 RUN_ELF_CXX_TESTS=0
813fi
814plan_tests $NUM_TESTS
815print_test_banner "$TEST_DESC"
816
817if [ "$(id -u)" == "0" ]; then
818 isroot=1
819else
820 isroot=0
821fi
822
823skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
824{
ebdd11df 825 validate_lttng_modules_present
a9c2df2b
FD
826 start_lttng_sessiond
827
828 # Unsuccessful event enabling
829 test_userspace_probe_enable_file_noexist
830 test_userspace_probe_enable_file_not_elf
831
832 test_userspace_probe_enable_elf_missing_symbol_name
833 test_userspace_probe_enable_elf_nonexistant_symbol
834 test_userspace_probe_enable_elf_symbol_not_function
6a0a91e8 835 test_userspace_probe_unsupported_types
a9c2df2b
FD
836
837 # Successful userspace probe elf enabling
838 test_userspace_probe_enable_implicit_probe_type
839 test_userspace_probe_enable_in_path
840 test_userspace_probe_enable_full_path
841 test_userspace_probe_enable_elf_symbol_exists
842 test_userspace_probe_enable_colon_in_path
843
844 # Successful tracing userspace probe elf
845 test_userspace_probe_elf
ef3dfe5d 846 test_userspace_probe_elf_dynamic_symbol
a9c2df2b
FD
847
848 # Disable userspace-probe elf
849 test_userspace_probe_elf_disable
850
851 # Successful listing of userspace probe elf
852 test_userspace_probe_elf_list
853
854 # Successful save and load of userspace probe elf
855 test_userspace_probe_save_load_elf
856
857 if test $RUN_ELF_CXX_TESTS == 1; then
858 # Successful tracing of userspace probe elf on C++ symbol
859 test_userspace_probe_elf_cxx_function
860 test_userspace_probe_elf_cxx_method
861 fi
862
863 if test $RUN_SDT_TESTS == 1; then
864 # Unsuccessful event enabling
865 test_userspace_probe_enable_sdt_nonexistant_provider
866 test_userspace_probe_enable_sdt_nonexistant_probe
867 test_userspace_probe_enable_sdt_with_sema
868
869 # Successful userspace probe sdt enabling
870 test_userspace_probe_sdt_one_probe
871 test_userspace_probe_sdt_two_probes
872 test_userspace_probe_sdt_with_arg
873 test_userspace_probe_sdt_in_shared_object
874 test_userspace_probe_sdt_in_shared_object_dlopen
875 test_userspace_probe_sdt_in_shared_object_ldpreload
876
877 # Successful tracing of userspace probe sdt
878 test_userspace_probe_sdt
879
880 # Successful listing of userspace probe sdt
881 test_userspace_probe_sdt_list
882
883 # Successful save and load of userspace probe sdt
884 test_userspace_probe_save_load_sdt
885 fi
886
887 stop_lttng_sessiond
888}
This page took 0.078019 seconds and 4 git commands to generate.