3 # Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Metadata env - Kernel space tracing"
9 CURDIR
=$
(dirname "$0")/
10 TESTDIR
=$CURDIR/..
/..
/..
11 EVENT_NAME
="lttng_test_filter_event"
13 TRACE_PATH
=$
(mktemp
--tmpdir -d tmp.test_metadata_env_kernel_trace_path.XXXXXX
)
17 source "$TESTDIR/utils/utils.sh"
19 # Fetch utils functions common to ust and kernel tests.
20 source "$CURDIR/utils.sh"
22 function test_kernel
()
27 local expected_path
="${TRACE_PATH}/lttng-traces"
28 local session_name
="kernel"
29 local metadata
=$
(mktemp
--tmpdir "tmp.${FUNCNAME[0]}_metadata.XXXXXX")
30 local metadata_env
=$
(mktemp
--tmpdir "tmp.${FUNCNAME[0]}_metadata_env.XXXXXX")
32 diag
"Test Kernel metadata env field"
33 create_lttng_session_ok
"$session_name"
34 enable_kernel_lttng_event_ok
"$session_name" "$EVENT_NAME"
35 start_lttng_tracing_ok
"$session_name"
37 echo -n "10" > /proc
/lttng-test-filter-event
39 stop_lttng_tracing_ok
"$session_name"
40 destroy_lttng_session_ok
"$session_name"
42 # bt1 accepts only a directory while bt2 accepts either the metadata
43 # file directly or a directory with an immediate metadata file.
44 # Settle for the common denominator.
45 metadata_path
=$
(find "${expected_path}/${session_name}"* -name "metadata")
46 metadata_path
=$
(dirname "$metadata_path")
48 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" > "$metadata"
51 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
53 # Construct the expected path from the env metadata and use it to
54 # validate that all information make sense. This information is present
55 # to allow trace viewer to recreate the same directory hierarchy.
58 value
=$
(get_env_value
"$metadata_env" trace_name
)
59 ok $?
"Extracting trace_name from env metadata"
60 expected_path
="${expected_path}/${value}"
62 # Session creation time
63 value
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
64 ok $?
"Extracting trace_creation_datetime from env metadata"
65 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
66 expected_path
="${expected_path}-${value}"
69 value
=$
(get_env_value
"$metadata_env" domain
)
70 ok $?
"Extracting domain from env metadata"
71 expected_path
="${expected_path}/${value}"
73 # Append "metadata" and test that we find the file.
74 expected_path
="${expected_path}/metadata"
76 test -e "$expected_path"
77 ok $?
"Reconstructed path from metadata is valid"
80 # The hostname is not part of the lttng hierarchy still we can test for
82 value
=$
(get_env_value
"$metadata_env" hostname
)
83 ok $?
"Extracting hostname from env metadata"
84 is
"$value" "$(hostname)" "Hostname is valid"
91 print_test_banner
"$TEST_DESC"
94 if [ "$(id -u)" == "0" ]; then
100 skip
$isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
102 validate_lttng_modules_present
105 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
106 # with "<session_name>-<datetime>/...".
107 LTTNG_HOME
="$TRACE_PATH"
112 tests
=( test_kernel
)
114 for fct_test
in "${tests[@]}";
119 modprobe
--remove lttng-test