Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 1 | """Test that the 'add-dsym', aka 'target symbols add', command informs the user about success or failure.""" |
| 2 | |
| 3 | import os, time |
| 4 | import unittest2 |
| 5 | import lldb |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 6 | from lldbtest import * |
| 7 | |
Robert Flack | 13c7ad9 | 2015-03-30 14:12:17 +0000 | [diff] [blame] | 8 | @skipUnlessDarwin |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 9 | class AddDsymCommandCase(TestBase): |
| 10 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 11 | mydir = TestBase.compute_mydir(__file__) |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 12 | |
| 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 Cabecinhas | 7d4c68a | 2012-09-12 14:43:45 +0000 | [diff] [blame] | 45 | 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 Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 56 | 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 Cabecinhas | 7d4c68a | 2012-09-12 14:43:45 +0000 | [diff] [blame] | 77 | wrong_path = os.path.join("%s.dSYM" % exe_name, "Contents") |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 78 | self.expect("add-dsym " + wrong_path, error=True, |
Filipe Cabecinhas | 7d4c68a | 2012-09-12 14:43:45 +0000 | [diff] [blame] | 79 | substrs = ['invalid module path']) |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 80 | |
Filipe Cabecinhas | 7d4c68a | 2012-09-12 14:43:45 +0000 | [diff] [blame] | 81 | right_path = os.path.join("%s.dSYM" % exe_name, "Contents", "Resources", "DWARF", exe_name) |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 82 | self.expect("add-dsym " + right_path, error=True, |
Greg Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 83 | substrs = ['symbol file', 'does not match']) |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 84 | |
| 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 Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 92 | substrs = ['symbol file', 'has been added to']) |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 93 | |
Filipe Cabecinhas | 7d4c68a | 2012-09-12 14:43:45 +0000 | [diff] [blame] | 94 | 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 Clayton | 89deb06 | 2012-12-12 01:15:30 +0000 | [diff] [blame] | 101 | substrs = ['symbol file', 'has been added to']) |
Filipe Cabecinhas | 7d4c68a | 2012-09-12 14:43:45 +0000 | [diff] [blame] | 102 | |
Johnny Chen | 82e5a26 | 2012-08-22 00:18:43 +0000 | [diff] [blame] | 103 | |
| 104 | if __name__ == '__main__': |
| 105 | import atexit |
| 106 | lldb.SBDebugger.Initialize() |
| 107 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 108 | unittest2.main() |