[pypy-svn] r20131 - pypy/dist/pypy/translator/llvm/test

rxe at codespeak.net rxe at codespeak.net
Mon Nov 21 16:01:04 CET 2005


Author: rxe
Date: Mon Nov 21 16:01:02 2005
New Revision: 20131

Modified:
   pypy/dist/pypy/translator/llvm/test/test_exception.py
   pypy/dist/pypy/translator/llvm/test/test_extfunc.py
Log:
Added tests

* copied over thread tests from genc - but only test TheadLock pbcs in 
  test_prebuilt_lock() (all disabled)

* add an exception test to ensure skipping catching a base exception 



Modified: pypy/dist/pypy/translator/llvm/test/test_exception.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_exception.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_exception.py	Mon Nov 21 16:01:02 2005
@@ -242,6 +242,36 @@
     finally:
         restore_magic(saved)
 
+def test_miss_base():
+
+    class A(Exception):
+        pass
+
+    class B(A):
+        pass
+
+    def raise_exception(n):
+        if n == 1: raise A
+        elif n == 0: raise B
+        
+    def fn(n):
+        ok = False
+        try:
+            raise_exception(n)
+        except B, exc:
+            ok = True
+        return ok
+    
+    f = compile_function(fn, [int])
+    res = False
+    assert fn(0)
+    try:
+        f(1)
+    except:
+        res = True
+    assert res
+    assert not f(2)
+
 def no_magic():
     import __builtin__
     try:

Modified: pypy/dist/pypy/translator/llvm/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_extfunc.py	Mon Nov 21 16:01:02 2005
@@ -370,7 +370,95 @@
     compared_with.sort()
     assert result == compared_with
 
-# end of tests taken from c backend
+def test_lock():
+    py.test.skip("WIP")    
+    import thread
+    import pypy.module.thread.rpython.exttable   # for declare()/declaretype()
+    def fn():
+        l = thread.allocate_lock()
+        ok1 = l.acquire(True)
+        ok2 = l.acquire(False)
+        l.release()
+        ok2_and_a_half = False
+        try:
+            l.release()
+        except thread.error:
+            ok2_and_a_half = True
+        ok3 = l.acquire(False)
+        return ok1 and not ok2 and ok2_and_a_half and ok3
+    f = compile_function(fn, [])
+    res = f()
+    assert res
+
+def test_simple_start_new_thread():
+    py.test.skip("WIP")    
+    import thread
+    import pypy.module.thread.rpython.exttable   # for declare()/declaretype()
+    class Arg:
+        pass
+    def mythreadedfunction(arg):
+        assert arg.value == 42
+    def myotherthreadedfunction(arg):
+        assert arg.value == 43
+    a42 = Arg()
+    a42.value = 42
+    a43 = Arg()
+    a43.value = 43
+    def fn(i):
+        thread.start_new_thread(mythreadedfunction, (a42,))
+        thread.start_new_thread(myotherthreadedfunction, (a43,))
+        if i == 1:
+            x = mythreadedfunction
+            a = a42
+        else:
+            x = myotherthreadedfunction
+            a = a43
+        thread.start_new_thread(x, (a,))
+        return 42
+    f = compile_function(fn, [int])
+    res = f(1)
+    assert res == 42
 
+def test_start_new_thread():
+    py.test.skip("WIP")    
+    import thread
+    import pypy.module.thread.rpython.exttable   # for declare()/declaretype()
+    class Arg:
+        pass
+    a = Arg()
+    a.x = 5
+    def mythreadedfunction(arg):
+        arg.x += 37
+        arg.myident = thread.get_ident()
+        arg.lock.release()
+    def fn():
+        a.lock = thread.allocate_lock()
+        a.lock.acquire(True)
+        ident = thread.start_new_thread(mythreadedfunction, (a,))
+        assert ident != thread.get_ident()
+        a.lock.acquire(True)  # wait for the thread to finish
+        assert a.myident == ident
+        return a.x
+    f = compile_function(fn, [])
+    res = f()
+    assert res == 42
 
+def test_prebuilt_lock():
+    py.test.skip("WIP")    
+    import thread
+    import pypy.module.thread.rpython.exttable   # for declare()/declaretype()
+    lock0 = thread.allocate_lock()
+    lock1 = thread.allocate_lock()
+    lock1.acquire()
+    def fn(i):
+        lock = [lock0, lock1][i]
+        ok = lock.acquire(False)
+        if ok: lock.release()
+        return ok
+    f = compile_function(fn, [int])
+    res = f(0)
+    assert res is True
+    res = f(1)
+    assert res is False
 
+# end of tests taken from c backend



More information about the Pypy-commit mailing list