517b076c957c72b6f53d7139c18d0c993dde3253
[babeltrace.git] / tests / cli / convert / test_convert_args
1 #!/bin/bash
2 #
3 # Copyright (C) 2017 Philippe Proulx <pproulx@efficios.com>
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 SH_TAP=1
19
20 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
21 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
22 else
23 UTILSSH="$(dirname "$0")/../../utils/utils.sh"
24 fi
25
26 # shellcheck source=../../utils/utils.sh
27 source "$UTILSSH"
28
29 tmp_stdout=$(mktemp -t test_convert_args_stdout.XXXXXX)
30 tmp_stderr=$(mktemp -t test_convert_args_stderr.XXXXXX)
31
32 test_bt_convert_run_args() {
33 local what="$1"
34 local convert_args="$2"
35 local expected_run_args="$3"
36
37 local run_args
38
39 # Split argument string into array.
40 IFS=' ' read -ra convert_args_array <<< "$convert_args"
41
42 # Execute convert command.
43 bt_cli "${tmp_stdout}" "${tmp_stderr}" convert --run-args "${convert_args_array[@]}"
44 ok $? "${what}: success exit status"
45
46 run_args=$(cat "${tmp_stdout}")
47
48 # Verify output run args.
49 [ "$run_args" = "$expected_run_args" ]
50 ok $? "${what}: run arguments"
51 }
52
53 test_bt_convert_fails() {
54 local what="$1"
55 local convert_args="$2"
56 local expected_error_str="$3"
57
58 # Split argument string into array.
59 IFS=' ' read -ra convert_args_array <<< "$convert_args"
60
61 # Execute convert command.
62 bt_cli "${tmp_stdout}" "${tmp_stderr}" convert --run-args "${convert_args_array[@]}"
63 isnt "$?" 0 "failure exit status"
64
65 # Nothing should be printed on stdout.
66 bt_diff /dev/null "${tmp_stdout}"
67 ok $? "$what: nothing is printed on stdout"
68
69 # Check for expected error string in stderr.
70 grep --quiet --fixed-strings -e "$expected_error_str" "$tmp_stderr"
71 local status=$?
72 ok "$status" "$what: expected error message"
73 if [ "$status" -ne 0 ]; then
74 diag "Expected error string '${expected_error_str}' not found in stderr:"
75 diag "$(cat "${tmp_stderr}")"
76 fi
77 }
78
79 path_to_trace="${BT_CTF_TRACES_PATH}/succeed/succeed1"
80 path_to_trace2="${BT_CTF_TRACES_PATH}/succeed/succeed2"
81 output_path="/output/path"
82
83 if [ "$BT_OS_TYPE" = "mingw" ]; then
84 # Use Windows native paths for comparison because Unix
85 # paths are converted by the shell before they are passed
86 # to the native babeltrace2 binary.
87 path_to_trace=$(cygpath -m "$path_to_trace")
88 path_to_trace2=$(cygpath -m "$path_to_trace2")
89 output_path=$(cygpath -m "$output_path")
90 fi
91
92 plan_tests 161
93
94 test_bt_convert_run_args 'path non-option arg' "$path_to_trace" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
95 test_bt_convert_run_args 'path non-option args' "$path_to_trace $path_to_trace2" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\", \"${path_to_trace2}\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
96 test_bt_convert_run_args 'path non-option arg + named user source with --params' "$path_to_trace --component ZZ:source.another.source --params salut=yes" "--component ZZ:source.another.source --params salut=yes --component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect ZZ:muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
97 test_bt_convert_run_args 'unnamed user source' '--component source.salut.com' "--component source.salut.com:source.salut.com --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect 'source\.salut\.com:muxer' --connect muxer:pretty"
98 test_bt_convert_run_args "path non-option arg + user source named \`auto-disc-source-ctf-fs\`" "--component auto-disc-source-ctf-fs:source.salut.com $path_to_trace" "--component auto-disc-source-ctf-fs:source.salut.com --component auto-disc-source-ctf-fs-0:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect auto-disc-source-ctf-fs-0:muxer --connect muxer:pretty"
99 test_bt_convert_run_args "path non-option arg + user sink named \`pretty\`" "--component pretty:sink.my.sink $path_to_trace" "--component pretty:sink.my.sink --component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
100 test_bt_convert_run_args "path non-option arg + user filter named \`muxer\`" "--component muxer:filter.salut.com $path_to_trace" "--component muxer:filter.salut.com --component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer-0:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer-0 --connect muxer-0:muxer --connect muxer:pretty"
101 test_bt_convert_run_args "path non-option arg + --begin + user filter named \`trimmer\`" "$path_to_trace --component trimmer:filter.salut.com --begin=abc" "--component trimmer:filter.salut.com --component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --component trimmer-0:filter.utils.trimmer --params 'begin=\"abc\"' --connect auto-disc-source-ctf-fs:muxer --connect muxer:trimmer-0 --connect trimmer-0:trimmer --connect trimmer:pretty"
102 test_bt_convert_run_args 'path non-option arg + --begin' "$path_to_trace --begin=123" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --component trimmer:filter.utils.trimmer --params 'begin=\"123\"' --connect auto-disc-source-ctf-fs:muxer --connect muxer:trimmer --connect trimmer:pretty"
103 test_bt_convert_run_args 'path non-option arg + --begin --end' "$path_to_trace --end=456 --begin 123" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --component trimmer:filter.utils.trimmer --params 'end=\"456\"' --params 'begin=\"123\"' --connect auto-disc-source-ctf-fs:muxer --connect muxer:trimmer --connect trimmer:pretty"
104 test_bt_convert_run_args 'path non-option arg + --timerange' "$path_to_trace --timerange=[abc,xyz]" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --component trimmer:filter.utils.trimmer --params 'begin=\"abc\"' --params 'end=\"xyz\"' --connect auto-disc-source-ctf-fs:muxer --connect muxer:trimmer --connect trimmer:pretty"
105 test_bt_convert_run_args 'path non-option arg + --clock-cycles' "$path_to_trace --clock-cycles" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params clock-cycles=yes --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
106 test_bt_convert_run_args 'path non-option arg + --clock-date' "$path_to_trace --clock-date" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params clock-date=yes --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
107 test_bt_convert_run_args 'path non-option arg + --clock-force-correlate' "$path_to_trace --clock-force-correlate" "--component auto-disc-source-ctf-fs:source.ctf.fs --params force-clock-class-origin-unix-epoch=yes --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
108 test_bt_convert_run_args 'path non-option arg + --clock-gmt' "$path_to_trace --clock-gmt" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params clock-gmt=yes --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
109 test_bt_convert_run_args 'path non-option arg + --clock-offset' "$path_to_trace --clock-offset=15487" "--component auto-disc-source-ctf-fs:source.ctf.fs --params clock-class-offset-s=15487 --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
110 test_bt_convert_run_args 'path non-option arg + --clock-offset-ns' "$path_to_trace --clock-offset-ns=326159487" "--component auto-disc-source-ctf-fs:source.ctf.fs --params clock-class-offset-ns=326159487 --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
111 test_bt_convert_run_args 'path non-option arg + --clock-seconds' "$path_to_trace --clock-seconds" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params clock-seconds=yes --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
112 test_bt_convert_run_args 'path non-option arg + --color' "$path_to_trace --color=never" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params 'color=\"never\"' --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
113 test_bt_convert_run_args 'path non-option arg + --debug-info' "$path_to_trace --debug-info" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --component debug-info:filter.lttng-utils.debug-info --connect auto-disc-source-ctf-fs:muxer --connect muxer:debug-info --connect debug-info:pretty"
114 test_bt_convert_run_args 'path non-option arg + --debug-info-dir' "$path_to_trace --debug-info-dir=${output_path}" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --component debug-info:filter.lttng-utils.debug-info --params 'debug-info-dir=\"${output_path}\"' --connect auto-disc-source-ctf-fs:muxer --connect muxer:debug-info --connect debug-info:pretty"
115 test_bt_convert_run_args 'path non-option arg + --debug-info-target-prefix' "$path_to_trace --debug-info-target-prefix=${output_path}" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --component debug-info:filter.lttng-utils.debug-info --params 'target-prefix=\"${output_path}\"' --connect auto-disc-source-ctf-fs:muxer --connect muxer:debug-info --connect debug-info:pretty"
116 test_bt_convert_run_args 'path non-option arg + --debug-info-full-path' "$path_to_trace --debug-info-full-path" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --component debug-info:filter.lttng-utils.debug-info --params full-path=yes --connect auto-disc-source-ctf-fs:muxer --connect muxer:debug-info --connect debug-info:pretty"
117 test_bt_convert_run_args 'path non-option arg + --fields=trace:domain,loglevel' "--fields=trace:domain,loglevel $path_to_trace" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params field-trace:domain=yes,field-loglevel=yes,field-default=hide --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
118 test_bt_convert_run_args 'path non-option arg + --fields=all' "--fields=all $path_to_trace" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params field-default=show --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
119 test_bt_convert_run_args 'path non-option arg + --names=context,header' "--names=context,header $path_to_trace" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params name-context=yes,name-header=yes,name-default=hide --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
120 test_bt_convert_run_args 'path non-option arg + --names=all' "--names=all $path_to_trace" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params name-default=show --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
121 test_bt_convert_run_args 'path non-option arg + --no-delta' "$path_to_trace --no-delta" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params no-delta=yes --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
122 test_bt_convert_run_args 'path non-option arg + --output' "$path_to_trace --output $output_path" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --params 'path=\"$output_path\"' --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
123 test_bt_convert_run_args 'path non-option arg + -i ctf' "$path_to_trace -i ctf" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:pretty"
124 test_bt_convert_run_args 'URL non-option arg + -i lttng-live' 'net://some-host/host/target/session -i lttng-live' "--component lttng-live:source.ctf.lttng-live --params 'inputs=[\"net://some-host/host/target/session\"]' --params 'session-not-found-action=\"end\"' --component pretty:sink.text.pretty --component muxer:filter.utils.muxer --connect lttng-live:muxer --connect muxer:pretty"
125 test_bt_convert_run_args 'path non-option arg + -o dummy' "$path_to_trace -o dummy" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component dummy:sink.utils.dummy --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:dummy"
126 test_bt_convert_run_args 'path non-option arg + -o ctf + --output' "$path_to_trace -o ctf --output $output_path" "--component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component sink-ctf-fs:sink.ctf.fs --params 'path=\"$output_path\"' --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect muxer:sink-ctf-fs"
127 test_bt_convert_run_args 'path non-option arg + user sink with log level' "$path_to_trace -c sink.mein.sink -lW" "--component sink.mein.sink:sink.mein.sink --log-level W --component auto-disc-source-ctf-fs:source.ctf.fs --params 'inputs=[\"$path_to_trace\"]' --component muxer:filter.utils.muxer --connect auto-disc-source-ctf-fs:muxer --connect 'muxer:sink\.mein\.sink'"
128
129 test_bt_convert_fails \
130 'bad --component format (plugin only)' \
131 '--component salut' \
132 "Invalid format for --component option's argument:"
133
134 test_bt_convert_fails \
135 'bad --component format (name and plugin only)' \
136 '--component name:salut' \
137 "Missing component class type (\`source\`, \`filter\`, or \`sink\`)."
138
139 test_bt_convert_fails \
140 'bad --component format (name only)' \
141 '--component name:' \
142 "Missing component class type (\`source\`, \`filter\`, or \`sink\`)."
143
144 test_bt_convert_fails \
145 'bad --component format (extra dot found)' \
146 '--component name:source.plugin.comp.cls' \
147 "Invalid format for --component option's argument:"
148
149 test_bt_convert_fails \
150 'duplicate component name' \
151 '--component hello:sink.a.b --component hello:source.c.d' \
152 'Duplicate component instance name:'
153
154 test_bt_convert_fails \
155 'unknown option' \
156 '--component hello:sink.a.b --salut' \
157 "Unknown option \`--salut\`"
158
159 # The error string spans two lines in this error message, it's not convenient to
160 # check for multiple lines, so we just check the first line.
161 test_bt_convert_fails \
162 '--params without current component' \
163 '--params lol=23' \
164 "No current component (--component option) or non-option argument of which to"
165
166 test_bt_convert_fails \
167 'duplicate --begin' \
168 '--begin abc --clock-seconds --begin cde' \
169 'At --begin option: --begin or --timerange option already specified'
170
171 test_bt_convert_fails \
172 'duplicate --end' \
173 '--begin abc --end xyz --clock-seconds --end cde' \
174 'At --end option: --end or --timerange option already specified'
175
176 test_bt_convert_fails \
177 '--begin and --timerange' \
178 '--begin abc --clock-seconds --timerange abc,def' \
179 'At --timerange option: --begin, --end, or --timerange option already specified'
180
181 test_bt_convert_fails \
182 '--end and --timerange' \
183 '--end abc --clock-seconds --timerange abc,def' \
184 'At --timerange option: --begin, --end, or --timerange option already specified'
185
186 test_bt_convert_fails \
187 'bad --timerange format (1)' \
188 '--timerange abc' \
189 "Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:"
190
191 test_bt_convert_fails \
192 'bad --timerange format (2)' \
193 '--timerange abc,' \
194 "Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:"
195
196 test_bt_convert_fails \
197 'bad --timerange format (3)' \
198 '--timerange ,cde' \
199 "Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:"
200
201 test_bt_convert_fails \
202 'bad --fields format' \
203 '--fields salut' \
204 "Unknown field: \`salut\`."
205
206 test_bt_convert_fails \
207 'bad --names format' \
208 '--names salut' \
209 "Unknown name: \`salut\`."
210
211 test_bt_convert_fails \
212 'unknown -i' \
213 '-i lol' \
214 'Unknown legacy input format:'
215
216 test_bt_convert_fails \
217 'duplicate -i' \
218 '-i lttng-live --clock-seconds --input-format=ctf' \
219 'Duplicate --input-format option.'
220
221 test_bt_convert_fails \
222 'unknown -o' \
223 '-o lol' \
224 'Unknown legacy output format:'
225
226 test_bt_convert_fails \
227 'duplicate -o' \
228 '-o dummy --clock-seconds --output-format=text' \
229 'Duplicate --output-format option.'
230
231 test_bt_convert_fails \
232 '--run-args and --run-args-0' \
233 "$path_to_trace --run-args --run-args-0" \
234 'Cannot specify --run-args and --run-args-0.'
235
236 test_bt_convert_fails \
237 '-o ctf-metadata without path' \
238 '-o ctf-metadata' \
239 '--output-format=ctf-metadata specified without a path.'
240
241 test_bt_convert_fails \
242 '-i lttng-live and implicit source.ctf.fs' \
243 '-i lttng-live net://some-host/host/target/session --clock-offset=23' \
244 '--clock-offset specified, but no source.ctf.fs component instantiated.'
245
246 test_bt_convert_fails \
247 'implicit source.ctf.fs without path' \
248 '--clock-offset=23' \
249 '--clock-offset specified, but no source.ctf.fs component instantiated.'
250
251 test_bt_convert_fails \
252 'implicit source.ctf.lttng-live without URL' \
253 '-i lttng-live' \
254 "Missing URL for implicit \`source.ctf.lttng-live\` component."
255
256 test_bt_convert_fails \
257 'no source' \
258 '-o text' \
259 'No source component.'
260
261 test_bt_convert_fails \
262 '-o ctf without --output' \
263 'my-trace -o ctf' \
264 '--output-format=ctf specified without --output (trace output path).'
265
266 # The error string spans two lines in this error message, it's not convenient to
267 # check for multiple lines, so we just check the first line.
268 test_bt_convert_fails \
269 '-o ctf + --output with implicit sink.text.pretty' \
270 "my-trace -o ctf --output $output_path --no-delta" \
271 'Ambiguous --output option: --output-format=ctf specified but another option'
272
273 test_bt_convert_fails \
274 '--stream-intersection' \
275 "$path_to_trace --stream-intersection" \
276 'Cannot specify --stream-intersection with --run-args or --run-args-0.'
277
278 test_bt_convert_fails \
279 'two sinks with -o dummy + --clock-seconds' \
280 "$path_to_trace -o dummy --clock-seconds" \
281 'More than one sink component specified.'
282
283 test_bt_convert_fails \
284 'path non-option arg + user sink + -o text' \
285 "$path_to_trace --component=sink.abc.def -o text" \
286 'More than one sink component specified.'
287
288 rm -f "${tmp_stdout}"
289 rm -f "${tmp_stderr}"
This page took 0.039521 seconds and 3 git commands to generate.