Newer
Older
Johnny Chen
committed
"""
LLDB module which provides the abstract base class of lldb test case.
The concrete subclass can override lldbtest.TesBase in order to inherit the
common behavior for unitest.TestCase.setUp/tearDown implemented in this file.
The subclass should override the attribute mydir in order for the python runtime
to locate the individual test cases when running as part of a large test suite
or when running each test case as a separate python invocation.
./dotest.py provides a test driver which sets up the environment to run the
Johnny Chen
committed
entire of part of the test suite . Example:
Johnny Chen
committed
Johnny Chen
committed
# Exercises the test suite in the types directory....
/Volumes/data/lldb/svn/ToT/test $ ./dotest.py -A x86_64 types
Johnny Chen
committed
...
Johnny Chen
committed
Session logs for test failures/errors/unexpected successes will go into directory '2012-05-16-13_35_42'
Command invoked: python ./dotest.py -A x86_64 types
compilers=['clang']
Johnny Chen
committed
Configuration: arch=x86_64 compiler=clang
----------------------------------------------------------------------
Collected 72 tests
Johnny Chen
committed
........................................................................
----------------------------------------------------------------------
Johnny Chen
committed
Ran 72 tests in 135.468s
Johnny Chen
committed
OK
$
"""
import os, sys, traceback
Enrico Granata
committed
import os.path
Johnny Chen
committed
import re
Johnny Chen
committed
from subprocess import *
import StringIO
import time
Johnny Chen
committed
import types
import unittest2
Johnny Chen
committed
import lldb
Johnny Chen
committed
# See also dotest.parseOptionsAndInitTestdirs(), where the environment variables
# LLDB_COMMAND_TRACE and LLDB_DO_CLEANUP are set from '-t' and '-r dir' options.
Johnny Chen
committed
# By default, traceAlways is False.
Johnny Chen
committed
if "LLDB_COMMAND_TRACE" in os.environ and os.environ["LLDB_COMMAND_TRACE"]=="YES":
traceAlways = True
else:
traceAlways = False
Johnny Chen
committed
# By default, doCleanup is True.
if "LLDB_DO_CLEANUP" in os.environ and os.environ["LLDB_DO_CLEANUP"]=="NO":
doCleanup = False
else:
doCleanup = True
Johnny Chen
committed
Johnny Chen
committed
#
# Some commonly used assert messages.
#
COMMAND_FAILED_AS_EXPECTED = "Command has failed as expected"
Johnny Chen
committed
CURRENT_EXECUTABLE_SET = "Current executable set successfully"
Johnny Chen
committed
PROCESS_IS_VALID = "Process is valid"
PROCESS_KILLED = "Process is killed successfully"
PROCESS_EXITED = "Process exited successfully"
PROCESS_STOPPED = "Process status should be stopped"
Johnny Chen
committed
RUN_SUCCEEDED = "Process is launched successfully"
Johnny Chen
committed
RUN_COMPLETED = "Process exited successfully"
Johnny Chen
committed
Johnny Chen
committed
BACKTRACE_DISPLAYED_CORRECTLY = "Backtrace displayed correctly"
BREAKPOINT_CREATED = "Breakpoint created successfully"
Johnny Chen
committed
BREAKPOINT_STATE_CORRECT = "Breakpoint state is correct"
BREAKPOINT_PENDING_CREATED = "Pending breakpoint created successfully"
BREAKPOINT_HIT_ONCE = "Breakpoint resolved with hit cout = 1"
Johnny Chen
committed
BREAKPOINT_HIT_TWICE = "Breakpoint resolved with hit cout = 2"
BREAKPOINT_HIT_THRICE = "Breakpoint resolved with hit cout = 3"
MISSING_EXPECTED_REGISTERS = "At least one expected register is unavailable."
OBJECT_PRINTED_CORRECTLY = "Object printed correctly"
Johnny Chen
committed
SOURCE_DISPLAYED_CORRECTLY = "Source code displayed correctly"
STEP_OUT_SUCCEEDED = "Thread step-out succeeded"
Johnny Chen
committed
STOPPED_DUE_TO_EXC_BAD_ACCESS = "Process should be stopped due to bad access exception"
Ashok Thirumurthi
committed
STOPPED_DUE_TO_ASSERT = "Process should be stopped due to an assertion"
STOPPED_DUE_TO_BREAKPOINT = "Process should be stopped due to breakpoint"
Johnny Chen
committed
STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS = "%s, %s" % (
STOPPED_DUE_TO_BREAKPOINT, "instead, the actual stop reason is: '%s'")
Johnny Chen
committed
Johnny Chen
committed
STOPPED_DUE_TO_BREAKPOINT_CONDITION = "Stopped due to breakpoint condition"
Johnny Chen
committed
STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT = "Stopped due to breakpoint and ignore count"
Johnny Chen
committed
STOPPED_DUE_TO_SIGNAL = "Process state is stopped due to signal"
Johnny Chen
committed
STOPPED_DUE_TO_STEP_IN = "Process state is stopped due to step in"
Johnny Chen
committed
STOPPED_DUE_TO_WATCHPOINT = "Process should be stopped due to watchpoint"
DATA_TYPES_DISPLAYED_CORRECTLY = "Data type(s) displayed correctly"
VALID_BREAKPOINT = "Got a valid breakpoint"
VALID_BREAKPOINT_LOCATION = "Got a valid breakpoint location"
VALID_COMMAND_INTERPRETER = "Got a valid command interpreter"
Johnny Chen
committed
VALID_FILESPEC = "Got a valid filespec"
Johnny Chen
committed
VALID_MODULE = "Got a valid module"
VALID_PROCESS = "Got a valid process"
Johnny Chen
committed
VALID_SYMBOL = "Got a valid symbol"
VALID_TARGET = "Got a valid target"
VALID_TYPE = "Got a valid type"
VALID_VARIABLE = "Got a valid variable"
Johnny Chen
committed
VARIABLES_DISPLAYED_CORRECTLY = "Variable(s) displayed correctly"
Johnny Chen
committed
Johnny Chen
committed
WATCHPOINT_CREATED = "Watchpoint created successfully"
def CMD_MSG(str):
'''A generic "Command '%s' returns successfully" message generator.'''
return "Command '%s' returns successfully" % str
Johnny Chen
committed
def COMPLETION_MSG(str_before, str_after):
'''A generic message generator for the completion mechanism.'''
return "'%s' successfully completes to '%s'" % (str_before, str_after)
def EXP_MSG(str, exe):
'''A generic "'%s' returns expected result" message generator if exe.
Otherwise, it generates "'%s' matches expected result" message.'''
return "'%s' %s expected result" % (str, 'returns' if exe else 'matches')
def SETTING_MSG(setting):
'''A generic "Value of setting '%s' is correct" message generator.'''
return "Value of setting '%s' is correct" % setting
"""Returns an env variable array from the os.environ map object."""
return map(lambda k,v: k+"="+v, os.environ.keys(), os.environ.values())
Johnny Chen
committed
def line_number(filename, string_to_match):
"""Helper function to return the line number of the first matched string."""
with open(filename, 'r') as f:
for i, line in enumerate(f):
if line.find(string_to_match) != -1:
# Found our match.
return i+1
Johnny Chen
committed
raise Exception("Unable to find '%s' within file %s" % (string_to_match, filename))
Johnny Chen
committed
Johnny Chen
committed
def pointer_size():
"""Return the pointer size of the host system."""
import ctypes
a_pointer = ctypes.c_void_p(0xffff)
return 8 * ctypes.sizeof(a_pointer)
Johnny Chen
committed
def is_exe(fpath):
"""Returns true if fpath is an executable."""
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
def which(program):
"""Returns the full path to a program; None otherwise."""
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
Loading
Loading full blame...