82 lines · python
1"""2Test some lldb command abbreviations.3"""4 5 6import lldb7import os8import sys9import json10from lldbsuite.test.decorators import *11from lldbsuite.test.lldbtest import *12from lldbsuite.test import lldbutil13from lldbsuite.test import lldbplatformutil14 15 16class TestPaths(TestBase):17 @no_debug_info_test18 def test_paths(self):19 """Test to make sure no file names are set in the lldb.SBFileSpec objects returned by lldb.SBHostOS.GetLLDBPath() for paths that are directories"""20 dir_path_types = [21 lldb.ePathTypeLLDBShlibDir,22 lldb.ePathTypeSupportExecutableDir,23 lldb.ePathTypeHeaderDir,24 lldb.ePathTypePythonDir,25 lldb.ePathTypeLLDBSystemPlugins,26 lldb.ePathTypeLLDBUserPlugins,27 lldb.ePathTypeLLDBTempSystemDir,28 lldb.ePathTypeClangDir,29 ]30 31 for path_type in dir_path_types:32 f = lldb.SBHostOS.GetLLDBPath(path_type)33 # No directory path types should have the filename set34 self.assertIsNone(f.GetFilename())35 36 shlib_dir = lldb.SBHostOS.GetLLDBPath(lldb.ePathTypeLLDBShlibDir).GetDirectory()37 if lldbplatformutil.getHostPlatform() == "windows":38 filenames = ["liblldb.dll"]39 elif lldbplatformutil.getHostPlatform() == "macosx":40 filenames = ["LLDB", "liblldb.dylib"]41 else:42 filenames = ["liblldb.so"]43 self.assertTrue(44 any([os.path.exists(os.path.join(shlib_dir, f)) for f in filenames]),45 "shlib_dir = " + shlib_dir,46 )47 48 @no_debug_info_test49 def test_interpreter_info(self):50 info_sd = self.dbg.GetScriptInterpreterInfo(51 self.dbg.GetScriptingLanguage("python")52 )53 self.assertTrue(info_sd.IsValid())54 stream = lldb.SBStream()55 self.assertSuccess(info_sd.GetAsJSON(stream))56 info = json.loads(stream.GetData())57 prefix = info["prefix"]58 self.assertEqual(os.path.realpath(sys.prefix), os.path.realpath(prefix))59 self.assertEqual(60 os.path.realpath(os.path.join(info["lldb-pythonpath"], "lldb")),61 os.path.realpath(os.path.dirname(lldb.__file__)),62 )63 self.assertTrue(os.path.exists(info["executable"]))64 self.assertEqual(info["language"], "python")65 66 @no_debug_info_test67 def test_directory_doesnt_end_with_slash(self):68 current_directory_spec = lldb.SBFileSpec(os.path.curdir)69 current_directory_string = current_directory_spec.GetDirectory()70 self.assertNotEqual(current_directory_string[-1:], "/")71 72 @skipUnlessPlatform(["windows"])73 @no_debug_info_test74 def test_windows_double_slash(self):75 """Test to check the path with double slash is handled correctly"""76 # Create a path and see if lldb gets the directory and file right77 fspec = lldb.SBFileSpec("C:\\dummy1\\dummy2//unknown_file", True)78 self.assertEqual(79 os.path.normpath(fspec.GetDirectory()), os.path.normpath("C:/dummy1/dummy2")80 )81 self.assertEqual(fspec.GetFilename(), "unknown_file")82