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
15 class AddDsymCommandCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
21 self.template = 'main.cpp.template'
22 self.source = 'main.cpp'
23 self.teardown_hook_added = False
26 def test_add_dsym_command_with_error(self):
27 """Test that the 'add-dsym' command informs the user about failures."""
29 # Call the program generator to produce main.cpp, version 1.
30 self.generate_main_cpp(version=1)
31 self.buildDsym(clean=True)
33 # Insert some delay and then call the program generator to produce
34 # main.cpp, version 2.
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)
40 self.exe_name = 'a.out'
41 self.do_add_dsym_with_error(self.exe_name)
44 def test_add_dsym_command_with_success(self):
45 """Test that the 'add-dsym' command informs the user about success."""
47 # Call the program generator to produce main.cpp, version 1.
48 self.generate_main_cpp(version=1)
49 self.buildDsym(clean=True)
51 self.exe_name = 'a.out'
52 self.do_add_dsym_with_success(self.exe_name)
55 def test_add_dsym_with_dSYM_bundle(self):
56 """Test that the 'add-dsym' command informs the user about success."""
58 # Call the program generator to produce main.cpp, version 1.
59 self.generate_main_cpp(version=1)
60 self.buildDsym(clean=True)
62 self.exe_name = 'a.out'
63 self.do_add_dsym_with_dSYM_bundle(self.exe_name)
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:
71 new_content = content.replace(
73 'printf("This is version %d\\n");' %
75 src = os.path.join(os.getcwd(), self.source)
76 with open(src, 'w') as f:
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
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)
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'])
92 right_path = os.path.join(
99 self.expect("add-dsym " + right_path, error=True,
100 substrs=['symbol file', 'does not match'])
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)
106 # This time, the UUID should match and we expect some feedback from
108 right_path = os.path.join(
115 self.expect("add-dsym " + right_path,
116 substrs=['symbol file', 'has been added to'])
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)
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'])