3 # SPDX-License-Identifier: GPL-2.0-only
5 # Copyright (C) 2017 Philippe Proulx <pproulx@efficios.com>
10 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
11 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
13 UTILSSH
="$(dirname "$0")/../../utils/utils.sh"
16 # shellcheck source=../../utils/utils.sh
19 tmp_stdout
=$
(mktemp
-t test_convert_args_stdout.XXXXXX
)
20 tmp_stderr
=$
(mktemp
-t test_convert_args_stderr.XXXXXX
)
22 test_bt_convert_run_args
() {
24 local convert_args
="$2"
25 local expected_run_args
="$3"
29 # Split argument string into array.
30 IFS
=' ' read -ra convert_args_array
<<< "$convert_args"
32 # Execute convert command.
33 bt_cli
"${tmp_stdout}" "${tmp_stderr}" convert --run-args "${convert_args_array[@]}"
34 ok $?
"${what}: success exit status"
36 run_args
=$
(cat "${tmp_stdout}")
38 # Verify output run args.
39 [ "$run_args" = "$expected_run_args" ]
40 ok $?
"${what}: run arguments"
43 test_bt_convert_fails
() {
45 local convert_args
="$2"
46 local expected_error_str
="$3"
48 # Split argument string into array.
49 IFS
=' ' read -ra convert_args_array
<<< "$convert_args"
51 # Execute convert command.
52 bt_cli
"${tmp_stdout}" "${tmp_stderr}" convert --run-args "${convert_args_array[@]}"
53 isnt
"$?" 0 "failure exit status"
55 # Nothing should be printed on stdout.
56 bt_diff
/dev
/null
"${tmp_stdout}"
57 ok $?
"$what: nothing is printed on stdout"
59 # Check for expected error string in stderr.
60 grep --quiet --fixed-strings -e "$expected_error_str" "$tmp_stderr"
62 ok
"$status" "$what: expected error message"
63 if [ "$status" -ne 0 ]; then
64 diag
"Expected error string '${expected_error_str}' not found in stderr:"
65 diag
"$(cat "${tmp_stderr}")"
69 path_to_trace
="${BT_CTF_TRACES_PATH}/succeed/succeed1"
70 path_to_trace2
="${BT_CTF_TRACES_PATH}/succeed/succeed2"
71 output_path
="/output/path"
73 if [ "$BT_OS_TYPE" = "mingw" ]; then
74 # Use Windows native paths for comparison because Unix
75 # paths are converted by the shell before they are passed
76 # to the native babeltrace2 binary.
77 path_to_trace
=$
(cygpath
-m "$path_to_trace")
78 path_to_trace2
=$
(cygpath
-m "$path_to_trace2")
79 output_path
=$
(cygpath
-m "$output_path")
84 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"
85 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"
86 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"
87 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"
88 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"
89 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"
90 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"
91 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"
92 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"
93 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"
94 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"
95 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"
96 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"
97 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"
98 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"
99 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"
100 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"
101 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"
102 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"
103 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"
104 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"
105 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"
106 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"
107 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"
108 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"
109 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"
110 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"
111 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"
112 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"
113 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"
114 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"
115 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"
116 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"
117 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'"
119 test_bt_convert_fails \
120 'bad --component format (plugin only)' \
121 '--component salut' \
122 "Invalid format for --component option's argument:"
124 test_bt_convert_fails \
125 'bad --component format (name and plugin only)' \
126 '--component name:salut' \
127 "Missing component class type (\`source\`, \`filter\`, or \`sink\`)."
129 test_bt_convert_fails \
130 'bad --component format (name only)' \
131 '--component name:' \
132 "Missing component class type (\`source\`, \`filter\`, or \`sink\`)."
134 test_bt_convert_fails \
135 'bad --component format (extra dot found)' \
136 '--component name:source.plugin.comp.cls' \
137 "Invalid format for --component option's argument:"
139 test_bt_convert_fails \
140 'duplicate component name' \
141 '--component hello:sink.a.b --component hello:source.c.d' \
142 'Duplicate component instance name:'
144 test_bt_convert_fails \
146 '--component hello:sink.a.b --salut' \
147 "Unknown option \`--salut\`"
149 # The error string spans two lines in this error message, it's not convenient to
150 # check for multiple lines, so we just check the first line.
151 test_bt_convert_fails \
152 '--params without current component' \
154 "No current component (--component option) or non-option argument of which to"
156 test_bt_convert_fails \
157 'duplicate --begin' \
158 '--begin abc --clock-seconds --begin cde' \
159 'At --begin option: --begin or --timerange option already specified'
161 test_bt_convert_fails \
163 '--begin abc --end xyz --clock-seconds --end cde' \
164 'At --end option: --end or --timerange option already specified'
166 test_bt_convert_fails \
167 '--begin and --timerange' \
168 '--begin abc --clock-seconds --timerange abc,def' \
169 'At --timerange option: --begin, --end, or --timerange option already specified'
171 test_bt_convert_fails \
172 '--end and --timerange' \
173 '--end abc --clock-seconds --timerange abc,def' \
174 'At --timerange option: --begin, --end, or --timerange option already specified'
176 test_bt_convert_fails \
177 'bad --timerange format (1)' \
179 "Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:"
181 test_bt_convert_fails \
182 'bad --timerange format (2)' \
184 "Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:"
186 test_bt_convert_fails \
187 'bad --timerange format (3)' \
189 "Invalid --timerange option's argument: expecting BEGIN,END or [BEGIN,END]:"
191 test_bt_convert_fails \
192 'bad --fields format' \
194 "Unknown field: \`salut\`."
196 test_bt_convert_fails \
197 'bad --names format' \
199 "Unknown name: \`salut\`."
201 test_bt_convert_fails \
204 'Unknown legacy input format:'
206 test_bt_convert_fails \
208 '-i lttng-live --clock-seconds --input-format=ctf' \
209 'Duplicate --input-format option.'
211 test_bt_convert_fails \
214 'Unknown legacy output format:'
216 test_bt_convert_fails \
218 '-o dummy --clock-seconds --output-format=text' \
219 'Duplicate --output-format option.'
221 test_bt_convert_fails \
222 '--run-args and --run-args-0' \
223 "$path_to_trace --run-args --run-args-0" \
224 'Cannot specify --run-args and --run-args-0.'
226 test_bt_convert_fails \
227 '-o ctf-metadata without path' \
229 '--output-format=ctf-metadata specified without a path.'
231 test_bt_convert_fails \
232 '-i lttng-live and implicit source.ctf.fs' \
233 '-i lttng-live net://some-host/host/target/session --clock-offset=23' \
234 '--clock-offset specified, but no source.ctf.fs component instantiated.'
236 test_bt_convert_fails \
237 'implicit source.ctf.fs without path' \
238 '--clock-offset=23' \
239 '--clock-offset specified, but no source.ctf.fs component instantiated.'
241 test_bt_convert_fails \
242 'implicit source.ctf.lttng-live without URL' \
244 "Missing URL for implicit \`source.ctf.lttng-live\` component."
246 test_bt_convert_fails \
249 'No source component.'
251 test_bt_convert_fails \
252 '-o ctf without --output' \
254 '--output-format=ctf specified without --output (trace output path).'
256 # The error string spans two lines in this error message, it's not convenient to
257 # check for multiple lines, so we just check the first line.
258 test_bt_convert_fails \
259 '-o ctf + --output with implicit sink.text.pretty' \
260 "my-trace -o ctf --output $output_path --no-delta" \
261 'Ambiguous --output option: --output-format=ctf specified but another option'
263 test_bt_convert_fails \
264 '--stream-intersection' \
265 "$path_to_trace --stream-intersection" \
266 'Cannot specify --stream-intersection with --run-args or --run-args-0.'
268 test_bt_convert_fails \
269 'two sinks with -o dummy + --clock-seconds' \
270 "$path_to_trace -o dummy --clock-seconds" \
271 'More than one sink component specified.'
273 test_bt_convert_fails \
274 'path non-option arg + user sink + -o text' \
275 "$path_to_trace --component=sink.abc.def -o text" \
276 'More than one sink component specified.'
278 rm -f "${tmp_stdout}"
279 rm -f "${tmp_stderr}"