]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/tsan/cpp_global_location/TestTsanCPPGlobalLocation.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / tsan / cpp_global_location / TestTsanCPPGlobalLocation.py
1 """
2 Tests that TSan correctly reports the filename and line number of a racy global C++ variable.
3 """
4
5 import os
6 import time
7 import lldb
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test.decorators import *
10 import lldbsuite.test.lldbutil as lldbutil
11 import json
12
13
14 class TsanCPPGlobalLocationTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     @expectedFailureAll(
19         oslist=["linux"],
20         bugnumber="non-core functionality, need to reenable and fix later (DES 2014.11.07)")
21     @skipIfFreeBSD  # llvm.org/pr21136 runtimes not yet available by default
22     @skipIfRemote
23     @skipUnlessThreadSanitizer
24     def test(self):
25         self.build()
26         self.tsan_tests()
27
28     def setUp(self):
29         # Call super's setUp().
30         TestBase.setUp(self)
31
32     def tsan_tests(self):
33         exe = os.path.join(os.getcwd(), "a.out")
34         self.expect(
35             "file " + exe,
36             patterns=["Current executable set to .*a.out"])
37
38         self.runCmd("run")
39
40         stop_reason = self.dbg.GetSelectedTarget().process.GetSelectedThread().GetStopReason()
41         if stop_reason == lldb.eStopReasonExec:
42             # On OS X 10.10 and older, we need to re-exec to enable
43             # interceptors.
44             self.runCmd("continue")
45
46         # the stop reason of the thread should be breakpoint.
47         self.expect("thread list", "A data race should be detected",
48                     substrs=['stopped', 'stop reason = Data race detected'])
49
50         self.expect(
51             "thread info -s",
52             "The extended stop info should contain the TSan provided fields",
53             substrs=[
54                 "instrumentation_class",
55                 "description",
56                 "mops"])
57
58         output_lines = self.res.GetOutput().split('\n')
59         json_line = '\n'.join(output_lines[2:])
60         data = json.loads(json_line)
61         self.assertEqual(data["instrumentation_class"], "ThreadSanitizer")
62         self.assertEqual(data["issue_type"], "data-race")
63
64         self.assertTrue(data["location_filename"].endswith("/main.cpp"))
65         self.assertEqual(
66             data["location_line"],
67             line_number(
68                 'main.cpp',
69                 '// global variable'))