brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · ed65f68 Raw
62 lines · python
1"""2Tests that TSan correctly reports the filename and line number of a racy global C++ variable.3"""4 5import lldb6from lldbsuite.test.lldbtest import *7from lldbsuite.test.decorators import *8import lldbsuite.test.lldbutil as lldbutil9import json10 11 12class TsanCPPGlobalLocationTestCase(TestBase):13    @expectedFailureAll(14        oslist=["linux"],15        bugnumber="non-core functionality, need to reenable and fix later (DES 2014.11.07)",16    )17    @expectedFailureNetBSD18    @skipIfFreeBSD  # llvm.org/pr21136 runtimes not yet available by default19    @skipIfRemote20    @skipUnlessThreadSanitizer21    def test(self):22        self.build()23        self.tsan_tests()24 25    def tsan_tests(self):26        exe = self.getBuildArtifact("a.out")27        self.expect("file " + exe, patterns=["Current executable set to .*a.out"])28 29        self.runCmd("run")30 31        stop_reason = (32            self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason()33        )34        if stop_reason == lldb.eStopReasonExec:35            # On OS X 10.10 and older, we need to re-exec to enable36            # interceptors.37            self.runCmd("continue")38 39        # the stop reason of the thread should be breakpoint.40        self.expect(41            "thread list",42            "A data race should be detected",43            substrs=["stopped", "stop reason = Data race detected"],44        )45 46        self.expect(47            "thread info -s",48            "The extended stop info should contain the TSan provided fields",49            substrs=["instrumentation_class", "description", "mops"],50        )51 52        output_lines = self.res.GetOutput().split("\n")53        json_line = "\n".join(output_lines[2:])54        data = json.loads(json_line)55        self.assertEqual(data["instrumentation_class"], "ThreadSanitizer")56        self.assertEqual(data["issue_type"], "data-race")57 58        self.assertTrue(data["location_filename"].endswith("/main.cpp"))59        self.assertEqual(60            data["location_line"], line_number("main.cpp", "// global variable")61        )62