Download | Plain Text | No Line Numbers


  1. #!/bin/bash
  2.  
  3. binary="./mycpu"
  4. tmpfile="test/tmpfile"
  5. inputs=( $(ls test/* | grep _program | sort -n) )
  6.  
  7. for input in ${inputs[@]}
  8. do
  9. echo "Testing $input ..."
  10.  
  11. programfile="$input"
  12. args="-c $programfile"
  13. argsfile="${input/_program/_args}"
  14. memoryfile="${input/_program/_memory}"
  15. reffile="${input/_program/_output}"
  16.  
  17. if [ ! -e "$argsfile" ]
  18. then
  19. echo " ERROR: argsfile $argsfile doesn't exist"
  20. exit 1
  21. fi
  22.  
  23. args=$(cat "$argsfile")
  24. args=${args/\#program\#/$input}
  25. args=${args/\#memory\#/$memoryfile}
  26.  
  27. if [ ! -e "$reffile" ]
  28. then
  29. echo " ERROR: reference file $reffile doesn't exist"
  30. exit 1
  31. fi
  32.  
  33. rm -rf "$tmpfile"
  34. echo " Executing $binary $args ..."
  35. $binary $args > $tmpfile
  36.  
  37. md5_1=$(md5sum < "$reffile")
  38. md5_2=$(md5sum < "$tmpfile")
  39. if [ "$md5_1" != "$md5_2" ]
  40. then
  41. echo " ERROR: output and $reffile differ"
  42. diff -Naur "$reffile" "$tmpfile"
  43. rm -rf "$tmpfile"
  44. exit 1
  45. else
  46. echo " SUCCESS"
  47. fi
  48. rm -rf "$tmpfile"
  49. done
  50.