1 """Test that the 'add-dsym', aka 'target symbols add', command informs the user about success or failure."""
3 from __future__ import print_function
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class AddDsymCommandCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
20 self.template = 'main.cpp.template'
21 self.source = 'main.cpp'
22 self.teardown_hook_added = False
25 def test_add_dsym_command_with_error(self):
26 """Test that the 'add-dsym' command informs the user about failures."""
28 # Call the program generator to produce main.cpp, version 1.
29 self.generate_main_cpp(version=1)
30 self.buildDsym(clean=True)
32 # Insert some delay and then call the program generator to produce main.cpp, version 2.
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)
38 self.exe_name = 'a.out'
39 self.do_add_dsym_with_error(self.exe_name)
42 def test_add_dsym_command_with_success(self):
43 """Test that the 'add-dsym' command informs the user about success."""
45 # Call the program generator to produce main.cpp, version 1.
46 self.generate_main_cpp(version=1)
47 self.buildDsym(clean=True)
49 self.exe_name = 'a.out'
50 self.do_add_dsym_with_success(self.exe_name)
53 def test_add_dsym_with_dSYM_bundle(self):
54 """Test that the 'add-dsym' command informs the user about success."""
56 # Call the program generator to produce main.cpp, version 1.
57 self.generate_main_cpp(version=1)
58 self.buildDsym(clean=True)
60 self.exe_name = 'a.out'
61 self.do_add_dsym_with_dSYM_bundle(self.exe_name)
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:
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:
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
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)
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'])
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'])
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)
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'])
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)
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'])