if [ $(uname -m) != "riscv64" ]; then function compile() { riscv64-linux-gnu-gcc-12 -static $1.s -o $1.elf } function run_with_input() { qemu-riscv64 $1.elf < $1.in > $1.ans } function run_without_input() { qemu-riscv64 $1.elf > $1.ans } else function compile() { gcc $1.s -o $1.elf } function run_with_input() { ./$1.elf < $1.in > $1.ans } function run_without_input() { ./$1.elf > $1.ans } fi cd test gcc ../boot.c -o boot.elf all_cnt=0 succ_cnt=0 for D in *; do if [ -d "${D}" ]; then echo "Testing subdirectory '$D'" cd $D for i in *.c; do all_cnt=$((all_cnt+1)) failed=1 i=$(basename $i .c) if [ -f $i.out ]; then ../boot.elf < $i.c > $i.s && compile $i if [[ $? == 0 ]]; then if [ -f $i.in ]; then run_with_input $i else run_without_input $i fi echo $? >> $i.ans cmp $i.out $i.ans failed=$? if [[ $failed == 0 ]]; then rm $i.ans $i.elf $i.s fi else failed=1 fi else ../boot.elf < $i.c > /dev/null 2>/dev/null failed=$((!$?)) fi if [[ $failed == 0 ]]; then echo "Test '$D/$i' passed" succ_cnt=$((succ_cnt+1)) else echo "Test '$D/$i' failed" fi done cd .. fi done echo "Passed $succ_cnt/$all_cnt tests" rm boot.elf