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