Commits

Armin Rigo committed a94a05e

Kill test files too.

Comments (0)

Files changed (4)

pypy/translator/stm/test/test_gcsource.py

-from pypy.translator.translator import TranslationContext
-from pypy.translator.stm.gcsource import GcSource
-from pypy.objspace.flow.model import SpaceOperation, Constant
-from pypy.rpython.lltypesystem import lltype
-from pypy.rlib.jit import hint
-
-
-class X:
-    def __init__(self, n):
-        self.n = n
-
-
-def gcsource(func, sig):
-    t = TranslationContext()
-    t.buildannotator().build_types(func, sig)
-    t.buildrtyper().specialize()
-    gsrc = GcSource(t)
-    return gsrc
-
-def test_simple():
-    def main(n):
-        return X(n)
-    gsrc = gcsource(main, [int])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert len(s) == 1
-    [op] = list(s)
-    assert isinstance(op, SpaceOperation)
-    assert op.opname == 'malloc'
-
-def test_two_sources():
-    foo = X(42)
-    def main(n):
-        if n > 5:
-            return X(n)
-        else:
-            return foo
-    gsrc = gcsource(main, [int])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert len(s) == 2
-    [s1, s2] = list(s)
-    if isinstance(s1, SpaceOperation):
-        s1, s2 = s2, s1
-    assert isinstance(s1, Constant)
-    assert s1.value.inst_n == 42
-    assert isinstance(s2, SpaceOperation)
-    assert s2.opname == 'malloc'
-
-def test_call():
-    def f1(n):
-        return X(n)
-    def main(n):
-        return f1(n)
-    gsrc = gcsource(main, [int])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert len(s) == 1
-    assert list(s)[0].opname == 'malloc'
-
-def test_indirect_call():
-    foo = X(42)
-    def f1(n):
-        return X(n)
-    def f2(n):
-        return foo
-    lst = [f1, f2]
-    def main(n):
-        return lst[n % 2](n)
-    gsrc = gcsource(main, [int])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert len(s) == 2
-    [s1, s2] = list(s)
-    if isinstance(s1, SpaceOperation):
-        s1, s2 = s2, s1
-    assert isinstance(s1, Constant)
-    assert s1.value.inst_n == 42
-    assert isinstance(s2, SpaceOperation)
-    assert s2.opname == 'malloc'
-
-def test_argument():
-    def f1(x):
-        return x
-    def main(n):
-        return f1(X(5))
-    gsrc = gcsource(main, [int])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert len(s) == 1
-    assert list(s)[0].opname == 'malloc'
-
-def test_argument_twice():
-    foo = X(42)
-    def f1(x):
-        return x
-    def main(n):
-        f1(foo)
-        return f1(X(5))
-    gsrc = gcsource(main, [int])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert len(s) == 2
-    [s1, s2] = list(s)
-    if isinstance(s1, SpaceOperation):
-        s1, s2 = s2, s1
-    assert isinstance(s1, Constant)
-    assert s1.value.inst_n == 42
-    assert isinstance(s2, SpaceOperation)
-    assert s2.opname == 'malloc'
-
-def test_unknown_source():
-    def main(x):
-        return x
-    gsrc = gcsource(main, [lltype.Ptr(lltype.GcStruct('S'))])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert list(s) == []
-
-def test_exception():
-    class FooError(Exception):
-        pass
-    def f(n):
-        raise FooError
-    def main(n):
-        try:
-            f(n)
-        except FooError, e:
-            return e
-    gsrc = gcsource(main, [int])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert list(s) == ['last_exc_value']
-
-def test_hint_xyz():
-    def main(n):
-        return hint(X(n), xyz=True)
-    gsrc = gcsource(main, [int])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert len(s) == 1
-    assert list(s)[0].opname == 'malloc'
-
-def test_hint_stm_write():
-    def main(n):
-        return hint(X(n), stm_write=True)
-    gsrc = gcsource(main, [int])
-    v_result = gsrc.translator.graphs[0].getreturnvar()
-    s = gsrc[v_result]
-    assert len(s) == 1
-    assert list(s)[0].opname == 'hint'

pypy/translator/stm/test/test_llstminterp.py

-import py
-py.test.skip("llstminterp disabled")
-from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.test.test_llinterp import get_interpreter
-from pypy.translator.stm.llstminterp import eval_stm_graph
-from pypy.translator.stm.llstminterp import ForbiddenInstructionInSTMMode
-from pypy.translator.stm.llstminterp import ReturnWithTransactionActive
-from pypy.translator.stm import llstm
-
-ALL_STM_MODES = ["not_in_transaction",
-                 "regular_transaction",
-                 "inevitable_transaction"]
-
-def test_simple():
-    def func(n):
-        return (n+1) * (n+2)
-    interp, graph = get_interpreter(func, [5])
-    res = eval_stm_graph(interp, graph, [5],
-                         stm_mode="not_in_transaction",
-                         final_stm_mode="not_in_transaction")
-    assert res == 42
-
-def test_forbidden():
-    S = lltype.GcStruct('S', ('x', lltype.Signed))
-    p = lltype.malloc(S, immortal=True)
-    p.x = 42
-    #
-    def funcget(p):
-        return p.x
-    interp, graph = get_interpreter(funcget, [p])
-    py.test.raises(ForbiddenInstructionInSTMMode,
-                   eval_stm_graph, interp, graph, [p],
-                   stm_mode="regular_transaction")
-    #
-    def funcset(p):
-        p.x = 43
-    interp, graph = get_interpreter(funcset, [p])
-    py.test.raises(ForbiddenInstructionInSTMMode,
-                   eval_stm_graph, interp, graph, [p],
-                   stm_mode="regular_transaction")
-
-def test_stm_getfield_stm_setfield():
-    S = lltype.GcStruct('S', ('x', lltype.Signed), ('y', lltype.Signed))
-    p = lltype.malloc(S, immortal=True)
-    p.x = 42
-    def func(p):
-        llstm.stm_setfield(p, 'y', 43)
-        return llstm.stm_getfield(p, 'x')
-    interp, graph = get_interpreter(func, [p])
-    # works in all modes
-    for mode in ALL_STM_MODES:
-        p.y = 0
-        res = eval_stm_graph(interp, graph, [p], stm_mode=mode)
-        assert res == 42
-        assert p.y == 43
-
-def test_stm_getarrayitem_stm_setarrayitem():
-    A = lltype.GcArray(lltype.Signed)
-    p = lltype.malloc(A, 5, immortal=True)
-    p[3] = 42
-    def func(p):
-        llstm.stm_setarrayitem(p, 2, 43)
-        return llstm.stm_getarrayitem(p, 3)
-    interp, graph = get_interpreter(func, [p])
-    # works in all modes
-    for mode in ALL_STM_MODES:
-        p[2] = 0
-        res = eval_stm_graph(interp, graph, [p], stm_mode=mode)
-        assert res == 42
-        assert p[2] == 43
-
-def test_getfield_immutable():
-    S = lltype.GcStruct('S', ('x', lltype.Signed), hints = {'immutable': True})
-    p = lltype.malloc(S, immortal=True)
-    p.x = 42
-    def func(p):
-        return p.x
-    interp, graph = get_interpreter(func, [p])
-    # a plain 'getfield' of an immutable field works in all modes
-    for mode in ALL_STM_MODES:
-        res = eval_stm_graph(interp, graph, [p], stm_mode=mode)
-        assert res == 42
-
-def test_become_inevitable():
-    def func():
-        llstm.stm_become_inevitable("foobar!")
-    interp, graph = get_interpreter(func, [])
-    py.test.raises(ForbiddenInstructionInSTMMode,
-                   eval_stm_graph, interp, graph, [],
-                   stm_mode="not_in_transaction")
-    eval_stm_graph(interp, graph, [], stm_mode="regular_transaction",
-                   final_stm_mode="inevitable_transaction")
-    eval_stm_graph(interp, graph, [], stm_mode="inevitable_transaction")

pypy/translator/stm/test/test_localtracker.py

-from pypy.translator.stm.localtracker import StmLocalTracker
-from pypy.translator.translator import TranslationContext, graphof
-from pypy.conftest import option
-from pypy.rlib.jit import hint
-from pypy.rlib.nonconst import NonConstant
-from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.extregistry import ExtRegistryEntry
-from pypy.annotation import model as annmodel
-
-
-class TestStmLocalTracker(object):
-
-    def translate(self, func, sig):
-        t = TranslationContext()
-        self.translator = t
-        t._seen_locals = {}
-        t.buildannotator().build_types(func, sig)
-        t.buildrtyper().specialize()
-        if option.view:
-            t.view()
-        localtracker = StmLocalTracker(t)
-        self.localtracker = localtracker
-        return localtracker
-
-    def check(self, expected_names):
-        got_local_names = set()
-        for name, v in self.translator._seen_locals.items():
-            if self.localtracker.try_ensure_local(v):
-                got_local_names.add(name)
-                self.localtracker.assert_local(v, 'foo')
-        assert got_local_names == set(expected_names)
-
-
-    def test_no_local(self):
-        x = X(42)
-        def g(x):
-            return x.n
-        def f(n):
-            return g(x)
-        #
-        localtracker = self.translate(f, [int])
-        self.check([])
-
-    def test_freshly_allocated(self):
-        z = [lltype.malloc(S), lltype.malloc(S)]
-        def f(n):
-            x = lltype.malloc(S)
-            x.n = n
-            y = lltype.malloc(S)
-            y.n = n+1
-            _see(x, 'x')
-            _see(y, 'y')
-            _see(z[n % 2], 'z')
-            return x.n, y.n
-        #
-        self.translate(f, [int])
-        self.check(['x', 'y'])      # x and y are locals; z is prebuilt
-
-    def test_freshly_allocated_in_one_path(self):
-        z = lltype.malloc(S)
-        def f(n):
-            x = lltype.malloc(S)
-            x.n = n
-            if n > 5:
-                y = lltype.malloc(S)
-                y.n = n+1
-            else:
-                y = z
-            _see(x, 'x')
-            _see(y, 'y')
-            return x.n + y.n
-        #
-        self.translate(f, [int])
-        self.check(['x'])      # x is local; y not, as it can be equal to z
-
-    def test_freshly_allocated_in_the_other_path(self):
-        z = lltype.malloc(S)
-        def f(n):
-            x = lltype.malloc(S)
-            x.n = n
-            if n > 5:
-                y = z
-            else:
-                y = lltype.malloc(S)
-                y.n = n+1
-            _see(x, 'x')
-            _see(y, 'y')
-            return x.n + y.n
-        #
-        self.translate(f, [int])
-        self.check(['x'])      # x is local; y not, as it can be equal to z
-
-    def test_freshly_allocated_in_loop(self):
-        z = lltype.malloc(S)
-        def f(n):
-            while True:
-                x = lltype.malloc(S)
-                x.n = n
-                n -= 1
-                if n < 0:
-                    break
-            _see(x, 'x')
-            return x.n
-        #
-        self.translate(f, [int])
-        self.check(['x'])      # x is local
-
-    def test_none_variable_is_local(self):
-        def f(n):
-            if n > 5:
-                x = lltype.nullptr(S)
-            else:
-                x = lltype.malloc(S)
-                x.n = n
-            _see(x, 'x')
-        #
-        localtracker = self.translate(f, [int])
-        self.check(['x'])
-
-    def test_freshly_allocated_to_g(self):
-        def g(x):
-            _see(x, 'x')
-            return x[0]
-        def f(n):
-            g([n])
-            g([n+1])
-            g([n+2])
-        #
-        self.translate(f, [int])
-        self.check(['x'])           # x is a local in all possible calls to g()
-
-    def test_not_always_freshly_allocated_to_g(self):
-        z = [42]
-        def g(x):
-            _see(x, 'x')
-            return x[0]
-        def f(n):
-            y = [n]
-            g(y)
-            g(z)
-            _see(y, 'y')
-        #
-        self.translate(f, [int])
-        self.check(['y'])    # x is not a local in one possible call to g()
-                             # but y is still a local
-
-    def test_constructor_allocates_freshly(self):
-        def f(n):
-            x = X(n)
-            _see(x, 'x')
-        #
-        self.translate(f, [int])
-        self.check(['x'])
-
-    def test_fresh_in_init(self):
-        class Foo:
-            def __init__(self, n):
-                self.n = n
-                _see(self, 'foo')
-        def f(n):
-            return Foo(n)
-        #
-        self.translate(f, [int])
-        self.check(['foo'])
-
-    def test_returns_fresh_object(self):
-        def g(n):
-            return X(n)
-        def f(n):
-            x = g(n)
-            _see(x, 'x')
-        #
-        self.translate(f, [int])
-        self.check(['x'])
-
-    def test_indirect_call_returns_fresh_object(self):
-        def g(n):
-            return X(n)
-        def h(n):
-            return Y(n)
-        lst = [g, h]
-        def f(n):
-            x = lst[n % 2](n)
-            _see(x, 'x')
-        #
-        self.translate(f, [int])
-        self.check(['x'])
-
-    def test_indirect_call_may_return_nonfresh_object(self):
-        z = X(42)
-        def g(n):
-            return X(n)
-        def h(n):
-            return z
-        lst = [g, h]
-        def f(n):
-            x = lst[n % 2](n)
-            _see(x, 'x')
-        #
-        self.translate(f, [int])
-        self.check([])
-
-    def test_instantiate_returns_fresh_object(self):
-        def f(n):
-            if n > 5:
-                cls = X
-            else:
-                cls = Y
-            _see(cls(n), 'x')
-        #
-        self.translate(f, [int])
-        self.check(['x'])
-
-    def test_hint_stm_write(self):
-        z = X(42)
-        def f(n):
-            x = hint(z, stm_write=True)
-            _see(x, 'x')
-        #
-        self.translate(f, [int])
-        self.check(['x'])
-
-
-S = lltype.GcStruct('S', ('n', lltype.Signed))
-
-class X:
-    def __init__(self, n):
-        self.n = n
-
-class Y(X):
-    pass
-
-
-def _see(var, name):
-    pass
-
-class Entry(ExtRegistryEntry):
-    _about_ = _see
-
-    def compute_result_annotation(self, s_var, s_name):
-        return annmodel.s_None
-
-    def specialize_call(self, hop):
-        v = hop.inputarg(hop.args_r[0], arg=0)
-        name = hop.args_s[1].const
-        assert name not in hop.rtyper.annotator.translator._seen_locals, (
-            "duplicate name %r" % (name,))
-        hop.rtyper.annotator.translator._seen_locals[name] = v
-        hop.exception_cannot_occur()
-        return hop.inputconst(lltype.Void, None)

pypy/translator/stm/test/test_transform.py

-from pypy.translator.stm.transform import STMTransformer
-from pypy.translator.stm.transform import pre_insert_stm_writebarrier
-from pypy.translator.translator import TranslationContext, graphof
-from pypy.conftest import option
-from pypy.objspace.flow.model import summary
-
-
-def get_graph(func, sig):
-    t = TranslationContext()
-    t.buildannotator().build_types(func, sig)
-    t.buildrtyper().specialize()
-    if option.view:
-        t.view()
-    return graphof(t, func)
-
-
-def test_pre_insert_stm_writebarrier():
-    class X:
-        pass
-    class Y(X):
-        pass
-    class Z(X):
-        pass
-    def f1(n):
-        if n > 5:
-            x = Z()
-        else:
-            x = Y()
-        x.n = n
-        if n > 5:
-            assert isinstance(x, Z)
-            x.n = n + 2
-            x.sub = n + 1
-        x.n *= 2
-        if n < 10:
-            return x.n
-        else:
-            return 0
-    #
-    graph = get_graph(f1, [int])
-    pre_insert_stm_writebarrier(graph)
-    if option.view:
-        graph.show()
-    # weak test: check that there are exactly 3 stm_writebarrier inserted.
-    # one should be for 'x.n = n', one should cover both field assignments
-    # to the Z instance, and the 3rd one is in the block 'x.n *= 2'.
-    # (the latter two should be killed by the later phases.)
-    sum = summary(graph)
-    assert sum['stm_writebarrier'] == 3
-
-
-def test_all_the_rest_in_transform():
-    import py
-    py.test.skip("XXX! tests missing!")