blob: 0596757c05bbabf683fa4de6c437719117f54e97 [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.
38 mydir = ""
39
40 def setUp(self):
41 # Save old working directory.
42 self.oldcwd = os.getcwd()
43
44 # Change current working directory if ${LLDB_TEST} is defined.
45 # See also dotest.py which sets up ${LLDB_TEST}.
46 if ("LLDB_TEST" in os.environ):
47 os.chdir(os.path.join(os.environ["LLDB_TEST"], self.mydir));
48
49 # Create the debugger instance if necessary.
50 try:
51 self.dbg = lldb.DBG
52 except NameError:
53 self.dbg = lldb.SBDebugger.Create()
54 except AttributeError:
55 self.dbg = lldb.SBDebugger.Create()
56 if not self.dbg.IsValid():
57 raise Exception('Invalid debugger instance')
58
59 # We want our debugger to be synchronous.
60 self.dbg.SetAsync(False)
61
62 # Retrieve the associated command interpreter instance.
63 self.ci = self.dbg.GetCommandInterpreter()
64 if not self.ci:
65 raise Exception('Could not get the command interpreter')
66
67 # And the result object.
68 self.res = lldb.SBCommandReturnObject()
69
70
71 def tearDown(self):
72 del self.dbg
73
74 # Restore old working directory.
75 os.chdir(self.oldcwd)