1
0

Added tests

This commit is contained in:
Jon Michael Aanes 2016-03-13 15:44:59 +01:00
parent 8b146efe68
commit 57049e1377

View File

@ -40,9 +40,10 @@ def execute_tests():
if output != result:
failed_tests += 1
printf("Failed in {}. {} was {}, should be {}",
name, register, result, output)
name, register, output, result)
except BaseException as e:
if not isinstance(e, result):
print(e)
if not isinstance(result, BaseException) or not isinstance(e, result):
error_tests += 1
printf("Encountered error in {}, at operation {}: {}",
name, emu.getVal('%rip'), e)
@ -53,6 +54,7 @@ def execute_tests():
failed_tests, error_tests)
################################################################################
# Arithmetic Operations
add_test("constant $255", 255, "%rsi", """
movq $255, %rsi
@ -69,7 +71,36 @@ movq $20, %rax
addq %rax, %rsi
""")
add_test("register subtraction 10-20", -10, "%rsi", """
movq $10, %rsi
movq $20, %rax
subq %rax, %rsi
""")
################################################################################
# Branching
branch_tests = [
("jg",10,">",5,0), ("jg",5,">",5,1), ("jg",5,">",10,1),
("jl",10,"<",5,1), ("jl",5,"<",5,1), ("jl",5,"<",10,0),
("je",10,"==",5,1),("je",5,"==",5,0),("je",5,"==",10,1),
("jge",10,">=",5,0),("jge",5,">=",5,0),("jge",5,">=",10,1),
("jle",10,"<=",5,1),("jle",5,"<=",5,0),("jle",5,"<=",10,0),
("jne",10,"!=",5,0),("jne",5,"!=",5,1),("jne",5,"!=",10,0),
]
for jump_instruct, a, comp, b, result in branch_tests:
add_test("branch {a} {comp} {b}={result}".format(a=a,comp=comp,b=b,result=not result), result, "%rsi", """
start: cmpq ${b}, ${a}
{jump_instruct} true
movq $1, %rsi
jmp return
true: movq $0, %rsi
return: ret
""".format(a=a,b=b,jump_instruct=jump_instruct))
################################################################################
# Junk Comparisons
add_test("invalid comparison 1", infernal.JunkComparisonException, "None", """
start: movq $100, %rsp # Set stack pointer to a random position.