3 # Copyright (C) - 2017 Erica Bugden <erica.bugden@efficios.com>
4 # Copyright (C) - 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
6 # This library is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation; version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this library; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 TEST_DESC
="Userspace probe - Testing userspace probe on ELF symbol"
21 CURDIR
=$
(dirname "$0")/
23 TESTAPP_DIR
="$TESTDIR/utils/testapp/"
24 ELF_TEST_BIN_DIR
="$TESTAPP_DIR/userspace-probe-elf-binary/.libs/"
25 ELF_TEST_BIN_NAME
="userspace-probe-elf-binary"
26 ELF_TEST_BIN
="$ELF_TEST_BIN_DIR/$ELF_TEST_BIN_NAME"
27 ELF_CXX_TEST_BIN_DIR
="$TESTAPP_DIR/userspace-probe-elf-cxx-binary/"
28 ELF_CXX_TEST_BIN_NAME
="userspace-probe-elf-cxx-binary"
29 ELF_CXX_TEST_BIN
="$ELF_CXX_TEST_BIN_DIR/$ELF_CXX_TEST_BIN_NAME"
30 SDT_TEST_BIN_DIR
="$TESTAPP_DIR/userspace-probe-sdt-binary/.libs/"
31 SDT_TEST_BIN_NAME
="userspace-probe-sdt-binary"
32 SDT_TEST_BIN
="$SDT_TEST_BIN_DIR/$SDT_TEST_BIN_NAME"
33 ELF_SYMBOL
="test_function"
34 PROBE_EVENT_NAME
=userspace_probe_test_event
37 ERROR_OUTPUT_DEST
=/dev
/null
39 source "$TESTDIR/utils/utils.sh"
41 function validate_list
()
46 out
=$
("$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list
"$session_name" |
grep "$event_name")
47 if [ -z "$out" ]; then
48 fail
"Validate userspace probe listing"
49 diag
"$event_name not found when listing $session_name"
51 pass
"Validate userspace probe listing. Found $event_name."
55 function test_userspace_probe_enable_file_noexist
()
57 TRACE_PATH
=$
(mktemp
-d)
58 SESSION_NAME
="test_userspace_probe_enable_file_noexist"
59 ENABLE_EXPR
="elf:/etc/file-not-exist:$ELF_SYMBOL"
61 diag
"Userspace probe enable on non-existant file"
63 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
65 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME $ENABLE_EXPR $PROBE_EVENT_NAME
67 destroy_lttng_session_ok
$SESSION_NAME
72 function test_userspace_probe_enable_file_not_elf
()
74 TRACE_PATH
=$
(mktemp
-d)
75 SESSION_NAME
="test_userspace_probe_enable_file_not_elf"
76 ENABLE_EXPR
="elf:/etc/passwd:$ELF_SYMBOL"
78 diag
"Userspace probe enable on a non ELF file"
80 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
82 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME $ENABLE_EXPR $PROBE_EVENT_NAME
84 destroy_lttng_session_ok
$SESSION_NAME
89 function test_userspace_probe_enable_elf_missing_symbol_name
()
91 TRACE_PATH
=$
(mktemp
-d)
92 SESSION_NAME
="test_userspace_probe_enable_elf_missing_symbol"
93 ENABLE_EXPR
="elf:$ELF_TEST_BIN:"
95 diag
"Userspace probe enable with unspecified ELF symbol"
97 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
99 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
101 destroy_lttng_session_ok
$SESSION_NAME
106 function test_userspace_probe_enable_elf_nonexistant_symbol
()
108 TRACE_PATH
=$
(mktemp
-d)
109 SESSION_NAME
="test_userspace_probe_enable_elf_nonexistant_symbol"
110 ELF_SYMBOL_NO_EXIST
="function_doesnt_exist"
111 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL_NO_EXIST"
113 diag
"Userspace probe enable with nonexistant ELF symbol"
115 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
117 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
119 destroy_lttng_session_ok
$SESSION_NAME
124 function test_userspace_probe_enable_elf_symbol_not_function
()
126 TRACE_PATH
=$
(mktemp
-d)
127 SESSION_NAME
="test_userspace_probe_enable_elf_symbol_not_function"
128 ELF_SYMBOL_NO_FUNC
="not_a_function"
129 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL_NO_FUNC"
131 diag
"Userspace probe enable with non-function ELF symbol"
133 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
135 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
137 destroy_lttng_session_ok
$SESSION_NAME
142 function test_userspace_probe_unsupported_types
()
144 TRACE_PATH
=$
(mktemp
-d)
145 SESSION_NAME
="test_userspace_probe_unsupported_types"
146 # Userspace probe at an address or at an offset to a function
147 # instrumentation description types are not supported at the moment.
148 ENABLE_EXPR_1
="elf:$ELF_TEST_BIN:0x400030"
149 ENABLE_EXPR_2
="elf:$ELF_TEST_BIN:4194364"
150 ENABLE_EXPR_3
="elf:$ELF_TEST_BIN:$ELF_SYMBOL+0x21"
151 ENABLE_EXPR_4
="elf:$ELF_TEST_BIN:$ELF_SYMBOL+2"
153 diag
"Userspace probe enable with unsupported instrumentation description type"
155 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
157 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR_1" $PROBE_EVENT_NAME
158 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR_2" $PROBE_EVENT_NAME
159 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR_3" $PROBE_EVENT_NAME
160 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR_4" $PROBE_EVENT_NAME
162 destroy_lttng_session_ok
$SESSION_NAME
167 function test_userspace_probe_enable_implicit_probe_type
()
169 TRACE_PATH
=$
(mktemp
-d)
170 SESSION_NAME
="test_userspace_probe_enable_implicit_probe_type"
171 ENABLE_EXPR
="$ELF_TEST_BIN:$ELF_SYMBOL"
173 diag
"Userspace probe enabled successfully with implicit probe type"
175 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
177 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
179 validate_list
$SESSION_NAME $ELF_SYMBOL
180 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
181 validate_list
$SESSION_NAME "ELF"
182 validate_list
$SESSION_NAME "Function"
184 destroy_lttng_session_ok
$SESSION_NAME
189 function test_userspace_probe_enable_elf_symbol_exists
()
191 TRACE_PATH
=$
(mktemp
-d)
192 SESSION_NAME
="test_userspace_probe_enable_elf_symbol_exists"
193 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
195 diag
"Userspace probe enabled successfully"
197 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
199 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
201 validate_list
$SESSION_NAME $ELF_SYMBOL
202 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
203 validate_list
$SESSION_NAME "ELF"
204 validate_list
$SESSION_NAME "Function"
206 destroy_lttng_session_ok
$SESSION_NAME
211 function test_userspace_probe_enable_in_path
()
213 TRACE_PATH
=$
(mktemp
-d)
214 SESSION_NAME
="test_userspace_probe_enable_in_path"
215 ENABLE_EXPR
="elf:$ELF_TEST_BIN_NAME:$ELF_SYMBOL"
217 diag
"Userspace probe on binary in PATH enabled successfully"
219 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
221 # Save old PATH and add the test directory to the PATH.
223 export PATH
="$PATH:$(realpath $ELF_TEST_BIN_DIR)"
225 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
227 validate_list
$SESSION_NAME $ELF_SYMBOL
228 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
229 validate_list
$SESSION_NAME "ELF"
230 validate_list
$SESSION_NAME "Function"
232 # Reset the previously saved PATH.
233 export PATH
="$OLDPATH"
235 destroy_lttng_session_ok
$SESSION_NAME
240 function test_userspace_probe_enable_full_path
()
242 TRACE_PATH
=$
(mktemp
-d)
243 SESSION_NAME
="test_userspace_probe_enable_full_path"
244 ENABLE_EXPR
="elf:$(realpath $ELF_TEST_BIN):$ELF_SYMBOL"
245 diag
"Userspace probe with full path enabled successfully"
247 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
249 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
251 validate_list
$SESSION_NAME $ELF_SYMBOL
252 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
253 validate_list
$SESSION_NAME "ELF"
254 validate_list
$SESSION_NAME "Function"
256 destroy_lttng_session_ok
$SESSION_NAME
261 function test_userspace_probe_enable_colon_in_path
()
263 TRACE_PATH
=$
(mktemp
-d)
264 SESSION_NAME
="test_userspace_probe_enable_colon_in_path"
265 COLON_FILE_PATH
=$
(mktemp
-d)
266 ELF_BIN_SYMLINK
="$COLON_FILE_PATH/colon_:_in_name"
267 ELF_BIN_WITH_COLON_IN_NAME_ESCAPED
="$COLON_FILE_PATH/colon_\:_in_name"
268 ENABLE_EXPR
="elf:"$ELF_BIN_WITH_COLON_IN_NAME_ESCAPED":$ELF_SYMBOL"
270 ln -s $
(realpath
$ELF_TEST_BIN) $ELF_BIN_SYMLINK
272 diag
"Userspace probe with binary with colon in name enabled successfully"
274 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
276 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
278 validate_list
$SESSION_NAME $ELF_SYMBOL
279 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
280 validate_list
$SESSION_NAME "ELF"
281 validate_list
$SESSION_NAME "Function"
283 destroy_lttng_session_ok
$SESSION_NAME
286 rm -rf "$COLON_FILE_PATH"
289 function test_userspace_probe_elf
()
291 TRACE_PATH
=$
(mktemp
-d)
292 SESSION_NAME
="test_userprobe_elf"
293 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
295 diag
"Userspace probe on Elf symbol enabled and traced"
297 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
299 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
301 start_lttng_tracing_ok
$SESSION_NAME
302 eval "$ELF_TEST_BIN" > /dev
/null
303 stop_lttng_tracing_ok
$SESSION_NAME
305 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
307 destroy_lttng_session_ok
$SESSION_NAME
312 function test_userspace_probe_elf_dynamic_symbol
()
314 TRACE_PATH
=$
(mktemp
-d)
315 SESSION_NAME
="test_userprobe_elf"
316 LIBFOO_PATH
="$ELF_TEST_BIN_DIR/libfoo.so"
317 ENABLE_EXPR
="elf:$LIBFOO_PATH:dynamic_symbol"
319 diag
"Userspace probe on Elf dynamic symbol enabled and traced"
321 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
323 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
325 start_lttng_tracing_ok
$SESSION_NAME
326 eval "$ELF_TEST_BIN" > /dev
/null
327 stop_lttng_tracing_ok
$SESSION_NAME
329 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
331 destroy_lttng_session_ok
$SESSION_NAME
336 function test_userspace_probe_elf_cxx_function
()
338 TRACE_PATH
=$
(mktemp
-d)
339 SESSION_NAME
="test_userprobe_elf_cxx_function"
340 # Probing C++ mangled symbols should work the same way as regular Elf
342 ELF_SYMBOL_CXX
="_Z17test_cxx_functionv"
343 ENABLE_EXPR
="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
345 diag
"Userspace probe on C++ mangled function enabled and traced"
347 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
349 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
351 start_lttng_tracing_ok
$SESSION_NAME
352 eval "$ELF_CXX_TEST_BIN" > /dev
/null
353 stop_lttng_tracing_ok
$SESSION_NAME
355 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
357 destroy_lttng_session_ok
$SESSION_NAME
362 function test_userspace_probe_elf_cxx_method
()
364 TRACE_PATH
=$
(mktemp
-d)
365 SESSION_NAME
="test_userprobe_elf_cxx_method"
366 # Probing C++ mangled symbols should work the same way as regular Elf
368 ELF_SYMBOL_CXX
="_ZN10test_class11test_methodEv"
369 ENABLE_EXPR
="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
371 diag
"Userspace probe on C++ mangled method enabled and traced"
373 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
375 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
377 start_lttng_tracing_ok
$SESSION_NAME
378 eval "$ELF_CXX_TEST_BIN" > /dev
/null
379 stop_lttng_tracing_ok
$SESSION_NAME
381 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
383 destroy_lttng_session_ok
$SESSION_NAME
388 function test_userspace_probe_elf_disable
()
390 TRACE_PATH
=$
(mktemp
-d)
391 SESSION_NAME
="test_userprobe_elf_disable"
392 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
394 diag
"Userspace probe on Elf symbol disabled and traced"
396 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
398 # Activate and disable event
399 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
400 disable_kernel_lttng_userspace_probe_event_ok
$SESSION_NAME $PROBE_EVENT_NAME
402 start_lttng_tracing_ok
$SESSION_NAME
403 eval "$ELF_TEST_BIN" > /dev
/null
404 stop_lttng_tracing_ok
$SESSION_NAME
406 # Verify that the trace contains zero event.
407 validate_trace_empty
"$TRACE_PATH"
409 destroy_lttng_session_ok
$SESSION_NAME
414 function test_userspace_probe_elf_list
()
416 TRACE_PATH
=$
(mktemp
-d)
417 SESSION_NAME
="test_userprobe_elf_list"
418 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
420 diag
"Userspace probe ELF enabled and listed"
422 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
424 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
426 validate_list
$SESSION_NAME $PROBE_EVENT_NAME
427 validate_list
$SESSION_NAME $ELF_SYMBOL
428 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
429 validate_list
$SESSION_NAME "ELF"
430 validate_list
$SESSION_NAME "Function"
432 destroy_lttng_session_ok
$SESSION_NAME
437 function test_userspace_probe_save_load_elf
()
439 # Test that the load and save works for userspace probes AND that when
440 # a userspace probe is placed on a symlink by the user the save command
441 # saves the path to the link and not to the actual file. This is to
442 # support instrumentation of shared objects that are often accessed
443 # through symlinks and updated.
444 TRACE_PATH
=$
(mktemp
-d)
445 TMP_LINK_DIR
=$
(mktemp
-d)
446 TMP_SAVE_DIR
=$
(mktemp
-d)
448 SESSION_NAME
="test_userprobe_save_load_elf"
450 ELF_BIN_SYMLINK
="$TMP_LINK_DIR"/bin_elf_symlink
452 ENABLE_EXPR_ELF
="elf:$ELF_BIN_SYMLINK:$ELF_SYMBOL"
453 PROBE_EVENT_NAME_ELF
="$PROBE_EVENT_NAME"_elf
455 # Create symlinks to the target binaries.
456 ln -s $
(realpath
$ELF_TEST_BIN) $ELF_BIN_SYMLINK
458 diag
"Userspace probes Elf are saved and loaded"
460 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
462 # Enable userspace prove events.
463 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR_ELF" "$PROBE_EVENT_NAME_ELF"
465 # Confirm that the events were enabled.
466 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
468 # Save the session to a file.
469 lttng_save
$SESSION_NAME "--output-path=$TMP_SAVE_DIR"
471 destroy_lttng_session_ok
$SESSION_NAME
473 # Confirm that the userspace probe are save to the xml file.
474 local count
=$
(cat $TMP_SAVE_DIR/* |
grep --count -E "$ELF_BIN_SYMLINK")
475 if [[ $count -eq "1" ]]; then
476 pass
"Symlink found in saved session"
478 fail
"Symlink to binary not found in saved session"
481 # Load the saved session.
482 lttng_load_ok
"--input-path=$TMP_SAVE_DIR"
484 # Confirm that the userspace probes event are enabled in the newly
486 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
488 # Cleanup temp files and folders.
490 rm -rf "$TMP_LINK_DIR"
491 rm -rf "$TMP_SAVE_DIR"
493 function test_userspace_probe_save_load_sdt
()
495 # Test that the load and save works for userspace probes AND that when
496 # a userspace probe is placed on a symlink by the user the save command
497 # saves the path to the link and not to the actual file. This is to
498 # support instrumentation of shared objects that are often accessed
499 # through symlinks and updated.
500 TRACE_PATH
=$
(mktemp
-d)
501 TMP_LINK_DIR
=$
(mktemp
-d)
502 TMP_SAVE_DIR
=$
(mktemp
-d)
504 SESSION_NAME
="test_userprobe_save_load_sdt"
508 SDT_BIN_SYMLINK
="$TMP_LINK_DIR"/bin_sdt_symlink
510 ENABLE_EXPR_SDT
="sdt:$SDT_BIN_SYMLINK:$PROVIDER:$PROBE"
511 PROBE_EVENT_NAME_SDT
="$PROBE_EVENT_NAME"_sdt
513 # Create symlinks to the target binaries.
514 ln -s $
(realpath
$SDT_TEST_BIN) $SDT_BIN_SYMLINK
516 diag
"Userspace probes SDT are saved and loaded"
518 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
520 # Enable userspace prove events.
521 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR_SDT" "$PROBE_EVENT_NAME_SDT"
523 # Confirm that the events were enabled.
524 validate_list
$SESSION_NAME $SDT_TEST_BIN_NAME
526 # Save the session to a file.
527 lttng_save
$SESSION_NAME "--output-path=$TMP_SAVE_DIR"
529 destroy_lttng_session_ok
$SESSION_NAME
531 # Confirm that the userspace probe are save to the xml file.
532 local count
=$
(cat $TMP_SAVE_DIR/* |
grep --count -E "$SDT_BIN_SYMLINK")
533 if [[ $count -eq "1" ]]; then
534 pass
"Symlink found in saved session"
536 fail
"Symlink to binary not found in saved session"
539 # Load the saved session.
540 lttng_load_ok
"--input-path=$TMP_SAVE_DIR"
542 # Confirm that the userspace probes event are enabled in the newly
544 validate_list
$SESSION_NAME $SDT_TEST_BIN_NAME
546 # Cleanup temp files and folders.
548 rm -rf "$TMP_LINK_DIR"
549 rm -rf "$TMP_SAVE_DIR"
552 function test_userspace_probe_sdt
()
554 TRACE_PATH
=$
(mktemp
-d)
557 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
559 diag
"Userspace probe on SDT tracepoint enabled and traced"
561 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
563 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
565 start_lttng_tracing_ok
$SESSION_NAME
566 eval "$SDT_TEST_BIN" > /dev
/null
567 stop_lttng_tracing_ok
$SESSION_NAME
569 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
571 destroy_lttng_session_ok
$SESSION_NAME
576 function test_userspace_probe_sdt_list
()
578 TRACE_PATH
=$
(mktemp
-d)
579 SESSION_NAME
="test_userprobe_sdt_list"
582 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
584 diag
"Userspace probe SDT enabled and listed"
586 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
588 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
590 validate_list
$SESSION_NAME $PROBE_EVENT_NAME
591 validate_list
$SESSION_NAME $PROVIDER
592 validate_list
$SESSION_NAME $PROBE
593 validate_list
$SESSION_NAME $SDT_TEST_BIN_NAME
594 validate_list
$SESSION_NAME "SDT"
595 validate_list
$SESSION_NAME "Tracepoint"
597 destroy_lttng_session_ok
$SESSION_NAME
602 function test_userspace_probe_enable_sdt_nonexistant_provider
()
604 TRACE_PATH
=$
(mktemp
-d)
605 SESSION_NAME
="test_userprobe_sdt_nonexistand_provider"
606 PROVIDER
="not_provider"
608 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
610 diag
"Userspace probe SDT on tracepoint non existant provider"
612 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
614 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
616 destroy_lttng_session_ok
$SESSION_NAME
621 function test_userspace_probe_enable_sdt_nonexistant_probe
()
623 TRACE_PATH
=$
(mktemp
-d)
624 SESSION_NAME
="test_userprobe_sdt_nonexistant_probe"
626 PROBE
="not_a_tracepoint"
627 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
629 diag
"Userspace probe SDT on non existant probe"
631 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
633 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
635 destroy_lttng_session_ok
$SESSION_NAME
640 function test_userspace_probe_enable_sdt_with_sema
()
642 TRACE_PATH
=$
(mktemp
-d)
643 SESSION_NAME
="test_userprobe_sdt_with_sema"
645 PROBE
="tp_with_semaphore"
646 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
648 diag
"Userspace probe SDT on non existant probe"
650 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
652 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
654 destroy_lttng_session_ok
$SESSION_NAME
659 function test_userspace_probe_sdt_one_probe
()
661 TRACE_PATH
=$
(mktemp
-d)
662 SESSION_NAME
="test_userprobe_sdt_one_probe"
665 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
667 diag
"Userspace probe SDT on tracepoint with one callsite"
669 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
671 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
673 start_lttng_tracing_ok
$SESSION_NAME
674 eval "$SDT_TEST_BIN" > /dev
/null
675 stop_lttng_tracing_ok
$SESSION_NAME
677 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
679 destroy_lttng_session_ok
$SESSION_NAME
684 function test_userspace_probe_sdt_two_probes
()
686 TRACE_PATH
=$
(mktemp
-d)
687 SESSION_NAME
="test_userprobe_sdt_two_probes"
690 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
692 diag
"Userspace probe SDT on tracepoint with two callsites"
694 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
696 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
698 start_lttng_tracing_ok
$SESSION_NAME
699 eval "$SDT_TEST_BIN" > /dev
/null
700 stop_lttng_tracing_ok
$SESSION_NAME
702 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
704 destroy_lttng_session_ok
$SESSION_NAME
709 function test_userspace_probe_sdt_in_shared_object
()
711 TRACE_PATH
=$
(mktemp
-d)
712 SESSION_NAME
="test_userprobe_sdt_shared_object"
714 PROBE
="tp_in_shared_object"
715 ENABLE_EXPR
="sdt:$SDT_TEST_BIN_DIR/libfoo.so:$PROVIDER:$PROBE"
717 diag
"Userspace probe SDT on tracepoint in shared object"
719 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
721 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
723 start_lttng_tracing_ok
$SESSION_NAME
724 eval "$SDT_TEST_BIN" > /dev
/null
725 stop_lttng_tracing_ok
$SESSION_NAME
727 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
729 destroy_lttng_session_ok
$SESSION_NAME
734 function test_userspace_probe_sdt_in_shared_object_dlopen
()
736 TRACE_PATH
=$
(mktemp
-d)
737 SESSION_NAME
="test_userprobe_sdt_shared_object_dlopen"
740 ENABLE_EXPR
="sdt:$SDT_TEST_BIN_DIR/libbar.so:$PROVIDER:$PROBE"
742 diag
"Userspace probe SDT on tracepoint in dlopen()ed shared object"
744 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
746 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
748 start_lttng_tracing_ok
$SESSION_NAME
749 eval "$SDT_TEST_BIN" > /dev
/null
750 stop_lttng_tracing_ok
$SESSION_NAME
752 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
754 destroy_lttng_session_ok
$SESSION_NAME
759 function test_userspace_probe_sdt_in_shared_object_ldpreload
()
761 TRACE_PATH
=$
(mktemp
-d)
762 SESSION_NAME
="test_userprobe_sdt_shared_object_ldpreload"
764 PROBE
="tp_in_ldpreload"
765 ENABLE_EXPR
="sdt:$SDT_TEST_BIN_DIR/libzzz.so:$PROVIDER:$PROBE"
767 diag
"Userspace probe SDT on tracepoint in an LD_PRELOADed shared object"
769 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
771 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
773 start_lttng_tracing_ok
$SESSION_NAME
774 LD_PRELOAD
="$SDT_TEST_BIN_DIR/libzzz.so" eval "$SDT_TEST_BIN" > /dev
/null
775 stop_lttng_tracing_ok
$SESSION_NAME
777 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
779 destroy_lttng_session_ok
$SESSION_NAME
784 function test_userspace_probe_sdt_with_arg
()
786 TRACE_PATH
=$
(mktemp
-d)
787 SESSION_NAME
="test_userprobe_sdt_arg"
790 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
792 diag
"Userspace probe SDT on tracepoint with argument"
794 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
796 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
798 start_lttng_tracing_ok
$SESSION_NAME
799 eval "$SDT_TEST_BIN" > /dev
/null
800 stop_lttng_tracing_ok
$SESSION_NAME
802 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
804 destroy_lttng_session_ok
$SESSION_NAME
809 ls "$SDT_TEST_BIN" >/dev
/null
2>&1
810 if test $?
== 0; then
811 NUM_TESTS
=$
((NUM_TESTS
+68))
817 ls "$ELF_CXX_TEST_BIN" >/dev
/null
2>&1
818 if test $?
== 0; then
819 NUM_TESTS
=$
((NUM_TESTS
+12))
824 plan_tests
$NUM_TESTS
825 print_test_banner
"$TEST_DESC"
827 if [ "$(id -u)" == "0" ]; then
833 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
837 # Unsuccessful event enabling
838 test_userspace_probe_enable_file_noexist
839 test_userspace_probe_enable_file_not_elf
841 test_userspace_probe_enable_elf_missing_symbol_name
842 test_userspace_probe_enable_elf_nonexistant_symbol
843 test_userspace_probe_enable_elf_symbol_not_function
844 test_userspace_probe_unsupported_types
846 # Successful userspace probe elf enabling
847 test_userspace_probe_enable_implicit_probe_type
848 test_userspace_probe_enable_in_path
849 test_userspace_probe_enable_full_path
850 test_userspace_probe_enable_elf_symbol_exists
851 test_userspace_probe_enable_colon_in_path
853 # Successful tracing userspace probe elf
854 test_userspace_probe_elf
855 test_userspace_probe_elf_dynamic_symbol
857 # Disable userspace-probe elf
858 test_userspace_probe_elf_disable
860 # Successful listing of userspace probe elf
861 test_userspace_probe_elf_list
863 # Successful save and load of userspace probe elf
864 test_userspace_probe_save_load_elf
866 if test $RUN_ELF_CXX_TESTS == 1; then
867 # Successful tracing of userspace probe elf on C++ symbol
868 test_userspace_probe_elf_cxx_function
869 test_userspace_probe_elf_cxx_method
872 if test $RUN_SDT_TESTS == 1; then
873 # Unsuccessful event enabling
874 test_userspace_probe_enable_sdt_nonexistant_provider
875 test_userspace_probe_enable_sdt_nonexistant_probe
876 test_userspace_probe_enable_sdt_with_sema
878 # Successful userspace probe sdt enabling
879 test_userspace_probe_sdt_one_probe
880 test_userspace_probe_sdt_two_probes
881 test_userspace_probe_sdt_with_arg
882 test_userspace_probe_sdt_in_shared_object
883 test_userspace_probe_sdt_in_shared_object_dlopen
884 test_userspace_probe_sdt_in_shared_object_ldpreload
886 # Successful tracing of userspace probe sdt
887 test_userspace_probe_sdt
889 # Successful listing of userspace probe sdt
890 test_userspace_probe_sdt_list
892 # Successful save and load of userspace probe sdt
893 test_userspace_probe_save_load_sdt