| 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 parameters are applied to sources auto-discovered by the convert |
| 9 | # 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_test_params=("--params" 'what="test-params"') |
| 33 | details_sink=("-c" "sink.text.details" "--params=with-metadata=false") |
| 34 | |
| 35 | # Apply params to two components from one non-option argument. |
| 36 | cat > "$expected_file" <<END |
| 37 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 38 | Stream beginning: |
| 39 | Name: TestSourceA: ('test-allo', 'madame') |
| 40 | Trace: |
| 41 | Stream (ID 0, Class ID 0) |
| 42 | |
| 43 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 44 | Stream beginning: |
| 45 | Name: TestSourceB: ('test-allo', 'madame') |
| 46 | Trace: |
| 47 | Stream (ID 0, Class ID 0) |
| 48 | |
| 49 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 50 | Stream end |
| 51 | |
| 52 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 53 | Stream end |
| 54 | END |
| 55 | |
| 56 | bt_diff_cli "$expected_file" "/dev/null" \ |
| 57 | --plugin-path "${plugin_dir}" convert \ |
| 58 | "${dir_ab}" --params 'test-allo="madame"' "${print_test_params[@]}" \ |
| 59 | "${details_sink[@]}" |
| 60 | ok "$?" "apply params to two components from one non-option argument" |
| 61 | |
| 62 | # Apply params to two components from two distinct non-option arguments. |
| 63 | cat > "$expected_file" <<END |
| 64 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 65 | Stream beginning: |
| 66 | Name: TestSourceA: ('test-allo', 'madame') |
| 67 | Trace: |
| 68 | Stream (ID 0, Class ID 0) |
| 69 | |
| 70 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 71 | Stream beginning: |
| 72 | Name: TestSourceB: ('test-bonjour', 'monsieur') |
| 73 | Trace: |
| 74 | Stream (ID 0, Class ID 0) |
| 75 | |
| 76 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 77 | Stream end |
| 78 | |
| 79 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 80 | Stream end |
| 81 | END |
| 82 | |
| 83 | bt_diff_cli "$expected_file" "/dev/null" \ |
| 84 | --plugin-path "${plugin_dir}" convert \ |
| 85 | "${dir_a}" --params 'test-allo="madame"' "${print_test_params[@]}" "${dir_b}" --params 'test-bonjour="monsieur"' "${print_test_params[@]}" \ |
| 86 | "${details_sink[@]}" |
| 87 | ok "$?" "apply params to two non-option arguments" |
| 88 | |
| 89 | # Apply params to one component coming from one non-option argument and one component coming from two non-option arguments (1). |
| 90 | cat > "$expected_file" <<END |
| 91 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 92 | Stream beginning: |
| 93 | Name: TestSourceA: ('test-allo', 'madame'), ('test-bonjour', 'monsieur') |
| 94 | Trace: |
| 95 | Stream (ID 0, Class ID 0) |
| 96 | |
| 97 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 98 | Stream beginning: |
| 99 | Name: TestSourceB: ('test-bonjour', 'monsieur') |
| 100 | Trace: |
| 101 | Stream (ID 0, Class ID 0) |
| 102 | |
| 103 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 104 | Stream end |
| 105 | |
| 106 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 107 | Stream end |
| 108 | END |
| 109 | |
| 110 | bt_diff_cli "$expected_file" "/dev/null" \ |
| 111 | --plugin-path "${plugin_dir}" convert \ |
| 112 | "${dir_a}" --params 'test-allo="madame"' "${print_test_params[@]}" "${dir_ab}" --params 'test-bonjour="monsieur"' "${print_test_params[@]}" \ |
| 113 | "${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)" |
| 115 | |
| 116 | # Apply params to one component coming from one non-option argument and one component coming from two non-option arguments (2). |
| 117 | cat > "$expected_file" <<END |
| 118 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 119 | Stream beginning: |
| 120 | Name: TestSourceA: ('test-bonjour', 'monsieur'), ('test-salut', 'les amis') |
| 121 | Trace: |
| 122 | Stream (ID 0, Class ID 0) |
| 123 | |
| 124 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 125 | Stream beginning: |
| 126 | Name: TestSourceB: ('test-bonjour', 'madame'), ('test-salut', 'les amis') |
| 127 | Trace: |
| 128 | Stream (ID 0, Class ID 0) |
| 129 | |
| 130 | {Trace 0, Stream class ID 0, Stream ID 0} |
| 131 | Stream end |
| 132 | |
| 133 | {Trace 1, Stream class ID 0, Stream ID 0} |
| 134 | Stream end |
| 135 | END |
| 136 | |
| 137 | bt_diff_cli "$expected_file" "/dev/null" \ |
| 138 | --plugin-path "${plugin_dir}" convert \ |
| 139 | "${dir_ab}" --params 'test-bonjour="madame",test-salut="les amis"' "${print_test_params[@]}" "${dir_a}" --params 'test-bonjour="monsieur"' "${print_test_params[@]}" \ |
| 140 | "${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)" |
| 142 | |
| 143 | rm -f "$expected_file" |