84 lines · python
1"""2Tests that TSan and LLDB have correct thread numbers.3"""4 5import lldb6from lldbsuite.test.lldbtest import *7from lldbsuite.test.decorators import *8import lldbsuite.test.lldbutil as lldbutil9import json10 11 12class TsanThreadNumbersTestCase(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.assertEqual(47 self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason(),48 lldb.eStopReasonInstrumentation,49 )50 51 report_thread_id = (52 self.dbg.GetSelectedTarget().process.GetSelectedThread().GetIndexID()53 )54 55 self.expect(56 "thread info -s",57 "The extended stop info should contain the TSan provided fields",58 substrs=["instrumentation_class", "description", "mops"],59 )60 61 output_lines = self.res.GetOutput().split("\n")62 json_line = "\n".join(output_lines[2:])63 data = json.loads(json_line)64 self.assertEqual(data["instrumentation_class"], "ThreadSanitizer")65 self.assertEqual(data["issue_type"], "data-race")66 self.assertEqual(len(data["mops"]), 2)67 68 self.assertEqual(data["mops"][0]["thread_id"], report_thread_id)69 70 other_thread_id = data["mops"][1]["thread_id"]71 self.assertNotEqual(other_thread_id, report_thread_id)72 other_thread = self.dbg.GetSelectedTarget().process.GetThreadByIndexID(73 other_thread_id74 )75 self.assertTrue(other_thread.IsValid())76 77 self.runCmd("thread select %d" % other_thread_id)78 79 self.expect(80 "thread backtrace",81 "The other thread should be stopped in f1 or f2",82 substrs=["a.out", "main.c"],83 )84