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