brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 4675b4a Raw
73 lines · python
1"""2Tests basic Main Thread Checker support (detecting a main-thread-only violation).3"""4 5import lldb6from lldbsuite.test.lldbtest import *7from lldbsuite.test.decorators import *8import lldbsuite.test.lldbutil as lldbutil9from lldbsuite.test.lldbplatformutil import *10import json11 12 13class MTCSimpleTestCase(TestBase):14    @skipUnlessDarwin15    @skipIf(compiler="clang", compiler_version=["<", "9.0"])16    def test(self):17        self.mtc_dylib_path = findMainThreadCheckerDylib()18        if self.mtc_dylib_path == "":19            self.skipTest("This test requires libMainThreadChecker.dylib")20 21        self.build()22        self.mtc_tests()23 24    @skipIf(archs=["i386"])25    @skipIf(compiler="clang", compiler_version=["<", "9.0"])26    def mtc_tests(self):27        self.assertNotEqual(self.mtc_dylib_path, "")28 29        # Load the test30        exe = self.getBuildArtifact("a.out")31        self.expect("file " + exe, patterns=["Current executable set to .*a.out"])32 33        self.runCmd("env DYLD_INSERT_LIBRARIES=%s" % self.mtc_dylib_path)34        self.runCmd("run")35 36        process = self.dbg.GetSelectedTarget().process37        thread = process.GetSelectedThread()38        frame = thread.GetSelectedFrame()39 40        view = "NSView" if lldbplatformutil.getPlatform() == "macosx" else "UIView"41 42        self.expect(43            "thread info",44            substrs=[45                "stop reason = -["46                + view47                + " superview] must be used from main thread only"48            ],49        )50 51        self.expect(52            "thread info -s",53            substrs=[54                "api_name",55                "class_name",56                "description",57                "instrumentation_class",58                "selector",59            ],60        )61        self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonInstrumentation)62        output_lines = self.res.GetOutput().split("\n")63        json_line = "\n".join(output_lines[2:])64        data = json.loads(json_line)65        self.assertEqual(data["instrumentation_class"], "MainThreadChecker")66        self.assertEqual(data["api_name"], "-[" + view + " superview]")67        self.assertEqual(data["class_name"], view)68        self.assertEqual(data["selector"], "superview")69        self.assertEqual(70            data["description"],71            "-[" + view + " superview] must be used from main thread only",72        )73