Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | # |
Gavin Howard | 29e00ba | 2020-06-30 09:25:21 -0600 | [diff] [blame] | 3 | # SPDX-License-Identifier: BSD-2-Clause |
| 4 | # |
Gavin Howard | 4feb708 | 2021-01-26 01:19:25 -0700 | [diff] [blame] | 5 | # Copyright (c) 2018-2021 Gavin D. Howard and contributors. |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 6 | # |
Gavin Howard | 7345cb9 | 2019-04-08 14:13:43 -0600 | [diff] [blame] | 7 | # Redistribution and use in source and binary forms, with or without |
| 8 | # modification, are permitted provided that the following conditions are met: |
| 9 | # |
| 10 | # * Redistributions of source code must retain the above copyright notice, this |
| 11 | # list of conditions and the following disclaimer. |
| 12 | # |
| 13 | # * Redistributions in binary form must reproduce the above copyright notice, |
| 14 | # this list of conditions and the following disclaimer in the documentation |
| 15 | # and/or other materials provided with the distribution. |
| 16 | # |
| 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 21 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | # POSSIBILITY OF SUCH DAMAGE. |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 28 | # |
| 29 | |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 30 | readlink() { |
| 31 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 32 | _readlink_f="$1" |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 33 | shift |
| 34 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 35 | _readlink_arrow="-> " |
| 36 | _readlink_d=$(dirname "$_readlink_f") |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 37 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 38 | _readlink_lsout="" |
| 39 | _readlink_link="" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 40 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 41 | _readlink_lsout=$(ls -dl "$_readlink_f") |
| 42 | _readlink_link=$(printf '%s' "${_readlink_lsout#*$_readlink_arrow}") |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 43 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 44 | while [ -z "${_readlink_lsout##*$_readlink_arrow*}" ]; do |
| 45 | _readlink_f="$_readlink_d/$_readlink_link" |
| 46 | _readlink_d=$(dirname "$_readlink_f") |
| 47 | _readlink_lsout=$(ls -dl "$_readlink_f") |
| 48 | _readlink_link=$(printf '%s' "${_readlink_lsout#*$_readlink_arrow}") |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 49 | done |
| 50 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 51 | printf '%s' "${_readlink_f##*$_readlink_d/}" |
Gavin Howard | 5008025 | 2019-02-20 15:27:43 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Gavin Howard | 8237f80 | 2019-04-11 12:23:03 -0600 | [diff] [blame] | 54 | err_exit() { |
| 55 | |
| 56 | if [ "$#" -ne 2 ]; then |
| 57 | printf 'Invalid number of args to err_exit\n' |
| 58 | exit 1 |
| 59 | fi |
| 60 | |
| 61 | printf '%s\n' "$1" |
Gavin Howard | 8237f80 | 2019-04-11 12:23:03 -0600 | [diff] [blame] | 62 | exit "$2" |
| 63 | } |
| 64 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 65 | checktest_retcode() { |
| 66 | |
| 67 | _checktest_retcode_d="$1" |
| 68 | shift |
| 69 | |
| 70 | _checktest_retcode_err="$1" |
| 71 | shift |
| 72 | |
| 73 | _checktest_retcode_name="$1" |
| 74 | shift |
| 75 | |
| 76 | if [ "$_checktest_retcode_err" -ne 0 ]; then |
| 77 | printf 'FAIL!!!\n' |
| 78 | err_exit "$_checktest_retcode_d failed test '$_checktest_retcode_name' with error code $_checktest_retcode_err" 1 |
| 79 | fi |
| 80 | } |
| 81 | |
| 82 | checktest() { |
| 83 | |
| 84 | _checktest_d="$1" |
| 85 | shift |
| 86 | |
| 87 | _checktest_err="$1" |
| 88 | shift |
| 89 | |
| 90 | _checktest_name="$1" |
| 91 | shift |
| 92 | |
| 93 | _checktest_test_path="$1" |
| 94 | shift |
| 95 | |
| 96 | _checktest_results_name="$1" |
| 97 | shift |
| 98 | |
| 99 | checktest_retcode "$_checktest_d" "$_checktest_err" "$_checktest_name" |
| 100 | |
| 101 | _checktest_diff=$(diff "$_checktest_test_path" "$_checktest_results_name") |
| 102 | |
| 103 | _checktest_err="$?" |
| 104 | |
| 105 | if [ "$_checktest_err" -ne 0 ]; then |
| 106 | printf 'FAIL!!!\n' |
| 107 | printf '%s\n' "$_checktest_diff" |
| 108 | err_exit "$_checktest_d failed test $_checktest_name" 1 |
| 109 | fi |
| 110 | } |
| 111 | |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 112 | die() { |
| 113 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 114 | _die_d="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 115 | shift |
| 116 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 117 | _die_msg="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 118 | shift |
| 119 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 120 | _die_name="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 121 | shift |
| 122 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 123 | _die_err="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 124 | shift |
| 125 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 126 | _die_str=$(printf '\n%s %s on test:\n\n %s\n' "$_die_d" "$_die_msg" "$_die_name") |
Gavin Howard | 8237f80 | 2019-04-11 12:23:03 -0600 | [diff] [blame] | 127 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 128 | err_exit "$_die_str" "$_die_err" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | checkcrash() { |
| 132 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 133 | _checkcrash_d="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 134 | shift |
| 135 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 136 | _checkcrash_error="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 137 | shift |
| 138 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 139 | _checkcrash_name="$1" |
| 140 | shift |
| 141 | |
| 142 | if [ "$_checkcrash_error" -gt 127 ]; then |
| 143 | die "$_checkcrash_d" "crashed ($_checkcrash_error)" \ |
| 144 | "$_checkcrash_name" "$_checkcrash_error" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 145 | fi |
| 146 | } |
| 147 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 148 | checkerrtest() |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 149 | { |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 150 | _checkerrtest_d="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 151 | shift |
| 152 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 153 | _checkerrtest_error="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 154 | shift |
| 155 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 156 | _checkerrtest_name="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 157 | shift |
| 158 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 159 | _checkerrtest_out="$1" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 160 | shift |
| 161 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 162 | _checkerrtest_exebase="$1" |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 163 | shift |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 164 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 165 | checkcrash "$_checkerrtest_d" "$_checkerrtest_error" "$_checkerrtest_name" |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 166 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 167 | if [ "$_checkerrtest_error" -eq 0 ]; then |
| 168 | die "$_checkerrtest_d" "returned no error" "$_checkerrtest_name" 127 |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 169 | fi |
| 170 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 171 | if [ "$_checkerrtest_error" -eq 100 ]; then |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 172 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 173 | _checkerrtest_output=$(cat "$_checkerrtest_out") |
| 174 | _checkerrtest_fatal_error="Fatal error" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 175 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 176 | if [ "${_checkerrtest_output##*$_checkerrtest_fatal_error*}" ]; then |
| 177 | printf "%s\n" "$_checkerrtest_output" |
| 178 | die "$_checkerrtest_d" "had memory errors on a non-fatal error" \ |
| 179 | "$_checkerrtest_name" "$_checkerrtest_error" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 180 | fi |
| 181 | fi |
| 182 | |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 183 | if [ ! -s "$_checkerrtest_out" ]; then |
| 184 | die "$_checkerrtest_d" "produced no error message" "$_checkerrtest_name" "$_checkerrtest_error" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 185 | fi |
| 186 | |
| 187 | # Display the error messages if not directly running exe. |
| 188 | # This allows the script to print valgrind output. |
Gavin Howard | b0c6bf8 | 2021-01-29 13:02:21 -0700 | [diff] [blame] | 189 | if [ "$_checkerrtest_exebase" != "bc" -a "$_checkerrtest_exebase" != "dc" ]; then |
| 190 | cat "$_checkerrtest_out" |
Gavin Howard | 7c715d6 | 2019-02-20 10:41:08 -0700 | [diff] [blame] | 191 | fi |
| 192 | } |
Gavin Howard | 2425bf2 | 2019-04-08 17:05:45 -0600 | [diff] [blame] | 193 | |
| 194 | substring_replace() { |
| 195 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 196 | _substring_replace_str="$1" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 197 | shift |
Gavin Howard | 2425bf2 | 2019-04-08 17:05:45 -0600 | [diff] [blame] | 198 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 199 | _substring_replace_needle="$1" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 200 | shift |
| 201 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 202 | _substring_replace_replacement="$1" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 203 | shift |
Gavin Howard | 2425bf2 | 2019-04-08 17:05:45 -0600 | [diff] [blame] | 204 | |
Zach van Rijn | 579518c | 2020-01-14 21:56:45 +0000 | [diff] [blame] | 205 | _substring_replace_result=$(printf '%s\n' "$_substring_replace_str" | \ |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 206 | sed -e "s!$_substring_replace_needle!$_substring_replace_replacement!g") |
Gavin Howard | 2425bf2 | 2019-04-08 17:05:45 -0600 | [diff] [blame] | 207 | |
Zach van Rijn | 579518c | 2020-01-14 21:56:45 +0000 | [diff] [blame] | 208 | printf '%s' "$_substring_replace_result" |
Gavin Howard | 2425bf2 | 2019-04-08 17:05:45 -0600 | [diff] [blame] | 209 | } |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 210 | |
| 211 | gen_nlspath() { |
| 212 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 213 | _gen_nlspath_nlspath="$1" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 214 | shift |
| 215 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 216 | _gen_nlspath_locale="$1" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 217 | shift |
| 218 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 219 | _gen_nlspath_execname="$1" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 220 | shift |
| 221 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 222 | _gen_nlspath_char="@" |
| 223 | _gen_nlspath_modifier="${_gen_nlspath_locale#*$_gen_nlspath_char}" |
| 224 | _gen_nlspath_tmplocale="${_gen_nlspath_locale%%$_gen_nlspath_char*}" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 225 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 226 | _gen_nlspath_char="." |
| 227 | _gen_nlspath_charset="${_gen_nlspath_tmplocale#*$_gen_nlspath_char}" |
| 228 | _gen_nlspath_tmplocale="${_gen_nlspath_tmplocale%%$_gen_nlspath_char*}" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 229 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 230 | if [ "$_gen_nlspath_charset" = "$_gen_nlspath_tmplocale" ]; then |
| 231 | _gen_nlspath_charset="" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 232 | fi |
| 233 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 234 | _gen_nlspath_char="_" |
| 235 | _gen_nlspath_territory="${_gen_nlspath_tmplocale#*$_gen_nlspath_char}" |
| 236 | _gen_nlspath_language="${_gen_nlspath_tmplocale%%$_gen_nlspath_char*}" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 237 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 238 | if [ "$_gen_nlspath_territory" = "$_gen_nlspath_tmplocale" ]; then |
| 239 | _gen_nlspath_territory="" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 240 | fi |
| 241 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 242 | if [ "$_gen_nlspath_language" = "$_gen_nlspath_tmplocale" ]; then |
| 243 | _gen_nlspath_language="" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 244 | fi |
| 245 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 246 | _gen_nlspath_needles="%%:%L:%N:%l:%t:%c" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 247 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 248 | _gen_nlspath_needles=$(printf '%s' "$_gen_nlspath_needles" | tr ':' '\n') |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 249 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 250 | for _gen_nlspath_i in $_gen_nlspath_needles; do |
| 251 | _gen_nlspath_nlspath=$(substring_replace "$_gen_nlspath_nlspath" "$_gen_nlspath_i" "|$_gen_nlspath_i|") |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 252 | done |
| 253 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 254 | _gen_nlspath_nlspath=$(substring_replace "$_gen_nlspath_nlspath" "%%" "%") |
| 255 | _gen_nlspath_nlspath=$(substring_replace "$_gen_nlspath_nlspath" "%L" "$_gen_nlspath_locale") |
| 256 | _gen_nlspath_nlspath=$(substring_replace "$_gen_nlspath_nlspath" "%N" "$_gen_nlspath_execname") |
| 257 | _gen_nlspath_nlspath=$(substring_replace "$_gen_nlspath_nlspath" "%l" "$_gen_nlspath_language") |
| 258 | _gen_nlspath_nlspath=$(substring_replace "$_gen_nlspath_nlspath" "%t" "$_gen_nlspath_territory") |
| 259 | _gen_nlspath_nlspath=$(substring_replace "$_gen_nlspath_nlspath" "%c" "$_gen_nlspath_charset") |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 260 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 261 | _gen_nlspath_nlspath=$(printf '%s' "$_gen_nlspath_nlspath" | tr -d '|') |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 262 | |
Gavin Howard | 62421e9 | 2019-04-17 12:56:30 -0600 | [diff] [blame] | 263 | printf '%s' "$_gen_nlspath_nlspath" |
Gavin Howard | aea5bdb | 2019-04-09 09:01:15 -0600 | [diff] [blame] | 264 | } |