Skip to content

Commit 0325525

Browse files
committed
tests: add bt_test_cli
Add the `bt_test_cli` test util function, whose purpose is to reduce the boilerplate in tests. `bt_test_cli` runs `bt_cli`, checks some aspects of the result, and records some TAP test results (hence the `test` in the name). See its doc for more details. I changed a bunch of tests to use it, just enough to validate that the approach was flexible enough and can apply in a variety of situations. There are certainly more tests that could be changed to use it, and we can add more options later to cater to more use cases. Change-Id: I54d3b4ae96d33b0a5c7eae374b30d7ef5880fe09 Signed-off-by: Simon Marchi <[email protected]> Reviewed-on: https://review.lttng.org/c/babeltrace/+/14629 Reviewed-by: Philippe Proulx <[email protected]> Tested-by: jenkins <[email protected]> (cherry picked from commit 6ec27c7) Reviewed-on: https://review.lttng.org/c/babeltrace/+/14868
1 parent 1449164 commit 0325525

File tree

13 files changed

+182
-65
lines changed

13 files changed

+182
-65
lines changed

tests/cli/convert/test-auto-source-discovery-log-level.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717
# shellcheck source=../../utils/utils.sh
1818
SH_TAP=1 source "$UTILSSH"
1919

20-
NUM_TESTS=4
20+
NUM_TESTS=12
2121

2222
plan_tests $NUM_TESTS
2323

@@ -53,11 +53,11 @@ Stream end
5353
Stream end
5454
END
5555

56-
bt_diff_cli "$expected_file" "/dev/null" \
56+
bt_test_cli "apply log level to two components from one non-option argument" \
57+
--expect-stdout "$expected_file" -- \
5758
--plugin-path "${plugin_dir}" convert \
5859
"${dir_ab}" --log-level DEBUG "${print_log_level[@]}" \
5960
"${details_sink[@]}"
60-
ok "$?" "apply log level to two components from one non-option argument"
6161

6262
# Apply log level to two components from two distinct non-option arguments.
6363
cat > "$expected_file" <<END
@@ -80,11 +80,11 @@ Stream end
8080
Stream end
8181
END
8282

83-
bt_diff_cli "$expected_file" "/dev/null" \
83+
bt_test_cli "apply log level to two non-option arguments" \
84+
--expect-stdout "$expected_file" -- \
8485
--plugin-path "${plugin_dir}" convert \
8586
"${dir_a}" --log-level DEBUG "${print_log_level[@]}" "${dir_b}" --log-level TRACE "${print_log_level[@]}" \
8687
"${details_sink[@]}"
87-
ok "$?" "apply log level to two non-option arguments"
8888

8989
# Apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (1).
9090
cat > "$expected_file" <<END
@@ -107,11 +107,11 @@ Stream end
107107
Stream end
108108
END
109109

110-
bt_diff_cli "$expected_file" "/dev/null" \
110+
bt_test_cli "apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (1)" \
111+
--expect-stdout "$expected_file" -- \
111112
--plugin-path "${plugin_dir}" convert \
112113
"${dir_a}" --log-level DEBUG "${print_log_level[@]}" "${dir_ab}" --log-level TRACE "${print_log_level[@]}" \
113114
"${details_sink[@]}"
114-
ok "$?" "apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (1)"
115115

116116
# Apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (2).
117117
cat > "$expected_file" <<END
@@ -134,10 +134,10 @@ Stream end
134134
Stream end
135135
END
136136

137-
bt_diff_cli "$expected_file" "/dev/null" \
137+
bt_test_cli "apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (2)" \
138+
--expect-stdout "$expected_file" -- \
138139
--plugin-path "${plugin_dir}" convert \
139140
"${dir_ab}" --log-level DEBUG "${print_log_level[@]}" "${dir_a}" --log-level TRACE "${print_log_level[@]}" \
140141
"${details_sink[@]}"
141-
ok "$?" "apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (2)"
142142

143143
rm -f "$expected_file"

tests/cli/convert/test-auto-source-discovery-params.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717
# shellcheck source=../../utils/utils.sh
1818
SH_TAP=1 source "$UTILSSH"
1919

20-
NUM_TESTS=4
20+
NUM_TESTS=12
2121

2222
plan_tests $NUM_TESTS
2323

@@ -53,11 +53,11 @@ Stream end
5353
Stream end
5454
END
5555

56-
bt_diff_cli "$expected_file" "/dev/null" \
56+
bt_test_cli "apply params to two components from one non-option argument" \
57+
--expect-stdout "$expected_file" -- \
5758
--plugin-path "${plugin_dir}" convert \
5859
"${dir_ab}" --params 'test-allo="madame"' "${print_test_params[@]}" \
5960
"${details_sink[@]}"
60-
ok "$?" "apply params to two components from one non-option argument"
6161

6262
# Apply params to two components from two distinct non-option arguments.
6363
cat > "$expected_file" <<END
@@ -80,11 +80,11 @@ Stream end
8080
Stream end
8181
END
8282

83-
bt_diff_cli "$expected_file" "/dev/null" \
83+
bt_test_cli "apply params to two non-option arguments" \
84+
--expect-stdout "$expected_file" -- \
8485
--plugin-path "${plugin_dir}" convert \
8586
"${dir_a}" --params 'test-allo="madame"' "${print_test_params[@]}" "${dir_b}" --params 'test-bonjour="monsieur"' "${print_test_params[@]}" \
8687
"${details_sink[@]}"
87-
ok "$?" "apply params to two non-option arguments"
8888

8989
# Apply params to one component coming from one non-option argument and one component coming from two non-option arguments (1).
9090
cat > "$expected_file" <<END
@@ -107,11 +107,11 @@ Stream end
107107
Stream end
108108
END
109109

110-
bt_diff_cli "$expected_file" "/dev/null" \
110+
bt_test_cli "apply params to one component coming from one non-option argument and one component coming from two non-option arguments (1)" \
111+
--expect-stdout "$expected_file" -- \
111112
--plugin-path "${plugin_dir}" convert \
112113
"${dir_a}" --params 'test-allo="madame"' "${print_test_params[@]}" "${dir_ab}" --params 'test-bonjour="monsieur"' "${print_test_params[@]}" \
113114
"${details_sink[@]}"
114-
ok "$?" "apply params to one component coming from one non-option argument and one component coming from two non-option arguments (1)"
115115

116116
# Apply params to one component coming from one non-option argument and one component coming from two non-option arguments (2).
117117
cat > "$expected_file" <<END
@@ -134,10 +134,10 @@ Stream end
134134
Stream end
135135
END
136136

137-
bt_diff_cli "$expected_file" "/dev/null" \
137+
bt_test_cli "apply params to one component coming from one non-option argument and one component coming from two non-option arguments (2)" \
138+
--expect-stdout "$expected_file" -- \
138139
--plugin-path "${plugin_dir}" convert \
139140
"${dir_ab}" --params 'test-bonjour="madame",test-salut="les amis"' "${print_test_params[@]}" "${dir_a}" --params 'test-bonjour="monsieur"' "${print_test_params[@]}" \
140141
"${details_sink[@]}"
141-
ok "$?" "apply params to one component coming from one non-option argument and one component coming from two non-option arguments (2)"
142142

143143
rm -f "$expected_file"

tests/cli/params/test-params.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717
# shellcheck source=../../utils/utils.sh
1818
SH_TAP=1 source "$UTILSSH"
1919

20-
NUM_TESTS=9
20+
NUM_TESTS=27
2121

2222
plan_tests $NUM_TESTS
2323

@@ -34,9 +34,9 @@ function expect_success
3434

3535
echo "$expected_str" > "$expected_file"
3636

37-
bt_diff_cli "$expected_file" /dev/null --plugin-path "$plugin_dir" -c "src.text.dmesg" \
37+
bt_test_cli "$test_name" --expect-stdout "$expected_file" -- \
38+
--plugin-path "$plugin_dir" -c "src.text.dmesg" \
3839
-c "sink.params.SinkThatPrintsParams" --params "$params_str"
39-
ok "$?" "$test_name"
4040
}
4141

4242
expect_success 'null' 'a=null,b=nul,c=NULL' \

tests/cli/query/test-query.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fi
1414
# shellcheck source=../../utils/utils.sh
1515
SH_TAP=1 source "$UTILSSH"
1616

17-
NUM_TESTS=15
17+
NUM_TESTS=21
1818

1919
plan_tests $NUM_TESTS
2020

@@ -32,11 +32,10 @@ expect_success() {
3232

3333
echo "$expected_str" > "$stdout_expected_file"
3434

35-
bt_diff_cli "$stdout_expected_file" /dev/null \
35+
bt_test_cli "${args[*]}" --expect-stdout "$stdout_expected_file" -- \
3636
--plugin-path "$plugin_dir" \
3737
query "src.query.SourceWithQueryThatPrintsParams" \
3838
"${args[@]}"
39-
ok "$?" "${args[*]}"
4039
}
4140

4241
expect_failure() {

tests/cli/test-exit-status.sh

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,9 @@ source_name="src.test-exit-status.StatusSrc"
2121

2222
test_interrupted_graph() {
2323
local cli_args=("--plugin-path=$data_dir" "-c" "$source_name" "-p" "case=\"INTERRUPTED\"")
24-
local actual_stdout
25-
local actual_stderr
26-
27-
actual_stdout=$(mktemp -t test-cli-exit-status-stdout-actual.XXXXXX)
28-
actual_stderr=$(mktemp -t test-cli-exit-status-stderr-actual.XXXXXX)
29-
30-
bt_cli --stdout-file "$actual_stdout" --stderr-file "$actual_stderr" -- "${cli_args[@]}"
3124

32-
is $? 2 "Interrupted graph exits with status 2"
33-
34-
bt_diff /dev/null "$actual_stdout"
35-
ok $? "Interrupted graph gives no stdout"
36-
37-
bt_diff /dev/null "$actual_stderr"
38-
ok $? "Interrupted graph gives no stderr"
39-
40-
rm -f "${actual_stdout}"
41-
rm -f "${actual_stderr}"
25+
bt_test_cli "interrupted graph" \
26+
--expect-stdout /dev/null --expect-exit-status 2 -- "${cli_args[@]}"
4227
}
4328

4429
test_error_graph() {

tests/plugins/flt.lttng-utils.debug-info/test-succeed.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ test_debug_info() {
3838
)
3939

4040
for mip_version in 0 1; do
41-
bt_diff_cli "$expect_dir/trace-$name-mip$mip_version.expect" "/dev/null" \
41+
bt_test_cli "MIP '$mip_version': Trace '$name' gives the expected output" \
42+
--expect-stdout "$expect_dir/trace-$name-mip$mip_version.expect" -- \
4243
"$succeed_trace_dir/$name" "${local_args[@]}" \
4344
"--allowed-mip-versions=$mip_version"
44-
ok $? "MIP '$mip_version': Trace '$name' gives the expected output"
4545
done
4646
}
4747

@@ -123,7 +123,7 @@ test_compare_complete_src_trace() {
123123
done
124124
}
125125

126-
plan_tests 18
126+
plan_tests 22
127127

128128
test_debug_info debug-info
129129

tests/plugins/flt.utils.muxer/succeed/test-succeed.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ source "$UTILSSH"
2020

2121
data_dir="$BT_TESTS_DATADIR/plugins/flt.utils.muxer"
2222

23-
plan_tests 12
23+
plan_tests 36
2424

2525
function run_test
2626
{
@@ -34,8 +34,8 @@ function run_test
3434
)
3535

3636
stdout_expected="$data_dir/succeed/$test_name.expect"
37-
bt_diff_cli "$stdout_expected" /dev/null "${local_args[@]}"
38-
ok $? "$test_name"
37+
bt_test_cli "$test_name" --expect-stdout "$stdout_expected" -- \
38+
"${local_args[@]}"
3939
}
4040

4141

tests/plugins/flt.utils.trimmer/test-trimming.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ source "$UTILSSH"
2121

2222
data_dir="$BT_TESTS_DATADIR/plugins/flt.utils.trimmer"
2323
temp_stdout_expected=$(mktemp)
24-
temp_stderr_expected="/dev/null"
2524

26-
plan_tests 56
25+
plan_tests 168
2726

2827
function run_test
2928
{
@@ -66,8 +65,8 @@ function run_test
6665
test_name="$test_name, without --end"
6766
fi
6867

69-
bt_diff_cli "$temp_stdout_expected" "$temp_stderr_expected" "${local_args[@]}"
70-
ok $? "$test_name"
68+
bt_test_cli "$test_name" --expect-stdout "$temp_stdout_expected" -- \
69+
"${local_args[@]}"
7170
}
7271

7372
function test_with_stream_msg_cs_with_packets {
@@ -620,6 +619,4 @@ test_without_stream_msg_cs_with_packets
620619
test_with_stream_msg_cs_without_packets
621620
test_without_stream_msg_cs_without_packets
622621

623-
# Do not `rm` $temp_stderr_expected because it's set to `/dev/null` right now
624-
# and that would print an error.
625622
rm -f "$temp_stdout_expected"

tests/plugins/sink.ctf.fs/test-assume-single-trace.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if [ "$BT_TESTS_ENABLE_PYTHON_PLUGINS" != "1" ]; then
3333
exit
3434
fi
3535

36-
plan_tests 7
36+
plan_tests 9
3737

3838
bt_cli --stdout-file "$temp_stdout" --stderr-file "$temp_stderr" -- \
3939
"--plugin-path=${data_dir}" \
@@ -67,8 +67,8 @@ ok "$?" "the-stream file exists"
6767

6868
# Read back the output trace to make sure it's properly formed.
6969
echo "the-event: " > "$temp_expected_stdout"
70-
bt_diff_cli "$temp_expected_stdout" /dev/null "$trace_dir"
71-
ok "$?" "read back output trace"
70+
bt_test_cli "read back output trace" --expect-stdout "$temp_expected_stdout" -- \
71+
"$trace_dir"
7272

7373
rm -f "$temp_stdout"
7474
rm -f "$temp_stderr"

tests/plugins/sink.ctf.fs/test-stream-names.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if [ "$BT_TESTS_ENABLE_PYTHON_PLUGINS" != "1" ]; then
3535
exit
3636
fi
3737

38-
plan_tests 9
38+
plan_tests 11
3939

4040
bt_cli --stdout-file "$temp_stdout" --stderr-file "$temp_stderr" -- \
4141
"--plugin-path=${data_dir}" \
@@ -80,8 +80,8 @@ the-event:
8080
the-event:
8181
the-event:
8282
END
83-
bt_diff_cli "$temp_expected_stdout" /dev/null "$trace_dir"
84-
ok "$?" "read back output trace"
83+
bt_test_cli "read back output trace" --expect-stdout "$temp_expected_stdout" -- \
84+
"$trace_dir"
8585

8686
rm -f "$temp_stdout"
8787
rm -f "$temp_stderr"

0 commit comments

Comments
 (0)