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)
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
()
29 local expected_path
="${TRACE_PATH}/lttng-traces"
30 local session_name
="kernel"
33 metadata_env
=$
(mktemp
)
35 diag
"Test Kernel metadata env field"
36 create_lttng_session_ok
"$session_name"
37 enable_kernel_lttng_event_ok
"$session_name" "$EVENT_NAME"
38 start_lttng_tracing_ok
"$session_name"
40 echo -n "10" > /proc
/lttng-test-filter-event
42 stop_lttng_tracing_ok
"$session_name"
43 destroy_lttng_session_ok
"$session_name"
45 # bt1 accepts only a directory while bt2 accepts either the metadata
46 # file directly or a directory with an immediate metadata file.
47 # Settle for the common denominator.
48 metadata_path
=$
(find "${expected_path}/${session_name}"* |
grep metadata
)
49 metadata_path
=$
(dirname "$metadata_path")
51 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" > "$metadata"
54 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
56 # Construct the expected path from the env metadata and use it to
57 # validate that all information make sense. This information is present
58 # to allow trace viewer to recreate the same directory hierarchy.
61 value
=$
(get_env_value
"$metadata_env" trace_name
)
62 ok $?
"Extracting trace_name from env metadata"
63 expected_path
="${expected_path}/${value}"
65 # Session creation time
66 value
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
67 ok $?
"Extracting trace_creation_datetime from env metadata"
68 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
69 expected_path
="${expected_path}-${value}"
72 value
=$
(get_env_value
"$metadata_env" domain
)
73 ok $?
"Extracting domain from env metadata"
74 expected_path
="${expected_path}/${value}"
76 # Append "metadata" and test that we find the file.
77 expected_path
="${expected_path}/metadata"
79 test -e "$expected_path"
80 ok $?
"Reconstructed path from metadata is valid"
83 # The hostname is not part of the lttng hierarchy still we can test for
85 value
=$
(get_env_value
"$metadata_env" hostname
)
86 ok $?
"Extracting hostname from env metadata"
87 is
"$value" "$(hostname)" "Hostname is valid"
94 print_test_banner
"$TEST_DESC"
97 if [ "$(id -u)" == "0" ]; then
103 skip
$isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
105 validate_lttng_modules_present
108 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
109 # with "<session_name>-<datetime>/...".
110 LTTNG_HOME
="$TRACE_PATH"
115 tests
=( test_kernel
)
117 for fct_test
in "${tests[@]}";
122 modprobe
--remove lttng-test