[pypy-svn] r77648 - pypy/branch/jitffi/pypy/rlib/test
antocuni at codespeak.net
antocuni at codespeak.net
Wed Oct 6 15:13:20 CEST 2010
Author: antocuni
Date: Wed Oct 6 15:13:18 2010
New Revision: 77648
Modified:
pypy/branch/jitffi/pypy/rlib/test/test_libffi.py
Log:
use an ad-hoc function instead of time: it tests the same behaviour, but at least we don't have to sleep() for 1 second waiting for the time to change
Modified: pypy/branch/jitffi/pypy/rlib/test/test_libffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/rlib/test/test_libffi.py (original)
+++ pypy/branch/jitffi/pypy/rlib/test/test_libffi.py Wed Oct 6 15:13:18 2010
@@ -172,29 +172,43 @@
res = self.call(func, [chr(20), 22], rffi.LONG)
assert res == 42
- def test_call_time(self):
- import time
- libc = self.get_libc()
- # XXX assume time_t is long
- # XXX: on msvcr80 the name of the function is _time32, fix it in that case
- func = (libc, 'time', [types.pointer], types.ulong)
- LONGP = rffi.CArray(rffi.LONG)
- null = lltype.nullptr(LONGP)
- t0 = self.call(func, [null], rffi.LONG)
- time.sleep(1)
- t1 = self.call(func, [null], rffi.LONG)
- assert t1 > t0
+ def test_pointer_as_argument(self):
+ """#include <stdlib.h>
+ long inc(long* x)
+ {
+ long oldval;
+ if (x == NULL)
+ return -1;
+ oldval = *x;
+ *x = oldval+1;
+ return oldval;
+ }
+ """
+ libfoo = self.get_libfoo()
+ func = (libfoo, 'inc', [types.pointer], types.slong)
+ LONGP = lltype.Ptr(rffi.CArray(rffi.LONG))
+ null = lltype.nullptr(LONGP.TO)
+ res = self.call(func, [null], rffi.LONG)
+ assert res == -1
#
- ptr_result = lltype.malloc(LONGP, 1, flavor='raw')
- t2 = self.call(func, [ptr_result], rffi.LONG)
- assert ptr_result[0] == t2
- lltype.free(ptr_result, flavor='raw')
+ ptr_result = lltype.malloc(LONGP.TO, 1, flavor='raw')
+ ptr_result[0] = 41
+ res = self.call(func, [ptr_result], rffi.LONG)
if self.__class__ is TestLibffiCall:
+ # the function was called only once
+ assert res == 41
+ assert ptr_result[0] == 42
+ lltype.free(ptr_result, flavor='raw')
# the test does not make sense when run with the JIT through
# meta_interp, because the __del__ are not properly called (hence
# we "leak" memory)
- del libc
+ del libfoo
assert not ALLOCATED
+ else:
+ # the function as been called 9 times
+ assert res == 50
+ assert ptr_result[0] == 51
+ lltype.free(ptr_result, flavor='raw')
def test_return_pointer(self):
"""
@@ -216,3 +230,4 @@
null = lltype.nullptr(LONGP.TO)
res = self.call(func, [], LONGP, init_result=null)
assert res[0] == 20
+
More information about the Pypy-commit
mailing list