]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/c/tls_globals/TestTlsGlobals.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / c / tls_globals / TestTlsGlobals.py
1 """Test that thread-local storage can be read correctly."""
2
3 from __future__ import print_function
4
5
6 import unittest2
7 import os
8 import time
9 import lldb
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
13
14
15 class TlsGlobalTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         TestBase.setUp(self)
21
22         if self.getPlatform() == "freebsd" or self.getPlatform() == "linux":
23             # LD_LIBRARY_PATH must be set so the shared libraries are found on
24             # startup
25             if "LD_LIBRARY_PATH" in os.environ:
26                 self.runCmd(
27                     "settings set target.env-vars " +
28                     self.dylibPath +
29                     "=" +
30                     os.environ["LD_LIBRARY_PATH"] +
31                     ":" +
32                     os.getcwd())
33             else:
34                 self.runCmd("settings set target.env-vars " +
35                             self.dylibPath + "=" + os.getcwd())
36             self.addTearDownHook(
37                 lambda: self.runCmd(
38                     "settings remove target.env-vars " +
39                     self.dylibPath))
40
41     # TLS works differently on Windows, this would need to be implemented
42     # separately.
43     @skipIfWindows
44     @expectedFailureAll(
45         bugnumber="llvm.org/pr28392",
46         oslist=no_match(
47             lldbplatformutil.getDarwinOSTriples()))
48     def test(self):
49         """Test thread-local storage."""
50         self.build()
51         exe = os.path.join(os.getcwd(), "a.out")
52         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
53
54         line1 = line_number('main.c', '// thread breakpoint')
55         lldbutil.run_break_set_by_file_and_line(
56             self, "main.c", line1, num_expected_locations=1, loc_exact=True)
57         self.runCmd("run", RUN_SUCCEEDED)
58
59         # The stop reason of the thread should be breakpoint.
60         self.runCmd("process status", "Get process status")
61         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
62                     substrs=['stopped',
63                              'stop reason = breakpoint'])
64
65         # BUG: sometimes lldb doesn't change threads to the stopped thread.
66         # (unrelated to this test).
67         self.runCmd("thread select 2", "Change thread")
68
69         # Check that TLS evaluates correctly within the thread.
70         self.expect("expr var_static", VARIABLES_DISPLAYED_CORRECTLY,
71                     patterns=["\(int\) \$.* = 88"])
72         self.expect("expr var_shared", VARIABLES_DISPLAYED_CORRECTLY,
73                     patterns=["\(int\) \$.* = 66"])
74
75         # Continue on the main thread
76         line2 = line_number('main.c', '// main breakpoint')
77         lldbutil.run_break_set_by_file_and_line(
78             self, "main.c", line2, num_expected_locations=1, loc_exact=True)
79         self.runCmd("continue", RUN_SUCCEEDED)
80
81         # The stop reason of the thread should be breakpoint.
82         self.runCmd("process status", "Get process status")
83         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
84                     substrs=['stopped',
85                              'stop reason = breakpoint'])
86
87         # BUG: sometimes lldb doesn't change threads to the stopped thread.
88         # (unrelated to this test).
89         self.runCmd("thread select 1", "Change thread")
90
91         # Check that TLS evaluates correctly within the main thread.
92         self.expect("expr var_static", VARIABLES_DISPLAYED_CORRECTLY,
93                     patterns=["\(int\) \$.* = 44"])
94         self.expect("expr var_shared", VARIABLES_DISPLAYED_CORRECTLY,
95                     patterns=["\(int\) \$.* = 33"])