1da816ca0SGreg Clayton"""Test the LLDB module cache funcionality for universal mach-o files."""
2da816ca0SGreg Clayton
3da816ca0SGreg Claytonimport glob
4da816ca0SGreg Claytonimport lldb
5da816ca0SGreg Claytonfrom lldbsuite.test.decorators import *
6da816ca0SGreg Claytonfrom lldbsuite.test.lldbtest import *
7da816ca0SGreg Claytonfrom lldbsuite.test import lldbutil
8da816ca0SGreg Claytonimport os
9da816ca0SGreg Claytonimport time
10da816ca0SGreg Clayton
11da816ca0SGreg Clayton
12da816ca0SGreg Claytonclass ModuleCacheTestcaseUniversal(TestBase):
13da816ca0SGreg Clayton
14da816ca0SGreg Clayton    mydir = TestBase.compute_mydir(__file__)
15da816ca0SGreg Clayton
16da816ca0SGreg Clayton    def setUp(self):
17da816ca0SGreg Clayton        # Call super's setUp().
18da816ca0SGreg Clayton        TestBase.setUp(self)
19da816ca0SGreg Clayton        # Find the line number in a(int) to break at.
20da816ca0SGreg Clayton        self.cache_dir = os.path.join(self.getBuildDir(), 'lldb-module-cache')
21da816ca0SGreg Clayton        # Set the lldb module cache directory to a directory inside the build
22da816ca0SGreg Clayton        # artifacts directory so no other tests are interfered with.
23da816ca0SGreg Clayton        self.runCmd('settings set symbols.lldb-index-cache-path "%s"' % (self.cache_dir))
24da816ca0SGreg Clayton        self.runCmd('settings set symbols.enable-lldb-index-cache true')
25da816ca0SGreg Clayton
26da816ca0SGreg Clayton    def get_module_cache_files(self, basename):
27da816ca0SGreg Clayton        module_file_glob = os.path.join(self.cache_dir, "llvmcache-*%s*" % (basename))
28da816ca0SGreg Clayton        return glob.glob(module_file_glob)
29da816ca0SGreg Clayton
30da816ca0SGreg Clayton
31da816ca0SGreg Clayton    # Doesn't depend on any specific debug information.
32da816ca0SGreg Clayton    @no_debug_info_test
33da816ca0SGreg Clayton    @skipUnlessDarwin
34da816ca0SGreg Clayton    @skipIfDarwinEmbedded # this test file assumes we're targetting an x86 system
35da816ca0SGreg Clayton    def test(self):
36da816ca0SGreg Clayton        """
37da816ca0SGreg Clayton            Test module cache functionality for a universal mach-o files.
38da816ca0SGreg Clayton
39da816ca0SGreg Clayton            This will test that if we enable the module cache, we can create
40da816ca0SGreg Clayton            lldb module caches for each slice of a universal mach-o file and
41da816ca0SGreg Clayton            they will each have a unique directory.
42da816ca0SGreg Clayton        """
43da816ca0SGreg Clayton        exe_basename = "testit"
44*2a844c88SGreg Clayton        src_dir = self.getSourceDir()
45*2a844c88SGreg Clayton        yaml_path = os.path.join(src_dir, "universal.yaml")
46*2a844c88SGreg Clayton        yaml_base, ext = os.path.splitext(yaml_path)
47da816ca0SGreg Clayton        exe = self.getBuildArtifact(exe_basename)
48*2a844c88SGreg Clayton        self.yaml2obj(yaml_path, exe)
49*2a844c88SGreg Clayton        self.assertTrue(os.path.exists(exe))
50da816ca0SGreg Clayton        # Create a module with no depedencies.
51da816ca0SGreg Clayton        self.runCmd('target create -d --arch x86_64 %s' % (exe))
52da816ca0SGreg Clayton        self.runCmd('image dump symtab %s' % (exe_basename))
53da816ca0SGreg Clayton        self.runCmd('target create -d --arch arm64 %s' % (exe))
54da816ca0SGreg Clayton        self.runCmd('image dump symtab %s' % (exe_basename))
55da816ca0SGreg Clayton
56da816ca0SGreg Clayton        cache_files = self.get_module_cache_files(exe_basename)
57da816ca0SGreg Clayton
58da816ca0SGreg Clayton        self.assertEqual(len(cache_files), 2,
59da816ca0SGreg Clayton                "make sure there are two files in the module cache directory (%s) for %s" % (self.cache_dir, exe_basename))
60