1c432c8f8SZachary TurnerThis README file describes the files and directories related to the Python test 2c432c8f8SZachary Turnersuite under the current 'test' directory. 3c432c8f8SZachary Turner 4c432c8f8SZachary Turnero dotest.py 5c432c8f8SZachary Turner 6c432c8f8SZachary Turner Provides the test driver for the test suite. To invoke it, cd to the 'test' 7c432c8f8SZachary Turner directory and issue the './dotest.py' command or './dotest.py -v' for more 8c432c8f8SZachary Turner verbose output. '.dotest.py -h' prints out the help messge. 9c432c8f8SZachary Turner 10c432c8f8SZachary Turner A specific naming pattern is followed by the .py script under the 'test' 11c432c8f8SZachary Turner directory in order to be recognized by 'dotest.py' test driver as a module 12c432c8f8SZachary Turner which implements a test case, namely, Test*.py. 13c432c8f8SZachary Turner 14c432c8f8SZachary Turner Some example usages: 15c432c8f8SZachary Turner 16c432c8f8SZachary Turner 1. ./dotest.py -v . 2> ~/Developer/Log/lldbtest.log0 17c432c8f8SZachary Turner This runs the test suite and directs the run log to a file. 18c432c8f8SZachary Turner 19c432c8f8SZachary Turner 2. LLDB_LOG=/tmp/lldb.log GDB_REMOTE_LOG=/tmp/gdb-remote.log ./dotest.py -v . 2> ~/Developer/Log/lldbtest.log 20c432c8f8SZachary Turner This runs the test suite, with logging turned on for the lldb as well as 21c432c8f8SZachary Turner the process.gdb-remote channels and directs the run log to a file. 22c432c8f8SZachary Turner 23c432c8f8SZachary Turnero lldbtest.py 24c432c8f8SZachary Turner 25c432c8f8SZachary Turner Provides an abstract base class of lldb test case named 'TestBase', which in 26c432c8f8SZachary Turner turn inherits from Python's unittest.TestCase. The concrete subclass can 27c432c8f8SZachary Turner override lldbtest.TestBase in order to inherit the common behavior for 28c432c8f8SZachary Turner unittest.TestCase.setUp/tearDown implemented in this file. 29c432c8f8SZachary Turner 30c432c8f8SZachary Turner To provide a test case, the concrete subclass provides methods whose names 31c432c8f8SZachary Turner start with the letters test. For more details about the Python's unittest 32c432c8f8SZachary Turner framework, go to http://docs.python.org/library/unittest.html. 33c432c8f8SZachary Turner 34c432c8f8SZachary Turner ./command_source/TestCommandSource.py provides a simple example of test case 35c432c8f8SZachary Turner which overrides lldbtest.TestBase to exercise the lldb's 'command source' 36c432c8f8SZachary Turner command. The subclass should override the attribute 'mydir' in order for the 37c432c8f8SZachary Turner runtime to locate the individual test cases when running as part of a large 38c432c8f8SZachary Turner test suite or when running each test case as a separate Python invocation. 39c432c8f8SZachary Turner 40c432c8f8SZachary Turner The doc string provides more details about the setup required for running a 41c432c8f8SZachary Turner test case on its own. To run the whole test suite, 'dotest.py' is all you 42c432c8f8SZachary Turner need to do. 43c432c8f8SZachary Turner 44c432c8f8SZachary Turnero subdirectories of 'test' 45c432c8f8SZachary Turner 46c432c8f8SZachary Turner Most of them predate the introduction of the python test suite and contain 47c432c8f8SZachary Turner example C/C++/ObjC source files which get compiled into executables which are 48c432c8f8SZachary Turner to be exercised by the debugger. 49c432c8f8SZachary Turner 50c432c8f8SZachary Turner For such subdirectory which has an associated Test*.py file, it was added as 51c432c8f8SZachary Turner part of the Python-based test suite to test lldb functionality. 52c432c8f8SZachary Turner 53c432c8f8SZachary Turner Some of the subdirectories, for example, the 'help' subdirectory, do not have 54c432c8f8SZachary Turner C/C++/ObjC source files; they were created to house the Python test case which 55c432c8f8SZachary Turner does not involve lldb reading in an executable file at all. 56c432c8f8SZachary Turner 57c432c8f8SZachary Turnero make directory 58c432c8f8SZachary Turner 59c432c8f8SZachary Turner Contains Makefile.rules, which can be utilized by test cases to write Makefile 60c432c8f8SZachary Turner based rules to build binaries for the inferiors. 61c432c8f8SZachary Turner 62c432c8f8SZachary Turner By default, the built executable name is a.out, which can be overwritten by 63c432c8f8SZachary Turner specifying your EXE make variable, via the Makefile under the specific test 64c432c8f8SZachary Turner directory or via supplying a Python dictionary to the build method in your 65c432c8f8SZachary Turner Python test script. An example of the latter can be found in 66c432c8f8SZachary Turner test/lang/objc/radar-9691614/TestObjCMethodReturningBOOL.py, where: 67c432c8f8SZachary Turner 68c432c8f8SZachary Turner def test_method_ret_BOOL_with_dsym(self): 69c432c8f8SZachary Turner """Test that objective-c method returning BOOL works correctly.""" 70c432c8f8SZachary Turner d = {'EXE': self.exe_name} 71c432c8f8SZachary Turner self.buildDsym(dictionary=d) 72c432c8f8SZachary Turner self.setTearDownCleanup(dictionary=d) 73c432c8f8SZachary Turner self.objc_method_ret_BOOL(self.exe_name) 74c432c8f8SZachary Turner 75c432c8f8SZachary Turner def test_method_ret_BOOL_with_dwarf(self): 76c432c8f8SZachary Turner """Test that objective-c method returning BOOL works correctly.""" 77c432c8f8SZachary Turner d = {'EXE': self.exe_name} 78c432c8f8SZachary Turner self.buildDwarf(dictionary=d) 79c432c8f8SZachary Turner self.setTearDownCleanup(dictionary=d) 80c432c8f8SZachary Turner self.objc_method_ret_BOOL(self.exe_name) 81c432c8f8SZachary Turner 82c432c8f8SZachary Turner def setUp(self): 83c432c8f8SZachary Turner # Call super's setUp(). 84c432c8f8SZachary Turner TestBase.setUp(self) 85c432c8f8SZachary Turner # We'll use the test method name as the exe_name. 86c432c8f8SZachary Turner self.exe_name = self.testMethodName 87c432c8f8SZachary Turner # Find the line number to break inside main(). 88c432c8f8SZachary Turner self.main_source = "main.m" 89c432c8f8SZachary Turner self.line = line_number(self.main_source, '// Set breakpoint here.') 90c432c8f8SZachary Turner 91c432c8f8SZachary Turner The exe names for the two test methods are equal to the test method names and 92c432c8f8SZachary Turner are therefore guaranteed different. 93c432c8f8SZachary Turner 94c432c8f8SZachary Turnero plugins directory 95c432c8f8SZachary Turner 96c432c8f8SZachary Turner Contains platform specific plugin to build binaries with dsym/dwarf debugging 97c432c8f8SZachary Turner info. Other platform specific functionalities may be added in the future. 98c432c8f8SZachary Turner 99c432c8f8SZachary Turnero unittest2 directory 100c432c8f8SZachary Turner 101c432c8f8SZachary Turner Many new features were added to unittest in Python 2.7, including test 102c432c8f8SZachary Turner discovery. unittest2 allows you to use these features with earlier versions of 103c432c8f8SZachary Turner Python. 104c432c8f8SZachary Turner 105c432c8f8SZachary Turner It currently has unittest2 0.5.1 from http://pypi.python.org/pypi/unittest2. 106c432c8f8SZachary Turner Version 0.5.1 of unittest2 has feature parity with unittest in Python 2.7 107c432c8f8SZachary Turner final. If you want to ensure that your tests run identically under unittest2 108c432c8f8SZachary Turner and unittest in Python 2.7 you should use unittest2 0.5.1. 109c432c8f8SZachary Turner 110c432c8f8SZachary Turner Later versions of unittest2 include changes in unittest made in Python 3.2 and 111c432c8f8SZachary Turner onwards after the release of Python 2.7. 112c432c8f8SZachary Turner 113c432c8f8SZachary Turnero dotest.pl 114c432c8f8SZachary Turner 115c432c8f8SZachary Turner In case you wonder, there is also a 'dotest.pl' perl script file. It was 116c432c8f8SZachary Turner created to visit each Python test case under the specified directory and 117c432c8f8SZachary Turner invoke Python's builtin unittest.main() on each test case. 118c432c8f8SZachary Turner 119c432c8f8SZachary Turner It does not take advantage of the test runner and test suite functionality 120c432c8f8SZachary Turner provided by Python's unitest framework. Its existence is because we want a 121c432c8f8SZachary Turner different way of running the whole test suite. As lldb and the Python test 122c432c8f8SZachary Turner suite become more reliable, we don't expect to be using 'dotest.pl' anymore. 123c432c8f8SZachary Turner 124c432c8f8SZachary Turner Note: dotest.pl has been moved to the attic directory. 125c432c8f8SZachary Turner 126c432c8f8SZachary Turnero Profiling dotest.py runs 127c432c8f8SZachary Turner 128c432c8f8SZachary Turner I used the following command line thingy to do the profiling on a SnowLeopard 129c432c8f8SZachary Turner machine: 130c432c8f8SZachary Turner 131c432c8f8SZachary Turner$ 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 132c432c8f8SZachary Turner 133c432c8f8SZachary Turner After that, I used the pstats.py module to browse the statistics: 134c432c8f8SZachary Turner 135c432c8f8SZachary Turner$ python /System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/pstats.py my.profile 136c432c8f8SZachary Turner 137c432c8f8SZachary Turnero Writing test cases: 138c432c8f8SZachary Turner 139c432c8f8SZachary Turner We strongly prefer writing test cases using the SB API's rather than the runCmd & expect. 140c432c8f8SZachary Turner Unless you are actually testing some feature of the command line, please don't write 141c432c8f8SZachary Turner command based tests. For historical reasons there are plenty of examples of tests in the 142c432c8f8SZachary Turner test suite that use runCmd where they shouldn't, but don't copy them, copy the plenty that 143c432c8f8SZachary Turner do use the SB API's instead. 144c432c8f8SZachary Turner 145c432c8f8SZachary Turner The reason for this is that our policy is that we will maintain compatibility with the 146c432c8f8SZachary Turner SB API's. But we don't make any similar guarantee about the details of command result format. 147c432c8f8SZachary Turner If your test is using the command line, it is going to have to check against the command result 148c432c8f8SZachary Turner text, and you either end up writing your check pattern by checking as little as possible so 149c432c8f8SZachary Turner you won't be exposed to random changes in the text; in which case you can end up missing some 150c432c8f8SZachary Turner failure, or you test too much and it means irrelevant changes break your tests. 151c432c8f8SZachary Turner 152c432c8f8SZachary Turner However, if you use the Python API's it is possible to check all the results you want 153c432c8f8SZachary Turner to check in a very explicit way, which makes the tests much more robust. 154c432c8f8SZachary Turner 155c432c8f8SZachary Turner Even if you are testing that a command-line command does some specific thing, it is still 156c432c8f8SZachary Turner better in general to use the SB API's to drive to the point where you want to run the test, 157c432c8f8SZachary Turner then use SBInterpreter::HandleCommand to run the command. You get the full result text 158c432c8f8SZachary Turner from the command in the command return object, and all the part where you are driving the 159c432c8f8SZachary Turner debugger to the point you want to test will be more robust. 160*d0f89cd7SPavel Labath 161*d0f89cd7SPavel Labatho Attaching in test cases: 162*d0f89cd7SPavel Labath 163*d0f89cd7SPavel Labath If you need to attach to inferiors in your tests, you must make sure the inferior calls 164*d0f89cd7SPavel Labath lldb_enable_attach(), before the debugger attempts to attach. This function performs any 165*d0f89cd7SPavel Labath platform-specific processing needed to enable attaching to this process (e.g., on Linux, we 166*d0f89cd7SPavel Labath execute prctl(PR_SET_TRACER) syscall to disable protections present in some Linux systems). 167