run.bash 3.9 KB

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