Implement userspace-probe regression tests
[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/"
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=81
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_cxx_function ()
288 {
289 TRACE_PATH=$(mktemp -d)
290 SESSION_NAME="test_userprobe_elf_cxx_function"
291 # Probing C++ mangled symbols should work the same way as regular Elf
292 # symbols
293 ELF_SYMBOL_CXX="_Z17test_cxx_functionv"
294 ENABLE_EXPR="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
295
296 diag "Userspace probe on C++ mangled function enabled and traced"
297
298 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
299
300 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
301
302 start_lttng_tracing_ok $SESSION_NAME
303 eval "$ELF_CXX_TEST_BIN" > /dev/null
304 stop_lttng_tracing_ok $SESSION_NAME
305
306 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
307
308 destroy_lttng_session_ok $SESSION_NAME
309
310 rm -rf "$TRACE_PATH"
311 }
312
313 function test_userspace_probe_elf_cxx_method ()
314 {
315 TRACE_PATH=$(mktemp -d)
316 SESSION_NAME="test_userprobe_elf_cxx_method"
317 # Probing C++ mangled symbols should work the same way as regular Elf
318 # symbols
319 ELF_SYMBOL_CXX="_ZN10test_class11test_methodEv"
320 ENABLE_EXPR="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
321
322 diag "Userspace probe on C++ mangled method enabled and traced"
323
324 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
325
326 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
327
328 start_lttng_tracing_ok $SESSION_NAME
329 eval "$ELF_CXX_TEST_BIN" > /dev/null
330 stop_lttng_tracing_ok $SESSION_NAME
331
332 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
333
334 destroy_lttng_session_ok $SESSION_NAME
335
336 rm -rf "$TRACE_PATH"
337 }
338
339 function test_userspace_probe_elf_disable ()
340 {
341 TRACE_PATH=$(mktemp -d)
342 SESSION_NAME="test_userprobe_elf_disable"
343 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
344
345 diag "Userspace probe on Elf symbol disabled and traced"
346
347 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
348
349 # Activate and disable event
350 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
351 disable_kernel_lttng_userspace_probe_event_ok $SESSION_NAME $PROBE_EVENT_NAME
352
353 start_lttng_tracing_ok $SESSION_NAME
354 eval "$ELF_TEST_BIN" > /dev/null
355 stop_lttng_tracing_ok $SESSION_NAME
356
357 # Verify that the trace contains zero event.
358 validate_trace_empty "$TRACE_PATH"
359
360 destroy_lttng_session_ok $SESSION_NAME
361
362 rm -rf "$TRACE_PATH"
363 }
364
365 function test_userspace_probe_elf_list ()
366 {
367 TRACE_PATH=$(mktemp -d)
368 SESSION_NAME="test_userprobe_elf_list"
369 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
370
371 diag "Userspace probe ELF enabled and listed"
372
373 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
374
375 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
376
377 validate_list $SESSION_NAME $PROBE_EVENT_NAME
378 validate_list $SESSION_NAME $ELF_SYMBOL
379 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
380 validate_list $SESSION_NAME "ELF"
381 validate_list $SESSION_NAME "Function"
382
383 destroy_lttng_session_ok $SESSION_NAME
384
385 rm -rf "$TRACE_PATH"
386 }
387
388 function test_userspace_probe_save_load_elf()
389 {
390 # Test that the load and save works for userspace probes AND that when
391 # a userspace probe is placed on a symlink by the user the save command
392 # saves the path to the link and not to the actual file. This is to
393 # support instrumentation of shared objects that are often accessed
394 # through symlinks and updated.
395 TRACE_PATH=$(mktemp -d)
396 TMP_LINK_DIR=$(mktemp -d)
397 TMP_SAVE_DIR=$(mktemp -d)
398
399 SESSION_NAME="test_userprobe_save_load_elf"
400
401 ELF_BIN_SYMLINK="$TMP_LINK_DIR"/bin_elf_symlink
402
403 ENABLE_EXPR_ELF="elf:$ELF_BIN_SYMLINK:$ELF_SYMBOL"
404 PROBE_EVENT_NAME_ELF="$PROBE_EVENT_NAME"_elf
405
406 # Create symlinks to the target binaries.
407 ln -s $(realpath $ELF_TEST_BIN) $ELF_BIN_SYMLINK
408
409 diag "Userspace probes Elf are saved and loaded"
410
411 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
412
413 # Enable userspace prove events.
414 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR_ELF" "$PROBE_EVENT_NAME_ELF"
415
416 # Confirm that the events were enabled.
417 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
418
419 # Save the session to a file.
420 lttng_save $SESSION_NAME "--output-path=$TMP_SAVE_DIR"
421
422 destroy_lttng_session_ok $SESSION_NAME
423
424 # Confirm that the userspace probe are save to the xml file.
425 local count=$(cat $TMP_SAVE_DIR/* | grep --count -E "$ELF_BIN_SYMLINK")
426 if [[ $count -eq "1" ]]; then
427 pass "Symlink found in saved session"
428 else
429 fail "Symlink to binary not found in saved session"
430 fi
431
432 # Load the saved session.
433 lttng_load_ok "--input-path=$TMP_SAVE_DIR"
434
435 # Confirm that the userspace probes event are enabled in the newly
436 # loaded session.
437 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
438
439 # Cleanup temp files and folders.
440 rm -rf "$TRACE_PATH"
441 rm -rf "$TMP_LINK_DIR"
442 rm -rf "$TMP_SAVE_DIR"
443 }
444 function test_userspace_probe_save_load_sdt()
445 {
446 # Test that the load and save works for userspace probes AND that when
447 # a userspace probe is placed on a symlink by the user the save command
448 # saves the path to the link and not to the actual file. This is to
449 # support instrumentation of shared objects that are often accessed
450 # through symlinks and updated.
451 TRACE_PATH=$(mktemp -d)
452 TMP_LINK_DIR=$(mktemp -d)
453 TMP_SAVE_DIR=$(mktemp -d)
454
455 SESSION_NAME="test_userprobe_save_load_sdt"
456 PROVIDER="foobar"
457 PROBE="tp1"
458
459 SDT_BIN_SYMLINK="$TMP_LINK_DIR"/bin_sdt_symlink
460
461 ENABLE_EXPR_SDT="sdt:$SDT_BIN_SYMLINK:$PROVIDER:$PROBE"
462 PROBE_EVENT_NAME_SDT="$PROBE_EVENT_NAME"_sdt
463
464 # Create symlinks to the target binaries.
465 ln -s $(realpath $SDT_TEST_BIN) $SDT_BIN_SYMLINK
466
467 diag "Userspace probes SDT are saved and loaded"
468
469 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
470
471 # Enable userspace prove events.
472 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR_SDT" "$PROBE_EVENT_NAME_SDT"
473
474 # Confirm that the events were enabled.
475 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
476
477 # Save the session to a file.
478 lttng_save $SESSION_NAME "--output-path=$TMP_SAVE_DIR"
479
480 destroy_lttng_session_ok $SESSION_NAME
481
482 # Confirm that the userspace probe are save to the xml file.
483 local count=$(cat $TMP_SAVE_DIR/* | grep --count -E "$SDT_BIN_SYMLINK")
484 if [[ $count -eq "1" ]]; then
485 pass "Symlink found in saved session"
486 else
487 fail "Symlink to binary not found in saved session"
488 fi
489
490 # Load the saved session.
491 lttng_load_ok "--input-path=$TMP_SAVE_DIR"
492
493 # Confirm that the userspace probes event are enabled in the newly
494 # loaded session.
495 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
496
497 # Cleanup temp files and folders.
498 rm -rf "$TRACE_PATH"
499 rm -rf "$TMP_LINK_DIR"
500 rm -rf "$TMP_SAVE_DIR"
501 }
502
503 function test_userspace_probe_sdt ()
504 {
505 TRACE_PATH=$(mktemp -d)
506 PROVIDER="foobar"
507 PROBE="tp1"
508 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
509
510 diag "Userspace probe on SDT tracepoint enabled and traced"
511
512 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
513
514 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
515
516 start_lttng_tracing_ok $SESSION_NAME
517 eval "$SDT_TEST_BIN" > /dev/null
518 stop_lttng_tracing_ok $SESSION_NAME
519
520 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
521
522 destroy_lttng_session_ok $SESSION_NAME
523
524 rm -rf "$TRACE_PATH"
525 }
526
527 function test_userspace_probe_sdt_list ()
528 {
529 TRACE_PATH=$(mktemp -d)
530 SESSION_NAME="test_userprobe_sdt_list"
531 PROVIDER="foobar"
532 PROBE="tp1"
533 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
534
535 diag "Userspace probe SDT enabled and listed"
536
537 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
538
539 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
540
541 validate_list $SESSION_NAME $PROBE_EVENT_NAME
542 validate_list $SESSION_NAME $PROVIDER
543 validate_list $SESSION_NAME $PROBE
544 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
545 validate_list $SESSION_NAME "SDT"
546 validate_list $SESSION_NAME "Tracepoint"
547
548 destroy_lttng_session_ok $SESSION_NAME
549
550 rm -rf "$TRACE_PATH"
551 }
552
553 function test_userspace_probe_enable_sdt_nonexistant_provider ()
554 {
555 TRACE_PATH=$(mktemp -d)
556 SESSION_NAME="test_userprobe_sdt_nonexistand_provider"
557 PROVIDER="not_provider"
558 PROBE="tp1"
559 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
560
561 diag "Userspace probe SDT on tracepoint non existant provider"
562
563 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
564
565 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
566
567 destroy_lttng_session_ok $SESSION_NAME
568
569 rm -rf "$TRACE_PATH"
570 }
571
572 function test_userspace_probe_enable_sdt_nonexistant_probe ()
573 {
574 TRACE_PATH=$(mktemp -d)
575 SESSION_NAME="test_userprobe_sdt_nonexistant_probe"
576 PROVIDER="foobar"
577 PROBE="not_a_tracepoint"
578 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
579
580 diag "Userspace probe SDT on non existant probe"
581
582 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
583
584 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
585
586 destroy_lttng_session_ok $SESSION_NAME
587
588 rm -rf "$TRACE_PATH"
589 }
590
591 function test_userspace_probe_enable_sdt_with_sema ()
592 {
593 TRACE_PATH=$(mktemp -d)
594 SESSION_NAME="test_userprobe_sdt_with_sema"
595 PROVIDER="foobar"
596 PROBE="tp_with_semaphore"
597 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
598
599 diag "Userspace probe SDT on non existant probe"
600
601 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
602
603 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
604
605 destroy_lttng_session_ok $SESSION_NAME
606
607 rm -rf "$TRACE_PATH"
608 }
609
610 function test_userspace_probe_sdt_one_probe ()
611 {
612 TRACE_PATH=$(mktemp -d)
613 SESSION_NAME="test_userprobe_sdt_one_probe"
614 PROVIDER="foobar"
615 PROBE="tp1"
616 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
617
618 diag "Userspace probe SDT on tracepoint with one callsite"
619
620 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
621
622 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
623
624 start_lttng_tracing_ok $SESSION_NAME
625 eval "$SDT_TEST_BIN" > /dev/null
626 stop_lttng_tracing_ok $SESSION_NAME
627
628 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
629
630 destroy_lttng_session_ok $SESSION_NAME
631
632 rm -rf "$TRACE_PATH"
633 }
634
635 function test_userspace_probe_sdt_two_probes ()
636 {
637 TRACE_PATH=$(mktemp -d)
638 SESSION_NAME="test_userprobe_sdt_two_probes"
639 PROVIDER="foobar"
640 PROBE="tp2"
641 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
642
643 diag "Userspace probe SDT on tracepoint with two callsites"
644
645 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
646
647 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
648
649 start_lttng_tracing_ok $SESSION_NAME
650 eval "$SDT_TEST_BIN" > /dev/null
651 stop_lttng_tracing_ok $SESSION_NAME
652
653 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
654
655 destroy_lttng_session_ok $SESSION_NAME
656
657 rm -rf "$TRACE_PATH"
658 }
659
660 function test_userspace_probe_sdt_in_shared_object ()
661 {
662 TRACE_PATH=$(mktemp -d)
663 SESSION_NAME="test_userprobe_sdt_shared_object"
664 PROVIDER="foobar"
665 PROBE="tp_in_shared_object"
666 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libfoo.so:$PROVIDER:$PROBE"
667
668 diag "Userspace probe SDT on tracepoint in shared object"
669
670 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
671
672 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
673
674 start_lttng_tracing_ok $SESSION_NAME
675 eval "$SDT_TEST_BIN" > /dev/null
676 stop_lttng_tracing_ok $SESSION_NAME
677
678 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
679
680 destroy_lttng_session_ok $SESSION_NAME
681
682 rm -rf "$TRACE_PATH"
683 }
684
685 function test_userspace_probe_sdt_in_shared_object_dlopen ()
686 {
687 TRACE_PATH=$(mktemp -d)
688 SESSION_NAME="test_userprobe_sdt_shared_object_dlopen"
689 PROVIDER="foobar"
690 PROBE="tp_in_dlopen"
691 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libbar.so:$PROVIDER:$PROBE"
692
693 diag "Userspace probe SDT on tracepoint in dlopen()ed shared object"
694
695 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
696
697 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
698
699 start_lttng_tracing_ok $SESSION_NAME
700 eval "$SDT_TEST_BIN" > /dev/null
701 stop_lttng_tracing_ok $SESSION_NAME
702
703 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
704
705 destroy_lttng_session_ok $SESSION_NAME
706
707 rm -rf "$TRACE_PATH"
708 }
709
710 function test_userspace_probe_sdt_in_shared_object_ldpreload ()
711 {
712 TRACE_PATH=$(mktemp -d)
713 SESSION_NAME="test_userprobe_sdt_shared_object_ldpreload"
714 PROVIDER="foobar"
715 PROBE="tp_in_ldpreload"
716 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libzzz.so:$PROVIDER:$PROBE"
717
718 diag "Userspace probe SDT on tracepoint in an LD_PRELOADed shared object"
719
720 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
721
722 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
723
724 start_lttng_tracing_ok $SESSION_NAME
725 LD_PRELOAD="$SDT_TEST_BIN_DIR/libzzz.so" eval "$SDT_TEST_BIN" > /dev/null
726 stop_lttng_tracing_ok $SESSION_NAME
727
728 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
729
730 destroy_lttng_session_ok $SESSION_NAME
731
732 rm -rf "$TRACE_PATH"
733 }
734
735 function test_userspace_probe_sdt_with_arg ()
736 {
737 TRACE_PATH=$(mktemp -d)
738 SESSION_NAME="test_userprobe_sdt_arg"
739 PROVIDER="foobar"
740 PROBE="tp_with_arg"
741 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
742
743 diag "Userspace probe SDT on tracepoint with argument"
744
745 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
746
747 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
748
749 start_lttng_tracing_ok $SESSION_NAME
750 eval "$SDT_TEST_BIN" > /dev/null
751 stop_lttng_tracing_ok $SESSION_NAME
752
753 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
754
755 destroy_lttng_session_ok $SESSION_NAME
756
757 rm -rf "$TRACE_PATH"
758 }
759
760 ls "$SDT_TEST_BIN" >/dev/null 2>&1
761 if test $? == 0; then
762 NUM_TESTS=$((NUM_TESTS+68))
763 RUN_SDT_TESTS=1
764 else
765 RUN_SDT_TESTS=0
766 fi
767
768 ls "$ELF_CXX_TEST_BIN" >/dev/null 2>&1
769 if test $? == 0; then
770 NUM_TESTS=$((NUM_TESTS+12))
771 RUN_ELF_CXX_TESTS=1
772 else
773 RUN_ELF_CXX_TESTS=0
774 fi
775 plan_tests $NUM_TESTS
776 print_test_banner "$TEST_DESC"
777
778 if [ "$(id -u)" == "0" ]; then
779 isroot=1
780 else
781 isroot=0
782 fi
783
784 skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
785 {
786 start_lttng_sessiond
787
788 # Unsuccessful event enabling
789 test_userspace_probe_enable_file_noexist
790 test_userspace_probe_enable_file_not_elf
791
792 test_userspace_probe_enable_elf_missing_symbol_name
793 test_userspace_probe_enable_elf_nonexistant_symbol
794 test_userspace_probe_enable_elf_symbol_not_function
795
796 # Successful userspace probe elf enabling
797 test_userspace_probe_enable_implicit_probe_type
798 test_userspace_probe_enable_in_path
799 test_userspace_probe_enable_full_path
800 test_userspace_probe_enable_elf_symbol_exists
801 test_userspace_probe_enable_colon_in_path
802
803 # Successful tracing userspace probe elf
804 test_userspace_probe_elf
805
806 # Disable userspace-probe elf
807 test_userspace_probe_elf_disable
808
809 # Successful listing of userspace probe elf
810 test_userspace_probe_elf_list
811
812 # Successful save and load of userspace probe elf
813 test_userspace_probe_save_load_elf
814
815 if test $RUN_ELF_CXX_TESTS == 1; then
816 # Successful tracing of userspace probe elf on C++ symbol
817 test_userspace_probe_elf_cxx_function
818 test_userspace_probe_elf_cxx_method
819 fi
820
821 if test $RUN_SDT_TESTS == 1; then
822 # Unsuccessful event enabling
823 test_userspace_probe_enable_sdt_nonexistant_provider
824 test_userspace_probe_enable_sdt_nonexistant_probe
825 test_userspace_probe_enable_sdt_with_sema
826
827 # Successful userspace probe sdt enabling
828 test_userspace_probe_sdt_one_probe
829 test_userspace_probe_sdt_two_probes
830 test_userspace_probe_sdt_with_arg
831 test_userspace_probe_sdt_in_shared_object
832 test_userspace_probe_sdt_in_shared_object_dlopen
833 test_userspace_probe_sdt_in_shared_object_ldpreload
834
835 # Successful tracing of userspace probe sdt
836 test_userspace_probe_sdt
837
838 # Successful listing of userspace probe sdt
839 test_userspace_probe_sdt_list
840
841 # Successful save and load of userspace probe sdt
842 test_userspace_probe_save_load_sdt
843 fi
844
845 stop_lttng_sessiond
846 }
This page took 0.076631 seconds and 4 git commands to generate.