Introduce emission site for syscall event rule
[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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
254 SESSION_NAME="test_userspace_probe_enable_colon_in_path"
255 COLON_FILE_PATH=$(mktemp -d)
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)
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 eval "$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)
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 eval "$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)
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)
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)
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)
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)
435 TMP_LINK_DIR=$(mktemp -d)
436 TMP_SAVE_DIR=$(mktemp -d)
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)
491 TMP_LINK_DIR=$(mktemp -d)
492 TMP_SAVE_DIR=$(mktemp -d)
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)
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
556 eval "$SDT_TEST_BIN" > /dev/null
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
566 function test_userspace_probe_sdt_list ()
567 {
568 TRACE_PATH=$(mktemp -d)
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
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"
586
587 destroy_lttng_session_ok $SESSION_NAME
588
589 rm -rf "$TRACE_PATH"
590 }
591
592 function test_userspace_probe_enable_sdt_nonexistant_provider ()
593 {
594 TRACE_PATH=$(mktemp -d)
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
611 function test_userspace_probe_enable_sdt_nonexistant_probe ()
612 {
613 TRACE_PATH=$(mktemp -d)
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
630 function test_userspace_probe_enable_sdt_with_sema ()
631 {
632 TRACE_PATH=$(mktemp -d)
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
649 function test_userspace_probe_sdt_one_probe ()
650 {
651 TRACE_PATH=$(mktemp -d)
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
664 eval "$SDT_TEST_BIN" > /dev/null
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
674 function test_userspace_probe_sdt_two_probes ()
675 {
676 TRACE_PATH=$(mktemp -d)
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
689 eval "$SDT_TEST_BIN" > /dev/null
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
699 function test_userspace_probe_sdt_in_shared_object ()
700 {
701 TRACE_PATH=$(mktemp -d)
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
714 eval "$SDT_TEST_BIN" > /dev/null
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
724 function test_userspace_probe_sdt_in_shared_object_dlopen ()
725 {
726 TRACE_PATH=$(mktemp -d)
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
739 eval "$SDT_TEST_BIN" > /dev/null
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
749 function test_userspace_probe_sdt_in_shared_object_ldpreload ()
750 {
751 TRACE_PATH=$(mktemp -d)
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
764 LD_PRELOAD="$SDT_TEST_BIN_DIR/libzzz.so" eval "$SDT_TEST_BIN" > /dev/null
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
774 function test_userspace_probe_sdt_with_arg ()
775 {
776 TRACE_PATH=$(mktemp -d)
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
789 eval "$SDT_TEST_BIN" > /dev/null
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
799 ls "$SDT_TEST_BIN" >/dev/null 2>&1
800 if test $? == 0; then
801 NUM_TESTS=$((NUM_TESTS+68))
802 RUN_SDT_TESTS=1
803 else
804 RUN_SDT_TESTS=0
805 fi
806
807 ls "$ELF_CXX_TEST_BIN" >/dev/null 2>&1
808 if test $? == 0; then
809 NUM_TESTS=$((NUM_TESTS+12))
810 RUN_ELF_CXX_TESTS=1
811 else
812 RUN_ELF_CXX_TESTS=0
813 fi
814 plan_tests $NUM_TESTS
815 print_test_banner "$TEST_DESC"
816
817 if [ "$(id -u)" == "0" ]; then
818 isroot=1
819 else
820 isroot=0
821 fi
822
823 skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
824 {
825 start_lttng_sessiond
826
827 # Unsuccessful event enabling
828 test_userspace_probe_enable_file_noexist
829 test_userspace_probe_enable_file_not_elf
830
831 test_userspace_probe_enable_elf_missing_symbol_name
832 test_userspace_probe_enable_elf_nonexistant_symbol
833 test_userspace_probe_enable_elf_symbol_not_function
834 test_userspace_probe_unsupported_types
835
836 # Successful userspace probe elf enabling
837 test_userspace_probe_enable_implicit_probe_type
838 test_userspace_probe_enable_in_path
839 test_userspace_probe_enable_full_path
840 test_userspace_probe_enable_elf_symbol_exists
841 test_userspace_probe_enable_colon_in_path
842
843 # Successful tracing userspace probe elf
844 test_userspace_probe_elf
845 test_userspace_probe_elf_dynamic_symbol
846
847 # Disable userspace-probe elf
848 test_userspace_probe_elf_disable
849
850 # Successful listing of userspace probe elf
851 test_userspace_probe_elf_list
852
853 # Successful save and load of userspace probe elf
854 test_userspace_probe_save_load_elf
855
856 if test $RUN_ELF_CXX_TESTS == 1; then
857 # Successful tracing of userspace probe elf on C++ symbol
858 test_userspace_probe_elf_cxx_function
859 test_userspace_probe_elf_cxx_method
860 fi
861
862 if test $RUN_SDT_TESTS == 1; then
863 # Unsuccessful event enabling
864 test_userspace_probe_enable_sdt_nonexistant_provider
865 test_userspace_probe_enable_sdt_nonexistant_probe
866 test_userspace_probe_enable_sdt_with_sema
867
868 # Successful userspace probe sdt enabling
869 test_userspace_probe_sdt_one_probe
870 test_userspace_probe_sdt_two_probes
871 test_userspace_probe_sdt_with_arg
872 test_userspace_probe_sdt_in_shared_object
873 test_userspace_probe_sdt_in_shared_object_dlopen
874 test_userspace_probe_sdt_in_shared_object_ldpreload
875
876 # Successful tracing of userspace probe sdt
877 test_userspace_probe_sdt
878
879 # Successful listing of userspace probe sdt
880 test_userspace_probe_sdt_list
881
882 # Successful save and load of userspace probe sdt
883 test_userspace_probe_save_load_sdt
884 fi
885
886 stop_lttng_sessiond
887 }
This page took 0.049558 seconds and 4 git commands to generate.