Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More emscripten test fixes #31623

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/librustc_back/target/asmjs_unknown_emscripten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ pub fn target() -> Target {
linker: "emcc".to_string(),
ar: "emar".to_string(),

pre_link_args: vec![
// Emscripten has exceptions disabled by default when building with -01 or more.
// This flag forces them to be enabled.
"-s".to_owned(), "DISABLE_EXCEPTION_CATCHING=0".to_owned(),
"-s".to_owned(), "ERROR_ON_UNDEFINED_SYMBOLS=1".to_owned(),
],

dynamic_linking: false,
executables: true,
exe_suffix: ".js".to_string(),
Expand Down
1 change: 0 additions & 1 deletion src/libstd/sys/common/libunwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ pub const unwinder_private_data_size: usize = 2;
pub const unwinder_private_data_size: usize = 2;

#[cfg(target_arch = "asmjs")]
// FIXME: Copied from arm. Need to confirm.
pub const unwinder_private_data_size: usize = 20;

#[repr(C)]
Expand Down
6 changes: 4 additions & 2 deletions src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,13 @@ pub fn home_dir() -> Option<PathBuf> {

#[cfg(any(target_os = "android",
target_os = "ios",
target_os = "nacl"))]
target_os = "nacl",
target_os = "emscripten"))]
unsafe fn fallback() -> Option<OsString> { None }
#[cfg(not(any(target_os = "android",
target_os = "ios",
target_os = "nacl")))]
target_os = "nacl",
target_os = "emscripten")))]
unsafe fn fallback() -> Option<OsString> {
#[cfg(not(target_os = "solaris"))]
unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd,
Expand Down
9 changes: 4 additions & 5 deletions src/libstd/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use prelude::v1::*;

use alloc::boxed::FnBox;
use cmp;
#[cfg(not(any(target_env = "newlib", target_os = "solaris")))]
#[cfg(not(any(target_env = "newlib", target_os = "solaris", target_os = "emscripten")))]
use ffi::CString;
use io;
use libc;
Expand Down Expand Up @@ -82,8 +82,7 @@ impl Thread {
}

#[cfg(any(target_os = "linux",
target_os = "android",
target_os = "emscripten"))]
target_os = "android"))]
pub fn set_name(name: &str) {
const PR_SET_NAME: libc::c_int = 15;
let cname = CString::new(name).unwrap_or_else(|_| {
Expand Down Expand Up @@ -124,9 +123,9 @@ impl Thread {
carg.as_ptr() as *mut libc::c_void);
}
}
#[cfg(any(target_env = "newlib", target_os = "solaris"))]
#[cfg(any(target_env = "newlib", target_os = "solaris", target_os = "emscripten"))]
pub fn set_name(_name: &str) {
// Newlib and Illumos has no way to set a thread name.
// Newlib, Illumos and Emscripten have no way to set a thread name.
}

pub fn sleep(dur: Duration) {
Expand Down
40 changes: 37 additions & 3 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
#![feature(box_syntax)]
#![feature(fnbox)]
#![feature(libc)]
#![feature(recover)]
#![feature(rustc_private)]
#![feature(set_stdio)]
#![feature(staged_api)]
#![feature(std_panic)]
#![feature(time2)]

extern crate getopts;
Expand Down Expand Up @@ -70,6 +72,7 @@ use std::fs::File;
use std::io::prelude::*;
use std::io;
use std::iter::repeat;
use std::panic;
use std::path::PathBuf;
use std::sync::mpsc::{channel, Sender};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -1067,9 +1070,17 @@ pub fn run_test(opts: &TestOpts,
}
}

thread::spawn(move || {
let data = Arc::new(Mutex::new(Vec::new()));
let data2 = data.clone();
let testfn = Arc::new(Mutex::new(Some(testfn)));
let testfn2 = testfn.clone();
let desc2 = desc.clone();
let monitor_ch2 = monitor_ch.clone();

// This Vec will contain the output of stderr and stdout.
let data = Arc::new(Mutex::new(Vec::new()));
let data2 = data.clone();
let data3 = data.clone();

let res = thread::Builder::new().spawn(move || {
let cfg = thread::Builder::new().name(match desc.name {
DynTestName(ref name) => name.clone(),
StaticTestName(name) => name.to_owned(),
Expand All @@ -1080,13 +1091,36 @@ pub fn run_test(opts: &TestOpts,
io::set_print(box Sink(data2.clone()));
io::set_panic(box Sink(data2));
}
let testfn = testfn.lock().unwrap().take().unwrap();
testfn()
})
.unwrap();
let test_result = calc_result(&desc, result_guard.join());
let stdout = data.lock().unwrap().to_vec();
monitor_ch.send((desc.clone(), test_result, stdout)).unwrap();
});

// If the thread failed to spawn (for example if the platform doesn't support threads),
// we do everything in a single-threaded way instead.
if let Err(_) = res {
let testfn = testfn2.lock().unwrap().take().unwrap();
let mut testfn = panic::AssertRecoverSafe::new(Some(testfn));

let test_result = if !nocapture {
let old_print = io::set_print(box Sink(data3.clone()));
let old_panic = io::set_panic(box Sink(data3.clone()));
let r = panic::recover(move || (testfn.take().unwrap())());
if let Some(old_print) = old_print { io::set_print(old_print); }
if let Some(old_panic) = old_panic { io::set_panic(old_panic); }
r
} else {
panic::recover(move || (testfn.take().unwrap())())
};

let test_result = calc_result(&desc2, test_result);
let stdout = data3.lock().unwrap().to_vec();
monitor_ch2.send((desc2.clone(), test_result, stdout)).unwrap();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could become the way tests are run? It'd be good to exercise this all the time rather than just with emscripten.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then tests would execute one at a time instead of concurrently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to reuse threads for tests generally because of TLS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look like a lot of duplication for a path that won't be exercised much. Can any of it be factored out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to reduce it, except for some minor things.
It would probably be feasible if Builder::spawn() returned the closure that was supposed to be called in the case of an error.

}

match testfn {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/command-before-exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// ignore-windows - this is a unix-specific test
// ignore-emscripten

#![feature(process_exec, libc)]

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/command-exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// ignore-windows - this is a unix-specific test
// ignore-emscripten
// ignore-pretty

#![feature(process_exec)]
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/drop-flag-sanity-check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// compile-flags: -Z force-dropflag-checks=on
// ignore-emscripten

// Quick-and-dirty test to ensure -Z force-dropflag-checks=on works as
// expected. Note that the inlined drop-flag is slated for removal
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/drop-trait-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten no threads support

#![allow(unknown_features)]
#![feature(box_syntax)]

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/env-home-dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

#![feature(path)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/exec-env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

// exec-env:TEST_EXEC_ENV=22

// ignore-emscripten FIXME: issue #31622

use std::env;

Expand Down
3 changes: 2 additions & 1 deletion src/test/run-pass/intrinsic-alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ mod rusti {
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"))]
target_os = "solaris",
target_os = "emscripten"))]
mod m {
#[main]
#[cfg(target_arch = "x86")]
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-10626.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

// Make sure that if a process doesn't have its stdio/stderr descriptors set up
// that we don't die in a large ball of fire
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-12133-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// aux-build:issue-12133-dylib.rs
// aux-build:issue-12133-dylib2.rs
// ignore-musl
// ignore-emscripten no dylib support

// pretty-expanded FIXME #23616

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-13304.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// ignore-aarch64
// ignore-emscripten
#![feature(io, process_capture)]

use std::env;
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-14456.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

#![feature(io, process_capture)]

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-14940.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

use std::env;
use std::process::Command;
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-16272.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// ignore-aarch64
// ignore-emscripten

use std::process::Command;
use std::env;
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-20091.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// ignore-aarch64
// ignore-emscripten
#![feature(std_misc, os)]

#[cfg(unix)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/issue-24313.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

use std::thread;
use std::env;
use std::process::Command;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/issue-30490.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

// Previously libstd would set stdio descriptors of a child process
// by `dup`ing the requested descriptors to inherit directly into the
// stdio descriptors. This, however, would incorrectly handle cases
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/linkage1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// ignore-windows
// ignore-macos
// ignore-emscripten
// aux-build:linkage1.rs

#![feature(linkage)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/multi-panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() > 1 && args[1] == "run_test" {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/no-stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

#![feature(libc)]

extern crate libc;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/process-exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

use std::env;
use std::process::{self, Command, Stdio};

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/process-remove-from-env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

use std::process::Command;
use std::env;
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/process-spawn-with-unicode-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// intact.

// ignore-aarch64
// ignore-emscripten

use std::io::prelude::*;
use std::io;
Expand Down
7 changes: 4 additions & 3 deletions src/test/run-pass/rec-align-u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ struct Outer {
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"))]
target_os = "solaris",
target_os = "emscripten"))]
mod m {
#[cfg(target_arch = "x86")]
#[cfg(any(target_arch = "x86", target_arch = "asmjs"))]
pub mod m {
pub fn align() -> usize { 4 }
pub fn size() -> usize { 12 }
}

#[cfg(not(target_arch = "x86"))]
#[cfg(not(any(target_arch = "x86", target_arch = "asmjs")))]
pub mod m {
pub fn align() -> usize { 8 }
pub fn size() -> usize { 16 }
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/running-with-no-runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

#![feature(std_panic, recover, start)]

use std::ffi::CStr;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/segfault-no-out-of-stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten can't run commands

#![feature(libc)]

extern crate libc;
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/signal-exit-status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// ignore-windows
// ignore-emscripten

use std::env;
use std::process::Command;
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/sigpipe-should-be-ignored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// doesn't die in a ball of fire, but rather it's gracefully handled.

// ignore-aarch64
// ignore-emscripten

use std::env;
use std::io::prelude::*;
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/wait-forked-but-failed-child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-emscripten

#![feature(libc)]

Expand Down