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