1""" 2Test the MemoryCache L1 flush. 3""" 4 5 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9import lldbsuite.test.lldbutil as lldbutil 10 11 12class MemoryCacheTestCase(TestBase): 13 def setUp(self): 14 # Call super's setUp(). 15 TestBase.setUp(self) 16 # Find the line number to break inside main(). 17 self.line = line_number("main.cpp", "// Set break point at this line.") 18 19 @skipIfWindows # This is flakey on Windows: llvm.org/pr38373 20 def test_memory_cache(self): 21 """Test the MemoryCache class with a sequence of 'memory read' and 'memory write' operations.""" 22 self.build() 23 exe = self.getBuildArtifact("a.out") 24 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 25 26 # Break in main() after the variables are assigned values. 27 lldbutil.run_break_set_by_file_and_line( 28 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True 29 ) 30 31 self.runCmd("run", RUN_SUCCEEDED) 32 33 # The stop reason of the thread should be breakpoint. 34 self.expect( 35 "thread list", 36 STOPPED_DUE_TO_BREAKPOINT, 37 substrs=["stopped", "stop reason = breakpoint"], 38 ) 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.assertEqual(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.assertEqual(0x000000AA, int(line.split(":")[1], 0)) 62