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_enable_implicit_probe_type
()
144 TRACE_PATH
=$
(mktemp
-d)
145 SESSION_NAME
="test_userspace_probe_enable_implicit_probe_type"
146 ENABLE_EXPR
="$ELF_TEST_BIN:$ELF_SYMBOL"
148 diag
"Userspace probe enabled successfully with implicit probe type"
150 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
152 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
154 validate_list
$SESSION_NAME $ELF_SYMBOL
155 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
156 validate_list
$SESSION_NAME "ELF"
157 validate_list
$SESSION_NAME "Function"
159 destroy_lttng_session_ok
$SESSION_NAME
164 function test_userspace_probe_enable_elf_symbol_exists
()
166 TRACE_PATH
=$
(mktemp
-d)
167 SESSION_NAME
="test_userspace_probe_enable_elf_symbol_exists"
168 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
170 diag
"Userspace probe enabled successfully"
172 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
174 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
176 validate_list
$SESSION_NAME $ELF_SYMBOL
177 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
178 validate_list
$SESSION_NAME "ELF"
179 validate_list
$SESSION_NAME "Function"
181 destroy_lttng_session_ok
$SESSION_NAME
186 function test_userspace_probe_enable_in_path
()
188 TRACE_PATH
=$
(mktemp
-d)
189 SESSION_NAME
="test_userspace_probe_enable_in_path"
190 ENABLE_EXPR
="elf:$ELF_TEST_BIN_NAME:$ELF_SYMBOL"
192 diag
"Userspace probe on binary in PATH enabled successfully"
194 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
196 # Save old PATH and add the test directory to the PATH.
198 export PATH
="$PATH:$(realpath $ELF_TEST_BIN_DIR)"
200 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
202 validate_list
$SESSION_NAME $ELF_SYMBOL
203 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
204 validate_list
$SESSION_NAME "ELF"
205 validate_list
$SESSION_NAME "Function"
207 # Reset the previously saved PATH.
208 export PATH
="$OLDPATH"
210 destroy_lttng_session_ok
$SESSION_NAME
215 function test_userspace_probe_enable_full_path
()
217 TRACE_PATH
=$
(mktemp
-d)
218 SESSION_NAME
="test_userspace_probe_enable_full_path"
219 ENABLE_EXPR
="elf:$(realpath $ELF_TEST_BIN):$ELF_SYMBOL"
220 diag
"Userspace probe with full path enabled successfully"
222 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
224 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
226 validate_list
$SESSION_NAME $ELF_SYMBOL
227 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
228 validate_list
$SESSION_NAME "ELF"
229 validate_list
$SESSION_NAME "Function"
231 destroy_lttng_session_ok
$SESSION_NAME
236 function test_userspace_probe_enable_colon_in_path
()
238 TRACE_PATH
=$
(mktemp
-d)
239 SESSION_NAME
="test_userspace_probe_enable_colon_in_path"
240 COLON_FILE_PATH
=$
(mktemp
-d)
241 ELF_BIN_SYMLINK
="$COLON_FILE_PATH/colon_:_in_name"
242 ELF_BIN_WITH_COLON_IN_NAME_ESCAPED
="$COLON_FILE_PATH/colon_\:_in_name"
243 ENABLE_EXPR
="elf:"$ELF_BIN_WITH_COLON_IN_NAME_ESCAPED":$ELF_SYMBOL"
245 ln -s $
(realpath
$ELF_TEST_BIN) $ELF_BIN_SYMLINK
247 diag
"Userspace probe with binary with colon in name enabled successfully"
249 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
251 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
253 validate_list
$SESSION_NAME $ELF_SYMBOL
254 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
255 validate_list
$SESSION_NAME "ELF"
256 validate_list
$SESSION_NAME "Function"
258 destroy_lttng_session_ok
$SESSION_NAME
261 rm -rf "$COLON_FILE_PATH"
264 function test_userspace_probe_elf
()
266 TRACE_PATH
=$
(mktemp
-d)
267 SESSION_NAME
="test_userprobe_elf"
268 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
270 diag
"Userspace probe on Elf symbol enabled and traced"
272 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
274 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
276 start_lttng_tracing_ok
$SESSION_NAME
277 eval "$ELF_TEST_BIN" > /dev
/null
278 stop_lttng_tracing_ok
$SESSION_NAME
280 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
282 destroy_lttng_session_ok
$SESSION_NAME
287 function test_userspace_probe_elf_dynamic_symbol
()
289 TRACE_PATH
=$
(mktemp
-d)
290 SESSION_NAME
="test_userprobe_elf"
291 LIBFOO_PATH
="$ELF_TEST_BIN_DIR/libfoo.so"
292 ENABLE_EXPR
="elf:$LIBFOO_PATH:dynamic_symbol"
294 diag
"Userspace probe on Elf dynamic symbol enabled and traced"
296 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
298 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
300 start_lttng_tracing_ok
$SESSION_NAME
301 eval "$ELF_TEST_BIN" > /dev
/null
302 stop_lttng_tracing_ok
$SESSION_NAME
304 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
306 destroy_lttng_session_ok
$SESSION_NAME
311 function test_userspace_probe_elf_cxx_function
()
313 TRACE_PATH
=$
(mktemp
-d)
314 SESSION_NAME
="test_userprobe_elf_cxx_function"
315 # Probing C++ mangled symbols should work the same way as regular Elf
317 ELF_SYMBOL_CXX
="_Z17test_cxx_functionv"
318 ENABLE_EXPR
="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
320 diag
"Userspace probe on C++ mangled function enabled and traced"
322 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
324 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
326 start_lttng_tracing_ok
$SESSION_NAME
327 eval "$ELF_CXX_TEST_BIN" > /dev
/null
328 stop_lttng_tracing_ok
$SESSION_NAME
330 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
332 destroy_lttng_session_ok
$SESSION_NAME
337 function test_userspace_probe_elf_cxx_method
()
339 TRACE_PATH
=$
(mktemp
-d)
340 SESSION_NAME
="test_userprobe_elf_cxx_method"
341 # Probing C++ mangled symbols should work the same way as regular Elf
343 ELF_SYMBOL_CXX
="_ZN10test_class11test_methodEv"
344 ENABLE_EXPR
="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
346 diag
"Userspace probe on C++ mangled method enabled and traced"
348 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
350 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
352 start_lttng_tracing_ok
$SESSION_NAME
353 eval "$ELF_CXX_TEST_BIN" > /dev
/null
354 stop_lttng_tracing_ok
$SESSION_NAME
356 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
358 destroy_lttng_session_ok
$SESSION_NAME
363 function test_userspace_probe_elf_disable
()
365 TRACE_PATH
=$
(mktemp
-d)
366 SESSION_NAME
="test_userprobe_elf_disable"
367 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
369 diag
"Userspace probe on Elf symbol disabled and traced"
371 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
373 # Activate and disable event
374 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
375 disable_kernel_lttng_userspace_probe_event_ok
$SESSION_NAME $PROBE_EVENT_NAME
377 start_lttng_tracing_ok
$SESSION_NAME
378 eval "$ELF_TEST_BIN" > /dev
/null
379 stop_lttng_tracing_ok
$SESSION_NAME
381 # Verify that the trace contains zero event.
382 validate_trace_empty
"$TRACE_PATH"
384 destroy_lttng_session_ok
$SESSION_NAME
389 function test_userspace_probe_elf_list
()
391 TRACE_PATH
=$
(mktemp
-d)
392 SESSION_NAME
="test_userprobe_elf_list"
393 ENABLE_EXPR
="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
395 diag
"Userspace probe ELF enabled and listed"
397 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
399 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
401 validate_list
$SESSION_NAME $PROBE_EVENT_NAME
402 validate_list
$SESSION_NAME $ELF_SYMBOL
403 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
404 validate_list
$SESSION_NAME "ELF"
405 validate_list
$SESSION_NAME "Function"
407 destroy_lttng_session_ok
$SESSION_NAME
412 function test_userspace_probe_save_load_elf
()
414 # Test that the load and save works for userspace probes AND that when
415 # a userspace probe is placed on a symlink by the user the save command
416 # saves the path to the link and not to the actual file. This is to
417 # support instrumentation of shared objects that are often accessed
418 # through symlinks and updated.
419 TRACE_PATH
=$
(mktemp
-d)
420 TMP_LINK_DIR
=$
(mktemp
-d)
421 TMP_SAVE_DIR
=$
(mktemp
-d)
423 SESSION_NAME
="test_userprobe_save_load_elf"
425 ELF_BIN_SYMLINK
="$TMP_LINK_DIR"/bin_elf_symlink
427 ENABLE_EXPR_ELF
="elf:$ELF_BIN_SYMLINK:$ELF_SYMBOL"
428 PROBE_EVENT_NAME_ELF
="$PROBE_EVENT_NAME"_elf
430 # Create symlinks to the target binaries.
431 ln -s $
(realpath
$ELF_TEST_BIN) $ELF_BIN_SYMLINK
433 diag
"Userspace probes Elf are saved and loaded"
435 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
437 # Enable userspace prove events.
438 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR_ELF" "$PROBE_EVENT_NAME_ELF"
440 # Confirm that the events were enabled.
441 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
443 # Save the session to a file.
444 lttng_save
$SESSION_NAME "--output-path=$TMP_SAVE_DIR"
446 destroy_lttng_session_ok
$SESSION_NAME
448 # Confirm that the userspace probe are save to the xml file.
449 local count
=$
(cat $TMP_SAVE_DIR/* |
grep --count -E "$ELF_BIN_SYMLINK")
450 if [[ $count -eq "1" ]]; then
451 pass
"Symlink found in saved session"
453 fail
"Symlink to binary not found in saved session"
456 # Load the saved session.
457 lttng_load_ok
"--input-path=$TMP_SAVE_DIR"
459 # Confirm that the userspace probes event are enabled in the newly
461 validate_list
$SESSION_NAME $ELF_TEST_BIN_NAME
463 # Cleanup temp files and folders.
465 rm -rf "$TMP_LINK_DIR"
466 rm -rf "$TMP_SAVE_DIR"
468 function test_userspace_probe_save_load_sdt
()
470 # Test that the load and save works for userspace probes AND that when
471 # a userspace probe is placed on a symlink by the user the save command
472 # saves the path to the link and not to the actual file. This is to
473 # support instrumentation of shared objects that are often accessed
474 # through symlinks and updated.
475 TRACE_PATH
=$
(mktemp
-d)
476 TMP_LINK_DIR
=$
(mktemp
-d)
477 TMP_SAVE_DIR
=$
(mktemp
-d)
479 SESSION_NAME
="test_userprobe_save_load_sdt"
483 SDT_BIN_SYMLINK
="$TMP_LINK_DIR"/bin_sdt_symlink
485 ENABLE_EXPR_SDT
="sdt:$SDT_BIN_SYMLINK:$PROVIDER:$PROBE"
486 PROBE_EVENT_NAME_SDT
="$PROBE_EVENT_NAME"_sdt
488 # Create symlinks to the target binaries.
489 ln -s $
(realpath
$SDT_TEST_BIN) $SDT_BIN_SYMLINK
491 diag
"Userspace probes SDT are saved and loaded"
493 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
495 # Enable userspace prove events.
496 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR_SDT" "$PROBE_EVENT_NAME_SDT"
498 # Confirm that the events were enabled.
499 validate_list
$SESSION_NAME $SDT_TEST_BIN_NAME
501 # Save the session to a file.
502 lttng_save
$SESSION_NAME "--output-path=$TMP_SAVE_DIR"
504 destroy_lttng_session_ok
$SESSION_NAME
506 # Confirm that the userspace probe are save to the xml file.
507 local count
=$
(cat $TMP_SAVE_DIR/* |
grep --count -E "$SDT_BIN_SYMLINK")
508 if [[ $count -eq "1" ]]; then
509 pass
"Symlink found in saved session"
511 fail
"Symlink to binary not found in saved session"
514 # Load the saved session.
515 lttng_load_ok
"--input-path=$TMP_SAVE_DIR"
517 # Confirm that the userspace probes event are enabled in the newly
519 validate_list
$SESSION_NAME $SDT_TEST_BIN_NAME
521 # Cleanup temp files and folders.
523 rm -rf "$TMP_LINK_DIR"
524 rm -rf "$TMP_SAVE_DIR"
527 function test_userspace_probe_sdt
()
529 TRACE_PATH
=$
(mktemp
-d)
532 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
534 diag
"Userspace probe on SDT tracepoint enabled and traced"
536 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
538 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
540 start_lttng_tracing_ok
$SESSION_NAME
541 eval "$SDT_TEST_BIN" > /dev
/null
542 stop_lttng_tracing_ok
$SESSION_NAME
544 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
546 destroy_lttng_session_ok
$SESSION_NAME
551 function test_userspace_probe_sdt_list
()
553 TRACE_PATH
=$
(mktemp
-d)
554 SESSION_NAME
="test_userprobe_sdt_list"
557 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
559 diag
"Userspace probe SDT enabled and listed"
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 validate_list
$SESSION_NAME $PROBE_EVENT_NAME
566 validate_list
$SESSION_NAME $PROVIDER
567 validate_list
$SESSION_NAME $PROBE
568 validate_list
$SESSION_NAME $SDT_TEST_BIN_NAME
569 validate_list
$SESSION_NAME "SDT"
570 validate_list
$SESSION_NAME "Tracepoint"
572 destroy_lttng_session_ok
$SESSION_NAME
577 function test_userspace_probe_enable_sdt_nonexistant_provider
()
579 TRACE_PATH
=$
(mktemp
-d)
580 SESSION_NAME
="test_userprobe_sdt_nonexistand_provider"
581 PROVIDER
="not_provider"
583 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
585 diag
"Userspace probe SDT on tracepoint non existant provider"
587 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
589 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
591 destroy_lttng_session_ok
$SESSION_NAME
596 function test_userspace_probe_enable_sdt_nonexistant_probe
()
598 TRACE_PATH
=$
(mktemp
-d)
599 SESSION_NAME
="test_userprobe_sdt_nonexistant_probe"
601 PROBE
="not_a_tracepoint"
602 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
604 diag
"Userspace probe SDT on non existant probe"
606 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
608 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
610 destroy_lttng_session_ok
$SESSION_NAME
615 function test_userspace_probe_enable_sdt_with_sema
()
617 TRACE_PATH
=$
(mktemp
-d)
618 SESSION_NAME
="test_userprobe_sdt_with_sema"
620 PROBE
="tp_with_semaphore"
621 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
623 diag
"Userspace probe SDT on non existant probe"
625 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
627 lttng_enable_kernel_userspace_probe_event_fail
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
629 destroy_lttng_session_ok
$SESSION_NAME
634 function test_userspace_probe_sdt_one_probe
()
636 TRACE_PATH
=$
(mktemp
-d)
637 SESSION_NAME
="test_userprobe_sdt_one_probe"
640 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
642 diag
"Userspace probe SDT on tracepoint with one callsite"
644 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
646 lttng_enable_kernel_userspace_probe_event_ok
$SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
648 start_lttng_tracing_ok
$SESSION_NAME
649 eval "$SDT_TEST_BIN" > /dev
/null
650 stop_lttng_tracing_ok
$SESSION_NAME
652 validate_trace
$PROBE_EVENT_NAME "$TRACE_PATH"
654 destroy_lttng_session_ok
$SESSION_NAME
659 function test_userspace_probe_sdt_two_probes
()
661 TRACE_PATH
=$
(mktemp
-d)
662 SESSION_NAME
="test_userprobe_sdt_two_probes"
665 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
667 diag
"Userspace probe SDT on tracepoint with two callsites"
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_in_shared_object
()
686 TRACE_PATH
=$
(mktemp
-d)
687 SESSION_NAME
="test_userprobe_sdt_shared_object"
689 PROBE
="tp_in_shared_object"
690 ENABLE_EXPR
="sdt:$SDT_TEST_BIN_DIR/libfoo.so:$PROVIDER:$PROBE"
692 diag
"Userspace probe SDT on tracepoint in shared object"
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_dlopen
()
711 TRACE_PATH
=$
(mktemp
-d)
712 SESSION_NAME
="test_userprobe_sdt_shared_object_dlopen"
715 ENABLE_EXPR
="sdt:$SDT_TEST_BIN_DIR/libbar.so:$PROVIDER:$PROBE"
717 diag
"Userspace probe SDT on tracepoint in dlopen()ed 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_ldpreload
()
736 TRACE_PATH
=$
(mktemp
-d)
737 SESSION_NAME
="test_userprobe_sdt_shared_object_ldpreload"
739 PROBE
="tp_in_ldpreload"
740 ENABLE_EXPR
="sdt:$SDT_TEST_BIN_DIR/libzzz.so:$PROVIDER:$PROBE"
742 diag
"Userspace probe SDT on tracepoint in an LD_PRELOADed 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 LD_PRELOAD
="$SDT_TEST_BIN_DIR/libzzz.so" 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_with_arg
()
761 TRACE_PATH
=$
(mktemp
-d)
762 SESSION_NAME
="test_userprobe_sdt_arg"
765 ENABLE_EXPR
="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
767 diag
"Userspace probe SDT on tracepoint with argument"
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 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 ls "$SDT_TEST_BIN" >/dev
/null
2>&1
785 if test $?
== 0; then
786 NUM_TESTS
=$
((NUM_TESTS
+68))
792 ls "$ELF_CXX_TEST_BIN" >/dev
/null
2>&1
793 if test $?
== 0; then
794 NUM_TESTS
=$
((NUM_TESTS
+12))
799 plan_tests
$NUM_TESTS
800 print_test_banner
"$TEST_DESC"
802 if [ "$(id -u)" == "0" ]; then
808 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
812 # Unsuccessful event enabling
813 test_userspace_probe_enable_file_noexist
814 test_userspace_probe_enable_file_not_elf
816 test_userspace_probe_enable_elf_missing_symbol_name
817 test_userspace_probe_enable_elf_nonexistant_symbol
818 test_userspace_probe_enable_elf_symbol_not_function
820 # Successful userspace probe elf enabling
821 test_userspace_probe_enable_implicit_probe_type
822 test_userspace_probe_enable_in_path
823 test_userspace_probe_enable_full_path
824 test_userspace_probe_enable_elf_symbol_exists
825 test_userspace_probe_enable_colon_in_path
827 # Successful tracing userspace probe elf
828 test_userspace_probe_elf
829 test_userspace_probe_elf_dynamic_symbol
831 # Disable userspace-probe elf
832 test_userspace_probe_elf_disable
834 # Successful listing of userspace probe elf
835 test_userspace_probe_elf_list
837 # Successful save and load of userspace probe elf
838 test_userspace_probe_save_load_elf
840 if test $RUN_ELF_CXX_TESTS == 1; then
841 # Successful tracing of userspace probe elf on C++ symbol
842 test_userspace_probe_elf_cxx_function
843 test_userspace_probe_elf_cxx_method
846 if test $RUN_SDT_TESTS == 1; then
847 # Unsuccessful event enabling
848 test_userspace_probe_enable_sdt_nonexistant_provider
849 test_userspace_probe_enable_sdt_nonexistant_probe
850 test_userspace_probe_enable_sdt_with_sema
852 # Successful userspace probe sdt enabling
853 test_userspace_probe_sdt_one_probe
854 test_userspace_probe_sdt_two_probes
855 test_userspace_probe_sdt_with_arg
856 test_userspace_probe_sdt_in_shared_object
857 test_userspace_probe_sdt_in_shared_object_dlopen
858 test_userspace_probe_sdt_in_shared_object_ldpreload
860 # Successful tracing of userspace probe sdt
861 test_userspace_probe_sdt
863 # Successful listing of userspace probe sdt
864 test_userspace_probe_sdt_list
866 # Successful save and load of userspace probe sdt
867 test_userspace_probe_save_load_sdt