| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com> |
| 6 | # |
| 7 | |
| 8 | SH_TAP=1 |
| 9 | |
| 10 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; then |
| 11 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" |
| 12 | else |
| 13 | UTILSSH="$(dirname "$0")/../utils/utils.sh" |
| 14 | fi |
| 15 | |
| 16 | # shellcheck source=../utils/utils.sh |
| 17 | source "$UTILSSH" |
| 18 | |
| 19 | clean_tmp() { |
| 20 | rm -rf "${out_path}" "${text_output1}" "${text_output2_intermediary}" "${text_output2}" "${stderr_file}" |
| 21 | } |
| 22 | |
| 23 | SUCCESS_TRACES=("${BT_CTF_TRACES_PATH}/succeed/"*) |
| 24 | |
| 25 | # -4 because there are two empty traces that we skip |
| 26 | NUM_TESTS=$((${#SUCCESS_TRACES[@]} * 3 - 4)) |
| 27 | |
| 28 | plan_tests $NUM_TESTS |
| 29 | |
| 30 | for path in "${SUCCESS_TRACES[@]}"; do |
| 31 | out_path="$(mktemp -d)" |
| 32 | text_output1="$(mktemp)" |
| 33 | text_output2_intermediary="$(mktemp)" |
| 34 | text_output2="$(mktemp)" |
| 35 | stderr_file="$(mktemp)" |
| 36 | trace="$(basename "${path}")" |
| 37 | sort_cmd="cat" # by default do not sort the trace |
| 38 | |
| 39 | bt_cli "${text_output1}" "/dev/null" --no-delta "${path}" |
| 40 | ret=$? |
| 41 | cnt="$(wc -l < "${text_output1}")" |
| 42 | if test "$ret" == 0 && test "${cnt// /}" == 0; then |
| 43 | pass "Empty trace ${trace}, nothing to copy" |
| 44 | clean_tmp |
| 45 | continue |
| 46 | fi |
| 47 | |
| 48 | # If the trace has a timestamp (starts with [), check if there are |
| 49 | # duplicate timestamps in the output. |
| 50 | # If there are, we have to sort the text output to make sure it is |
| 51 | # always the same. |
| 52 | head -1 "${text_output1}" | bt_grep "^\[" >/dev/null |
| 53 | if test $? = 0; then |
| 54 | # shellcheck disable=SC2016 |
| 55 | uniq_ts_cnt="$("${BT_TESTS_AWK_BIN}" '{ print $1 }' < "${text_output1}" | sort | uniq | wc -l)" |
| 56 | # Extract only the timestamp columns and compare the number of |
| 57 | # unique lines with the total number of lines to see if there |
| 58 | # are duplicate timestamps. |
| 59 | if test "${cnt// /}" != "${uniq_ts_cnt// /}"; then |
| 60 | diag "Trace with non unique timestamps, sorting the output" |
| 61 | sort_cmd="sort" |
| 62 | tmp="$(mktemp)" |
| 63 | sort "${text_output1}" > "$tmp" |
| 64 | rm "${text_output1}" |
| 65 | text_output1="$tmp" |
| 66 | fi |
| 67 | fi |
| 68 | |
| 69 | bt_cli "/dev/null" "${stderr_file}" "${path}" --component sink.ctf.fs "--params=path=\"${out_path}\"" |
| 70 | if ! ok $? "Copy trace ${trace} with ctf-fs sink"; then |
| 71 | diag "stderr:" |
| 72 | diag_file "${stderr_file}" |
| 73 | fi |
| 74 | |
| 75 | bt_cli "/dev/null" "${stderr_file}" "${out_path}" |
| 76 | if ! ok $? "Read the new trace in ${out_path}"; then |
| 77 | diag "stderr:" |
| 78 | diag_file "${stderr_file}" |
| 79 | fi |
| 80 | |
| 81 | if ! bt_cli "${text_output2_intermediary}" "${stderr_file}" --no-delta "${out_path}"; then |
| 82 | diag "stderr:" |
| 83 | diag_file "${stderr_file}" |
| 84 | fi |
| 85 | |
| 86 | $sort_cmd "${text_output2_intermediary}" > "${text_output2}" |
| 87 | bt_diff "${text_output1}" "${text_output2}" |
| 88 | ok $? "Exact same content between the two traces" |
| 89 | |
| 90 | clean_tmp |
| 91 | done |