config is lazy_static to amoritze it
This commit is contained in:
7
crates/test-programs/wasi-tests/Cargo.lock
generated
7
crates/test-programs/wasi-tests/Cargo.lock
generated
@@ -1,5 +1,11 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.72"
|
version = "0.2.72"
|
||||||
@@ -22,6 +28,7 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
|||||||
name = "wasi-tests"
|
name = "wasi-tests"
|
||||||
version = "0.19.0"
|
version = "0.19.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
"more-asserts",
|
"more-asserts",
|
||||||
"wasi",
|
"wasi",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ publish = false
|
|||||||
libc = "0.2.65"
|
libc = "0.2.65"
|
||||||
wasi = "0.10.2"
|
wasi = "0.10.2"
|
||||||
more-asserts = "0.2.1"
|
more-asserts = "0.2.1"
|
||||||
|
lazy_static = "1.4"
|
||||||
|
|
||||||
# This crate is built with the wasm32-wasi target, so it's separate
|
# This crate is built with the wasm32-wasi target, so it's separate
|
||||||
# from the main Wasmtime build, so use this directive to exclude it
|
# from the main Wasmtime build, so use this directive to exclude it
|
||||||
|
|||||||
48
crates/test-programs/wasi-tests/src/config.rs
Normal file
48
crates/test-programs/wasi-tests/src/config.rs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
pub struct TestConfig {
|
||||||
|
errno_mode: ErrnoMode,
|
||||||
|
no_dangling_symlinks: bool,
|
||||||
|
no_fd_allocate: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ErrnoMode {
|
||||||
|
Linux,
|
||||||
|
Windows,
|
||||||
|
Permissive,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TestConfig {
|
||||||
|
pub fn from_env() -> Self {
|
||||||
|
let errno_mode = if std::env::var("ERRNO_MODE_LINUX").is_ok() {
|
||||||
|
ErrnoMode::Linux
|
||||||
|
} else if std::env::var("ERRNO_MODE_WINDOWS").is_ok() {
|
||||||
|
ErrnoMode::Windows
|
||||||
|
} else {
|
||||||
|
ErrnoMode::Permissive
|
||||||
|
};
|
||||||
|
let no_dangling_symlinks = std::env::var("NO_DANGLING_SYMLINKS").is_ok();
|
||||||
|
let no_fd_allocate = std::env::var("NO_FD_ALLOCATE").is_ok();
|
||||||
|
TestConfig {
|
||||||
|
errno_mode,
|
||||||
|
no_dangling_symlinks,
|
||||||
|
no_fd_allocate,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn errno_expect_linux(&self) -> bool {
|
||||||
|
match self.errno_mode {
|
||||||
|
ErrnoMode::Linux => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn errno_expect_windows(&self) -> bool {
|
||||||
|
match self.errno_mode {
|
||||||
|
ErrnoMode::Windows => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn support_dangling_symlinks(&self) -> bool {
|
||||||
|
!self.no_dangling_symlinks
|
||||||
|
}
|
||||||
|
pub fn support_fd_allocate(&self) -> bool {
|
||||||
|
!self.no_fd_allocate
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
use more_asserts::assert_gt;
|
use more_asserts::assert_gt;
|
||||||
|
pub mod config;
|
||||||
|
|
||||||
|
lazy_static::lazy_static! {
|
||||||
|
pub static ref TESTCONFIG: config::TestConfig = config::TestConfig::from_env();
|
||||||
|
}
|
||||||
|
|
||||||
// The `wasi` crate version 0.9.0 and beyond, doesn't
|
// The `wasi` crate version 0.9.0 and beyond, doesn't
|
||||||
// seem to define these constants, so we do it ourselves.
|
// seem to define these constants, so we do it ourselves.
|
||||||
@@ -69,7 +74,7 @@ macro_rules! assert_errno {
|
|||||||
};
|
};
|
||||||
($s:expr, windows => $i:expr, $( $rest:expr ),+) => {
|
($s:expr, windows => $i:expr, $( $rest:expr ),+) => {
|
||||||
let e = $s;
|
let e = $s;
|
||||||
if std::env::var("ERRNO_EXPECT_WINDOWS").is_ok() {
|
if $crate::TESTCONFIG.errno_expect_windows() {
|
||||||
assert_errno!(e, $i);
|
assert_errno!(e, $i);
|
||||||
} else {
|
} else {
|
||||||
assert_errno!(e, $($rest),+, $i);
|
assert_errno!(e, $($rest),+, $i);
|
||||||
@@ -77,7 +82,7 @@ macro_rules! assert_errno {
|
|||||||
};
|
};
|
||||||
($s:expr, linux => $i:expr, $( $rest:expr ),+) => {
|
($s:expr, linux => $i:expr, $( $rest:expr ),+) => {
|
||||||
let e = $s;
|
let e = $s;
|
||||||
if std::env::var("ERRNO_EXPECT_LINUX").is_ok() {
|
if $crate::TESTCONFIG.errno_expect_linux() {
|
||||||
assert_errno!(e, $i);
|
assert_errno!(e, $i);
|
||||||
} else {
|
} else {
|
||||||
assert_errno!(e, $($rest),+, $i);
|
assert_errno!(e, $($rest),+, $i);
|
||||||
|
|||||||
Reference in New Issue
Block a user