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 - User space tracing"
19 CURDIR
=$
(dirname "$0")/
20 TESTDIR
=$CURDIR/..
/..
/..
21 TESTAPP_PATH
="$TESTDIR/utils/testapp"
22 TESTAPP_NAME
="gen-ust-events"
23 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
24 EVENT_NAME
="tp:tptest"
26 TRACE_PATH
=$
(mktemp
-d)
33 source "$TESTDIR/utils/utils.sh"
35 # Fetch utils functions common to ust and kernel tests.
36 source "$CURDIR/utils.sh"
38 if [ ! -x "$TESTAPP_BIN" ]; then
39 BAIL_OUT
"No UST events binary detected."
42 function test_per_uid
()
50 local expected_path
="${TRACE_PATH}/lttng-traces"
51 local session_name
="per-uid"
54 metadata_env
=$
(mktemp
)
56 diag
"Test UST metadata env field in per-uid mode"
57 create_lttng_session_ok
"$session_name"
58 enable_ust_lttng_event_ok
"$session_name" $EVENT_NAME
59 start_lttng_tracing_ok
"$session_name"
61 $TESTAPP_BIN -i $NR_ITER
63 stop_lttng_tracing_ok
"$session_name"
64 destroy_lttng_session_ok
"$session_name"
66 # bt1 accepts only a directory while bt2 accepts either the metadata
67 # file directly or a directory with an immediate metadata file.
68 # Settle for the common denominator.
69 metadata_path
=$
(find "${expected_path}/${session_name}"* |
grep metadata
)
70 metadata_path
=$
(dirname "$metadata_path")
72 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" > "$metadata"
75 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
77 # Construct the expected path from the env metadata and use it to
78 # validate that all information make sense. This information is present
79 # to allow trace viewer to recreate the same directory hierarchy.
82 value
=$
(get_env_value
"$metadata_env" trace_name
)
83 ok $?
"Extracting trace_name from env metadata"
84 expected_path
="${expected_path}/${value}"
86 # Session creation time
87 value
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
88 ok $?
"Extracting trace_creation_datetime from env metadata"
89 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
90 expected_path
="${expected_path}-${value}"
93 value
=$
(get_env_value
"$metadata_env" domain
)
94 ok $?
"Extracting domain from env metadata"
95 expected_path
="${expected_path}/${value}"
98 value
=$
(get_env_value
"$metadata_env" tracer_buffering_scheme
)
99 ok $?
"Extracting tracer_buffering_scheme from env metadata"
100 expected_path
="${expected_path}/${value}"
102 # tracer_buffering_id
103 value
=$
(get_env_value
"$metadata_env" tracer_buffering_id
)
104 ok $?
"Extracting tracer_buffering_id from env metadata"
105 expected_path
="${expected_path}/${value}"
107 # Check that the uid is the one we expect from the current user
108 is
"$value" "$(id -u)" "tracer_buffering_id match current user uid"
110 # Architecture_bit_width
111 value
=$
(get_env_value
"$metadata_env" architecture_bit_width
)
112 ok $?
"Extracting architecture_bit_width from env metadata"
113 expected_path
="${expected_path}/${value}-bit"
115 # Append "metadata" and test that we find the file.
116 expected_path
="${expected_path}/metadata"
118 test -e "$expected_path"
119 ok $?
"Reconstructed path from metadata is valid"
122 # The hostname is not part of the lttng hierarchy still we can test for
124 value
=$
(get_env_value
"$metadata_env" hostname
)
125 ok $?
"Extracting hostname from env metadata"
126 is
"$value" "$(hostname)" "Hostname is valid"
129 rm -f "$metadata_env"
132 function test_per_pid
()
141 local expected_path
="${TRACE_PATH}/lttng-traces"
142 local session_name
="per-pid"
145 metadata_env
=$
(mktemp
)
147 diag
"Test UST metadata env field in per-pid mode"
148 create_lttng_session_ok
"$session_name"
149 enable_ust_lttng_channel_ok
"$session_name" channel
"--buffers-pid"
150 enable_ust_lttng_event_ok
"$session_name" $EVENT_NAME channel
151 start_lttng_tracing_ok
"$session_name"
153 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
157 stop_lttng_tracing_ok
"$session_name"
158 destroy_lttng_session_ok
"$session_name"
160 # bt1 accepts only a directory while bt2 accepts either the metadata
161 # file directly or a directory with an immediate metadata file.
162 # Settle for the common denominator.
163 metadata_path
=$
(find "${expected_path}/${session_name}"* |
grep metadata
)
164 metadata_path
=$
(dirname "$metadata_path")
166 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" 1> "$metadata"
168 # Extract "env" scope
169 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
171 # Construct the expected path from the env metadata and use it to
172 # validate that all information make sense. This information is present
173 # to allow trace viewer to recreate the same directory hierarchy.
176 value
=$
(get_env_value
"$metadata_env" trace_name
)
177 ok $?
"Extracting trace_name from env metadata"
178 expected_path
="${expected_path}/${value}"
180 # Session creation time
181 value
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
182 ok $?
"Extracting trace_creation_datetime from env metadata"
183 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
184 expected_path
="${expected_path}-${value}"
187 value
=$
(get_env_value
"$metadata_env" domain
)
188 ok $?
"Extracting domain from env metadata"
189 expected_path
="${expected_path}/${value}"
192 value
=$
(get_env_value
"$metadata_env" tracer_buffering_scheme
)
193 ok $?
"Extracting tracer_buffering_scheme from env metadata"
194 expected_path
="${expected_path}/${value}"
197 value
=$
(get_env_value
"$metadata_env" procname
)
198 ok $?
"Extracting procname from env metadata"
199 expected_path
="${expected_path}/${value}"
201 # vpid and tracer_buffering_id should be the same here.
202 # "vpid =" is used since other key have vpid in them.
203 value
=$
(get_env_value
"$metadata_env" "vpid =")
204 ok $?
"Extracting vpid from env metadata"
206 value2
=$
(get_env_value
"$metadata_env" tracer_buffering_id
)
207 ok $?
"Extracting tracer_buffering_id from env metadata"
208 expected_path
="${expected_path}-${value2}"
210 is
"$value" "$value2" "vpid and tracer_buffering_id are identical"
211 is
"$testapp_pid" "$value" "vpid and known testapp pid are identical"
212 is
"$testapp_pid" "$value2" "tracer_buffering_id and known testapp pid are identical"
215 value
=$
(get_env_value
"$metadata_env" vpid_datetime
)
216 ok $?
"Extracting vpid_datetime from env metadata"
217 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
218 expected_path
="${expected_path}-${value}"
220 # Append "metadata" and test that we find the file.
221 expected_path
="${expected_path}/metadata"
223 test -e "$expected_path"
224 ok $?
"Reconstructed path from metadata is valid"
227 # The hostname is not part of the lttng hierarchy still we can test for
229 value
=$
(get_env_value
"$metadata_env" hostname
)
230 ok $?
"Extracting hostname from env metadata"
231 is
"$value" "$(hostname)" "Hostname is valid"
234 rm -f "$metadata_env"
237 plan_tests
$NUM_TESTS
239 print_test_banner
"$TEST_DESC"
241 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
242 # with "<session_name>-<datetime>/...".
243 LTTNG_HOME
="$TRACE_PATH"
248 tests
=( test_per_uid test_per_pid
)
250 for fct_test
in "${tests[@]}";