summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/test/test.sh
blob: ad2ae4daf02f83cf76b2edeaa08a86d5efb2a97d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash

binary="./mycpu"
tmpfile="test/tmpfile"
inputs=( $(ls test/* | grep _program | sort -n) )

for input in ${inputs[@]}
do
  echo "Testing $input ..."

  programfile="$input"
  args="-c $programfile"
  memoryfile="${input/_program/_memory}"
  reffile="${input/_program/_output}"
  if [ -e "$memoryfile" ]
  then
    args+=" -m $memoryfile"
  fi

  if [ ! -e "$reffile" ]
  then
    echo "  ERROR: reference file $reffile doesn't exist"
    exit 1
  fi

  rm -rf "$tmpfile"
  echo "  Executing $binary $args ..."
  $binary $args > $tmpfile

  md5_1=$(md5sum < "$reffile")
  md5_2=$(md5sum < "$tmpfile")
  if [ "$md5_1" != "$md5_2" ]
  then
    echo "  ERROR: output and $reffile differ"
    diff -Nau $reffile $tmpfile
    exit 1
  else
    echo "  SUCCESS"
  fi
done