Skip to content

Commit

Permalink
Move emscripten-tests to tests dir + misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed Apr 2, 2020
1 parent 976bf9b commit 513e6ac
Show file tree
Hide file tree
Showing 1,057 changed files with 969 additions and 937 deletions.
24 changes: 9 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ wasmer-llvm-backend = { path = "lib/llvm-backend", optional = true }
wasmer-wasi = { path = "lib/wasi", optional = true }
wasmer-kernel-loader = { path = "lib/kernel-loader", optional = true }
wasmer-dev-utils = { path = "lib/dev-utils", optional = true }
wasmer-emscripten-tests = { path = "lib/emscripten-tests", optional = true }
wasmer-wasi-experimental-io-devices = { path = "lib/wasi-experimental-io-devices", optional = true }

[workspace]
Expand All @@ -59,16 +58,17 @@ members = [
"lib/kernel-net",
"lib/dev-utils",
"lib/wasi-experimental-io-devices",
"lib/emscripten-tests",
"lib/interface-types",
"examples/parallel",
"examples/plugin-for-example",
"examples/parallel-guest",
"tests/generate-wasi-tests",
"tests/generate-emscripten-tests",
]

[build-dependencies]
wabt = "0.9.1"
generate-emscripten-tests = { path = "tests/generate-emscripten-tests" }
generate-wasi-tests = { path = "tests/generate-wasi-tests" }
glob = "0.3"
rustc_version = "0.2"
Expand Down
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
//!
//! Please try to keep this file as clean as possible.
use generate_emscripten_tests;
use generate_wasi_tests;

fn main() {
generate_wasi_tests::build();
generate_emscripten_tests::build();
}
74 changes: 56 additions & 18 deletions lib/dev-utils/src/stdio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::file_descriptor::FileDescriptor;
use libc;
use std::io;
use std::io::BufReader;
use std::io::Read;

Expand All @@ -21,39 +22,76 @@ const STDOUT_FILENO: libc::c_int = 1;
#[cfg(target_os = "windows")]
const STDERR_FILENO: libc::c_int = 2;

fn pipe(ptr: *mut libc::c_int) -> Result<libc::c_int, io::Error> {
#[cfg(not(target_os = "windows"))]
let result = unsafe { libc::pipe(ptr) };
#[cfg(target_os = "windows")]
let result = unsafe { libc::pipe(ptr, 1000, libc::O_TEXT) };

if result == -1 {
Err(std::io::Error::last_os_error())
} else {
Ok(result)
}
}

/// `dup` creates a new `fd`, make sure you `close` it when you're done with it!!
fn dup(oldfd: libc::c_int) -> Result<libc::c_int, io::Error> {
let result = unsafe { libc::dup(oldfd) };

if result == -1 {
Err(std::io::Error::last_os_error())
} else {
Ok(result)
}
}

fn dup2(oldfd: libc::c_int, newfd: libc::c_int) -> Result<libc::c_int, io::Error> {
let result = unsafe { libc::dup2(oldfd, newfd) };

if result == -1 {
Err(std::io::Error::last_os_error())
} else {
Ok(result)
}
}

fn close(fd: libc::c_int) -> Result<libc::c_int, io::Error> {
let result = unsafe { libc::close(fd) };

if result == -1 {
Err(std::io::Error::last_os_error())
} else {
Ok(result)
}
}

// Implementation inspired in
// https://github.com/rust-lang/rust/blob/7d52cbce6db83e4fc2d8706b4e4b9c7da76cbcf8/src/test/run-pass/issues/issue-30490.rs
// Currently only works in Unix systems (Mac, Linux)
impl StdioCapturer {
fn pipe() -> (libc::c_int, libc::c_int) {
let mut fds = [0; 2];

#[cfg(not(target_os = "windows"))]
assert_eq!(unsafe { libc::pipe(fds.as_mut_ptr()) }, 0);
#[cfg(target_os = "windows")]
assert_eq!(
unsafe { libc::pipe(fds.as_mut_ptr(), 1000, libc::O_TEXT) },
0
);
pipe(fds.as_mut_ptr()).unwrap();

(fds[0], fds[1])
}

pub fn new() -> Self {
let stdout_backup = unsafe { libc::dup(STDOUT_FILENO) };
let stderr_backup = unsafe { libc::dup(STDERR_FILENO) };
let stdout_backup = dup(STDOUT_FILENO).unwrap();
let stderr_backup = dup(STDERR_FILENO).unwrap();

let (stdout_reader, stdout_writer) = Self::pipe();
let (stderr_reader, stderr_writer) = Self::pipe();

assert!(unsafe { libc::dup2(stdout_writer, STDOUT_FILENO) } > -1);
assert!(unsafe { libc::dup2(stderr_writer, STDERR_FILENO) } > -1);
dup2(stdout_writer, STDOUT_FILENO).unwrap();
dup2(stderr_writer, STDERR_FILENO).unwrap();

// Make sure we close any duplicates of the writer end of the pipe,
// otherwise we can get stuck reading from the pipe which has open
// writers but no one supplying any input
assert_eq!(unsafe { libc::close(stdout_writer) }, 0);
assert_eq!(unsafe { libc::close(stderr_writer) }, 0);
close(stdout_writer).unwrap();
close(stderr_writer).unwrap();

StdioCapturer {
stdout_backup,
Expand All @@ -64,11 +102,11 @@ impl StdioCapturer {
}

pub fn end(self) -> Result<(String, String), std::io::Error> {
// The Stdio passed into the Command took over (and closed) std{out, err}
// so we should restore them as they were.
dup2(self.stdout_backup, STDOUT_FILENO).unwrap();
dup2(self.stderr_backup, STDERR_FILENO).unwrap();

assert!(unsafe { libc::dup2(self.stdout_backup, STDOUT_FILENO) } > -1);
assert!(unsafe { libc::dup2(self.stderr_backup, STDERR_FILENO) } > -1);
close(self.stdout_backup).unwrap();
close(self.stderr_backup).unwrap();

let fd = FileDescriptor::new(self.stdout_reader);
let mut reader = BufReader::new(fd);
Expand Down
28 changes: 0 additions & 28 deletions lib/emscripten-tests/Cargo.toml

This file was deleted.

Empty file removed lib/emscripten-tests/a.txt
Empty file.
9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/clock_gettime.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/env.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/localtime.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/printf.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/puts.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_addr_of_stacked.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_alloca.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_alloca_stack.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_array2.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_array2b.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_atomic.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_atox.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_bsearch.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_complex.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_double_varargs.rs

This file was deleted.

9 changes: 0 additions & 9 deletions lib/emscripten-tests/tests/emtests/test_erf.rs

This file was deleted.

Loading

0 comments on commit 513e6ac

Please sign in to comment.