From 574ccee478b9da9457cdf0e476b8df6eb584b580 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 16 Jul 2012 06:48:11 +0000 Subject: Minor memory management, performance, and tracing improvements. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1361917 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/python/python-test.cpp | 37 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'sca-cpp/trunk/modules/python/python-test.cpp') diff --git a/sca-cpp/trunk/modules/python/python-test.cpp b/sca-cpp/trunk/modules/python/python-test.cpp index bc275f27c7..29a66cc2e7 100644 --- a/sca-cpp/trunk/modules/python/python-test.cpp +++ b/sca-cpp/trunk/modules/python/python-test.cpp @@ -42,7 +42,7 @@ bool testEvalExpr() { PythonRuntime py; istringstream is(testPythonAdd); - failable script = readScript("script", "script.py", is, py); + failable script = readScript("script1", "script1.py", is, py); assert(hasContent(script)); const value exp = mklist("add", 2, 3); @@ -54,6 +54,29 @@ bool testEvalExpr() { return true; } +const string testPythonMap = + "def addmap(x, y):\n" + " return tuple(map(lambda i: i + y, x))\n"; + +bool testEvalList() { + gc_scoped_pool pool; + PythonRuntime py; + + istringstream is(testPythonMap); + failable script = readScript("script2", "script2.py", is, py); + assert(hasContent(script)); + + const value exp = mklist("addmap", mklist(1, 2, 3), 1); + const failable r = evalScript(exp, content(script), py); + assert(hasContent(r)); + assert(car(content(r)) == value(2)); + assert(cadr(content(r)) == value(3)); + assert(caddr(content(r)) == value(4)); + + releaseScript(content(script), py); + return true; +} + const value mult(const list& args) { const double x = car(args); const double y = cadr(args); @@ -104,7 +127,7 @@ struct testEvalReadAdd { } const bool operator()() const { istringstream is(testPythonAdd); - failable script = readScript("script", "script.py", is, py); + failable script = readScript("script3", "script3.py", is, py); assert(hasContent(script)); const value exp = mklist("add", 2, 3); @@ -139,7 +162,7 @@ bool testEvalPerf() { cout << "Python read + eval test " << time(erl, 5, 10000) << " ms" << endl; istringstream is(testPythonAdd); - failable script = readScript("script", "script.py", is, py); + failable script = readScript("script4", "script4.py", is, py); assert(hasContent(script)); const lambda el = lambda(testEvalAdd(content(script), py)); @@ -158,7 +181,7 @@ struct testReadEvalAddLoop { const bool operator()() const { for (int i = 0; i < 100; i++) { istringstream is(testPythonAdd); - failable script = readScript("script", "script.py", is, py); + failable script = readScript("script6", "script6.py", is, py); assert(hasContent(script)); const value exp = mklist("add", 2, 3); @@ -247,7 +270,7 @@ bool testThreads() { cout << "Python eval + read thread test " << time(elr, 1, 1) / 10000.0 << " ms" << endl; istringstream is(testPythonAdd); - failable script = readScript("script", "script.py", is, py); + failable script = readScript("script7", "script7.py", is, py); assert(hasContent(script)); const lambda el = lambda(testEvalThreads(w, max, content(script), py)); @@ -263,9 +286,13 @@ bool testThreads() { } int main() { + tuscany::gc_scoped_pool p; tuscany::cout << "Testing..." << tuscany::endl; tuscany::python::testEvalExpr(); + tuscany::python::testEvalList(); + tuscany::python::testEvalLambda(); + tuscany::python::testEvalLambda(); tuscany::python::testEvalLambda(); tuscany::python::testEvalPerf(); #ifdef WANT_THREADS -- cgit v1.2.3