| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com> |
| 6 | # |
| 7 | |
| 8 | SH_TAP=1 |
| 9 | |
| 10 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; 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" |
| 18 | |
| 19 | plan_tests 20 |
| 20 | |
| 21 | stdout=$(mktemp -t test-intersection-stdout.XXXXXX) |
| 22 | stderr=$(mktemp -t test-intersection-stderr.XXXXXX) |
| 23 | |
| 24 | test_intersect() { |
| 25 | local trace="$1" |
| 26 | local totalevents="$2" |
| 27 | local intersect="$3" |
| 28 | |
| 29 | local cnt |
| 30 | |
| 31 | bt_cli "${stdout}" "/dev/null" "${trace}" |
| 32 | ok $? "run without --stream-intersection" |
| 33 | |
| 34 | cnt=$(wc -l < "${stdout}") |
| 35 | test "${cnt// /}" = "$totalevents" |
| 36 | ok $? "$totalevents events in the whole trace" |
| 37 | |
| 38 | bt_cli "${stdout}" "/dev/null" --stream-intersection "${trace}" |
| 39 | ok $? "run with --stream-intersection" |
| 40 | |
| 41 | cnt=$(wc -l < "${stdout}") |
| 42 | test "${cnt// /}" = "$intersect" |
| 43 | ok $? "$intersect events in streams intersecting" |
| 44 | } |
| 45 | |
| 46 | test_intersect_fails() { |
| 47 | local trace="$1" |
| 48 | local totalevents="$2" |
| 49 | local expected_error_message="$3" |
| 50 | |
| 51 | bt_cli "${stdout}" "/dev/null" "${trace}" |
| 52 | ok $? "run without --stream-intersection" |
| 53 | |
| 54 | cnt=$(wc -l < "${stdout}") |
| 55 | test "${cnt// /}" = "$totalevents" |
| 56 | ok $? "$totalevents events in the whole trace" |
| 57 | |
| 58 | bt_cli "${stdout}" "${stderr}" --stream-intersection "${trace}" |
| 59 | isnt "$?" 0 "run with --stream-intersection fails" |
| 60 | |
| 61 | bt_grep_ok \ |
| 62 | "${expected_error_message}" \ |
| 63 | "${stderr}" \ |
| 64 | "stderr contains expected error message" |
| 65 | } |
| 66 | |
| 67 | diag "Test the stream intersection feature" |
| 68 | |
| 69 | diag "2 streams offsetted with 3 packets intersecting" |
| 70 | test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersect" 8 3 |
| 71 | |
| 72 | diag "2 streams offsetted with 3 packets intersecting (exchanged file names)" |
| 73 | test_intersect "${BT_CTF_TRACES_PATH}/intersection/3eventsintersectreverse" 8 3 |
| 74 | |
| 75 | diag "Only 1 stream" |
| 76 | test_intersect "${BT_CTF_TRACES_PATH}/intersection/onestream" 3 3 |
| 77 | |
| 78 | diag "No intersection between 2 streams" |
| 79 | test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nointersect" 6 \ |
| 80 | "Trimming time range's beginning time is greater than end time: " |
| 81 | |
| 82 | diag "No stream at all" |
| 83 | test_intersect_fails "${BT_CTF_TRACES_PATH}/intersection/nostream" 0 \ |
| 84 | "Trace has no streams: " |
| 85 | |
| 86 | rm -f "${stdout}" "${stderr}" |