diff --git a/lldb/test/array_types/TestArrayTypes.py b/lldb/test/array_types/TestArrayTypes.py new file mode 100644 index 0000000000000000000000000000000000000000..8b626a6862682afb068f810a76cfc609455962d8 --- /dev/null +++ b/lldb/test/array_types/TestArrayTypes.py @@ -0,0 +1,79 @@ +"""Test breakpoint by file/line number; and list variables with array types.""" + +import os +import lldb +import unittest + +class TestArrayTypes(unittest.TestCase): + + def setUp(self): + # Save old working directory. + self.oldcwd = os.getcwd() + # Change current working directory if ${LLDB_TEST} is defined. + if ("LLDB_TEST" in os.environ): + os.chdir(os.path.join(os.environ["LLDB_TEST"], "array_types")); + self.dbg = lldb.SBDebugger.Create() + self.dbg.SetAsync(False) + self.ci = self.dbg.GetCommandInterpreter() + if not self.ci: + raise Exception('Could not get the command interpreter') + + def tearDown(self): + # Restore old working directory. + os.chdir(self.oldcwd) + + def test_array_types(self): + """Test 'variable list var_name' on some variables with array types.""" + res = lldb.SBCommandReturnObject() + self.ci.HandleCommand("file a.out", res) + self.assertTrue(res.Succeeded()) + self.ci.HandleCommand("breakpoint set -f main.c -l 42", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith( + "Breakpoint created: 1: file ='main.c', line = 42, locations = 1")) + + self.ci.HandleCommand("run", res) + self.assertTrue(res.Succeeded()) + + self.ci.HandleCommand("breakpoint list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('resolved, hit count = 1')) + + self.ci.HandleCommand("thread list", res) + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('state is Stopped') and + res.GetOutput().find('stop reason = breakpoint')) + + self.ci.HandleCommand("variable list strings", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith('(char *[4])') and + res.GetOutput().find('(char *) strings[0]') and + res.GetOutput().find('(char *) strings[1]') and + res.GetOutput().find('(char *) strings[2]') and + res.GetOutput().find('(char *) strings[3]') and + res.GetOutput().find('Hello') and + res.GetOutput().find('Hola') and + res.GetOutput().find('Bonjour') and + res.GetOutput().find('Guten Tag')) + + self.ci.HandleCommand("variable list char_16", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().find('(char) char_16[0]') and + res.GetOutput().find('(char) char_16[15]')) + + self.ci.HandleCommand("variable list ushort_matrix", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith('(unsigned short [2][3])')) + + self.ci.HandleCommand("variable list long_6", res); + self.assertTrue(res.Succeeded()) + self.assertTrue(res.GetOutput().startswith('(long [6])')) + + self.ci.HandleCommand("continue", res) + self.assertTrue(res.Succeeded()) + + +if __name__ == '__main__': + lldb.SBDebugger.Initialize() + unittest.main() + lldb.SBDebugger.Terminate() diff --git a/lldb/test/array_types/main.c b/lldb/test/array_types/main.c index b6eaf4b0d548d9b29d7e4a2256e8c004cab6112c..f395df52210051a9491b3eb44eb1ff45c2b35fa1 100644 --- a/lldb/test/array_types/main.c +++ b/lldb/test/array_types/main.c @@ -27,7 +27,7 @@ int main (int argc, char const *argv[]) short short_4[4] = { 1,2,3,4 }; short short_matrix[1][2] = { {1,2} }; unsigned short ushort_4[4] = { 1,2,3,4 }; - short ushort_matrix[2][3] = { + unsigned short ushort_matrix[2][3] = { { 1, 2, 3}, {11,22,33} }; diff --git a/lldb/test/dotest.py b/lldb/test/dotest.py index 9d51816d9efc40e34888fdad6c13c59c0f061986..3ab116bd0a2ad884f74c82b417531b15e488fefa 100755 --- a/lldb/test/dotest.py +++ b/lldb/test/dotest.py @@ -42,6 +42,9 @@ where options: and: args : specify a list of directory names to search for python Test*.py scripts if empty, search from the curret working directory, instead + +Running of this script also sets up the LLDB_TEST environment variable so that +individual test cases can locate their supporting files correctly. """ @@ -54,6 +57,8 @@ def setupSysPath(): print "This script expects to reside in lldb's test directory." sys.exit(-1) + os.environ["LLDB_TEST"] = testPath + base = os.path.abspath(os.path.join(testPath, os.pardir)) dbgPath = os.path.join(base, 'build', 'Debug', 'LLDB.framework', 'Resources', 'Python') diff --git a/lldb/test/help/TestHelp.py b/lldb/test/help/TestHelp.py index 5b006efab8b5dc8ad6f6d1b36d2391b9bf56db79..56ec504ff65dd2c1a616dc05a00a9007315821d1 100644 --- a/lldb/test/help/TestHelp.py +++ b/lldb/test/help/TestHelp.py @@ -1,19 +1,26 @@ """Test lldb help command.""" +import os import lldb import unittest class TestHelpCommand(unittest.TestCase): def setUp(self): - self.debugger = lldb.SBDebugger.Create() - self.debugger.SetAsync(False) - self.ci = self.debugger.GetCommandInterpreter() + # Save old working directory. + self.oldcwd = os.getcwd() + # Change current working directory if ${LLDB_TEST} is defined. + if ("LLDB_TEST" in os.environ): + os.chdir(os.path.join(os.environ["LLDB_TEST"], "help")); + self.dbg = lldb.SBDebugger.Create() + self.dbg.SetAsync(False) + self.ci = self.dbg.GetCommandInterpreter() if not self.ci: raise Exception('Could not get the command interpreter') def tearDown(self): - pass + # Restore old working directory. + os.chdir(self.oldcwd) def test_simplehelp(self): """A simple test of 'help' command and its output.""" @@ -22,7 +29,6 @@ class TestHelpCommand(unittest.TestCase): self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( 'The following is a list of built-in, permanent debugger commands')) - #print res.GetOutput() def test_help_should_not_hang_emacsshell(self): """'set term-width 0' should not hang the help command.""" @@ -33,7 +39,6 @@ class TestHelpCommand(unittest.TestCase): self.assertTrue(res.Succeeded()) self.assertTrue(res.GetOutput().startswith( 'The following is a list of built-in, permanent debugger commands')) - #print res.GetOutput() if __name__ == '__main__':