tests: quote ${BT_CTF_TRACES_PATH} in test_trace_read and test_trace_copy
[babeltrace.git] / tests / cli / test_trace_copy
CommitLineData
5177c351
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
644e0364
MJ
18SH_TAP=1
19
20if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
21 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
22else
23 UTILSSH="$(dirname "$0")/../utils/utils.sh"
24fi
25
26# shellcheck source=../utils/utils.sh
27source "$UTILSSH"
5177c351 28
95a4b348 29clean_tmp() {
1f8a8691 30 rm -rf "${out_path}" "${text_output1}" "${text_output2_intermediary}" "${text_output2}"
95a4b348
MJ
31}
32
6b66b7a9 33SUCCESS_TRACES=("${BT_CTF_TRACES_PATH}/succeed/"*)
5177c351 34
c22ffa09
JD
35# -2 because there is an empty trace that we skip
36NUM_TESTS=$((${#SUCCESS_TRACES[@]} * 3 - 2))
5177c351
JD
37
38plan_tests $NUM_TESTS
39
03f007c8
MJ
40for path in "${SUCCESS_TRACES[@]}"; do
41 out_path="$(mktemp -d)"
42 text_output1="$(mktemp)"
1f8a8691 43 text_output2_intermediary="$(mktemp)"
03f007c8
MJ
44 text_output2="$(mktemp)"
45 trace="$(basename "${path}")"
95a4b348 46 sort_cmd="cat" # by default do not sort the trace
03f007c8 47
1f8a8691 48 bt_cli "${text_output1}" "/dev/null" --no-delta "${path}"
03f007c8
MJ
49 ret=$?
50 cnt="$(wc -l < "${text_output1}")"
644e0364 51 if test "$ret" == 0 && test "${cnt// /}" == 0; then
95a4b348
MJ
52 pass "Empty trace ${trace}, nothing to copy"
53 clean_tmp
c22ffa09
JD
54 continue
55 fi
5177c351 56
95a4b348
MJ
57 # If the trace has a timestamp (starts with [), check if there are
58 # duplicate timestamps in the output.
59 # If there are, we have to sort the text output to make sure it is
60 # always the same.
644e0364 61 head -1 "${text_output1}" | "${BT_TESTS_GREP_BIN}" "^\[" >/dev/null
95a4b348 62 if test $? = 0; then
644e0364 63 uniq_ts_cnt="$("${BT_TESTS_AWK_BIN}" '{ print $1 }' < "${text_output1}" | sort | uniq | wc -l)"
95a4b348
MJ
64 # Extract only the timestamp columns and compare the number of
65 # unique lines with the total number of lines to see if there
66 # are duplicate timestamps.
644e0364 67 if test "${cnt// /}" != "${uniq_ts_cnt// /}"; then
95a4b348
MJ
68 diag "Trace with non unique timestamps, sorting the output"
69 sort_cmd="sort"
70 tmp="$(mktemp)"
71 sort "${text_output1}" > "$tmp"
72 rm "${text_output1}"
73 text_output1="$tmp"
74 fi
75 fi
76
1f8a8691 77 bt_cli "/dev/null" "/dev/null" "${path}" --component sink.ctf.fs "--params=path=\"${out_path}\""
5177c351
JD
78 ok $? "Copy trace ${trace} with ctf-fs sink"
79
1f8a8691 80 bt_cli "/dev/null" "/dev/null" "${out_path}"
95a4b348 81 ok $? "Read the new trace in ${out_path}"
5177c351 82
1f8a8691
SM
83 bt_cli "${text_output2_intermediary}" "/dev/null" --no-delta "${out_path}"
84 $sort_cmd "${text_output2_intermediary}" > "${text_output2}"
03f007c8 85 cnt=$(diff "${text_output1}" "${text_output2}" | wc -l)
644e0364 86 test "${cnt// /}" == 0
c22ffa09 87 ok $? "Exact same content between the two traces"
5177c351 88
95a4b348 89 clean_tmp
5177c351 90done
This page took 0.051495 seconds and 4 git commands to generate.