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