Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / functionalities / tsan / thread_numbers / TestTsanThreadNumbers.py
blob8fc1ae64c267e61b2fd9aaae1f3fe5ea8541ce91
1 """
2 Tests that TSan and LLDB have correct thread numbers.
3 """
5 import lldb
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test.decorators import *
8 import lldbsuite.test.lldbutil as lldbutil
9 import json
12 class TsanThreadNumbersTestCase(TestBase):
13 @expectedFailureAll(
14 oslist=["linux"],
15 bugnumber="non-core functionality, need to reenable and fix later (DES 2014.11.07)",
17 @expectedFailureNetBSD
18 @skipIfFreeBSD # llvm.org/pr21136 runtimes not yet available by default
19 @skipIfRemote
20 @skipUnlessThreadSanitizer
21 def test(self):
22 self.build()
23 self.tsan_tests()
25 def tsan_tests(self):
26 exe = self.getBuildArtifact("a.out")
27 self.expect("file " + exe, patterns=["Current executable set to .*a.out"])
29 self.runCmd("run")
31 stop_reason = (
32 self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason()
34 if stop_reason == lldb.eStopReasonExec:
35 # On OS X 10.10 and older, we need to re-exec to enable
36 # interceptors.
37 self.runCmd("continue")
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"],
46 self.assertEqual(
47 self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason(),
48 lldb.eStopReasonInstrumentation,
51 report_thread_id = (
52 self.dbg.GetSelectedTarget().process.GetSelectedThread().GetIndexID()
55 self.expect(
56 "thread info -s",
57 "The extended stop info should contain the TSan provided fields",
58 substrs=["instrumentation_class", "description", "mops"],
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)
68 self.assertEqual(data["mops"][0]["thread_id"], report_thread_id)
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_id
75 self.assertTrue(other_thread.IsValid())
77 self.runCmd("thread select %d" % other_thread_id)
79 self.expect(
80 "thread backtrace",
81 "The other thread should be stopped in f1 or f2",
82 substrs=["a.out", "main.c"],