run.bash 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/usr/bin/env bash
  2. CIVAS=${CIVAS-../bin32/civas}
  3. CIVVM=${CIVVM-../bin32/civvm}
  4. CIVCC=${CIVCC-../civicc}
  5. CFLAGS="-v 1"
  6. ALIGN=52
  7. total_tests=0
  8. failed_tests=0
  9. function echo_success {
  10. echo -e '\E[27;32m'"\033[1mok\033[0m"
  11. }
  12. function echo_failed {
  13. echo -e '\E[27;31m'"\033[1merror\033[0m"
  14. }
  15. # The real tests: compile a file, run it, and compare the output to the
  16. # expected output.
  17. function check_output {
  18. file=$1
  19. expect_file=${file%.*}.out
  20. if [ ! -f $file ]; then return; fi
  21. total_tests=$((total_tests+1))
  22. printf "%-${ALIGN}s " $file:
  23. if $CIVCC $CGLAGS -o tmp.s $file > tmp.out 2>&1 &&
  24. $CIVAS tmp.s -o tmp.o > tmp.out 2>&1 &&
  25. $CIVVM tmp.o > tmp.out 2>&1 &&
  26. mv tmp.out tmp.res &&
  27. diff tmp.res $expect_file --side-by-side --ignore-space-change > tmp.out 2>&1
  28. then
  29. echo_success
  30. else
  31. echo_failed
  32. echo -------------------------------
  33. cat tmp.out
  34. echo -------------------------------
  35. echo
  36. failed_tests=$((failed_tests+1))
  37. fi
  38. rm -f tmp.res tmp.s tmp.o tmp.out
  39. }
  40. # Special case: multiple files must be compiled and run together (e.g., for
  41. # extern variables). Compile all the *.cvc files in the given directory, run
  42. # them, and compare the output to the content of expected.out.
  43. function check_combined {
  44. dir=$1
  45. expect_file=$dir/expected.out
  46. if [ ! -d $dir ]; then return; fi
  47. if [ ! -f $expect_file ]; then return; fi
  48. files=`find $dir -maxdepth 1 -name \*.cvc`
  49. total_tests=$((total_tests+1))
  50. compiled=1
  51. ofiles=""
  52. compiled_files=""
  53. printf "%-${ALIGN}s " $dir:
  54. for file in $files
  55. do
  56. asfile=${file%.*}.s
  57. ofile=${file%.*}.o
  58. ofiles="$ofiles $ofile"
  59. if $CIVCC $CGLAGS -o $asfile $file &&
  60. $CIVAS -o $ofile $asfile
  61. then
  62. compiled_files="$compiled_files `basename $file`"
  63. else
  64. compiled=0
  65. fi
  66. done
  67. if [ $compiled -eq 1 ]
  68. then
  69. if $CIVVM $ofiles > tmp.out 2>&1 &&
  70. mv tmp.out tmp.res &&
  71. diff tmp.res $expect_file --side-by-side --ignore-space-change > tmp.out 2>&1
  72. then
  73. echo_success
  74. else
  75. echo_failed
  76. echo -------------------------------
  77. cat tmp.out
  78. echo -------------------------------
  79. echo
  80. failed_tests=$((failed_tests+1))
  81. fi
  82. else
  83. echo "failed, only compiled$compiled_files"
  84. failed_tests=$((failed_tests+1))
  85. fi
  86. rm -f $d/*.s $d/*.o tmp.out tmp.res
  87. }
  88. # Easy tests, check if the parser, context analysis and typechecking work
  89. # properly by checking if the compiler returns 0 (or non-zero when expected to
  90. # fail)
  91. function check_return {
  92. file=$1
  93. expect_failure=$2
  94. if [ ! -f $file ]; then return; fi
  95. total_tests=$((total_tests+1))
  96. printf "%-${ALIGN}s " $file:
  97. if $CIVCC $CFLAGS $file -o tmp.s > /dev/null 2>&1
  98. then
  99. if [ $expect_failure -eq 1 ]; then
  100. echo failed
  101. failed_tests=$((failed_tests+1))
  102. else
  103. echo_success
  104. fi
  105. else
  106. if [ $expect_failure -eq 1 ]; then
  107. echo_success
  108. else
  109. echo failed
  110. failed_tests=$((failed_tests+1))
  111. fi
  112. fi
  113. rm -f tmp.s
  114. }
  115. function run_dir {
  116. BASE=$1
  117. for f in $BASE/check_success/*.cvc; do
  118. check_return $f 0
  119. done
  120. for f in $BASE/check_error/*.cvc; do
  121. check_return $f 1
  122. done
  123. for f in $BASE/functional/*.cvc; do
  124. check_output $f
  125. done
  126. for d in $BASE/combined_*; do
  127. check_combined $d
  128. done
  129. echo
  130. }
  131. for arg in $@; do
  132. run_dir $arg
  133. done
  134. echo $total_tests tests, $failed_tests failures