Add UST namespace contexts tests
[lttng-tools.git] / tests / regression / kernel / test_userspace_probe
CommitLineData
a9c2df2b
FD
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
19TEST_DESC="Userspace probe - Testing userspace probe on ELF symbol"
20
21CURDIR=$(dirname "$0")/
22TESTDIR=$CURDIR/../..
23TESTAPP_DIR="$TESTDIR/utils/testapp/"
ef3dfe5d 24ELF_TEST_BIN_DIR="$TESTAPP_DIR/userspace-probe-elf-binary/.libs/"
a9c2df2b
FD
25ELF_TEST_BIN_NAME="userspace-probe-elf-binary"
26ELF_TEST_BIN="$ELF_TEST_BIN_DIR/$ELF_TEST_BIN_NAME"
27ELF_CXX_TEST_BIN_DIR="$TESTAPP_DIR/userspace-probe-elf-cxx-binary/"
28ELF_CXX_TEST_BIN_NAME="userspace-probe-elf-cxx-binary"
29ELF_CXX_TEST_BIN="$ELF_CXX_TEST_BIN_DIR/$ELF_CXX_TEST_BIN_NAME"
30SDT_TEST_BIN_DIR="$TESTAPP_DIR/userspace-probe-sdt-binary/.libs/"
31SDT_TEST_BIN_NAME="userspace-probe-sdt-binary"
32SDT_TEST_BIN="$SDT_TEST_BIN_DIR/$SDT_TEST_BIN_NAME"
33ELF_SYMBOL="test_function"
34PROBE_EVENT_NAME=userspace_probe_test_event
6a0a91e8 35NUM_TESTS=93
a9c2df2b
FD
36OUTPUT_DEST=/dev/null
37ERROR_OUTPUT_DEST=/dev/null
38
39source "$TESTDIR/utils/utils.sh"
40
41function 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
55function 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
72function 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
89function 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
106function 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
124function 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
6a0a91e8
FD
142function test_userspace_probe_unsupported_types ()
143{
144 TRACE_PATH=$(mktemp -d)
145 SESSION_NAME="test_userspace_probe_unsupported_types"
146 # Userspace probe at an address or at an offset to a function
147 # instrumentation description types are not supported at the moment.
148 ENABLE_EXPR_1="elf:$ELF_TEST_BIN:0x400030"
149 ENABLE_EXPR_2="elf:$ELF_TEST_BIN:4194364"
150 ENABLE_EXPR_3="elf:$ELF_TEST_BIN:$ELF_SYMBOL+0x21"
151 ENABLE_EXPR_4="elf:$ELF_TEST_BIN:$ELF_SYMBOL+2"
152
153 diag "Userspace probe enable with unsupported instrumentation description type"
154
155 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
156
157 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR_1" $PROBE_EVENT_NAME
158 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR_2" $PROBE_EVENT_NAME
159 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR_3" $PROBE_EVENT_NAME
160 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR_4" $PROBE_EVENT_NAME
161
162 destroy_lttng_session_ok $SESSION_NAME
163
164 rm -rf "$TRACE_PATH"
165}
166
a9c2df2b
FD
167function test_userspace_probe_enable_implicit_probe_type ()
168{
169 TRACE_PATH=$(mktemp -d)
170 SESSION_NAME="test_userspace_probe_enable_implicit_probe_type"
171 ENABLE_EXPR="$ELF_TEST_BIN:$ELF_SYMBOL"
172
173 diag "Userspace probe enabled successfully with implicit probe type"
174
175 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
176
177 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
178
179 validate_list $SESSION_NAME $ELF_SYMBOL
180 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
181 validate_list $SESSION_NAME "ELF"
182 validate_list $SESSION_NAME "Function"
183
184 destroy_lttng_session_ok $SESSION_NAME
185
186 rm -rf "$TRACE_PATH"
187}
188
189function test_userspace_probe_enable_elf_symbol_exists ()
190{
191 TRACE_PATH=$(mktemp -d)
192 SESSION_NAME="test_userspace_probe_enable_elf_symbol_exists"
193 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
194
195 diag "Userspace probe enabled successfully"
196
197 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
198
199 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
200
201 validate_list $SESSION_NAME $ELF_SYMBOL
202 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
203 validate_list $SESSION_NAME "ELF"
204 validate_list $SESSION_NAME "Function"
205
206 destroy_lttng_session_ok $SESSION_NAME
207
208 rm -rf "$TRACE_PATH"
209}
210
211function test_userspace_probe_enable_in_path ()
212{
213 TRACE_PATH=$(mktemp -d)
214 SESSION_NAME="test_userspace_probe_enable_in_path"
215 ENABLE_EXPR="elf:$ELF_TEST_BIN_NAME:$ELF_SYMBOL"
216
217 diag "Userspace probe on binary in PATH enabled successfully"
218
219 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
220
221 # Save old PATH and add the test directory to the PATH.
222 OLDPATH="$PATH"
223 export PATH="$PATH:$(realpath $ELF_TEST_BIN_DIR)"
224
225 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
226
227 validate_list $SESSION_NAME $ELF_SYMBOL
228 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
229 validate_list $SESSION_NAME "ELF"
230 validate_list $SESSION_NAME "Function"
231
232 # Reset the previously saved PATH.
233 export PATH="$OLDPATH"
234
235 destroy_lttng_session_ok $SESSION_NAME
236
237 rm -rf "$TRACE_PATH"
238}
239
240function test_userspace_probe_enable_full_path ()
241{
242 TRACE_PATH=$(mktemp -d)
243 SESSION_NAME="test_userspace_probe_enable_full_path"
244 ENABLE_EXPR="elf:$(realpath $ELF_TEST_BIN):$ELF_SYMBOL"
245 diag "Userspace probe with full path enabled successfully"
246
247 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
248
249 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
250
251 validate_list $SESSION_NAME $ELF_SYMBOL
252 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
253 validate_list $SESSION_NAME "ELF"
254 validate_list $SESSION_NAME "Function"
255
256 destroy_lttng_session_ok $SESSION_NAME
257
258 rm -rf "$TRACE_PATH"
259}
260
261function test_userspace_probe_enable_colon_in_path ()
262{
263 TRACE_PATH=$(mktemp -d)
264 SESSION_NAME="test_userspace_probe_enable_colon_in_path"
265 COLON_FILE_PATH=$(mktemp -d)
266 ELF_BIN_SYMLINK="$COLON_FILE_PATH/colon_:_in_name"
267 ELF_BIN_WITH_COLON_IN_NAME_ESCAPED="$COLON_FILE_PATH/colon_\:_in_name"
268 ENABLE_EXPR="elf:"$ELF_BIN_WITH_COLON_IN_NAME_ESCAPED":$ELF_SYMBOL"
269
270 ln -s $(realpath $ELF_TEST_BIN) $ELF_BIN_SYMLINK
271
272 diag "Userspace probe with binary with colon in name enabled successfully"
273
274 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
275
276 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
277
278 validate_list $SESSION_NAME $ELF_SYMBOL
279 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
280 validate_list $SESSION_NAME "ELF"
281 validate_list $SESSION_NAME "Function"
282
283 destroy_lttng_session_ok $SESSION_NAME
284
285 rm -rf "$TRACE_PATH"
286 rm -rf "$COLON_FILE_PATH"
287}
288
289function test_userspace_probe_elf ()
290{
291 TRACE_PATH=$(mktemp -d)
292 SESSION_NAME="test_userprobe_elf"
293 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
294
295 diag "Userspace probe on Elf symbol enabled and traced"
296
297 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
298
299 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
300
301 start_lttng_tracing_ok $SESSION_NAME
302 eval "$ELF_TEST_BIN" > /dev/null
303 stop_lttng_tracing_ok $SESSION_NAME
304
305 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
306
307 destroy_lttng_session_ok $SESSION_NAME
308
309 rm -rf "$TRACE_PATH"
310}
311
ef3dfe5d
FD
312function test_userspace_probe_elf_dynamic_symbol ()
313{
314 TRACE_PATH=$(mktemp -d)
315 SESSION_NAME="test_userprobe_elf"
316 LIBFOO_PATH="$ELF_TEST_BIN_DIR/libfoo.so"
317 ENABLE_EXPR="elf:$LIBFOO_PATH:dynamic_symbol"
318
319 diag "Userspace probe on Elf dynamic symbol enabled and traced"
320
321 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
322
323 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
324
325 start_lttng_tracing_ok $SESSION_NAME
326 eval "$ELF_TEST_BIN" > /dev/null
327 stop_lttng_tracing_ok $SESSION_NAME
328
329 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
330
331 destroy_lttng_session_ok $SESSION_NAME
332
333 rm -rf "$TRACE_PATH"
334}
335
a9c2df2b
FD
336function test_userspace_probe_elf_cxx_function ()
337{
338 TRACE_PATH=$(mktemp -d)
339 SESSION_NAME="test_userprobe_elf_cxx_function"
340 # Probing C++ mangled symbols should work the same way as regular Elf
341 # symbols
342 ELF_SYMBOL_CXX="_Z17test_cxx_functionv"
343 ENABLE_EXPR="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
344
345 diag "Userspace probe on C++ mangled function enabled and traced"
346
347 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
348
349 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
350
351 start_lttng_tracing_ok $SESSION_NAME
352 eval "$ELF_CXX_TEST_BIN" > /dev/null
353 stop_lttng_tracing_ok $SESSION_NAME
354
355 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
356
357 destroy_lttng_session_ok $SESSION_NAME
358
359 rm -rf "$TRACE_PATH"
360}
361
362function test_userspace_probe_elf_cxx_method ()
363{
364 TRACE_PATH=$(mktemp -d)
365 SESSION_NAME="test_userprobe_elf_cxx_method"
366 # Probing C++ mangled symbols should work the same way as regular Elf
367 # symbols
368 ELF_SYMBOL_CXX="_ZN10test_class11test_methodEv"
369 ENABLE_EXPR="elf:$ELF_CXX_TEST_BIN:$ELF_SYMBOL_CXX"
370
371 diag "Userspace probe on C++ mangled method enabled and traced"
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 start_lttng_tracing_ok $SESSION_NAME
378 eval "$ELF_CXX_TEST_BIN" > /dev/null
379 stop_lttng_tracing_ok $SESSION_NAME
380
381 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
382
383 destroy_lttng_session_ok $SESSION_NAME
384
385 rm -rf "$TRACE_PATH"
386}
387
388function test_userspace_probe_elf_disable ()
389{
390 TRACE_PATH=$(mktemp -d)
391 SESSION_NAME="test_userprobe_elf_disable"
392 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
393
394 diag "Userspace probe on Elf symbol disabled and traced"
395
396 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
397
398 # Activate and disable event
399 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
400 disable_kernel_lttng_userspace_probe_event_ok $SESSION_NAME $PROBE_EVENT_NAME
401
402 start_lttng_tracing_ok $SESSION_NAME
403 eval "$ELF_TEST_BIN" > /dev/null
404 stop_lttng_tracing_ok $SESSION_NAME
405
406 # Verify that the trace contains zero event.
407 validate_trace_empty "$TRACE_PATH"
408
409 destroy_lttng_session_ok $SESSION_NAME
410
411 rm -rf "$TRACE_PATH"
412}
413
414function test_userspace_probe_elf_list ()
415{
416 TRACE_PATH=$(mktemp -d)
417 SESSION_NAME="test_userprobe_elf_list"
418 ENABLE_EXPR="elf:$ELF_TEST_BIN:$ELF_SYMBOL"
419
420 diag "Userspace probe ELF enabled and listed"
421
422 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
423
424 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
425
426 validate_list $SESSION_NAME $PROBE_EVENT_NAME
427 validate_list $SESSION_NAME $ELF_SYMBOL
428 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
429 validate_list $SESSION_NAME "ELF"
430 validate_list $SESSION_NAME "Function"
431
432 destroy_lttng_session_ok $SESSION_NAME
433
434 rm -rf "$TRACE_PATH"
435}
436
437function test_userspace_probe_save_load_elf()
438{
439 # Test that the load and save works for userspace probes AND that when
440 # a userspace probe is placed on a symlink by the user the save command
441 # saves the path to the link and not to the actual file. This is to
442 # support instrumentation of shared objects that are often accessed
443 # through symlinks and updated.
444 TRACE_PATH=$(mktemp -d)
445 TMP_LINK_DIR=$(mktemp -d)
446 TMP_SAVE_DIR=$(mktemp -d)
447
448 SESSION_NAME="test_userprobe_save_load_elf"
449
450 ELF_BIN_SYMLINK="$TMP_LINK_DIR"/bin_elf_symlink
451
452 ENABLE_EXPR_ELF="elf:$ELF_BIN_SYMLINK:$ELF_SYMBOL"
453 PROBE_EVENT_NAME_ELF="$PROBE_EVENT_NAME"_elf
454
455 # Create symlinks to the target binaries.
456 ln -s $(realpath $ELF_TEST_BIN) $ELF_BIN_SYMLINK
457
458 diag "Userspace probes Elf are saved and loaded"
459
460 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
461
462 # Enable userspace prove events.
463 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR_ELF" "$PROBE_EVENT_NAME_ELF"
464
465 # Confirm that the events were enabled.
466 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
467
468 # Save the session to a file.
469 lttng_save $SESSION_NAME "--output-path=$TMP_SAVE_DIR"
470
471 destroy_lttng_session_ok $SESSION_NAME
472
473 # Confirm that the userspace probe are save to the xml file.
474 local count=$(cat $TMP_SAVE_DIR/* | grep --count -E "$ELF_BIN_SYMLINK")
475 if [[ $count -eq "1" ]]; then
476 pass "Symlink found in saved session"
477 else
478 fail "Symlink to binary not found in saved session"
479 fi
480
481 # Load the saved session.
482 lttng_load_ok "--input-path=$TMP_SAVE_DIR"
483
484 # Confirm that the userspace probes event are enabled in the newly
485 # loaded session.
486 validate_list $SESSION_NAME $ELF_TEST_BIN_NAME
487
488 # Cleanup temp files and folders.
489 rm -rf "$TRACE_PATH"
490 rm -rf "$TMP_LINK_DIR"
491 rm -rf "$TMP_SAVE_DIR"
492}
493function test_userspace_probe_save_load_sdt()
494{
495 # Test that the load and save works for userspace probes AND that when
496 # a userspace probe is placed on a symlink by the user the save command
497 # saves the path to the link and not to the actual file. This is to
498 # support instrumentation of shared objects that are often accessed
499 # through symlinks and updated.
500 TRACE_PATH=$(mktemp -d)
501 TMP_LINK_DIR=$(mktemp -d)
502 TMP_SAVE_DIR=$(mktemp -d)
503
504 SESSION_NAME="test_userprobe_save_load_sdt"
505 PROVIDER="foobar"
506 PROBE="tp1"
507
508 SDT_BIN_SYMLINK="$TMP_LINK_DIR"/bin_sdt_symlink
509
510 ENABLE_EXPR_SDT="sdt:$SDT_BIN_SYMLINK:$PROVIDER:$PROBE"
511 PROBE_EVENT_NAME_SDT="$PROBE_EVENT_NAME"_sdt
512
513 # Create symlinks to the target binaries.
514 ln -s $(realpath $SDT_TEST_BIN) $SDT_BIN_SYMLINK
515
516 diag "Userspace probes SDT are saved and loaded"
517
518 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
519
520 # Enable userspace prove events.
521 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR_SDT" "$PROBE_EVENT_NAME_SDT"
522
523 # Confirm that the events were enabled.
524 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
525
526 # Save the session to a file.
527 lttng_save $SESSION_NAME "--output-path=$TMP_SAVE_DIR"
528
529 destroy_lttng_session_ok $SESSION_NAME
530
531 # Confirm that the userspace probe are save to the xml file.
532 local count=$(cat $TMP_SAVE_DIR/* | grep --count -E "$SDT_BIN_SYMLINK")
533 if [[ $count -eq "1" ]]; then
534 pass "Symlink found in saved session"
535 else
536 fail "Symlink to binary not found in saved session"
537 fi
538
539 # Load the saved session.
540 lttng_load_ok "--input-path=$TMP_SAVE_DIR"
541
542 # Confirm that the userspace probes event are enabled in the newly
543 # loaded session.
544 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
545
546 # Cleanup temp files and folders.
547 rm -rf "$TRACE_PATH"
548 rm -rf "$TMP_LINK_DIR"
549 rm -rf "$TMP_SAVE_DIR"
550}
551
552function test_userspace_probe_sdt ()
553{
554 TRACE_PATH=$(mktemp -d)
555 PROVIDER="foobar"
556 PROBE="tp1"
557 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
558
559 diag "Userspace probe on SDT tracepoint enabled and traced"
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 start_lttng_tracing_ok $SESSION_NAME
566 eval "$SDT_TEST_BIN" > /dev/null
567 stop_lttng_tracing_ok $SESSION_NAME
568
569 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
570
571 destroy_lttng_session_ok $SESSION_NAME
572
573 rm -rf "$TRACE_PATH"
574}
575
576function test_userspace_probe_sdt_list ()
577{
578 TRACE_PATH=$(mktemp -d)
579 SESSION_NAME="test_userprobe_sdt_list"
580 PROVIDER="foobar"
581 PROBE="tp1"
582 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
583
584 diag "Userspace probe SDT enabled and listed"
585
586 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
587
588 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
589
590 validate_list $SESSION_NAME $PROBE_EVENT_NAME
591 validate_list $SESSION_NAME $PROVIDER
592 validate_list $SESSION_NAME $PROBE
593 validate_list $SESSION_NAME $SDT_TEST_BIN_NAME
594 validate_list $SESSION_NAME "SDT"
595 validate_list $SESSION_NAME "Tracepoint"
596
597 destroy_lttng_session_ok $SESSION_NAME
598
599 rm -rf "$TRACE_PATH"
600}
601
602function test_userspace_probe_enable_sdt_nonexistant_provider ()
603{
604 TRACE_PATH=$(mktemp -d)
605 SESSION_NAME="test_userprobe_sdt_nonexistand_provider"
606 PROVIDER="not_provider"
607 PROBE="tp1"
608 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
609
610 diag "Userspace probe SDT on tracepoint non existant provider"
611
612 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
613
614 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
615
616 destroy_lttng_session_ok $SESSION_NAME
617
618 rm -rf "$TRACE_PATH"
619}
620
621function test_userspace_probe_enable_sdt_nonexistant_probe ()
622{
623 TRACE_PATH=$(mktemp -d)
624 SESSION_NAME="test_userprobe_sdt_nonexistant_probe"
625 PROVIDER="foobar"
626 PROBE="not_a_tracepoint"
627 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
628
629 diag "Userspace probe SDT on non existant probe"
630
631 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
632
633 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
634
635 destroy_lttng_session_ok $SESSION_NAME
636
637 rm -rf "$TRACE_PATH"
638}
639
640function test_userspace_probe_enable_sdt_with_sema ()
641{
642 TRACE_PATH=$(mktemp -d)
643 SESSION_NAME="test_userprobe_sdt_with_sema"
644 PROVIDER="foobar"
645 PROBE="tp_with_semaphore"
646 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
647
648 diag "Userspace probe SDT on non existant probe"
649
650 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
651
652 lttng_enable_kernel_userspace_probe_event_fail $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
653
654 destroy_lttng_session_ok $SESSION_NAME
655
656 rm -rf "$TRACE_PATH"
657}
658
659function test_userspace_probe_sdt_one_probe ()
660{
661 TRACE_PATH=$(mktemp -d)
662 SESSION_NAME="test_userprobe_sdt_one_probe"
663 PROVIDER="foobar"
664 PROBE="tp1"
665 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
666
667 diag "Userspace probe SDT on tracepoint with one callsite"
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
684function test_userspace_probe_sdt_two_probes ()
685{
686 TRACE_PATH=$(mktemp -d)
687 SESSION_NAME="test_userprobe_sdt_two_probes"
688 PROVIDER="foobar"
689 PROBE="tp2"
690 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
691
692 diag "Userspace probe SDT on tracepoint with two callsites"
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
709function test_userspace_probe_sdt_in_shared_object ()
710{
711 TRACE_PATH=$(mktemp -d)
712 SESSION_NAME="test_userprobe_sdt_shared_object"
713 PROVIDER="foobar"
714 PROBE="tp_in_shared_object"
715 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libfoo.so:$PROVIDER:$PROBE"
716
717 diag "Userspace probe SDT on tracepoint in 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
734function test_userspace_probe_sdt_in_shared_object_dlopen ()
735{
736 TRACE_PATH=$(mktemp -d)
737 SESSION_NAME="test_userprobe_sdt_shared_object_dlopen"
738 PROVIDER="foobar"
739 PROBE="tp_in_dlopen"
740 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libbar.so:$PROVIDER:$PROBE"
741
742 diag "Userspace probe SDT on tracepoint in dlopen()ed 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 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
759function test_userspace_probe_sdt_in_shared_object_ldpreload ()
760{
761 TRACE_PATH=$(mktemp -d)
762 SESSION_NAME="test_userprobe_sdt_shared_object_ldpreload"
763 PROVIDER="foobar"
764 PROBE="tp_in_ldpreload"
765 ENABLE_EXPR="sdt:$SDT_TEST_BIN_DIR/libzzz.so:$PROVIDER:$PROBE"
766
767 diag "Userspace probe SDT on tracepoint in an LD_PRELOADed shared object"
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 LD_PRELOAD="$SDT_TEST_BIN_DIR/libzzz.so" 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
784function test_userspace_probe_sdt_with_arg ()
785{
786 TRACE_PATH=$(mktemp -d)
787 SESSION_NAME="test_userprobe_sdt_arg"
788 PROVIDER="foobar"
789 PROBE="tp_with_arg"
790 ENABLE_EXPR="sdt:$SDT_TEST_BIN:$PROVIDER:$PROBE"
791
792 diag "Userspace probe SDT on tracepoint with argument"
793
794 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
795
796 lttng_enable_kernel_userspace_probe_event_ok $SESSION_NAME "$ENABLE_EXPR" $PROBE_EVENT_NAME
797
798 start_lttng_tracing_ok $SESSION_NAME
799 eval "$SDT_TEST_BIN" > /dev/null
800 stop_lttng_tracing_ok $SESSION_NAME
801
802 validate_trace $PROBE_EVENT_NAME "$TRACE_PATH"
803
804 destroy_lttng_session_ok $SESSION_NAME
805
806 rm -rf "$TRACE_PATH"
807}
808
809ls "$SDT_TEST_BIN" >/dev/null 2>&1
810if test $? == 0; then
811 NUM_TESTS=$((NUM_TESTS+68))
812 RUN_SDT_TESTS=1
813else
814 RUN_SDT_TESTS=0
815fi
816
817ls "$ELF_CXX_TEST_BIN" >/dev/null 2>&1
818if test $? == 0; then
819 NUM_TESTS=$((NUM_TESTS+12))
820 RUN_ELF_CXX_TESTS=1
821else
822 RUN_ELF_CXX_TESTS=0
823fi
824plan_tests $NUM_TESTS
825print_test_banner "$TEST_DESC"
826
827if [ "$(id -u)" == "0" ]; then
828 isroot=1
829else
830 isroot=0
831fi
832
833skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
834{
835 start_lttng_sessiond
836
837 # Unsuccessful event enabling
838 test_userspace_probe_enable_file_noexist
839 test_userspace_probe_enable_file_not_elf
840
841 test_userspace_probe_enable_elf_missing_symbol_name
842 test_userspace_probe_enable_elf_nonexistant_symbol
843 test_userspace_probe_enable_elf_symbol_not_function
6a0a91e8 844 test_userspace_probe_unsupported_types
a9c2df2b
FD
845
846 # Successful userspace probe elf enabling
847 test_userspace_probe_enable_implicit_probe_type
848 test_userspace_probe_enable_in_path
849 test_userspace_probe_enable_full_path
850 test_userspace_probe_enable_elf_symbol_exists
851 test_userspace_probe_enable_colon_in_path
852
853 # Successful tracing userspace probe elf
854 test_userspace_probe_elf
ef3dfe5d 855 test_userspace_probe_elf_dynamic_symbol
a9c2df2b
FD
856
857 # Disable userspace-probe elf
858 test_userspace_probe_elf_disable
859
860 # Successful listing of userspace probe elf
861 test_userspace_probe_elf_list
862
863 # Successful save and load of userspace probe elf
864 test_userspace_probe_save_load_elf
865
866 if test $RUN_ELF_CXX_TESTS == 1; then
867 # Successful tracing of userspace probe elf on C++ symbol
868 test_userspace_probe_elf_cxx_function
869 test_userspace_probe_elf_cxx_method
870 fi
871
872 if test $RUN_SDT_TESTS == 1; then
873 # Unsuccessful event enabling
874 test_userspace_probe_enable_sdt_nonexistant_provider
875 test_userspace_probe_enable_sdt_nonexistant_probe
876 test_userspace_probe_enable_sdt_with_sema
877
878 # Successful userspace probe sdt enabling
879 test_userspace_probe_sdt_one_probe
880 test_userspace_probe_sdt_two_probes
881 test_userspace_probe_sdt_with_arg
882 test_userspace_probe_sdt_in_shared_object
883 test_userspace_probe_sdt_in_shared_object_dlopen
884 test_userspace_probe_sdt_in_shared_object_ldpreload
885
886 # Successful tracing of userspace probe sdt
887 test_userspace_probe_sdt
888
889 # Successful listing of userspace probe sdt
890 test_userspace_probe_sdt_list
891
892 # Successful save and load of userspace probe sdt
893 test_userspace_probe_save_load_sdt
894 fi
895
896 stop_lttng_sessiond
897}
This page took 0.059893 seconds and 5 git commands to generate.