Skip to content

Commit 286180a

Browse files
committed
Add some asserts to the tests
1 parent 21be341 commit 286180a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

tests/example.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def old_test():
3939
print(icicle.MemoryProtection.ReadOnly)
4040
print(f"Architectures: {icicle.architectures()}")
4141
vm = icicle.Icicle("x86_64")
42+
print(vm)
4243

4344
for name, (offset, size) in vm.reg_list().items():
4445
value = vm.reg_read(name.lower())
@@ -59,11 +60,10 @@ def old_test():
5960
data = vm.mem_read(addr, 4)
6061
print(data, type(data))
6162

62-
print(vm)
63-
6463
def main():
6564
old_test()
6665

66+
print("")
6767
vm = icicle.Icicle("x86_64", jit=False)
6868
print(vm)
6969

@@ -86,9 +86,10 @@ def main():
8686
print(status)
8787
if status == icicle.RunStatus.UnhandledException:
8888
print(f"code: {vm.exception_code}, value: {hex(vm.exception_value)}")
89-
print(f"rip: {hex(vm.reg_read('rip'))}")
89+
print(f"rip: {hex(vm.reg_read('rip'))} (OK)")
9090
else:
9191
print(f"rax: {hex(vm.reg_read('rax'))}")
92+
assert False, "Should be unreachable"
9293

9394
if __name__ == "__main__":
9495
main()

tests/invalid.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def nx():
1818
status = vm.run()
1919
print(status)
2020
print(vm.exception_code, hex(vm.exception_value))
21+
# We expect an execution violation at rip
22+
assert vm.exception_code == ExceptionCode.ExecViolation
23+
assert vm.exception_value == page
2124

2225
def inv_start():
2326
vm = Icicle("x86_64", jit=False)
@@ -28,6 +31,9 @@ def inv_start():
2831
status = vm.run()
2932
print(status)
3033
print(vm.exception_code, hex(vm.exception_value))
34+
# We expect an invalid instruction at rip
35+
assert vm.exception_code == ExceptionCode.InvalidInstruction
36+
assert vm.exception_value == page
3137

3238
def inv_middle():
3339
vm = Icicle("x86_64", jit=False)
@@ -38,6 +44,9 @@ def inv_middle():
3844
status = vm.run()
3945
print(status)
4046
print(vm.exception_code, hex(vm.exception_value))
47+
# We expect an invalid instruction at rip+2
48+
assert vm.exception_code == ExceptionCode.InvalidInstruction
49+
assert vm.exception_value == page + 2
4150

4251
def main():
4352
print("=== NX ===")
@@ -46,6 +55,7 @@ def main():
4655
inv_start()
4756
print("=== Invalid instruction (block middle) ===")
4857
inv_middle()
58+
print("\nSUCCESS")
4959

5060
if __name__ == "__main__":
5161
main()

0 commit comments

Comments
 (0)