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
1899451b44SJordan Rupprecht    @no_debug_info_test
1999451b44SJordan Rupprecht    def test_paths(self):
2099451b44SJordan Rupprecht        '''Test to make sure no file names are set in the lldb.SBFileSpec objects returned by lldb.SBHostOS.GetLLDBPath() for paths that are directories'''
2199451b44SJordan Rupprecht        dir_path_types = [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,
2899451b44SJordan Rupprecht                          lldb.ePathTypeClangDir]
2999451b44SJordan Rupprecht
3099451b44SJordan Rupprecht        for path_type in dir_path_types:
3199451b44SJordan Rupprecht            f = lldb.SBHostOS.GetLLDBPath(path_type)
3299451b44SJordan Rupprecht            # No directory path types should have the filename set
33004a264fSPavel Labath            self.assertIsNone(f.GetFilename())
34004a264fSPavel Labath
35004a264fSPavel Labath        shlib_dir = lldb.SBHostOS.GetLLDBPath(lldb.ePathTypeLLDBShlibDir).GetDirectory()
36004a264fSPavel Labath        if lldbplatformutil.getHostPlatform() == 'windows':
37004a264fSPavel Labath            filenames = ['liblldb.dll']
38*21c5bb0aSPavel Labath        elif lldbplatformutil.getHostPlatform() == 'macosx':
39004a264fSPavel Labath            filenames = ['LLDB', 'liblldb.dylib']
40004a264fSPavel Labath        else:
41004a264fSPavel Labath            filenames = ['liblldb.so']
42004a264fSPavel Labath        self.assertTrue(any([os.path.exists(os.path.join(shlib_dir, f)) for f in
43004a264fSPavel Labath            filenames]), "shlib_dir = " + shlib_dir)
44004a264fSPavel Labath
45bbef51ebSLawrence D'Anna    @no_debug_info_test
46bbef51ebSLawrence D'Anna    def test_interpreter_info(self):
47bbef51ebSLawrence D'Anna        info_sd = self.dbg.GetScriptInterpreterInfo(self.dbg.GetScriptingLanguage("python"))
48bbef51ebSLawrence D'Anna        self.assertTrue(info_sd.IsValid())
49bbef51ebSLawrence D'Anna        stream = lldb.SBStream()
50779bbbf2SDave Lee        self.assertSuccess(info_sd.GetAsJSON(stream))
51bbef51ebSLawrence D'Anna        info = json.loads(stream.GetData())
52bbef51ebSLawrence D'Anna        prefix = info['prefix']
53bbef51ebSLawrence D'Anna        self.assertEqual(os.path.realpath(sys.prefix), os.path.realpath(prefix))
54bbef51ebSLawrence D'Anna        self.assertEqual(
55bbef51ebSLawrence D'Anna            os.path.realpath(os.path.join(info['lldb-pythonpath'], 'lldb')),
56bbef51ebSLawrence D'Anna            os.path.realpath(os.path.dirname(lldb.__file__)))
57bbef51ebSLawrence D'Anna        self.assertTrue(os.path.exists(info['executable']))
58bbef51ebSLawrence D'Anna        self.assertEqual(info['language'], 'python')
59bbef51ebSLawrence D'Anna
6099451b44SJordan Rupprecht
6199451b44SJordan Rupprecht    @no_debug_info_test
6299451b44SJordan Rupprecht    def test_directory_doesnt_end_with_slash(self):
6399451b44SJordan Rupprecht        current_directory_spec = lldb.SBFileSpec(os.path.curdir)
6499451b44SJordan Rupprecht        current_directory_string = current_directory_spec.GetDirectory()
6599451b44SJordan Rupprecht        self.assertNotEqual(current_directory_string[-1:], '/')
6699451b44SJordan Rupprecht
6799451b44SJordan Rupprecht    @skipUnlessPlatform(["windows"])
6899451b44SJordan Rupprecht    @no_debug_info_test
6999451b44SJordan Rupprecht    def test_windows_double_slash(self):
7099451b44SJordan Rupprecht        '''Test to check the path with double slash is handled correctly '''
7199451b44SJordan Rupprecht        # Create a path and see if lldb gets the directory and file right
7299451b44SJordan Rupprecht        fspec = lldb.SBFileSpec("C:\\dummy1\\dummy2//unknown_file", True)
7399451b44SJordan Rupprecht        self.assertEqual(
7499451b44SJordan Rupprecht            os.path.normpath(
7599451b44SJordan Rupprecht                fspec.GetDirectory()),
7699451b44SJordan Rupprecht            os.path.normpath("C:/dummy1/dummy2"))
7799451b44SJordan Rupprecht        self.assertEqual(fspec.GetFilename(), "unknown_file")
78