summaryrefslogtreecommitdiffstats
path: root/lldb/test/functionalities/command_script/import/TestImport.py
diff options
context:
space:
mode:
authorEnrico Granata <granata.enrico@gmail.com>2011-10-17 21:45:27 +0000
committerEnrico Granata <granata.enrico@gmail.com>2011-10-17 21:45:27 +0000
commita9dbf4325e9b97ca4c68baf4d05fad55bd194332 (patch)
treefc59812edc526ec91c28e8fbddc6ca5c32e1833b /lldb/test/functionalities/command_script/import/TestImport.py
parenta5748e22e2c997ae5fbe4aa3b9170e7a12375e26 (diff)
downloadbcm5719-llvm-a9dbf4325e9b97ca4c68baf4d05fad55bd194332.tar.gz
bcm5719-llvm-a9dbf4325e9b97ca4c68baf4d05fad55bd194332.zip
this patch introduces a new command script import command which takes as input a filename for a Python script and imports the module contained in that file. the containing directory is added to the Python path such that dependencies are honored. also, the module may contain an __lldb_init_module(debugger,dict) function, which gets called after importing, and which can somehow initialize the module's interaction with lldb
llvm-svn: 142283
Diffstat (limited to 'lldb/test/functionalities/command_script/import/TestImport.py')
-rw-r--r--lldb/test/functionalities/command_script/import/TestImport.py71
1 files changed, 71 insertions, 0 deletions
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()
OpenPOWER on IntegriCloud