Guest User

Untitled

a guest
Feb 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Usage:
  4. # Switch to the directory containing the files and run:
  5. #
  6. # ./grade.sh ../hw3
  7. #
  8. # where "~/hw3" is the directory containing your solution to homeworke 3.
  9.  
  10. TIMEOUT=10s
  11. rm time.o # Not sure if it's automatically overwritten
  12. gcc -Wall -c time.c -o time.o; # Where the magic happens
  13. for i in $1/*; do
  14. echo =================================================
  15. echo Creating temp directory...
  16. TEMPDIR=`mktemp -d`
  17. TEMPDIR2=`mktemp -d`
  18. rm -fr $TEMPDIR $TEMPDIR2;
  19. mkdir -p $TEMPDIR $TEMPDIR2;
  20. echo Grading $i
  21. cp -r $i $TEMPDIR;
  22. pushd $TEMPDIR > /dev/null;
  23. find . -name "*.zip" -exec unzip {} -d $TEMPDIR \; > /dev/null 2>&1 ;
  24. find . -name "*.cpp" -exec cp -f {} $TEMPDIR2 \; > /dev/null 2>&1 ;
  25. find . -name "*.h" -exec cp -f {} $TEMPDIR2 \; >/dev/null 2>&1;
  26. popd >/dev/null;
  27. cp book.txt $TEMPDIR2;
  28. cp time.o $TEMPDIR2;
  29. cp input $TEMPDIR2;
  30. cp output $TEMPDIR2;
  31. pushd $TEMPDIR2 >/dev/null;
  32. COMPILED_SUCCESFULLY=0;
  33. cd $TEM
  34. if g++ -Wall -Werror -ansi -Xlinker --wrap=time *.cpp time.o > /dev/null 2>&1;
  35. then echo Compiled successfully without errors and warnings;
  36. COMPILED_SUCCESFULLY=1;HASWARNING=0;
  37. else if g++ -ansi -Xlinker --wrap=time *.cpp time.o > /dev/null 2>&1;
  38. then echo Compiled successfully with warnings;
  39. COMPILED_SUCCESFULLY=1; HASWARNING=1;
  40. else echo 'Compilation was unsuccessful';
  41. COMPILED_SUCCESFULLY=0;
  42. fi;
  43. fi;
  44. if [ $COMPILED_SUCCESFULLY = 1 ]; then
  45. ./a.out < input > out 2>/dev/null &
  46. sleep $TIMEOUT;
  47. kill %1 >/dev/null ;
  48. if cmp -s output out;
  49. then echo 'Output matches reference (cmp byte-by-byte comparison)';
  50. else if diff -q output out > /dev/null;
  51. then echo 'Output matches reference (diff comparison)';
  52. else if diff -q -w -i -E -B -t output out > /dev/null;
  53. then echo 'Output matches reference (diff comparison, ignore whitespace, case)';
  54. else echo Output does NOT match;
  55. fi; fi;
  56. fi; fi;
  57. popd >/dev/null;
  58. done;
Add Comment
Please, Sign In to add comment