#!/bin/bash # # Moneymaker Test Script # COMP444, Winter 2005, Serguei Mokhov # # MoneyLoser = MoneyMaker # # $Id: moneymaker-test,v 1.7 2005/03/29 09:21:31 mokhov Exp $ # BASEDIR=base-tests ADVANCEDDIR=advanced-tests NASTYDIR=nasty-tests # # Base # function createBaseTests() { echo -n "Preparing virgin directory structure in [$1]... " rm -rf $1 mkdir -p $1 mkdir -p $1/sub1/subsub1 mkdir -p $1/sub1/subsub2 mkdir -p $1/sub1/subsub3 mkdir -p $1/sub2/subsub1 mkdir -p $1/sub2/subsub2 mkdir -p $1/sub2/subsub3 # Just text files, like ourselves that contain the word "MoNeYlOsEr" cp $0 $1 cp $0 $1/sub2 cp $0 $1/sub1/subsub3 # Binary moneylosers should also be considered ( cat /bin/ls; echo "Moneyloser Corporation"; cat /bin/ps ) > $1/sub1/subsub1/loser.bin cp $1/sub1/subsub1/loser.bin $1/sub1/subsub2 cp $1/sub1/subsub1/loser.bin $1/sub2 # Create a mini-C program with the string in it and compile it: cat > $1/foo.c <<-MINI-C #include int main(void) { printf("Moneyloser Writes Non-ANSI C Programs.\n"); return 0;} MINI-C gcc $1/foo.c -o $1/foo.exe # Some normal files, that should NOT be altered cal > $1/sub1/cal.txt cp /bin/ls $1/sub2/ls.bin # Some non-nasty symlinks ln -s $1/sub1/cal.txt $1/sub2/cal-sym.txt ln -s $1/sub1/subsub1/loser.bin $1/sub2/subsub3/loser-sym.bin ln -s $1/sub2 $1/sub2/subsub1/sub2 echo "Done." # Done preparing directory structure } # # Advanced # function createAdvancedTests() { echo -n "Preparing advanced directory structure in [$1]... " # Some dead symlinks ln -s $1-$1-$$ $1/$1.dead ln -s $1-$1-$1-$$ $1/sub1/$1.dead ln -s $1-$1-$1-$$ $1/sub2/subsub1/$1.dead # Weird chars (shouldn't really matter to a C program # using standard file system calls and not library functions. mkdir -p "$1/weird/space test" touch "$1/weird/ssdf [ ] * 7" mkdir "$1/weird/\$ ( * ) # , ;\"" touch "$1/weird/\\ ^ 2>&1" mkdir "$1/weird/\"\` :-) :-P" # Filenames and directory names contain "moneyloser" cp $1/foo.exe $1/moneyloser.exe mkdir $1/moneyloser # A filename and directory name initially named # as _oldfiles. These ought to be processed # regularly. cp -r $1/sub1 $1/$1-sub1-$$_oldfiles du > $1/sub1/du_oldfiles echo "Done." # Done preparing directory structure } # # Advanced # function createNastyTests() { echo -n "Preparing nasty directory structure in [$1]... " # Some directly and indirectly recursive symlinks # Softcore mkdir -p $1/softcore cd $1/softcore cal > cal.txt pwd > pwd.txt mkdir subdir1 subdir2 subdir3 ln -s subdir2 subdir2.symlink cd subdir1 mkdir subsubdir1 subsubdir2 subsubdir3 ln -s ../cal.txt cal.symlink ps > ps.txt cd .. ln -s subdir1/subsubdir2 subsubdir2.symlink cd subdir1/subsubdir3 ls > ls.txt du > ../../subdir2/du.txt ln -s ../../subdir2/du.txt du.symlink cd ../../subdir2 ln -s .. softcore.symlink # Hardcore cd ../.. cp -r softcore hardcore cd hardcore ln -s / root.symlink cd subdir1/subsubdir2 ln -s ../../subsubdir2.symlink recursive.symlink ln -s recursive.a.symlink recursive.b.symlink ln -s recursive.b.symlink recursive.a.symlink cd ../../subdir2 cal > ../subdir1/junk ln -s ../subdir1/junk dead.symlink rm ../subdir1/junk # Some hardlinks cd ../.. ln foo.exe foo.hard ln foo.exe money.hard ln foo.exe loser.hard ln moneyloser.exe moneyloser.hard cd .. echo "Done." # Done preparing directory structure } # # Build # function build() { echo -n "Compiling the application... " make if [ $? != 0 ]; then echo "Failed to compile the application." exit 1 fi echo "Done." } # # Run # function runApplication() { EXE="moneymaker" # Locate an executable other than us for strFile in * do if [ -f "$strFile" -a -x "$strFile" -a "$strFile" != "moneymaker-test" ]; then EXE="$strFile" echo "Executable found". break fi done echo "[$EXE]" # Test runs: # Regular run "./$EXE" $1 # No arguments "./$EXE" # Invalid/inexisting path "./$EXE" /some-foo-bar-baz-$$-non-existent-dir # File as an argument, not a dir "./$EXE" $1/moneymaker-test # Many arguments "./$EXE" $1 foo bar baz case $1 in $BASEDIR ) # Enough for base case return ;; $ADVANCEDDIR ) # Repeated run "./$EXE" $1 ;; $NASTYDIR ) # Repeated run "./$EXE" $1 # Subject to permissions and special files # and memory exhaustion "./$EXE" / ;; esac } # main echo "Moneymaker Test Suite, \$Revision: 1.7 $" echo "" case $1 in --clean ) echo -n "Wiping out test dirs... " rm -rf $BASEDIR $ADVANCEDDIR $NASTYDIR echo "Done." ;; --base ) cat <<-BASE Creates Base Test Cases These include regular files, directories, and non-recursive or dead symlinks. The filenames consist of regular alpha-numerical names, do not have any "moneyloser" in them or "*_oldfiles". Case-sensitivity also checked. The test also includes some preliminary error handling. BASE createBaseTests $BASEDIR build runApplication $BASEDIR echo "Any missed moneyloser strings will show here:" echo "---------------------------------------------" grep -ie 'moneyloser' -r $BASEDIR | grep -v "_oldfiles" echo "---------------------------------------------" echo "All _oldfiles were ignored. Test is complete." echo "" ;; --advanced ) cat <<-ADVANCED Creates Advanced Test Cases These include all of the base cases plus dead symlinks. The filenames consist of irregular characters, or have "moneyloser" in them and "*_oldfiles". ADVANCED createBaseTests $ADVANCEDDIR createAdvancedTests $ADVANCEDDIR build runApplication $ADVANCEDDIR echo "Any missed moneyloser strings will show here:" echo "---------------------------------------------" echo "Contents:" echo "---------------------------------------------" grep -ie 'moneyloser' -r $ADVANCEDDIR echo "---------------------------------------------" echo "Filenames:" echo "---------------------------------------------" ls -lR $ADVANCEDDIR | grep -ie moneyloser echo "---------------------------------------------" echo "All _oldfiles were not ignored. Test is over." echo "" ;; --nasty ) cat <<-NASTY Creates Nasty Test Cases These include all of the base and advanced cases plus recursive symbolic links and hard links pointing in and out of the original starting directory. NASTY createBaseTests $NASTYDIR createAdvancedTests $NASTYDIR createNastyTests $NASTYDIR build runApplication $NASTYDIR echo "Any missed moneyloser strings will show here:" echo "---------------------------------------------" echo "Contents:" echo "---------------------------------------------" grep -ie 'moneyloser' -r $NASTYDIR echo "---------------------------------------------" echo "Filenames:" echo "---------------------------------------------" ls -lR $NASTYDIR | grep -ie moneyloser echo "---------------------------------------------" echo "All _oldfiles were not ignored. Test is over." echo "" ;; * ) cat <<-USAGE Please be kind and supply what type of test you want. Avaialble test suites (as options) are: --base basic requirements tests, approximate grade range: F to B --advanced advanced set of things to consiedr, includes base; approximate grade range: B+ to A- --nasty very extensive test of various pathological or nearly-so cases, or some really advanced ones; includes base and advanced; approximate grade range: A to A+ --clean remove testing directories USAGE ;; esac exit 0 #EOF