This repository has been archived by the owner on Oct 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit needs to get broken up but I want it to be public so.. here we go! Signed-off-by: Will Woods <[email protected]>
- Loading branch information
Showing
15 changed files
with
132 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nightly-2021-09-30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub const CRATE: &str = env!("CARGO_MANIFEST_DIR"); | ||
pub const KEEP_BIN: &str = env!("CARGO_BIN_EXE_enarx-keepldr"); | ||
pub const OUT_DIR: &str = env!("OUT_DIR"); | ||
pub const TEST_BINS_OUT: &str = "bin"; | ||
pub const TIMEOUT_SECS: u64 = 10; | ||
pub const MAX_ASSERT_ELEMENTS: usize = 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::fs::File; | ||
use std::path::Path; | ||
use std::process::{Command, Stdio}; | ||
//use std::os::unix::process::CommandExt; | ||
use std::os::unix::io::{RawFd, FromRawFd, IntoRawFd}; | ||
use std::io; | ||
use std::time::Duration; | ||
use process_control::{ChildExt, Output, Timeout}; | ||
|
||
extern crate libc; | ||
use libc::c_int; | ||
|
||
mod common; | ||
use common::{CRATE, OUT_DIR, TEST_BINS_OUT, KEEP_BIN, TIMEOUT_SECS}; | ||
|
||
use serial_test::serial; | ||
//use anyhow::Result; | ||
|
||
const MODULE_FD: RawFd = 3; | ||
|
||
// wrap a libc call to return io::Result | ||
fn cvt(rv: c_int) -> io::Result<c_int> { | ||
if rv == -1 { Err(io::Error::last_os_error()) } else { Ok(rv) } | ||
} | ||
|
||
fn open_module(path: &Path) -> io::Result<File> { | ||
let mut file = File::open(path)?; | ||
let fd = file.into_raw_fd(); | ||
unsafe { | ||
file = File::from_raw_fd(cvt(libc::dup2(fd, MODULE_FD))?) | ||
} | ||
Ok(file) | ||
} | ||
|
||
fn run_test(wasm: &str) -> Output { | ||
let path = Path::new(CRATE).join(OUT_DIR).join(TEST_BINS_OUT).join(wasm); | ||
let _fd3 = open_module(&path).unwrap(); | ||
let child = Command::new(KEEP_BIN) | ||
.arg("exec") | ||
.stdin(Stdio::piped()) | ||
.stdout(Stdio::piped()) | ||
.stderr(Stdio::piped()) | ||
.spawn() | ||
.unwrap_or_else(|e| panic!("failed to run `{:?}`: {:#?}", wasm, e)); | ||
let output = child | ||
.with_output_timeout(Duration::from_secs(TIMEOUT_SECS)) | ||
.terminating() | ||
.wait() | ||
.unwrap_or_else(|e| panic!("failed to run `{}`: {:#?}", wasm, e)) | ||
.unwrap_or_else(|| panic!("process `{}` timed out", wasm)); | ||
|
||
let _exit_status = output.status.code().unwrap_or_else(|| { | ||
panic!("process `{}` terminated by signal {:?}", wasm, output.status.signal()) | ||
}); | ||
|
||
// TODO: compare output.stdout, output.stderr, etc. | ||
|
||
output | ||
} | ||
|
||
#[test] | ||
#[serial] | ||
fn hello_wasi_snapshot1() { | ||
let out = run_test("hello_wasi_snapshot1.wasm"); | ||
assert_eq!(out.stdout, &b"Hello, world!\n"[..]); | ||
} |