1"""
2Test 'target modules dump pcm-info'.
3"""
4
5import os
6import shutil
7import glob
8
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class TestCase(TestBase):
15    @no_debug_info_test
16    @skipUnlessDarwin
17    def test(self):
18        self.build()
19
20        lldbutil.run_to_source_breakpoint(
21            self, "return", lldb.SBFileSpec("main.m"))
22
23        mod_cache = self.getBuildArtifact("private-module-cache")
24        if os.path.isdir(mod_cache):
25            shutil.rmtree(mod_cache)
26
27        self.runCmd(f"settings set symbols.clang-modules-cache-path '{mod_cache}'")
28
29        # Cause lldb to generate a Darwin-*.pcm
30        self.runCmd("p @import Darwin")
31
32        # root/<config-hash>/<module-name>-<modulemap-path-hash>.pcm
33        pcm_paths = glob.glob(os.path.join(mod_cache, '*', 'Darwin-*.pcm'))
34        self.assertEqual(len(pcm_paths), 1, "Expected one Darwin pcm")
35        pcm_path = pcm_paths[0]
36
37        self.expect(
38            f"target modules dump pcm-info '{pcm_path}'",
39            startstr=f"Information for module file '{pcm_path}'",
40            substrs=["Module name: Darwin"])
41