brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · d5fcbcc Raw
114 lines · python
1"""2Make sure that we handle an expression on a thread, if3the thread exits while the expression is running.4"""5 6import lldb7from lldbsuite.test.decorators import *8import lldbsuite.test.lldbutil as lldbutil9from lldbsuite.test.lldbtest import *10 11 12@skipIfAsan13class TestExitDuringExpression(TestBase):14    NO_DEBUG_INFO_TESTCASE = True15 16    @skipIfWindows17    @skipIf(oslist=["linux"], archs=["arm$", "aarch64"], bugnumber="llvm.org/pr48414")18    @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr48414")19    @expectedFailureNetBSD20    def test_exit_before_one_thread_unwind(self):21        """Test the case where we exit within the one thread timeout"""22        self.exiting_expression_test(True, True)23 24    @skipIfWindows25    @skipIf(oslist=["linux"], archs=["arm$", "aarch64"], bugnumber="llvm.org/pr48414")26    @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr48414")27    @expectedFailureNetBSD28    def test_exit_before_one_thread_no_unwind(self):29        """Test the case where we exit within the one thread timeout"""30        self.exiting_expression_test(True, False)31 32    @skipIfWindows33    def test_exit_after_one_thread_unwind(self):34        """Test the case where we exit within the one thread timeout"""35        self.exiting_expression_test(False, True)36 37    @skipIfWindows38    def test_exit_after_one_thread_no_unwind(self):39        """Test the case where we exit within the one thread timeout"""40        self.exiting_expression_test(False, False)41 42    def setUp(self):43        TestBase.setUp(self)44        self.main_source_file = lldb.SBFileSpec("main.c")45        self.build()46 47    def exiting_expression_test(self, before_one_thread_timeout, unwind):48        """function_to_call sleeps for g_timeout microseconds, then calls pthread_exit.49        This test calls function_to_call with an overall timeout of 50050        microseconds, and a one_thread_timeout as passed in.51        It also sets unwind_on_exit for the call to the unwind passed in.52        This allows you to have the thread exit either before the one thread53        timeout is passed."""54 55        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(56            self, "Break here and cause the thread to exit", self.main_source_file57        )58 59        # We'll continue to this breakpoint after running our expression:60        return_bkpt = target.BreakpointCreateBySourceRegex(61            "Break here to make sure the thread exited", self.main_source_file62        )63        frame = thread.frames[0]64        tid = thread.GetThreadID()65        # Find the timeout:66        var_options = lldb.SBVariablesOptions()67        var_options.SetIncludeArguments(False)68        var_options.SetIncludeLocals(False)69        var_options.SetIncludeStatics(True)70 71        value_list = frame.GetVariables(var_options)72        g_timeout = value_list.GetFirstValueByName("g_timeout")73        self.assertTrue(g_timeout.IsValid(), "Found g_timeout")74 75        error = lldb.SBError()76        timeout_value = g_timeout.GetValueAsUnsigned(error)77        self.assertSuccess(error, "Couldn't get timeout value")78 79        one_thread_timeout = 080        if before_one_thread_timeout:81            one_thread_timeout = timeout_value * 282        else:83            one_thread_timeout = int(timeout_value / 2)84 85        options = lldb.SBExpressionOptions()86        options.SetUnwindOnError(unwind)87        options.SetOneThreadTimeoutInMicroSeconds(one_thread_timeout)88        options.SetTimeoutInMicroSeconds(4 * timeout_value)89 90        result = frame.EvaluateExpression("function_to_call()", options)91 92        # Make sure the thread actually exited:93        thread = process.GetThreadByID(tid)94        self.assertFalse(thread.IsValid(), "The thread exited")95 96        # Make sure the expression failed:97        self.assertFalse(result.GetError().Success(), "Expression failed.")98 99        # Make sure we can keep going:100        threads = lldbutil.continue_to_breakpoint(process, return_bkpt)101        if not threads:102            self.fail("didn't get any threads back after continuing")103 104        self.assertEqual(len(threads), 1, "One thread hit our breakpoint")105        thread = threads[0]106        frame = thread.frames[0]107        # Now get the return value, if we successfully caused the thread to exit108        # it should be 10, not 20.109        ret_val = frame.FindVariable("ret_val")110        self.assertSuccess(ret_val.GetError(), "Found ret_val")111        ret_val_value = ret_val.GetValueAsSigned(error)112        self.assertSuccess(error, "Got ret_val's value")113        self.assertEqual(ret_val_value, 10, "We put the right value in ret_val")114