Author: Armin Rigo <ar...@tunes.org> Branch: stm Changeset: r51341:91a0ee8fc4ab Date: 2012-01-16 11:53 +0100 http://bitbucket.org/pypy/pypy/changeset/91a0ee8fc4ab/
Log: Add a (skipped) test about using the minimark GC. diff --git a/pypy/translator/stm/test/targetdemo.py b/pypy/translator/stm/test/targetdemo.py --- a/pypy/translator/stm/test/targetdemo.py +++ b/pypy/translator/stm/test/targetdemo.py @@ -3,29 +3,35 @@ from pypy.translator.stm import rstm -NUM_THREADS = 4 -LENGTH = 5000 - - class Node: def __init__(self, value): self.value = value self.next = None +class Global: + NUM_THREADS = 4 + LENGTH = 5000 + USE_MEMORY = False + anchor = Node(-1) +glob = Global() + def add_at_end_of_chained_list(node, value): + x = Node(value) while node.next: node = node.next - newnode = Node(value) + if glob.USE_MEMORY: + x = Node(value) + newnode = x node.next = newnode def check_chained_list(node): - seen = [0] * (LENGTH+1) - seen[-1] = NUM_THREADS + seen = [0] * (glob.LENGTH+1) + seen[-1] = glob.NUM_THREADS while node is not None: value = node.value #print value - if not (0 <= value < LENGTH): + if not (0 <= value < glob.LENGTH): print "node.value out of bounds:", value raise AssertionError seen[value] += 1 @@ -34,19 +40,15 @@ value, seen[value]) raise AssertionError node = node.next - if seen[LENGTH-1] != NUM_THREADS: + if seen[glob.LENGTH-1] != glob.NUM_THREADS: print "seen[LENGTH-1] != NUM_THREADS" raise AssertionError print "check ok!" -class Global: - anchor = Node(-1) -glob = Global() - def run_me(): print "thread starting..." - for i in range(LENGTH): + for i in range(glob.LENGTH): add_at_end_of_chained_list(glob.anchor, i) rstm.transaction_boundary() print "thread done." @@ -57,11 +59,17 @@ def entry_point(argv): print "hello world" + if len(argv) > 1: + glob.NUM_THREADS = int(argv[1]) + if len(argv) > 2: + glob.LENGTH = int(argv[2]) + if len(argv) > 3: + glob.USE_MEMORY = bool(int(argv[3])) glob.done = 0 - for i in range(NUM_THREADS): + for i in range(glob.NUM_THREADS): ll_thread.start_new_thread(run_me, ()) print "sleeping..." - while glob.done < NUM_THREADS: # poor man's lock + while glob.done < glob.NUM_THREADS: # poor man's lock time.sleep(1) print "done sleeping." check_chained_list(glob.anchor.next) diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py --- a/pypy/translator/stm/test/test_transform.py +++ b/pypy/translator/stm/test/test_transform.py @@ -183,12 +183,13 @@ # ____________________________________________________________ class CompiledSTMTests(StandaloneTests): + gc = "none" def compile(self, entry_point): from pypy.config.pypyoption import get_pypy_config self.config = get_pypy_config(translating=True) self.config.translation.stm = True - self.config.translation.gc = "none" + self.config.translation.gc = self.gc # # Prevent the RaiseAnalyzer from just emitting "WARNING: Unknown # operation". We want instead it to crash. diff --git a/pypy/translator/stm/test/test_ztranslated.py b/pypy/translator/stm/test/test_ztranslated.py --- a/pypy/translator/stm/test/test_ztranslated.py +++ b/pypy/translator/stm/test/test_ztranslated.py @@ -1,3 +1,4 @@ +import py from pypy.translator.stm.test.test_transform import CompiledSTMTests from pypy.translator.stm.test import targetdemo @@ -6,6 +7,18 @@ def test_hello_world(self): t, cbuilder = self.compile(targetdemo.entry_point) - data = cbuilder.cmdexec('') + data = cbuilder.cmdexec('4 5000') assert 'done sleeping.' in data assert 'check ok!' in data + + +class TestSTMFramework(CompiledSTMTests): + gc = "minimark" + + def test_hello_world(self): + py.test.skip("in-progress") + t, cbuilder = self.compile(targetdemo.entry_point) + data = cbuilder.cmdexec('4 5000 1') + # ^^^ should check that it doesn't take 1G of RAM + assert 'done sleeping.' in data + assert 'check ok!' in data _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit