tests: sync tests/utils/tap with Babeltrace repository
[lttng-tools.git] / tests / regression / tools / metadata / test_ust
1 #!/bin/bash
2 #
3 # Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="Metadata env - User space tracing"
8
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"
15
16 TRACE_PATH=$(mktemp --tmpdir -d tmp.test_metadata_env_ust_trace_path.XXXXXX)
17
18 NUM_TESTS=37
19
20 NR_ITER=10
21 NR_USEC_WAIT=0
22
23 source "$TESTDIR/utils/utils.sh"
24
25 # Fetch utils functions common to ust and kernel tests.
26 source "$CURDIR/utils.sh"
27
28 if [ ! -x "$TESTAPP_BIN" ]; then
29 BAIL_OUT "No UST events binary detected."
30 fi
31
32 function test_per_uid ()
33 {
34 local metadata_path
35 local value
36 local value2
37
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)
42
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"
47
48 $TESTAPP_BIN -i $NR_ITER
49
50 stop_lttng_tracing_ok "$session_name"
51 destroy_lttng_session_ok "$session_name"
52
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")
58
59 $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" > "$metadata"
60
61 # Extract "env" scope
62 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
63
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.
67
68 # Trace name
69 value=$(get_env_value "$metadata_env" trace_name)
70 ok $? "Extracting trace_name from env metadata"
71 expected_path="${expected_path}/${value}"
72
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}"
78
79 # Domain
80 value=$(get_env_value "$metadata_env" domain)
81 ok $? "Extracting domain from env metadata"
82 expected_path="${expected_path}/${value}"
83
84 # Buffering scheme
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}"
88
89 # tracer_buffering_id
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}"
93
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"
96
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"
101
102 # Append "metadata" and test that we find the file.
103 expected_path="${expected_path}/metadata"
104
105 test -e "$expected_path"
106 ok $? "Reconstructed path from metadata is valid"
107
108 # Hostname
109 # The hostname is not part of the lttng hierarchy still we can test for
110 # its validity here.
111 value=$(get_env_value "$metadata_env" hostname)
112 ok $? "Extracting hostname from env metadata"
113 is "$value" "$(hostname)" "Hostname is valid"
114
115 rm -f "$metadata"
116 rm -f "$metadata_env"
117 }
118
119 function test_per_pid ()
120 {
121 local metadata_path
122 local testapp_pid
123 local value
124 local value2
125
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)
130
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"
136
137 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
138 testapp_pid=$!
139 wait $testapp_pid
140
141 stop_lttng_tracing_ok "$session_name"
142 destroy_lttng_session_ok "$session_name"
143
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")
149
150 $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" 1> "$metadata"
151
152 # Extract "env" scope
153 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
154
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.
158
159 # Trace name
160 value=$(get_env_value "$metadata_env" trace_name)
161 ok $? "Extracting trace_name from env metadata"
162 expected_path="${expected_path}/${value}"
163
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}"
169
170 # Domain
171 value=$(get_env_value "$metadata_env" domain)
172 ok $? "Extracting domain from env metadata"
173 expected_path="${expected_path}/${value}"
174
175 # Buffering scheme
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}"
179
180 # Procname
181 value=$(get_env_value "$metadata_env" procname)
182 ok $? "Extracting procname from env metadata"
183 expected_path="${expected_path}/${value}"
184
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"
189
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}"
193
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"
197
198 # vpid_datetime
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}"
203
204 # Append "metadata" and test that we find the file.
205 expected_path="${expected_path}/metadata"
206
207 test -e "$expected_path"
208 ok $? "Reconstructed path from metadata is valid"
209
210 # Hostname
211 # The hostname is not part of the lttng hierarchy still we can test for
212 # its validity here.
213 value=$(get_env_value "$metadata_env" hostname)
214 ok $? "Extracting hostname from env metadata"
215 is "$value" "$(hostname)" "Hostname is valid"
216
217 rm -f "$metadata"
218 rm -f "$metadata_env"
219 }
220
221 plan_tests $NUM_TESTS
222
223 print_test_banner "$TEST_DESC"
224
225 bail_out_if_no_babeltrace
226
227 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
228 # with "<session_name>-<datetime>/...".
229 LTTNG_HOME="$TRACE_PATH"
230
231 export LTTNG_HOME
232 start_lttng_sessiond
233
234 tests=( test_per_uid test_per_pid )
235
236 for fct_test in "${tests[@]}";
237 do
238 ${fct_test}
239 done
240
241 stop_lttng_sessiond
242 unset LTTNG_HOME
243
244 rm -rf "$TRACE_PATH"
This page took 0.039124 seconds and 4 git commands to generate.