Commit | Line | Data |
---|---|---|
d19b245b SM |
1 | #!/bin/bash |
2 | # | |
3 | # SPDX-License-Identifier: GPL-2.0-only | |
4 | # | |
5 | # Copyright (C) 2020 EfficiOS Inc. | |
6 | # | |
7 | ||
8 | # This file tests corner cases related to stream names: | |
9 | # | |
10 | # - two streams with the same name | |
11 | # - a stream named "metadata" | |
12 | ||
13 | SH_TAP=1 | |
14 | ||
75e396f6 | 15 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; then |
d19b245b SM |
16 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" |
17 | else | |
18 | UTILSSH="$(dirname "$0")/../../utils/utils.sh" | |
19 | fi | |
20 | ||
21 | # shellcheck source=../../utils/utils.sh | |
22 | source "$UTILSSH" | |
23 | ||
24 | # Directory containing the Python test source. | |
25 | data_dir="$BT_TESTS_DATADIR/plugins/sink.ctf.fs/stream-names" | |
26 | ||
27 | temp_stdout=$(mktemp) | |
28 | temp_expected_stdout=$(mktemp) | |
29 | temp_stderr=$(mktemp) | |
30 | temp_output_dir=$(mktemp -d) | |
31 | trace_dir="$temp_output_dir/trace" | |
32 | ||
faf5c654 SM |
33 | if [ "$BT_TESTS_ENABLE_PYTHON_PLUGINS" != "1" ]; then |
34 | plan_skip_all "This test requires the Python plugin provider" | |
35 | exit | |
36 | fi | |
37 | ||
d19b245b SM |
38 | plan_tests 9 |
39 | ||
40 | bt_cli "$temp_stdout" "$temp_stderr" \ | |
41 | "--plugin-path=${data_dir}" \ | |
42 | -c src.foo.TheSource \ | |
43 | -c sink.ctf.fs -p "path=\"${temp_output_dir}\"" | |
44 | ok "$?" "run babeltrace" | |
45 | ||
46 | # Check stdout. | |
a0baab4a | 47 | if [ "$BT_TESTS_OS_TYPE" = "mingw" ]; then |
c169867c SM |
48 | # shellcheck disable=SC2028 |
49 | echo "Created CTF trace \`$(cygpath -m "${temp_output_dir}")\\trace\`." > "$temp_expected_stdout" | |
d19b245b SM |
50 | else |
51 | echo "Created CTF trace \`${trace_dir}\`." > "$temp_expected_stdout" | |
52 | fi | |
53 | bt_diff "$temp_expected_stdout" "$temp_stdout" | |
54 | ok "$?" "expected message on stdout" | |
55 | ||
56 | # Check stderr. | |
57 | bt_diff "/dev/null" "$temp_stderr" | |
58 | ok "$?" "stderr is empty" | |
59 | ||
60 | # Verify only the expected files exist. | |
61 | files=("$trace_dir"/*) | |
62 | num_files=${#files[@]} | |
63 | is "$num_files" "4" "expected number of files in output directory" | |
64 | ||
65 | test -f "$trace_dir/metadata" | |
66 | ok "$?" "metadata file exists" | |
67 | ||
68 | test -f "$trace_dir/metadata-0" | |
69 | ok "$?" "metadata-0 file exists" | |
70 | ||
71 | test -f "$trace_dir/the-stream" | |
72 | ok "$?" "the-stream file exists" | |
73 | ||
74 | test -f "$trace_dir/the-stream-0" | |
75 | ok "$?" "the-stream-0 file exists" | |
76 | ||
77 | # Read back the output trace to make sure it's properly formed. | |
78 | cat <<- 'END' > "$temp_expected_stdout" | |
79 | the-event: | |
80 | the-event: | |
81 | the-event: | |
82 | END | |
83 | bt_diff_cli "$temp_expected_stdout" /dev/null "$trace_dir" | |
84 | ok "$?" "read back output trace" | |
85 | ||
86 | rm -f "$temp_stdout" | |
87 | rm -f "$temp_stderr" | |
88 | rm -f "$temp_expected_stdout" | |
89 | rm -f "$trace_dir/metadata" | |
90 | rm -f "$trace_dir/metadata-0" | |
91 | rm -f "$trace_dir/the-stream" | |
92 | rm -f "$trace_dir/the-stream-0" | |
93 | rmdir "$trace_dir" | |
94 | rmdir "$temp_output_dir" |