tests: Move to kernel style SPDX license identifiers
[deliverable/lttng-tools.git] / tests / regression / tools / metadata / test_ust
1 #!/bin/bash
2 #
3 # Copyright (C) 2019 Jonathan Rajotte-Julien <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 -d)
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
35 local metadata_env
36 local metadata_path
37 local value
38 local value2
39
40 local expected_path="${TRACE_PATH}/lttng-traces"
41 local session_name="per-uid"
42
43 metadata=$(mktemp)
44 metadata_env=$(mktemp)
45
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"
50
51 $TESTAPP_BIN -i $NR_ITER
52
53 stop_lttng_tracing_ok "$session_name"
54 destroy_lttng_session_ok "$session_name"
55
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")
61
62 $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" > "$metadata"
63
64 # Extract "env" scope
65 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
66
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.
70
71 # Trace name
72 value=$(get_env_value "$metadata_env" trace_name)
73 ok $? "Extracting trace_name from env metadata"
74 expected_path="${expected_path}/${value}"
75
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}"
81
82 # Domain
83 value=$(get_env_value "$metadata_env" domain)
84 ok $? "Extracting domain from env metadata"
85 expected_path="${expected_path}/${value}"
86
87 # Buffering scheme
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}"
91
92 # tracer_buffering_id
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}"
96
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"
99
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"
104
105 # Append "metadata" and test that we find the file.
106 expected_path="${expected_path}/metadata"
107
108 test -e "$expected_path"
109 ok $? "Reconstructed path from metadata is valid"
110
111 # Hostname
112 # The hostname is not part of the lttng hierarchy still we can test for
113 # its validity here.
114 value=$(get_env_value "$metadata_env" hostname)
115 ok $? "Extracting hostname from env metadata"
116 is "$value" "$(hostname)" "Hostname is valid"
117
118 rm -f "$metadata"
119 rm -f "$metadata_env"
120 }
121
122 function test_per_pid ()
123 {
124 local metadata
125 local metadata_env
126 local metadata_path
127 local testapp_pid
128 local value
129 local value2
130
131 local expected_path="${TRACE_PATH}/lttng-traces"
132 local session_name="per-pid"
133
134 metadata=$(mktemp)
135 metadata_env=$(mktemp)
136
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"
142
143 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
144 testapp_pid=$!
145 wait $testapp_pid
146
147 stop_lttng_tracing_ok "$session_name"
148 destroy_lttng_session_ok "$session_name"
149
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")
155
156 $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" 1> "$metadata"
157
158 # Extract "env" scope
159 awk '/env {/,/};/' < "$metadata" > "$metadata_env"
160
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.
164
165 # Trace name
166 value=$(get_env_value "$metadata_env" trace_name)
167 ok $? "Extracting trace_name from env metadata"
168 expected_path="${expected_path}/${value}"
169
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}"
175
176 # Domain
177 value=$(get_env_value "$metadata_env" domain)
178 ok $? "Extracting domain from env metadata"
179 expected_path="${expected_path}/${value}"
180
181 # Buffering scheme
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}"
185
186 # Procname
187 value=$(get_env_value "$metadata_env" procname)
188 ok $? "Extracting procname from env metadata"
189 expected_path="${expected_path}/${value}"
190
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"
195
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}"
199
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"
203
204 # vpid_datetime
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}"
209
210 # Append "metadata" and test that we find the file.
211 expected_path="${expected_path}/metadata"
212
213 test -e "$expected_path"
214 ok $? "Reconstructed path from metadata is valid"
215
216 # Hostname
217 # The hostname is not part of the lttng hierarchy still we can test for
218 # its validity here.
219 value=$(get_env_value "$metadata_env" hostname)
220 ok $? "Extracting hostname from env metadata"
221 is "$value" "$(hostname)" "Hostname is valid"
222
223 rm -f "$metadata"
224 rm -f "$metadata_env"
225 }
226
227 plan_tests $NUM_TESTS
228
229 print_test_banner "$TEST_DESC"
230
231 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
232 # with "<session_name>-<datetime>/...".
233 LTTNG_HOME="$TRACE_PATH"
234
235 export LTTNG_HOME
236 start_lttng_sessiond
237
238 tests=( test_per_uid test_per_pid )
239
240 for fct_test in "${tests[@]}";
241 do
242 ${fct_test}
243 done
244
245 stop_lttng_sessiond
246 unset LTTNG_HOME
247
248 rm -rf "$TRACE_PATH"
This page took 0.037511 seconds and 6 git commands to generate.