Tests: use jq for extracting info from ctf2 traces
[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 metadata_env
36 local value
37 local value2
38
39 local expected_path="${TRACE_PATH}/lttng-traces"
40 local session_name="per-uid"
41 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 extract_env_to_file "$metadata_path" "$metadata_env"
60
61 # Construct the expected path from the env metadata and use it to
62 # validate that all information make sense. This information is present
63 # to allow trace viewer to recreate the same directory hierarchy.
64
65 # Trace name
66 value=$(get_env_value "$metadata_env" trace_name)
67 ok $? "Extracting trace_name from env metadata"
68 expected_path="${expected_path}/${value}"
69
70 # Session creation time
71 value=$(get_env_value "$metadata_env" trace_creation_datetime)
72 ok $? "Extracting trace_creation_datetime from env metadata"
73 value=$(iso8601_to_lttng_dir_datetime "$value")
74 expected_path="${expected_path}-${value}"
75
76 # Domain
77 value=$(get_env_value "$metadata_env" domain)
78 ok $? "Extracting domain from env metadata"
79 expected_path="${expected_path}/${value}"
80
81 # Buffering scheme
82 value=$(get_env_value "$metadata_env" tracer_buffering_scheme)
83 ok $? "Extracting tracer_buffering_scheme from env metadata"
84 expected_path="${expected_path}/${value}"
85
86 # tracer_buffering_id
87 value=$(get_env_value "$metadata_env" tracer_buffering_id)
88 ok $? "Extracting tracer_buffering_id from env metadata"
89 expected_path="${expected_path}/${value}"
90
91 # Check that the uid is the one we expect from the current user
92 is "$value" "$(id -u)" "tracer_buffering_id match current user uid"
93
94 # Architecture_bit_width
95 value=$(get_env_value "$metadata_env" architecture_bit_width)
96 ok $? "Extracting architecture_bit_width from env metadata"
97 expected_path="${expected_path}/${value}-bit"
98
99 # Append "metadata" and test that we find the file.
100 expected_path="${expected_path}/metadata"
101
102 test -e "$expected_path"
103 ok $? "Reconstructed path from metadata is valid"
104
105 # Hostname
106 # The hostname is not part of the lttng hierarchy still we can test for
107 # its validity here.
108 value=$(get_env_value "$metadata_env" hostname)
109 ok $? "Extracting hostname from env metadata"
110 is "$value" "$(hostname)" "Hostname is valid"
111
112 rm -f "$metadata_env"
113 }
114
115 function test_per_pid ()
116 {
117 local metadata_path
118 local testapp_pid
119 local value
120 local value2
121
122 local expected_path="${TRACE_PATH}/lttng-traces"
123 local session_name="per-pid"
124 local metadata_env
125
126 metadata_env=$(mktemp --tmpdir "tmp.test_${FUNCNAME[0]}_metadata_env.XXXXXX")
127
128 diag "Test UST metadata env field in per-pid mode"
129 create_lttng_session_ok "$session_name"
130 enable_ust_lttng_channel_ok "$session_name" channel "--buffers-pid"
131 enable_ust_lttng_event_ok "$session_name" $EVENT_NAME channel
132 start_lttng_tracing_ok "$session_name"
133
134 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
135 testapp_pid=$!
136 wait $testapp_pid
137
138 stop_lttng_tracing_ok "$session_name"
139 destroy_lttng_session_ok "$session_name"
140
141 # bt1 accepts only a directory while bt2 accepts either the metadata
142 # file directly or a directory with an immediate metadata file.
143 # Settle for the common denominator.
144 metadata_path=$(find "${expected_path}/${session_name}"* -name "metadata")
145 metadata_path=$(dirname "$metadata_path")
146
147 extract_env_to_file "$metadata_path" "$metadata_env"
148
149 # Construct the expected path from the env metadata and use it to
150 # validate that all information make sense. This information is present
151 # to allow trace viewer to recreate the same directory hierarchy.
152
153 # Trace name
154 value=$(get_env_value "$metadata_env" trace_name)
155 ok $? "Extracting trace_name from env metadata"
156 expected_path="${expected_path}/${value}"
157
158 # Session creation time
159 value=$(get_env_value "$metadata_env" trace_creation_datetime)
160 ok $? "Extracting trace_creation_datetime from env metadata"
161 value=$(iso8601_to_lttng_dir_datetime "$value")
162 expected_path="${expected_path}-${value}"
163
164 # Domain
165 value=$(get_env_value "$metadata_env" domain)
166 ok $? "Extracting domain from env metadata"
167 expected_path="${expected_path}/${value}"
168
169 # Buffering scheme
170 value=$(get_env_value "$metadata_env" tracer_buffering_scheme)
171 ok $? "Extracting tracer_buffering_scheme from env metadata"
172 expected_path="${expected_path}/${value}"
173
174 # Procname
175 value=$(get_env_value "$metadata_env" procname)
176 ok $? "Extracting procname from env metadata"
177 expected_path="${expected_path}/${value}"
178
179 # vpid and tracer_buffering_id should be the same here.
180 # "vpid =" is used since other key have vpid in them.
181 value=$(get_env_value "$metadata_env" "vpid =")
182 ok $? "Extracting vpid from env metadata"
183
184 value2=$(get_env_value "$metadata_env" tracer_buffering_id)
185 ok $? "Extracting tracer_buffering_id from env metadata"
186 expected_path="${expected_path}-${value2}"
187
188 is "$value" "$value2" "vpid and tracer_buffering_id are identical"
189 is "$testapp_pid" "$value" "vpid and known testapp pid are identical"
190 is "$testapp_pid" "$value2" "tracer_buffering_id and known testapp pid are identical"
191
192 # vpid_datetime
193 value=$(get_env_value "$metadata_env" vpid_datetime)
194 ok $? "Extracting vpid_datetime from env metadata"
195 value=$(iso8601_to_lttng_dir_datetime "$value")
196 expected_path="${expected_path}-${value}"
197
198 # Append "metadata" and test that we find the file.
199 expected_path="${expected_path}/metadata"
200
201 test -e "$expected_path"
202 ok $? "Reconstructed path from metadata is valid"
203
204 # Hostname
205 # The hostname is not part of the lttng hierarchy still we can test for
206 # its validity here.
207 value=$(get_env_value "$metadata_env" hostname)
208 ok $? "Extracting hostname from env metadata"
209 is "$value" "$(hostname)" "Hostname is valid"
210
211 rm -f "$metadata_env"
212 }
213
214 plan_tests $NUM_TESTS
215
216 print_test_banner "$TEST_DESC"
217
218 bail_out_if_no_babeltrace
219
220 # Use LTTNG_HOME since we want the complete "default" lttng directory hierarchy
221 # with "<session_name>-<datetime>/...".
222 LTTNG_HOME="$TRACE_PATH"
223
224 export LTTNG_HOME
225 start_lttng_sessiond
226
227 tests=( test_per_uid test_per_pid )
228
229 for fct_test in "${tests[@]}";
230 do
231 ${fct_test}
232 done
233
234 stop_lttng_sessiond
235 unset LTTNG_HOME
236
237 rm -rf "$TRACE_PATH"
This page took 0.036167 seconds and 5 git commands to generate.