elf: support dynamic symbol table lookup
[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 # 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.
9 #
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
13 # details.
14 #
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
18
19 TEST_DESC="Userspace probe - Testing userspace probe on ELF symbol"
20
21 CURDIR=$(dirname "$0")/
22 TESTDIR=$CURDIR/../..
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
35 NUM_TESTS=87
36 OUTPUT_DEST=/dev/null
37 ERROR_OUTPUT_DEST=/dev/null
38
39 source "$TESTDIR/utils/utils.sh"
40
41 function validate_list()
42 {
43 local session_name=$1
44 local event_name=$2
45
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"
50 else
51 pass "Validate userspace probe listing. Found $event_name."
52 fi
53 }
54
55 function test_userspace_probe_enable_file_noexist ()
56 {
57 TRACE_PATH=$(mktemp -d)
58 SESSION_NAME="test_userspace_probe_enable_file_noexist"
59 ENABLE_EXPR="elf:/etc/file-not-exist:$ELF_SYMBOL"
60
61 diag "Userspace probe enable on non-existant file"
62
63 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
64
65 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME $ENABLE_EXPR $PROBE_EVENT_NAME
66
67 destroy_lttng_session_ok $SESSION_NAME
68
69 rm -rf "$TRACE_PATH"
70 }
71
72 function test_userspace_probe_enable_file_not_elf ()
73 {
74 TRACE_PATH=$(mktemp -d)
75 SESSION_NAME="test_userspace_probe_enable_file_not_elf"
76 ENABLE_EXPR="elf:/etc/passwd:$ELF_SYMBOL"
77
78 diag "Userspace probe enable on a non ELF file"
79
80 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
81
82 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME $ENABLE_EXPR $PROBE_EVENT_NAME
83
84 destroy_lttng_session_ok $SESSION_NAME
85
86 rm -rf "$TRACE_PATH"
87 }
88
89 function test_userspace_probe_enable_elf_missing_symbol_name ()
90 {
91 TRACE_PATH=$(mktemp -d)
92 SESSION_NAME="test_userspace_probe_enable_elf_missing_symbol"
93 ENABLE_EXPR="elf:$ELF_TEST_BIN:"
94
95 diag "Userspace probe enable with unspecified ELF symbol"
96
97 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
98
99 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
100
101 destroy_lttng_session_ok $SESSION_NAME
102
103 rm -rf "$TRACE_PATH"
104 }
105
106 function test_userspace_probe_enable_elf_nonexistant_symbol ()
107 {
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"
112
113 diag "Userspace probe enable with nonexistant ELF symbol"
114
115 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
116
117 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
118
119 destroy_lttng_session_ok $SESSION_NAME
120
121 rm -rf "$TRACE_PATH"
122 }
123
124 function test_userspace_probe_enable_elf_symbol_not_function ()
125 {
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"
130
131 diag "Userspace probe enable with non-function ELF symbol"
132
133 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
134
135 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
136
137 destroy_lttng_session_ok $SESSION_NAME
138
139 rm -rf "$TRACE_PATH"
140 }
141
142 function test_userspace_probe_enable_implicit_probe_type ()
143 {
144 TRACE_PATH=$(mktemp -d)
145 SESSION_NAME="test_userspace_probe_enable_implicit_probe_type"
146 ENABLE_EXPR="$ELF_TEST_BIN:$ELF_SYMBOL"
147
148 diag "Userspace probe enabled successfully with implicit probe type"
149
150 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
151
152 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
153
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"
158
159 destroy_lttng_session_ok $SESSION_NAME
160
161 rm -rf "$TRACE_PATH"
162 }
163
164 function test_userspace_probe_enable_elf_symbol_exists ()
165 {
166 TRACE_PATH=$(mktemp -d)
167 SESSION_NAME="test_userspace_probe_enable_elf_symbol_exists"
168 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
169
170 diag "Userspace probe enabled successfully"
171
172 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
173
174 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
175
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"
180
181 destroy_lttng_session_ok $SESSION_NAME
182
183 rm -rf "$TRACE_PATH"
184 }
185
186 function test_userspace_probe_enable_in_path ()
187 {
188 TRACE_PATH=$(mktemp -d)
189 SESSION_NAME="test_userspace_probe_enable_in_path"
190 ENABLE_EXPR="elf:$ELF_TEST_BIN_NAME:$ELF_SYMBOL"
191
192 diag "Userspace probe on binary in PATH enabled successfully"
193
194 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
195
196 # Save old PATH and add the test directory to the PATH.
197 OLDPATH="$PATH"
198 export PATH="$PATH:$(realpath $ELF_TEST_BIN_DIR)"
199
200 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
201
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"
206
207 # Reset the previously saved PATH.
208 export PATH="$OLDPATH"
209
210 destroy_lttng_session_ok $SESSION_NAME
211
212 rm -rf "$TRACE_PATH"
213 }
214
215 function test_userspace_probe_enable_full_path ()
216 {
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"
221
222 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
223
224 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
225
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"
230
231 destroy_lttng_session_ok $SESSION_NAME
232
233 rm -rf "$TRACE_PATH"
234 }
235
236 function test_userspace_probe_enable_colon_in_path ()
237 {
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"
244
245 ln -s $(realpath $ELF_TEST_BIN) $ELF_BIN_SYMLINK
246
247 diag "Userspace probe with binary with colon in name enabled successfully"
248
249 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
250
251 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
252
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"
257
258 destroy_lttng_session_ok $SESSION_NAME
259
260 rm -rf "$TRACE_PATH"
261 rm -rf "$COLON_FILE_PATH"
262 }
263
264 function test_userspace_probe_elf ()
265 {
266 TRACE_PATH=$(mktemp -d)
267 SESSION_NAME="test_userprobe_elf"
268 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
269
270 diag "Userspace probe on Elf symbol enabled and traced"
271
272 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
273
274 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
275
276 start_lttng_tracing_ok $SESSION_NAME
277 eval "$ELF_TEST_BIN" > /dev/null
278 stop_lttng_tracing_ok $SESSION_NAME
279
280 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
281
282 destroy_lttng_session_ok $SESSION_NAME
283
284 rm -rf "$TRACE_PATH"
285 }
286
287 function test_userspace_probe_elf_dynamic_symbol ()
288 {
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"
293
294 diag "Userspace probe on Elf dynamic symbol enabled and traced"
295
296 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
297
298 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
299
300 start_lttng_tracing_ok $SESSION_NAME
301 eval "$ELF_TEST_BIN" > /dev/null
302 stop_lttng_tracing_ok $SESSION_NAME
303
304 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
305
306 destroy_lttng_session_ok $SESSION_NAME
307
308 rm -rf "$TRACE_PATH"
309 }
310
311 function test_userspace_probe_elf_cxx_function ()
312 {
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
316 # symbols
317 ELF_SYMBOL_CXX="_Z17test_cxx_functionv"
318 ENABLE_EXPR="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
319
320 diag "Userspace probe on C++ mangled function enabled and traced"
321
322 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
323
324 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
325
326 start_lttng_tracing_ok $SESSION_NAME
327 eval "$ELF_CXX_TEST_BIN" > /dev/null
328 stop_lttng_tracing_ok $SESSION_NAME
329
330 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
331
332 destroy_lttng_session_ok $SESSION_NAME
333
334 rm -rf "$TRACE_PATH"
335 }
336
337 function test_userspace_probe_elf_cxx_method ()
338 {
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
342 # symbols
343 ELF_SYMBOL_CXX="_ZN10test_class11test_methodEv"
344 ENABLE_EXPR="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
345
346 diag "Userspace probe on C++ mangled method enabled and traced"
347
348 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
349
350 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
351
352 start_lttng_tracing_ok $SESSION_NAME
353 eval "$ELF_CXX_TEST_BIN" > /dev/null
354 stop_lttng_tracing_ok $SESSION_NAME
355
356 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
357
358 destroy_lttng_session_ok $SESSION_NAME
359
360 rm -rf "$TRACE_PATH"
361 }
362
363 function test_userspace_probe_elf_disable ()
364 {
365 TRACE_PATH=$(mktemp -d)
366 SESSION_NAME="test_userprobe_elf_disable"
367 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
368
369 diag "Userspace probe on Elf symbol disabled and traced"
370
371 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
372
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
376
377 start_lttng_tracing_ok $SESSION_NAME
378 eval "$ELF_TEST_BIN" > /dev/null
379 stop_lttng_tracing_ok $SESSION_NAME
380
381 # Verify that the trace contains zero event.
382 validate_trace_empty "$TRACE_PATH"
383
384 destroy_lttng_session_ok $SESSION_NAME
385
386 rm -rf "$TRACE_PATH"
387 }
388
389 function test_userspace_probe_elf_list ()
390 {
391 TRACE_PATH=$(mktemp -d)
392 SESSION_NAME="test_userprobe_elf_list"
393 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
394
395 diag "Userspace probe ELF enabled and listed"
396
397 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
398
399 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
400
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"
406
407 destroy_lttng_session_ok $SESSION_NAME
408
409 rm -rf "$TRACE_PATH"
410 }
411
412 function test_userspace_probe_save_load_elf()
413 {
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)
422
423 SESSION_NAME="test_userprobe_save_load_elf"
424
425 ELF_BIN_SYMLINK="$TMP_LINK_DIR"/bin_elf_symlink
426
427 ENABLE_EXPR_ELF="elf:$ELF_BIN_SYMLINK:$ELF_SYMBOL"
428 PROBE_EVENT_NAME_ELF="$PROBE_EVENT_NAME"_elf
429
430 # Create symlinks to the target binaries.
431 ln -s $(realpath $ELF_TEST_BIN) $ELF_BIN_SYMLINK
432
433 diag "Userspace probes Elf are saved and loaded"
434
435 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
436
437 # Enable userspace prove events.
438 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR_ELF" "$PROBE_EVENT_NAME_ELF"
439
440 # Confirm that the events were enabled.
441 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
442
443 # Save the session to a file.
444 lttng_save $SESSION_NAME "--output-path=$TMP_SAVE_DIR"
445
446 destroy_lttng_session_ok $SESSION_NAME
447
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"
452 else
453 fail "Symlink to binary not found in saved session"
454 fi
455
456 # Load the saved session.
457 lttng_load_ok "--input-path=$TMP_SAVE_DIR"
458
459 # Confirm that the userspace probes event are enabled in the newly
460 # loaded session.
461 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
462
463 # Cleanup temp files and folders.
464 rm -rf "$TRACE_PATH"
465 rm -rf "$TMP_LINK_DIR"
466 rm -rf "$TMP_SAVE_DIR"
467 }
468 function test_userspace_probe_save_load_sdt()
469 {
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)
478
479 SESSION_NAME="test_userprobe_save_load_sdt"
480 PROVIDER="foobar"
481 PROBE="tp1"
482
483 SDT_BIN_SYMLINK="$TMP_LINK_DIR"/bin_sdt_symlink
484
485 ENABLE_EXPR_SDT="sdt:$SDT_BIN_SYMLINK:$PROVIDER:$PROBE"
486 PROBE_EVENT_NAME_SDT="$PROBE_EVENT_NAME"_sdt
487
488 # Create symlinks to the target binaries.
489 ln -s $(realpath $SDT_TEST_BIN) $SDT_BIN_SYMLINK
490
491 diag "Userspace probes SDT are saved and loaded"
492
493 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
494
495 # Enable userspace prove events.
496 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR_SDT" "$PROBE_EVENT_NAME_SDT"
497
498 # Confirm that the events were enabled.
499 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
500
501 # Save the session to a file.
502 lttng_save $SESSION_NAME "--output-path=$TMP_SAVE_DIR"
503
504 destroy_lttng_session_ok $SESSION_NAME
505
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"
510 else
511 fail "Symlink to binary not found in saved session"
512 fi
513
514 # Load the saved session.
515 lttng_load_ok "--input-path=$TMP_SAVE_DIR"
516
517 # Confirm that the userspace probes event are enabled in the newly
518 # loaded session.
519 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
520
521 # Cleanup temp files and folders.
522 rm -rf "$TRACE_PATH"
523 rm -rf "$TMP_LINK_DIR"
524 rm -rf "$TMP_SAVE_DIR"
525 }
526
527 function test_userspace_probe_sdt ()
528 {
529 TRACE_PATH=$(mktemp -d)
530 PROVIDER="foobar"
531 PROBE="tp1"
532 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
533
534 diag "Userspace probe on SDT tracepoint enabled and traced"
535
536 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
537
538 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
539
540 start_lttng_tracing_ok $SESSION_NAME
541 eval "$SDT_TEST_BIN" > /dev/null
542 stop_lttng_tracing_ok $SESSION_NAME
543
544 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
545
546 destroy_lttng_session_ok $SESSION_NAME
547
548 rm -rf "$TRACE_PATH"
549 }
550
551 function test_userspace_probe_sdt_list ()
552 {
553 TRACE_PATH=$(mktemp -d)
554 SESSION_NAME="test_userprobe_sdt_list"
555 PROVIDER="foobar"
556 PROBE="tp1"
557 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
558
559 diag "Userspace probe SDT enabled and listed"
560
561 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
562
563 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
564
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"
571
572 destroy_lttng_session_ok $SESSION_NAME
573
574 rm -rf "$TRACE_PATH"
575 }
576
577 function test_userspace_probe_enable_sdt_nonexistant_provider ()
578 {
579 TRACE_PATH=$(mktemp -d)
580 SESSION_NAME="test_userprobe_sdt_nonexistand_provider"
581 PROVIDER="not_provider"
582 PROBE="tp1"
583 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
584
585 diag "Userspace probe SDT on tracepoint non existant provider"
586
587 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
588
589 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
590
591 destroy_lttng_session_ok $SESSION_NAME
592
593 rm -rf "$TRACE_PATH"
594 }
595
596 function test_userspace_probe_enable_sdt_nonexistant_probe ()
597 {
598 TRACE_PATH=$(mktemp -d)
599 SESSION_NAME="test_userprobe_sdt_nonexistant_probe"
600 PROVIDER="foobar"
601 PROBE="not_a_tracepoint"
602 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
603
604 diag "Userspace probe SDT on non existant probe"
605
606 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
607
608 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
609
610 destroy_lttng_session_ok $SESSION_NAME
611
612 rm -rf "$TRACE_PATH"
613 }
614
615 function test_userspace_probe_enable_sdt_with_sema ()
616 {
617 TRACE_PATH=$(mktemp -d)
618 SESSION_NAME="test_userprobe_sdt_with_sema"
619 PROVIDER="foobar"
620 PROBE="tp_with_semaphore"
621 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
622
623 diag "Userspace probe SDT on non existant probe"
624
625 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
626
627 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
628
629 destroy_lttng_session_ok $SESSION_NAME
630
631 rm -rf "$TRACE_PATH"
632 }
633
634 function test_userspace_probe_sdt_one_probe ()
635 {
636 TRACE_PATH=$(mktemp -d)
637 SESSION_NAME="test_userprobe_sdt_one_probe"
638 PROVIDER="foobar"
639 PROBE="tp1"
640 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
641
642 diag "Userspace probe SDT on tracepoint with one callsite"
643
644 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
645
646 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
647
648 start_lttng_tracing_ok $SESSION_NAME
649 eval "$SDT_TEST_BIN" > /dev/null
650 stop_lttng_tracing_ok $SESSION_NAME
651
652 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
653
654 destroy_lttng_session_ok $SESSION_NAME
655
656 rm -rf "$TRACE_PATH"
657 }
658
659 function test_userspace_probe_sdt_two_probes ()
660 {
661 TRACE_PATH=$(mktemp -d)
662 SESSION_NAME="test_userprobe_sdt_two_probes"
663 PROVIDER="foobar"
664 PROBE="tp2"
665 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
666
667 diag "Userspace probe SDT on tracepoint with two callsites"
668
669 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
670
671 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
672
673 start_lttng_tracing_ok $SESSION_NAME
674 eval "$SDT_TEST_BIN" > /dev/null
675 stop_lttng_tracing_ok $SESSION_NAME
676
677 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
678
679 destroy_lttng_session_ok $SESSION_NAME
680
681 rm -rf "$TRACE_PATH"
682 }
683
684 function test_userspace_probe_sdt_in_shared_object ()
685 {
686 TRACE_PATH=$(mktemp -d)
687 SESSION_NAME="test_userprobe_sdt_shared_object"
688 PROVIDER="foobar"
689 PROBE="tp_in_shared_object"
690 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libfoo.so:$PROVIDER:$PROBE"
691
692 diag "Userspace probe SDT on tracepoint in shared object"
693
694 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
695
696 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
697
698 start_lttng_tracing_ok $SESSION_NAME
699 eval "$SDT_TEST_BIN" > /dev/null
700 stop_lttng_tracing_ok $SESSION_NAME
701
702 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
703
704 destroy_lttng_session_ok $SESSION_NAME
705
706 rm -rf "$TRACE_PATH"
707 }
708
709 function test_userspace_probe_sdt_in_shared_object_dlopen ()
710 {
711 TRACE_PATH=$(mktemp -d)
712 SESSION_NAME="test_userprobe_sdt_shared_object_dlopen"
713 PROVIDER="foobar"
714 PROBE="tp_in_dlopen"
715 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libbar.so:$PROVIDER:$PROBE"
716
717 diag "Userspace probe SDT on tracepoint in dlopen()ed shared object"
718
719 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
720
721 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
722
723 start_lttng_tracing_ok $SESSION_NAME
724 eval "$SDT_TEST_BIN" > /dev/null
725 stop_lttng_tracing_ok $SESSION_NAME
726
727 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
728
729 destroy_lttng_session_ok $SESSION_NAME
730
731 rm -rf "$TRACE_PATH"
732 }
733
734 function test_userspace_probe_sdt_in_shared_object_ldpreload ()
735 {
736 TRACE_PATH=$(mktemp -d)
737 SESSION_NAME="test_userprobe_sdt_shared_object_ldpreload"
738 PROVIDER="foobar"
739 PROBE="tp_in_ldpreload"
740 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libzzz.so:$PROVIDER:$PROBE"
741
742 diag "Userspace probe SDT on tracepoint in an LD_PRELOADed shared object"
743
744 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
745
746 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
747
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
751
752 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
753
754 destroy_lttng_session_ok $SESSION_NAME
755
756 rm -rf "$TRACE_PATH"
757 }
758
759 function test_userspace_probe_sdt_with_arg ()
760 {
761 TRACE_PATH=$(mktemp -d)
762 SESSION_NAME="test_userprobe_sdt_arg"
763 PROVIDER="foobar"
764 PROBE="tp_with_arg"
765 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
766
767 diag "Userspace probe SDT on tracepoint with argument"
768
769 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
770
771 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
772
773 start_lttng_tracing_ok $SESSION_NAME
774 eval "$SDT_TEST_BIN" > /dev/null
775 stop_lttng_tracing_ok $SESSION_NAME
776
777 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
778
779 destroy_lttng_session_ok $SESSION_NAME
780
781 rm -rf "$TRACE_PATH"
782 }
783
784 ls "$SDT_TEST_BIN" >/dev/null 2>&1
785 if test $? == 0; then
786 NUM_TESTS=$((NUM_TESTS+68))
787 RUN_SDT_TESTS=1
788 else
789 RUN_SDT_TESTS=0
790 fi
791
792 ls "$ELF_CXX_TEST_BIN" >/dev/null 2>&1
793 if test $? == 0; then
794 NUM_TESTS=$((NUM_TESTS+12))
795 RUN_ELF_CXX_TESTS=1
796 else
797 RUN_ELF_CXX_TESTS=0
798 fi
799 plan_tests $NUM_TESTS
800 print_test_banner "$TEST_DESC"
801
802 if [ "$(id -u)" == "0" ]; then
803 isroot=1
804 else
805 isroot=0
806 fi
807
808 skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
809 {
810 start_lttng_sessiond
811
812 # Unsuccessful event enabling
813 test_userspace_probe_enable_file_noexist
814 test_userspace_probe_enable_file_not_elf
815
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
819
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
826
827 # Successful tracing userspace probe elf
828 test_userspace_probe_elf
829 test_userspace_probe_elf_dynamic_symbol
830
831 # Disable userspace-probe elf
832 test_userspace_probe_elf_disable
833
834 # Successful listing of userspace probe elf
835 test_userspace_probe_elf_list
836
837 # Successful save and load of userspace probe elf
838 test_userspace_probe_save_load_elf
839
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
844 fi
845
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
851
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
859
860 # Successful tracing of userspace probe sdt
861 test_userspace_probe_sdt
862
863 # Successful listing of userspace probe sdt
864 test_userspace_probe_sdt_list
865
866 # Successful save and load of userspace probe sdt
867 test_userspace_probe_save_load_sdt
868 fi
869
870 stop_lttng_sessiond
871 }
This page took 0.049249 seconds and 5 git commands to generate.