vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

hashcalc.sh (2092B)


      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     for m in md5 sha1 sha256 sha512; do
     55 	sum_0=$($hashcalc "$i" "$m" | tr -d / )
     56 	sum_1=$(${m}sum   "$i" | awk '{ print $1}' )
     57 
     58 	# compare only the first 80 chars as vhashify will cut digest to MAXPATHLEN
     59 	test x"${sum_0::80}" = x"${sum_1::80}" || {
     60 	  echo "$m mismatch at $(basename $i): '$sum_0' vs. '$sum_1'"
     61 	  exit 1
     62 	}
     63     done
     64 done
     65 
     66 true