1061da546SpatrickThis README file describes the files and directories related -*- rst -*- 2061da546Spatrickto the Python test suite under the current 'test' directory. 3061da546Spatrick 4061da546Spatrick- dotest.py 5061da546Spatrick 6061da546Spatrick Provides the test driver for the test suite. To invoke it, cd to the 'test' 7061da546Spatrick directory and issue the './dotest.py' command or './dotest.py -v' for more 8061da546Spatrick verbose output. '.dotest.py -h' prints out the help messge. 9061da546Spatrick 10061da546Spatrick A specific naming pattern is followed by the .py script under the 'test' 11061da546Spatrick directory in order to be recognized by 'dotest.py' test driver as a module 12061da546Spatrick which implements a test case, namely, Test*.py. 13061da546Spatrick 14061da546Spatrick Some example usages: 15061da546Spatrick 16061da546Spatrick 1. ./dotest.py -v . 2> ~/Developer/Log/lldbtest.log0 17061da546Spatrick This runs the test suite and directs the run log to a file. 18061da546Spatrick 19061da546Spatrick 2. LLDB_LOG=/tmp/lldb.log GDB_REMOTE_LOG=/tmp/gdb-remote.log ./dotest.py -v . 2> ~/Developer/Log/lldbtest.log 20061da546Spatrick This runs the test suite, with logging turned on for the lldb as well as 21061da546Spatrick the process.gdb-remote channels and directs the run log to a file. 22061da546Spatrick 23061da546Spatrick- lldbtest.py 24061da546Spatrick 25061da546Spatrick Provides an abstract base class of lldb test case named 'TestBase', which in 26061da546Spatrick turn inherits from Python's unittest.TestCase. The concrete subclass can 27061da546Spatrick override lldbtest.TestBase in order to inherit the common behavior for 28061da546Spatrick unittest.TestCase.setUp/tearDown implemented in this file. 29061da546Spatrick 30061da546Spatrick To provide a test case, the concrete subclass provides methods whose names 31061da546Spatrick start with the letters test. For more details about the Python's unittest 32061da546Spatrick framework, go to http://docs.python.org/library/unittest.html. 33061da546Spatrick 34061da546Spatrick ./command_source/TestCommandSource.py provides a simple example of test case 35061da546Spatrick which overrides lldbtest.TestBase to exercise the lldb's 'command source' 36*f6aab3d8Srobert command. 37061da546Spatrick 38061da546Spatrick The doc string provides more details about the setup required for running a 39061da546Spatrick test case on its own. To run the whole test suite, 'dotest.py' is all you 40061da546Spatrick need to do. 41061da546Spatrick 42061da546Spatrick- subdirectories of 'test' 43061da546Spatrick 44061da546Spatrick Most of them predate the introduction of the python test suite and contain 45061da546Spatrick example C/C++/ObjC source files which get compiled into executables which are 46061da546Spatrick to be exercised by the debugger. 47061da546Spatrick 48061da546Spatrick For such subdirectory which has an associated Test*.py file, it was added as 49061da546Spatrick part of the Python-based test suite to test lldb functionality. 50061da546Spatrick 51061da546Spatrick Some of the subdirectories, for example, the 'help' subdirectory, do not have 52061da546Spatrick C/C++/ObjC source files; they were created to house the Python test case which 53061da546Spatrick does not involve lldb reading in an executable file at all. 54061da546Spatrick 55061da546Spatrick The sample_test directory contains examples of both a full and an "inline" 56061da546Spatrick testcase that run a process to a breakpoint and check a local variable. These 57061da546Spatrick are convenient starting points for adding new tests. 58061da546Spatrick 59061da546Spatrick- make directory 60061da546Spatrick 61061da546Spatrick Contains Makefile.rules, which can be utilized by test cases to write Makefile 62061da546Spatrick based rules to build binaries for the inferiors. 63061da546Spatrick 64061da546Spatrick By default, the built executable name is a.out, which can be overwritten by 65061da546Spatrick specifying your EXE make variable, via the Makefile under the specific test 66061da546Spatrick directory or via supplying a Python dictionary to the build method in your 67061da546Spatrick Python test script. An example of the latter can be found in 68061da546Spatrick test/lang/objc/radar-9691614/TestObjCMethodReturningBOOL.py, where: 69061da546Spatrick 70*f6aab3d8Srobert def test_method_ret_BOOL(self): 71061da546Spatrick """Test that objective-c method returning BOOL works correctly.""" 72061da546Spatrick d = {'EXE': self.exe_name} 73*f6aab3d8Srobert self.build(dictionary=d) 74061da546Spatrick self.setTearDownCleanup(dictionary=d) 75*f6aab3d8Srobert ... 76061da546Spatrick 77061da546Spatrick def setUp(self): 78061da546Spatrick # Call super's setUp(). 79061da546Spatrick TestBase.setUp(self) 80061da546Spatrick # We'll use the test method name as the exe_name. 81061da546Spatrick self.exe_name = self.testMethodName 82061da546Spatrick # Find the line number to break inside main(). 83061da546Spatrick self.main_source = "main.m" 84061da546Spatrick self.line = line_number(self.main_source, '// Set breakpoint here.') 85061da546Spatrick 86061da546Spatrick The exe names for the two test methods are equal to the test method names and 87061da546Spatrick are therefore guaranteed different. 88061da546Spatrick 89061da546Spatrick- plugins directory 90061da546Spatrick 91061da546Spatrick Contains platform specific plugin to build binaries with dsym/dwarf debugging 92061da546Spatrick info. Other platform specific functionalities may be added in the future. 93061da546Spatrick 94061da546Spatrick- unittest2 directory 95061da546Spatrick 96061da546Spatrick Many new features were added to unittest in Python 2.7, including test 97061da546Spatrick discovery. unittest2 allows you to use these features with earlier versions of 98061da546Spatrick Python. 99061da546Spatrick 100061da546Spatrick It currently has unittest2 0.5.1 from http://pypi.python.org/pypi/unittest2. 101061da546Spatrick Version 0.5.1 of unittest2 has feature parity with unittest in Python 2.7 102061da546Spatrick final. If you want to ensure that your tests run identically under unittest2 103061da546Spatrick and unittest in Python 2.7 you should use unittest2 0.5.1. 104061da546Spatrick 105061da546Spatrick Later versions of unittest2 include changes in unittest made in Python 3.2 and 106061da546Spatrick onwards after the release of Python 2.7. 107061da546Spatrick 108061da546Spatrick- Profiling dotest.py runs 109061da546Spatrick 110061da546Spatrick I used the following command line thingy to do the profiling on a SnowLeopard 111061da546Spatrick machine: 112061da546Spatrick 113061da546Spatrick $ DOTEST_PROFILE=YES DOTEST_SCRIPT_DIR=/Volumes/data/lldb/svn/trunk/test /System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/cProfile.py -o my.profile ./dotest.py -v -w 2> ~/Developer/Log/lldbtest.log 114061da546Spatrick 115061da546Spatrick After that, I used the pstats.py module to browse the statistics: 116061da546Spatrick 117061da546Spatrick $ python /System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/pstats.py my.profile 118061da546Spatrick 119061da546Spatrick- Writing test cases: 120061da546Spatrick 121061da546Spatrick We strongly prefer writing test cases using the SB API's rather than 122061da546Spatrick the runCmd & expect. Unless you are actually testing some feature 123061da546Spatrick of the command line, please don't write command based tests. For 124061da546Spatrick historical reasons there are plenty of examples of tests in the test 125061da546Spatrick suite that use runCmd where they shouldn't, but don't copy them, 126061da546Spatrick copy the plenty that do use the SB API's instead. 127061da546Spatrick 128061da546Spatrick The reason for this is that our policy is that we will maintain 129061da546Spatrick compatibility with the SB API's. But we don't make any similar 130061da546Spatrick guarantee about the details of command result format. If your test 131061da546Spatrick is using the command line, it is going to have to check against the 132061da546Spatrick command result text, and you either end up writing your check 133061da546Spatrick pattern by checking as little as possible so you won't be exposed to 134061da546Spatrick random changes in the text; in which case you can end up missing 135061da546Spatrick some failure, or you test too much and it means irrelevant changes 136061da546Spatrick break your tests. 137061da546Spatrick 138061da546Spatrick However, if you use the Python API's it is possible to check all the 139061da546Spatrick results you want to check in a very explicit way, which makes the 140061da546Spatrick tests much more robust. 141061da546Spatrick 142061da546Spatrick Even if you are testing that a command-line command does some 143061da546Spatrick specific thing, it is still better in general to use the SB API's to 144061da546Spatrick drive to the point where you want to run the test, then use 145061da546Spatrick SBInterpreter::HandleCommand to run the command. You get the full 146061da546Spatrick result text from the command in the command return object, and all 147061da546Spatrick the part where you are driving the debugger to the point you want to 148061da546Spatrick test will be more robust. 149061da546Spatrick 150061da546Spatrick The sample_test directory contains a standard and an "inline" test 151061da546Spatrick that are good starting points for writing a new test. 152061da546Spatrick 153061da546Spatrick- Attaching in test cases: 154061da546Spatrick 155061da546Spatrick If you need to attach to inferiors in your tests, you must make sure 156061da546Spatrick the inferior calls lldb_enable_attach(), before the debugger 157061da546Spatrick attempts to attach. This function performs any platform-specific 158061da546Spatrick processing needed to enable attaching to this process (e.g., on 159061da546Spatrick Linux, we execute prctl(PR_SET_TRACER) syscall to disable 160061da546Spatrick protections present in some Linux systems). 161