Exemple #1
0
def test_env_change_set(monkeypatch, caplog):
    env = EnvChangeSet("bach", 1685)
    assert env.var == "bach"
    assert env.val == 1685
    with pytest.raises(FatalKrunError):
        env.apply({"bach": 1695})
    assert "Environment bach is already defined" in caplog.text
Exemple #2
0
def test_env_change_set(monkeypatch, caplog):
    env = EnvChangeSet("bach", 1685)
    assert env.var == "bach"
    assert env.val == 1685
    with pytest.raises(FatalKrunError):
        env.apply({"bach": 1695})
    assert "Environment bach is already defined" in caplog.text()
Exemple #3
0
def test_env_apply_all():
    env0 = EnvChangeSet("bach", 1685)
    env1 = EnvChangeSet("handel", 1685)
    env2 = EnvChangeSet("vivaldi", 1678)
    assert env0.var == "bach"
    assert env0.val == 1685
    dict0 = {}
    dict1 = {"handel":1685, "vivaldi":1678, "bach":1685}
    env0.apply_all((env0, env1, env2), dict0)
    assert dict0 == dict1
Exemple #4
0
def _run_shell_cmd_start_process(cmd, extra_env):
    debug("execute shell cmd: %s" % cmd)

    env = os.environ.copy()
    if extra_env:
        # Use EnvChangeSet so that we crash out if extra_env conflicts
        # with the current environment.
        from krun.env import EnvChangeSet
        for var, val in extra_env.iteritems():
            ec = EnvChangeSet(var, val)
            ec.apply(env)

    return Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, env=env)
Exemple #5
0
    def __init__(self,
                 truffleruby_dir=None,
                 graal_home=None,
                 mx_dir=None,
                 jvmci_home=None,
                 env=None):
        """
        Args:
            truffleruby_dir: path to a (built) truffleruby src dir
            graal_home: path to the built graal-core directory
            mx_dir: path to mx directory

        Note that this is for the open-source graal-core powered TruffleRuby,
        not for the proprietary graalvm binaries found on Oracle Technology
        Network.
        """

        jtrb_path = os.path.join(truffleruby_dir, 'tool', 'jt.rb')
        mx_bin_dir = os.path.join(mx_dir, "bin")

        RubyVMDef.__init__(self, jtrb_path, env=env)
        self.add_env_change(EnvChangeAppend("GRAAL_HOME", graal_home))
        self.add_env_change(EnvChangeAppend("PATH", mx_dir))
        self.extra_vm_args += ['run', '--graal']

        if jvmci_home is not None:
            self.add_env_change(EnvChangeSet("JAVA_HOME", jvmci_home))
Exemple #6
0
    def __init__(self, graal_dir, mx_path, java_home=None, env=None):
        JavaVMDef.__init__(self, mx_path, env=env)

        # This is for the JDK8 targetted version of graal.  Once JDK9 is
        # available it will include Graal and running the VM should be much
        # simpler. Hopefully just invoking 'java' with some flag.
        self.extra_vm_args += ['-p', graal_dir, 'vm', '-XX:+UseJVMCICompiler']

        if java_home is not None:
            self.add_env_change(EnvChangeSet("JAVA_HOME", java_home))
Exemple #7
0
def run_shell_cmd(cmd, failure_fatal=True, extra_env=None):
    debug("execute shell cmd: %s" % cmd)

    env = os.environ.copy()
    if extra_env:
        # Use EnvChangeSet so that we crash out if extra_env conflicts
        # with the current environment.
        from krun.env import EnvChangeSet
        for var, val in extra_env.iteritems():
            ec = EnvChangeSet(var, val)
            ec.apply(env)

    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, env=env)
    stdout, stderr = p.communicate()
    rc = p.wait()
    if failure_fatal and rc != 0:
        msg = "Command failed: '%s'\n" % cmd
        msg += "stdout:\n%s\n" % stdout
        msg += "stderr:\n%s\n" % stderr
        fatal(msg)
    return stdout.strip(), stderr.strip(), rc
Exemple #8
0
def run_shell_cmd(cmd, failure_fatal=True, extra_env=None):
    debug("execute shell cmd: %s" % cmd)

    env = os.environ.copy()
    if extra_env:
        # Use EnvChangeSet so that we crash out if extra_env conflicts
        # with the current environment.
        from krun.env import EnvChangeSet
        for var, val in extra_env.iteritems():
            ec = EnvChangeSet(var, val)
            ec.apply(env)

    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, env=env)
    stdout, stderr = p.communicate()
    rc = p.wait()
    if failure_fatal and rc != 0:
        msg = "Command failed: '%s'\n" % cmd
        msg += "stdout:\n%s\n" % stdout
        msg += "stderr:\n%s\n" % stderr
        fatal(msg)
    return stdout.strip(), stderr.strip(), rc
Exemple #9
0
def test_env_apply_all():
    env0 = EnvChangeSet("bach", 1685)
    env1 = EnvChangeSet("handel", 1685)
    env2 = EnvChangeSet("vivaldi", 1678)
    assert env0.var == "bach"
    assert env0.val == 1685
    dict0 = {}
    dict1 = {"handel": 1685, "vivaldi": 1678, "bach": 1685}
    env0.apply_all((env0, env1, env2), dict0)
    assert dict0 == dict1
Exemple #10
0
    def __init__(self, vm_path, env=None, instrument=False):
        """When instrument=True, record GC and compilation events"""

        if instrument:
            if env is None:
                env = {}
            # Causes PyPy to emit VM events on stderr
            EnvChangeSet("PYPYLOG", "gc:-").apply(env)

        PythonVMDef.__init__(self, vm_path, env=env, instrument=instrument)

        # XXX: On OpenBSD the PyPy build fails to encode the rpath to libpypy-c.so
        # into the VM executable, so we have to force it ourselves.
        #
        # For fairness, we apply the environment change to all platforms.
        #
        # Ideally fix in PyPy.
        # The user's environment (if any) comes first however
        lib_dir = os.path.dirname(vm_path)
        self.add_env_change(EnvChangeAppend("LD_LIBRARY_PATH", lib_dir))
Exemple #11
0
 def bench_env_changes(self):
     # Force malloc flags
     changes = UnixLikePlatform.bench_env_changes(self)
     changes.append(EnvChangeSet("MALLOC_OPTIONS", self.MALLOC_OPTS))
     return changes
Exemple #12
0
def test_env_change_set_apply():
    env = EnvChangeSet("bach", 1685)
    my_dict = {"handel": 1685}
    env.apply(my_dict)
    assert my_dict["bach"] == 1685
    assert my_dict["handel"] == 1685
Exemple #13
0
    def __init__(self, vm_path, java_home=None, env=None):
        JavaVMDef.__init__(self, vm_path, env=env)
        if java_home is not None:
            self.add_env_change(EnvChangeSet("JAVA_HOME", java_home))

        self.extra_vm_args.append("-jvmci")
Exemple #14
0
def test_env_change_set_apply():
    env = EnvChangeSet("bach", 1685)
    my_dict = {"handel": 1685}
    env.apply(my_dict)
    assert my_dict["bach"] == 1685
    assert my_dict["handel"] == 1685