Author: Remi Meier <[email protected]>
Branch: c7
Changeset: r611:8a471acbcc36
Date: 2014-01-15 10:22 +0100
http://bitbucket.org/pypy/stmgc/changeset/8a471acbcc36/
Log: tests
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -88,25 +88,30 @@
return lib._stm_is_in_nursery(ptr)
def stm_allocate_old(size):
- return lib._stm_real_address(lib._stm_allocate_old(size))
+ o = lib._stm_allocate_old(size)
+ return o, lib._stm_real_address(o)
def stm_allocate(size):
- return lib._stm_real_address(lib.stm_allocate(size))
+ o = lib.stm_allocate(size)
+ return o, lib._stm_real_address(o)
+def stm_get_real_address(obj):
+ return lib._stm_real_address(ffi.cast('object_t*', obj))
+
def stm_get_tl_address(ptr):
return int(ffi.cast('uintptr_t', lib._stm_tl_address(ptr)))
-def stm_read(ptr):
- lib.stm_read(lib._stm_tl_address(ptr))
+def stm_read(o):
+ lib.stm_read(o)
-def stm_write(ptr):
- lib.stm_write(lib._stm_tl_address(ptr))
+def stm_write(o):
+ lib.stm_write(o)
-def stm_was_read(ptr):
- return lib._stm_was_read(lib._stm_tl_address(ptr))
+def stm_was_read(o):
+ return lib._stm_was_read(o)
-def stm_was_written(ptr):
- return lib._stm_was_written(lib._stm_tl_address(ptr))
+def stm_was_written(o):
+ return lib._stm_was_written(o)
def stm_start_transaction():
lib.stm_start_transaction(ffi.cast("jmpbufptr_t*", -1))
diff --git a/c7/test/test_basic.py b/c7/test/test_basic.py
--- a/c7/test/test_basic.py
+++ b/c7/test/test_basic.py
@@ -7,20 +7,20 @@
pass
def test_thread_local_allocations(self):
- p1 = stm_allocate(16)
- p2 = stm_allocate(16)
+ lp1, p1 = stm_allocate(16)
+ lp2, p2 = stm_allocate(16)
assert is_in_nursery(p1)
assert is_in_nursery(p2)
assert p2 - p1 == 16
- p3 = stm_allocate(16)
+ lp3, p3 = stm_allocate(16)
assert p3 - p2 == 16
#
self.switch(1)
- p1s = stm_allocate(16)
+ lp1s, p1s = stm_allocate(16)
assert abs(p1s - p3) >= 4000
#
self.switch(0)
- p4 = stm_allocate(16)
+ lp4, p4 = stm_allocate(16)
assert p4 - p3 == 16
def test_transaction_start_stop(self):
@@ -33,26 +33,33 @@
def test_simple_read(self):
stm_start_transaction()
- p1 = stm_allocate(16)
- stm_read(p1)
- assert stm_was_read(p1)
+ lp1, _ = stm_allocate(16)
+ stm_read(lp1)
+ assert stm_was_read(lp1)
def test_simple_write(self):
stm_start_transaction()
- p1 = stm_allocate(16)
- assert stm_was_written(p1)
- stm_write(p1)
- assert stm_was_written(p1)
+ lp1, _ = stm_allocate(16)
+ assert stm_was_written(lp1)
+ stm_write(lp1)
+ assert stm_was_written(lp1)
+ def test_allocate_old(self):
+ lp1, _ = stm_allocate_old(16)
+ self.switch(1)
+ lp2, _ = stm_allocate_old(16)
+ assert lp1 != lp2
+
def test_write_on_old(self):
- p1 = stm_allocate_old(16)
- p1tl = stm_get_tl_address(p1)
+ lp1, p1 = stm_allocate_old(16)
+ stm_start_transaction()
+ stm_write(lp1)
+ p1[15] = 'a'
self.switch(1)
- p2 = stm_allocate_old(16)
- p2tl = stm_get_tl_address(p2)
- assert p1tl != p2tl
-
-
+ stm_start_transaction()
+ stm_read(lp1)
+ tp1 = stm_get_real_address(lp1)
+ assert tp1[15] == '\0'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit