| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com> |
| 6 | # |
| 7 | |
| 8 | # Test how log level options are applied to sources auto-discovered by the |
| 9 | # convert command. |
| 10 | |
| 11 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; then |
| 12 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" |
| 13 | else |
| 14 | UTILSSH="$(dirname "$0")/../../utils/utils.sh" |
| 15 | fi |
| 16 | |
| 17 | # shellcheck source=../../utils/utils.sh |
| 18 | SH_TAP=1 source "$UTILSSH" |
| 19 | |
| 20 | NUM_TESTS=4 |
| 21 | |
| 22 | plan_tests $NUM_TESTS |
| 23 | |
| 24 | data_dir="${BT_TESTS_DATADIR}/auto-source-discovery/params-log-level" |
| 25 | plugin_dir="${data_dir}" |
| 26 | dir_a="${data_dir}/dir-a" |
| 27 | dir_b="${data_dir}/dir-b" |
| 28 | dir_ab="${data_dir}/dir-ab" |
| 29 | |
| 30 | expected_file=$(mktemp -t expected.XXXXXX) |
| 31 | |
| 32 | print_log_level=(--params 'what="log-level"') |
| 33 | details_sink=("-c" "sink.text.details" "--params=with-metadata=false") |
| 34 | |
| 35 | debug=2 |
| 36 | trace=1 |
| 37 | |
| 38 | # Apply log level to two components from one non-option argument. |
| 39 | cat > "$expected_file" <<END |
| 40 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 41 | Stream beginning: |
| 42 | Name: TestSourceA: ${debug} |
| 43 | Trace: |
| 44 | Stream (ID 0, Class ID 0) |
| 45 | |
| 46 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 47 | Stream beginning: |
| 48 | Name: TestSourceB: ${debug} |
| 49 | Trace: |
| 50 | Stream (ID 0, Class ID 0) |
| 51 | |
| 52 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 53 | Stream end |
| 54 | |
| 55 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 56 | Stream end |
| 57 | END |
| 58 | |
| 59 | bt_diff_cli "$expected_file" "/dev/null" \ |
| 60 | --plugin-path "${plugin_dir}" convert \ |
| 61 | "${dir_ab}" --log-level DEBUG "${print_log_level[@]}" \ |
| 62 | "${details_sink[@]}" |
| 63 | ok "$?" "apply log level to two components from one non-option argument" |
| 64 | |
| 65 | # Apply log level to two components from two distinct non-option arguments. |
| 66 | cat > "$expected_file" <<END |
| 67 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 68 | Stream beginning: |
| 69 | Name: TestSourceA: ${debug} |
| 70 | Trace: |
| 71 | Stream (ID 0, Class ID 0) |
| 72 | |
| 73 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 74 | Stream beginning: |
| 75 | Name: TestSourceB: ${trace} |
| 76 | Trace: |
| 77 | Stream (ID 0, Class ID 0) |
| 78 | |
| 79 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 80 | Stream end |
| 81 | |
| 82 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 83 | Stream end |
| 84 | END |
| 85 | |
| 86 | bt_diff_cli "$expected_file" "/dev/null" \ |
| 87 | --plugin-path "${plugin_dir}" convert \ |
| 88 | "${dir_a}" --log-level DEBUG "${print_log_level[@]}" "${dir_b}" --log-level TRACE "${print_log_level[@]}" \ |
| 89 | "${details_sink[@]}" |
| 90 | ok "$?" "apply log level to two non-option arguments" |
| 91 | |
| 92 | # Apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (1). |
| 93 | cat > "$expected_file" <<END |
| 94 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 95 | Stream beginning: |
| 96 | Name: TestSourceA: ${trace} |
| 97 | Trace: |
| 98 | Stream (ID 0, Class ID 0) |
| 99 | |
| 100 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 101 | Stream beginning: |
| 102 | Name: TestSourceB: ${trace} |
| 103 | Trace: |
| 104 | Stream (ID 0, Class ID 0) |
| 105 | |
| 106 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 107 | Stream end |
| 108 | |
| 109 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 110 | Stream end |
| 111 | END |
| 112 | |
| 113 | bt_diff_cli "$expected_file" "/dev/null" \ |
| 114 | --plugin-path "${plugin_dir}" convert \ |
| 115 | "${dir_a}" --log-level DEBUG "${print_log_level[@]}" "${dir_ab}" --log-level TRACE "${print_log_level[@]}" \ |
| 116 | "${details_sink[@]}" |
| 117 | ok "$?" "apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (1)" |
| 118 | |
| 119 | # Apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (2). |
| 120 | cat > "$expected_file" <<END |
| 121 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 122 | Stream beginning: |
| 123 | Name: TestSourceA: ${trace} |
| 124 | Trace: |
| 125 | Stream (ID 0, Class ID 0) |
| 126 | |
| 127 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 128 | Stream beginning: |
| 129 | Name: TestSourceB: ${debug} |
| 130 | Trace: |
| 131 | Stream (ID 0, Class ID 0) |
| 132 | |
| 133 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 134 | Stream end |
| 135 | |
| 136 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 137 | Stream end |
| 138 | END |
| 139 | |
| 140 | bt_diff_cli "$expected_file" "/dev/null" \ |
| 141 | --plugin-path "${plugin_dir}" convert \ |
| 142 | "${dir_ab}" --log-level DEBUG "${print_log_level[@]}" "${dir_a}" --log-level TRACE "${print_log_level[@]}" \ |
| 143 | "${details_sink[@]}" |
| 144 | ok "$?" "apply log level to one component coming from one non-option argument and one component coming from two non-option arguments (2)" |
| 145 | |
| 146 | rm -f "$expected_file" |