Author: Remi Meier <[email protected]>
Branch: c7
Changeset: r621:bf2603b4cfbb
Date: 2014-01-17 12:12 +0100
http://bitbucket.org/pypy/stmgc/changeset/bf2603b4cfbb/
Log: adapt testing framework
diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -291,17 +291,12 @@
return object_pages + thread_num * (NB_PAGES * 4096UL);
}
-bool _is_young(object_t *o)
+bool _stm_is_young(object_t *o)
{
assert((uintptr_t)o >= FIRST_NURSERY_PAGE * 4096);
return (uintptr_t)o < FIRST_AFTER_NURSERY_PAGE * 4096;
}
-bool _stm_is_in_nursery(char *ptr)
-{
- object_t * o = _stm_tl_address(ptr);
- return _is_young(o);
-}
char *_stm_real_address(object_t *o)
{
@@ -495,7 +490,7 @@
{
if (*pobj == NULL)
return;
- if (!_is_young(*pobj))
+ if (!_stm_is_young(*pobj))
return;
/* the location the object moved to is at an 8b offset */
@@ -536,7 +531,7 @@
while (!stm_list_is_empty(old_objs)) {
object_t *item = stm_list_pop_item(old_objs);
- assert(!_is_young(item));
+ assert(!_stm_is_young(item));
assert(!(item->stm_flags & GCFLAG_WRITE_BARRIER));
/* re-add write-barrier */
@@ -567,6 +562,7 @@
object_t *stm_allocate(size_t size)
{
+ assert(_STM_TL2->running_transaction);
assert(size % 8 == 0);
size_t i = size / 8;
assert(2 <= i && i < LARGE_OBJECT_WORDS);//XXX
diff --git a/c7/core.h b/c7/core.h
--- a/c7/core.h
+++ b/c7/core.h
@@ -115,7 +115,7 @@
char *_stm_real_address(object_t *o);
object_t *_stm_tl_address(char *ptr);
-bool _stm_is_in_nursery(char *ptr);
+bool _stm_is_young(object_t *o);
object_t *_stm_allocate_old(size_t size);
void _stm_start_safe_point(void);
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -48,7 +48,7 @@
char *_stm_real_address(object_t *o);
object_t *_stm_tl_address(char *ptr);
-bool _stm_is_in_nursery(char *ptr);
+bool _stm_is_young(object_t *o);
object_t *_stm_allocate_old(size_t size);
void _stm_start_safe_point(void);
@@ -188,26 +188,26 @@
HDR = lib.SIZEOF_MYOBJ
-def is_in_nursery(ptr):
- return lib._stm_is_in_nursery(ptr)
+def is_in_nursery(o):
+ return lib._stm_is_young(o)
def stm_allocate_old(size):
o = lib._stm_allocate_old(size)
tid = 42 + size
lib._set_type_id(o, tid)
- return o, lib._stm_real_address(o)
+ return o
def stm_allocate(size):
o = lib.stm_allocate(size)
tid = 42 + size
lib._set_type_id(o, tid)
- return o, lib._stm_real_address(o)
+ return o
def stm_allocate_refs(n):
o = lib.stm_allocate(HDR + n * WORD)
tid = 42142 + n
lib._set_type_id(o, tid)
- return o, lib._stm_real_address(o)
+ return o
def stm_set_ref(obj, idx, ref):
stm_write(obj)
@@ -217,6 +217,14 @@
stm_read(obj)
return lib._get_ptr(obj, idx)
+def stm_set_char(obj, c):
+ stm_write(obj)
+ stm_get_real_address(obj)[HDR] = c
+
+def stm_get_char(obj):
+ stm_read(obj)
+ return stm_get_real_address(obj)[HDR]
+
def stm_get_real_address(obj):
return lib._stm_real_address(ffi.cast('object_t*', obj))
@@ -272,11 +280,12 @@
self.current_thread = 0
def teardown_method(self, meth):
- lib._stm_restore_local_state(1)
+ if self.current_thread != 1:
+ self.switch(1)
if lib._stm_is_in_transaction():
stm_stop_transaction()
- lib._stm_restore_local_state(0)
+ self.switch(0)
if lib._stm_is_in_transaction():
stm_stop_transaction()
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,21 +7,25 @@
pass
def test_thread_local_allocations(self):
- lp1, p1 = stm_allocate(16)
- lp2, p2 = stm_allocate(16)
- assert is_in_nursery(p1)
- assert is_in_nursery(p2)
- assert p2 - p1 == 16
- lp3, p3 = stm_allocate(16)
- assert p3 - p2 == 16
+ stm_start_transaction()
+ lp1 = stm_allocate(16)
+ lp2 = stm_allocate(16)
+ assert is_in_nursery(lp1)
+ assert is_in_nursery(lp2)
+ assert stm_get_real_address(lp2) - stm_get_real_address(lp1) == 16
+ lp3 = stm_allocate(16)
+ p3 = stm_get_real_address(lp3)
+ assert p3 - stm_get_real_address(lp2) == 16
#
self.switch(1)
- lp1s, p1s = stm_allocate(16)
- assert abs(p1s - p3) >= 4000
+ stm_start_transaction()
+ lp1s = stm_allocate(16)
+ assert is_in_nursery(lp1s)
+ assert abs(stm_get_real_address(lp1s) - p3) >= 4000
#
self.switch(0)
- lp4, p4 = stm_allocate(16)
- assert p4 - p3 == 16
+ lp4 = stm_allocate(16)
+ assert stm_get_real_address(lp4) - p3 == 16
def test_transaction_start_stop(self):
stm_start_transaction()
@@ -35,62 +39,57 @@
def test_simple_read(self):
stm_start_transaction()
- lp1, _ = stm_allocate(16)
+ lp1 = stm_allocate(16)
stm_read(lp1)
assert stm_was_read(lp1)
stm_stop_transaction()
def test_simple_write(self):
stm_start_transaction()
- lp1, _ = stm_allocate(16)
+ lp1 = stm_allocate(16)
assert stm_was_written(lp1)
stm_write(lp1)
assert stm_was_written(lp1)
stm_stop_transaction()
def test_allocate_old(self):
- lp1, _ = stm_allocate_old(16)
+ lp1 = stm_allocate_old(16)
self.switch(1)
- lp2, _ = stm_allocate_old(16)
+ lp2 = stm_allocate_old(16)
assert lp1 != lp2
def test_write_on_old(self):
- lp1, p1 = stm_allocate_old(16)
+ lp1 = stm_allocate_old(16)
stm_start_transaction()
stm_write(lp1)
assert stm_was_written(lp1)
- p1[15] = 'a'
+ stm_set_char(lp1, 'a')
self.switch(1)
stm_start_transaction()
stm_read(lp1)
assert stm_was_read(lp1)
- tp1 = stm_get_real_address(lp1)
- assert tp1[15] == '\0'
- stm_stop_transaction()
- self.switch(0)
-
+ assert stm_get_char(lp1) == '\0'
stm_stop_transaction()
+
def test_read_write_1(self):
- lp1, p1 = stm_allocate_old(16)
- p1[8] = 'a'
+ lp1 = stm_allocate_old(16)
+ stm_get_real_address(lp1)[HDR] = 'a' #setchar
stm_start_transaction()
stm_stop_transaction()
#
self.switch(1)
stm_start_transaction()
stm_write(lp1)
- p1 = stm_get_real_address(lp1)
- assert p1[8] == 'a'
- p1[8] = 'b'
+ assert stm_get_char(lp1) == 'a'
+ stm_set_char(lp1, 'b')
#
self.switch(0)
stm_start_transaction()
stm_read(lp1)
- p1 = stm_get_real_address(lp1)
- assert p1[8] == 'a'
+ assert stm_get_char(lp1) == 'a'
#
self.switch(1)
stm_stop_transaction(False)
@@ -99,8 +98,9 @@
def test_commit_fresh_objects(self):
stm_start_transaction()
- lp, p = stm_allocate(16)
- p[8] = 'u'
+ lp = stm_allocate(16)
+ stm_set_char(lp, 'u')
+ p = stm_get_real_address(lp)
stm_push_root(lp)
stm_stop_transaction()
lp = stm_pop_root()
@@ -114,18 +114,18 @@
p_ = stm_get_real_address(lp)
assert p != p_
assert p1 != p_
- assert p_[8] == 'u'
+ assert stm_get_char(lp) == 'u'
stm_stop_transaction()
def test_commit_fresh_objects2(self):
self.switch(1)
stm_start_transaction()
- lp, p = stm_allocate(16)
- p[8] = 'u'
- lp2, p2 = stm_allocate(16)
- p2[8] = 'v'
- assert p2 - p == 16
+ lp = stm_allocate(16)
+ stm_set_char(lp, 'u')
+ lp2 = stm_allocate(16)
+ stm_set_char(lp2, 'v')
+ assert stm_get_real_address(lp2) - stm_get_real_address(lp) == 16
stm_write(lp) # test not crash
stm_write(lp2) # test not crash
stm_read(lp) # test not crash
@@ -140,55 +140,52 @@
stm_start_transaction()
stm_write(lp) # privatize page
- p_ = stm_get_real_address(lp)
- assert p_[8] == 'u'
- p_[8] = 'x'
+ assert stm_get_char(lp) == 'u'
+ stm_set_char(lp, 'x')
stm_write(lp2)
- p2_ = stm_get_real_address(lp2)
- assert p2_[8] == 'v'
- p2_[8] = 'y'
+ assert stm_get_char(lp2) == 'v'
+ stm_set_char(lp2, 'y')
stm_stop_transaction()
self.switch(1)
stm_start_transaction()
stm_write(lp)
- p_ = stm_get_real_address(lp)
- assert p_[8] == 'x'
- stm_read(lp2)
- p2_ = stm_get_real_address(lp2)
- assert p2_[8] == 'y'
+ assert stm_get_char(lp) == 'x'
+ assert stm_get_char(lp2) == 'y'
stm_stop_transaction()
def test_simple_refs(self):
stm_start_transaction()
- lp, p = stm_allocate_refs(3)
- lq, q = stm_allocate(16)
- lr, r = stm_allocate(16)
- q[8] = 'x'
- r[8] = 'y'
+ lp = stm_allocate_refs(3)
+ lq = stm_allocate(16)
+ lr = stm_allocate(16)
+ stm_set_char(lq, 'x')
+ stm_set_char(lr, 'y')
stm_set_ref(lp, 0, lq)
stm_set_ref(lp, 1, lr)
stm_push_root(lp)
stm_stop_transaction()
lp = stm_pop_root()
+
self.switch(1)
+
stm_start_transaction()
stm_write(lp)
lq = stm_get_ref(lp, 0)
lr = stm_get_ref(lp, 1)
stm_read(lq)
stm_read(lr)
- assert stm_get_real_address(lq)[8] == 'x'
- assert stm_get_real_address(lr)[8] == 'y'
+ assert stm_get_char(lq) == 'x'
+ assert stm_get_char(lr) == 'y'
stm_stop_transaction()
def test_start_transaction_updates(self):
stm_start_transaction()
- lp1, p1 = stm_allocate(16)
- p1[8] = 'a'
+ lp1 = stm_allocate(16)
+ stm_set_char(lp1, 'a')
stm_push_root(lp1)
stm_stop_transaction()
lp1 = stm_pop_root()
@@ -196,44 +193,54 @@
self.switch(1)
stm_start_transaction()
stm_write(lp1)
- p1 = stm_get_real_address(lp1)
- assert p1[8] == 'a'
- p1[8] = 'b'
+ assert stm_get_char(lp1) == 'a'
+ stm_set_char(lp1, 'b')
stm_stop_transaction()
#
self.switch(0)
stm_start_transaction()
- p1 = stm_get_real_address(lp1)
- assert p1[8] == 'b'
+ assert stm_get_char(lp1) == 'b'
- # def test_resolve_no_conflict_empty(self):
- # stm_start_transaction()
- # #
- # self.switch(1)
- # stm_start_transaction()
- # stm_stop_transaction(False)
- # #
- # self.switch(0)
- # stm_stop_transaction(False)
+ def test_resolve_no_conflict_empty(self):
+ stm_start_transaction()
+ #
+ self.switch(1)
+ stm_start_transaction()
+ stm_stop_transaction(False)
+ #
+ self.switch(0)
+ stm_stop_transaction(False)
- # def test_resolve_no_conflict_write_only_in_already_committed(self):
- # stm_start_transaction()
- # p1 = stm_allocate(16)
- # p1[8] = 'a'
- # stm_stop_transaction(False)
- # stm_start_transaction()
- # #
- # self.switch(1)
- # stm_start_transaction()
- # stm_write(p1)
- # p1[8] = 'b'
- # stm_stop_transaction(False)
- # #
- # self.switch(0)
- # assert p1[8] == 'a'
- # stm_stop_transaction(False)
- # assert p1[8] == 'b'
+ def test_resolve_no_conflict_write_only_in_already_committed(self):
+ stm_start_transaction()
+ lp1 = stm_allocate(16)
+ p1 = stm_get_real_address(lp1)
+ p1[HDR] = 'a'
+ stm_push_root(lp1)
+ stm_stop_transaction(False)
+ lp1 = stm_pop_root()
+ # 'a' in SHARED_PAGE
+
+ stm_start_transaction()
+
+ self.switch(1)
+
+ stm_start_transaction()
+ stm_write(lp1) # privatize page
+ p1 = stm_get_real_address(lp1)
+ assert p1[HDR] == 'a'
+ p1[HDR] = 'b'
+ stm_stop_transaction(False)
+ # 'b' both private pages
+ #
+ self.switch(0)
+ #
+ assert p1[HDR] == 'b'
+ p1 = stm_get_real_address(lp1)
+ assert p1[HDR] == 'b'
+ stm_stop_transaction(False)
+ assert p1[HDR] == 'b'
# def test_resolve_write_read_conflict(self):
# stm_start_transaction()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit