]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/warnings/uuid/TestAddDsymCommand.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / warnings / uuid / TestAddDsymCommand.py
1 """Test that the 'add-dsym', aka 'target symbols add', command informs the user about success or failure."""
2
3 from __future__ import print_function
4
5
6 import os
7 import time
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 @skipUnlessDarwin
15 class AddDsymCommandCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         TestBase.setUp(self)
21         self.template = 'main.cpp.template'
22         self.source = 'main.cpp'
23         self.teardown_hook_added = False
24
25     @no_debug_info_test
26     def test_add_dsym_command_with_error(self):
27         """Test that the 'add-dsym' command informs the user about failures."""
28
29         # Call the program generator to produce main.cpp, version 1.
30         self.generate_main_cpp(version=1)
31         self.buildDsym(clean=True)
32
33         # Insert some delay and then call the program generator to produce
34         # main.cpp, version 2.
35         time.sleep(5)
36         self.generate_main_cpp(version=101)
37         # Now call make again, but this time don't generate the dSYM.
38         self.buildDwarf(clean=False)
39
40         self.exe_name = 'a.out'
41         self.do_add_dsym_with_error(self.exe_name)
42
43     @no_debug_info_test
44     def test_add_dsym_command_with_success(self):
45         """Test that the 'add-dsym' command informs the user about success."""
46
47         # Call the program generator to produce main.cpp, version 1.
48         self.generate_main_cpp(version=1)
49         self.buildDsym(clean=True)
50
51         self.exe_name = 'a.out'
52         self.do_add_dsym_with_success(self.exe_name)
53
54     @no_debug_info_test
55     def test_add_dsym_with_dSYM_bundle(self):
56         """Test that the 'add-dsym' command informs the user about success."""
57
58         # Call the program generator to produce main.cpp, version 1.
59         self.generate_main_cpp(version=1)
60         self.buildDsym(clean=True)
61
62         self.exe_name = 'a.out'
63         self.do_add_dsym_with_dSYM_bundle(self.exe_name)
64
65     def generate_main_cpp(self, version=0):
66         """Generate main.cpp from main.cpp.template."""
67         temp = os.path.join(os.getcwd(), self.template)
68         with open(temp, 'r') as f:
69             content = f.read()
70
71         new_content = content.replace(
72             '%ADD_EXTRA_CODE%',
73             'printf("This is version %d\\n");' %
74             version)
75         src = os.path.join(os.getcwd(), self.source)
76         with open(src, 'w') as f:
77             f.write(new_content)
78
79         # The main.cpp has been generated, add a teardown hook to remove it.
80         if not self.teardown_hook_added:
81             self.addTearDownHook(lambda: os.remove(src))
82             self.teardown_hook_added = True
83
84     def do_add_dsym_with_error(self, exe_name):
85         """Test that the 'add-dsym' command informs the user about failures."""
86         self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
87
88         wrong_path = os.path.join("%s.dSYM" % exe_name, "Contents")
89         self.expect("add-dsym " + wrong_path, error=True,
90                     substrs=['invalid module path'])
91
92         right_path = os.path.join(
93             "%s.dSYM" %
94             exe_name,
95             "Contents",
96             "Resources",
97             "DWARF",
98             exe_name)
99         self.expect("add-dsym " + right_path, error=True,
100                     substrs=['symbol file', 'does not match'])
101
102     def do_add_dsym_with_success(self, exe_name):
103         """Test that the 'add-dsym' command informs the user about success."""
104         self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
105
106         # This time, the UUID should match and we expect some feedback from
107         # lldb.
108         right_path = os.path.join(
109             "%s.dSYM" %
110             exe_name,
111             "Contents",
112             "Resources",
113             "DWARF",
114             exe_name)
115         self.expect("add-dsym " + right_path,
116                     substrs=['symbol file', 'has been added to'])
117
118     def do_add_dsym_with_dSYM_bundle(self, exe_name):
119         """Test that the 'add-dsym' command informs the user about success when loading files in bundles."""
120         self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
121
122         # This time, the UUID should be found inside the bundle
123         right_path = "%s.dSYM" % exe_name
124         self.expect("add-dsym " + right_path,
125                     substrs=['symbol file', 'has been added to'])