File: Tester

package info (click to toggle)
lbzip2 2.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,624 kB
  • sloc: ansic: 27,584; sh: 4,306; perl: 154; makefile: 70
file content (46 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download | duplicates (6)
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
#! /bin/sh
# Copyright (C) 2011 Mikolaj Izdebski

set -e -C
IFS=' ''	''
'

test -r "$1"

# Try limiting virtual memory usage to 1 GiB. This can save users of systems
# with memory overcommit enabled and no ulimit set.
ulimit -v $(expr 1024 \* 1024) || :

# Unset variables that may affect behavior of lbzip2.
# (Some shells don't like unsetting variables that are not set.)
LBZIP2= unset LBZIP2
BZIP2=  unset BZIP2
BZIP=   unset BZIP

# Create temp files in current working directory.
bn=$(echo "$1" | sed 's@^\(.*/\)*\([^/.][^/.]*\)\.[^/]*$@\2@')
r1=tmp.$bn.1.$$
r2=tmp.$bn.2.$$

# Run decompressors, temporarly disabling error checking.
set +e
./timeout ./minbzcat <"$1" >$r1 2>/dev/null; rc1=$?
./timeout ../src/lbzip2 -dcqn4 <"$1" >$r2 2>/dev/null; rc2=$?
set -e

# Make sure none of decompressors crashed (exit code >= 128)
test $rc1 -lt 128 -a $rc2 -lt 128

# bad - bad bz2 file according to lbzip2
# xbad - bad bz2 file according to minbzcat (expected bad)
test $rc1 = 0 && xbad= || xbad=1
test $rc2 = 0 &&  bad= ||  bad=1

# pdksh needs whitespace between the two left parentheses.
# dash builtin test needs this redundand quoting before $bad and $xbad,
# see: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=598238
( (test $xbad && test $bad) || (test ! ''$xbad && test ! ''$bad &&
    cmp $r1 $r2 2>/dev/null)) && rc= || rc=1

rm -f $r1 $r2
exit $rc