| 1 | # This file is sourced by init.sh, *before* its initialization.
|
|---|
| 2 |
|
|---|
| 3 | # Copyright (C) 2010-2022 Free Software Foundation, Inc.
|
|---|
| 4 |
|
|---|
| 5 | # This program is free software: you can redistribute it and/or modify
|
|---|
| 6 | # it under the terms of the GNU General Public License as published by
|
|---|
| 7 | # the Free Software Foundation, either version 3 of the License, or
|
|---|
| 8 | # (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | # This program is distributed in the hope that it will be useful,
|
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 13 | # GNU General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | # You should have received a copy of the GNU General Public License
|
|---|
| 16 | # along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|---|
| 17 |
|
|---|
| 18 | # This goes hand in hand with the "exec 9>&2;" in tests/Makefile.am's
|
|---|
| 19 | # TESTS_ENVIRONMENT definition.
|
|---|
| 20 | stderr_fileno_=9
|
|---|
| 21 |
|
|---|
| 22 | # Skip the current test if valgrind doesn't work,
|
|---|
| 23 | # which could happen if not installed,
|
|---|
| 24 | # or hasn't support for the built architecture,
|
|---|
| 25 | # or hasn't appropriate error suppressions installed etc.
|
|---|
| 26 | # or the program under test was compiled with address sanitizer.
|
|---|
| 27 | require_valgrind_()
|
|---|
| 28 | {
|
|---|
| 29 | valgrind --error-exitcode=1 true 2>/dev/null ||
|
|---|
| 30 | skip_ "requires a working valgrind"
|
|---|
| 31 |
|
|---|
| 32 | # We cannot apply valgrind to an ASAN-enabled executable.
|
|---|
| 33 | # An ASAN-enabled binary will print this on the first line of
|
|---|
| 34 | # its help output: Available flags for AddressSanitizer:
|
|---|
| 35 | ASAN_OPTIONS=help=1 sed qq 2>&1 | grep AddressSanitizer: \
|
|---|
| 36 | && skip_ 'ASAN enabled binary cannot work with valgrind'
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | # Call this with a list of programs under test immediately after
|
|---|
| 40 | # sourcing init.sh.
|
|---|
| 41 | print_ver_()
|
|---|
| 42 | {
|
|---|
| 43 | if test "$VERBOSE" = yes; then
|
|---|
| 44 | local i
|
|---|
| 45 | for i in $*; do
|
|---|
| 46 | env $i --version
|
|---|
| 47 | done
|
|---|
| 48 | fi
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | # Some tests would fail without this particular locale.
|
|---|
| 52 | # If the locale is not available, just skip the test.
|
|---|
| 53 | require_en_utf8_locale_()
|
|---|
| 54 | {
|
|---|
| 55 | path_prepend_ ./testsuite
|
|---|
| 56 | case $(get-mb-cur-max en_US.UTF-8) in
|
|---|
| 57 | [3456]) ;;
|
|---|
| 58 | *) skip_ 'en_US.UTF-8 locale not found' ;;
|
|---|
| 59 | esac
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | # Some tests would fail without this particular locale.
|
|---|
| 63 | # If the locale is not available, just skip the test.
|
|---|
| 64 | require_ru_utf8_locale_()
|
|---|
| 65 | {
|
|---|
| 66 | path_prepend_ ./testsuite
|
|---|
| 67 | case $(get-mb-cur-max ru_RU.UTF-8) in
|
|---|
| 68 | [3456]) ;;
|
|---|
| 69 | *) skip_ 'ru_RU.UTF-8 locale not found' ;;
|
|---|
| 70 | esac
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | require_el_iso88597_locale_()
|
|---|
| 74 | {
|
|---|
| 75 | path_prepend_ ./testsuite
|
|---|
| 76 | case $(get-mb-cur-max el_GR.iso88597) in
|
|---|
| 77 | 1) ;;
|
|---|
| 78 | *) skip_ 'el_GR.iso88597 locale not found' ;;
|
|---|
| 79 | esac
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | # Some tests would fail without this particular locale.
|
|---|
| 83 | # If the locale is not available, just skip the test.
|
|---|
| 84 | # The exact spelling differs between operating systems
|
|---|
| 85 | # (ja_JP.shiftjis on Ubuntu, ja_JP.sjis on Debian, ja_JP.SJIS on Mac OS X).
|
|---|
| 86 | # If a sjift-jis locale is found the function sets shell variable
|
|---|
| 87 | # 'LOCALE_JA_SJIS' to the locale name.
|
|---|
| 88 | require_ja_shiftjis_locale_()
|
|---|
| 89 | {
|
|---|
| 90 | path_prepend_ ./testsuite
|
|---|
| 91 | LOCALE_JA_SJIS=
|
|---|
| 92 | for l in shiftjis sjis SJIS ; do
|
|---|
| 93 | n=$(get-mb-cur-max ja_JP.$l) || continue
|
|---|
| 94 | test 2 -eq "$n" || continue
|
|---|
| 95 | LOCALE_JA_SJIS="ja_JP.$l"
|
|---|
| 96 | break
|
|---|
| 97 | done
|
|---|
| 98 | test -z "$LOCALE_JA_SJIS" && skip_ 'ja_JP shift-jis locale not found'
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | # Ensure the implementation of mbrtowc can detect invalid
|
|---|
| 102 | # multibyte shiftjis sequences. Otherwise, skip the test, to avoid
|
|---|
| 103 | # false-alarms.
|
|---|
| 104 | # "$1" should be the name of the SHIFT-JIS locale
|
|---|
| 105 | # (as set by 'require_ja_shiftjis_locale_' above)
|
|---|
| 106 | require_valid_ja_shiftjis_locale_()
|
|---|
| 107 | {
|
|---|
| 108 | path_prepend_ ./testsuite
|
|---|
| 109 | local n=$(printf '\203:' | LC_ALL="$1" test-mbrtowc)
|
|---|
| 110 | test "x$n" = "x-2,-1" || skip_ "locale '$1' is buggy"
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | # Ensure the implementation of mbrtowc can detect invalid
|
|---|
| 114 | # multibyte eucJP sequences. Otherwise, skip the test, to avoid
|
|---|
| 115 | # false-alarms.
|
|---|
| 116 | # "$1" should be the name of the ja_JP.eucJP locale
|
|---|
| 117 | # (as set in $LOCALE_JA by m4/locale-ja.m4)
|
|---|
| 118 | require_valid_ja_eucjp_locale_()
|
|---|
| 119 | {
|
|---|
| 120 | path_prepend_ .
|
|---|
| 121 | local n=$(printf '\262C' | LC_ALL="$1" test-mbrtowc)
|
|---|
| 122 | test "x$n" = "x-2,-1" || skip_ "locale '$1' is buggy"
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | # When testing on a Windows machine, sed might output
|
|---|
| 126 | # line endings as CR,LF (\r\n) pairs - which will
|
|---|
| 127 | # then fail comparison with the expected output files.
|
|---|
| 128 | #
|
|---|
| 129 | # This function removes the CR (\r) characters from the given input file.
|
|---|
| 130 | remove_cr_inplace()
|
|---|
| 131 | {
|
|---|
| 132 | sed -i -e "s/\r//g" "$@" || framework_failure_
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | require_selinux_()
|
|---|
| 136 | {
|
|---|
| 137 | # When in a chroot of an SELinux-enabled system, but with a mock-simulated
|
|---|
| 138 | # SELinux-*disabled* system, recognize that SELinux is disabled system wide:
|
|---|
| 139 | grep 'selinuxfs$' /proc/filesystems > /dev/null \
|
|---|
| 140 | || skip_ "this system lacks SELinux support"
|
|---|
| 141 |
|
|---|
| 142 | # Independent of whether SELinux is enabled system-wide,
|
|---|
| 143 | # the current file system may lack SELinux support.
|
|---|
| 144 | # Also the current build may have SELinux support disabled.
|
|---|
| 145 | case $(ls -Zd .) in
|
|---|
| 146 | '? .'|'unlabeled .')
|
|---|
| 147 | test -z "$CONFIG_HEADER" \
|
|---|
| 148 | && framework_failure_ 'CONFIG_HEADER not defined'
|
|---|
| 149 | grep '^#define HAVE_SELINUX_SELINUX_H 1' "$CONFIG_HEADER" > /dev/null \
|
|---|
| 150 | && selinux_missing_="(file) system" || selinux_missing_="build"
|
|---|
| 151 | skip_ "this $selinux_missing_ lacks SELinux support"
|
|---|
| 152 | ;;
|
|---|
| 153 | esac
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | very_expensive_()
|
|---|
| 157 | {
|
|---|
| 158 | if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
|
|---|
| 159 | skip_ 'very expensive: disabled by default
|
|---|
| 160 | This test is very expensive, so it is disabled by default.
|
|---|
| 161 | To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
|
|---|
| 162 | environment variable set to yes. E.g.,
|
|---|
| 163 |
|
|---|
| 164 | env RUN_VERY_EXPENSIVE_TESTS=yes make check
|
|---|
| 165 |
|
|---|
| 166 | or use the shortcut target of the toplevel Makefile,
|
|---|
| 167 |
|
|---|
| 168 | make check-very-expensive
|
|---|
| 169 | '
|
|---|
| 170 | fi
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | expensive_()
|
|---|
| 174 | {
|
|---|
| 175 | if test "$RUN_EXPENSIVE_TESTS" != yes; then
|
|---|
| 176 | skip_ 'expensive: disabled by default
|
|---|
| 177 | This test is relatively expensive, so it is disabled by default.
|
|---|
| 178 | To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
|
|---|
| 179 | environment variable set to yes. E.g.,
|
|---|
| 180 |
|
|---|
| 181 | env RUN_EXPENSIVE_TESTS=yes make check
|
|---|
| 182 |
|
|---|
| 183 | or use the shortcut target of the toplevel Makefile,
|
|---|
| 184 |
|
|---|
| 185 | make check-expensive
|
|---|
| 186 | '
|
|---|
| 187 | fi
|
|---|
| 188 | }
|
|---|