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