[pypy-svn] rev 2016 - pypy/trunk/src/pypy/translator/test

sanxiyn at codespeak.net sanxiyn at codespeak.net
Tue Oct 21 13:01:22 CEST 2003


Author: sanxiyn
Date: Tue Oct 21 13:01:21 2003
New Revision: 2016

Modified:
   pypy/trunk/src/pypy/translator/test/benchmark.py
   pypy/trunk/src/pypy/translator/test/buildcl.py
   pypy/trunk/src/pypy/translator/test/test_cltrans.py
Log:
Extracted CL detection functionality from testcase
to module. After all, it doesn't belong there.

Added CL to benchmark, and commented them out.
Try uncommenting yourself. It's very slow.


Modified: pypy/trunk/src/pypy/translator/test/benchmark.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/benchmark.py	(original)
+++ pypy/trunk/src/pypy/translator/test/benchmark.py	Tue Oct 21 13:01:21 2003
@@ -2,6 +2,7 @@
 from pypy.tool import test
 from pypy.tool.udir import udir
 from pypy.translator.test.test_pyrextrans import make_cfunc
+from pypy.translator.test.test_cltrans import make_cl_func
 
 def benchmark(func):
     try:
@@ -9,11 +10,14 @@
     except AttributeError:
         pass
     c_func = make_cfunc(func)
+    #cl_func = make_cl_func(func)
     print "generated c-func for", func.func_name
     t1 = timeit(100, func)
     t2 = timeit(100, c_func)
+    #t3 = timeit(100, cl_func)
     print "cpython func       ", t1, "seconds"
     print "pypy/pyrex/cmodule ", t2, "seconds"
+    #print "cl (experimental)  ", t3, "seconds"
    
 def timeit(num, func, *args):
     from time import time as now

Modified: pypy/trunk/src/pypy/translator/test/buildcl.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/buildcl.py	(original)
+++ pypy/trunk/src/pypy/translator/test/buildcl.py	Tue Oct 21 13:01:21 2003
@@ -16,7 +16,7 @@
     else:
         return int(s)
 
-def make_cl_func(func, cl, path):
+def _make_cl_func(func, cl, path):
     fun = FlowObjSpace().build_flow(func)
     gen = GenCL(fun)
     out = gen.emitcode()

Modified: pypy/trunk/src/pypy/translator/test/test_cltrans.py
==============================================================================
--- pypy/trunk/src/pypy/translator/test/test_cltrans.py	(original)
+++ pypy/trunk/src/pypy/translator/test/test_cltrans.py	Tue Oct 21 13:01:21 2003
@@ -1,39 +1,42 @@
 import autopath
 from pypy.tool import test
 from pypy.tool.udir import udir
-from pypy.translator.test.buildcl import make_cl_func
+from pypy.translator.test.buildcl import _make_cl_func
 from vpath.adapter.process import exec_cmd, ExecutionFailed
 
+
+import os
+
+def get_cl():
+    cl = os.getenv("PYPY_CL")
+    if cl: return cl
+    cl = cl_detect()
+    if cl: return cl
+    return None
+
+def cl_detect(self):
+    if self.is_on_path("clisp"):
+        return "clisp"
+    elif self.is_on_path("lisp"):
+        if self.is_on_path("cmuclinvoke.sh"):
+            return "cmuclinvoke.sh"
+    return None
+
+def is_on_path(self, name):
+    return os.system("which %s >/dev/null" % name) == 0
+
+global_cl = get_cl()
+
+def make_cl_func(func):
+    return _make_cl_func(func, global_cl, udir)
+
+
 class GenCLTestCase(test.IntTestCase):
 
     def setUp(self):
-        import os
-        cl = os.getenv("PYPY_CL")
-        if cl:
-            self.cl = cl
-        else:
-            cl = self.cl_detect()
-            if cl:
-                self.cl = cl
-            else:
-                raise (test.TestSkip,
-                       "Common Lisp neither configured nor detected.")
-
-    def cl_detect(self):
-        import os
-        if self.is_on_path("clisp"):
-            return "clisp"
-        elif self.is_on_path("lisp"):
-            if self.is_on_path("cmuclinvoke.sh"):
-                return "cmuclinvoke.sh"
-        return None
-
-    def is_on_path(self, name):
-        import os
-        return os.system("which %s >/dev/null" % name) == 0
-
-    def cl_func(self, func):
-        return make_cl_func(func, self.cl, udir)
+        if not global_cl:
+            raise (test.TestSkip,
+                   "Common Lisp neither configured nor detected.")
 
     #___________________________________
     def if_then_else(cond, x, y):
@@ -42,11 +45,11 @@
         else:
             return y
     def test_if_bool(self):
-        cl_if = self.cl_func(self.if_then_else)
+        cl_if = make_cl_func(self.if_then_else)
         self.assertEquals(cl_if(True, 50, 100), 50)
         self.assertEquals(cl_if(False, 50, 100), 100)
     def test_if_int(self):
-        cl_if = self.cl_func(self.if_then_else)
+        cl_if = make_cl_func(self.if_then_else)
         self.assertEquals(cl_if(0, 50, 100), 100)
         self.assertEquals(cl_if(1, 50, 100), 50)
 
@@ -59,7 +62,7 @@
             r = a % b
         return b
     def test_gcd(self):
-        cl_gcd = self.cl_func(self.my_gcd)
+        cl_gcd = make_cl_func(self.my_gcd)
         self.assertEquals(cl_gcd(96, 64), 32)
 
     #___________________________________
@@ -72,7 +75,7 @@
             div += 1
         return n == sum
     def test_is_perfect(self): # pun intended
-        cl_perfect = self.cl_func(self.is_perfect_number)
+        cl_perfect = make_cl_func(self.is_perfect_number)
         self.assertEquals(cl_perfect(24), False)
         self.assertEquals(cl_perfect(28), True)
 
@@ -80,7 +83,7 @@
     def my_bool(x):
         return not not x
     def test_bool(self):
-        cl_bool = self.cl_func(self.my_bool)
+        cl_bool = make_cl_func(self.my_bool)
         self.assertEquals(cl_bool(0), False)
         self.assertEquals(cl_bool(42), True)
         self.assertEquals(cl_bool(True), True)
@@ -93,7 +96,7 @@
         array[2] = array[0] + array[1]
         return array[2]
     def test_array(self):
-        cl_four = self.cl_func(self.two_plus_two)
+        cl_four = make_cl_func(self.two_plus_two)
         self.assertEquals(cl_four(), 4)
 
     #___________________________________
@@ -113,7 +116,7 @@
             i = i + 1
         return count
     def test_sieve(self):
-        cl_sieve = self.cl_func(self.sieve_of_eratosthenes)
+        cl_sieve = make_cl_func(self.sieve_of_eratosthenes)
         self.assertEquals(cl_sieve(), 1028)
 
 if __name__ == '__main__':


More information about the Pypy-commit mailing list