Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Usage:
- # Switch to the directory containing the files and run:
- #
- # ./grade.sh ../hw3
- #
- # where "~/hw3" is the directory containing your solution to homeworke 3.
- TIMEOUT=10s
- rm time.o # Not sure if it's automatically overwritten
- gcc -Wall -c time.c -o time.o; # Where the magic happens
- for i in $1/*; do
- echo =================================================
- echo Creating temp directory...
- TEMPDIR=`mktemp -d`
- TEMPDIR2=`mktemp -d`
- rm -fr $TEMPDIR $TEMPDIR2;
- mkdir -p $TEMPDIR $TEMPDIR2;
- echo Grading $i
- cp -r $i $TEMPDIR;
- pushd $TEMPDIR > /dev/null;
- find . -name "*.zip" -exec unzip {} -d $TEMPDIR \; > /dev/null 2>&1 ;
- find . -name "*.cpp" -exec cp -f {} $TEMPDIR2 \; > /dev/null 2>&1 ;
- find . -name "*.h" -exec cp -f {} $TEMPDIR2 \; >/dev/null 2>&1;
- popd >/dev/null;
- cp book.txt $TEMPDIR2;
- cp time.o $TEMPDIR2;
- cp input $TEMPDIR2;
- cp output $TEMPDIR2;
- pushd $TEMPDIR2 >/dev/null;
- COMPILED_SUCCESFULLY=0;
- cd $TEM
- if g++ -Wall -Werror -ansi -Xlinker --wrap=time *.cpp time.o > /dev/null 2>&1;
- then echo Compiled successfully without errors and warnings;
- COMPILED_SUCCESFULLY=1;HASWARNING=0;
- else if g++ -ansi -Xlinker --wrap=time *.cpp time.o > /dev/null 2>&1;
- then echo Compiled successfully with warnings;
- COMPILED_SUCCESFULLY=1; HASWARNING=1;
- else echo 'Compilation was unsuccessful';
- COMPILED_SUCCESFULLY=0;
- fi;
- fi;
- if [ $COMPILED_SUCCESFULLY = 1 ]; then
- ./a.out < input > out 2>/dev/null &
- sleep $TIMEOUT;
- kill %1 >/dev/null ;
- if cmp -s output out;
- then echo 'Output matches reference (cmp byte-by-byte comparison)';
- else if diff -q output out > /dev/null;
- then echo 'Output matches reference (diff comparison)';
- else if diff -q -w -i -E -B -t output out > /dev/null;
- then echo 'Output matches reference (diff comparison, ignore whitespace, case)';
- else echo Output does NOT match;
- fi; fi;
- fi; fi;
- popd >/dev/null;
- done;
Add Comment
Please, Sign In to add comment