Commit | Line | Data |
---|---|---|
673a485c JD |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2017 Julien Desfossez <jdesfossez@efficios.com> | |
4 | # | |
5 | # This program is free software; you can redistribute it and/or modify it | |
6 | # under the terms of the GNU General Public License, version 2 only, as | |
7 | # published by the Free Software Foundation. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | # more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License along with | |
15 | # this program; if not, write to the Free Software Foundation, Inc., 51 | |
16 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | ||
abdabab5 MJ |
18 | SH_TAP=1 |
19 | ||
20 | if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then | |
21 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" | |
22 | else | |
23 | UTILSSH="$(dirname "$0")/../utils/utils.sh" | |
24 | fi | |
25 | ||
26 | # shellcheck source=../utils/utils.sh | |
27 | source "$UTILSSH" | |
673a485c | 28 | |
6dff0cfb MJ |
29 | clean_tmp() { |
30 | rm -rf "${out_path}" "${text_output1}" "${text_output2}" | |
31 | } | |
32 | ||
b7c5d194 | 33 | SUCCESS_TRACES=(${BT_CTF_TRACES_PATH}/succeed/*) |
673a485c | 34 | |
37b92a38 JD |
35 | # -2 because there is an empty trace that we skip |
36 | NUM_TESTS=$((${#SUCCESS_TRACES[@]} * 3 - 2)) | |
673a485c JD |
37 | |
38 | plan_tests $NUM_TESTS | |
39 | ||
de3fb4cd MJ |
40 | for path in "${SUCCESS_TRACES[@]}"; do |
41 | out_path="$(mktemp -d)" | |
42 | text_output1="$(mktemp)" | |
43 | text_output2="$(mktemp)" | |
44 | trace="$(basename "${path}")" | |
6dff0cfb | 45 | sort_cmd="cat" # by default do not sort the trace |
de3fb4cd | 46 | |
abdabab5 | 47 | "${BT_TESTS_BT2_BIN}" --no-delta "${path}" 2>/dev/null >"${text_output1}" |
de3fb4cd MJ |
48 | ret=$? |
49 | cnt="$(wc -l < "${text_output1}")" | |
abdabab5 | 50 | if test "$ret" == 0 && test "${cnt// /}" == 0; then |
6dff0cfb MJ |
51 | pass "Empty trace ${trace}, nothing to copy" |
52 | clean_tmp | |
37b92a38 JD |
53 | continue |
54 | fi | |
673a485c | 55 | |
6dff0cfb MJ |
56 | # If the trace has a timestamp (starts with [), check if there are |
57 | # duplicate timestamps in the output. | |
58 | # If there are, we have to sort the text output to make sure it is | |
59 | # always the same. | |
abdabab5 | 60 | head -1 "${text_output1}" | "${BT_TESTS_GREP_BIN}" "^\[" >/dev/null |
6dff0cfb | 61 | if test $? = 0; then |
abdabab5 | 62 | uniq_ts_cnt="$("${BT_TESTS_AWK_BIN}" '{ print $1 }' < "${text_output1}" | sort | uniq | wc -l)" |
6dff0cfb MJ |
63 | # Extract only the timestamp columns and compare the number of |
64 | # unique lines with the total number of lines to see if there | |
65 | # are duplicate timestamps. | |
abdabab5 | 66 | if test "${cnt// /}" != "${uniq_ts_cnt// /}"; then |
6dff0cfb MJ |
67 | diag "Trace with non unique timestamps, sorting the output" |
68 | sort_cmd="sort" | |
69 | tmp="$(mktemp)" | |
70 | sort "${text_output1}" > "$tmp" | |
71 | rm "${text_output1}" | |
72 | text_output1="$tmp" | |
73 | fi | |
74 | fi | |
75 | ||
99854915 | 76 | "${BT_TESTS_BT2_BIN}" "${path}" --component sink.ctf.fs "--params=path=\"${out_path}\"" >/dev/null 2>&1 |
673a485c JD |
77 | ok $? "Copy trace ${trace} with ctf-fs sink" |
78 | ||
abdabab5 | 79 | "${BT_TESTS_BT2_BIN}" "${out_path}" >/dev/null 2>&1 |
6dff0cfb | 80 | ok $? "Read the new trace in ${out_path}" |
673a485c | 81 | |
abdabab5 | 82 | "${BT_TESTS_BT2_BIN}" --no-delta "${out_path}" 2>/dev/null | $sort_cmd >"${text_output2}" |
de3fb4cd | 83 | cnt=$(diff "${text_output1}" "${text_output2}" | wc -l) |
abdabab5 | 84 | test "${cnt// /}" == 0 |
37b92a38 | 85 | ok $? "Exact same content between the two traces" |
673a485c | 86 | |
6dff0cfb | 87 | clean_tmp |
673a485c | 88 | done |