scope-exit: Clarify scope_exit noexcept requirement
[lttng-tools.git] / tests / regression / kernel / test_userspace_probe
1 #!/bin/bash
2 #
3 # Copyright (C) 2017 Erica Bugden <erica.bugden@efficios.com>
4 # Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
5 #
6 # SPDX-License-Identifier: LGPL-2.1-only
7 #
8
9 TEST_DESC="Userspace probe - Testing userspace probe on ELF symbol"
10
11 CURDIR=$(dirname "$0")/
12 TESTDIR=$CURDIR/../..
13 TESTAPP_DIR="$TESTDIR/utils/testapp/"
14 ELF_TEST_BIN_DIR="$TESTAPP_DIR/userspace-probe-elf-binary/.libs/"
15 ELF_TEST_BIN_NAME="userspace-probe-elf-binary"
16 ELF_TEST_BIN="$ELF_TEST_BIN_DIR/$ELF_TEST_BIN_NAME"
17 ELF_CXX_TEST_BIN_DIR="$TESTAPP_DIR/userspace-probe-elf-cxx-binary/"
18 ELF_CXX_TEST_BIN_NAME="userspace-probe-elf-cxx-binary"
19 ELF_CXX_TEST_BIN="$ELF_CXX_TEST_BIN_DIR/$ELF_CXX_TEST_BIN_NAME"
20 SDT_TEST_BIN_DIR="$TESTAPP_DIR/userspace-probe-sdt-binary/.libs/"
21 SDT_TEST_BIN_NAME="userspace-probe-sdt-binary"
22 SDT_TEST_BIN="$SDT_TEST_BIN_DIR/$SDT_TEST_BIN_NAME"
23 ELF_SYMBOL="test_function"
24 PROBE_EVENT_NAME=userspace_probe_test_event
25 NUM_TESTS=93
26 OUTPUT_DEST=/dev/null
27 ERROR_OUTPUT_DEST=/dev/null
28
29 source "$TESTDIR/utils/utils.sh"
30
31 function 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
45 function test_userspace_probe_enable_file_noexist ()
46 {
47 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
62 function test_userspace_probe_enable_file_not_elf ()
63 {
64 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
79 function test_userspace_probe_enable_elf_missing_symbol_name ()
80 {
81 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
96 function test_userspace_probe_enable_elf_nonexistant_symbol ()
97 {
98 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
114 function test_userspace_probe_enable_elf_symbol_not_function ()
115 {
116 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
132 function test_userspace_probe_unsupported_types ()
133 {
134 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
157 function test_userspace_probe_enable_implicit_probe_type ()
158 {
159 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
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"
173
174 destroy_lttng_session_ok $SESSION_NAME
175
176 rm -rf "$TRACE_PATH"
177 }
178
179 function test_userspace_probe_enable_elf_symbol_exists ()
180 {
181 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
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"
195
196 destroy_lttng_session_ok $SESSION_NAME
197
198 rm -rf "$TRACE_PATH"
199 }
200
201 function test_userspace_probe_enable_in_path ()
202 {
203 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
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"
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
230 function test_userspace_probe_enable_full_path ()
231 {
232 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
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"
245
246 destroy_lttng_session_ok $SESSION_NAME
247
248 rm -rf "$TRACE_PATH"
249 }
250
251 function test_userspace_probe_enable_colon_in_path ()
252 {
253 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
254 SESSION_NAME="test_userspace_probe_enable_colon_in_path"
255 COLON_FILE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
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"
272
273 destroy_lttng_session_ok $SESSION_NAME
274
275 rm -rf "$TRACE_PATH"
276 rm -rf "$COLON_FILE_PATH"
277 }
278
279 function test_userspace_probe_elf ()
280 {
281 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
292 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-elf-binary/.libs" "$ELF_TEST_BIN" > /dev/null
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
302 function test_userspace_probe_elf_dynamic_symbol ()
303 {
304 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
316 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-elf-binary/.libs" "$ELF_TEST_BIN" > /dev/null
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
326 function test_userspace_probe_elf_cxx_function ()
327 {
328 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
342 eval "$ELF_CXX_TEST_BIN" > /dev/null
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
352 function test_userspace_probe_elf_cxx_method ()
353 {
354 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
368 eval "$ELF_CXX_TEST_BIN" > /dev/null
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
378 function test_userspace_probe_elf_disable ()
379 {
380 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
393 eval "$ELF_TEST_BIN" > /dev/null
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
404 function test_userspace_probe_elf_list ()
405 {
406 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
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"
421
422 destroy_lttng_session_ok $SESSION_NAME
423
424 rm -rf "$TRACE_PATH"
425 }
426
427 function 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.
434 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
435 TMP_LINK_DIR=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
436 TMP_SAVE_DIR=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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 }
483 function 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.
490 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
491 TMP_LINK_DIR=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
492 TMP_SAVE_DIR=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
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
542 function test_userspace_probe_sdt ()
543 {
544 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
545 PROVIDER="foobar"
546 PROBE="tp1"
547 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
548 SESSION_NAME="${FUNCNAME[0]}"
549
550 diag "Userspace probe on SDT tracepoint enabled and traced"
551
552 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
553
554 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
555
556 start_lttng_tracing_ok $SESSION_NAME
557 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null
558 stop_lttng_tracing_ok $SESSION_NAME
559
560 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
561
562 destroy_lttng_session_ok $SESSION_NAME
563
564 rm -rf "$TRACE_PATH"
565 }
566
567 function test_userspace_probe_sdt_list ()
568 {
569 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
570 SESSION_NAME="test_userprobe_sdt_list"
571 PROVIDER="foobar"
572 PROBE="tp1"
573 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
574
575 diag "Userspace probe SDT enabled and listed"
576
577 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
578
579 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
580
581 validate_list $SESSION_NAME $PROBE_EVENT_NAME
582 validate_list $SESSION_NAME $PROVIDER
583 validate_list $SESSION_NAME $PROBE
584 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
585 validate_list $SESSION_NAME "SDT"
586 validate_list $SESSION_NAME "Tracepoint"
587
588 destroy_lttng_session_ok $SESSION_NAME
589
590 rm -rf "$TRACE_PATH"
591 }
592
593 function test_userspace_probe_enable_sdt_nonexistant_provider ()
594 {
595 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
596 SESSION_NAME="test_userprobe_sdt_nonexistand_provider"
597 PROVIDER="not_provider"
598 PROBE="tp1"
599 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
600
601 diag "Userspace probe SDT on tracepoint non existant provider"
602
603 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
604
605 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
606
607 destroy_lttng_session_ok $SESSION_NAME
608
609 rm -rf "$TRACE_PATH"
610 }
611
612 function test_userspace_probe_enable_sdt_nonexistant_probe ()
613 {
614 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
615 SESSION_NAME="test_userprobe_sdt_nonexistant_probe"
616 PROVIDER="foobar"
617 PROBE="not_a_tracepoint"
618 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
619
620 diag "Userspace probe SDT on non existant probe"
621
622 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
623
624 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
625
626 destroy_lttng_session_ok $SESSION_NAME
627
628 rm -rf "$TRACE_PATH"
629 }
630
631 function test_userspace_probe_enable_sdt_with_sema ()
632 {
633 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
634 SESSION_NAME="test_userprobe_sdt_with_sema"
635 PROVIDER="foobar"
636 PROBE="tp_with_semaphore"
637 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
638
639 diag "Userspace probe SDT on non existant probe"
640
641 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
642
643 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
644
645 destroy_lttng_session_ok $SESSION_NAME
646
647 rm -rf "$TRACE_PATH"
648 }
649
650 function test_userspace_probe_sdt_one_probe ()
651 {
652 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
653 SESSION_NAME="test_userprobe_sdt_one_probe"
654 PROVIDER="foobar"
655 PROBE="tp1"
656 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
657
658 diag "Userspace probe SDT on tracepoint with one callsite"
659
660 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
661
662 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
663
664 start_lttng_tracing_ok $SESSION_NAME
665 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null
666 stop_lttng_tracing_ok $SESSION_NAME
667
668 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
669
670 destroy_lttng_session_ok $SESSION_NAME
671
672 rm -rf "$TRACE_PATH"
673 }
674
675 function test_userspace_probe_sdt_two_probes ()
676 {
677 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
678 SESSION_NAME="test_userprobe_sdt_two_probes"
679 PROVIDER="foobar"
680 PROBE="tp2"
681 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
682
683 diag "Userspace probe SDT on tracepoint with two callsites"
684
685 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
686
687 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
688
689 start_lttng_tracing_ok $SESSION_NAME
690 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null
691 stop_lttng_tracing_ok $SESSION_NAME
692
693 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
694
695 destroy_lttng_session_ok $SESSION_NAME
696
697 rm -rf "$TRACE_PATH"
698 }
699
700 function test_userspace_probe_sdt_in_shared_object ()
701 {
702 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
703 SESSION_NAME="test_userprobe_sdt_shared_object"
704 PROVIDER="foobar"
705 PROBE="tp_in_shared_object"
706 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libfoo.so:$PROVIDER:$PROBE"
707
708 diag "Userspace probe SDT on tracepoint in shared object"
709
710 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
711
712 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
713
714 start_lttng_tracing_ok $SESSION_NAME
715 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null
716 stop_lttng_tracing_ok $SESSION_NAME
717
718 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
719
720 destroy_lttng_session_ok $SESSION_NAME
721
722 rm -rf "$TRACE_PATH"
723 }
724
725 function test_userspace_probe_sdt_in_shared_object_dlopen ()
726 {
727 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
728 SESSION_NAME="test_userprobe_sdt_shared_object_dlopen"
729 PROVIDER="foobar"
730 PROBE="tp_in_dlopen"
731 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libbar.so:$PROVIDER:$PROBE"
732
733 diag "Userspace probe SDT on tracepoint in dlopen()ed shared object"
734
735 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
736
737 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
738
739 start_lttng_tracing_ok $SESSION_NAME
740 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null
741 stop_lttng_tracing_ok $SESSION_NAME
742
743 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
744
745 destroy_lttng_session_ok $SESSION_NAME
746
747 rm -rf "$TRACE_PATH"
748 }
749
750 function test_userspace_probe_sdt_in_shared_object_ldpreload ()
751 {
752 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
753 SESSION_NAME="test_userprobe_sdt_shared_object_ldpreload"
754 PROVIDER="foobar"
755 PROBE="tp_in_ldpreload"
756 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libzzz.so:$PROVIDER:$PROBE"
757
758 diag "Userspace probe SDT on tracepoint in an LD_PRELOADed shared object"
759
760 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
761
762 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
763
764 start_lttng_tracing_ok $SESSION_NAME
765 LD_PRELOAD="$SDT_TEST_BIN_DIR/libzzz.so" LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null
766 stop_lttng_tracing_ok $SESSION_NAME
767
768 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
769
770 destroy_lttng_session_ok $SESSION_NAME
771
772 rm -rf "$TRACE_PATH"
773 }
774
775 function test_userspace_probe_sdt_with_arg ()
776 {
777 TRACE_PATH=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
778 SESSION_NAME="test_userprobe_sdt_arg"
779 PROVIDER="foobar"
780 PROBE="tp_with_arg"
781 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
782
783 diag "Userspace probe SDT on tracepoint with argument"
784
785 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
786
787 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
788
789 start_lttng_tracing_ok $SESSION_NAME
790 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-sdt-binary/.libs" "$SDT_TEST_BIN" > /dev/null
791 stop_lttng_tracing_ok $SESSION_NAME
792
793 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
794
795 destroy_lttng_session_ok $SESSION_NAME
796
797 rm -rf "$TRACE_PATH"
798 }
799
800 ls "$SDT_TEST_BIN" >/dev/null 2>&1
801 if test $? == 0; then
802 NUM_TESTS=$((NUM_TESTS+68))
803 RUN_SDT_TESTS=1
804 else
805 RUN_SDT_TESTS=0
806 fi
807
808 ls "$ELF_CXX_TEST_BIN" >/dev/null 2>&1
809 if test $? == 0; then
810 NUM_TESTS=$((NUM_TESTS+12))
811 RUN_ELF_CXX_TESTS=1
812 else
813 RUN_ELF_CXX_TESTS=0
814 fi
815 plan_tests $NUM_TESTS
816 print_test_banner "$TEST_DESC"
817
818 check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
819 {
820 validate_lttng_modules_present
821 start_lttng_sessiond
822
823 # Unsuccessful event enabling
824 test_userspace_probe_enable_file_noexist
825 test_userspace_probe_enable_file_not_elf
826
827 test_userspace_probe_enable_elf_missing_symbol_name
828 test_userspace_probe_enable_elf_nonexistant_symbol
829 test_userspace_probe_enable_elf_symbol_not_function
830 test_userspace_probe_unsupported_types
831
832 # Successful userspace probe elf enabling
833 test_userspace_probe_enable_implicit_probe_type
834 test_userspace_probe_enable_in_path
835 test_userspace_probe_enable_full_path
836 test_userspace_probe_enable_elf_symbol_exists
837 test_userspace_probe_enable_colon_in_path
838
839 # Successful tracing userspace probe elf
840 test_userspace_probe_elf
841 test_userspace_probe_elf_dynamic_symbol
842
843 # Disable userspace-probe elf
844 test_userspace_probe_elf_disable
845
846 # Successful listing of userspace probe elf
847 test_userspace_probe_elf_list
848
849 # Successful save and load of userspace probe elf
850 test_userspace_probe_save_load_elf
851
852 if test $RUN_ELF_CXX_TESTS == 1; then
853 # Successful tracing of userspace probe elf on C++ symbol
854 test_userspace_probe_elf_cxx_function
855 test_userspace_probe_elf_cxx_method
856 fi
857
858 if test $RUN_SDT_TESTS == 1; then
859 # Unsuccessful event enabling
860 test_userspace_probe_enable_sdt_nonexistant_provider
861 test_userspace_probe_enable_sdt_nonexistant_probe
862 test_userspace_probe_enable_sdt_with_sema
863
864 # Successful userspace probe sdt enabling
865 test_userspace_probe_sdt_one_probe
866 test_userspace_probe_sdt_two_probes
867 test_userspace_probe_sdt_with_arg
868 test_userspace_probe_sdt_in_shared_object
869 test_userspace_probe_sdt_in_shared_object_dlopen
870 test_userspace_probe_sdt_in_shared_object_ldpreload
871
872 # Successful tracing of userspace probe sdt
873 test_userspace_probe_sdt
874
875 # Successful listing of userspace probe sdt
876 test_userspace_probe_sdt_list
877
878 # Successful save and load of userspace probe sdt
879 test_userspace_probe_save_load_sdt
880 fi
881
882 stop_lttng_sessiond
883 }
This page took 0.058701 seconds and 4 git commands to generate.