cli: make --plugin-path and --omit-{system,home}-plugin-path global opts
[babeltrace.git] / tests / plugins / flt.utils.trimmer / test_trimming
CommitLineData
b7cbc799
SM
1#!/bin/bash
2#
3# Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License
7# as published by the Free Software Foundation; only version 2
8# of the License.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19# This file tests what happens when we trim at different points in the message
20# flow.
21
22SH_TAP=1
23
24if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
25 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
26else
27 UTILSSH="$(dirname "$0")/../../utils/utils.sh"
28fi
29
8c083b3e 30# shellcheck source=../../utils/utils.sh
b7cbc799
SM
31source "$UTILSSH"
32
8c083b3e 33data_dir="$BT_TESTS_DATADIR/plugins/flt.utils.trimmer"
ca5f1044
FD
34temp_stdout_expected=$(mktemp)
35temp_stderr_expected="/dev/null"
b7cbc799
SM
36
37plan_tests 32
38
39function run_test
40{
41 local begin_time="$1"
42 local end_time="$2"
8c083b3e 43 local local_args=(
d36258d0 44 "--plugin-path" "$data_dir"
8c083b3e
MJ
45 "-c" "src.test-trimmer.TheSourceOfAllEvil"
46 "-p" "with-stream-msgs-cs=$with_stream_msgs_cs"
47 "-c" "sink.text.details"
48 "--params=compact=true,with-metadata=false"
8c083b3e 49 )
b7cbc799
SM
50
51 if [ -n "$begin_time" ]; then
8c083b3e
MJ
52 local_args+=("--begin=$begin_time")
53 test_name="with --begin=$begin_time"
b7cbc799 54 else
b7cbc799
SM
55 test_name="without --begin"
56 fi
57
58 if [ -n "$end_time" ]; then
8c083b3e
MJ
59 local_args+=("--end=$end_time")
60 test_name="$test_name, with --end=$end_time"
b7cbc799 61 else
b7cbc799
SM
62 test_name="$test_name, without --end"
63 fi
64
65 # with_stream_msgs_cs is set to "true" or "false" by the tests.
66
ca5f1044 67 bt_diff_cli "$temp_stdout_expected" "$temp_stderr_expected" "${local_args[@]}"
b7cbc799
SM
68 ok $? "$test_name"
69}
70
71function test_with_stream_msg_cs {
72 with_stream_msgs_cs="true"
73
74 # Baseline (without trimming)
ca5f1044 75 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
76 [100 10,100,000,000,000] {0 0 0} Stream beginning
77 [200 10,200,000,000,000] {0 0 0} Packet beginning
78 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
79 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
80 [900 10,900,000,000,000] {0 0 0} Packet end
81 [1000 11,000,000,000,000] {0 0 0} Stream end
82 END
83 run_test "" ""
84
85 # Trim begin at a time before what the clock class can represent
ca5f1044 86 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
87 [100 10,100,000,000,000] {0 0 0} Stream beginning
88 [200 10,200,000,000,000] {0 0 0} Packet beginning
89 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
90 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
91 [900 10,900,000,000,000] {0 0 0} Packet end
92 [1000 11,000,000,000,000] {0 0 0} Stream end
93 END
94 run_test 50 ""
95
96 # Trim begin before stream beginning
ca5f1044 97 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
98 [100 10,100,000,000,000] {0 0 0} Stream beginning
99 [200 10,200,000,000,000] {0 0 0} Packet beginning
100 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
101 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
102 [900 10,900,000,000,000] {0 0 0} Packet end
103 [1000 11,000,000,000,000] {0 0 0} Stream end
104 END
105 run_test 10050 ""
106
107 # Trim begin before packet beginning
ca5f1044 108 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
109 [150 10,150,000,000,000] {0 0 0} Stream beginning
110 [200 10,200,000,000,000] {0 0 0} Packet beginning
111 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
112 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
113 [900 10,900,000,000,000] {0 0 0} Packet end
114 [1000 11,000,000,000,000] {0 0 0} Stream end
115 END
116 run_test 10150 ""
117
118 # Trim begin before first event
ca5f1044 119 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
120 [250 10,250,000,000,000] {0 0 0} Stream beginning
121 [250 10,250,000,000,000] {0 0 0} Packet beginning
122 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
123 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
124 [900 10,900,000,000,000] {0 0 0} Packet end
125 [1000 11,000,000,000,000] {0 0 0} Stream end
126 END
127 run_test 10250 ""
128
129 # Trim begin before second event
ca5f1044 130 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
131 [350 10,350,000,000,000] {0 0 0} Stream beginning
132 [350 10,350,000,000,000] {0 0 0} Packet beginning
133 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
134 [900 10,900,000,000,000] {0 0 0} Packet end
135 [1000 11,000,000,000,000] {0 0 0} Stream end
136 END
137
138 run_test 10350 ""
139
140 # Trim begin before packet end
ca5f1044 141 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
142 [850 10,850,000,000,000] {0 0 0} Stream beginning
143 [850 10,850,000,000,000] {0 0 0} Packet beginning
144 [900 10,900,000,000,000] {0 0 0} Packet end
145 [1000 11,000,000,000,000] {0 0 0} Stream end
146 END
147
148 run_test 10850 ""
149
150 # Trim begin after everything
ca5f1044 151 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
152 END
153
154 run_test 11050 ""
155
156 # Trim end after stream end
ca5f1044 157 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
158 [100 10,100,000,000,000] {0 0 0} Stream beginning
159 [200 10,200,000,000,000] {0 0 0} Packet beginning
160 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
161 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
162 [900 10,900,000,000,000] {0 0 0} Packet end
163 [1000 11,000,000,000,000] {0 0 0} Stream end
164 END
165
166 run_test "" 11050
167
168 # Trim end after packet end
ca5f1044 169 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
170 [100 10,100,000,000,000] {0 0 0} Stream beginning
171 [200 10,200,000,000,000] {0 0 0} Packet beginning
172 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
173 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
174 [900 10,900,000,000,000] {0 0 0} Packet end
175 [950 10,950,000,000,000] {0 0 0} Stream end
176 END
177
178 run_test "" 10950
179
180 # Trim end after second event
ca5f1044 181 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
182 [100 10,100,000,000,000] {0 0 0} Stream beginning
183 [200 10,200,000,000,000] {0 0 0} Packet beginning
184 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
185 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
186 [450 10,450,000,000,000] {0 0 0} Packet end
187 [450 10,450,000,000,000] {0 0 0} Stream end
188 END
189
190 run_test "" 10450
191
192 # Trim end after first event
ca5f1044 193 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
194 [100 10,100,000,000,000] {0 0 0} Stream beginning
195 [200 10,200,000,000,000] {0 0 0} Packet beginning
196 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
197 [350 10,350,000,000,000] {0 0 0} Packet end
198 [350 10,350,000,000,000] {0 0 0} Stream end
199 END
200
201 run_test "" 10350
202
203 # Trim end after packet beginning
ca5f1044 204 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
205 [100 10,100,000,000,000] {0 0 0} Stream beginning
206 [200 10,200,000,000,000] {0 0 0} Packet beginning
207 [250 10,250,000,000,000] {0 0 0} Packet end
208 [250 10,250,000,000,000] {0 0 0} Stream end
209 END
210
211 run_test "" 10250
212
213 # Trim end after stream beginning
ca5f1044 214 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
215 [100 10,100,000,000,000] {0 0 0} Stream beginning
216 [150 10,150,000,000,000] {0 0 0} Stream end
217 END
218
219 run_test "" 10150
220
221 # Trim end before everything
ca5f1044 222 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
223 END
224
225 run_test "" 10050
226
227 # Trim end at a time before what the clock class can represent
ca5f1044 228 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
229 END
230
231 run_test "" 50
232}
233
234function test_without_stream_msg_cs {
235 with_stream_msgs_cs="false"
236
237 # Baseline (without trimming)
ca5f1044 238 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
239 [Unknown] {0 0 0} Stream beginning
240 [200 10,200,000,000,000] {0 0 0} Packet beginning
241 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
242 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
243 [900 10,900,000,000,000] {0 0 0} Packet end
244 [Unknown] {0 0 0} Stream end
245 END
246 run_test "" ""
247
248 # Trim begin at a time before what the clock class can represent
ca5f1044 249 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
250 [Unknown] {0 0 0} Stream beginning
251 [200 10,200,000,000,000] {0 0 0} Packet beginning
252 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
253 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
254 [900 10,900,000,000,000] {0 0 0} Packet end
255 [Unknown] {0 0 0} Stream end
256 END
257 run_test 50 ""
258
259 # Trim begin before stream beginning
ca5f1044 260 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
261 [Unknown] {0 0 0} Stream beginning
262 [200 10,200,000,000,000] {0 0 0} Packet beginning
263 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
264 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
265 [900 10,900,000,000,000] {0 0 0} Packet end
266 [Unknown] {0 0 0} Stream end
267 END
268 run_test 10050 ""
269
270 # Trim begin before packet beginning
ca5f1044 271 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
272 [Unknown] {0 0 0} Stream beginning
273 [200 10,200,000,000,000] {0 0 0} Packet beginning
274 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
275 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
276 [900 10,900,000,000,000] {0 0 0} Packet end
277 [Unknown] {0 0 0} Stream end
278 END
279 run_test 10150 ""
280
281 # Trim begin before first event
ca5f1044 282 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
283 [250 10,250,000,000,000] {0 0 0} Stream beginning
284 [250 10,250,000,000,000] {0 0 0} Packet beginning
285 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
286 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
287 [900 10,900,000,000,000] {0 0 0} Packet end
288 [Unknown] {0 0 0} Stream end
289 END
290 run_test 10250 ""
291
292 # Trim begin before second event
ca5f1044 293 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
294 [350 10,350,000,000,000] {0 0 0} Stream beginning
295 [350 10,350,000,000,000] {0 0 0} Packet beginning
296 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
297 [900 10,900,000,000,000] {0 0 0} Packet end
298 [Unknown] {0 0 0} Stream end
299 END
300
301 run_test 10350 ""
302
303 # Trim begin before packet end
ca5f1044 304 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
305 [850 10,850,000,000,000] {0 0 0} Stream beginning
306 [850 10,850,000,000,000] {0 0 0} Packet beginning
307 [900 10,900,000,000,000] {0 0 0} Packet end
308 [Unknown] {0 0 0} Stream end
309 END
310
311 run_test 10850 ""
312
313 # Trim begin after everything
ca5f1044 314 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
315 END
316
317 run_test 11050 ""
318
319 # Trim end after stream end
ca5f1044 320 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
321 [Unknown] {0 0 0} Stream beginning
322 [200 10,200,000,000,000] {0 0 0} Packet beginning
323 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
324 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
325 [900 10,900,000,000,000] {0 0 0} Packet end
326 [Unknown] {0 0 0} Stream end
327 END
328
329 run_test "" 11050
330
331 # Trim end after packet end
ca5f1044 332 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
333 [Unknown] {0 0 0} Stream beginning
334 [200 10,200,000,000,000] {0 0 0} Packet beginning
335 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
336 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
337 [900 10,900,000,000,000] {0 0 0} Packet end
338 [Unknown] {0 0 0} Stream end
339 END
340
341 run_test "" 10950
342
343 # Trim end after second event
ca5f1044 344 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
345 [Unknown] {0 0 0} Stream beginning
346 [200 10,200,000,000,000] {0 0 0} Packet beginning
347 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
348 [400 10,400,000,000,000] {0 0 0} Event `event 2` (1)
349 [450 10,450,000,000,000] {0 0 0} Packet end
350 [450 10,450,000,000,000] {0 0 0} Stream end
351 END
352
353 run_test "" 10450
354
355 # Trim end after first event
ca5f1044 356 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
357 [Unknown] {0 0 0} Stream beginning
358 [200 10,200,000,000,000] {0 0 0} Packet beginning
359 [300 10,300,000,000,000] {0 0 0} Event `event 1` (0)
360 [350 10,350,000,000,000] {0 0 0} Packet end
361 [350 10,350,000,000,000] {0 0 0} Stream end
362 END
363
364 run_test "" 10350
365
366 # Trim end after packet beginning
ca5f1044 367 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
368 [Unknown] {0 0 0} Stream beginning
369 [200 10,200,000,000,000] {0 0 0} Packet beginning
370 [250 10,250,000,000,000] {0 0 0} Packet end
371 [250 10,250,000,000,000] {0 0 0} Stream end
372 END
373
374 run_test "" 10250
375
376 # Trim end after stream beginning
ca5f1044 377 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
378 [Unknown] {0 0 0} Stream beginning
379 [Unknown] {0 0 0} Stream end
380 END
381
382 run_test "" 10150
383
384 # Trim end before everything
ca5f1044 385 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
386 [Unknown] {0 0 0} Stream beginning
387 [Unknown] {0 0 0} Stream end
388 END
389
390 run_test "" 10050
391
392 # Trim end at a time before what the clock class can represent
ca5f1044 393 cat <<- 'END' > "$temp_stdout_expected"
b7cbc799
SM
394 [Unknown] {0 0 0} Stream beginning
395 [Unknown] {0 0 0} Stream end
396 END
397
398 run_test "" 50
399}
400
401test_with_stream_msg_cs
402test_without_stream_msg_cs
403
ca5f1044
FD
404# Do not `rm` $temp_stderr_expected because it's set to `/dev/null` right now
405# and that would print an error.
406rm -f "$temp_stdout_expected"
This page took 0.043273 seconds and 4 git commands to generate.