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.
WIP: Add wasmldr integration test(s)
* Remove internal/wasmldr's build.rs * Move wasmldr test sources to tests/wasm/*.wat * Build tests/wasm/*.wat to OUT_DIR/bin/*.wasm in build.rs * Add tests/wasmldr_tests.rs, which tries to run .wasm test binaries TODO: gotta fix how we pass the module into the keep, because the test doesn't work but this works OK: cargo run -- exec 3< $(find target -name hello_wasi_snapshot1.wasm | tail -n1) Signed-off-by: Will Woods <will@profian.com>
- Loading branch information
Showing
11 changed files
with
117 additions
and
35 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.
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,77 @@ | ||
// 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 process_control::{ChildExt, Output, Timeout}; | ||
use std::io; | ||
use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd}; | ||
use std::time::Duration; | ||
|
||
extern crate libc; | ||
use libc::c_int; | ||
|
||
mod common; | ||
use common::{CRATE, KEEP_BIN, OUT_DIR, TEST_BINS_OUT, 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"[..]); | ||
} |