3 # Copyright (C) 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Metadata env - User space tracing"
9 CURDIR
=$
(dirname "$0")/
10 TESTDIR
=$CURDIR/..
/..
/..
11 TESTAPP_PATH
="$TESTDIR/utils/testapp"
12 TESTAPP_NAME
="gen-ust-events"
13 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
14 EVENT_NAME
="tp:tptest"
16 TRACE_PATH
=$
(mktemp
-d)
23 source "$TESTDIR/utils/utils.sh"
25 # Fetch utils functions common to ust and kernel tests.
26 source "$CURDIR/utils.sh"
28 if [ ! -x "$TESTAPP_BIN" ]; then
29 BAIL_OUT
"No UST events binary detected."
32 function test_per_uid
()
40 local expected_path
="${TRACE_PATH}/lttng-traces"
41 local session_name
="per-uid"
44 metadata_env
=$
(mktemp
)
46 diag
"Test UST metadata env field in per-uid mode"
47 create_lttng_session_ok
"$session_name"
48 enable_ust_lttng_event_ok
"$session_name" $EVENT_NAME
49 start_lttng_tracing_ok
"$session_name"
51 $TESTAPP_BIN -i $NR_ITER
53 stop_lttng_tracing_ok
"$session_name"
54 destroy_lttng_session_ok
"$session_name"
56 # bt1 accepts only a directory while bt2 accepts either the metadata
57 # file directly or a directory with an immediate metadata file.
58 # Settle for the common denominator.
59 metadata_path
=$
(find "${expected_path}/${session_name}"* |
grep metadata
)
60 metadata_path
=$
(dirname "$metadata_path")
62 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" > "$metadata"
65 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
67 # Construct the expected path from the env metadata and use it to
68 # validate that all information make sense. This information is present
69 # to allow trace viewer to recreate the same directory hierarchy.
72 value
=$
(get_env_value
"$metadata_env" trace_name
)
73 ok $?
"Extracting trace_name from env metadata"
74 expected_path
="${expected_path}/${value}"
76 # Session creation time
77 value
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
78 ok $?
"Extracting trace_creation_datetime from env metadata"
79 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
80 expected_path
="${expected_path}-${value}"
83 value
=$
(get_env_value
"$metadata_env" domain
)
84 ok $?
"Extracting domain from env metadata"
85 expected_path
="${expected_path}/${value}"
88 value
=$
(get_env_value
"$metadata_env" tracer_buffering_scheme
)
89 ok $?
"Extracting tracer_buffering_scheme from env metadata"
90 expected_path
="${expected_path}/${value}"
93 value
=$
(get_env_value
"$metadata_env" tracer_buffering_id
)
94 ok $?
"Extracting tracer_buffering_id from env metadata"
95 expected_path
="${expected_path}/${value}"
97 # Check that the uid is the one we expect from the current user
98 is
"$value" "$(id -u)" "tracer_buffering_id match current user uid"
100 # Architecture_bit_width
101 value
=$
(get_env_value
"$metadata_env" architecture_bit_width
)
102 ok $?
"Extracting architecture_bit_width from env metadata"
103 expected_path
="${expected_path}/${value}-bit"
105 # Append "metadata" and test that we find the file.
106 expected_path
="${expected_path}/metadata"
108 test -e "$expected_path"
109 ok $?
"Reconstructed path from metadata is valid"
112 # The hostname is not part of the lttng hierarchy still we can test for
114 value
=$
(get_env_value
"$metadata_env" hostname
)
115 ok $?
"Extracting hostname from env metadata"
116 is
"$value" "$(hostname)" "Hostname is valid"
119 rm -f "$metadata_env"
122 function test_per_pid
()
131 local expected_path
="${TRACE_PATH}/lttng-traces"
132 local session_name
="per-pid"
135 metadata_env
=$
(mktemp
)
137 diag
"Test UST metadata env field in per-pid mode"
138 create_lttng_session_ok
"$session_name"
139 enable_ust_lttng_channel_ok
"$session_name" channel
"--buffers-pid"
140 enable_ust_lttng_event_ok
"$session_name" $EVENT_NAME channel
141 start_lttng_tracing_ok
"$session_name"
143 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
147 stop_lttng_tracing_ok
"$session_name"
148 destroy_lttng_session_ok
"$session_name"
150 # bt1 accepts only a directory while bt2 accepts either the metadata
151 # file directly or a directory with an immediate metadata file.
152 # Settle for the common denominator.
153 metadata_path
=$
(find "${expected_path}/${session_name}"* |
grep metadata
)
154 metadata_path
=$
(dirname "$metadata_path")
156 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" 1> "$metadata"
158 # Extract "env" scope
159 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
161 # Construct the expected path from the env metadata and use it to
162 # validate that all information make sense. This information is present
163 # to allow trace viewer to recreate the same directory hierarchy.
166 value
=$
(get_env_value
"$metadata_env" trace_name
)
167 ok $?
"Extracting trace_name from env metadata"
168 expected_path
="${expected_path}/${value}"
170 # Session creation time
171 value
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
172 ok $?
"Extracting trace_creation_datetime from env metadata"
173 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
174 expected_path
="${expected_path}-${value}"
177 value
=$
(get_env_value
"$metadata_env" domain
)
178 ok $?
"Extracting domain from env metadata"
179 expected_path
="${expected_path}/${value}"
182 value
=$
(get_env_value
"$metadata_env" tracer_buffering_scheme
)
183 ok $?
"Extracting tracer_buffering_scheme from env metadata"
184 expected_path
="${expected_path}/${value}"
187 value
=$
(get_env_value
"$metadata_env" procname
)
188 ok $?
"Extracting procname from env metadata"
189 expected_path
="${expected_path}/${value}"
191 # vpid and tracer_buffering_id should be the same here.
192 # "vpid =" is used since other key have vpid in them.
193 value
=$
(get_env_value
"$metadata_env" "vpid =")
194 ok $?
"Extracting vpid from env metadata"
196 value2
=$
(get_env_value
"$metadata_env" tracer_buffering_id
)
197 ok $?
"Extracting tracer_buffering_id from env metadata"
198 expected_path
="${expected_path}-${value2}"
200 is
"$value" "$value2" "vpid and tracer_buffering_id are identical"
201 is
"$testapp_pid" "$value" "vpid and known testapp pid are identical"
202 is
"$testapp_pid" "$value2" "tracer_buffering_id and known testapp pid are identical"
205 value
=$
(get_env_value
"$metadata_env" vpid_datetime
)
206 ok $?
"Extracting vpid_datetime from env metadata"
207 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
208 expected_path
="${expected_path}-${value}"
210 # Append "metadata" and test that we find the file.
211 expected_path
="${expected_path}/metadata"
213 test -e "$expected_path"
214 ok $?
"Reconstructed path from metadata is valid"
217 # The hostname is not part of the lttng hierarchy still we can test for
219 value
=$
(get_env_value
"$metadata_env" hostname
)
220 ok $?
"Extracting hostname from env metadata"
221 is
"$value" "$(hostname)" "Hostname is valid"
224 rm -f "$metadata_env"
227 plan_tests
$NUM_TESTS
229 print_test_banner
"$TEST_DESC"
231 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
232 # with "<session_name>-<datetime>/...".
233 LTTNG_HOME
="$TRACE_PATH"
238 tests
=( test_per_uid test_per_pid
)
240 for fct_test
in "${tests[@]}";