#!/bin/bash #Copyright 2002, William Stearns #Released under the GPL. SuccessCount=0 TestBin="../freedups.pl" if [ -n "$1" ] && [ -f "$1" ] && [ -x "$1" ]; then TestBin="$1" fi echo "Testing $TestBin" LogFile="/usr/src/freedups-work/regression-log" if [ ! -f "$LogFile" ] || [ ! -w "$LogFile" ]; then echo Please create "$LogFile" and make it writable, exiting. exit 1 fi error () { echo echo Failed test: $* if [ -d /usr/src/freedups-work ]; then echo Failed test: $* on `date` >>"$LogFile" if [ -n "$FreeDupsOut" ]; then echo Freedups output: >>"$LogFile" echo "$FreeDupsOut" >>"$LogFile" fi if [ -d workdir ]; then echo Workdir: >>"$LogFile" ls -ali workdir >>"$LogFile" fi fi echo -n -e "\a" >/dev/stderr sleep 1 echo -n -e "\a" >/dev/stderr sleep 1 echo -n -e "\a" >/dev/stderr exit 1 } success () { SuccessCount=$[ $SuccessCount + 1 ] echo -n "$SuccessCount.." } InodeNumOf () { ls -ali "$@" | awk '{print $1}' } #Sample uses: #C2Num="`InodeNumOf /path/to/somefile`" #echo $C2Num #if [ "`InodeNumOf somefile`" = "5155990" ]; then # echo equal #else # echo not #fi [ ! -e workdir ] || error workdir-exists mkdir ./workdir || error making-workdir cd workdir || error cd-to-workdir echo "Test 12 takes a while, please be patient." #Different content, should not be linked echo Hello >file01a echo There >file01b FreeDupsOut=`$TestBin -a file01a file01b 2>&1` if [ file01a -ef file01b ]; then error freedups-diffcon-1 ; fi success #Identical content but no -a, should not be linked echo Hello >file02a echo Hello >file02b FreeDupsOut=`$TestBin file02a file02b 2>&1` if [ file02a -ef file02b ]; then error freedups-dry-run-1 ; fi success #Identical content but filenamesequal=yes, should not be linked FreeDupsOut=`$TestBin -a -f file02a file02b 2>&1` if [ file02a -ef file02b ]; then error freedups-filenameseq-1 ; fi success #Identical content but minsize=6, should not be linked (note: the files are 6 bytes=Hello+linefeed, and minsize=6 => at least 7 bytes before considering) FreeDupsOut=`$TestBin -a -m 6 file02a file02b 2>&1` if [ file02a -ef file02b ]; then error freedups-minsize-1 ; fi success #Identical content, files are 6 bytes large, should be linked FreeDupsOut=`$TestBin -a -m 5 file02a file02b 2>&1` if [ ! file02a -ef file02b ]; then error freedups-samecon-1 ; fi success #Identical content, triplet should be linked echo Hello >file02c FreeDupsOut=`$TestBin -a file02a file02c 2>&1` if [ ! file02b -ef file02c ]; then error freedups-samecon-2 ; fi success #Two pairs of files, all the same size, but not everyone links to everyone. #Checks the bug fixed between 0.6.3 and 0.6.4 by Martin Sheppard. echo Hello >file02d cp -p file02d file02e echo There >file02f cp -p file02f file02g FreeDupsOut=`$TestBin -a file02d file02e file02f file02g 2>&1` if [ ! file02d -ef file02e ] || [ ! file02f -ef file02g ]; then error freedups-samecon-3 ; fi success #Identical files, different dates echo Hello >file03a sleep 2 echo Hello >file03b #-d specified, should not be linked FreeDupsOut=`$TestBin -a -d file03a file03b 2>&1` if [ file03a -ef file03b ]; then error freedups-difftime-1 ; fi success #No -d, now they should be linked FreeDupsOut=`$TestBin -a file03a file03b 2>&1` if [ ! file03a -ef file03b ]; then error freedups-difftime-2 ; fi success echo Hi >file04a echo There >file04b #Different sizes, should not be linked FreeDupsOut=`$TestBin -a file04a file04b 2>&1` if [ file04a -ef file04b ]; then error freedups-diffsize-1 ; fi success #Make sure older file linked to, no matter which specified first on command line echo Hello >file05a echo Hello >file06a sleep 2 echo Hello >file05b echo Hello >file06b FiveInode="`InodeNumOf file05a`" FreeDupsOut=`$TestBin -a file05a file05b 2>&1` if [ "`InodeNumOf file05b`" != "$FiveInode" ]; then error freedups-oldfile-1 ; fi success SixInode="`InodeNumOf file06a`" FreeDupsOut=`$TestBin -a file06b file06a 2>&1` if [ "`InodeNumOf file06b`" != "$SixInode" ]; then error freedups-oldfile-2 ; fi success KernelTar=`ls -A1rt /usr/src/source/kernel/linux-*.tar.bz2 | tail -1` [ -n "$KernelTar" ] || error finding-kernel-tar cat "$KernelTar" | bunzip2 - | tar -xf - || error opening-kernel-tar KernelDir=`ls -A1drt linux* | tail -1` [ -n "$KernelDir" ] || error missing-kernel-dir [ -d "$KernelDir" ] || error kernel-dir-isnt-a-dir cp -a "$KernelDir" "$KernelDir.copy2" || error failed-copy-to-copy2 FreeDupsOut=`$TestBin -a -d "$PWD/$KernelDir" "$PWD/$KernelDir.copy2" 2>&1` if ! diff -qr "$KernelDir" "$KernelDir.copy2" >/dev/null 2>&1; then error freedups-tar-1 ; fi success if [ ! "$KernelDir/README" -ef "$KernelDir.copy2/README" ]; then error freedups-READMES not linked ; fi success if [ ! "$KernelDir/Documentation/00-INDEX" -ef "$KernelDir.copy2/Documentation/00-INDEX" ]; then error freedups-00-INDEX not linked ; fi success #Add: change a file that's in the md5sum cache and make sure it's not linked. #Add: test to make sure more sparse file linked to, no matter which specified first on command line #Add: test to make sure more heavily linked file linked to, no matter which specified first on command line #Add: check how program handles dangling symlink #Add: check that different owners handled correctly #Add: check that different modes handled correctly rm -f file[0-9][0-9][abcdefg] if [ -d "./$KernelDir" ]; then rm -rf "./$KernelDir" fi if [ -d "./$KernelDir.copy2" ]; then rm -rf "./$KernelDir.copy2" fi cd .. || error cd-up rmdir workdir || error rmdir-workdir echo done. echo ---------- Exit with a fanfare ---------- echo `cat $0 | sed -e 's/#.*//' | grep 'error .* fi' | grep -v regression | wc -l` regression tests successful if [ -d /usr/src/freedups-work ]; then date >>"$LogFile" echo `cat $0 | sed -e 's/#.*//' | grep 'error .* fi' | grep -v regression | wc -l` regression tests successful >>"$LogFile" fi exit 0