3 # Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 TEST_DESC
="Metadata env - Kernel space tracing"
19 CURDIR
=$
(dirname "$0")/
20 TESTDIR
=$CURDIR/..
/..
/..
21 EVENT_NAME
="lttng_test_filter_event"
23 TRACE_PATH
=$
(mktemp
-d)
27 source "$TESTDIR/utils/utils.sh"
29 # Fetch utils functions common to ust and kernel tests.
30 source "$CURDIR/utils.sh"
32 function test_kernel
()
39 local expected_path
="${TRACE_PATH}/lttng-traces"
40 local session_name
="kernel"
43 metadata_env
=$
(mktemp
)
45 diag
"Test Kernel metadata env field"
46 create_lttng_session_ok
"$session_name"
47 enable_kernel_lttng_event_ok
"$session_name" "$EVENT_NAME"
48 start_lttng_tracing_ok
"$session_name"
50 echo -n "10" > /proc
/lttng-test-filter-event
52 stop_lttng_tracing_ok
"$session_name"
53 destroy_lttng_session_ok
"$session_name"
55 # bt1 accepts only a directory while bt2 accepts either the metadata
56 # file directly or a directory with an immediate metadata file.
57 # Settle for the common denominator.
58 metadata_path
=$
(find "${expected_path}/${session_name}"* |
grep metadata
)
59 metadata_path
=$
(dirname "$metadata_path")
61 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" > "$metadata"
64 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
66 # Construct the expected path from the env metadata and use it to
67 # validate that all information make sense. This information is present
68 # to allow trace viewer to recreate the same directory hierarchy.
71 value
=$
(get_env_value
"$metadata_env" trace_name
)
72 ok $?
"Extracting trace_name from env metadata"
73 expected_path
="${expected_path}/${value}"
75 # Session creation time
76 value
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
77 ok $?
"Extracting trace_creation_datetime from env metadata"
78 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
79 expected_path
="${expected_path}-${value}"
82 value
=$
(get_env_value
"$metadata_env" domain
)
83 ok $?
"Extracting domain from env metadata"
84 expected_path
="${expected_path}/${value}"
86 # Append "metadata" and test that we find the file.
87 expected_path
="${expected_path}/metadata"
89 test -e "$expected_path"
90 ok $?
"Reconstructed path from metadata is valid"
93 # The hostname is not part of the lttng hierarchy still we can test for
95 value
=$
(get_env_value
"$metadata_env" hostname
)
96 ok $?
"Extracting hostname from env metadata"
97 is
"$value" "$(hostname)" "Hostname is valid"
100 rm -f "$metadata_env"
103 plan_tests
$NUM_TESTS
104 print_test_banner
"$TEST_DESC"
107 if [ "$(id -u)" == "0" ]; then
113 skip
$isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
115 validate_lttng_modules_present
118 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
119 # with "<session_name>-<datetime>/...".
120 LTTNG_HOME
="$TRACE_PATH"
125 tests
=( test_kernel
)
127 for fct_test
in "${tests[@]}";