3 # Copyright (C) 2019 Jonathan Rajotte <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
--tmpdir -d tmp.test_metadata_env_ust_trace_path.XXXXXX
)
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
()
38 local expected_path
="${TRACE_PATH}/lttng-traces"
39 local session_name
="per-uid"
40 local metadata
=$
(mktemp
--tmpdir tmp.test_
${FUNCNAME[0]}_metadata.XXXXXX
)
41 local metadata_env
=$
(mktemp
--tmpdir tmp.test_
${FUNCNAME[0]}_metadata_env.XXXXXX
)
43 diag
"Test UST metadata env field in per-uid mode"
44 create_lttng_session_ok
"$session_name"
45 enable_ust_lttng_event_ok
"$session_name" $EVENT_NAME
46 start_lttng_tracing_ok
"$session_name"
48 $TESTAPP_BIN -i $NR_ITER
50 stop_lttng_tracing_ok
"$session_name"
51 destroy_lttng_session_ok
"$session_name"
53 # bt1 accepts only a directory while bt2 accepts either the metadata
54 # file directly or a directory with an immediate metadata file.
55 # Settle for the common denominator.
56 metadata_path
=$
(find "${expected_path}/${session_name}"* -name "metadata")
57 metadata_path
=$
(dirname "$metadata_path")
59 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" > "$metadata"
62 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
64 # Construct the expected path from the env metadata and use it to
65 # validate that all information make sense. This information is present
66 # to allow trace viewer to recreate the same directory hierarchy.
69 value
=$
(get_env_value
"$metadata_env" trace_name
)
70 ok $?
"Extracting trace_name from env metadata"
71 expected_path
="${expected_path}/${value}"
73 # Session creation time
74 value
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
75 ok $?
"Extracting trace_creation_datetime from env metadata"
76 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
77 expected_path
="${expected_path}-${value}"
80 value
=$
(get_env_value
"$metadata_env" domain
)
81 ok $?
"Extracting domain from env metadata"
82 expected_path
="${expected_path}/${value}"
85 value
=$
(get_env_value
"$metadata_env" tracer_buffering_scheme
)
86 ok $?
"Extracting tracer_buffering_scheme from env metadata"
87 expected_path
="${expected_path}/${value}"
90 value
=$
(get_env_value
"$metadata_env" tracer_buffering_id
)
91 ok $?
"Extracting tracer_buffering_id from env metadata"
92 expected_path
="${expected_path}/${value}"
94 # Check that the uid is the one we expect from the current user
95 is
"$value" "$(id -u)" "tracer_buffering_id match current user uid"
97 # Architecture_bit_width
98 value
=$
(get_env_value
"$metadata_env" architecture_bit_width
)
99 ok $?
"Extracting architecture_bit_width from env metadata"
100 expected_path
="${expected_path}/${value}-bit"
102 # Append "metadata" and test that we find the file.
103 expected_path
="${expected_path}/metadata"
105 test -e "$expected_path"
106 ok $?
"Reconstructed path from metadata is valid"
109 # The hostname is not part of the lttng hierarchy still we can test for
111 value
=$
(get_env_value
"$metadata_env" hostname
)
112 ok $?
"Extracting hostname from env metadata"
113 is
"$value" "$(hostname)" "Hostname is valid"
116 rm -f "$metadata_env"
119 function test_per_pid
()
126 local expected_path
="${TRACE_PATH}/lttng-traces"
127 local session_name
="per-pid"
128 local metadata
=$
(mktemp
--tmpdir tmp.test_
${FUNCNAME[0]}_metadata.XXXXXX
)
129 local metadata_env
=$
(mktemp
--tmpdir tmp.test_
${FUNCNAME[0]}_metadata_env.XXXXXX
)
131 diag
"Test UST metadata env field in per-pid mode"
132 create_lttng_session_ok
"$session_name"
133 enable_ust_lttng_channel_ok
"$session_name" channel
"--buffers-pid"
134 enable_ust_lttng_event_ok
"$session_name" $EVENT_NAME channel
135 start_lttng_tracing_ok
"$session_name"
137 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
141 stop_lttng_tracing_ok
"$session_name"
142 destroy_lttng_session_ok
"$session_name"
144 # bt1 accepts only a directory while bt2 accepts either the metadata
145 # file directly or a directory with an immediate metadata file.
146 # Settle for the common denominator.
147 metadata_path
=$
(find "${expected_path}/${session_name}"* -name "metadata")
148 metadata_path
=$
(dirname "$metadata_path")
150 $BABELTRACE_BIN --output-format=ctf-metadata
"${metadata_path}" 1> "$metadata"
152 # Extract "env" scope
153 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
155 # Construct the expected path from the env metadata and use it to
156 # validate that all information make sense. This information is present
157 # to allow trace viewer to recreate the same directory hierarchy.
160 value
=$
(get_env_value
"$metadata_env" trace_name
)
161 ok $?
"Extracting trace_name from env metadata"
162 expected_path
="${expected_path}/${value}"
164 # Session creation time
165 value
=$
(get_env_value
"$metadata_env" trace_creation_datetime
)
166 ok $?
"Extracting trace_creation_datetime from env metadata"
167 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
168 expected_path
="${expected_path}-${value}"
171 value
=$
(get_env_value
"$metadata_env" domain
)
172 ok $?
"Extracting domain from env metadata"
173 expected_path
="${expected_path}/${value}"
176 value
=$
(get_env_value
"$metadata_env" tracer_buffering_scheme
)
177 ok $?
"Extracting tracer_buffering_scheme from env metadata"
178 expected_path
="${expected_path}/${value}"
181 value
=$
(get_env_value
"$metadata_env" procname
)
182 ok $?
"Extracting procname from env metadata"
183 expected_path
="${expected_path}/${value}"
185 # vpid and tracer_buffering_id should be the same here.
186 # "vpid =" is used since other key have vpid in them.
187 value
=$
(get_env_value
"$metadata_env" "vpid =")
188 ok $?
"Extracting vpid from env metadata"
190 value2
=$
(get_env_value
"$metadata_env" tracer_buffering_id
)
191 ok $?
"Extracting tracer_buffering_id from env metadata"
192 expected_path
="${expected_path}-${value2}"
194 is
"$value" "$value2" "vpid and tracer_buffering_id are identical"
195 is
"$testapp_pid" "$value" "vpid and known testapp pid are identical"
196 is
"$testapp_pid" "$value2" "tracer_buffering_id and known testapp pid are identical"
199 value
=$
(get_env_value
"$metadata_env" vpid_datetime
)
200 ok $?
"Extracting vpid_datetime from env metadata"
201 value
=$
(iso8601_to_lttng_dir_datetime
"$value")
202 expected_path
="${expected_path}-${value}"
204 # Append "metadata" and test that we find the file.
205 expected_path
="${expected_path}/metadata"
207 test -e "$expected_path"
208 ok $?
"Reconstructed path from metadata is valid"
211 # The hostname is not part of the lttng hierarchy still we can test for
213 value
=$
(get_env_value
"$metadata_env" hostname
)
214 ok $?
"Extracting hostname from env metadata"
215 is
"$value" "$(hostname)" "Hostname is valid"
218 rm -f "$metadata_env"
221 plan_tests
$NUM_TESTS
223 print_test_banner
"$TEST_DESC"
225 bail_out_if_no_babeltrace
227 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
228 # with "<session_name>-<datetime>/...".
229 LTTNG_HOME
="$TRACE_PATH"
234 tests
=( test_per_uid test_per_pid
)
236 for fct_test
in "${tests[@]}";