X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fcli%2Ftest_trace_copy.in;h=c9047460b70df55595708fdfea2d5c06cdbe3d63;hb=bbff0ab4992445a57cb04e35da8e63b8ed32ea38;hp=b2de187ebcfba3a89afb4854b3e5d30d47e85ead;hpb=5177c3519afdc36b0948209c73f1d0719a9a3eb0;p=babeltrace.git diff --git a/tests/cli/test_trace_copy.in b/tests/cli/test_trace_copy.in index b2de187e..c9047460 100644 --- a/tests/cli/test_trace_copy.in +++ b/tests/cli/test_trace_copy.in @@ -15,38 +15,65 @@ # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -CURDIR=$(dirname $0) -TESTDIR=$CURDIR/.. +. "@abs_top_builddir@/tests/utils/common.sh" -BABELTRACE_BIN=$CURDIR/../../cli/babeltrace +clean_tmp() { + rm -rf "${out_path}" "${text_output1}" "${text_output2}" +} -CTF_TRACES=@abs_top_srcdir@/tests/ctf-traces +SUCCESS_TRACES=(${BT_CTF_TRACES_PATH}/succeed/*) -source $TESTDIR/utils/tap/tap.sh - -SUCCESS_TRACES=(${CTF_TRACES}/succeed/*) -FAIL_TRACES=(${CTF_TRACES}/fail/*) - -NUM_TESTS=$((${#SUCCESS_TRACES[@]} * 3)) +# -2 because there is an empty trace that we skip +NUM_TESTS=$((${#SUCCESS_TRACES[@]} * 3 - 2)) plan_tests $NUM_TESTS -for path in ${SUCCESS_TRACES[@]}; do - out_path=$(mktemp -d) - trace=$(basename ${path}) +for path in "${SUCCESS_TRACES[@]}"; do + out_path="$(mktemp -d)" + text_output1="$(mktemp)" + text_output2="$(mktemp)" + trace="$(basename "${path}")" + sort_cmd="cat" # by default do not sort the trace - orig_cnt=$($BABELTRACE_BIN ${path} 2>/dev/null | wc -l) + "${BT_BIN}" --no-delta "${path}" 2>/dev/null >"${text_output1}" + ret=$? + cnt="$(wc -l < "${text_output1}")" + if test "$ret" == 0 && test $cnt == 0; then + pass "Empty trace ${trace}, nothing to copy" + clean_tmp + continue + fi - $BABELTRACE_BIN ${path} --component sink.ctf.fs --path ${out_path} >/dev/null 2>&1 + # If the trace has a timestamp (starts with [), check if there are + # duplicate timestamps in the output. + # If there are, we have to sort the text output to make sure it is + # always the same. + head -1 "${text_output1}" | @GREP@ "^\[" >/dev/null + if test $? = 0; then + uniq_ts_cnt="$(@AWK@ '{ print $1 }' < "${text_output1}" | sort | uniq | wc -l)" + # Extract only the timestamp columns and compare the number of + # unique lines with the total number of lines to see if there + # are duplicate timestamps. + if test $cnt != $uniq_ts_cnt; then + diag "Trace with non unique timestamps, sorting the output" + sort_cmd="sort" + tmp="$(mktemp)" + sort "${text_output1}" > "$tmp" + rm "${text_output1}" + text_output1="$tmp" + fi + fi + + "${BT_BIN}" "${path}" --component sink.ctf.fs --path "${out_path}" >/dev/null 2>&1 ok $? "Copy trace ${trace} with ctf-fs sink" - $BABELTRACE_BIN ${out_path} >/dev/null 2>&1 + "${BT_BIN}" "${out_path}" >/dev/null 2>&1 ok $? "Read the new trace in ${out_path}" - new_cnt=$($BABELTRACE_BIN ${out_path} 2>/dev/null | wc -l) - - test $orig_cnt == $new_cnt - ok $? "Same number of events as the original trace ($orig_cnt -> $new_cnt)" + "${BT_BIN}" --no-delta "${out_path}" 2>/dev/null | $sort_cmd >"${text_output2}" + cnt=$(diff "${text_output1}" "${text_output2}" | wc -l) + test $cnt == 0 + ok $? "Exact same content between the two traces" - rm -rf ${out_path} + clean_tmp done