• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Test the MemoryCache L1 flush.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10import lldbsuite.test.lldbutil as lldbutil
11
12
13class MemoryCacheTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    def setUp(self):
18        # Call super's setUp().
19        TestBase.setUp(self)
20        # Find the line number to break inside main().
21        self.line = line_number('main.cpp', '// Set break point at this line.')
22
23    @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
24    def test_memory_cache(self):
25        """Test the MemoryCache class with a sequence of 'memory read' and 'memory write' operations."""
26        self.build()
27        exe = self.getBuildArtifact("a.out")
28        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
29
30        # Break in main() after the variables are assigned values.
31        lldbutil.run_break_set_by_file_and_line(
32            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
33
34        self.runCmd("run", RUN_SUCCEEDED)
35
36        # The stop reason of the thread should be breakpoint.
37        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38                    substrs=['stopped', 'stop reason = breakpoint'])
39
40        # The breakpoint should have a hit count of 1.
41        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
42                    substrs=[' resolved, hit count = 1'])
43
44        # Read a chunk of memory containing &my_ints[0]. The number of bytes read
45        # must be greater than m_L2_cache_line_byte_size to make sure the L1
46        # cache is used.
47        self.runCmd('memory read -f d -c 201 `&my_ints - 100`')
48
49        # Check the value of my_ints[0] is the same as set in main.cpp.
50        line = self.res.GetOutput().splitlines()[100]
51        self.assertEquals(0x00000042, int(line.split(':')[1], 0))
52
53        # Change the value of my_ints[0] in memory.
54        self.runCmd("memory write -s 4 `&my_ints` AA")
55
56        # Re-read the chunk of memory. The cache line should have been
57        # flushed because of the 'memory write'.
58        self.runCmd('memory read -f d -c 201 `&my_ints - 100`')
59
60        # Check the value of my_ints[0] have been updated correctly.
61        line = self.res.GetOutput().splitlines()[100]
62        self.assertEquals(0x000000AA, int(line.split(':')[1], 0))
63