[Lldb-commits] [lldb] r138444 - in /lldb/trunk/test/functionalities: alias/TestAliases.py alias/welcome.py command_python/ command_python/Makefile command_python/TestCommandPython.py command_python/main.cpp command_python/py_import command_python/welcome.py
Enrico Granata
granata.enrico at gmail.com
Wed Aug 24 10:45:40 PDT 2011
Author: enrico
Date: Wed Aug 24 12:45:40 2011
New Revision: 138444
URL: http://llvm.org/viewvc/llvm-project?rev=138444&view=rev
Log:
Moved the test code for Python commands out of the test case for aliases, into its own dedicated test case
Added:
lldb/trunk/test/functionalities/command_python/
lldb/trunk/test/functionalities/command_python/Makefile
lldb/trunk/test/functionalities/command_python/TestCommandPython.py
lldb/trunk/test/functionalities/command_python/main.cpp
lldb/trunk/test/functionalities/command_python/py_import
lldb/trunk/test/functionalities/command_python/welcome.py
Removed:
lldb/trunk/test/functionalities/alias/welcome.py
Modified:
lldb/trunk/test/functionalities/alias/TestAliases.py
Modified: lldb/trunk/test/functionalities/alias/TestAliases.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/alias/TestAliases.py?rev=138444&r1=138443&r2=138444&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/alias/TestAliases.py (original)
+++ lldb/trunk/test/functionalities/alias/TestAliases.py Wed Aug 24 12:45:40 2011
@@ -130,44 +130,6 @@
substrs = [ "use of undeclared identifier 'f'",
"1 errors parsing expression" ])
- self.runCmd("command source py_import")
-
- self.expect('welcome Enrico',
- substrs = ['Hello Enrico, welcome to LLDB']);
-
- self.expect("help welcome",
- substrs = ['Just a docstring for welcome_impl',
- 'A command that says hello to LLDB users'])
-
- self.runCmd("command script delete welcome");
-
- self.expect('welcome Enrico', matching=False, error=True,
- substrs = ['Hello Enrico, welcome to LLDB']);
-
- self.expect('targetname',
- substrs = ['a.out'])
-
- self.expect('targetname fail', error=True,
- substrs = ['a test for error in command'])
-
- self.expect('command script list',
- substrs = ['targetname',
- 'Run Python function welcome.target_name_impl'])
-
- self.expect("help targetname",
- substrs = ['Run Python function welcome.target_name_imp',
- 'This command takes \'raw\' input',
- 'quote stuff'])
-
- self.expect("longwait",
- substrs = ['Done; if you saw the delays I am doing OK'])
-
- self.runCmd("command script clear")
-
- self.expect('command script list', matching=False,
- substrs = ['targetname',
- 'longwait'])
-
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
Removed: lldb/trunk/test/functionalities/alias/welcome.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/alias/welcome.py?rev=138443&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/alias/welcome.py (original)
+++ lldb/trunk/test/functionalities/alias/welcome.py (removed)
@@ -1,27 +0,0 @@
-import sys
-
-def welcome_impl(debugger, args, result, dict):
- """
- Just a docstring for welcome_impl
- A command that says hello to LLDB users
- """
- result.Printf('Hello ' + args + ', welcome to LLDB');
- return None;
-
-def target_name_impl(debugger, args, result, dict):
- target = debugger.GetSelectedTarget()
- file = target.GetExecutable()
- result.PutCString('Current target ' + file.GetFilename())
- if args == 'fail':
- return 'a test for error in command'
- else:
- return None
-
-def print_wait_impl(debugger, args, result, dict):
- print 'Trying to do long task..';
- import time
- time.sleep(1)
- print 'Still doing long task..';
- time.sleep(1)
- result.PutCString('Done; if you saw the delays I am doing OK')
- return None
\ No newline at end of file
Added: lldb/trunk/test/functionalities/command_python/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_python/Makefile?rev=138444&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/command_python/Makefile (added)
+++ lldb/trunk/test/functionalities/command_python/Makefile Wed Aug 24 12:45:40 2011
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/functionalities/command_python/TestCommandPython.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_python/TestCommandPython.py?rev=138444&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/command_python/TestCommandPython.py (added)
+++ lldb/trunk/test/functionalities/command_python/TestCommandPython.py Wed Aug 24 12:45:40 2011
@@ -0,0 +1,71 @@
+"""
+Test lldb Python commands.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class CmdPythonTestCase(TestBase):
+
+ mydir = os.path.join("functionalities", "command_python")
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ def test_with_dsym (self):
+ self.buildDsym ()
+ self.pycmd_tests ()
+
+ def test_with_dwarf (self):
+ self.buildDwarf ()
+ self.pycmd_tests ()
+
+ def pycmd_tests (self):
+ exe = os.path.join (os.getcwd(), "a.out")
+ self.expect("file " + exe,
+ patterns = [ "Current executable set to .*a.out" ])
+
+ self.runCmd("command source py_import")
+
+ self.expect('welcome Enrico',
+ substrs = ['Hello Enrico, welcome to LLDB']);
+
+ self.expect("help welcome",
+ substrs = ['Just a docstring for welcome_impl',
+ 'A command that says hello to LLDB users'])
+
+ self.runCmd("command script delete welcome");
+
+ self.expect('welcome Enrico', matching=False, error=True,
+ substrs = ['Hello Enrico, welcome to LLDB']);
+
+ self.expect('targetname',
+ substrs = ['a.out'])
+
+ self.expect('targetname fail', error=True,
+ substrs = ['a test for error in command'])
+
+ self.expect('command script list',
+ substrs = ['targetname',
+ 'Run Python function welcome.target_name_impl'])
+
+ self.expect("help targetname",
+ substrs = ['Run Python function welcome.target_name_imp',
+ 'This command takes \'raw\' input',
+ 'quote stuff'])
+
+ self.expect("longwait",
+ substrs = ['Done; if you saw the delays I am doing OK'])
+
+ self.runCmd("command script clear")
+
+ self.expect('command script list', matching=False,
+ substrs = ['targetname',
+ 'longwait'])
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
+
Added: lldb/trunk/test/functionalities/command_python/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_python/main.cpp?rev=138444&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/command_python/main.cpp (added)
+++ lldb/trunk/test/functionalities/command_python/main.cpp Wed Aug 24 12:45:40 2011
@@ -0,0 +1,62 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <cstdlib>
+#include <string>
+#include <fstream>
+#include <iostream>
+
+int
+product (int x, int y)
+{
+ int result = x * y;
+ return result;
+}
+
+int
+sum (int a, int b)
+{
+ int result = a + b;
+ return result;
+}
+
+int
+strange_max (int m, int n)
+{
+ if (m > n)
+ return m;
+ else if (n > m)
+ return n;
+ else
+ return 0;
+}
+
+int
+foo (int i, int j)
+{
+ if (strange_max (i, j) == i)
+ return product (i, j);
+ else if (strange_max (i, j) == j)
+ return sum (i, j);
+ else
+ return product (sum (i, i), sum (j, j));
+}
+
+int
+main(int argc, char const *argv[])
+{
+
+ int array[3];
+
+ array[0] = foo (1238, 78392);
+ array[1] = foo (379265, 23674);
+ array[2] = foo (872934, 234);
+
+ return 0;
+}
Added: lldb/trunk/test/functionalities/command_python/py_import
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_python/py_import?rev=138444&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/command_python/py_import (added)
+++ lldb/trunk/test/functionalities/command_python/py_import Wed Aug 24 12:45:40 2011
@@ -0,0 +1,6 @@
+script import sys, os
+script sys.path.append(os.path.join(os.getcwd(), os.pardir))
+script import welcome
+command script add welcome --function welcome.welcome_impl
+command script add targetname --function welcome.target_name_impl
+command script add longwait --function welcome.print_wait_impl
Added: lldb/trunk/test/functionalities/command_python/welcome.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_python/welcome.py?rev=138444&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/command_python/welcome.py (added)
+++ lldb/trunk/test/functionalities/command_python/welcome.py Wed Aug 24 12:45:40 2011
@@ -0,0 +1,27 @@
+import sys
+
+def welcome_impl(debugger, args, result, dict):
+ """
+ Just a docstring for welcome_impl
+ A command that says hello to LLDB users
+ """
+ result.Printf('Hello ' + args + ', welcome to LLDB');
+ return None;
+
+def target_name_impl(debugger, args, result, dict):
+ target = debugger.GetSelectedTarget()
+ file = target.GetExecutable()
+ result.PutCString('Current target ' + file.GetFilename())
+ if args == 'fail':
+ return 'a test for error in command'
+ else:
+ return None
+
+def print_wait_impl(debugger, args, result, dict):
+ print 'Trying to do long task..';
+ import time
+ time.sleep(1)
+ print 'Still doing long task..';
+ time.sleep(1)
+ result.PutCString('Done; if you saw the delays I am doing OK')
+ return None
\ No newline at end of file
More information about the lldb-commits
mailing list