Skip to content

Commit

Permalink
Properly check the return value of launch_and_wait in the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
xusheng6 committed Apr 11, 2023
1 parent ac0108e commit 02afb9d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test/debugger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_repeated_use(self):
def run_once():
dbg = DebuggerController(bv)
dbg.cmd_line = 'foobar'
self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])

# continue execution to the entry point, and check the stop reason
reason = dbg.step_into_and_wait()
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_return_code(self):
dbg = DebuggerController(bv)
dbg.cmd_line = arg

self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])
reason = dbg.go_and_wait()
self.assertEqual(reason, DebugStopReason.ProcessExited)
exit_code = dbg.exit_code
Expand All @@ -111,7 +111,7 @@ def test_exception_segfault(self):
dbg = DebuggerController(bv)

dbg.cmd_line = 'segfault'
self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])
# time.sleep(1)
reason = dbg.go_and_wait()
self.expect_segfault(reason)
Expand All @@ -123,7 +123,7 @@ def test_exception_segfault(self):
# bv = BinaryViewType.get_view_of_file(fpath)
# dbg = DebuggerController(bv)
# dbg.cmd_line = 'illegalinstr'
# self.assertTrue(dbg.launch_and_wait())
# self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])
# dbg.go()
# reason = dbg.go()
# if platform.system() in ['Windows', 'Linux']:
Expand All @@ -146,7 +146,7 @@ def test_exception_divzero(self):
dbg = DebuggerController(bv)
if not self.arch == 'arm64':
dbg.cmd_line = 'divzero'
self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])
reason = dbg.go_and_wait()
self.expect_divide_by_zero(reason)
dbg.quit_and_wait()
Expand All @@ -156,7 +156,7 @@ def test_step_into(self):
bv = BinaryViewType.get_view_of_file(fpath)
dbg = DebuggerController(bv)
dbg.cmd_line = 'foobar'
self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])
reason = dbg.step_into_and_wait()
self.assertEqual(reason, DebugStopReason.SingleStep)
reason = dbg.step_into_and_wait()
Expand All @@ -168,7 +168,7 @@ def test_breakpoint(self):
fpath = name_to_fpath('helloworld', self.arch)
bv = BinaryViewType.get_view_of_file(fpath)
dbg = DebuggerController(bv)
self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])
# TODO: right now we are not returning whether the operation succeeds, so we cannot use assertTrue/assertFalse
# breakpoint set/clear should fail at 0
self.assertIsNone(dbg.add_breakpoint(0))
Expand All @@ -186,7 +186,7 @@ def test_register_read_write(self):
fpath = name_to_fpath('helloworld', self.arch)
bv = BinaryViewType.get_view_of_file(fpath)
dbg = DebuggerController(bv)
self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])

arch_name = bv.arch.name
if arch_name == 'x86':
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_memory_read_write(self):
fpath = name_to_fpath('helloworld', self.arch)
bv = BinaryViewType.get_view_of_file(fpath)
dbg = DebuggerController(bv)
self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])

# Due to https://github.com/Vector35/debugger/issues/124, we have to skip the bytes at the entry point
addr = dbg.ip + 10
Expand All @@ -239,7 +239,7 @@ def test_thread(self):
fpath = name_to_fpath('helloworld_thread', self.arch)
bv = BinaryViewType.get_view_of_file(fpath)
dbg = DebuggerController(bv)
self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])

dbg.go()
time.sleep(1)
Expand All @@ -264,7 +264,7 @@ def test_assembly_code(self):
fpath = name_to_fpath('asmtest', 'x86_64')
bv = BinaryViewType.get_view_of_file(fpath)
dbg = DebuggerController(bv)
self.assertTrue(dbg.launch_and_wait())
self.assertNotIn(dbg.launch_and_wait(), [DebugStopReason.ProcessExited, DebugStopReason.InternalError])
entry = dbg.data.entry_point
self.assertEqual(dbg.ip, entry)

Expand Down

0 comments on commit 02afb9d

Please sign in to comment.