From 061da546b983eb767bad15e67af1174fb0bcf31c Mon Sep 17 00:00:00 2001 From: patrick Date: Mon, 3 Aug 2020 14:33:06 +0000 Subject: Import LLVM 10.0.0 release including clang, lld and lldb. ok hackroom tested by plenty --- .../lldbsuite/test/python_api/interpreter/Makefile | 3 + .../interpreter/TestCommandInterpreterAPI.py | 91 ++++++++++++++++++++++ .../interpreter/TestRunCommandInterpreterAPI.py | 75 ++++++++++++++++++ .../lldbsuite/test/python_api/interpreter/main.c | 6 ++ 4 files changed, 175 insertions(+) create mode 100644 gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/Makefile create mode 100644 gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py create mode 100644 gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestRunCommandInterpreterAPI.py create mode 100644 gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/main.c (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter') diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/Makefile new file mode 100644 index 00000000000..10495940055 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := main.c + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py new file mode 100644 index 00000000000..a920ce845b8 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestCommandInterpreterAPI.py @@ -0,0 +1,91 @@ +"""Test the SBCommandInterpreter APIs.""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class CommandInterpreterAPICase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break on inside main.cpp. + self.line = line_number('main.c', 'Hello world.') + + @add_test_categories(['pyapi']) + def test_with_process_launch_api(self): + """Test the SBCommandInterpreter APIs.""" + self.build() + exe = self.getBuildArtifact("a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Retrieve the associated command interpreter from our debugger. + ci = self.dbg.GetCommandInterpreter() + self.assertTrue(ci, VALID_COMMAND_INTERPRETER) + + # Exercise some APIs.... + + self.assertTrue(ci.HasCommands()) + self.assertTrue(ci.HasAliases()) + self.assertTrue(ci.HasAliasOptions()) + self.assertTrue(ci.CommandExists("breakpoint")) + self.assertTrue(ci.CommandExists("target")) + self.assertTrue(ci.CommandExists("platform")) + self.assertTrue(ci.AliasExists("file")) + self.assertTrue(ci.AliasExists("run")) + self.assertTrue(ci.AliasExists("bt")) + + res = lldb.SBCommandReturnObject() + ci.HandleCommand("breakpoint set -f main.c -l %d" % self.line, res) + self.assertTrue(res.Succeeded()) + ci.HandleCommand("process launch", res) + self.assertTrue(res.Succeeded()) + + # Boundary conditions should not crash lldb! + self.assertFalse(ci.CommandExists(None)) + self.assertFalse(ci.AliasExists(None)) + ci.HandleCommand(None, res) + self.assertFalse(res.Succeeded()) + res.AppendMessage("Just appended a message.") + res.AppendMessage(None) + if self.TraceOn(): + print(res) + + process = ci.GetProcess() + self.assertTrue(process) + + import lldbsuite.test.lldbutil as lldbutil + if process.GetState() != lldb.eStateStopped: + self.fail("Process should be in the 'stopped' state, " + "instead the actual state is: '%s'" % + lldbutil.state_type_to_str(process.GetState())) + + if self.TraceOn(): + lldbutil.print_stacktraces(process) + + @add_test_categories(['pyapi']) + def test_command_output(self): + """Test command output handling.""" + ci = self.dbg.GetCommandInterpreter() + self.assertTrue(ci, VALID_COMMAND_INTERPRETER) + + # Test that a command which produces no output returns "" instead of + # None. + res = lldb.SBCommandReturnObject() + ci.HandleCommand("settings set use-color false", res) + self.assertTrue(res.Succeeded()) + self.assertIsNotNone(res.GetOutput()) + self.assertEquals(res.GetOutput(), "") + self.assertIsNotNone(res.GetError()) + self.assertEquals(res.GetError(), "") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestRunCommandInterpreterAPI.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestRunCommandInterpreterAPI.py new file mode 100644 index 00000000000..a32805bf859 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/TestRunCommandInterpreterAPI.py @@ -0,0 +1,75 @@ +"""Test the RunCommandInterpreter API.""" + +import os +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * + +class CommandRunInterpreterLegacyAPICase(TestBase): + + NO_DEBUG_INFO_TESTCASE = True + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + self.stdin_path = self.getBuildArtifact("stdin.txt") + + with open(self.stdin_path, 'w') as input_handle: + input_handle.write("nonexistingcommand\nquit") + + # Python will close the file descriptor if all references + # to the filehandle object lapse, so we need to keep one + # around. + self.filehandle = open(self.stdin_path, 'r') + self.dbg.SetInputFileHandle(self.filehandle, False) + + # No need to track the output + self.devnull = open(os.devnull, 'w') + self.dbg.SetOutputFileHandle(self.devnull, False) + self.dbg.SetErrorFileHandle (self.devnull, False) + + @add_test_categories(['pyapi']) + def test_run_session_with_error_and_quit_legacy(self): + """Run non-existing and quit command returns appropriate values""" + + n_errors, quit_requested, has_crashed = self.dbg.RunCommandInterpreter( + True, False, lldb.SBCommandInterpreterRunOptions(), 0, False, + False) + + self.assertGreater(n_errors, 0) + self.assertTrue(quit_requested) + self.assertFalse(has_crashed) + + +class CommandRunInterpreterAPICase(TestBase): + + NO_DEBUG_INFO_TESTCASE = True + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + self.stdin_path = self.getBuildArtifact("stdin.txt") + + with open(self.stdin_path, 'w') as input_handle: + input_handle.write("nonexistingcommand\nquit") + + self.dbg.SetInputFile(open(self.stdin_path, 'r')) + + # No need to track the output + devnull = open(os.devnull, 'w') + self.dbg.SetOutputFile(devnull) + self.dbg.SetErrorFile(devnull) + + @add_test_categories(['pyapi']) + def test_run_session_with_error_and_quit(self): + """Run non-existing and quit command returns appropriate values""" + + n_errors, quit_requested, has_crashed = self.dbg.RunCommandInterpreter( + True, False, lldb.SBCommandInterpreterRunOptions(), 0, False, + False) + + self.assertGreater(n_errors, 0) + self.assertTrue(quit_requested) + self.assertFalse(has_crashed) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/main.c b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/main.c new file mode 100644 index 00000000000..277aa54a4ee --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/python_api/interpreter/main.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char const *argv[]) { + printf("Hello world.\n"); + return 0; +} -- cgit v1.2.3-59-g8ed1b