Tests: metadata env scope values
[lttng-tools.git] / tests / regression / tools / metadata / test_kernel
1 #!/bin/bash
2 #
3 # Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 #
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.
8 #
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
12 # details.
13 #
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"
18
19 CURDIR=$(dirname "$0")/
20 TESTDIR=$CURDIR/../../..
21 EVENT_NAME="lttng_test_filter_event"
22
23 TRACE_PATH=$(mktemp -d)
24
25 NUM_TESTS=13
26
27 source "$TESTDIR/utils/utils.sh"
28
29 # Fetch utils functions common to ust and kernel tests.
30 source "$CURDIR/utils.sh"
31
32 function test_kernel ()
33 {
34 local metadata
35 local metadata_env
36 local metadata_path
37 local value
38
39 local expected_path="${TRACE_PATH}/lttng-traces"
40 local session_name="kernel"
41
42 metadata=$(mktemp)
43 metadata_env=$(mktemp)
44
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"
49
50 echo -n "10" > /proc/lttng-test-filter-event
51
52 stop_lttng_tracing_ok "$session_name"
53 destroy_lttng_session_ok "$session_name"
54
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")
60
61 $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" > "$metadata"
62
63 # Extract "env" scope
64 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
65
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.
69
70 # Trace name
71 value=$(get_env_value "$metadata_env" trace_name)
72 ok $? "Extracting trace_name from env metadata"
73 expected_path="${expected_path}/${value}"
74
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}"
80
81 # Domain
82 value=$(get_env_value "$metadata_env" domain)
83 ok $? "Extracting domain from env metadata"
84 expected_path="${expected_path}/${value}"
85
86 # Append "metadata" and test that we find the file.
87 expected_path="${expected_path}/metadata"
88
89 test -e "$expected_path"
90 ok $? "Reconstructed path from metadata is valid"
91
92 # Hostname
93 # The hostname is not part of the lttng hierarchy still we can test for
94 # its validity here.
95 value=$(get_env_value "$metadata_env" hostname)
96 ok $? "Extracting hostname from env metadata"
97 is "$value" "$(hostname)" "Hostname is valid"
98
99 rm -f "$metadata"
100 rm -f "$metadata_env"
101 }
102
103 plan_tests $NUM_TESTS
104 print_test_banner "$TEST_DESC"
105
106
107 if [ "$(id -u)" == "0" ]; then
108 isroot=1
109 else
110 isroot=0
111 fi
112
113 skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
114 {
115 validate_lttng_modules_present
116 modprobe lttng-test
117
118 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
119 # with "<session_name>-<datetime>/...".
120 LTTNG_HOME="$TRACE_PATH"
121
122 export LTTNG_HOME
123 start_lttng_sessiond
124
125 tests=( test_kernel )
126
127 for fct_test in "${tests[@]}";
128 do
129 ${fct_test}
130 done
131
132 rmmod lttng-test
133
134 stop_lttng_sessiond
135 unset LTTNG_HOME
136 }
137
138 rm -rf "$TRACE_PATH"
This page took 0.0313 seconds and 4 git commands to generate.