port: Use sig_t instead of sighandler_t
[babeltrace.git] / tests / cli / test_trace_copy.in
CommitLineData
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
d8e292d4 18. "@abs_top_builddir@/tests/utils/common.sh"
673a485c 19
6dff0cfb
MJ
20clean_tmp() {
21 rm -rf "${out_path}" "${text_output1}" "${text_output2}"
22}
23
b7c5d194 24SUCCESS_TRACES=(${BT_CTF_TRACES_PATH}/succeed/*)
673a485c 25
37b92a38
JD
26# -2 because there is an empty trace that we skip
27NUM_TESTS=$((${#SUCCESS_TRACES[@]} * 3 - 2))
673a485c
JD
28
29plan_tests $NUM_TESTS
30
de3fb4cd
MJ
31for path in "${SUCCESS_TRACES[@]}"; do
32 out_path="$(mktemp -d)"
33 text_output1="$(mktemp)"
34 text_output2="$(mktemp)"
35 trace="$(basename "${path}")"
6dff0cfb 36 sort_cmd="cat" # by default do not sort the trace
de3fb4cd 37
6dff0cfb 38 "${BT_BIN}" --no-delta "${path}" 2>/dev/null >"${text_output1}"
de3fb4cd
MJ
39 ret=$?
40 cnt="$(wc -l < "${text_output1}")"
3119de00 41 if test "$ret" == 0 && test $cnt == 0; then
6dff0cfb
MJ
42 pass "Empty trace ${trace}, nothing to copy"
43 clean_tmp
37b92a38
JD
44 continue
45 fi
673a485c 46
6dff0cfb
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.
51 head -1 "${text_output1}" | @GREP@ "^\[" >/dev/null
52 if test $? = 0; then
53 uniq_ts_cnt="$(@AWK@ '{ print $1 }' < "${text_output1}" | sort | uniq | wc -l)"
54 # Extract only the timestamp columns and compare the number of
55 # unique lines with the total number of lines to see if there
56 # are duplicate timestamps.
3119de00 57 if test $cnt != $uniq_ts_cnt; then
6dff0cfb
MJ
58 diag "Trace with non unique timestamps, sorting the output"
59 sort_cmd="sort"
60 tmp="$(mktemp)"
61 sort "${text_output1}" > "$tmp"
62 rm "${text_output1}"
63 text_output1="$tmp"
64 fi
65 fi
66
de3fb4cd 67 "${BT_BIN}" "${path}" --component sink.ctf.fs --path "${out_path}" >/dev/null 2>&1
673a485c
JD
68 ok $? "Copy trace ${trace} with ctf-fs sink"
69
de3fb4cd 70 "${BT_BIN}" "${out_path}" >/dev/null 2>&1
6dff0cfb 71 ok $? "Read the new trace in ${out_path}"
673a485c 72
6dff0cfb 73 "${BT_BIN}" --no-delta "${out_path}" 2>/dev/null | $sort_cmd >"${text_output2}"
de3fb4cd 74 cnt=$(diff "${text_output1}" "${text_output2}" | wc -l)
3119de00 75 test $cnt == 0
37b92a38 76 ok $? "Exact same content between the two traces"
673a485c 77
6dff0cfb 78 clean_tmp
673a485c 79done
This page took 0.035405 seconds and 4 git commands to generate.