| 1 |
"""Test that the 'add-dsym', aka 'target symbols add', command informs the user about success or failure.""" |
| 2 |
|
| 3 |
|
| 4 |
import os |
| 5 |
import time |
| 6 |
import lldb |
| 7 |
from lldbsuite.test.decorators import * |
| 8 |
from lldbsuite.test.lldbtest import * |
| 9 |
from lldbsuite.test import lldbutil |
| 10 |
|
| 11 |
|
| 12 |
@skipUnlessDarwin |
| 13 |
class AddDsymCommandCase(TestBase): |
| 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 |
@no_debug_info_test |
| 21 |
def test_add_dsym_command_with_error(self): |
| 22 |
"""Test that the 'add-dsym' command informs the user about failures.""" |
| 23 |
|
| 24 |
# Call the program generator to produce main.cpp, version 1. |
| 25 |
self.generate_main_cpp(version=1) |
| 26 |
self.build(debug_info="dsym") |
| 27 |
|
| 28 |
# Insert some delay and then call the program generator to produce |
| 29 |
# main.cpp, version 2. |
| 30 |
time.sleep(5) |
| 31 |
self.generate_main_cpp(version=101) |
| 32 |
# Now call make again, but this time don't generate the dSYM. |
| 33 |
self.build(debug_info="dwarf") |
| 34 |
|
| 35 |
self.exe_name = "a.out" |
| 36 |
self.do_add_dsym_with_error(self.exe_name) |
| 37 |
|
| 38 |
@no_debug_info_test |
| 39 |
def test_add_dsym_command_with_success(self): |
| 40 |
"""Test that the 'add-dsym' command informs the user about success.""" |
| 41 |
|
| 42 |
# Call the program generator to produce main.cpp, version 1. |
| 43 |
self.generate_main_cpp(version=1) |
| 44 |
self.build(debug_info="dsym") |
| 45 |
|
| 46 |
self.exe_name = "a.out" |
| 47 |
self.do_add_dsym_with_success(self.exe_name) |
| 48 |
|
| 49 |
@no_debug_info_test |
| 50 |
def test_add_dsym_with_dSYM_bundle(self): |
| 51 |
"""Test that the 'add-dsym' command informs the user about success.""" |
| 52 |
|
| 53 |
# Call the program generator to produce main.cpp, version 1. |
| 54 |
self.generate_main_cpp(version=1) |
| 55 |
self.build(debug_info="dsym") |
| 56 |
|
| 57 |
self.exe_name = "a.out" |
| 58 |
self.do_add_dsym_with_dSYM_bundle(self.exe_name) |
| 59 |
|
| 60 |
def generate_main_cpp(self, version=0): |
| 61 |
"""Generate main.cpp from main.cpp.template.""" |
| 62 |
temp = os.path.join(self.getSourceDir(), self.template) |
| 63 |
with open(temp, "r") as f: |
| 64 |
content = f.read() |
| 65 |
|
| 66 |
new_content = content.replace( |
| 67 |
"%ADD_EXTRA_CODE%", 'printf("This is version %d\\n");' % version |
| 68 |
) |
| 69 |
src = os.path.join(self.getBuildDir(), self.source) |
| 70 |
with open(src, "w") as f: |
| 71 |
f.write(new_content) |
| 72 |
|
| 73 |
# The main.cpp has been generated, add a teardown hook to remove it. |
| 74 |
if not self.teardown_hook_added: |
| 75 |
self.addTearDownHook(lambda: os.remove(src)) |
| 76 |
self.teardown_hook_added = True |
| 77 |
|
| 78 |
def do_add_dsym_with_error(self, exe_name): |
| 79 |
"""Test that the 'add-dsym' command informs the user about failures.""" |
| 80 |
exe_path = self.getBuildArtifact(exe_name) |
| 81 |
self.runCmd("file " + exe_path, CURRENT_EXECUTABLE_SET) |
| 82 |
|
| 83 |
wrong_path = os.path.join(self.getBuildDir(), "%s.dSYM" % exe_name, "Contents") |
| 84 |
self.expect( |
| 85 |
"add-dsym " + wrong_path, error=True, substrs=["invalid module path"] |
| 86 |
) |
| 87 |
|
| 88 |
right_path = os.path.join( |
| 89 |
self.getBuildDir(), |
| 90 |
"%s.dSYM" % exe_path, |
| 91 |
"Contents", |
| 92 |
"Resources", |
| 93 |
"DWARF", |
| 94 |
exe_name, |
| 95 |
) |
| 96 |
self.expect( |
| 97 |
"add-dsym " + right_path, |
| 98 |
error=True, |
| 99 |
substrs=["symbol file", "does not match"], |
| 100 |
) |
| 101 |
|
| 102 |
def do_add_dsym_with_success(self, exe_name): |
| 103 |
"""Test that the 'add-dsym' command informs the user about success.""" |
| 104 |
exe_path = self.getBuildArtifact(exe_name) |
| 105 |
self.runCmd("file " + exe_path, CURRENT_EXECUTABLE_SET) |
| 106 |
|
| 107 |
# This time, the UUID should match and we expect some feedback from |
| 108 |
# lldb. |
| 109 |
right_path = os.path.join( |
| 110 |
self.getBuildDir(), |
| 111 |
"%s.dSYM" % exe_path, |
| 112 |
"Contents", |
| 113 |
"Resources", |
| 114 |
"DWARF", |
| 115 |
exe_name, |
| 116 |
) |
| 117 |
self.expect( |
| 118 |
"add-dsym " + right_path, substrs=["symbol file", "has been added to"] |
| 119 |
) |
| 120 |
|
| 121 |
def do_add_dsym_with_dSYM_bundle(self, exe_name): |
| 122 |
"""Test that the 'add-dsym' command informs the user about success when loading files in bundles.""" |
| 123 |
exe_path = self.getBuildArtifact(exe_name) |
| 124 |
self.runCmd("file " + exe_path, CURRENT_EXECUTABLE_SET) |
| 125 |
|
| 126 |
# This time, the UUID should be found inside the bundle |
| 127 |
right_path = "%s.dSYM" % exe_path |
| 128 |
self.expect( |
| 129 |
"add-dsym " + right_path, substrs=["symbol file", "has been added to"] |
| 130 |
) |