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        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
42
43        # Read a chunk of memory containing &my_ints[0]. The number of bytes read
44        # must be greater than m_L2_cache_line_byte_size to make sure the L1
45        # cache is used.
46        self.runCmd('memory read -f d -c 201 `&my_ints - 100`')
47
48        # Check the value of my_ints[0] is the same as set in main.cpp.
49        line = self.res.GetOutput().splitlines()[100]
50        self.assertEquals(0x00000042, int(line.split(':')[1], 0))
51
52        # Change the value of my_ints[0] in memory.
53        self.runCmd("memory write -s 4 `&my_ints` AA")
54
55        # Re-read the chunk of memory. The cache line should have been
56        # flushed because of the 'memory write'.
57        self.runCmd('memory read -f d -c 201 `&my_ints - 100`')
58
59        # Check the value of my_ints[0] have been updated correctly.
60        line = self.res.GetOutput().splitlines()[100]
61        self.assertEquals(0x000000AA, int(line.split(':')[1], 0))
62