summaryrefslogtreecommitdiffstats
path: root/lldb/test/functionalities/command_script/import
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/test/functionalities/command_script/import')
-rw-r--r--lldb/test/functionalities/command_script/import/Makefile6
-rw-r--r--lldb/test/functionalities/command_script/import/TestImport.py71
-rw-r--r--lldb/test/functionalities/command_script/import/bar/bar.py10
-rw-r--r--lldb/test/functionalities/command_script/import/bar/barutil.py2
-rw-r--r--lldb/test/functionalities/command_script/import/dummymodule.py2
-rw-r--r--lldb/test/functionalities/command_script/import/foo/bar/foobar.py3
-rw-r--r--lldb/test/functionalities/command_script/import/foo/foo.py3
-rw-r--r--lldb/test/functionalities/command_script/import/foo/foo2.py7
-rw-r--r--lldb/test/functionalities/command_script/import/main.c15
9 files changed, 119 insertions, 0 deletions
diff --git a/lldb/test/functionalities/command_script/import/Makefile b/lldb/test/functionalities/command_script/import/Makefile
new file mode 100644
index 00000000000..9374aef487f
--- /dev/null
+++ b/lldb/test/functionalities/command_script/import/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../../make
+
+C_SOURCES := main.c
+EXE := hello_world
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/functionalities/command_script/import/TestImport.py b/lldb/test/functionalities/command_script/import/TestImport.py
new file mode 100644
index 00000000000..a983e285c39
--- /dev/null
+++ b/lldb/test/functionalities/command_script/import/TestImport.py
@@ -0,0 +1,71 @@
+"""Test custom import command to import files by path."""
+
+import os, sys, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class ImportTestCase(TestBase):
+
+ mydir = os.path.join("functionalities", "command_script", "import")
+
+ @python_api_test
+ def test_import_command(self):
+ """Import some Python scripts by path and test them"""
+ self.run_test()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+
+ def run_test(self):
+ """Import some Python scripts by path and test them."""
+
+ # This is the function to remove the custom commands in order to have a
+ # clean slate for the next test case.
+ def cleanup():
+ self.runCmd('command script delete foo2cmd', check=False)
+ self.runCmd('command script delete foocmd', check=False)
+ self.runCmd('command script delete foobarcmd', check=False)
+ self.runCmd('command script delete barcmd', check=False)
+ self.runCmd('command script delete barothercmd', check=False)
+
+ # Execute the cleanup function during test case tear down.
+ self.addTearDownHook(cleanup)
+
+ self.runCmd("command script import ./foo/foo.py")
+ self.runCmd("command script import ./foo/foo2.py")
+ self.runCmd("command script import ./foo/bar/foobar.py")
+ self.runCmd("command script import ./bar/bar.py")
+
+ self.expect("command script import ./nosuchfile.py",
+ error=True, startstr='error: module importing failed')
+ self.expect("command script import ./nosuchfolder/",
+ error=True, startstr='error: module importing failed')
+ self.expect("command script import ./foo/foo.py",
+ error=True, startstr='error: module importing failed')
+
+ self.runCmd("script import dummymodule")
+ self.expect("command script import ./dummymodule.py",
+ error=True, startstr='error: module importing failed')
+
+ self.runCmd("command script add -f foo.foo_function foocmd")
+ self.runCmd("command script add -f foobar.foo_function foobarcmd")
+ self.runCmd("command script add -f bar.bar_function barcmd")
+ self.expect("foocmd hello",
+ substrs = ['foo says', 'hello'])
+ self.expect("foo2cmd hello",
+ substrs = ['foo2 says', 'hello'])
+ self.expect("barcmd hello",
+ substrs = ['barutil says', 'bar told me', 'hello'])
+ self.expect("barothercmd hello",
+ substrs = ['barutil says', 'bar told me', 'hello'])
+ self.expect("foobarcmd hello",
+ substrs = ['foobar says', 'hello'])
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/lldb/test/functionalities/command_script/import/bar/bar.py b/lldb/test/functionalities/command_script/import/bar/bar.py
new file mode 100644
index 00000000000..269fc935204
--- /dev/null
+++ b/lldb/test/functionalities/command_script/import/bar/bar.py
@@ -0,0 +1,10 @@
+def bar_function(debugger, args, result, dict):
+ global UtilityModule
+ result.Printf(UtilityModule.barutil_function("bar told me " + args))
+ return None
+
+def __lldb_init_module(debugger, session_dict):
+ global UtilityModule
+ UtilityModule = __import__("barutil")
+ debugger.HandleCommand("command script add -f bar.bar_function barothercmd")
+ return None \ No newline at end of file
diff --git a/lldb/test/functionalities/command_script/import/bar/barutil.py b/lldb/test/functionalities/command_script/import/bar/barutil.py
new file mode 100644
index 00000000000..0d3d2eb1b2d
--- /dev/null
+++ b/lldb/test/functionalities/command_script/import/bar/barutil.py
@@ -0,0 +1,2 @@
+def barutil_function(x):
+ return "barutil says: " + x
diff --git a/lldb/test/functionalities/command_script/import/dummymodule.py b/lldb/test/functionalities/command_script/import/dummymodule.py
new file mode 100644
index 00000000000..dcc724ec9c2
--- /dev/null
+++ b/lldb/test/functionalities/command_script/import/dummymodule.py
@@ -0,0 +1,2 @@
+def no_useful_code(foo):
+ return foo
diff --git a/lldb/test/functionalities/command_script/import/foo/bar/foobar.py b/lldb/test/functionalities/command_script/import/foo/bar/foobar.py
new file mode 100644
index 00000000000..c76afea903c
--- /dev/null
+++ b/lldb/test/functionalities/command_script/import/foo/bar/foobar.py
@@ -0,0 +1,3 @@
+def foo_function(debugger, args, result, dict):
+ result.Printf("foobar says " + args)
+ return None
diff --git a/lldb/test/functionalities/command_script/import/foo/foo.py b/lldb/test/functionalities/command_script/import/foo/foo.py
new file mode 100644
index 00000000000..852bd83c2ee
--- /dev/null
+++ b/lldb/test/functionalities/command_script/import/foo/foo.py
@@ -0,0 +1,3 @@
+def foo_function(debugger, args, result, dict):
+ result.Printf("foo says " + args)
+ return None
diff --git a/lldb/test/functionalities/command_script/import/foo/foo2.py b/lldb/test/functionalities/command_script/import/foo/foo2.py
new file mode 100644
index 00000000000..120f5b2dd41
--- /dev/null
+++ b/lldb/test/functionalities/command_script/import/foo/foo2.py
@@ -0,0 +1,7 @@
+def foo2_function(debugger, args, result, dict):
+ result.Printf("foo2 says " + args)
+ return None
+
+def __lldb_init_module(debugger, session_dict):
+ debugger.HandleCommand("command script add -f foo2.foo2_function foo2cmd")
+ return None \ No newline at end of file
diff --git a/lldb/test/functionalities/command_script/import/main.c b/lldb/test/functionalities/command_script/import/main.c
new file mode 100644
index 00000000000..dffc8c77b04
--- /dev/null
+++ b/lldb/test/functionalities/command_script/import/main.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main(int argc, char const *argv[]) {
+ printf("Hello world.\n"); // Set break point at this line.
+ if (argc == 1)
+ return 0;
+
+ // Waiting to be attached by the debugger, otherwise.
+ char line[100];
+ while (fgets(line, sizeof(line), stdin)) { // Waiting to be attached...
+ printf("input line=>%s\n", line);
+ }
+
+ printf("Exiting now\n");
+}
OpenPOWER on IntegriCloud