"""
Test the MemoryCache L1 flush.
"""
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil
class MemoryCacheTestCase(TestBase):
def setUp(self):
TestBase.setUp(self)
self.line = line_number("main.cpp", "// Set break point at this line.")
@skipIfWindows
def test_memory_cache(self):
"""Test the MemoryCache class with a sequence of 'memory read' and 'memory write' operations."""
self.build()
exe = self.getBuildArtifact("a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True
)
self.runCmd("run", RUN_SUCCEEDED)
self.expect(
"thread list",
STOPPED_DUE_TO_BREAKPOINT,
substrs=["stopped", "stop reason = breakpoint"],
)
lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
self.runCmd("memory read -f d -c 201 `&my_ints - 100`")
line = self.res.GetOutput().splitlines()[100]
self.assertEqual(0x00000042, int(line.split(":")[1], 0))
self.runCmd("memory write -s 4 `&my_ints` AA")
self.runCmd("memory read -f d -c 201 `&my_ints - 100`")
line = self.res.GetOutput().splitlines()[100]
self.assertEqual(0x000000AA, int(line.split(":")[1], 0))