Cleanup: tests: name all temporary files to better identify leakage
[lttng-tools.git] / tests / regression / tools / metadata / test_ust
CommitLineData
01654d69
JR
1#!/bin/bash
2#
4942c256 3# Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
01654d69 4#
9d16b343
MJ
5# SPDX-License-Identifier: LGPL-2.1-only
6
01654d69
JR
7TEST_DESC="Metadata env - User space tracing"
8
9CURDIR=$(dirname "$0")/
10TESTDIR=$CURDIR/../../..
11TESTAPP_PATH="$TESTDIR/utils/testapp"
12TESTAPP_NAME="gen-ust-events"
13TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
14EVENT_NAME="tp:tptest"
15
33e55711 16TRACE_PATH=$(mktemp --tmpdir -d tmp.test_metadata_env_ust_trace_path.XXXXXX)
01654d69
JR
17
18NUM_TESTS=37
19
20NR_ITER=10
21NR_USEC_WAIT=0
22
23source "$TESTDIR/utils/utils.sh"
24
25# Fetch utils functions common to ust and kernel tests.
26source "$CURDIR/utils.sh"
27
28if [ ! -x "$TESTAPP_BIN" ]; then
29 BAIL_OUT "No UST events binary detected."
30fi
31
32function test_per_uid ()
33{
01654d69
JR
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"
33e55711
FD
40 local metadata=$(mktemp --tmpdir tmp.test_${FUNCNAME[0]}_metadata.XXXXXX)
41 local metadata_env=$(mktemp --tmpdir tmp.test_${FUNCNAME[0]}_metadata_env.XXXXXX)
01654d69
JR
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
6c4a91d6 48 $TESTAPP_BIN -i $NR_ITER
01654d69
JR
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.
fc2dd19e 56 metadata_path=$(find "${expected_path}/${session_name}"* -name "metadata")
01654d69
JR
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
119function test_per_pid ()
120{
01654d69
JR
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"
33e55711
FD
128 local metadata=$(mktemp --tmpdir tmp.test_${FUNCNAME[0]}_metadata.XXXXXX)
129 local metadata_env=$(mktemp --tmpdir tmp.test_${FUNCNAME[0]}_metadata_env.XXXXXX)
01654d69
JR
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
6c4a91d6 137 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
01654d69
JR
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.
fc2dd19e 147 metadata_path=$(find "${expected_path}/${session_name}"* -name "metadata")
01654d69
JR
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
221plan_tests $NUM_TESTS
222
223print_test_banner "$TEST_DESC"
224
225# Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
226# with "<session_name>-<datetime>/...".
227LTTNG_HOME="$TRACE_PATH"
228
229export LTTNG_HOME
230start_lttng_sessiond
231
232tests=( test_per_uid test_per_pid )
233
234for fct_test in "${tests[@]}";
235do
236 ${fct_test}
237done
238
239stop_lttng_sessiond
240unset LTTNG_HOME
241
242rm -rf "$TRACE_PATH"
This page took 0.035456 seconds and 4 git commands to generate.