Exemplo n.º 1
0
def main(input_file, opt_level, pgc):
    SAVEDCWD = os.getcwd()
    tests = []

    # Lifted from libregr.main
    regex = re.compile(r'\btest_[a-zA-Z0-9_]+\b')
    with open(os.path.join(SAVEDCWD, input_file)) as fp:
        for line in fp:
            line = line.split('#', 1)[0]
            line = line.strip()
            match = regex.search(line)
            if match is not None:
                tests.append(match.group())

    has_failures = False

    for test in tests:
        test_cases = unittest.defaultTestLoader.loadTestsFromName(f"test.{test}")
        print(f"Testing {test}")
        for case in test_cases:
            pyjion.enable()
            pyjion.enable_tracing()
            if pgc:
                pyjion.enable_pgc()
                print("Enabling PGC")
            else:
                pyjion.disable_pgc()
                print("Disabling PGC")
            print(f"Trying with Optimizations = {opt_level}")
            pyjion.set_optimization_level(opt_level)
            r = unittest.result.TestResult()
            case.run(r)
            if r.wasSuccessful():
                print(f"All tests in case successful.")
            else:
                print(f"Failures occurred.")
                has_failures = True

                for failedcase, reason in r.expectedFailures:
                    print(f"---------------------------------------------------------------")
                    print(f"Test case {failedcase} was expected to fail:")
                    print(reason)
                    print(f"---------------------------------------------------------------")

                for failedcase, reason in r.failures:
                    print(f"---------------------------------------------------------------")
                    print(f"Test case {failedcase} failed:")
                    print(reason)
                    print(f"---------------------------------------------------------------")

                for failedcase, reason in r.errors:
                    print(f"---------------------------------------------------------------")
                    print(f"Test case {failedcase} failed with errors:")
                    print(reason)
                    print(f"---------------------------------------------------------------")

            pyjion.disable()
            gc.collect()

    return has_failures
Exemplo n.º 2
0
def test_dis_native(capsys):
    def test_f():
        numbers = (1, 2, 3, 4)
        return sum(numbers)

    assert test_f() == 10
    pyjion.disable()
    dis_native(test_f)
    captured = capsys.readouterr()
    assert "PUSH RBP" in captured.out
Exemplo n.º 3
0
def test_dis_native_with_offsets(capsys):
    def test_f():
        numbers = (1, 2, 3, 4)
        return sum(numbers)

    assert test_f() == 10
    pyjion.disable()
    dis_native(test_f, True)
    captured = capsys.readouterr()

    assert "PUSH RBP" in captured.out
    assert "; 10 RETURN_VALUE - None (None)" in captured.out
    assert "; METHOD_" in captured.out
Exemplo n.º 4
0
def pytest_runtest_call(item: pytest.Item) -> None:
    pyjion.enable()
    pyjion.config(level=int(item.config.option.opt_level))
    for mark in item.iter_markers():
        if mark.name == "graph":
            pyjion.config(graph=True)
    pyjion.config(debug=True)
    item.runtest()
    pyjion.disable()
    info = pyjion.info(item.function)
    if not info.compiled:
        warnings.warn("{0} did not compile ({1})".format(
            item.function, str(info.compile_result)))
    pyjion.config(graph=False)
    gc.collect()
Exemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser(prog='pyjion',
                                     description='Python JIT Compiler')

    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('script', help='script file', nargs='?')

    group.add_argument('-m',
                       action='store',
                       type=str,
                       dest="module",
                       help="Execute module")

    parser.add_argument('--graph',
                        action='store_true',
                        help='Enable instruction graph generation')

    parser.add_argument('--debug',
                        action='store_true',
                        help='Enable debuggable JIT methods')

    parser.add_argument('--no-pgc', action='store_true', help='Disable PGC')

    parser.add_argument('-o',
                        '--opt-level',
                        action='store',
                        type=int,
                        default=1,
                        help='Optimization level (default 1')

    args = parser.parse_args()

    pyjion.enable()

    pyjion.config(graph=args.graph,
                  debug=args.debug,
                  pgc=not args.no_pgc,
                  level=args.opt_level)

    if args.module:
        runpy.run_module(args.module)
    else:
        runpy.run_path(args.script)
    pyjion.disable()
Exemplo n.º 6
0
                perm[:k + 1] = perm[k::-1]
                flips_count += 1
                assert len(
                    perm
                ) > 0, f"Invalid size after reverse slice assignment for {k}"
                k = perm[0]

            if flips_count > max_flips:
                max_flips = flips_count

        while r != n:
            perm1_ins(r, perm1_pop(0))
            count[r] -= 1
            if count[r] > 0:
                break
            r += 1
        else:
            return max_flips


if __name__ == "__main__":
    print("Fannkuch({1}) took {0} without Pyjion".format(
        timeit.repeat(fannkuch, repeat=5, number=1), DEFAULT_ARG))
    try:
        pyjion.enable()
        print("Fannkuch({1}) took {0} with Pyjion".format(
            timeit.repeat(fannkuch, repeat=5, number=1), DEFAULT_ARG))
        pyjion.disable()
    except:
        pyjion.dis.dis(fannkuch)
Exemplo n.º 7
0
 def tearDown(self) -> None:
     pyjion.disable()
     gc.collect()
Exemplo n.º 8
0
 def _set_pyjion(pyjion_state: bool):
     if pyjion_state:
         pyjion.enable()
         pyjion.config(pgc=False)
     else:
         pyjion.disable()
Exemplo n.º 9
0
 def tearDown(self) -> None:
     pyjion.disable()
Exemplo n.º 10
0
def pytest_pyfunc_call(pyfuncitem):
    yield
    # Force pyjion to be disabled, useful when a test raises an exception
    # so it stops every consequent Python call to be JITted and making it
    # impossible to figure out what went wrong.
    pyjion.disable()