xref: /llvm-project/lldb/test/API/functionalities/paths/TestPaths.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest some lldb command abbreviations.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprechtimport lldb
799451b44SJordan Rupprechtimport os
8bbef51ebSLawrence D'Annaimport sys
9bbef51ebSLawrence D'Annaimport json
1099451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
1199451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
1299451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
13004a264fSPavel Labathfrom lldbsuite.test import lldbplatformutil
1499451b44SJordan Rupprecht
1599451b44SJordan Rupprecht
1699451b44SJordan Rupprechtclass TestPaths(TestBase):
1799451b44SJordan Rupprecht    @no_debug_info_test
1899451b44SJordan Rupprecht    def test_paths(self):
19*2238dcc3SJonas Devlieghere        """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*2238dcc3SJonas Devlieghere        dir_path_types = [
21*2238dcc3SJonas Devlieghere            lldb.ePathTypeLLDBShlibDir,
2299451b44SJordan Rupprecht            lldb.ePathTypeSupportExecutableDir,
2399451b44SJordan Rupprecht            lldb.ePathTypeHeaderDir,
2499451b44SJordan Rupprecht            lldb.ePathTypePythonDir,
2599451b44SJordan Rupprecht            lldb.ePathTypeLLDBSystemPlugins,
2699451b44SJordan Rupprecht            lldb.ePathTypeLLDBUserPlugins,
2799451b44SJordan Rupprecht            lldb.ePathTypeLLDBTempSystemDir,
28*2238dcc3SJonas Devlieghere            lldb.ePathTypeClangDir,
29*2238dcc3SJonas Devlieghere        ]
3099451b44SJordan Rupprecht
3199451b44SJordan Rupprecht        for path_type in dir_path_types:
3299451b44SJordan Rupprecht            f = lldb.SBHostOS.GetLLDBPath(path_type)
3399451b44SJordan Rupprecht            # No directory path types should have the filename set
34004a264fSPavel Labath            self.assertIsNone(f.GetFilename())
35004a264fSPavel Labath
36004a264fSPavel Labath        shlib_dir = lldb.SBHostOS.GetLLDBPath(lldb.ePathTypeLLDBShlibDir).GetDirectory()
37*2238dcc3SJonas Devlieghere        if lldbplatformutil.getHostPlatform() == "windows":
38*2238dcc3SJonas Devlieghere            filenames = ["liblldb.dll"]
39*2238dcc3SJonas Devlieghere        elif lldbplatformutil.getHostPlatform() == "macosx":
40*2238dcc3SJonas Devlieghere            filenames = ["LLDB", "liblldb.dylib"]
41004a264fSPavel Labath        else:
42*2238dcc3SJonas Devlieghere            filenames = ["liblldb.so"]
43*2238dcc3SJonas Devlieghere        self.assertTrue(
44*2238dcc3SJonas Devlieghere            any([os.path.exists(os.path.join(shlib_dir, f)) for f in filenames]),
45*2238dcc3SJonas Devlieghere            "shlib_dir = " + shlib_dir,
46*2238dcc3SJonas Devlieghere        )
47004a264fSPavel Labath
48bbef51ebSLawrence D'Anna    @no_debug_info_test
49bbef51ebSLawrence D'Anna    def test_interpreter_info(self):
50*2238dcc3SJonas Devlieghere        info_sd = self.dbg.GetScriptInterpreterInfo(
51*2238dcc3SJonas Devlieghere            self.dbg.GetScriptingLanguage("python")
52*2238dcc3SJonas Devlieghere        )
53bbef51ebSLawrence D'Anna        self.assertTrue(info_sd.IsValid())
54bbef51ebSLawrence D'Anna        stream = lldb.SBStream()
55779bbbf2SDave Lee        self.assertSuccess(info_sd.GetAsJSON(stream))
56bbef51ebSLawrence D'Anna        info = json.loads(stream.GetData())
57*2238dcc3SJonas Devlieghere        prefix = info["prefix"]
58bbef51ebSLawrence D'Anna        self.assertEqual(os.path.realpath(sys.prefix), os.path.realpath(prefix))
59bbef51ebSLawrence D'Anna        self.assertEqual(
60*2238dcc3SJonas Devlieghere            os.path.realpath(os.path.join(info["lldb-pythonpath"], "lldb")),
61*2238dcc3SJonas Devlieghere            os.path.realpath(os.path.dirname(lldb.__file__)),
62*2238dcc3SJonas Devlieghere        )
63*2238dcc3SJonas Devlieghere        self.assertTrue(os.path.exists(info["executable"]))
64*2238dcc3SJonas Devlieghere        self.assertEqual(info["language"], "python")
6599451b44SJordan Rupprecht
6699451b44SJordan Rupprecht    @no_debug_info_test
6799451b44SJordan Rupprecht    def test_directory_doesnt_end_with_slash(self):
6899451b44SJordan Rupprecht        current_directory_spec = lldb.SBFileSpec(os.path.curdir)
6999451b44SJordan Rupprecht        current_directory_string = current_directory_spec.GetDirectory()
70*2238dcc3SJonas Devlieghere        self.assertNotEqual(current_directory_string[-1:], "/")
7199451b44SJordan Rupprecht
7299451b44SJordan Rupprecht    @skipUnlessPlatform(["windows"])
7399451b44SJordan Rupprecht    @no_debug_info_test
7499451b44SJordan Rupprecht    def test_windows_double_slash(self):
75*2238dcc3SJonas Devlieghere        """Test to check the path with double slash is handled correctly"""
7699451b44SJordan Rupprecht        # Create a path and see if lldb gets the directory and file right
7799451b44SJordan Rupprecht        fspec = lldb.SBFileSpec("C:\\dummy1\\dummy2//unknown_file", True)
7899451b44SJordan Rupprecht        self.assertEqual(
79*2238dcc3SJonas Devlieghere            os.path.normpath(fspec.GetDirectory()), os.path.normpath("C:/dummy1/dummy2")
80*2238dcc3SJonas Devlieghere        )
8199451b44SJordan Rupprecht        self.assertEqual(fspec.GetFilename(), "unknown_file")
82