blob: 8d20fff53ef526b32081d04aeeea4fcc3b83b9e7 [file] [log] [blame]
Johnny Chenbf6ffa32010-07-03 03:41:59 +00001"""
2LLDB module which provides the abstract base class of lldb test case.
3
4The concrete subclass can override lldbtest.TesBase in order to inherit the
5common behavior for unitest.TestCase.setUp/tearDown implemented in this file.
6
7The subclass should override the attribute mydir in order for the python runtime
8to locate the individual test cases when running as part of a large test suite
9or when running each test case as a separate python invocation.
10
11./dotest.py provides a test driver which sets up the environment to run the
12entire test suite. Users who want to run a test case on its own can specify the
13LLDB_TEST and PYTHONPATH environment variables, for example:
14
15$ export LLDB_TEST=$PWD
16$ export PYTHONPATH=/Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:$LLDB_TEST
17$ echo $LLDB_TEST
18/Volumes/data/lldb/svn/trunk/test
19$ echo $PYTHONPATH
20/Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:/Volumes/data/lldb/svn/trunk/test
21$ python function_types/TestFunctionTypes.py
22.
23----------------------------------------------------------------------
24Ran 1 test in 0.363s
25
26OK
27$
28"""
29
30import os
31import unittest
32import lldb
33
34class TestBase(unittest.TestCase):
35 """This LLDB abstract base class is meant to be subclassed."""
36
37 # The concrete subclass should override this attribute.
Johnny Chenf02ec122010-07-03 20:41:42 +000038 mydir = None
Johnny Chenbf6ffa32010-07-03 03:41:59 +000039
40 def setUp(self):
Johnny Chenf02ec122010-07-03 20:41:42 +000041 # Fail fast if 'mydir' attribute is not overridden.
42 if not self.mydir or len(self.mydir) == 0:
43 raise Exception("Subclasses must override the 'mydir' attribute.")
Johnny Chenbf6ffa32010-07-03 03:41:59 +000044 # Save old working directory.
45 self.oldcwd = os.getcwd()
46
47 # Change current working directory if ${LLDB_TEST} is defined.
48 # See also dotest.py which sets up ${LLDB_TEST}.
49 if ("LLDB_TEST" in os.environ):
50 os.chdir(os.path.join(os.environ["LLDB_TEST"], self.mydir));
51
52 # Create the debugger instance if necessary.
53 try:
54 self.dbg = lldb.DBG
Johnny Chenbf6ffa32010-07-03 03:41:59 +000055 except AttributeError:
56 self.dbg = lldb.SBDebugger.Create()
Johnny Chenf02ec122010-07-03 20:41:42 +000057
Johnny Chenbf6ffa32010-07-03 03:41:59 +000058 if not self.dbg.IsValid():
59 raise Exception('Invalid debugger instance')
60
61 # We want our debugger to be synchronous.
62 self.dbg.SetAsync(False)
63
64 # Retrieve the associated command interpreter instance.
65 self.ci = self.dbg.GetCommandInterpreter()
66 if not self.ci:
67 raise Exception('Could not get the command interpreter')
68
69 # And the result object.
70 self.res = lldb.SBCommandReturnObject()
71
72
73 def tearDown(self):
74 del self.dbg
75
76 # Restore old working directory.
77 os.chdir(self.oldcwd)