run-test.sh 10.4 KB
Newer Older
Keith Packard's avatar
Keith Packard committed
1
#!/bin/sh
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# fontconfig/test/run-test.sh
#
# Copyright © 2000 Keith Packard
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of the author(s) not be used in
# advertising or publicity pertaining to distribution of the software without
# specific, written prior permission.  The authors make no
# representations about the suitability of this software for any purpose.  It
# is provided "as is" without express or implied warranty.
#
# THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
# EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
23 24 25 26
case "$OSTYPE" in
    msys ) MyPWD=`pwd -W` ;;  # On Msys/MinGW, returns a MS Windows style path.
    *    ) MyPWD=`pwd`    ;;  # On any other platforms, returns a Unix style path.
esac
27

28
TESTDIR=${srcdir-"$MyPWD"}
29
BUILDTESTDIR=${builddir-"$MyPWD"}
30

31 32 33
BASEDIR=`mktemp -d --tmpdir fontconfig.XXXXXXXX`
FONTDIR="$BASEDIR"/fonts
CACHEDIR="$BASEDIR"/cache.dir
34
EXPECTED=${EXPECTED-"out.expected"}
Keith Packard's avatar
Keith Packard committed
35 36 37

ECHO=true

38 39
FCLIST="$LOG_COMPILER ../fc-list/fc-list$EXEEXT"
FCCACHE="$LOG_COMPILER ../fc-cache/fc-cache$EXEEXT"
Keith Packard's avatar
Keith Packard committed
40

41 42 43 44 45
which bwrap > /dev/null 2>&1
if [ $? -eq 0 ]; then
    BWRAP=`which bwrap`
fi

46 47 48
FONT1=$TESTDIR/4x6.pcf
FONT2=$TESTDIR/8x16.pcf

Keith Packard's avatar
Keith Packard committed
49 50 51 52 53 54
check () {
  $FCLIST - family pixelsize | sort > out
  echo "=" >> out
  $FCLIST - family pixelsize | sort >> out
  echo "=" >> out
  $FCLIST - family pixelsize | sort >> out
55
  tr -d '\015' <out >out.tmp; mv out.tmp out
56
  if cmp out $BUILDTESTDIR/$EXPECTED > /dev/null ; then : ; else
Keith Packard's avatar
Keith Packard committed
57
    echo "*** Test failed: $TEST"
58
    echo "*** output is in 'out', expected output in '$EXPECTED'"
59
    exit 1
Keith Packard's avatar
Keith Packard committed
60
  fi
Akira TAGOH's avatar
Akira TAGOH committed
61
  rm -f out
Keith Packard's avatar
Keith Packard committed
62 63 64
}

prep() {
65
  rm -rf $CACHEDIR
Keith Packard's avatar
Keith Packard committed
66 67 68 69 70 71 72 73 74 75
  rm -rf $FONTDIR
  mkdir $FONTDIR
}

dotest () {
  TEST=$1
  test x$VERBOSE = x || echo Running: $TEST
}

sed "s!@FONTDIR@!$FONTDIR!
Akira TAGOH's avatar
Akira TAGOH committed
76
s!@REMAPDIR@!!
77
s!@CACHEDIR@!$CACHEDIR!" < $TESTDIR/fonts.conf.in > fonts.conf
Keith Packard's avatar
Keith Packard committed
78

79
FONTCONFIG_FILE="$MyPWD"/fonts.conf
Keith Packard's avatar
Keith Packard committed
80 81 82 83
export FONTCONFIG_FILE

dotest "Basic check"
prep
84
cp $FONT1 $FONT2 $FONTDIR
Keith Packard's avatar
Keith Packard committed
85 86 87 88
check

dotest "With a subdir"
prep
89
cp $FONT1 $FONT2 $FONTDIR
Keith Packard's avatar
Keith Packard committed
90 91 92 93 94 95
$FCCACHE $FONTDIR
check

dotest "Subdir with a cache file"
prep
mkdir $FONTDIR/a
96
cp $FONT1 $FONT2 $FONTDIR/a
Keith Packard's avatar
Keith Packard committed
97 98 99 100 101 102 103 104 105
$FCCACHE $FONTDIR/a
check

dotest "Complicated directory structure"
prep
mkdir $FONTDIR/a
mkdir $FONTDIR/a/a
mkdir $FONTDIR/b
mkdir $FONTDIR/b/a
106 107
cp $FONT1 $FONTDIR/a
cp $FONT2 $FONTDIR/b/a
Keith Packard's avatar
Keith Packard committed
108 109 110 111 112 113 114
check

dotest "Subdir with an out-of-date cache file"
prep
mkdir $FONTDIR/a
$FCCACHE $FONTDIR/a
sleep 1
115
cp $FONT1 $FONT2 $FONTDIR/a
Keith Packard's avatar
Keith Packard committed
116 117 118 119
check

dotest "Dir with an out-of-date cache file"
prep
120
cp $FONT1 $FONTDIR
Keith Packard's avatar
Keith Packard committed
121 122 123
$FCCACHE $FONTDIR
sleep 1
mkdir $FONTDIR/a
124
cp $FONT2 $FONTDIR/a
Keith Packard's avatar
Keith Packard committed
125 126
check

127 128 129 130 131 132 133 134 135 136 137 138 139
dotest "Keep mtime of the font directory"
prep
cp $FONT1 $FONTDIR
touch -d @0 $FONTDIR
stat $FONTDIR | grep Modify > out1
$FCCACHE $FONTDIR
stat $FONTDIR | grep Modify > out2
if cmp out1 out2 > /dev/null ; then : ; else
    echo "*** Test failed: $TEST"
    echo "mtime was modified"
    exit 1
fi

140
if [ x"$BWRAP" != "x" -a "x$EXEEXT" = "x" ]; then
141 142 143 144 145 146 147 148
dotest "Basic functionality with the bind-mounted cache dir"
prep
cp $FONT1 $FONT2 $FONTDIR
$FCCACHE $FONTDIR
sleep 1
ls -l $CACHEDIR > out1
TESTTMPDIR=`mktemp -d /tmp/fontconfig.XXXXXXXX`
sed "s!@FONTDIR@!$TESTTMPDIR/fonts!
Akira TAGOH's avatar
Akira TAGOH committed
149
s!@REMAPDIR@!<remap-dir as-path="'"'"$FONTDIR"'"'">$TESTTMPDIR/fonts</remap-dir>!
150
s!@CACHEDIR@!$TESTTMPDIR/cache.dir!" < $TESTDIR/fonts.conf.in > bind-fonts.conf
151
$BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/fc-match/fc-match$EXEEXT -f "%{file}\n" ":foundry=Misc" > xxx
152 153
$BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/test/test-bz106618$EXEEXT | sort > flist1
$BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev find $TESTTMPDIR/fonts/ -type f -name '*.pcf' | sort > flist2
Akira TAGOH's avatar
Akira TAGOH committed
154 155 156 157
ls -l $CACHEDIR > out2
if cmp out1 out2 > /dev/null ; then : ; else
  echo "*** Test failed: $TEST"
  echo "cache was created/updated."
158 159 160 161
  echo "Before:"
  cat out1
  echo "After:"
  cat out2
Akira TAGOH's avatar
Akira TAGOH committed
162 163
  exit 1
fi
164 165
if [ x`cat xxx` != "x$TESTTMPDIR/fonts/4x6.pcf" ]; then
  echo "*** Test failed: $TEST"
166
  echo "file property doesn't point to the new place: $TESTTMPDIR/fonts/4x6.pcf"
167 168
  exit 1
fi
169 170 171 172 173 174 175 176 177 178
if cmp flist1 flist2 > /dev/null ; then : ; else
  echo "*** Test failed: $TEST"
  echo "file properties doesn't point to the new places"
  echo "Expected result:"
  cat flist2
  echo "Actual result:"
  cat flist1
  exit 1
fi
rm -rf $TESTTMPDIR out1 out2 xxx flist1 flist2 bind-fonts.conf
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225

dotest "Different directory content between host and sandbox"
prep
cp $FONT1 $FONTDIR
$FCCACHE $FONTDIR
sleep 1
ls -1 --color=no $CACHEDIR/*cache*> out1
stat -c '%n %s %y %z' `cat out1` > stat1
TESTTMPDIR=`mktemp -d /tmp/fontconfig.XXXXXXXX`
TESTTMP2DIR=`mktemp -d /tmp/fontconfig.XXXXXXXX`
cp $FONT2 $TESTTMP2DIR
sed "s!@FONTDIR@!$TESTTMPDIR/fonts</dir><dir salt="'"'"salt-to-make-different"'"'">$FONTDIR!
s!@REMAPDIR@!<remap-dir as-path="'"'"$FONTDIR"'"'">$TESTTMPDIR/fonts</remap-dir>!
s!@CACHEDIR@!$TESTTMPDIR/cache.dir!" < $TESTDIR/fonts.conf.in > bind-fonts.conf
$BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind $TESTTMP2DIR $FONTDIR --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/fc-match/fc-match$EXEEXT -f "%{file}\n" ":foundry=Misc" > xxx
$BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind $TESTTMP2DIR $FONTDIR --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/test/test-bz106618$EXEEXT | sort > flist1
$BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind $TESTTMP2DIR $FONTDIR --bind .. $TESTTMPDIR/build --dev-bind /dev /dev find $TESTTMPDIR/fonts/ -type f -name '*.pcf' | sort > flist2
ls -1 --color=no $CACHEDIR/*cache* > out2
stat -c '%n %s %y %z' `cat out1` > stat2
if cmp stat1 stat2 > /dev/null ; then : ; else
  echo "*** Test failed: $TEST"
  echo "cache was created/updated."
  cat stat1 stat2
  exit 1
fi
if grep -v -- "`cat out1`" out2 > /dev/null ; then : ; else
  echo "*** Test failed: $TEST"
  echo "cache wasn't created for dir inside sandbox."
  cat out1 out2
  exit 1
fi
if [ x`cat xxx` != "x$TESTTMPDIR/fonts/4x6.pcf" ]; then
  echo "*** Test failed: $TEST"
  echo "file property doesn't point to the new place: $TESTTMPDIR/fonts/4x6.pcf"
  exit 1
fi
if cmp flist1 flist2 > /dev/null ; then
  echo "*** Test failed: $TEST"
  echo "Missing fonts should be available on sandbox"
  echo "Expected result:"
  cat flist2
  echo "Actual result:"
  cat flist1
  exit 1
fi
rm -rf $TESTTMPDIR $TESTTMP2DIR out1 out2 xxx flist1 flist2 stat1 stat2 bind-fonts.conf

226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
dotest "Check consistency of MD5 in cache name"
prep
mkdir -p $FONTDIR/sub
cp $FONT1 $FONTDIR/sub
$FCCACHE $FONTDIR
sleep 1
(cd $CACHEDIR; ls -1 --color=no *cache*) > out1
TESTTMPDIR=`mktemp -d /tmp/fontconfig.XXXXXXXX`
mkdir -p $TESTTMPDIR/cache.dir
sed "s!@FONTDIR@!$TESTTMPDIR/fonts!
s!@REMAPDIR@!<remap-dir as-path="'"'"$FONTDIR"'"'">$TESTTMPDIR/fonts</remap-dir>!
s!@CACHEDIR@!$TESTTMPDIR/cache.dir!" < $TESTDIR/fonts.conf.in > bind-fonts.conf
$BWRAP --bind / / --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/fc-cache/fc-cache$EXEEXT $TESTTMPDIR/fonts
(cd $TESTTMPDIR/cache.dir; ls -1 --color=no *cache*) > out2
if cmp out1 out2 > /dev/null ; then : ; else
    echo "*** Test failed: $TEST"
    echo "cache was created unexpectedly."
    echo "Before:"
    cat out1
    echo "After:"
    cat out2
    exit 1
248
fi
249 250
rm -rf $TESTTMPDIR out1 out2 bind-fonts.conf

251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
dotest "Fallback to uuid"
prep
cp $FONT1 $FONTDIR
touch -d @`stat -c %Y $FONTDIR` $FONTDIR
$FCCACHE $FONTDIR
sleep 1
_cache=`ls -1 --color=no $CACHEDIR/*cache*`
_mtime=`stat -c %Y $FONTDIR`
_uuid=`uuidgen`
_newcache=`echo $_cache | sed "s/\([0-9a-f]*\)\(\-.*\)/$_uuid\2/"`
mv $_cache $_newcache
echo $_uuid > $FONTDIR/.uuid
touch -d @$_mtime $FONTDIR
(cd $CACHEDIR; ls -1 --color=no *cache*) > out1
TESTTMPDIR=`mktemp -d /tmp/fontconfig.XXXXXXXX`
mkdir -p $TESTTMPDIR/cache.dir
sed "s!@FONTDIR@!$TESTTMPDIR/fonts!
s!@REMAPDIR@!<remap-dir as-path="'"'"$FONTDIR"'"'">$TESTTMPDIR/fonts</remap-dir>!
s!@CACHEDIR@!$TESTTMPDIR/cache.dir!" < $TESTDIR/fonts.conf.in > bind-fonts.conf
$BWRAP --bind / / --bind $CACHEDIR $TESTTMPDIR/cache.dir --bind $FONTDIR $TESTTMPDIR/fonts --bind .. $TESTTMPDIR/build --dev-bind /dev /dev --setenv FONTCONFIG_FILE $TESTTMPDIR/build/test/bind-fonts.conf $TESTTMPDIR/build/fc-match/fc-match$EXEEXT -f ""
(cd $CACHEDIR; ls -1 --color=no *cache*) > out2
if cmp out1 out2 > /dev/null ; then : ; else
    echo "*** Test failed: $TEST"
    echo "cache was created unexpectedly."
    echo "Before:"
    cat out1
    echo "After:"
    cat out2
    exit 1
fi
rm -rf $TESTTMPDIR out1 out2 bind-fonts.conf

283 284 285
else
    echo "No bubblewrap installed. skipping..."
fi # if [ x"$BWRAP" != "x" -a "x$EXEEXT" = "x" ]
286

287
if [ "x$EXEEXT" = "x" ]; then
288 289 290 291
dotest "sysroot option"
prep
mkdir -p $MyPWD/sysroot/$FONTDIR
mkdir -p $MyPWD/sysroot/$CACHEDIR
292
mkdir -p $MyPWD/sysroot/$MyPWD
293 294 295 296
cp $FONT1 $MyPWD/sysroot/$FONTDIR
cp $MyPWD/fonts.conf $MyPWD/sysroot/$MyPWD/fonts.conf
$FCCACHE -y $MyPWD/sysroot

297 298 299 300
dotest "creating cache file on sysroot"
md5=`echo -n $FONTDIR | md5sum | sed 's/ .*$//'`
echo "checking for cache file $md5"
ls "$MyPWD/sysroot/$CACHEDIR/$md5"*
301 302
if [ $? != 0 ]; then
  echo "*** Test failed: $TEST"
303
  echo "No cache for $FONTDIR ($md5)"
304 305 306 307 308 309
  ls $MyPWD/sysroot/$CACHEDIR
  exit 1
fi

rm -rf $MyPWD/sysroot

310 311
fi # if [ "x$EXEEXT" = "x" ]

312
rm -rf $FONTDIR $CACHEFILE $CACHEDIR $BASEDIR $FONTCONFIG_FILE out