[pypy-svn] r46492 - pypy/dist/pypy/translator/llvm/test
rxe at codespeak.net
rxe at codespeak.net
Wed Sep 12 12:05:50 CEST 2007
Author: rxe
Date: Wed Sep 12 12:05:49 2007
New Revision: 46492
Added:
pypy/dist/pypy/translator/llvm/test/test_rffi.py
pypy/dist/pypy/translator/llvm/test/test_threading.py
Modified:
pypy/dist/pypy/translator/llvm/test/runtest.py
pypy/dist/pypy/translator/llvm/test/test_extfunc.py
pypy/dist/pypy/translator/llvm/test/test_genllvm1.py
pypy/dist/pypy/translator/llvm/test/test_lltype.py
pypy/dist/pypy/translator/llvm/test/test_rtagged.py
Log:
just shuffling tests around. they are all still skipped
Modified: pypy/dist/pypy/translator/llvm/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/runtest.py (original)
+++ pypy/dist/pypy/translator/llvm/test/runtest.py Wed Sep 12 12:05:49 2007
@@ -1,6 +1,6 @@
import py
-py.test.skip("llvm is no longer actively maintained")
-from pypy.tool import isolate
+py.test.skip("llvm is not actively maintained")
+
from pypy.translator.llvm.buildllvm import llvm_is_on_path, llvm_version, gcc_version
from pypy.translator.llvm.genllvm import GenLLVM
@@ -9,14 +9,16 @@
ext_modules = []
-# test options
+# prevents resource leaking
+use_isolate = True
+
+# if test can't be run using isolate, skip the test (useful for buildbots)
run_isolated_only = True
-do_not_isolate = False
from pypy import conftest
def _cleanup(leave=0):
- # no test should ever need more than 5 compiled functions
+ from pypy.tool import isolate
if leave:
mods = ext_modules[:-leave]
else:
@@ -40,13 +42,6 @@
py.test.skip("llvm version not up-to-date (found "
"%.1f, should be >= %.1f)" % (llvm_ver, MINIMUM_LLVM_VERSION))
-def gcc3_test():
- gcc_ver = gcc_version()
- if int(gcc_ver) != 3:
- py.test.skip("test required gcc version 3 (found version %.1f)" % gcc_ver)
- return False
- return True
-
#______________________________________________________________________________
def genllvm_compile(function,
@@ -89,14 +84,15 @@
driver.translator.view()
return driver.c_module, driver.c_entryp
-def compile_test(function, annotation, isolate=True, **kwds):
+def compile_test(function, annotation, isolate_hint=True, **kwds):
" returns module and compiled function "
llvm_test()
- if run_isolated_only and not isolate:
- py.test.skip("skipping not isolated test")
+
+ if run_isolated_only and not isolate_hint:
+ py.test.skip("skipping unrecommended isolated test")
# turn off isolation?
- isolate = isolate and not do_not_isolate
+ isolate = use_isolate and isolate_hint
# maintain only 3 isolated process (if any)
_cleanup(leave=3)
@@ -107,7 +103,7 @@
ext_modules.append(mod)
return mod, fn
-def compile_function(function, annotation, isolate=True, **kwds):
+def compile_function(function, annotation, isolate_hint=True, **kwds):
" returns compiled function "
- return compile_test(function, annotation, isolate=isolate, **kwds)[1]
+ return compile_test(function, annotation, isolate_hint=isolate_hint, **kwds)[1]
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 Wed Sep 12 12:05:49 2007
@@ -4,21 +4,9 @@
import sys
import py
-from pypy.tool.udir import udir
-from pypy.rlib.rarithmetic import r_uint
-
-py.test.skip("Extfunc support in llvm needs refactoring")
-# XXX in particular, try to share the tests from c/test/test_extfunc!
from pypy.translator.llvm.test.runtest import *
-def test_external_function_ll_os_dup():
- def fn():
- return os.dup(0)
- f = compile_function(fn, [], isolate=False)
- fn()
- assert os.path.sameopenfile(f(), fn())
-
def test_external_function_ll_time_time():
import time
def fn():
@@ -30,135 +18,15 @@
import time
def fn():
return time.clock()
- f = compile_function(fn, [], isolate=False)
+ f = compile_function(fn, [], isolate_hint=False)
assert abs(f()-fn()) < 10.0
-def test_external_function_ll_time_sleep():
- import time
- def fn(t):
- time.sleep(t)
- return 666
- f = compile_function(fn, [float])
- start_time = time.time()
- delay_time = 2.0
- d = f(delay_time)
- duration = time.time() - start_time
- assert duration >= delay_time - 0.5
- assert duration <= delay_time + 0.5
-
-path = str(udir.join("e"))
-
-def test_os_file_ops_open_close():
- def openclose():
- fd = os.open(path, os.O_CREAT|os.O_RDWR, 0777)
- os.close(fd)
- return fd
-
- if os.path.exists(path):
- os.unlink(path)
- f = compile_function(openclose, [])
- result = f()
- assert os.path.exists(path)
-
-def test_os_file_ops_open_write_close():
- if sys.maxint != 2**31-1:
- py.test.skip("WIP on 64 bit architectures")
- def openwriteclose():
- fd = os.open(path, os.O_CREAT|os.O_RDWR, 0777)
- byteswritten = os.write(fd, path)
- os.close(fd)
- return byteswritten
-
- if os.path.exists(path):
- os.unlink(path)
- f = compile_function(openwriteclose, [])
- result = f()
- assert os.path.exists(path)
- assert open(path).read() == path
-
-def test_os_file_ops_open_write_read_close():
- if sys.maxint != 2**31-1:
- py.test.skip("WIP on 64 bit architectures")
- def openwriteclose_openreadclose():
- fd = os.open(path, os.O_CREAT|os.O_RDWR, 0777)
- byteswritten = os.write(fd, path+path+path)
- os.close(fd)
-
- fd = os.open(path, os.O_RDWR, 0777)
- maxread = 1000
- r = os.read(fd, maxread)
- os.close(fd)
-
- return len(r)
-
- if os.path.exists(path):
- os.unlink(path)
- f = compile_function(openwriteclose_openreadclose, [])
- result = f()
- assert os.path.exists(path)
- assert open(path).read() == path * 3
- assert result is len(path) * 3
-
-# following from translator/c/test/test_extfunc.py Revision: 15320 (jul 29th 2005)
-
-def test_os_stat():
- if sys.maxint != 2**31-1:
- py.test.skip("WIP on 64 bit architectures")
- filename = str(py.magic.autopath())
- def call_stat0():
- st = os.stat(filename)
- return st[0]
- def call_stat1():
- st = os.stat(filename)
- return st[1]
- def call_stat2():
- st = os.stat(filename)
- return st[2]
- f0 = compile_function(call_stat0, [])
- f1 = compile_function(call_stat1, [])
- f2 = compile_function(call_stat2, [])
- st = os.stat(filename)
- assert f0() == st[0]
- assert f1() == st[1]
- assert f2() == st[2]
+def test_math_frexp():
+ py.test.skip("what the hell is going on!")
-def test_os_fstat():
if sys.maxint != 2**31-1:
py.test.skip("WIP on 64 bit architectures")
- filename = str(py.magic.autopath())
- def call_fstat0():
- fd = os.open(filename, os.O_RDONLY, 0777)
- st = os.fstat(fd)
- os.close(fd)
- return st[0]
- def call_fstat1():
- fd = os.open(filename, os.O_RDONLY, 0777)
- st = os.fstat(fd)
- os.close(fd)
- return st[1]
- def call_fstat2():
- fd = os.open(filename, os.O_RDONLY, 0777)
- st = os.fstat(fd)
- os.close(fd)
- return st[2]
- f0 = compile_function(call_fstat0, [])
- f1 = compile_function(call_fstat1, [])
- f2 = compile_function(call_fstat2, [])
- st = os.stat(filename)
- assert f0() == st[0]
- assert f1() == st[1]
- assert f2() == st[2]
-
-def test_os_getcwd():
- cwd = os.getcwd()
- def does_stuff():
- return os.getcwd() == cwd
- f1 = compile_function(does_stuff, [])
- assert f1()
-def test_math_frexp():
- if sys.maxint != 2**31-1:
- py.test.skip("WIP on 64 bit architectures")
from math import frexp
def fn(x):
res = frexp(x)
@@ -168,6 +36,8 @@
assert res == fn(10.123)
def test_math_modf():
+ py.test.skip("what the hell is going on!")
+
from math import modf
def fn(x):
res = modf(x)
@@ -196,54 +66,6 @@
for funcname in simple_math_functions:
yield math_function_test, funcname
-def test_os_path_exists():
- if sys.maxint != 2**31-1:
- py.test.skip("WIP on 64 bit architectures")
- tmpfile = str(udir.join('test_os_path_exists.TMP'))
- def fn():
- return os.path.exists(tmpfile)
- f = compile_function(fn, [])
- open(tmpfile, 'w').close()
- assert f() == True
- os.unlink(tmpfile)
- assert f() == False
-
-def test_dynamic_string_null_termination():
- if sys.maxint != 2**31-1:
- py.test.skip("WIP on 64 bit architectures")
- # forces malloc / versus pbc for NUL testing of C string
- tmpfile = str(udir.join('test_os_path_exists.TMP'))
- def fn(l):
- filename = tmpfile[:l]
- return os.path.exists(filename)
- f = compile_function(fn, [r_uint])
- open(tmpfile, 'w').close()
- lfile = len(tmpfile)
- assert f(lfile) == True
- assert f(lfile-2) == False
-
-def test_os_path_isdir():
- if sys.maxint != 2**31-1:
- py.test.skip("WIP on 64 bit architectures")
- directory = "./."
- def fn():
- return os.path.isdir(directory)
- f = compile_function(fn, [])
- assert f() == True
- directory = "some/random/name"
- def fn():
- return os.path.isdir(directory)
- f = compile_function(fn, [])
- assert f() == False
-
-def test_os_isatty():
- def call_isatty(fd):
- return os.isatty(fd)
- f = compile_function(call_isatty, [int], isolate=False)
- assert f(0) == os.isatty(0)
- assert f(1) == os.isatty(1)
- assert f(2) == os.isatty(2)
-
def test_rarith_parts_to_float():
if sys.maxint != 2**31-1:
py.test.skip("WIP on 64 bit architectures")
@@ -276,305 +98,3 @@
for i, s in enumerate(as_string):
assert f(i)
-def test_os_unlink():
- tmpfile = str(udir.join('test_os_path_exists.TMP'))
- def fn():
- os.unlink(tmpfile)
- return 0
- f = compile_function(fn, [])
- open(tmpfile, 'w').close()
- fn()
- assert not os.path.exists(tmpfile)
-
-def test_chdir():
- path = '..'
- def does_stuff():
- os.chdir(path)
- return 0
- f1 = compile_function(does_stuff, [])
- curdir = os.getcwd()
- try:
- os.chdir()
- except: pass # toplevel
- def does_stuff2():
- os.chdir(curdir)
- return 0
- f1 = compile_function(does_stuff2, [])
- f1()
- assert curdir == os.getcwd()
-
-def test_mkdir_rmdir():
- path = str(udir.join('test_mkdir_rmdir'))
- def does_stuff(delete):
- if delete:
- os.rmdir(path)
- else:
- os.mkdir(path, 0777)
- return 0
- f1 = compile_function(does_stuff, [bool])
- f1(False)
- assert os.path.exists(path) and os.path.isdir(path)
- f1(True)
- assert not os.path.exists(path)
-
-# more from translator/c/test/test_extfunc.py Revision: 19054
-
-
-def test_lock():
- py.test.skip("XXX does not work with exception transform (why not?)")
- 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():
- 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():
- if sys.maxint != 2**31-1:
- py.test.skip("WIP on 64 bit architectures")
- 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():
- 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 == True
- res = f(1)
- assert res == False
-
-def test_pipe_dup_dup2():
- def does_stuff():
- a, b = os.pipe()
- c = os.dup(a)
- d = os.dup(b)
- assert a != b
- assert a != c
- assert a != d
- assert b != c
- assert b != d
- assert c != d
- os.close(c)
- os.dup2(d, c)
- e, f = os.pipe()
- assert e != a
- assert e != b
- assert e != c
- assert e != d
- assert f != a
- assert f != b
- assert f != c
- assert f != d
- assert f != e
- os.close(a)
- os.close(b)
- os.close(c)
- os.close(d)
- os.close(e)
- os.close(f)
- return 42
- f1 = compile_function(does_stuff, [])
- res = f1()
- assert res == 42
-
-def test_os_chmod():
- tmpfile = str(udir.join('test_os_chmod.txt'))
- f = open(tmpfile, 'w')
- f.close()
- def does_stuff(mode):
- os.chmod(tmpfile, mode)
- return 0
- f1 = compile_function(does_stuff, [int])
- f1(0000)
- assert os.stat(tmpfile).st_mode & 0777 == 0000
- f1(0644)
- assert os.stat(tmpfile).st_mode & 0777 == 0644
-
-def test_os_rename():
- tmpfile1 = str(udir.join('test_os_rename_1.txt'))
- tmpfile2 = str(udir.join('test_os_rename_2.txt'))
- f = open(tmpfile1, 'w')
- f.close()
- def does_stuff():
- os.rename(tmpfile1, tmpfile2)
- return 0
- f1 = compile_function(does_stuff, [])
- f1()
- assert os.path.exists(tmpfile2)
- assert not os.path.exists(tmpfile1)
-
-if hasattr(os, 'getpid'):
- def test_os_getpid():
- def does_stuff():
- return os.getpid()
- f1 = compile_function(does_stuff, [], isolate=False)
- res = f1()
- assert res == os.getpid()
-
-if hasattr(os, 'link'):
- def test_links():
- import stat
- tmpfile1 = str(udir.join('test_links_1.txt'))
- tmpfile2 = str(udir.join('test_links_2.txt'))
- tmpfile3 = str(udir.join('test_links_3.txt'))
- f = open(tmpfile1, 'w')
- f.close()
- def does_stuff():
- os.symlink(tmpfile1, tmpfile2)
- os.link(tmpfile1, tmpfile3)
- assert os.readlink(tmpfile2) == tmpfile1
- flag= 0
- st = os.lstat(tmpfile1)
- flag = flag*10 + stat.S_ISREG(st[0])
- flag = flag*10 + stat.S_ISLNK(st[0])
- st = os.lstat(tmpfile2)
- flag = flag*10 + stat.S_ISREG(st[0])
- flag = flag*10 + stat.S_ISLNK(st[0])
- st = os.lstat(tmpfile3)
- flag = flag*10 + stat.S_ISREG(st[0])
- flag = flag*10 + stat.S_ISLNK(st[0])
- return flag
- f1 = compile_function(does_stuff, [])
- res = f1()
- assert res == 100110
- assert os.path.islink(tmpfile2)
- assert not os.path.islink(tmpfile3)
-if hasattr(os, 'fork'):
- def test_fork():
- def does_stuff():
- pid = os.fork()
- if pid == 0: # child
- os._exit(4)
- pid1, status1 = os.waitpid(pid, 0)
- assert pid1 == pid
- return status1
- f1 = compile_function(does_stuff, [])
- status1 = f1()
- assert os.WIFEXITED(status1)
- assert os.WEXITSTATUS(status1) == 4
-
-if hasattr(posix, 'execv'):
- def test_execv():
- py.test.skip("not working yet")
- filename = str(udir.join('test_execv.txt'))
- executable = sys.executable
- def does_stuff():
- progname = str(executable)
- l = ['', '']
- l[0] = progname
- l[1] = "-c"
- l.append('open("%s","w").write("1")' % filename)
- pid = os.fork()
- if pid == 0:
- os.execv(progname, l)
- else:
- os.waitpid(pid, 0)
- return 1
- func = compile_function(does_stuff, [])
- func()
- assert open(filename).read() == "1"
-
- def test_execv_raising():
- py.test.skip("not working yet")
- def does_stuff():
- l = []
- l.append("asddsadw32eewdfwqdqwdqwd")
- try:
- os.execv(l[0], l)
- except OSError:
- return 1
- else:
- return 0
- func = compile_function(does_stuff, [])
- res = func()
- assert res == 1
-
- def test_execve():
- py.test.skip("not working yet")
- filename = str(udir.join('test_execve.txt'))
- executable = sys.executable
- def does_stuff():
- progname = executable
- l = []
- l.append(progname)
- l.append("-c")
- l.append('import os; open("%s", "w").write(os.environ["STH"])' % filename)
- env = {}
- env["STH"] = "42"
- env["sthelse"] = "a"
- pid = os.fork()
- if pid == 0:
- os.execve(progname, l, env)
- else:
- os.waitpid(pid, 0)
- return 1
- func = compile_function(does_stuff, [])
- func()
- assert open(filename).read() == "42"
Modified: pypy/dist/pypy/translator/llvm/test/test_genllvm1.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_genllvm1.py (original)
+++ pypy/dist/pypy/translator/llvm/test/test_genllvm1.py Wed Sep 12 12:05:49 2007
@@ -70,7 +70,7 @@
class TestString(object):
def test_f2(self):
f = compile_function(llvmsnippet.string_f2, [int, int])
- assert chr(f(1, 0)) == "a"
+ assert f(1, 0) == "a"
class TestPBC(object):
Modified: pypy/dist/pypy/translator/llvm/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_lltype.py (original)
+++ pypy/dist/pypy/translator/llvm/test/test_lltype.py Wed Sep 12 12:05:49 2007
@@ -240,7 +240,6 @@
assert f() == floats_fn()
def test_fixedsizearray():
- gcc3_test()
S = Struct("s", ('v', Signed))
A7 = FixedSizeArray(Signed, 7)
A3 = FixedSizeArray(S, 3)
@@ -269,7 +268,6 @@
assert fn() == 607
def test_recursivearray():
- gcc3_test()
A = ForwardReference()
A.become(FixedSizeArray(Struct("S", ('a', Ptr(A))), 5))
TREE = GcStruct("TREE", ("root", A), ("other", A))
@@ -300,7 +298,6 @@
fn()
def test_call_with_fixedsizearray():
- gcc3_test()
A = FixedSizeArray(Struct('s1', ('x', Signed)), 5)
S = GcStruct('s', ('a', Ptr(A)))
a = malloc(A, immortal=True)
@@ -316,7 +313,6 @@
assert res == 123
def test_more_prebuilt_arrays():
- gcc3_test()
A = FixedSizeArray(Struct('s1', ('x', Signed)), 5)
S = GcStruct('s', ('a1', Ptr(A)), ('a2', A))
s = malloc(S, zero=True)
@@ -336,7 +332,6 @@
assert res == 60
def test_fnptr_with_fixedsizearray():
- gcc3_test()
A = ForwardReference()
F = FuncType([Ptr(A)], Signed)
A.become(FixedSizeArray(Struct('s1', ('f', Ptr(F)), ('n', Signed)), 5))
@@ -385,7 +380,6 @@
assert res == 0 + 10 + 30 + 1000
def test_direct_fieldptr():
- gcc3_test()
S = GcStruct('S', ('x', Signed), ('y', Signed))
def llf(n):
s = malloc(S)
Added: pypy/dist/pypy/translator/llvm/test/test_rffi.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/test/test_rffi.py Wed Sep 12 12:05:49 2007
@@ -0,0 +1,401 @@
+import os
+import sys
+
+import py
+from pypy.tool.udir import udir
+from pypy.rlib.rarithmetic import r_uint
+
+py.test.skip("Extfunc support in llvm needs refactoring (!!??!)")
+
+from pypy.translator.llvm.test.runtest import *
+
+def test_external_function_ll_os_dup():
+ def fn():
+ return os.dup(0)
+ f = compile_function(fn, [], isolate_hint=False)
+ fn()
+ assert os.path.sameopenfile(f(), fn())
+
+def test_external_function_ll_time_sleep():
+ import time
+ def fn(t):
+ time.sleep(t)
+ return 666
+ f = compile_function(fn, [float])
+ start_time = time.time()
+ delay_time = 2.0
+ d = f(delay_time)
+ duration = time.time() - start_time
+ assert duration >= delay_time - 0.5
+ assert duration <= delay_time + 0.5
+
+path = str(udir.join("e"))
+
+def test_os_file_ops_open_close():
+ def openclose():
+ fd = os.open(path, os.O_CREAT|os.O_RDWR, 0777)
+ os.close(fd)
+ return fd
+
+ if os.path.exists(path):
+ os.unlink(path)
+ f = compile_function(openclose, [])
+ result = f()
+ assert os.path.exists(path)
+
+def test_os_file_ops_open_write_close():
+ if sys.maxint != 2**31-1:
+ py.test.skip("WIP on 64 bit architectures")
+ def openwriteclose():
+ fd = os.open(path, os.O_CREAT|os.O_RDWR, 0777)
+ byteswritten = os.write(fd, path)
+ os.close(fd)
+ return byteswritten
+
+ if os.path.exists(path):
+ os.unlink(path)
+ f = compile_function(openwriteclose, [])
+ result = f()
+ assert os.path.exists(path)
+ assert open(path).read() == path
+
+def test_os_file_ops_open_write_read_close():
+ if sys.maxint != 2**31-1:
+ py.test.skip("WIP on 64 bit architectures")
+ def openwriteclose_openreadclose():
+ fd = os.open(path, os.O_CREAT|os.O_RDWR, 0777)
+ byteswritten = os.write(fd, path+path+path)
+ os.close(fd)
+
+ fd = os.open(path, os.O_RDWR, 0777)
+ maxread = 1000
+ r = os.read(fd, maxread)
+ os.close(fd)
+
+ return len(r)
+
+ if os.path.exists(path):
+ os.unlink(path)
+ f = compile_function(openwriteclose_openreadclose, [])
+ result = f()
+ assert os.path.exists(path)
+ assert open(path).read() == path * 3
+ assert result is len(path) * 3
+
+# following from translator/c/test/test_extfunc.py Revision: 15320 (jul 29th 2005)
+
+def test_os_stat():
+ if sys.maxint != 2**31-1:
+ py.test.skip("WIP on 64 bit architectures")
+ filename = str(py.magic.autopath())
+ def call_stat0():
+ st = os.stat(filename)
+ return st[0]
+ def call_stat1():
+ st = os.stat(filename)
+ return st[1]
+ def call_stat2():
+ st = os.stat(filename)
+ return st[2]
+ f0 = compile_function(call_stat0, [])
+ f1 = compile_function(call_stat1, [])
+ f2 = compile_function(call_stat2, [])
+ st = os.stat(filename)
+ assert f0() == st[0]
+ assert f1() == st[1]
+ assert f2() == st[2]
+
+def test_os_fstat():
+ if sys.maxint != 2**31-1:
+ py.test.skip("WIP on 64 bit architectures")
+ filename = str(py.magic.autopath())
+ def call_fstat0():
+ fd = os.open(filename, os.O_RDONLY, 0777)
+ st = os.fstat(fd)
+ os.close(fd)
+ return st[0]
+ def call_fstat1():
+ fd = os.open(filename, os.O_RDONLY, 0777)
+ st = os.fstat(fd)
+ os.close(fd)
+ return st[1]
+ def call_fstat2():
+ fd = os.open(filename, os.O_RDONLY, 0777)
+ st = os.fstat(fd)
+ os.close(fd)
+ return st[2]
+ f0 = compile_function(call_fstat0, [])
+ f1 = compile_function(call_fstat1, [])
+ f2 = compile_function(call_fstat2, [])
+ st = os.stat(filename)
+ assert f0() == st[0]
+ assert f1() == st[1]
+ assert f2() == st[2]
+
+def test_os_getcwd():
+ cwd = os.getcwd()
+ def does_stuff():
+ return os.getcwd() == cwd
+ f1 = compile_function(does_stuff, [])
+
+ assert f1()
+
+def test_os_path_exists():
+ if sys.maxint != 2**31-1:
+ py.test.skip("WIP on 64 bit architectures")
+ tmpfile = str(udir.join('test_os_path_exists.TMP'))
+ def fn():
+ return os.path.exists(tmpfile)
+ f = compile_function(fn, [])
+ open(tmpfile, 'w').close()
+ assert f() == True
+ os.unlink(tmpfile)
+ assert f() == False
+
+def test_dynamic_string_null_termination():
+ if sys.maxint != 2**31-1:
+ py.test.skip("WIP on 64 bit architectures")
+ # forces malloc / versus pbc for NUL testing of C string
+ tmpfile = str(udir.join('test_os_path_exists.TMP'))
+ def fn(l):
+ filename = tmpfile[:l]
+ return os.path.exists(filename)
+ f = compile_function(fn, [r_uint])
+ open(tmpfile, 'w').close()
+ lfile = len(tmpfile)
+ assert f(lfile) == True
+ assert f(lfile-2) == False
+
+def test_os_path_isdir():
+ if sys.maxint != 2**31-1:
+ py.test.skip("WIP on 64 bit architectures")
+ directory = "./."
+ def fn():
+ return os.path.isdir(directory)
+ f = compile_function(fn, [])
+ assert f() == True
+ directory = "some/random/name"
+ def fn():
+ return os.path.isdir(directory)
+ f = compile_function(fn, [])
+ assert f() == False
+
+def test_os_isatty():
+ def call_isatty(fd):
+ return os.isatty(fd)
+ f = compile_function(call_isatty, [int], isolate_hint=False)
+ assert f(0) == os.isatty(0)
+ assert f(1) == os.isatty(1)
+ assert f(2) == os.isatty(2)
+
+
+def test_os_chmod():
+ tmpfile = str(udir.join('test_os_chmod.txt'))
+ f = open(tmpfile, 'w')
+ f.close()
+ def does_stuff(mode):
+ os.chmod(tmpfile, mode)
+ return 0
+ f1 = compile_function(does_stuff, [int])
+ f1(0000)
+ assert os.stat(tmpfile).st_mode & 0777 == 0000
+ f1(0644)
+ assert os.stat(tmpfile).st_mode & 0777 == 0644
+
+def test_os_rename():
+ tmpfile1 = str(udir.join('test_os_rename_1.txt'))
+ tmpfile2 = str(udir.join('test_os_rename_2.txt'))
+ f = open(tmpfile1, 'w')
+ f.close()
+ def does_stuff():
+ os.rename(tmpfile1, tmpfile2)
+ return 0
+ f1 = compile_function(does_stuff, [])
+ f1()
+ assert os.path.exists(tmpfile2)
+ assert not os.path.exists(tmpfile1)
+
+if hasattr(os, 'getpid'):
+ def test_os_getpid():
+ def does_stuff():
+ return os.getpid()
+ f1 = compile_function(does_stuff, [], isolate_hint=False)
+ res = f1()
+ assert res == os.getpid()
+
+if hasattr(os, 'link'):
+ def test_links():
+ import stat
+ tmpfile1 = str(udir.join('test_links_1.txt'))
+ tmpfile2 = str(udir.join('test_links_2.txt'))
+ tmpfile3 = str(udir.join('test_links_3.txt'))
+ f = open(tmpfile1, 'w')
+ f.close()
+ def does_stuff():
+ os.symlink(tmpfile1, tmpfile2)
+ os.link(tmpfile1, tmpfile3)
+ assert os.readlink(tmpfile2) == tmpfile1
+ flag= 0
+ st = os.lstat(tmpfile1)
+ flag = flag*10 + stat.S_ISREG(st[0])
+ flag = flag*10 + stat.S_ISLNK(st[0])
+ st = os.lstat(tmpfile2)
+ flag = flag*10 + stat.S_ISREG(st[0])
+ flag = flag*10 + stat.S_ISLNK(st[0])
+ st = os.lstat(tmpfile3)
+ flag = flag*10 + stat.S_ISREG(st[0])
+ flag = flag*10 + stat.S_ISLNK(st[0])
+ return flag
+ f1 = compile_function(does_stuff, [])
+ res = f1()
+ assert res == 100110
+ assert os.path.islink(tmpfile2)
+ assert not os.path.islink(tmpfile3)
+if hasattr(os, 'fork'):
+ def test_fork():
+ def does_stuff():
+ pid = os.fork()
+ if pid == 0: # child
+ os._exit(4)
+ pid1, status1 = os.waitpid(pid, 0)
+ assert pid1 == pid
+ return status1
+ f1 = compile_function(does_stuff, [])
+ status1 = f1()
+ assert os.WIFEXITED(status1)
+ assert os.WEXITSTATUS(status1) == 4
+
+posix = __import__(os.name)
+if hasattr(posix, 'execv'):
+ def test_execv():
+ py.test.skip("not working yet")
+ filename = str(udir.join('test_execv.txt'))
+ executable = sys.executable
+ def does_stuff():
+ progname = str(executable)
+ l = ['', '']
+ l[0] = progname
+ l[1] = "-c"
+ l.append('open("%s","w").write("1")' % filename)
+ pid = os.fork()
+ if pid == 0:
+ os.execv(progname, l)
+ else:
+ os.waitpid(pid, 0)
+ return 1
+ func = compile_function(does_stuff, [])
+ func()
+ assert open(filename).read() == "1"
+
+ def test_execv_raising():
+ py.test.skip("not working yet")
+ def does_stuff():
+ l = []
+ l.append("asddsadw32eewdfwqdqwdqwd")
+ try:
+ os.execv(l[0], l)
+ except OSError:
+ return 1
+ else:
+ return 0
+ func = compile_function(does_stuff, [])
+ res = func()
+ assert res == 1
+
+ def test_execve():
+ py.test.skip("not working yet")
+ filename = str(udir.join('test_execve.txt'))
+ executable = sys.executable
+ def does_stuff():
+ progname = executable
+ l = []
+ l.append(progname)
+ l.append("-c")
+ l.append('import os; open("%s", "w").write(os.environ["STH"])' % filename)
+ env = {}
+ env["STH"] = "42"
+ env["sthelse"] = "a"
+ pid = os.fork()
+ if pid == 0:
+ os.execve(progname, l, env)
+ else:
+ os.waitpid(pid, 0)
+ return 1
+ func = compile_function(does_stuff, [])
+ func()
+ assert open(filename).read() == "42"
+
+def test_os_unlink():
+ tmpfile = str(udir.join('test_os_path_exists.TMP'))
+ def fn():
+ os.unlink(tmpfile)
+ return 0
+ f = compile_function(fn, [])
+ open(tmpfile, 'w').close()
+ fn()
+ assert not os.path.exists(tmpfile)
+
+def test_chdir():
+ path = '..'
+ def does_stuff():
+ os.chdir(path)
+ return 0
+ f1 = compile_function(does_stuff, [])
+ curdir = os.getcwd()
+ try:
+ os.chdir()
+ except: pass # toplevel
+ def does_stuff2():
+ os.chdir(curdir)
+ return 0
+ f1 = compile_function(does_stuff2, [])
+ f1()
+ assert curdir == os.getcwd()
+
+def test_mkdir_rmdir():
+ path = str(udir.join('test_mkdir_rmdir'))
+ def does_stuff(delete):
+ if delete:
+ os.rmdir(path)
+ else:
+ os.mkdir(path, 0777)
+ return 0
+ f1 = compile_function(does_stuff, [bool])
+ f1(False)
+ assert os.path.exists(path) and os.path.isdir(path)
+ f1(True)
+ assert not os.path.exists(path)
+
+def test_pipe_dup_dup2():
+ def does_stuff():
+ a, b = os.pipe()
+ c = os.dup(a)
+ d = os.dup(b)
+ assert a != b
+ assert a != c
+ assert a != d
+ assert b != c
+ assert b != d
+ assert c != d
+ os.close(c)
+ os.dup2(d, c)
+ e, f = os.pipe()
+ assert e != a
+ assert e != b
+ assert e != c
+ assert e != d
+ assert f != a
+ assert f != b
+ assert f != c
+ assert f != d
+ assert f != e
+ os.close(a)
+ os.close(b)
+ os.close(c)
+ os.close(d)
+ os.close(e)
+ os.close(f)
+ return 42
+ f1 = compile_function(does_stuff, [])
+ res = f1()
+ assert res == 42
Modified: pypy/dist/pypy/translator/llvm/test/test_rtagged.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_rtagged.py (original)
+++ pypy/dist/pypy/translator/llvm/test/test_rtagged.py Wed Sep 12 12:05:49 2007
@@ -1,6 +1,10 @@
+import py
+
import sys, os
from pypy.rlib.objectmodel import UnboxedValue
+from pypy.translator.llvm.test.runtest import *
+
class A(object):
__slots__ = ()
def meth(self, x):
@@ -62,13 +66,11 @@
# ____________________________________________________________
# only with Boehm so far
-from pypy.translator.llvm.test import runtest
from pypy.translator.interactive import Translation
from pypy import conftest
def test_tagged_boehm():
- runtest.llvm_test()
- runtest.gcc3_test()
+ py.test.skip("broken as test need rffi")
t = Translation(entry_point, standalone=True, gc='boehm')
try:
exename = t.compile_llvm()
Added: pypy/dist/pypy/translator/llvm/test/test_threading.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/test/test_threading.py Wed Sep 12 12:05:49 2007
@@ -0,0 +1,88 @@
+import sys
+
+import py
+py.test.skip("threading is broken")
+
+import thread
+
+from pypy.translator.llvm.test.runtest import *
+
+def test_lock():
+ 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():
+ 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():
+ 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():
+ 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 == True
+ res = f(1)
+ assert res == False
+
More information about the Pypy-commit
mailing list