From 02afb9d043f064d2071ed5a593cf9f066d506511 Mon Sep 17 00:00:00 2001 From: Xusheng Date: Tue, 11 Apr 2023 17:53:53 +0800 Subject: [PATCH] Properly check the return value of launch_and_wait in the unit test --- test/debugger_test.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/debugger_test.py b/test/debugger_test.py index 32b90f89..64071d1b 100644 --- a/test/debugger_test.py +++ b/test/debugger_test.py @@ -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() @@ -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 @@ -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) @@ -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']: @@ -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() @@ -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() @@ -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)) @@ -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': @@ -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 @@ -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) @@ -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)