diff options
Diffstat (limited to 'ue3/mycpu/test')
| -rwxr-xr-x | ue3/mycpu/test/test.sh | 40 | ||||
| -rw-r--r-- | ue3/mycpu/test/test1_memory | 1 | ||||
| -rw-r--r-- | ue3/mycpu/test/test1_output | 19 | ||||
| -rw-r--r-- | ue3/mycpu/test/test1_program | 13 |
4 files changed, 73 insertions, 0 deletions
diff --git a/ue3/mycpu/test/test.sh b/ue3/mycpu/test/test.sh new file mode 100755 index 0000000..ad2ae4d --- /dev/null +++ b/ue3/mycpu/test/test.sh | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | binary="./mycpu" | ||
| 4 | tmpfile="test/tmpfile" | ||
| 5 | inputs=( $(ls test/* | grep _program | sort -n) ) | ||
| 6 | |||
| 7 | for input in ${inputs[@]} | ||
| 8 | do | ||
| 9 | echo "Testing $input ..." | ||
| 10 | |||
| 11 | programfile="$input" | ||
| 12 | args="-c $programfile" | ||
| 13 | memoryfile="${input/_program/_memory}" | ||
| 14 | reffile="${input/_program/_output}" | ||
| 15 | if [ -e "$memoryfile" ] | ||
| 16 | then | ||
| 17 | args+=" -m $memoryfile" | ||
| 18 | fi | ||
| 19 | |||
| 20 | if [ ! -e "$reffile" ] | ||
| 21 | then | ||
| 22 | echo " ERROR: reference file $reffile doesn't exist" | ||
| 23 | exit 1 | ||
| 24 | fi | ||
| 25 | |||
| 26 | rm -rf "$tmpfile" | ||
| 27 | echo " Executing $binary $args ..." | ||
| 28 | $binary $args > $tmpfile | ||
| 29 | |||
| 30 | md5_1=$(md5sum < "$reffile") | ||
| 31 | md5_2=$(md5sum < "$tmpfile") | ||
| 32 | if [ "$md5_1" != "$md5_2" ] | ||
| 33 | then | ||
| 34 | echo " ERROR: output and $reffile differ" | ||
| 35 | diff -Nau $reffile $tmpfile | ||
| 36 | exit 1 | ||
| 37 | else | ||
| 38 | echo " SUCCESS" | ||
| 39 | fi | ||
| 40 | done | ||
diff --git a/ue3/mycpu/test/test1_memory b/ue3/mycpu/test/test1_memory new file mode 100644 index 0000000..209e3ef --- /dev/null +++ b/ue3/mycpu/test/test1_memory | |||
| @@ -0,0 +1 @@ | |||
| 20 | |||
diff --git a/ue3/mycpu/test/test1_output b/ue3/mycpu/test/test1_output new file mode 100644 index 0000000..ac30dc2 --- /dev/null +++ b/ue3/mycpu/test/test1_output | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
diff --git a/ue3/mycpu/test/test1_program b/ue3/mycpu/test/test1_program new file mode 100644 index 0000000..ae5e9d2 --- /dev/null +++ b/ue3/mycpu/test/test1_program | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | # set R2 = 10 | ||
| 2 | LOAD R2, R1 | ||
| 3 | |||
| 4 | # start of loop | ||
| 5 | label Loop: | ||
| 6 | inc R3 | ||
| 7 | sub R4, R3, R2 | ||
| 8 | test R4 | ||
| 9 | jumpz EndLoop | ||
| 10 | write WDEZ, R3 | ||
| 11 | jumpa Loop | ||
| 12 | |||
| 13 | label EndLoop: | ||
