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
-d -t 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
()
28 local expected_path
="${TRACE_PATH}/lttng-traces"
29 local session_name
="kernel"
31 metadata
=$
(mktemp
-t "tmp.test_kernel_metadata.XXXXXX")
32 metadata_env
=$
(mktemp
-t "tmp.test_kernel_metadata_env.XXXXXX")
34 diag
"Test Kernel metadata env field"
35 create_lttng_session_ok
"$session_name"
36 enable_kernel_lttng_event_ok
"$session_name" "$EVENT_NAME"
37 start_lttng_tracing_ok
"$session_name"
39 echo -n "10" > /proc
/lttng-test-filter-event
41 stop_lttng_tracing_ok
"$session_name"
42 destroy_lttng_session_ok
"$session_name"
44 # bt1 accepts only a directory while bt2 accepts either the metadata
45 # file directly or a directory with an immediate metadata file.
46 # Settle for the common denominator.
47 metadata_path
=$
(find "${expected_path}/${session_name}"* -name "metadata")
48 metadata_path
=$
(dirname "$metadata_path")
50 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" > "$metadata"
53 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
55 # Construct the expected path from the env metadata and use it to
56 # validate that all information make sense. This information is present
57 # to allow trace viewer to recreate the same directory hierarchy.
61 trace_name
=$
(get_env_value
"$metadata_env" trace_name
)
62 ok $?
"Extracting trace_name from env metadata: \`$trace_name\`"
63 expected_path
="${expected_path}/${trace_name}"
65 # Session creation time
66 local trace_creation_datetime
67 trace_creation_datetime
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
68 ok $?
"Extracting trace_creation_datetime from env metadata: \`$trace_creation_datetime\`"
69 trace_creation_datetime
=$
(iso8601_to_lttng_dir_datetime
"$trace_creation_datetime")
70 expected_path
="${expected_path}-${trace_creation_datetime}"
74 domain
=$
(get_env_value
"$metadata_env" domain
)
75 ok $?
"Extracting domain from env metadata: \`$domain\`"
76 expected_path
="${expected_path}/${domain}"
78 # Append "metadata" and test that we find the file.
79 expected_path
="${expected_path}/metadata"
81 test -f "$expected_path"
82 ok $?
"Reconstructed path from metadata is an existing file: \`$expected_path\`"
85 # The hostname is not part of the lttng hierarchy still we can test for
88 hostname
=$
(get_env_value
"$metadata_env" hostname
)
89 ok $?
"Extracting hostname from env metadata: \`$hostname\`"
90 is
"$hostname" "$(hostname)" "Extracted hostname matches current hostname"
97 print_test_banner
"$TEST_DESC"
99 bail_out_if_no_babeltrace
101 if [ "$(id -u)" == "0" ]; then
107 skip
$isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
109 validate_lttng_modules_present
112 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
113 # with "<session_name>-<datetime>/...".
114 export LTTNG_HOME
="$TRACE_PATH"
118 tests
=( test_kernel
)
120 for fct_test
in "${tests[@]}";
125 modprobe
--remove lttng-test