merge with 0.30.213
[util-vserver.git] / src / testsuite / hashcalc.sh
1 #! /bin/bash
2
3 # Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
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; version 2 of the License.
8 #  
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #  
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 : ${srcdir=.}
19 : ${builddir=.}
20 : ${srctestsuitedir=$srcdir/src/testsuite}
21 : ${srcdatadir=$srctestsuitedir/data}
22 : ${tmptopdir=/var/tmp}
23 : ${hashcalc:=$builddir/src/testsuite/hashcalc}
24
25 set -e
26
27 tmpdir=$(mktemp -d "$tmptopdir"/rpm-fake-test.XXXXXX)
28 trap "rm -rf $tmpdir" EXIT
29
30 ## Usage: createRandFile <name> <size>
31 function createRandFile
32 {
33     dd if=/dev/urandom of=$tmpdir/$1-$2 bs=$2 count=1 &>/dev/null
34 }
35
36 pg=$(getconf PAGESIZE)
37
38 for i in 2 4 8 15 16 23 42 32 64 68 $pg $[ pg+42 ] $[ pg*2 ] \
39          $[ pg*2-23 ] $[ pg*23+42 ]; do
40     createRandFile rand $[ i - 1 ]
41     createRandFile rand $i
42     createRandFile rand $[ i + 1 ]
43 done
44
45 : > $tmpdir/rand-0
46
47 test x"$ensc_use_expensive_tests" != xyes || {
48     dd if=/dev/urandom of=$tmpdir/rand-LARGE1 bs=$[ pg-1 ]        count=1 seek=124123
49     dd if=/dev/urandom of=$tmpdir/rand-LARGE2 bs=$[ 1024*1024-1 ] count=1 seek=5003
50     #dd if=/dev/urandom of=$tmpdir/rand-LARGE3 bs=$[ pg-1 ] count=1 seek=12412373
51 } &>/dev/null
52
53 for i in $tmpdir/rand-*; do
54     sha1_0=$($hashcalc "$i" SHA-1 | tr -d / )
55     sha1_1=$(sha1sum   "$i" | awk '{ print $1}' )
56
57     test x"$sha1_0" = x"$sha1_1" || {
58         echo "SHA-1 mismatch at $(basename $i)"
59         exit 1
60     }
61
62     md5_0=$($hashcalc "$i" MD5  | tr -d / )
63     md5_1=$(md5sum   "$i" | awk '{ print $1}' )
64
65     test x"$md5_0" = x"$md5_1" || {
66         echo "MD5 mismatch at $(basename $i)"
67         exit 1
68     }
69 done
70
71 true