Skip to content

Commit d02fb3b

Browse files
committedJul 26, 2017
Auto merge of rust-lang#42059 - derekdreery:bugfix/fix_emscripten_tests, r=alexcrichton
Make compiletest set cwd before running js tests Proposed fix for rust-lang#38800. Not all tests pass yet - I will mention failures here once the test suite has finished.
2 parents 2fc3aec + 874ecdc commit d02fb3b

File tree

4 files changed

+58
-30
lines changed

4 files changed

+58
-30
lines changed
 

‎src/ci/docker/disabled/wasm32/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ RUN sh /scripts/dumb-init.sh
1919
# emscripten
2020
COPY scripts/emscripten.sh /scripts/
2121
RUN bash /scripts/emscripten.sh
22-
COPY disabled/wasm32/node.sh /usr/local/bin/node
2322

2423
COPY scripts/sccache.sh /scripts/
2524
RUN sh /scripts/sccache.sh
2625

2726
ENV PATH=$PATH:/emsdk-portable
2827
ENV PATH=$PATH:/emsdk-portable/clang/e1.37.13_64bit/
2928
ENV PATH=$PATH:/emsdk-portable/emscripten/1.37.13/
29+
ENV PATH=$PATH:/node-v8.0.0-linux-x64/bin/
3030
ENV EMSCRIPTEN=/emsdk-portable/emscripten/1.37.13/
3131
ENV BINARYEN_ROOT=/emsdk-portable/clang/e1.37.13_64bit/binaryen/
3232
ENV EM_CONFIG=/emsdk-portable/.emscripten

‎src/ci/docker/disabled/wasm32/node.sh

-18
This file was deleted.

‎src/tools/compiletest/src/procsrv.rs

+31-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
// except according to those terms.
1010

1111
use std::env;
12+
use std::ffi::OsString;
1213
use std::io::prelude::*;
1314
use std::io;
1415
use std::path::PathBuf;
1516
use std::process::{Child, Command, ExitStatus, Output, Stdio};
1617

18+
/// Get the name of the environment variable that holds dynamic library
19+
/// locations
1720
pub fn dylib_env_var() -> &'static str {
1821
if cfg!(windows) {
1922
"PATH"
@@ -26,11 +29,13 @@ pub fn dylib_env_var() -> &'static str {
2629
}
2730
}
2831

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

50+
/// Represents exit status, stdout and stderr of a completed process
4551
pub struct Result {
4652
pub status: ExitStatus,
4753
pub out: String,
4854
pub err: String,
4955
}
5056

57+
/// Runs a test program
58+
///
59+
/// # Params
60+
/// - `lib_path` Path to search for required library
61+
/// - `prog` command to run
62+
/// - `aux_path` Optional extra path to search for required
63+
/// auxiliary libraries
64+
/// - `args` List of arguments to pass to `prog`
65+
/// - `env` List of environment variables to set, `.0` is variable name,
66+
/// `.1` is value
67+
/// - `input` String to be fed as stdin
68+
/// - `current_dir` Optional working dir to run command in
69+
///
5170
pub fn run(lib_path: &str,
5271
prog: &str,
5372
aux_path: Option<&str>,
5473
args: &[String],
5574
env: Vec<(String, String)>,
56-
input: Option<String>)
75+
input: Option<String>,
76+
current_dir: Option<String>)
5777
-> io::Result<Result> {
5878

5979
let mut cmd = Command::new(prog);
@@ -66,6 +86,9 @@ pub fn run(lib_path: &str,
6686
for (key, val) in env {
6787
cmd.env(&key, &val);
6888
}
89+
if let Some(cwd) = current_dir {
90+
cmd.current_dir(cwd);
91+
}
6992

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

106+
/// Same as `run`, but return process rather than waiting on completion
83107
pub fn run_background(lib_path: &str,
84108
prog: &str,
85109
aux_path: Option<&str>,
86110
args: &[String],
87111
env: Vec<(String, String)>,
88-
input: Option<String>)
112+
input: Option<String>,
113+
current_dir: Option<String>)
89114
-> io::Result<Child> {
90115

91116
let mut cmd = Command::new(prog);
@@ -96,6 +121,9 @@ pub fn run_background(lib_path: &str,
96121
for (key, val) in env {
97122
cmd.env(&key, &val);
98123
}
124+
if let Some(cwd) = current_dir {
125+
cmd.current_dir(cwd);
126+
}
99127

100128
let mut process = cmd.spawn()?;
101129
if let Some(input) = input {

‎src/tools/compiletest/src/runtest.rs

+26-8
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ impl<'test> TestCx<'test> {
334334
self.props.exec_env.clone(),
335335
self.config.compile_lib_path.to_str().unwrap(),
336336
Some(aux_dir.to_str().unwrap()),
337-
Some(src))
337+
Some(src),
338+
None)
338339
}
339340

340341
fn make_pp_args(&self,
@@ -509,6 +510,7 @@ actual:\n\
509510
self.config.adb_test_dir.clone()
510511
],
511512
Vec::new(),
513+
None,
512514
None)
513515
.expect(&format!("failed to exec `{:?}`", self.config.adb_path));
514516

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

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

@@ -579,6 +583,7 @@ actual:\n\
579583
None,
580584
&debugger_opts,
581585
Vec::new(),
586+
None,
582587
None)
583588
.expect(&format!("failed to exec `{:?}`", gdb_path));
584589
let cmdline = {
@@ -686,6 +691,7 @@ actual:\n\
686691
environment,
687692
self.config.run_lib_path.to_str().unwrap(),
688693
None,
694+
None,
689695
None);
690696
}
691697
}
@@ -1231,15 +1237,21 @@ actual:\n\
12311237
env,
12321238
self.config.run_lib_path.to_str().unwrap(),
12331239
Some(aux_dir.to_str().unwrap()),
1240+
None,
12341241
None)
12351242
}
12361243
_ => {
12371244
let aux_dir = self.aux_output_dir_name();
1245+
let working_dir =
1246+
Some(self.output_base_name()
1247+
.parent().unwrap()
1248+
.to_str().unwrap().to_owned());
12381249
self.compose_and_run(self.make_run_args(),
12391250
env,
12401251
self.config.run_lib_path.to_str().unwrap(),
12411252
Some(aux_dir.to_str().unwrap()),
1242-
None)
1253+
None,
1254+
working_dir)
12431255
}
12441256
}
12451257
}
@@ -1317,6 +1329,7 @@ actual:\n\
13171329
Vec::new(),
13181330
aux_cx.config.compile_lib_path.to_str().unwrap(),
13191331
Some(aux_dir.to_str().unwrap()),
1332+
None,
13201333
None);
13211334
if !auxres.status.success() {
13221335
self.fatal_proc_rec(
@@ -1330,16 +1343,18 @@ actual:\n\
13301343
self.props.rustc_env.clone(),
13311344
self.config.compile_lib_path.to_str().unwrap(),
13321345
Some(aux_dir.to_str().unwrap()),
1333-
input)
1346+
input,
1347+
None)
13341348
}
13351349

13361350
fn compose_and_run(&self,
13371351
ProcArgs{ args, prog }: ProcArgs,
13381352
procenv: Vec<(String, String)> ,
13391353
lib_path: &str,
13401354
aux_path: Option<&str>,
1341-
input: Option<String>) -> ProcRes {
1342-
self.program_output(lib_path, prog, aux_path, args, procenv, input)
1355+
input: Option<String>,
1356+
working_dir: Option<String>) -> ProcRes {
1357+
self.program_output(lib_path, prog, aux_path, args, procenv, input, working_dir)
13431358
}
13441359

13451360
fn make_compile_args(&self,
@@ -1532,7 +1547,8 @@ actual:\n\
15321547
aux_path: Option<&str>,
15331548
args: Vec<String>,
15341549
env: Vec<(String, String)>,
1535-
input: Option<String>)
1550+
input: Option<String>,
1551+
working_dir: Option<String>)
15361552
-> ProcRes {
15371553
let cmdline =
15381554
{
@@ -1542,6 +1558,7 @@ actual:\n\
15421558
logv(self.config, format!("executing {}", cmdline));
15431559
cmdline
15441560
};
1561+
15451562
let procsrv::Result {
15461563
out,
15471564
err,
@@ -1551,7 +1568,8 @@ actual:\n\
15511568
aux_path,
15521569
&args,
15531570
env,
1554-
input).expect(&format!("failed to exec `{}`", prog));
1571+
input,
1572+
working_dir).expect(&format!("failed to exec `{}`", prog));
15551573
self.dump_output(&out, &err);
15561574
ProcRes {
15571575
status: status,
@@ -1715,7 +1733,7 @@ actual:\n\
17151733
args: vec![format!("-input-file={}", irfile.to_str().unwrap()),
17161734
self.testpaths.file.to_str().unwrap().to_owned()]
17171735
};
1718-
self.compose_and_run(proc_args, Vec::new(), "", None, None)
1736+
self.compose_and_run(proc_args, Vec::new(), "", None, None, None)
17191737
}
17201738

17211739
fn run_codegen_test(&self) {

0 commit comments

Comments
 (0)
Please sign in to comment.