llvm-project/lldb/test/functionalities/memory/read/TestMemoryRead.py

107 lines
4.1 KiB
Python
Raw Normal View History

"""
Test the 'memory read' command.
"""
import os, time
import re
import unittest2
import lldb
from lldbtest import *
import lldbutil
class MemoryReadTestCase(TestBase):
mydir = os.path.join("functionalities", "memory", "read")
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Add a new option to the test driver, -N dsym or -N dwarf, in order to exclude tests decorated with either @dsym_test or @dwarf_test to be executed during the testsuite run. There are still lots of Test*.py files which have not been decorated with the new decorator. An example: # From TestMyFirstWatchpoint.py -> class HelloWatchpointTestCase(TestBase): mydir = os.path.join("functionalities", "watchpoint", "hello_watchpoint") @dsym_test def test_hello_watchpoint_with_dsym_using_watchpoint_set(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDsym(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() @dwarf_test def test_hello_watchpoint_with_dwarf_using_watchpoint_set(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDwarf(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() # Invocation -> [17:50:14] johnny:/Volumes/data/lldb/svn/ToT/test $ ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py LLDB build dir: /Volumes/data/lldb/svn/ToT/build/Debug LLDB-137 Path: /Volumes/data/lldb/svn/ToT URL: https://johnny@llvm.org/svn/llvm-project/lldb/trunk Repository Root: https://johnny@llvm.org/svn/llvm-project Repository UUID: 91177308-0d34-0410-b5e6-96231b3b80d8 Revision: 154133 Node Kind: directory Schedule: normal Last Changed Author: gclayton Last Changed Rev: 154109 Last Changed Date: 2012-04-05 10:43:02 -0700 (Thu, 05 Apr 2012) Session logs for test failures/errors/unexpected successes will go into directory '2012-04-05-17_50_49' Command invoked: python ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py compilers=['clang'] Configuration: arch=x86_64 compiler=clang ---------------------------------------------------------------------- Collected 2 tests 1: test_hello_watchpoint_with_dsym_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... skipped 'dsym tests' 2: test_hello_watchpoint_with_dwarf_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... ok ---------------------------------------------------------------------- Ran 2 tests in 1.138s OK (skipped=1) Session logs for test failures/errors/unexpected successes can be found in directory '2012-04-05-17_50_49' [17:50:50] johnny:/Volumes/data/lldb/svn/ToT/test $ llvm-svn: 154154
2012-04-06 08:56:05 +08:00
@dsym_test
def test_memory_read_with_dsym(self):
"""Test the 'memory read' command with plain and vector formats."""
self.buildDsym()
self.memory_read_command()
Add a new option to the test driver, -N dsym or -N dwarf, in order to exclude tests decorated with either @dsym_test or @dwarf_test to be executed during the testsuite run. There are still lots of Test*.py files which have not been decorated with the new decorator. An example: # From TestMyFirstWatchpoint.py -> class HelloWatchpointTestCase(TestBase): mydir = os.path.join("functionalities", "watchpoint", "hello_watchpoint") @dsym_test def test_hello_watchpoint_with_dsym_using_watchpoint_set(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDsym(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() @dwarf_test def test_hello_watchpoint_with_dwarf_using_watchpoint_set(self): """Test a simple sequence of watchpoint creation and watchpoint hit.""" self.buildDwarf(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) self.hello_watchpoint() # Invocation -> [17:50:14] johnny:/Volumes/data/lldb/svn/ToT/test $ ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py LLDB build dir: /Volumes/data/lldb/svn/ToT/build/Debug LLDB-137 Path: /Volumes/data/lldb/svn/ToT URL: https://johnny@llvm.org/svn/llvm-project/lldb/trunk Repository Root: https://johnny@llvm.org/svn/llvm-project Repository UUID: 91177308-0d34-0410-b5e6-96231b3b80d8 Revision: 154133 Node Kind: directory Schedule: normal Last Changed Author: gclayton Last Changed Rev: 154109 Last Changed Date: 2012-04-05 10:43:02 -0700 (Thu, 05 Apr 2012) Session logs for test failures/errors/unexpected successes will go into directory '2012-04-05-17_50_49' Command invoked: python ./dotest.py -N dsym -v -p TestMyFirstWatchpoint.py compilers=['clang'] Configuration: arch=x86_64 compiler=clang ---------------------------------------------------------------------- Collected 2 tests 1: test_hello_watchpoint_with_dsym_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... skipped 'dsym tests' 2: test_hello_watchpoint_with_dwarf_using_watchpoint_set (TestMyFirstWatchpoint.HelloWatchpointTestCase) Test a simple sequence of watchpoint creation and watchpoint hit. ... ok ---------------------------------------------------------------------- Ran 2 tests in 1.138s OK (skipped=1) Session logs for test failures/errors/unexpected successes can be found in directory '2012-04-05-17_50_49' [17:50:50] johnny:/Volumes/data/lldb/svn/ToT/test $ llvm-svn: 154154
2012-04-06 08:56:05 +08:00
@dwarf_test
def test_memory_read_with_dwarf(self):
"""Test the 'memory read' command with plain and vector formats."""
self.buildDwarf()
self.memory_read_command()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
self.line = line_number('main.cpp', '// Set break point at this line.')
def memory_read_command(self):
"""Test the 'memory read' command with plain and vector formats."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Break in main() aftre the variables are assigned values.
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)
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped', 'stop reason = breakpoint'])
# The breakpoint should have a hit count of 1.
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])
# Test the memory read commands.
# (lldb) memory read -f d -c 1 `&argc`
# 0x7fff5fbff9a0: 1
self.runCmd("memory read -f d -c 1 `&argc`")
# Find the starting address for variable 'argc' to verify later that the
# '--format uint32_t[] --size 4 --count 4' option increments the address
# correctly.
line = self.res.GetOutput().splitlines()[0]
items = line.split(':')
address = int(items[0], 0)
argc = int(items[1], 0)
self.assertTrue(address > 0 and argc == 1)
# (lldb) memory read --format uint32_t[] --size 4 --count 4 `&argc`
# 0x7fff5fbff9a0: {0x00000001}
# 0x7fff5fbff9a4: {0x00000000}
# 0x7fff5fbff9a8: {0x0ec0bf27}
# 0x7fff5fbff9ac: {0x215db505}
self.runCmd("memory read --format uint32_t[] --size 4 --count 4 `&argc`")
lines = self.res.GetOutput().splitlines()
for i in range(4):
if i == 0:
# Verify that the printout for argc is correct.
self.assertTrue(argc == int(lines[i].split(':')[1].strip(' {}'), 0))
addr = int(lines[i].split(':')[0], 0)
# Verify that the printout for addr is incremented correctly.
self.assertTrue(addr == (address + i*4))
# (lldb) memory read --format char[] --size 7 --count 1 `&my_string`
# 0x7fff5fbff990: {abcdefg}
self.expect("memory read --format char[] --size 7 --count 1 `&my_string`",
substrs = ['abcdefg'])
# (lldb) memory read --format 'hex float' --size 16 `&argc`
# 0x7fff5fbff5b0: error: unsupported byte size (16) for hex float format
self.expect("memory read --format 'hex float' --size 16 `&argc`",
substrs = ['unsupported byte size (16) for hex float format'])
self.expect("memory read --format 'float' --count 1 --size 8 `&my_double`",
substrs = ['1234.'])
# (lldb) memory read --format 'float' --count 1 --size 20 `&my_double`
# 0x7fff5fbff598: error: unsupported byte size (20) for float format
self.expect("memory read --format 'float' --count 1 --size 20 `&my_double`",
substrs = ['unsupported byte size (20) for float format'])
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()