Author: Armin Rigo <ar...@tunes.org> Branch: hashtable Changeset: r1488:aefce8e8f935 Date: 2014-10-31 12:42 +0100 http://bitbucket.org/pypy/stmgc/changeset/aefce8e8f935/
Log: Tweak tweak diff --git a/c7/test/test_hashtable.py b/c7/test/test_hashtable.py --- a/c7/test/test_hashtable.py +++ b/c7/test/test_hashtable.py @@ -1,6 +1,6 @@ from support import * import random -import py +import py, sys def htget(o, key): @@ -19,9 +19,39 @@ class TestHashtable(BaseTest): + def setup_method(self, meth): + BaseTest.setup_method(self, meth) + # + @ffi.callback("void(object_t *)") + def light_finalizer(obj): + print 'light_finalizer:', obj + try: + assert lib._get_type_id(obj) == 421419 + self.seen_hashtables -= 1 + except: + self.errors.append(sys.exc_info()[2]) + raise + + lib.stmcb_light_finalizer = light_finalizer + self._light_finalizer_keepalive = light_finalizer + self.seen_hashtables = 0 + self.errors = [] + + def teardown_method(self, meth): + BaseTest.teardown_method(self, meth) + lib.stmcb_light_finalizer = ffi.NULL + assert self.errors == [] + assert self.seen_hashtables == 0 + + def allocate_hashtable(self): + h = stm_allocate_hashtable() + lib.stm_enable_light_finalizer(h) + self.seen_hashtables += 1 + return h + def test_empty(self): self.start_transaction() - h = stm_allocate_hashtable() + h = self.allocate_hashtable() for i in range(100): index = random.randrange(0, 1<<64) got = htget(h, index) @@ -29,7 +59,7 @@ def test_set_value(self): self.start_transaction() - h = stm_allocate_hashtable() + h = self.allocate_hashtable() lp1 = stm_allocate(16) htset(h, 12345678901, lp1) assert htget(h, 12345678901) == lp1 @@ -43,7 +73,7 @@ lp2 = stm_allocate_old(16) # self.start_transaction() - h = stm_allocate_hashtable() + h = self.allocate_hashtable() self.push_root(h) stm_set_char(lp1, 'A') htset(h, 1234, lp1) @@ -68,13 +98,16 @@ assert htget(h, 1234) == lp1 htset(h, 1234, ffi.NULL) self.commit_transaction() + # + self.start_transaction() + stm_major_collect() # to get rid of the hashtable object def test_conflict(self): lp1 = stm_allocate_old(16) lp2 = stm_allocate_old(16) # self.start_transaction() - h = stm_allocate_hashtable() + h = self.allocate_hashtable() self.push_root(h) self.commit_transaction() # @@ -86,10 +119,15 @@ self.switch(1) self.start_transaction() py.test.raises(Conflict, "htset(h, 1234, lp2)") + # + self.switch(0) + self.pop_root() + stm_major_collect() # to get rid of the hashtable object + self.commit_transaction() def test_keepalive_minor(self): self.start_transaction() - h = stm_allocate_hashtable() + h = self.allocate_hashtable() self.push_root(h) lp1 = stm_allocate(16) stm_set_char(lp1, 'N') @@ -105,7 +143,7 @@ lp1 = stm_allocate_old(16) # self.start_transaction() - h = stm_allocate_hashtable() + h = self.allocate_hashtable() self.push_root(h) stm_set_char(lp1, 'N') htset(h, 1234, lp1) @@ -114,7 +152,9 @@ self.start_transaction() stm_major_collect() h = self.pop_root() - self.push_root(h) lp1b = htget(h, 1234) assert lp1b == lp1 assert stm_get_char(lp1b) == 'N' + # + stm_major_collect() # to get rid of the hashtable object + self.commit_transaction() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit