File: TestModuleCacheBSD.py

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-16
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,496,368 kB
  • sloc: cpp: 5,593,980; ansic: 986,873; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,547; xml: 953; cs: 573; fortran: 567
file content (85 lines) | stat: -rw-r--r-- 3,695 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""Test the LLDB module cache funcionality."""

import glob
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import os
import time


class ModuleCacheTestcaseBSD(TestBase):

    mydir = TestBase.compute_mydir(__file__)

    def setUp(self):
        # Call super's setUp().
        TestBase.setUp(self)
        # Find the line number in a(int) to break at.
        self.line_a = line_number(
            'a.c', '// Set file and line breakpoint inside a().')
        self.line_b = line_number(
            'b.c', '// Set file and line breakpoint inside b().')
        self.line_c = line_number(
            'c.c', '// Set file and line breakpoint inside c().')
        self.cache_dir = os.path.join(self.getBuildDir(), 'lldb-module-cache')
        # Set the lldb module cache directory to a directory inside the build
        # artifacts directory so no other tests are interfered with.
        self.runCmd('settings set symbols.lldb-index-cache-path "%s"' % (self.cache_dir))
        self.runCmd('settings set symbols.enable-lldb-index-cache true')
        self.build()


    def get_module_cache_files(self, basename):
        module_cache_glob = os.path.join(self.cache_dir, "llvmcache-*%s*symtab*" % (basename))
        return glob.glob(module_cache_glob)


    # Requires no dSYM, so we let the Makefile make the right stuff for us
    @no_debug_info_test
    @skipUnlessDarwin
    def test(self):
        """
            Test module cache functionality for bsd archive object files.

            This will test that if we enable the module cache, we have a
            corresponding cache entry for the .o files in libfoo.a.

            The static library has two entries for "a.o":
            - one from a.c
            - one from c.c which had c.o renamed to a.o and then put into the
              libfoo.a as an extra .o file with different contents from the
              original a.o

            We do this to test that we can correctly cache duplicate .o files
            that appear in .a files.

            This test only works on darwin because of the way DWARF is stored
            where the debug map will refer to .o files inside of .a files.
        """
        exe = self.getBuildArtifact("a.out")

        # Create a module with no depedencies.
        target = self.createTestTarget(load_dependent_modules=False)

        self.runCmd('breakpoint set -f a.c -l %d' % (self.line_a))
        self.runCmd('breakpoint set -f b.c -l %d' % (self.line_b))
        self.runCmd('breakpoint set -f c.c -l %d' % (self.line_c))

        # Get the executable module and get the number of symbols to make
        # sure the symbol table gets parsed and cached. The module cache is
        # enabled in the setUp() function.
        main_module = target.GetModuleAtIndex(0)
        self.assertTrue(main_module.IsValid())
        # Make sure the symbol table gets loaded and cached
        main_module.GetNumSymbols()
        a_o_cache_files = self.get_module_cache_files("libfoo.a(a.o)")
        b_o_cache_files = self.get_module_cache_files("libfoo.a(b.o)")
        # We expect the directory for a.o to have two cache directories:
        # - 1 for the a.o with a earlier mod time
        # - 1 for the a.o that was renamed from c.o that should be 2 seconds older
        self.assertEqual(len(a_o_cache_files), 2,
                "make sure there are two files in the module cache directory (%s) for libfoo.a(a.o)" % (self.cache_dir))
        self.assertEqual(len(b_o_cache_files), 1,
                "make sure there are two files in the module cache directory (%s) for libfoo.a(b.o)" % (self.cache_dir))