summaryrefslogtreecommitdiff
path: root/init.cfg
blob: e5230943512552f975ba39adf8f43e33523ca2ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# This file is sourced by init.sh, *before* its initialization.

# Copyright (C) 2010-2023 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# This goes hand in hand with the "exec 9>&2;" in tests/Makefile.am's
# TESTS_ENVIRONMENT definition.
stderr_fileno_=9

# Skip the current test if valgrind doesn't work,
# which could happen if not installed,
# or hasn't support for the built architecture,
# or hasn't appropriate error suppressions installed etc.
# or the program under test was compiled with address sanitizer.
require_valgrind_()
{
  valgrind --error-exitcode=1 true 2>/dev/null ||
    skip_ "requires a working valgrind"

  # We cannot apply valgrind to an ASAN-enabled executable.
  # An ASAN-enabled binary will print this on the first line of
  # its help output: Available flags for AddressSanitizer:
  ASAN_OPTIONS=help=1 sed qq 2>&1 | grep AddressSanitizer: \
    && skip_ 'ASAN enabled binary cannot work with valgrind'
}

# Call this with a list of programs under test immediately after
# sourcing init.sh.
print_ver_()
{
  if test "$VERBOSE" = yes; then
    local i
    for i in $*; do
      env $i --version
    done
  fi
}

# Some tests would fail without this particular locale.
# If the locale is not available, just skip the test.
require_en_utf8_locale_()
{
  path_prepend_ ./testsuite
  case $(get-mb-cur-max en_US.UTF-8) in
    [3456]) ;;
    *) skip_ 'en_US.UTF-8 locale not found' ;;
  esac
}

# Some tests would fail without this particular locale.
# If the locale is not available, just skip the test.
require_ru_utf8_locale_()
{
  path_prepend_ ./testsuite
  case $(get-mb-cur-max ru_RU.UTF-8) in
    [3456]) ;;
    *) skip_ 'ru_RU.UTF-8 locale not found' ;;
  esac
}

require_el_iso88597_locale_()
{
  path_prepend_ ./testsuite
  case $(get-mb-cur-max el_GR.iso88597) in
    1) ;;
    *) skip_ 'el_GR.iso88597 locale not found' ;;
  esac
}

# Some tests would fail without this particular locale.
# If the locale is not available, just skip the test.
# The exact spelling differs between operating systems
# (ja_JP.shiftjis on Ubuntu, ja_JP.sjis on Debian, ja_JP.SJIS on Mac OS X).
# If a sjift-jis locale is found the function sets shell variable
# 'LOCALE_JA_SJIS' to the locale name.
require_ja_shiftjis_locale_()
{
  path_prepend_ ./testsuite
  LOCALE_JA_SJIS=
  for l in shiftjis sjis SJIS ; do
      n=$(get-mb-cur-max ja_JP.$l) || continue
      test 2 -eq "$n" || continue
      LOCALE_JA_SJIS="ja_JP.$l"
      break
  done
  test -z "$LOCALE_JA_SJIS" && skip_ 'ja_JP shift-jis locale not found'
}

# Ensure the implementation of mbrtowc can detect invalid
# multibyte shiftjis sequences. Otherwise, skip the test, to avoid
# false-alarms.
# "$1" should be the name of the SHIFT-JIS locale
# (as set by 'require_ja_shiftjis_locale_' above)
require_valid_ja_shiftjis_locale_()
{
  path_prepend_ ./testsuite
  local n=$(printf '\203:' | LC_ALL="$1" test-mbrtowc)
  test "x$n" = "x-2,-1" || skip_ "locale '$1' is buggy"
}

# Ensure the implementation of mbrtowc can detect invalid
# multibyte eucJP sequences. Otherwise, skip the test, to avoid
# false-alarms.
# "$1" should be the name of the ja_JP.eucJP locale
# (as set in $LOCALE_JA by m4/locale-ja.m4)
require_valid_ja_eucjp_locale_()
{
  path_prepend_ .
  local n=$(printf '\262C' | LC_ALL="$1" test-mbrtowc)
  test "x$n" = "x-2,-1" || skip_ "locale '$1' is buggy"
}

# When testing on a Windows machine, sed might output
# line endings as CR,LF (\r\n) pairs - which will
# then fail comparison with the expected output files.
#
# This function removes the CR (\r) characters from the given input file.
remove_cr_inplace()
{
  sed -i -e "s/\r//g" "$@" || framework_failure_
}

require_selinux_()
{
  # When in a chroot of an SELinux-enabled system, but with a mock-simulated
  # SELinux-*disabled* system, recognize that SELinux is disabled system wide:
  grep 'selinuxfs$' /proc/filesystems > /dev/null \
    || skip_ "this system lacks SELinux support"

  # Independent of whether SELinux is enabled system-wide,
  # the current file system may lack SELinux support.
  # Also the current build may have SELinux support disabled.
  case $(ls -Zd .) in
    '? .'|'unlabeled .')
      test -z "$CONFIG_HEADER" \
        && framework_failure_ 'CONFIG_HEADER not defined'
      grep '^#define HAVE_SELINUX_SELINUX_H 1' "$CONFIG_HEADER" > /dev/null \
        && selinux_missing_="(file) system" || selinux_missing_="build"
      skip_ "this $selinux_missing_ lacks SELinux support"
    ;;
  esac
}

very_expensive_()
{
  if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
    skip_ 'very expensive: disabled by default
This test is very expensive, so it is disabled by default.
To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
environment variable set to yes.  E.g.,

  env RUN_VERY_EXPENSIVE_TESTS=yes make check

or use the shortcut target of the toplevel Makefile,

  make check-very-expensive
'
  fi
}

expensive_()
{
  if test "$RUN_EXPENSIVE_TESTS" != yes; then
    skip_ 'expensive: disabled by default
This test is relatively expensive, so it is disabled by default.
To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
environment variable set to yes.  E.g.,

  env RUN_EXPENSIVE_TESTS=yes make check

or use the shortcut target of the toplevel Makefile,

  make check-expensive
'
  fi
}