run.bash 3.5 KB

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