3 # SPDX-License-Identifier: GPL-2.0-only
5 # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
8 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
9 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
11 UTILSSH
="$(dirname "$0")/../../utils/utils.sh"
14 # shellcheck source=../../utils/utils.sh
15 SH_TAP
=1 source "$UTILSSH"
21 data_dir
="${BT_TESTS_DATADIR}/cli/query"
22 plugin_dir
="${data_dir}"
24 stdout_expected_file
=$
(mktemp
-t test_cli_query_stdout_xpected.XXXXXX
)
25 stdout_file
=$
(mktemp
-t test_cli_query_stdout.XXXXXX
)
26 stderr_file
=$
(mktemp
-t test_cli_query_stderr.XXXXXX
)
29 local expected_str
="$1"
33 echo "$expected_str" > "$stdout_expected_file"
35 bt_diff_cli
"$stdout_expected_file" /dev
/null \
36 --plugin-path "$plugin_dir" \
37 query
"src.query.SourceWithQueryThatPrintsParams" \
43 local expected_str
="$1"
46 local test_name
="${args[*]}"
48 echo -n > "$stdout_expected_file"
50 bt_cli
"$stdout_file" "$stderr_file" \
51 --plugin-path "$plugin_dir" \
54 isnt
"$?" 0 "${test_name}: exit code is not 0"
56 bt_diff
/dev
/null
"$stdout_file"
57 ok
"$?" "${test_name}: nothing output on stout"
59 # Ensure that a CLI error stack is printed (and that babeltrace doesn't
61 grep --silent "^ERROR: " "${stderr_file}"
62 ok $?
"${test_name}: babeltrace produces an error stack"
64 grep --silent "${expected_str}" "${stderr_file}"
65 ok
"$?" "${test_name}: expect \`${expected_str}\` error message on stderr"
68 expect_success
'the-object:{}' \
70 expect_success
"the-object:{a=2}" \
73 # Check that -p parameters are processed in order.
74 expect_success
"the-object:{a=3, ben=kin, voyons=donc}" \
75 'the-object' -p 'a=2,ben=kin' -p 'voyons=donc,a=3'
77 # Failure inside the component class' query method.
78 expect_failure
"ValueError: catastrophic failure" \
79 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=2'
81 # Non-existent component class.
82 expect_failure
'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=1' \
83 'src.query.NonExistentSource' 'the-object' '-p' 'a=2'
85 # Wrong parameter syntax.
86 expect_failure
"Invalid format for --params option's argument:" \
87 'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=3,'
89 rm -f "$stdout_expected_file"