]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconvdata/run-iconv-test.sh
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / iconvdata / run-iconv-test.sh
CommitLineData
48d0341c 1#!/bin/sh -f
480bc727 2# Run available iconv(1) tests.
04277e02 3# Copyright (C) 1998-2019 Free Software Foundation, Inc.
480bc727
UD
4# This file is part of the GNU C Library.
5# Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
41bdb6e2 6
480bc727 7# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
8# modify it under the terms of the GNU Lesser General Public
9# License as published by the Free Software Foundation; either
10# version 2.1 of the License, or (at your option) any later version.
11
480bc727
UD
12# The GNU C Library is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2
AJ
15# Lesser General Public License for more details.
16
17# You should have received a copy of the GNU Lesser General Public
59ba27a6 18# License along with the GNU C Library; if not, see
5a82c748 19# <https://www.gnu.org/licenses/>.
480bc727 20
57c69bef
DL
21set -e
22
480bc727 23codir=$1
8540f6d2
JM
24test_wrapper_env="$2"
25run_program_env="$3"
480bc727
UD
26
27# We use always the same temporary file.
28temp1=$codir/iconvdata/iconv-test.xxx
29temp2=$codir/iconvdata/iconv-test.yyy
30
31trap "rm -f $temp1 $temp2" 1 2 3 15
32
298f2566
UD
33# We have to have some directories in the library path.
34LIBPATH=$codir:$codir/iconvdata
35
480bc727 36# How the start the iconv(1) program.
b0a01055 37ICONV='$codir/elf/ld.so --library-path $LIBPATH --inhibit-rpath ${from}.so \
310930c1 38 $codir/iconv/iconv_prog'
8540f6d2 39ICONV="$test_wrapper_env $run_program_env $ICONV"
480bc727 40
822078f6
UD
41# Which echo?
42if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
43 ac_n=-n ac_c= ac_t=
44else
45 ac_n= ac_c='\c' ac_t=
46fi
47
480bc727
UD
48# We read the file named TESTS. All non-empty lines not starting with
49# `#' are interpreted as commands.
5aa8ff62
UD
50failed=0
51while read from to subset targets; do
480bc727 52 # Ignore empty and comment lines.
3b7caeac 53 if test -z "$subset" || test "$from" = '#'; then continue; fi
480bc727 54
310930c1
UD
55 # Expand the variables now.
56 PROG=`eval echo $ICONV`
57
3b7caeac
UD
58 if test -n "$targets"; then
59 for t in $targets; do
60 if test -f testdata/$from; then
93693c4d 61 echo $ac_n " test data: $from -> $t $ac_c"
6fb54a22 62 $PROG -f $from -t $t testdata/$from < /dev/null > $temp1 ||
3b7caeac 63 { if test $? -gt 128; then exit 1; fi
93693c4d 64 echo "FAILED"; failed=1; continue; }
3b7caeac
UD
65 echo $ac_n "OK$ac_c"
66 if test -s testdata/$from..$t; then
82ae2712 67 LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 ||
3b7caeac
UD
68 { echo "/FAILED"; failed=1; continue; }
69 echo $ac_n "/OK$ac_c"
70 fi
71 echo $ac_n " -> $from $ac_c"
6fb54a22 72 $PROG -f $t -t $to -o $temp2 $temp1 < /dev/null ||
3b7caeac 73 { if test $? -gt 128; then exit 1; fi
93693c4d 74 echo "FAILED"; failed=1; continue; }
3b7caeac 75 echo $ac_n "OK$ac_c"
82ae2712
UD
76 test -s $temp1 &&
77 LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
3b7caeac
UD
78 { echo "/FAILED"; failed=1; continue; }
79 echo "/OK"
80 rm -f $temp1 $temp2
81 fi
82
83 # Now test some bigger text, entirely in ASCII. If ASCII is no subset
84 # of the coded character set we convert the text to this coded character
85 # set. Otherwise we convert to all the TARGETS.
86 if test $subset = Y; then
93693c4d 87 echo $ac_n " suntzu: $from -> $t -> $to $ac_c"
6fb54a22 88 $PROG -f $from -t $t testdata/suntzus < /dev/null |
3b7caeac
UD
89 $PROG -f $t -t $to > $temp1 ||
90 { if test $? -gt 128; then exit 1; fi
93693c4d 91 echo "FAILED"; failed=1; continue; }
3b7caeac 92 echo $ac_n "OK$ac_c"
82ae2712 93 LC_ALL=C cmp testdata/suntzus $temp1 ||
93693c4d 94 { echo "/FAILED"; failed=1; continue; }
3b7caeac
UD
95 echo "/OK"
96 fi
97 rm -f $temp1
93693c4d
UD
98
99 # And tests where iconv(1) has to handle charmaps.
100 if test "$t" = UTF8; then tc=UTF-8; else tc="$t"; fi
101 if test -f ../localedata/charmaps/$from &&
102 test -f ../localedata/charmaps/$tc &&
faaa6f62
UD
103 test -f testdata/$from &&
104 ! grep '<U....><U....>' ../localedata/charmaps/$from > /dev/null; then
93693c4d
UD
105 echo $ac_n "test charmap: $from -> $t $ac_c"
106 $PROG -f ../localedata/charmaps/$from -t ../localedata/charmaps/$tc \
6fb54a22 107 testdata/$from < /dev/null > $temp1 ||
93693c4d
UD
108 { if test $? -gt 128; then exit 1; fi
109 echo "FAILED"; failed=1; continue; }
110 echo $ac_n "OK$ac_c"
111 if test -s testdata/$from..$t; then
82ae2712 112 LC_ALL=C cmp $temp1 testdata/$from..$t > /dev/null 2>&1 ||
93693c4d
UD
113 { echo "/FAILED"; failed=1; continue; }
114 echo $ac_n "/OK$ac_c"
115 fi
116 echo $ac_n " -> $from $ac_c"
117 $PROG -t ../localedata/charmaps/$from -f ../localedata/charmaps/$tc \
6fb54a22 118 -o $temp2 $temp1 < /dev/null ||
93693c4d
UD
119 { if test $? -gt 128; then exit 1; fi
120 echo "FAILED"; failed=1; continue; }
121 echo $ac_n "OK$ac_c"
82ae2712
UD
122 test -s $temp1 &&
123 LC_ALL=C cmp testdata/$from $temp2 > /dev/null 2>&1 ||
93693c4d
UD
124 { echo "/FAILED"; failed=1; continue; }
125 echo "/OK"
126 rm -f $temp1 $temp2
127 fi
3b7caeac
UD
128 done
129 fi
130
c8d49f05 131 if test "$subset" = N; then
b721a2c0 132 echo $ac_n " suntzu: ASCII -> $to -> ASCII $ac_c"
6fb54a22 133 $PROG -f ASCII -t $to testdata/suntzus < /dev/null |
3b7caeac 134 $PROG -f $to -t ASCII > $temp1 ||
813bb1f1 135 { if test $? -gt 128; then exit 1; fi
93693c4d 136 echo "FAILED"; failed=1; continue; }
822078f6 137 echo $ac_n "OK$ac_c"
82ae2712 138 LC_ALL=C cmp testdata/suntzus $temp1 ||
93693c4d 139 { echo "/FAILED"; failed=1; continue; }
822078f6 140 echo "/OK"
3b7caeac 141 fi
480bc727
UD
142done < TESTS
143
b721a2c0
UD
144# We read the file named TESTS2. All non-empty lines not starting with
145# `#' are interpreted as commands.
146while read utf8 from filename; do
147 # Ignore empty and comment lines.
148 if test -z "$filename" || test "$utf8" = '#'; then continue; fi
149
150 # Expand the variables now.
151 PROG=`eval echo $ICONV`
152
153 # Test conversion to the endianness dependent encoding.
154 echo $ac_n "test encoder: $utf8 -> $from $ac_c"
155 $PROG -f $utf8 -t $from < testdata/${filename}..${utf8} > $temp1
82ae2712
UD
156 LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 ||
157 LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 ||
b721a2c0
UD
158 { echo "/FAILED"; failed=1; continue; }
159 echo "OK"
160
161 # Test conversion from the endianness dependent encoding.
162 echo $ac_n "test decoder: $from -> $utf8 $ac_c"
163 $PROG -f $from -t $utf8 < testdata/${filename}..${from}.BE > $temp1
82ae2712 164 LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 ||
b721a2c0
UD
165 { echo "/FAILED"; failed=1; continue; }
166 $PROG -f $from -t $utf8 < testdata/${filename}..${from}.LE > $temp1
82ae2712 167 LC_ALL=C cmp $temp1 testdata/${filename}..${utf8} > /dev/null 2>&1 ||
b721a2c0
UD
168 { echo "/FAILED"; failed=1; continue; }
169 echo "OK"
170
171 # Test byte swapping behaviour.
172 echo $ac_n "test non-BOM: ${from}BE -> ${from}LE $ac_c"
173 $PROG -f ${from}BE -t ${from}LE < testdata/${filename}..${from}.BE > $temp1
82ae2712 174 LC_ALL=C cmp $temp1 testdata/${filename}..${from}.LE > /dev/null 2>&1 ||
b721a2c0
UD
175 { echo "/FAILED"; failed=1; continue; }
176 echo "OK"
177
178 # Test byte swapping behaviour.
179 echo $ac_n "test non-BOM: ${from}LE -> ${from}BE $ac_c"
180 $PROG -f ${from}LE -t ${from}BE < testdata/${filename}..${from}.LE > $temp1
82ae2712 181 LC_ALL=C cmp $temp1 testdata/${filename}..${from}.BE > /dev/null 2>&1 ||
b721a2c0
UD
182 { echo "/FAILED"; failed=1; continue; }
183 echo "OK"
184
185done < TESTS2
186
41488498
FW
187# Check for crashes in decoders.
188printf '\016\377\377\377\377\377\377\377' > $temp1
189for from in $iconv_modules ; do
190 echo $ac_n "test decoder $from $ac_c"
191 PROG=`eval echo $ICONV`
7d81e8d6 192 if $PROG -f $from -t UTF8 < $temp1 >/dev/null 2>&1 ; then
41488498
FW
193 : # fall through
194 else
195 status=$?
196 if test $status -gt 1 ; then
197 echo "/FAILED"
198 failed=1
199 continue
200 fi
201 fi
202 echo "OK"
203done
204
5aa8ff62 205exit $failed
480bc727
UD
206# Local Variables:
207# mode:shell-script
208# End: