Ejemplo n.º 1
0
    def test_jitarg_works(self, cool_mod):
        # cannot actually check jit hint.
        argv = ['arg0'] + self.ok_jit_args + [cool_mod]
        config, names, args, retval = parse_args(argv)
        assert retval == RETURN_OK

        argv = ['arg0', cool_mod] + self.ok_jit_args
        config, names, args, retval = parse_args(argv)
        assert retval == RETURN_OK
Ejemplo n.º 2
0
    def test_verbose(self):
        config, names, args, retval = parse_args(['arg0', '--verbose'])
        assert config['verbose']
        assert names['verbosity_level'] == ['-1']

        config, names, args, retval = parse_args(['arg0', '--verbose', '2'])
        assert config['verbose']
        assert names['verbosity_level'] == ['2']
        assert retval == RETURN_OK
Ejemplo n.º 3
0
    def test_verbose(self):
        config, names, args, retval = parse_args(['arg0', '--verbose'])
        assert config['verbose']
        assert names['verbosity_level'] == ['-1']

        config, names, args, retval = parse_args(['arg0', '--verbose', '2'])
        assert config['verbose']
        assert names['verbosity_level'] == ['2']
        assert retval == RETURN_OK
Ejemplo n.º 4
0
    def test_jitarg_works(self, cool_mod):
        # cannot actually check jit hint.
        argv = ['arg0'] + self.ok_jit_args + [cool_mod]
        config, names, args, retval = parse_args(argv)
        assert retval == RETURN_OK

        argv = ['arg0', cool_mod] + self.ok_jit_args
        config, names, args, retval = parse_args(argv)
        assert retval == RETURN_OK
Ejemplo n.º 5
0
    def test_jitarg_works(self, empty_json):
        # cannot actually check jit hint.
        argv = ['arg0'] + self.ok_jit_args + [empty_json]
        config, names, args, retval = parse_args(argv)
        assert retval == 0

        argv = ['arg0', empty_json] + self.ok_jit_args
        config, names, args, retval = parse_args(argv)
        assert retval == 0
Ejemplo n.º 6
0
    def test_verbose_keywords(self):
        config, names, args, retval = parse_args(['arg0', '--verbose', 'regexp'])
        assert config['verbose']
        assert names['verbosity_level'] == ['-1']
        assert names['verbosity_keywords'] == ['regexp']

        config, names, args, retval = parse_args(['arg0', '--verbose', 'regexp', '--verbose', 'prims'])
        assert config['verbose']
        assert names['verbosity_level'] == ['-1']
        assert names['verbosity_keywords'] == ['regexp', 'prims']

        config, names, args, retval = parse_args(['arg0', '--verbose', 'regexp', '--verbose', '5', '--verbose', 'prims'])
        assert config['verbose']
        assert names['verbosity_level'] == ['5']
        assert names['verbosity_keywords'] == ['regexp', 'prims']
Ejemplo n.º 7
0
 def test_program_arguments_plain(self, cool_mod):
     program_args = ["foo", "bar", "baz"]
     argv = ['arg0', cool_mod] + program_args
     config, names, args, retval = parse_args(argv)
     # must use "--"
     assert retval == MISSING_ARG
     assert args == []
Ejemplo n.º 8
0
 def test_l(self, cool_mod):
     argv = ['arg0', "-l", cool_mod]
     config, names, args, retval = parse_args(argv)
     assert retval == RETURN_OK
     assert config['no-lib']
     assert 'loads' in names
     assert 'lib' in names['loads'] and cool_mod in names['load_arguments']
Ejemplo n.º 9
0
 def test_f(self, cool_mod):
     argv = ['arg0', "-f", cool_mod]
     config, names, args, retval = parse_args(argv)
     assert retval == RETURN_OK
     assert config == init_config
     assert 'loads' in names
     assert 'load' in names['loads'] and cool_mod in names['load_arguments']
Ejemplo n.º 10
0
    def test_program_arguments_explicit_with_switch(self, cool_mod):
        program_args = ["--jit", "foo", "bar", "baz"]
        argv = ['arg0', cool_mod] + ["--"] + program_args
        config, names, args, retval = parse_args(argv)

        assert retval == RETURN_OK
        assert args == program_args
Ejemplo n.º 11
0
 def test_m(self):
     f_name = 'multiple-modules.json'
     argv1 = ['arg0', "-c", f_name]
     config1, names1, args1, retval1 = parse_args(argv1)
     assert retval1 == 0
     assert names1['multiple-modules'] == f_name
     assert args1 == []
Ejemplo n.º 12
0
 def test_program_arguments_after_jit(self, cool_mod):
     program_args = ["foo", "bar", "baz"]
     argv = ['arg0', cool_mod] + self.ok_jit_args + program_args
     config, names, args, retval = parse_args(argv)
     # again, must use "--"
     assert retval == MISSING_ARG
     assert args == []
Ejemplo n.º 13
0
 def test_l(self, cool_mod):
     argv = ['arg0', "-l", cool_mod]
     config, names, args, retval = parse_args(argv)
     assert retval == RETURN_OK
     assert config['no-lib']
     assert 'loads' in names
     assert 'lib' in names['loads'] and cool_mod in names['load_arguments']
Ejemplo n.º 14
0
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)

        entry_flag = 'byte-expand' in names
        reader = JsonLoader(bytecode_expand=entry_flag)
        if json_ast is None:
            ast = reader.expand_to_ast(module_name)
        else:
            ast = reader.load_json_ast_rpython(module_name, json_ast)

        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown
            if config.get('save-callgraph', False):
                with open('callgraph.dot', 'w') as outfile:
                    env.callgraph.write_dot_file(outfile)
            shutdown(env)
        return 0
Ejemplo n.º 15
0
 def test_b(self):
     f_name = 'dummy.rkt'
     argv1 = ['arg0', "-b", f_name]
     config1, names1, args1, retval1 = parse_args(argv1)
     assert retval1 == 0
     assert names1['byte-expand'] == f_name
     assert args1 == []
Ejemplo n.º 16
0
 def test_b(self):
     f_name = 'dummy.rkt'
     argv1 = ['arg0', "-b", f_name]
     config1, names1, args1, retval1 = parse_args(argv1)
     assert retval1 == 0
     assert names1['byte-expand'] == f_name
     assert args1 == []
Ejemplo n.º 17
0
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)
        modtable = ModTable()
        if json_ast is None:
            ast = expand_to_ast(module_name, modtable)
        else:
            ast = load_json_ast_rpython(json_ast, modtable)
        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown
            shutdown(env)
        return 0
Ejemplo n.º 18
0
 def test_program_arguments_after_jit(self, cool_mod):
     program_args = ["foo", "bar", "baz"]
     argv = ['arg0', cool_mod] + self.ok_jit_args + program_args
     config, names, args, retval = parse_args(argv)
     # again, must use "--"
     assert retval == MISSING_ARG
     assert args == []
Ejemplo n.º 19
0
 def test_program_arguments_plain(self, cool_mod):
     program_args = ["foo", "bar", "baz"]
     argv = ['arg0', cool_mod] + program_args
     config, names, args, retval = parse_args(argv)
     # must use "--"
     assert retval == MISSING_ARG
     assert args == []
Ejemplo n.º 20
0
    def test_program_arguments_explicit_with_switch(self, empty_json):
        program_args = ["--jit", "foo", "bar", "baz"]
        argv = ['arg0', empty_json] + ["--"] + program_args
        config, names, args, retval = parse_args(argv)

        assert retval == 0
        assert args == program_args
Ejemplo n.º 21
0
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)
        jit.set_param(None, "max_unroll_loops", 10)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)

        entry_flag = 'byte-expand' in names
        reader = JsonLoader(bytecode_expand=entry_flag)
        if json_ast is None:
            ast = reader.expand_to_ast(module_name)
        else:
            ast = reader.load_json_ast_rpython(module_name, json_ast)

        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown
            for callback in POST_RUN_CALLBACKS:
                callback(config, env)
            shutdown(env)
        return 0
Ejemplo n.º 22
0
    def test_program_arguments_after_jit(self, empty_json):
        program_args = ["foo", "bar", "baz"]
        argv = ['arg0', empty_json] + self.ok_jit_args + program_args
        config, names, args, retval = parse_args(argv)

        assert retval == 0
        assert args == program_args
Ejemplo n.º 23
0
    def test_program_arguments_explicit(self, cool_mod):
        program_args = ["foo", "bar", "baz"]
        argv = ['arg0', cool_mod] + ["--"] + program_args
        config, names, args, retval = parse_args(argv)

        assert retval == RETURN_OK
        assert args == program_args
Ejemplo n.º 24
0
 def test_f(self, cool_mod):
     argv = ['arg0', "-f", cool_mod]
     config, names, args, retval = parse_args(argv)
     assert retval == RETURN_OK
     assert config == init_config
     assert 'loads' in names
     assert 'load' in names['loads'] and cool_mod in names['load_arguments']
Ejemplo n.º 25
0
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)
        jit.set_param(None, "max_unroll_loops", 15)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)

        entry_flag = 'byte-expand' in names
        reader = JsonLoader(bytecode_expand=entry_flag)
        if json_ast is None:
            ast = reader.expand_to_ast(module_name)
        else:
            ast = reader.load_json_ast_rpython(module_name, json_ast)

        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown
            for callback in POST_RUN_CALLBACKS:
                callback(config, env)
            shutdown(env)
        return 0
Ejemplo n.º 26
0
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)

        if NonConstant(False):
            # Hack to give os.open() the correct annotation
            os.open("foo", 1, 1)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)

        modtable = ModTable()
        modtable.enter_module(module_name)
        if json_ast is None:
            ast = expand_to_ast(module_name, modtable)
        else:
            ast = load_json_ast_rpython(json_ast, modtable)
        modtable.exit_module(module_name, ast)

        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown

            shutdown(env)
        return 0
Ejemplo n.º 27
0
 def test_p(self, empty_json):
     argv = ['arg0', "-p", empty_json]
     config, names, args, retval = parse_args(argv)
     assert retval == 0
     assert names['file'] == empty_json + ".p"
     assert config['mode'] == option_helper._eval
     assert names['exprs'] == '(require (planet "%s"))' % empty_json
     assert args == []
Ejemplo n.º 28
0
 def test_e(self):
     code = "(ratatta)"
     argv = ['arg0', "-e", code]
     config, names, args, retval = parse_args(argv)
     assert config == init_config
     assert retval == RETURN_OK
     assert 'loads' in names
     assert 'eval' in names['loads'] and code in names['load_arguments']
Ejemplo n.º 29
0
 def test_eval(self):
     code = "(ratatta)"
     argv = ['arg0', "-e", code]
     config, names, args, retval = parse_args(argv)
     assert retval == 0
     assert 'file' not in names
     assert config['mode'] == option_helper._eval
     assert names['exprs'] == code
Ejemplo n.º 30
0
 def test_e(self):
     code = "(ratatta)"
     argv = ['arg0', "-e", code]
     config, names, args, retval = parse_args(argv)
     assert config == init_config
     assert retval == RETURN_OK
     assert 'loads' in names
     assert 'eval' in names['loads'] and code in names['load_arguments']
Ejemplo n.º 31
0
 def test_f(self, empty_json):
     pytest.skip("re-enable when -f works again")
     argv = ['arg0', "-f", empty_json]
     config, names, args, retval = parse_args(argv)
     assert retval == 0
     assert names['file'] == empty_json+".f"
     assert config['mode'] == option_helper._eval
     assert names['exprs'] == '(load "%s")' % empty_json
     assert args == []
Ejemplo n.º 32
0
    def test_verbose_keywords(self):
        config, names, args, retval = parse_args(
            ['arg0', '--verbose', 'regexp'])
        assert config['verbose']
        assert names['verbosity_level'] == ['-1']
        assert names['verbosity_keywords'] == ['regexp']

        config, names, args, retval = parse_args(
            ['arg0', '--verbose', 'regexp', '--verbose', 'prims'])
        assert config['verbose']
        assert names['verbosity_level'] == ['-1']
        assert names['verbosity_keywords'] == ['regexp', 'prims']

        config, names, args, retval = parse_args([
            'arg0', '--verbose', 'regexp', '--verbose', '5', '--verbose',
            'prims'
        ])
        assert config['verbose']
        assert names['verbosity_level'] == ['5']
        assert names['verbosity_keywords'] == ['regexp', 'prims']
Ejemplo n.º 33
0
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)
        jit.set_param(None, "max_unroll_loops", 15)

        from pycket.env import w_global_config
        w_global_config.set_pycketconfig(pycketconfig)

        config, names, args, retval = parse_args(argv)

        if config['verbose']:
            level = int(names['verbosity_level'][0])
            w_global_config.set_config_val('verbose', level)

            if 'verbosity_keywords' in names:
                w_global_config.set_verbose_keywords(
                    names['verbosity_keywords'])

            if 'not-implemented' in names:
                print("These flags are not implemented yet : %s" %
                      names['not-implemented'])

        if retval == MISSING_ARG:
            print("Bad switch, or missing argument in : %s" % argv[1:])
            return 1

        if retval == JUST_EXIT or config is None:
            return RETURN_OK  # exit normally

        if 'stdout_level' in names:  # -O
            from pycket.prims.logging import w_main_logger
            w_main_logger.set_stdout_level(names['stdout_level'][0])

        if 'stderr_level' in names:  # -W
            from pycket.prims.logging import w_main_logger
            w_main_logger.set_stderr_level(names['stderr_level'][0])

        if 'syslog_level' in names:  # -L
            from pycket.prims.logging import w_main_logger
            w_main_logger.set_syslog_level(names['syslog_level'][0])

        current_cmd_args = [W_String.fromstr_utf8(arg) for arg in args]

        if 'json-linklets' in names:
            for linkl_json in names['json-linklets']:
                vvv = config['verbose']
                load_inst_linklet(linkl_json, debug=vvv)

        try:
            if not config['stop']:
                racket_entry(names, config, current_cmd_args)
        except ExitException, e:
            pass
Ejemplo n.º 34
0
def actual_entry(argv):
    jit.set_param(None, "trace_limit", 20000)

    config, names, args, retval = parse_args(argv)
    if retval != 0 or config is None:
        return retval
    args_w = [W_String(arg) for arg in args]
    module_name, json_ast = ensure_json_ast(config, names)
    if json_ast is None:
        ast = expand_to_ast(module_name) 
    else:
        ast = load_json_ast_rpython(json_ast)
    GlobalConfig.load(ast)
    env = ToplevelEnv()
    env.commandline_arguments = args_w
    env.module_env.add_module(module_name, ast)
    val = interpret_module(ast, env)
    return 0
Ejemplo n.º 35
0
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)
        modtable = ModTable()
        if json_ast is None:
            ast = expand_to_ast(module_name, modtable)
        else:
            ast = load_json_ast_rpython(json_ast, modtable)
        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown
            shutdown(env)
        return 0
Ejemplo n.º 36
0
    def actual_entry(argv):
        jit.set_param(None, "trace_limit", 1000000)
        jit.set_param(None, "threshold", 131)
        jit.set_param(None, "trace_eagerness", 50)

        if NonConstant(False):
            # Hack to give os.open() the correct annotation
            os.open('foo', 1, 1)

        config, names, args, retval = parse_args(argv)
        if retval != 0 or config is None:
            return retval
        args_w = [W_String.fromstr_utf8(arg) for arg in args]
        module_name, json_ast = ensure_json_ast(config, names)

        modtable = ModTable()
        modtable.enter_module(module_name)
        if json_ast is None:
            ast = expand_to_ast(module_name, modtable)
        else:
            ast = load_json_ast_rpython(json_ast, modtable)
        modtable.exit_module(module_name, ast)

        env = ToplevelEnv(pycketconfig)
        env.globalconfig.load(ast)
        env.commandline_arguments = args_w
        env.module_env.add_module(module_name, ast)
        try:
            val = interpret_module(ast, env)
        finally:
            from pycket.prims.input_output import shutdown
            if config.get('save-callgraph', False):
                with open('callgraph.dot', 'w') as outfile:
                    env.callgraph.write_dot_file(outfile)
            shutdown(env)
        return 0
Ejemplo n.º 37
0
 def test_no_args(self):
     config, names, args, retval = parse_args(['arg0'])
     assert retval == RETURN_OK
     assert config == init_config
     assert names == {}
Ejemplo n.º 38
0
 def test_jitarg_fail(self, cool_mod):
     with pytest.raises(ValueError):
         parse_args(['arg0', '--jit', cool_mod])
     argv = ['arg0', "cool-module.rkt", '--jit']
     config, names, args, retval = parse_args(argv)
     assert retval == RET_JIT
Ejemplo n.º 39
0
 def test_one_args(self, cool_mod):
     config, names, args, retval = parse_args(['arg0', "cool-module.rkt"])
     assert retval == RETURN_OK
     assert 'loads' in names
     assert "file" in names['loads']
     assert "cool-module.rkt" in names['load_arguments']
Ejemplo n.º 40
0
    def test_help(self, arg):
        argv = ["arg0", arg]
        assert (None, None, None, 0 == parse_args(argv))

        argv = ["arg0", "foobar", arg]
        assert (None, None, None, 0 == parse_args(argv))
Ejemplo n.º 41
0
 def test_one_args(self, cool_mod):
     config, names, args, retval = parse_args(['arg0', "cool-module.rkt"])
     assert retval == RETURN_OK
     assert 'loads' in names
     assert "file" in names['loads']
     assert "cool-module.rkt" in names['load_arguments']
Ejemplo n.º 42
0
 def test_jitarg_fail(self, empty_json):
     with pytest.raises(ValueError):
         parse_args(['arg0', '--jit', empty_json])
     argv = ['arg0', empty_json, '--jit']
     config, names, args, retval = parse_args(argv)
     assert retval == 2
Ejemplo n.º 43
0
 def test_one_args(self, empty_json):
     # Ok, this is grey-box-y
     config, names, args, retval = parse_args(['arg0', empty_json])
     assert retval == 0
     assert names['file'] == empty_json
     assert config['mode'] == option_helper._run
Ejemplo n.º 44
0
 def test_no_args(self):
     config, names, args, retval = parse_args(['arg0'])
     assert retval == 3
Ejemplo n.º 45
0
 def test_jitarg_fail(self, cool_mod):
     with pytest.raises(ValueError):
         parse_args(['arg0', '--jit', cool_mod])
     argv = ['arg0', "cool-module.rkt", '--jit']
     config, names, args, retval = parse_args(argv)
     assert retval == RET_JIT
Ejemplo n.º 46
0
 def test_u(self, empty_json):
     argv1 = ['arg0', "-t", empty_json, "--", "foo", "bar", "baz"]
     argv2 = ['arg0', "-u", empty_json, "foo", "bar", "baz"]
     assert parse_args(argv1) == parse_args(argv2)
Ejemplo n.º 47
0
 def test_r(self, empty_json):
     pytest.skip("re-enable when -f works again")
     argv1 = ['arg0', "-f", empty_json, "--", "foo", "bar", "baz"]
     argv2 = ['arg0', "-r", empty_json, "foo", "bar", "baz"]
     assert parse_args(argv1) == parse_args(argv2)