diff options
Diffstat (limited to 'rpython/jit/metainterp/test')
-rw-r--r-- | rpython/jit/metainterp/test/strategies.py | 13 | ||||
-rw-r--r-- | rpython/jit/metainterp/test/test_ajit.py | 25 | ||||
-rw-r--r-- | rpython/jit/metainterp/test/test_jitdriver.py | 17 | ||||
-rw-r--r-- | rpython/jit/metainterp/test/test_resume.py | 91 | ||||
-rw-r--r-- | rpython/jit/metainterp/test/test_resumecode.py | 17 | ||||
-rw-r--r-- | rpython/jit/metainterp/test/test_tlc.py | 1 |
6 files changed, 132 insertions, 32 deletions
diff --git a/rpython/jit/metainterp/test/strategies.py b/rpython/jit/metainterp/test/strategies.py new file mode 100644 index 0000000000..e7cd79ec20 --- /dev/null +++ b/rpython/jit/metainterp/test/strategies.py @@ -0,0 +1,13 @@ + +import sys +from hypothesis import strategies +from rpython.jit.metainterp.resoperation import InputArgInt +from rpython.jit.metainterp.history import ConstInt + +machine_ints = strategies.integers(min_value=-sys.maxint - 1, + max_value=sys.maxint) +intboxes = strategies.builds(InputArgInt) +intconsts = strategies.builds(ConstInt, machine_ints) +boxes = intboxes | intconsts +boxlists = strategies.lists(boxes, min_size=1).flatmap( + lambda cis: strategies.lists(strategies.sampled_from(cis)))
\ No newline at end of file diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py index fc4a231aca..ecf82bcbf6 100644 --- a/rpython/jit/metainterp/test/test_ajit.py +++ b/rpython/jit/metainterp/test/test_ajit.py @@ -1199,6 +1199,31 @@ class BasicTests: (-sys.maxint-1) // (-6) + 100 * 8) + def test_overflow_fold_if_divisor_constant(self): + import sys + from rpython.rtyper.lltypesystem.lloperation import llop + myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res']) + def f(x, y): + res = 0 + while y > 0: + myjitdriver.can_enter_jit(x=x, y=y, res=res) + myjitdriver.jit_merge_point(x=x, y=y, res=res) + try: + res += llop.int_floordiv_ovf(lltype.Signed, + x, 2) + res += llop.int_mod_ovf(lltype.Signed, + x, 2) + x += 5 + except OverflowError: + res += 100 + y -= 1 + return res + res = self.meta_interp(f, [-41, 8]) + # the guard_true are for the loop condition + # the guard_false needed to check whether an overflow can occur have + # been folded away + self.check_resops(guard_true=2, guard_false=0) + def test_isinstance(self): class A: pass diff --git a/rpython/jit/metainterp/test/test_jitdriver.py b/rpython/jit/metainterp/test/test_jitdriver.py index 56f26ffd85..cba873a956 100644 --- a/rpython/jit/metainterp/test/test_jitdriver.py +++ b/rpython/jit/metainterp/test/test_jitdriver.py @@ -213,6 +213,21 @@ class MultipleJitDriversTests(object): if op.getopname() == 'enter_portal_frame': assert op.getarg(0).getint() == 0 assert op.getarg(1).getint() == 1 - + + def test_manual_leave_enter_portal_frame(self): + from rpython.rlib import jit + driver = JitDriver(greens=[], reds='auto', is_recursive=True) + + def f(arg): + i = 0 + while i < 100: + driver.jit_merge_point() + jit.enter_portal_frame(42) + jit.leave_portal_frame() + i += 1 + + self.meta_interp(f, [0]) + self.check_simple_loop(enter_portal_frame=1, leave_portal_frame=1) + class TestLLtype(MultipleJitDriversTests, LLJitMixin): pass diff --git a/rpython/jit/metainterp/test/test_resume.py b/rpython/jit/metainterp/test/test_resume.py index ebbd602860..dd2a9f501d 100644 --- a/rpython/jit/metainterp/test/test_resume.py +++ b/rpython/jit/metainterp/test/test_resume.py @@ -10,7 +10,7 @@ from rpython.jit.metainterp.resume import ResumeDataVirtualAdder,\ VArrayInfoNotClear, VStrPlainInfo, VStrConcatInfo, VStrSliceInfo,\ VUniPlainInfo, VUniConcatInfo, VUniSliceInfo, Snapshot, FrameInfo,\ capture_resumedata, ResumeDataLoopMemo, UNASSIGNEDVIRTUAL, INT,\ - annlowlevel, PENDINGFIELDSP, unpack_uint, TAG_CONST_OFFSET + annlowlevel, PENDINGFIELDSP, unpack_uint, TAG_CONST_OFFSET, TopSnapshot from rpython.jit.metainterp.resumecode import unpack_numbering,\ create_numbering, NULL_NUMBER @@ -22,8 +22,12 @@ from rpython.jit.metainterp import executor from rpython.jit.codewriter import heaptracker, longlong from rpython.jit.metainterp.resoperation import ResOperation, InputArgInt,\ InputArgRef, rop +from rpython.jit.metainterp.test.strategies import boxlists from rpython.rlib.debug import debug_start, debug_stop, debug_print,\ have_debug_prints +from rpython.jit.metainterp import resumecode + +from hypothesis import given class Storage: rd_frame_info_list = None @@ -278,9 +282,7 @@ def _next_section(reader, *expected): assert bh.written_f == expected_f -def Numbering(nums): - numb = create_numbering(nums, 0) - return numb +Numbering = create_numbering def tagconst(i): return tag(i + TAG_CONST_OFFSET, TAGCONST) @@ -610,7 +612,8 @@ def test_capture_resumedata(): assert unpack_uint(frame_info_list.packed_jitcode_pc) == (2, 15) snapshot = storage.rd_snapshot - assert snapshot.boxes == vrs + vbs # in the same list + assert snapshot.boxes == vrs + assert snapshot.vable_boxes == [b2, b1] snapshot = snapshot.prev assert snapshot.prev is fs[2].parent_resumedata_snapshot @@ -904,9 +907,9 @@ def test_ResumeDataLoopMemo_number(): env = [b1, c1, b2, b1, c2] snap = Snapshot(None, env) env1 = [c3, b3, b1, c1] - snap1 = Snapshot(snap, env1) + snap1 = TopSnapshot(snap, env1, []) env2 = [c3, b3, b1, c3] - snap2 = Snapshot(snap, env2) + snap2 = TopSnapshot(snap, env2, []) memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) frameinfo = FrameInfo(None, FakeJitCode("jitcode", 0), 0) @@ -916,10 +919,11 @@ def test_ResumeDataLoopMemo_number(): assert liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX), b3: tag(2, TAGBOX)} - base = [tag(0, TAGBOX), tag(1, TAGINT), tag(1, TAGBOX), tag(0, TAGBOX), tag(2, TAGINT)] + base = [0, 0, tag(0, TAGBOX), tag(1, TAGINT), + tag(1, TAGBOX), tag(0, TAGBOX), tag(2, TAGINT)] - assert unpack_numbering(numb) == [ - tag(3, TAGINT), tag(2, TAGBOX), tag(0, TAGBOX), tag(1, TAGINT), 0, 0] + base + assert unpack_numbering(numb) == [0, 2, tag(3, TAGINT), tag(2, TAGBOX), + tag(0, TAGBOX), tag(1, TAGINT)] + base numb2, liveboxes2, v = memo.number(FakeOptimizer(), snap2, frameinfo) assert v == 0 @@ -927,11 +931,11 @@ def test_ResumeDataLoopMemo_number(): assert liveboxes2 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX), b3: tag(2, TAGBOX)} assert liveboxes2 is not liveboxes - assert unpack_numbering(numb2) == [ - tag(3, TAGINT), tag(2, TAGBOX), tag(0, TAGBOX), tag(3, TAGINT), 0, 0] + base + assert unpack_numbering(numb2) == [0, 2, tag(3, TAGINT), tag(2, TAGBOX), + tag(0, TAGBOX), tag(3, TAGINT)] + base env3 = [c3, b3, b1, c3] - snap3 = Snapshot(snap, env3) + snap3 = TopSnapshot(snap, env3, []) class FakeVirtualInfo(info.AbstractInfo): def __init__(self, virt): @@ -946,13 +950,12 @@ def test_ResumeDataLoopMemo_number(): assert v == 0 assert liveboxes3 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX)} - assert unpack_numbering(numb3) == [tag(3, TAGINT), tag(4, TAGINT), - tag(0, TAGBOX), - tag(3, TAGINT), 0, 0] + base + assert unpack_numbering(numb3) == [0, 2, tag(3, TAGINT), tag(4, TAGINT), + tag(0, TAGBOX), tag(3, TAGINT)] + base # virtual env4 = [c3, b4, b1, c3] - snap4 = Snapshot(snap, env4) + snap4 = TopSnapshot(snap, env4, []) b4.set_forwarded(FakeVirtualInfo(True)) numb4, liveboxes4, v = memo.number(FakeOptimizer(), snap4, frameinfo) @@ -960,11 +963,11 @@ def test_ResumeDataLoopMemo_number(): assert liveboxes4 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX), b4: tag(0, TAGVIRTUAL)} - assert unpack_numbering(numb4) == [tag(3, TAGINT), tag(0, TAGVIRTUAL), - tag(0, TAGBOX), tag(3, TAGINT), 0, 0] + base + assert unpack_numbering(numb4) == [0, 2, tag(3, TAGINT), tag(0, TAGVIRTUAL), + tag(0, TAGBOX), tag(3, TAGINT)] + base env5 = [b1, b4, b5] - snap5 = Snapshot(snap4, env5) + snap5 = TopSnapshot(snap4, [], env5) b4.set_forwarded(FakeVirtualInfo(True)) b5.set_forwarded(FakeVirtualInfo(True)) @@ -974,9 +977,30 @@ def test_ResumeDataLoopMemo_number(): assert liveboxes5 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX), b4: tag(0, TAGVIRTUAL), b5: tag(1, TAGVIRTUAL)} - assert unpack_numbering(numb5) == [tag(0, TAGBOX), tag(0, TAGVIRTUAL), - tag(1, TAGVIRTUAL), 2, 1] + unpack_numbering(numb4) - + assert unpack_numbering(numb5) == [ + 3, tag(0, TAGBOX), tag(0, TAGVIRTUAL), tag(1, TAGVIRTUAL), + 0, + 2, 1, tag(3, TAGINT), tag(0, TAGVIRTUAL), tag(0, TAGBOX), tag(3, TAGINT) + ] + base + +@given(boxlists) +def test_ResumeDataLoopMemo_random(lst): + s = TopSnapshot(None, [], lst) + frameinfo = FrameInfo(None, FakeJitCode("foo", 0), 0) + memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) + num, liveboxes, v = memo.number(FakeOptimizer(), s, frameinfo) + l = unpack_numbering(num) + assert l[-1] == 0 + assert l[0] == len(lst) + for i, item in enumerate(lst): + v, tag = untag(l[i + 1]) + if tag == TAGBOX: + assert l[i + 1] == liveboxes[item] + elif tag == TAGCONST: + assert memo.consts[v].getint() == item.getint() + elif tag == TAGINT: + assert v == item.getint() + def test_ResumeDataLoopMemo_number_boxes(): memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) b1, b2 = [InputArgInt(), InputArgInt()] @@ -1060,10 +1084,11 @@ def make_storage(b1, b2, b3): storage = Storage() snapshot = Snapshot(None, [b1, ConstInt(1), b1, b2]) snapshot = Snapshot(snapshot, [ConstInt(2), ConstInt(3)]) - snapshot = Snapshot(snapshot, [b1, b2, b3]) - frameinfo = FrameInfo(FrameInfo(None, FakeJitCode("code1", 21), 22), - FakeJitCode("code2", 31), 32) - storage.rd_snapshot = snapshot + snapshot = Snapshot(snapshot, [b1, b2, b3]) + top_snapshot = TopSnapshot(snapshot, [], []) + frameinfo = FrameInfo(FrameInfo(FrameInfo(None, FakeJitCode("code1", 21), 22), + FakeJitCode("code2", 31), 32), FakeJitCode("code3", 41), 42) + storage.rd_snapshot = top_snapshot storage.rd_frame_info_list = frameinfo return storage @@ -1076,6 +1101,8 @@ def test_virtual_adder_int_constants(): assert storage.rd_snapshot is None cpu = MyCPU([]) reader = ResumeDataDirectReader(MyMetaInterp(cpu), storage, "deadframe") + reader.consume_vref_and_vable(None, None, None) + reader.cur_index += 2 # framestack _next_section(reader, sys.maxint, 2**16, -65) reader.cur_index += 2 # framestack _next_section(reader, 2, 3) @@ -1116,7 +1143,8 @@ class ResumeDataFakeReader(ResumeDataBoxReader): class MyInfo: @staticmethod def enumerate_vars(callback_i, callback_r, callback_f, _, index): - for tagged in self.numb.code: + while index < len(self.numb.code): + tagged, _ = resumecode.numb_next_item(self.numb, index) _, tag = untag(tagged) if tag == TAGVIRTUAL: kind = REF @@ -1131,6 +1159,13 @@ class ResumeDataFakeReader(ResumeDataBoxReader): index = callback_f(index, index) else: assert 0 + size, self.cur_index = resumecode.numb_next_item(self.numb, 0) + assert size == 0 + size, self.cur_index = resumecode.numb_next_item(self.numb, self.cur_index) + assert size == 0 + pc, self.cur_index = resumecode.numb_next_item(self.numb, self.cur_index) + jitcode_pos, self.cur_index = resumecode.numb_next_item(self.numb, self.cur_index) + self._prepare_next_section(MyInfo()) return self.lst diff --git a/rpython/jit/metainterp/test/test_resumecode.py b/rpython/jit/metainterp/test/test_resumecode.py index 848a4f1009..f65fae7d07 100644 --- a/rpython/jit/metainterp/test/test_resumecode.py +++ b/rpython/jit/metainterp/test/test_resumecode.py @@ -1,9 +1,12 @@ from rpython.jit.metainterp.resumecode import NUMBERING, NULL_NUMBER from rpython.jit.metainterp.resumecode import create_numbering,\ - unpack_numbering, copy_from_list_to_numb + unpack_numbering from rpython.rtyper.lltypesystem import lltype +from hypothesis import strategies, given + + def test_pack_unpack(): examples = [ [1, 2, 3, 4, 257, 10000, 13, 15], @@ -12,5 +15,15 @@ def test_pack_unpack(): [13000, 12000, 10000, 256, 255, 254, 257, -3, -1000] ] for l in examples: - n = create_numbering(l, 0) + n = create_numbering(l) assert unpack_numbering(n) == l + +@given(strategies.lists(strategies.integers(-2**15, 2**15-1))) +def test_roundtrip(l): + n = create_numbering(l) + assert unpack_numbering(n) == l + +@given(strategies.lists(strategies.integers(-2**15, 2**15-1))) +def test_compressing(l): + n = create_numbering(l) + assert len(n.code) <= len(l) * 3 diff --git a/rpython/jit/metainterp/test/test_tlc.py b/rpython/jit/metainterp/test/test_tlc.py index ee88035bf2..5c1396d533 100644 --- a/rpython/jit/metainterp/test/test_tlc.py +++ b/rpython/jit/metainterp/test/test_tlc.py @@ -1,5 +1,4 @@ import py -from rpython.rtyper.module.support import LLSupport from rpython.jit.tl import tlc |