Skip to content

Commit

Permalink
Auto merge of #42059 - derekdreery:bugfix/fix_emscripten_tests, r=ale…
Browse files Browse the repository at this point in the history
…xcrichton

Make compiletest set cwd before running js tests

Proposed fix for #38800.

Not all tests pass yet - I will mention failures here once the test suite has finished.
  • Loading branch information
bors committed Jul 26, 2017
2 parents 2fc3aec + 874ecdc commit d02fb3b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/ci/docker/disabled/wasm32/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ RUN sh /scripts/dumb-init.sh
# emscripten
COPY scripts/emscripten.sh /scripts/
RUN bash /scripts/emscripten.sh
COPY disabled/wasm32/node.sh /usr/local/bin/node

COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

ENV PATH=$PATH:/emsdk-portable
ENV PATH=$PATH:/emsdk-portable/clang/e1.37.13_64bit/
ENV PATH=$PATH:/emsdk-portable/emscripten/1.37.13/
ENV PATH=$PATH:/node-v8.0.0-linux-x64/bin/
ENV EMSCRIPTEN=/emsdk-portable/emscripten/1.37.13/
ENV BINARYEN_ROOT=/emsdk-portable/clang/e1.37.13_64bit/binaryen/
ENV EM_CONFIG=/emsdk-portable/.emscripten
Expand Down
18 changes: 0 additions & 18 deletions src/ci/docker/disabled/wasm32/node.sh

This file was deleted.

34 changes: 31 additions & 3 deletions src/tools/compiletest/src/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
// except according to those terms.

use std::env;
use std::ffi::OsString;
use std::io::prelude::*;
use std::io;
use std::path::PathBuf;
use std::process::{Child, Command, ExitStatus, Output, Stdio};

/// Get the name of the environment variable that holds dynamic library
/// locations
pub fn dylib_env_var() -> &'static str {
if cfg!(windows) {
"PATH"
Expand All @@ -26,11 +29,13 @@ pub fn dylib_env_var() -> &'static str {
}
}

/// Add `lib_path` and `aux_path` (if it is `Some`) to the dynamic library
/// env var
fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
// Need to be sure to put both the lib_path and the aux path in the dylib
// search path for the child.
let var = dylib_env_var();
let mut path = env::split_paths(&env::var_os(var).unwrap_or_default())
let mut path = env::split_paths(&env::var_os(var).unwrap_or(OsString::new()))
.collect::<Vec<_>>();
if let Some(p) = aux_path {
path.insert(0, PathBuf::from(p))
Expand All @@ -42,18 +47,33 @@ fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
cmd.env(var, newpath);
}

/// Represents exit status, stdout and stderr of a completed process
pub struct Result {
pub status: ExitStatus,
pub out: String,
pub err: String,
}

/// Runs a test program
///
/// # Params
/// - `lib_path` Path to search for required library
/// - `prog` command to run
/// - `aux_path` Optional extra path to search for required
/// auxiliary libraries
/// - `args` List of arguments to pass to `prog`
/// - `env` List of environment variables to set, `.0` is variable name,
/// `.1` is value
/// - `input` String to be fed as stdin
/// - `current_dir` Optional working dir to run command in
///
pub fn run(lib_path: &str,
prog: &str,
aux_path: Option<&str>,
args: &[String],
env: Vec<(String, String)>,
input: Option<String>)
input: Option<String>,
current_dir: Option<String>)
-> io::Result<Result> {

let mut cmd = Command::new(prog);
Expand All @@ -66,6 +86,9 @@ pub fn run(lib_path: &str,
for (key, val) in env {
cmd.env(&key, &val);
}
if let Some(cwd) = current_dir {
cmd.current_dir(cwd);
}

let mut process = cmd.spawn()?;
if let Some(input) = input {
Expand All @@ -80,12 +103,14 @@ pub fn run(lib_path: &str,
})
}

/// Same as `run`, but return process rather than waiting on completion
pub fn run_background(lib_path: &str,
prog: &str,
aux_path: Option<&str>,
args: &[String],
env: Vec<(String, String)>,
input: Option<String>)
input: Option<String>,
current_dir: Option<String>)
-> io::Result<Child> {

let mut cmd = Command::new(prog);
Expand All @@ -96,6 +121,9 @@ pub fn run_background(lib_path: &str,
for (key, val) in env {
cmd.env(&key, &val);
}
if let Some(cwd) = current_dir {
cmd.current_dir(cwd);
}

let mut process = cmd.spawn()?;
if let Some(input) = input {
Expand Down
34 changes: 26 additions & 8 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ impl<'test> TestCx<'test> {
self.props.exec_env.clone(),
self.config.compile_lib_path.to_str().unwrap(),
Some(aux_dir.to_str().unwrap()),
Some(src))
Some(src),
None)
}

fn make_pp_args(&self,
Expand Down Expand Up @@ -509,6 +510,7 @@ actual:\n\
self.config.adb_test_dir.clone()
],
Vec::new(),
None,
None)
.expect(&format!("failed to exec `{:?}`", self.config.adb_path));

Expand All @@ -521,6 +523,7 @@ actual:\n\
"tcp:5039".to_owned()
],
Vec::new(),
None,
None)
.expect(&format!("failed to exec `{:?}`", self.config.adb_path));

Expand All @@ -543,6 +546,7 @@ actual:\n\
adb_arg.clone()
],
Vec::new(),
None,
None)
.expect(&format!("failed to exec `{:?}`", self.config.adb_path));

Expand Down Expand Up @@ -579,6 +583,7 @@ actual:\n\
None,
&debugger_opts,
Vec::new(),
None,
None)
.expect(&format!("failed to exec `{:?}`", gdb_path));
let cmdline = {
Expand Down Expand Up @@ -686,6 +691,7 @@ actual:\n\
environment,
self.config.run_lib_path.to_str().unwrap(),
None,
None,
None);
}
}
Expand Down Expand Up @@ -1231,15 +1237,21 @@ actual:\n\
env,
self.config.run_lib_path.to_str().unwrap(),
Some(aux_dir.to_str().unwrap()),
None,
None)
}
_ => {
let aux_dir = self.aux_output_dir_name();
let working_dir =
Some(self.output_base_name()
.parent().unwrap()
.to_str().unwrap().to_owned());
self.compose_and_run(self.make_run_args(),
env,
self.config.run_lib_path.to_str().unwrap(),
Some(aux_dir.to_str().unwrap()),
None)
None,
working_dir)
}
}
}
Expand Down Expand Up @@ -1317,6 +1329,7 @@ actual:\n\
Vec::new(),
aux_cx.config.compile_lib_path.to_str().unwrap(),
Some(aux_dir.to_str().unwrap()),
None,
None);
if !auxres.status.success() {
self.fatal_proc_rec(
Expand All @@ -1330,16 +1343,18 @@ actual:\n\
self.props.rustc_env.clone(),
self.config.compile_lib_path.to_str().unwrap(),
Some(aux_dir.to_str().unwrap()),
input)
input,
None)
}

fn compose_and_run(&self,
ProcArgs{ args, prog }: ProcArgs,
procenv: Vec<(String, String)> ,
lib_path: &str,
aux_path: Option<&str>,
input: Option<String>) -> ProcRes {
self.program_output(lib_path, prog, aux_path, args, procenv, input)
input: Option<String>,
working_dir: Option<String>) -> ProcRes {
self.program_output(lib_path, prog, aux_path, args, procenv, input, working_dir)
}

fn make_compile_args(&self,
Expand Down Expand Up @@ -1532,7 +1547,8 @@ actual:\n\
aux_path: Option<&str>,
args: Vec<String>,
env: Vec<(String, String)>,
input: Option<String>)
input: Option<String>,
working_dir: Option<String>)
-> ProcRes {
let cmdline =
{
Expand All @@ -1542,6 +1558,7 @@ actual:\n\
logv(self.config, format!("executing {}", cmdline));
cmdline
};

let procsrv::Result {
out,
err,
Expand All @@ -1551,7 +1568,8 @@ actual:\n\
aux_path,
&args,
env,
input).expect(&format!("failed to exec `{}`", prog));
input,
working_dir).expect(&format!("failed to exec `{}`", prog));
self.dump_output(&out, &err);
ProcRes {
status: status,
Expand Down Expand Up @@ -1715,7 +1733,7 @@ actual:\n\
args: vec![format!("-input-file={}", irfile.to_str().unwrap()),
self.testpaths.file.to_str().unwrap().to_owned()]
};
self.compose_and_run(proc_args, Vec::new(), "", None, None)
self.compose_and_run(proc_args, Vec::new(), "", None, None, None)
}

fn run_codegen_test(&self) {
Expand Down

0 comments on commit d02fb3b

Please sign in to comment.