| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2017 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 | TRACE_PATH="${BT_CTF_TRACES_PATH}/1/succeed/wk-heartbeat-u/" |
| 20 | |
| 21 | NUM_TESTS=118 |
| 22 | |
| 23 | plan_tests $NUM_TESTS |
| 24 | |
| 25 | tmp_out=$(mktemp) |
| 26 | tmp_err=$(mktemp) |
| 27 | |
| 28 | |
| 29 | # Run Babeltrace with some command line arguments, verify exit status and |
| 30 | # number of output events (i.e. number of output lines) |
| 31 | # |
| 32 | # Arguments: |
| 33 | # |
| 34 | # $1: expected number of events |
| 35 | # $2: test description |
| 36 | # remaining arguments: command-line arguments to pass to Babeltrace |
| 37 | |
| 38 | function expect_success() |
| 39 | { |
| 40 | local expected_num_events="$1" |
| 41 | local msg="$2" |
| 42 | shift 2 |
| 43 | |
| 44 | bt_cli "${tmp_out}" /dev/null "${TRACE_PATH}" "$@" |
| 45 | ok $? "trimmer: ${msg}: exit status" |
| 46 | |
| 47 | num_events=$(wc -l < "${tmp_out}") |
| 48 | # Use bash parameter expansion to strip spaces added by BSD 'wc' on macOs and Solaris |
| 49 | is "${num_events// /}" "${expected_num_events}" "trimmer: ${msg}: number of events (${expected_num_events})" |
| 50 | } |
| 51 | |
| 52 | # Run Babeltrace with some command line arguments, verify that the exit status |
| 53 | # is not 0 and that the error message contains a given string. |
| 54 | # |
| 55 | # Arguments: |
| 56 | # |
| 57 | # $1: a string expected to be found in the error message |
| 58 | # $2: test description |
| 59 | # remaining arguments: command-line arguments to pass to Babeltrace |
| 60 | |
| 61 | function expect_failure() |
| 62 | { |
| 63 | local expected_err_string="$1" |
| 64 | local msg="$2" |
| 65 | shift 2 |
| 66 | |
| 67 | # We check the error message logged by the trimmer plugin, set the env |
| 68 | # var necessary for it to log errors. |
| 69 | BABELTRACE_FLT_UTILS_TRIMMER_LOG_LEVEL=E bt_cli "${tmp_out}" "${tmp_err}" "${TRACE_PATH}" "$@" |
| 70 | isnt $? 0 "trimmer: ${msg}: exit status" |
| 71 | |
| 72 | num_events=$(wc -l < "${tmp_out}") |
| 73 | # Use bash parameter expansion to strip spaces added by BSD 'wc' on macOs and Solaris |
| 74 | is "${num_events// /}" 0 "trimmer: ${msg}: number of events (0)" |
| 75 | |
| 76 | stderr="$(cat "${tmp_err}")" |
| 77 | # "like" doesn't like when the passed text is empty. |
| 78 | if [ -n "${stderr}" ]; then |
| 79 | like "${stderr}" "${expected_err_string}" "trimmer: ${msg}: error message" |
| 80 | else |
| 81 | fail "trimmer: ${msg}: error message" |
| 82 | diag "Nothing was output on stderr". |
| 83 | fi |
| 84 | |
| 85 | } |
| 86 | |
| 87 | expect_success 18 "--begin, GMT relative timestamps" \ |
| 88 | --clock-gmt --begin 17:48:17.587029529 |
| 89 | expect_success 9 "--end, GMT relative timestamps" \ |
| 90 | --clock-gmt --end 17:48:17.588680018 |
| 91 | expect_success 7 "--begin and --end, GMT relative timestamps" \ |
| 92 | --clock-gmt --begin 17:48:17.587029529 --end 17:48:17.588680018 |
| 93 | expect_success 0 "--begin, out of range, GMT relative timestamps" \ |
| 94 | --clock-gmt --begin 18:48:17.587029529 |
| 95 | expect_success 0 "--end, out of range, GMT relative timestamps" \ |
| 96 | --clock-gmt --end 16:48:17.588680018 |
| 97 | |
| 98 | expect_success 18 "--begin, GMT absolute timestamps" \ |
| 99 | --clock-gmt --begin "2012-10-29 17:48:17.587029529" |
| 100 | expect_success 9 "--end, GMT absolute timestamps" \ |
| 101 | --clock-gmt --end "2012-10-29 17:48:17.588680018" |
| 102 | expect_success 7 "--begin and --end, GMT absolute timestamps" \ |
| 103 | --clock-gmt --begin "2012-10-29 17:48:17.587029529" --end "2012-10-29 17:48:17.588680018" |
| 104 | expect_success 0 "--begin, out of range, GMT absolute timestamps" \ |
| 105 | --clock-gmt --begin "2012-10-29 18:48:17.587029529" |
| 106 | expect_success 0 "--begin, out of range, GMT absolute timestamps" \ |
| 107 | --clock-gmt --end "2012-10-29 16:48:17.588680018" |
| 108 | |
| 109 | # Note here that the POSIX notation is a bit weird. |
| 110 | # The libc documentation shed some light on this: |
| 111 | # The offset specifies the time value you must add to the local time to get a |
| 112 | # Coordinated Universal Time value. It has syntax like [+|-]hh[:mm[:ss]]. This |
| 113 | # is positive if the local time zone is west of the Prime Meridian and negative |
| 114 | # if it is east. The hour must be between 0 and 24, and the minute and seconds |
| 115 | # between 0 and 59. [1] |
| 116 | # |
| 117 | # This is why we use EST5 to simulate an effective UTC-5:00 time. |
| 118 | # |
| 119 | # [1] https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html |
| 120 | export TZ=EST5 |
| 121 | |
| 122 | expect_success 18 "--begin, EST relative timestamps" \ |
| 123 | --begin "12:48:17.587029529" |
| 124 | expect_success 9 "--end, EST relative timestamps" \ |
| 125 | --end "12:48:17.588680018" |
| 126 | expect_success 7 "--begin and --end, EST relative timestamps" \ |
| 127 | --begin "12:48:17.587029529" --end "12:48:17.588680018" |
| 128 | expect_success 0 "--begin, out of range, EST relative timestamps" \ |
| 129 | --begin "13:48:17.587029529" |
| 130 | expect_success 0 "--end, out of range, EST relative timestamps" \ |
| 131 | --end "11:48:17.588680018" |
| 132 | |
| 133 | expect_success 18 "--begin, EST absolute timestamps" \ |
| 134 | --begin "2012-10-29 12:48:17.587029529" |
| 135 | expect_success 9 "--end, EST absolute timestamps" \ |
| 136 | --end "12:48:17.588680018" |
| 137 | expect_success 7 "--begin and --end, EST absolute timestamps" \ |
| 138 | --begin "2012-10-29 12:48:17.587029529" --end "2012-10-29 12:48:17.588680018" |
| 139 | expect_success 0 "--begin, out of range, EST absolute timestamps" \ |
| 140 | --begin "2012-10-29 13:48:17.587029529" |
| 141 | expect_success 0 "--end, out of range, EST absolute timestamps" \ |
| 142 | --end "2012-10-29 11:48:17.588680018" |
| 143 | |
| 144 | # Check various formats. |
| 145 | # |
| 146 | # We sometimes apply a clock offset to make the events of the trace span two |
| 147 | # different seconds or minutes. |
| 148 | |
| 149 | expect_success 13 "date time format: partial nanosecond precision" \ |
| 150 | --begin="2012-10-29 12:48:17.588" |
| 151 | expect_success 11 "date time format: second precision" \ |
| 152 | --clock-offset-ns=411282268 --begin="2012-10-29 12:48:18" |
| 153 | expect_success 11 "date time format: minute precision" \ |
| 154 | --clock-offset=42 --clock-offset-ns=411282268 --begin="2012-10-29 12:49" |
| 155 | |
| 156 | expect_success 11 "seconds from origin format: nanosecond precision" \ |
| 157 | --begin="1351532897.588717732" |
| 158 | expect_success 11 "seconds from origin format: partial nanosecond precision" \ |
| 159 | --begin="1351532897.58871773" |
| 160 | expect_success 11 "seconds from origin format: second precision" \ |
| 161 | --clock-offset-ns=411282268 --begin="1351532898" |
| 162 | |
| 163 | expect_failure "Invalid date/time format" "date time format: too many nanosecond digits" \ |
| 164 | --begin="2012-10-29 12:48:17.1231231231" |
| 165 | expect_failure "Invalid date/time format" "date time format: missing nanoseconds" \ |
| 166 | --begin="2012-10-29 12:48:17." |
| 167 | expect_failure "Invalid date/time format" "date time format: seconds with too many digit" \ |
| 168 | --begin="2012-10-29 12:48:123" |
| 169 | expect_failure "Invalid date/time format" "date time format: seconds with missing digit" \ |
| 170 | --begin="2012-10-29 12:48:1" |
| 171 | expect_failure "Invalid date/time format" "date time format: minutes with too many digit" \ |
| 172 | --begin="2012-10-29 12:489:17" |
| 173 | expect_failure "Invalid date/time format" "date time format: minutes with missing digit" \ |
| 174 | --begin="2012-10-29 12:4:17" |
| 175 | expect_failure "Invalid date/time format" "date time format: hours with too many digit" \ |
| 176 | --begin="2012-10-29 123:48:17" |
| 177 | expect_failure "Invalid date/time format" "date time format: hours with missing digit" \ |
| 178 | --begin="2012-10-29 2:48:17" |
| 179 | expect_failure "Invalid date/time format" "date time format: missing seconds" \ |
| 180 | --begin="2012-10-29 12:48:" |
| 181 | expect_failure "Invalid date/time format" "date time format: missing minutes 1" \ |
| 182 | --begin="2012-10-29 12:" |
| 183 | expect_failure "Invalid date/time format" "date time format: missing minutes 2" \ |
| 184 | --begin="2012-10-29 12" |
| 185 | expect_failure "Invalid date/time format" "date time format: missing time" \ |
| 186 | --begin="2012-10-29 " |
| 187 | expect_failure "Invalid date/time format" "date time format: day with too many digit" \ |
| 188 | --begin="2012-10-291" |
| 189 | expect_failure "Invalid date/time format" "date time format: day with missing digit" \ |
| 190 | --begin="2012-10-2" |
| 191 | expect_failure "Invalid date/time format" "date time format: month with too many digit" \ |
| 192 | --begin="2012-101-29" |
| 193 | expect_failure "Invalid date/time format" "date time format: month with missing digit" \ |
| 194 | --begin="2012-1-29" |
| 195 | expect_failure "Invalid date/time format" "date time format: year with too many digits" \ |
| 196 | --begin="20121-10-29" |
| 197 | expect_failure "Invalid date/time format" "date time format: year with missing digits" \ |
| 198 | --begin="12-10-29" |
| 199 | expect_failure "Invalid date/time format" "date time format: missing day 1" \ |
| 200 | --begin="2012-10-" |
| 201 | expect_failure "Invalid date/time format" "date time format: missing day 2" \ |
| 202 | --begin="2012-10" |
| 203 | |
| 204 | expect_failure "Invalid date/time format" "seconds from origin format: too many nanosecond digits" \ |
| 205 | --begin="1351532898.1231231231" |
| 206 | expect_failure "Invalid date/time format" "seconds from origin format: missing nanseconds" \ |
| 207 | --begin="1351532898." |
| 208 | |
| 209 | rm "${tmp_out}" "${tmp_err}" |