xref: /llvm-project/lldb/test/API/functionalities/memory/cache/TestMemoryCache.py (revision 80fcecb13c388ff087a27a4b0e7ca3dd8c98eaa4)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest the MemoryCache L1 flush.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprechtimport lldb
799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
999451b44SJordan Rupprechtimport lldbsuite.test.lldbutil as lldbutil
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprechtclass MemoryCacheTestCase(TestBase):
1399451b44SJordan Rupprecht    def setUp(self):
1499451b44SJordan Rupprecht        # Call super's setUp().
1599451b44SJordan Rupprecht        TestBase.setUp(self)
1699451b44SJordan Rupprecht        # Find the line number to break inside main().
172238dcc3SJonas Devlieghere        self.line = line_number("main.cpp", "// Set break point at this line.")
1899451b44SJordan Rupprecht
1999451b44SJordan Rupprecht    @skipIfWindows  # This is flakey on Windows: llvm.org/pr38373
2099451b44SJordan Rupprecht    def test_memory_cache(self):
2199451b44SJordan Rupprecht        """Test the MemoryCache class with a sequence of 'memory read' and 'memory write' operations."""
2299451b44SJordan Rupprecht        self.build()
2399451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
2499451b44SJordan Rupprecht        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
2599451b44SJordan Rupprecht
2699451b44SJordan Rupprecht        # Break in main() after the variables are assigned values.
2799451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
282238dcc3SJonas Devlieghere            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True
292238dcc3SJonas Devlieghere        )
3099451b44SJordan Rupprecht
3199451b44SJordan Rupprecht        self.runCmd("run", RUN_SUCCEEDED)
3299451b44SJordan Rupprecht
3399451b44SJordan Rupprecht        # The stop reason of the thread should be breakpoint.
342238dcc3SJonas Devlieghere        self.expect(
352238dcc3SJonas Devlieghere            "thread list",
362238dcc3SJonas Devlieghere            STOPPED_DUE_TO_BREAKPOINT,
372238dcc3SJonas Devlieghere            substrs=["stopped", "stop reason = breakpoint"],
382238dcc3SJonas Devlieghere        )
3999451b44SJordan Rupprecht
4099451b44SJordan Rupprecht        # The breakpoint should have a hit count of 1.
419f0b5f9aSSYNOPSYS\georgiev        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
4299451b44SJordan Rupprecht
4399451b44SJordan Rupprecht        # Read a chunk of memory containing &my_ints[0]. The number of bytes read
4499451b44SJordan Rupprecht        # must be greater than m_L2_cache_line_byte_size to make sure the L1
4599451b44SJordan Rupprecht        # cache is used.
462238dcc3SJonas Devlieghere        self.runCmd("memory read -f d -c 201 `&my_ints - 100`")
4799451b44SJordan Rupprecht
4899451b44SJordan Rupprecht        # Check the value of my_ints[0] is the same as set in main.cpp.
4999451b44SJordan Rupprecht        line = self.res.GetOutput().splitlines()[100]
50*80fcecb1SJonas Devlieghere        self.assertEqual(0x00000042, int(line.split(":")[1], 0))
5199451b44SJordan Rupprecht
5299451b44SJordan Rupprecht        # Change the value of my_ints[0] in memory.
5399451b44SJordan Rupprecht        self.runCmd("memory write -s 4 `&my_ints` AA")
5499451b44SJordan Rupprecht
5599451b44SJordan Rupprecht        # Re-read the chunk of memory. The cache line should have been
5699451b44SJordan Rupprecht        # flushed because of the 'memory write'.
572238dcc3SJonas Devlieghere        self.runCmd("memory read -f d -c 201 `&my_ints - 100`")
5899451b44SJordan Rupprecht
5999451b44SJordan Rupprecht        # Check the value of my_ints[0] have been updated correctly.
6099451b44SJordan Rupprecht        line = self.res.GetOutput().splitlines()[100]
61*80fcecb1SJonas Devlieghere        self.assertEqual(0x000000AA, int(line.split(":")[1], 0))
62