Commit | Line | Data |
---|---|---|
01654d69 JR |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> | |
4 | # | |
5 | # This library is free software; you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License as published by the Free | |
7 | # Software Foundation; version 2.1 of the License. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public License | |
15 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | TEST_DESC="Metadata env - User space tracing" | |
18 | ||
19 | CURDIR=$(dirname "$0")/ | |
20 | TESTDIR=$CURDIR/../../.. | |
21 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
22 | TESTAPP_NAME="gen-ust-events" | |
23 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
24 | EVENT_NAME="tp:tptest" | |
25 | ||
26 | TRACE_PATH=$(mktemp -d) | |
27 | ||
28 | NUM_TESTS=37 | |
29 | ||
30 | NR_ITER=10 | |
31 | NR_USEC_WAIT=0 | |
32 | ||
33 | source "$TESTDIR/utils/utils.sh" | |
34 | ||
35 | # Fetch utils functions common to ust and kernel tests. | |
36 | source "$CURDIR/utils.sh" | |
37 | ||
38 | if [ ! -x "$TESTAPP_BIN" ]; then | |
39 | BAIL_OUT "No UST events binary detected." | |
40 | fi | |
41 | ||
42 | function test_per_uid () | |
43 | { | |
44 | local metadata | |
45 | local metadata_env | |
46 | local metadata_path | |
47 | local value | |
48 | local value2 | |
49 | ||
50 | local expected_path="${TRACE_PATH}/lttng-traces" | |
51 | local session_name="per-uid" | |
52 | ||
53 | metadata=$(mktemp) | |
54 | metadata_env=$(mktemp) | |
55 | ||
56 | diag "Test UST metadata env field in per-uid mode" | |
57 | create_lttng_session_ok "$session_name" | |
58 | enable_ust_lttng_event_ok "$session_name" $EVENT_NAME | |
59 | start_lttng_tracing_ok "$session_name" | |
60 | ||
6c4a91d6 | 61 | $TESTAPP_BIN -i $NR_ITER |
01654d69 JR |
62 | |
63 | stop_lttng_tracing_ok "$session_name" | |
64 | destroy_lttng_session_ok "$session_name" | |
65 | ||
66 | # bt1 accepts only a directory while bt2 accepts either the metadata | |
67 | # file directly or a directory with an immediate metadata file. | |
68 | # Settle for the common denominator. | |
69 | metadata_path=$(find "${expected_path}/${session_name}"* | grep metadata) | |
70 | metadata_path=$(dirname "$metadata_path") | |
71 | ||
72 | $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" > "$metadata" | |
73 | ||
74 | # Extract "env" scope | |
75 | awk '/env {/,/};/' < "$metadata" > "$metadata_env" | |
76 | ||
77 | # Construct the expected path from the env metadata and use it to | |
78 | # validate that all information make sense. This information is present | |
79 | # to allow trace viewer to recreate the same directory hierarchy. | |
80 | ||
81 | # Trace name | |
82 | value=$(get_env_value "$metadata_env" trace_name) | |
83 | ok $? "Extracting trace_name from env metadata" | |
84 | expected_path="${expected_path}/${value}" | |
85 | ||
86 | # Session creation time | |
87 | value=$(get_env_value "$metadata_env" trace_creation_datetime) | |
88 | ok $? "Extracting trace_creation_datetime from env metadata" | |
89 | value=$(iso8601_to_lttng_dir_datetime "$value") | |
90 | expected_path="${expected_path}-${value}" | |
91 | ||
92 | # Domain | |
93 | value=$(get_env_value "$metadata_env" domain) | |
94 | ok $? "Extracting domain from env metadata" | |
95 | expected_path="${expected_path}/${value}" | |
96 | ||
97 | # Buffering scheme | |
98 | value=$(get_env_value "$metadata_env" tracer_buffering_scheme) | |
99 | ok $? "Extracting tracer_buffering_scheme from env metadata" | |
100 | expected_path="${expected_path}/${value}" | |
101 | ||
102 | # tracer_buffering_id | |
103 | value=$(get_env_value "$metadata_env" tracer_buffering_id) | |
104 | ok $? "Extracting tracer_buffering_id from env metadata" | |
105 | expected_path="${expected_path}/${value}" | |
106 | ||
107 | # Check that the uid is the one we expect from the current user | |
108 | is "$value" "$(id -u)" "tracer_buffering_id match current user uid" | |
109 | ||
110 | # Architecture_bit_width | |
111 | value=$(get_env_value "$metadata_env" architecture_bit_width) | |
112 | ok $? "Extracting architecture_bit_width from env metadata" | |
113 | expected_path="${expected_path}/${value}-bit" | |
114 | ||
115 | # Append "metadata" and test that we find the file. | |
116 | expected_path="${expected_path}/metadata" | |
117 | ||
118 | test -e "$expected_path" | |
119 | ok $? "Reconstructed path from metadata is valid" | |
120 | ||
121 | # Hostname | |
122 | # The hostname is not part of the lttng hierarchy still we can test for | |
123 | # its validity here. | |
124 | value=$(get_env_value "$metadata_env" hostname) | |
125 | ok $? "Extracting hostname from env metadata" | |
126 | is "$value" "$(hostname)" "Hostname is valid" | |
127 | ||
128 | rm -f "$metadata" | |
129 | rm -f "$metadata_env" | |
130 | } | |
131 | ||
132 | function test_per_pid () | |
133 | { | |
134 | local metadata | |
135 | local metadata_env | |
136 | local metadata_path | |
137 | local testapp_pid | |
138 | local value | |
139 | local value2 | |
140 | ||
141 | local expected_path="${TRACE_PATH}/lttng-traces" | |
142 | local session_name="per-pid" | |
143 | ||
144 | metadata=$(mktemp) | |
145 | metadata_env=$(mktemp) | |
146 | ||
147 | diag "Test UST metadata env field in per-pid mode" | |
148 | create_lttng_session_ok "$session_name" | |
149 | enable_ust_lttng_channel_ok "$session_name" channel "--buffers-pid" | |
150 | enable_ust_lttng_event_ok "$session_name" $EVENT_NAME channel | |
151 | start_lttng_tracing_ok "$session_name" | |
152 | ||
6c4a91d6 | 153 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT & |
01654d69 JR |
154 | testapp_pid=$! |
155 | wait $testapp_pid | |
156 | ||
157 | stop_lttng_tracing_ok "$session_name" | |
158 | destroy_lttng_session_ok "$session_name" | |
159 | ||
160 | # bt1 accepts only a directory while bt2 accepts either the metadata | |
161 | # file directly or a directory with an immediate metadata file. | |
162 | # Settle for the common denominator. | |
163 | metadata_path=$(find "${expected_path}/${session_name}"* | grep metadata) | |
164 | metadata_path=$(dirname "$metadata_path") | |
165 | ||
166 | $BABELTRACE_BIN --output-format=ctf-metadata "${metadata_path}" 1> "$metadata" | |
167 | ||
168 | # Extract "env" scope | |
169 | awk '/env {/,/};/' < "$metadata" > "$metadata_env" | |
170 | ||
171 | # Construct the expected path from the env metadata and use it to | |
172 | # validate that all information make sense. This information is present | |
173 | # to allow trace viewer to recreate the same directory hierarchy. | |
174 | ||
175 | # Trace name | |
176 | value=$(get_env_value "$metadata_env" trace_name) | |
177 | ok $? "Extracting trace_name from env metadata" | |
178 | expected_path="${expected_path}/${value}" | |
179 | ||
180 | # Session creation time | |
181 | value=$(get_env_value "$metadata_env" trace_creation_datetime) | |
182 | ok $? "Extracting trace_creation_datetime from env metadata" | |
183 | value=$(iso8601_to_lttng_dir_datetime "$value") | |
184 | expected_path="${expected_path}-${value}" | |
185 | ||
186 | # Domain | |
187 | value=$(get_env_value "$metadata_env" domain) | |
188 | ok $? "Extracting domain from env metadata" | |
189 | expected_path="${expected_path}/${value}" | |
190 | ||
191 | # Buffering scheme | |
192 | value=$(get_env_value "$metadata_env" tracer_buffering_scheme) | |
193 | ok $? "Extracting tracer_buffering_scheme from env metadata" | |
194 | expected_path="${expected_path}/${value}" | |
195 | ||
196 | # Procname | |
197 | value=$(get_env_value "$metadata_env" procname) | |
198 | ok $? "Extracting procname from env metadata" | |
199 | expected_path="${expected_path}/${value}" | |
200 | ||
201 | # vpid and tracer_buffering_id should be the same here. | |
202 | # "vpid =" is used since other key have vpid in them. | |
203 | value=$(get_env_value "$metadata_env" "vpid =") | |
204 | ok $? "Extracting vpid from env metadata" | |
205 | ||
206 | value2=$(get_env_value "$metadata_env" tracer_buffering_id) | |
207 | ok $? "Extracting tracer_buffering_id from env metadata" | |
208 | expected_path="${expected_path}-${value2}" | |
209 | ||
210 | is "$value" "$value2" "vpid and tracer_buffering_id are identical" | |
211 | is "$testapp_pid" "$value" "vpid and known testapp pid are identical" | |
212 | is "$testapp_pid" "$value2" "tracer_buffering_id and known testapp pid are identical" | |
213 | ||
214 | # vpid_datetime | |
215 | value=$(get_env_value "$metadata_env" vpid_datetime) | |
216 | ok $? "Extracting vpid_datetime from env metadata" | |
217 | value=$(iso8601_to_lttng_dir_datetime "$value") | |
218 | expected_path="${expected_path}-${value}" | |
219 | ||
220 | # Append "metadata" and test that we find the file. | |
221 | expected_path="${expected_path}/metadata" | |
222 | ||
223 | test -e "$expected_path" | |
224 | ok $? "Reconstructed path from metadata is valid" | |
225 | ||
226 | # Hostname | |
227 | # The hostname is not part of the lttng hierarchy still we can test for | |
228 | # its validity here. | |
229 | value=$(get_env_value "$metadata_env" hostname) | |
230 | ok $? "Extracting hostname from env metadata" | |
231 | is "$value" "$(hostname)" "Hostname is valid" | |
232 | ||
233 | rm -f "$metadata" | |
234 | rm -f "$metadata_env" | |
235 | } | |
236 | ||
237 | plan_tests $NUM_TESTS | |
238 | ||
239 | print_test_banner "$TEST_DESC" | |
240 | ||
241 | # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy | |
242 | # with "<session_name>-<datetime>/...". | |
243 | LTTNG_HOME="$TRACE_PATH" | |
244 | ||
245 | export LTTNG_HOME | |
246 | start_lttng_sessiond | |
247 | ||
248 | tests=( test_per_uid test_per_pid ) | |
249 | ||
250 | for fct_test in "${tests[@]}"; | |
251 | do | |
252 | ${fct_test} | |
253 | done | |
254 | ||
255 | stop_lttng_sessiond | |
256 | unset LTTNG_HOME | |
257 | ||
258 | rm -rf "$TRACE_PATH" |