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 |
| 6 | import pexpect |
| 7 | from lldbtest import * |
| 8 | |
| 9 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 10 | class AddDsymCommandCase(TestBase): |
| 11 | |
| 12 | mydir = os.path.join("warnings", "uuid") |
| 13 | |
| 14 | def setUp(self): |
| 15 | TestBase.setUp(self) |
| 16 | self.template = 'main.cpp.template' |
| 17 | self.source = 'main.cpp' |
| 18 | self.teardown_hook_added = False |
| 19 | |
| 20 | def test_add_dsym_command_with_error(self): |
| 21 | """Test that the 'add-dsym' command informs the user about failures.""" |
| 22 | |
| 23 | # Call the program generator to produce main.cpp, version 1. |
| 24 | self.generate_main_cpp(version=1) |
| 25 | self.buildDsym(clean=True) |
| 26 | |
| 27 | # Insert some delay and then call the program generator to produce main.cpp, version 2. |
| 28 | time.sleep(5) |
| 29 | self.generate_main_cpp(version=101) |
| 30 | # Now call make again, but this time don't generate the dSYM. |
| 31 | self.buildDwarf(clean=False) |
| 32 | |
| 33 | self.exe_name = 'a.out' |
| 34 | self.do_add_dsym_with_error(self.exe_name) |
| 35 | |
| 36 | def test_add_dsym_command_with_success(self): |
| 37 | """Test that the 'add-dsym' command informs the user about success.""" |
| 38 | |
| 39 | # Call the program generator to produce main.cpp, version 1. |
| 40 | self.generate_main_cpp(version=1) |
| 41 | self.buildDsym(clean=True) |
| 42 | |
| 43 | self.exe_name = 'a.out' |
| 44 | self.do_add_dsym_with_success(self.exe_name) |
| 45 | |
| 46 | def generate_main_cpp(self, version=0): |
| 47 | """Generate main.cpp from main.cpp.template.""" |
| 48 | temp = os.path.join(os.getcwd(), self.template) |
| 49 | with open(temp, 'r') as f: |
| 50 | content = f.read() |
| 51 | |
| 52 | new_content = content.replace('%ADD_EXTRA_CODE%', |
| 53 | 'printf("This is version %d\\n");' % version) |
| 54 | src = os.path.join(os.getcwd(), self.source) |
| 55 | with open(src, 'w') as f: |
| 56 | f.write(new_content) |
| 57 | |
| 58 | # The main.cpp has been generated, add a teardown hook to remove it. |
| 59 | if not self.teardown_hook_added: |
| 60 | self.addTearDownHook(lambda: os.remove(src)) |
| 61 | self.teardown_hook_added = True |
| 62 | |
| 63 | def do_add_dsym_with_error(self, exe_name): |
| 64 | """Test that the 'add-dsym' command informs the user about failures.""" |
| 65 | self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET) |
| 66 | |
| 67 | wrong_path = "%s.dSYM" % exe_name |
| 68 | self.expect("add-dsym " + wrong_path, error=True, |
| 69 | substrs = ['symbol file', 'with UUID', 'does not match', |
| 70 | 'please specify the full path to the symbol file']) |
| 71 | |
| 72 | right_path = os.path.join(wrong_path, "Contents", "Resources", "DWARF", exe_name) |
| 73 | self.expect("add-dsym " + right_path, error=True, |
| 74 | substrs = ['symbol file', 'with UUID', 'does not match']) |
| 75 | |
| 76 | def do_add_dsym_with_success(self, exe_name): |
| 77 | """Test that the 'add-dsym' command informs the user about success.""" |
| 78 | self.runCmd("file " + exe_name, CURRENT_EXECUTABLE_SET) |
| 79 | |
| 80 | # This time, the UUID should match and we expect some feedback from lldb. |
| 81 | right_path = os.path.join("%s.dSYM" % exe_name, "Contents", "Resources", "DWARF", exe_name) |
| 82 | self.expect("add-dsym " + right_path, |
| 83 | substrs = ['symbol file', 'with UUID', 'has been successfully added to the', |
| 84 | 'module']) |
| 85 | |
| 86 | |
| 87 | if __name__ == '__main__': |
| 88 | import atexit |
| 89 | lldb.SBDebugger.Initialize() |
| 90 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 91 | unittest2.main() |