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