blob: 9b94d8cfc74704700c55f22384cc900d349417ba [file] [log] [blame]
Johnny Chen82e5a262012-08-22 00:18:43 +00001"""Test that the 'add-dsym', aka 'target symbols add', command informs the user about success or failure."""
2
3import os, time
4import unittest2
5import lldb
Johnny Chen82e5a262012-08-22 00:18:43 +00006from lldbtest import *
7
Robert Flack13c7ad92015-03-30 14:12:17 +00008@skipUnlessDarwin
Johnny Chen82e5a262012-08-22 00:18:43 +00009class AddDsymCommandCase(TestBase):
10
Greg Clayton4570d3e2013-12-10 23:19:29 +000011 mydir = TestBase.compute_mydir(__file__)
Johnny Chen82e5a262012-08-22 00:18:43 +000012
13 def setUp(self):
14 TestBase.setUp(self)
15 self.template = 'main.cpp.template'
16 self.source = 'main.cpp'
17 self.teardown_hook_added = False
18
19 def test_add_dsym_command_with_error(self):
20 """Test that the 'add-dsym' command informs the user about failures."""
21
22 # Call the program generator to produce main.cpp, version 1.
23 self.generate_main_cpp(version=1)
24 self.buildDsym(clean=True)
25
26 # Insert some delay and then call the program generator to produce main.cpp, version 2.
27 time.sleep(5)
28 self.generate_main_cpp(version=101)
29 # Now call make again, but this time don't generate the dSYM.
30 self.buildDwarf(clean=False)
31
32 self.exe_name = 'a.out'
33 self.do_add_dsym_with_error(self.exe_name)
34
35 def test_add_dsym_command_with_success(self):
36 """Test that the 'add-dsym' command informs the user about success."""
37
38 # Call the program generator to produce main.cpp, version 1.
39 self.generate_main_cpp(version=1)
40 self.buildDsym(clean=True)
41
42 self.exe_name = 'a.out'
43 self.do_add_dsym_with_success(self.exe_name)
44
Filipe Cabecinhas7d4c68a2012-09-12 14:43:45 +000045 def test_add_dsym_with_dSYM_bundle(self):
46 """Test that the 'add-dsym' command informs the user about success."""
47
48 # Call the program generator to produce main.cpp, version 1.
49 self.generate_main_cpp(version=1)
50 self.buildDsym(clean=True)
51
52 self.exe_name = 'a.out'
53 self.do_add_dsym_with_dSYM_bundle(self.exe_name)
54
55
Johnny Chen82e5a262012-08-22 00:18:43 +000056 def generate_main_cpp(self, version=0):
57 """Generate main.cpp from main.cpp.template."""
58 temp = os.path.join(os.getcwd(), self.template)
59 with open(temp, 'r') as f:
60 content = f.read()
61
62 new_content = content.replace('%ADD_EXTRA_CODE%',
63 'printf("This is version %d\\n");' % version)
64 src = os.path.join(os.getcwd(), self.source)
65 with open(src, 'w') as f:
66 f.write(new_content)
67
68 # The main.cpp has been generated, add a teardown hook to remove it.
69 if not self.teardown_hook_added:
70 self.addTearDownHook(lambda: os.remove(src))
71 self.teardown_hook_added = True
72
73 def do_add_dsym_with_error(self, exe_name):
74 """Test that the 'add-dsym' command informs the user about failures."""
75 self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
76
Filipe Cabecinhas7d4c68a2012-09-12 14:43:45 +000077 wrong_path = os.path.join("%s.dSYM" % exe_name, "Contents")
Johnny Chen82e5a262012-08-22 00:18:43 +000078 self.expect("add-dsym " + wrong_path, error=True,
Filipe Cabecinhas7d4c68a2012-09-12 14:43:45 +000079 substrs = ['invalid module path'])
Johnny Chen82e5a262012-08-22 00:18:43 +000080
Filipe Cabecinhas7d4c68a2012-09-12 14:43:45 +000081 right_path = os.path.join("%s.dSYM" % exe_name, "Contents", "Resources", "DWARF", exe_name)
Johnny Chen82e5a262012-08-22 00:18:43 +000082 self.expect("add-dsym " + right_path, error=True,
Greg Clayton89deb062012-12-12 01:15:30 +000083 substrs = ['symbol file', 'does not match'])
Johnny Chen82e5a262012-08-22 00:18:43 +000084
85 def do_add_dsym_with_success(self, exe_name):
86 """Test that the 'add-dsym' command informs the user about success."""
87 self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
88
89 # This time, the UUID should match and we expect some feedback from lldb.
90 right_path = os.path.join("%s.dSYM" % exe_name, "Contents", "Resources", "DWARF", exe_name)
91 self.expect("add-dsym " + right_path,
Greg Clayton89deb062012-12-12 01:15:30 +000092 substrs = ['symbol file', 'has been added to'])
Johnny Chen82e5a262012-08-22 00:18:43 +000093
Filipe Cabecinhas7d4c68a2012-09-12 14:43:45 +000094 def do_add_dsym_with_dSYM_bundle(self, exe_name):
95 """Test that the 'add-dsym' command informs the user about success when loading files in bundles."""
96 self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET)
97
98 # This time, the UUID should be found inside the bundle
99 right_path = "%s.dSYM" % exe_name
100 self.expect("add-dsym " + right_path,
Greg Clayton89deb062012-12-12 01:15:30 +0000101 substrs = ['symbol file', 'has been added to'])
Filipe Cabecinhas7d4c68a2012-09-12 14:43:45 +0000102
Johnny Chen82e5a262012-08-22 00:18:43 +0000103
104if __name__ == '__main__':
105 import atexit
106 lldb.SBDebugger.Initialize()
107 atexit.register(lambda: lldb.SBDebugger.Terminate())
108 unittest2.main()