Created
February 13, 2012 03:05
-
-
Save awwaiid/1813029 to your computer and use it in GitHub Desktop.
Unit Testing Spim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ prove -v unittest.t | |
unittest.t .. | |
ok 1 - expect_run | |
ok 2 - Load program | |
ok 3 - print $a0 | |
ok 4 - $a0 starts out as 0 | |
ok 5 - Stepping toward [main] | |
ok 6 - Initial jump to [main] | |
ok 7 - Stepping past [main] | |
ok 8 - print $a0 | |
ok 9 - $a0 starts out as 0 | |
ok 10 | |
ok 11 - print $a0 | |
ok 12 - $a0 now non-zero | |
ok 13 - Stepping until (?^:TEST: print string) | |
ok 14 - Stepping until (?^:TEST: print string) | |
ok 15 - Printed "Hello World"! | |
ok 16 - Stepping until (?^:TEST: print inum) | |
ok 17 - Stepping until (?^:TEST: print inum) | |
ok 18 - Stepping until (?^:TEST: print inum) | |
ok 19 - Stepping until (?^:TEST: print inum) | |
ok 20 - Stepping until (?^:TEST: print inum) | |
ok 21 - Stepping until (?^:TEST: print inum) | |
ok 22 - Stepping until (?^:TEST: print inum) | |
ok 23 - Stepping until (?^:TEST: print inum) | |
ok 24 - Got int | |
ok 25 - Stepping until (?^:TEST: print dnum) | |
ok 26 - Stepping until (?^:TEST: print dnum) | |
ok 27 - Stepping until (?^:TEST: print dnum) | |
ok 28 - Stepping until (?^:TEST: print dnum) | |
ok 29 - Stepping until (?^:TEST: print dnum) | |
ok 30 - Stepping until (?^:TEST: print dnum) | |
ok 31 - Stepping until (?^:TEST: print dnum) | |
ok 32 - Stepping until (?^:TEST: print dnum) | |
ok 33 - Got double | |
ok 34 - Stepping until (?^:TEST: print fnum) | |
ok 35 - Stepping until (?^:TEST: print fnum) | |
ok 36 - Stepping until (?^:TEST: print fnum) | |
ok 37 - Stepping until (?^:TEST: print fnum) | |
ok 38 - Stepping until (?^:TEST: print fnum) | |
ok 39 - Stepping until (?^:TEST: print fnum) | |
ok 40 - Stepping until (?^:TEST: print fnum) | |
ok 41 - Stepping until (?^:TEST: print fnum) | |
ok 42 - Got (approximate) float | |
1..42 | |
ok | |
All tests successful. | |
Files=1, Tests=42, 0 wallclock secs ( 0.03 usr 0.02 sys + 0.04 cusr 0.01 csys = 0.10 CPU) | |
Result: PASS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Annotated with TEST: comments | |
######################################################################### | |
#Program : printstuff.s # | |
#Purpose : To learn how to print strings, int, float and double numbers # | |
#Ref : Appendix B of Text, Figure B.9.1, p B-44 (0ld edition) # | |
######################################################################### | |
.data | |
tab : .asciiz "\t" | |
newline : .asciiz "\n" | |
str : .asciiz "Hello World" | |
inum : .word 6745 | |
dnum : .double 67.45 | |
fnum : .float 67.45 | |
.text | |
.globl main | |
main : | |
#print string at str | |
la $a0, str # TEST: Loading str | |
#$a0 contains a pointer which points to "Hello World":) | |
li $v0, 4 | |
syscall # TEST: print string | |
#print a newline | |
la $a0, newline | |
li $v0, 4 | |
syscall | |
#print an int at inum | |
lw $a0, inum | |
li $v0, 1 | |
syscall # TEST: print inum | |
#print a newline | |
la $a0, newline | |
li $v0, 4 | |
syscall | |
#print a double at dnum | |
l.d $f12, dnum | |
li $v0, 3 | |
syscall # TEST: print dnum | |
#print a newline | |
la $a0, newline | |
li $v0, 4 | |
syscall | |
#print a float at fnum | |
l.d $f12, fnum | |
li $v0, 2 | |
syscall # TEST: print fnum | |
#print a newline | |
la $a0, newline | |
li $v0,4 | |
syscall | |
#terminate program gracefully | |
li $v0, 10 # terminate program and | |
syscall # return control to system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use Test::Expect; | |
use Test::More 'no_plan'; | |
# Test::Expect doesn't have this. But it should. | |
sub expect_unlike { | |
my ($unlike, $comment) = @_; | |
unlike( Test::Expect::before(), $unlike, $comment ); | |
} | |
sub step { expect_send('step', @_) } | |
sub step_until { | |
my ($lookfor) = @_; | |
while( Test::Expect::before() !~ /$lookfor/ ) { | |
step("Stepping until $lookfor"); | |
} | |
} | |
expect_run( | |
command => 'spim', | |
prompt => "(spim) ", | |
quit => 'quit', | |
); | |
# expect_handle()->log_file("expect.out"); | |
# expect_handle()->log_user(1); | |
expect_send('read "printstuff.s"', 'Load program'); | |
expect_send('print $a0', 'print $a0'); | |
expect_like(qr/0x00000000/, '$a0 starts out as 0'); | |
expect_send("step 6", 'Stepping toward [main]'); | |
expect_like(qr/jal main/, 'Initial jump to [main]'); | |
expect_send("step", 'Stepping past [main]'); | |
step_until(qr/TEST:/); | |
expect_send('print $a0', 'print $a0'); | |
expect_like(qr/0x00000000/, '$a0 starts out as 0'); | |
step(); | |
expect_send('print $a0', 'print $a0'); | |
expect_unlike(qr/0x00000000/, '$a0 now non-zero'); | |
step_until(qr/TEST: print string/); | |
expect_like(qr/Hello World/, 'Printed "Hello World"!'); | |
step_until(qr/TEST: print inum/); | |
expect_like(qr/6745/, 'Got int'); | |
step_until(qr/TEST: print dnum/); | |
expect_like(qr/67\.45/, 'Got double'); | |
step_until(qr/TEST: print fnum/); | |
expect_like(qr/67\.44999695/, 'Got (approximate) float'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment