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