From 985e740cd94c7416b2c42f19053f35bb031fa5cf Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Mon, 1 Aug 2011 21:13:26 +0000 Subject: [PATCH] Add an abstract base class called BenchBase to be inherited by benchmark tests. Modify the example TestRepeatedExprs.py to use BenchBase, instead. llvm-svn: 136649 --- .../benchmarks/example/TestRepeatedExprs.py | 4 +- lldb/test/lldbbench.py | 8 +++ lldb/test/lldbtest.py | 65 ++++++++++--------- 3 files changed, 43 insertions(+), 34 deletions(-) create mode 100644 lldb/test/lldbbench.py diff --git a/lldb/test/benchmarks/example/TestRepeatedExprs.py b/lldb/test/benchmarks/example/TestRepeatedExprs.py index 719efb93617d..228e8994e087 100644 --- a/lldb/test/benchmarks/example/TestRepeatedExprs.py +++ b/lldb/test/benchmarks/example/TestRepeatedExprs.py @@ -4,9 +4,9 @@ import os import unittest2 import lldb import pexpect -from lldbtest import * +from lldbbench import * -class RepeatedExprssCase(TestBase): +class RepeatedExprsCase(BenchBase): mydir = os.path.join("benchmarks", "example") diff --git a/lldb/test/lldbbench.py b/lldb/test/lldbbench.py new file mode 100644 index 000000000000..19dcabc9f07d --- /dev/null +++ b/lldb/test/lldbbench.py @@ -0,0 +1,8 @@ +import lldbtest +from lldbtest import benchmarks_test + +class BenchBase(lldbtest.Base): + """ + Abstract base class for benchmark tests. + """ + diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py index 4b073c590be6..dea1a235cc05 100644 --- a/lldb/test/lldbtest.py +++ b/lldb/test/lldbtest.py @@ -451,6 +451,14 @@ class Base(unittest2.TestCase): #import traceback #traceback.print_stack() + # Assign the test method name to self.testMethodName. + # + # For an example of the use of this attribute, look at test/types dir. + # There are a bunch of test cases under test/types and we don't want the + # module cacheing subsystem to be confused with executable name "a.out" + # used for all the test cases. + self.testMethodName = self._testMethodName + # Python API only test is decorated with @python_api_test, # which also sets the "__python_api_test__" attribute of the # function object to True. @@ -477,6 +485,16 @@ class Base(unittest2.TestCase): except AttributeError: pass + # This is for the case of directly spawning 'lldb'/'gdb' and interacting + # with it using pexpect. + self.child = None + self.child_prompt = "(lldb) " + # If the child is interacting with the embedded script interpreter, + # there are two exits required during tear down, first to quit the + # embedded script interpreter and second to quit the lldb command + # interpreter. + self.child_in_script_interpreter = False + # These are for customized teardown cleanup. self.dict = None self.doTearDownCleanup = False @@ -562,6 +580,21 @@ class Base(unittest2.TestCase): #import traceback #traceback.print_stack() + # This is for the case of directly spawning 'lldb' and interacting with it + # using pexpect. + import pexpect + if self.child and self.child.isalive(): + with recording(self, traceAlways) as sbuf: + print >> sbuf, "tearing down the child process...." + if self.child_in_script_interpreter: + self.child.sendline('quit()') + self.child.expect_exact(self.child_prompt) + self.child.sendline('quit') + try: + self.child.expect(pexpect.EOF) + except: + pass + # Check and run any hook functions. for hook in reversed(self.hooks): with recording(self, traceAlways) as sbuf: @@ -804,14 +837,6 @@ class TestBase(Base): # Works with the test driver to conditionally skip tests via decorators. Base.setUp(self) - # Assign the test method name to self.testMethodName. - # - # For an example of the use of this attribute, look at test/types dir. - # There are a bunch of test cases under test/types and we don't want the - # module cacheing subsystem to be confused with executable name "a.out" - # used for all the test cases. - self.testMethodName = self._testMethodName - if "LLDB_EXEC" in os.environ: self.lldbExec = os.environ["LLDB_EXEC"] @@ -847,15 +872,6 @@ class TestBase(Base): # We want our debugger to be synchronous. self.dbg.SetAsync(False) - # This is for the case of directly spawning 'lldb' and interacting with - # it using pexpect. - self.child = None - # If the child is interacting with the embedded script interpreter, - # there are two exits required during tear down, first to quit the - # embedded script interpreter and second to quit the lldb command - # interpreter. - self.child_in_script_interpreter = False - # Retrieve the associated command interpreter instance. self.ci = self.dbg.GetCommandInterpreter() if not self.ci: @@ -870,21 +886,6 @@ class TestBase(Base): Base.tearDown(self) - # This is for the case of directly spawning 'lldb' and interacting with it - # using pexpect. - import pexpect - if self.child and self.child.isalive(): - with recording(self, traceAlways) as sbuf: - print >> sbuf, "tearing down the child process...." - if self.child_in_script_interpreter: - self.child.sendline('quit()') - self.child.expect_exact('(lldb) ') - self.child.sendline('quit') - try: - self.child.expect(pexpect.EOF) - except: - pass - # Delete the target(s) from the debugger as a general cleanup step. # This includes terminating the process for each target, if any. # We'd like to reuse the debugger for our next test without incurring