test(c-api) Add tests for the wasmer_is_*_available API.

This commit is contained in:
Ivan Enderlin
2021-02-12 10:29:58 +01:00
parent 2a93fbd717
commit bdcc95925c
4 changed files with 121 additions and 13 deletions

View File

@@ -58,6 +58,11 @@ pub extern "C" fn wasmer_is_compiler_available(compiler: wasmer_compiler_t) -> b
}
}
#[no_mangle]
pub extern "C" fn wasmer_is_headless() -> bool {
!cfg!(feature = "compiler")
}
#[no_mangle]
pub extern "C" fn wasmer_is_engine_available(engine: wasmer_engine_t) -> bool {
match engine {
@@ -67,3 +72,102 @@ pub extern "C" fn wasmer_is_engine_available(engine: wasmer_engine_t) -> bool {
_ => false,
}
}
#[cfg(test)]
mod tests {
use inline_c::assert_c;
use std::env::{remove_var, set_var};
#[test]
fn test_wasmer_is_headless() {
set_var(
"COMPILER",
if cfg!(feature = "compiler") { "0" } else { "1" },
);
(assert_c! {
#include "tests/wasmer_wasm.h"
#include <stdlib.h>
int main() {
assert(wasmer_is_headless() == (getenv("COMPILER")[0] == '1'));
return 0;
}
})
.success();
remove_var("COMPILER");
}
#[test]
fn test_wasmer_is_compiler_available() {
set_var(
"CRANELIFT",
if cfg!(feature = "cranelift") {
"1"
} else {
"0"
},
);
set_var("LLVM", if cfg!(feature = "llvm") { "1" } else { "0" });
set_var(
"SINGLEPASS",
if cfg!(feature = "singlepass") {
"1"
} else {
"0"
},
);
(assert_c! {
#include "tests/wasmer_wasm.h"
#include <stdlib.h>
int main() {
assert(wasmer_is_compiler_available(CRANELIFT) == (getenv("CRANELIFT")[0] == '1'));
assert(wasmer_is_compiler_available(LLVM) == (getenv("LLVM")[0] == '1'));
assert(wasmer_is_compiler_available(SINGLEPASS) == (getenv("SINGLEPASS")[0] == '1'));
return 0;
}
})
.success();
remove_var("CRANELIFT");
remove_var("LLVM");
remove_var("SINGLEPASS");
}
#[test]
fn test_wasmer_is_engine_available() {
set_var("JIT", if cfg!(feature = "jit") { "1" } else { "0" });
set_var("NATIVE", if cfg!(feature = "native") { "1" } else { "0" });
set_var(
"OBJECT_FILE",
if cfg!(feature = "object-file") {
"1"
} else {
"0"
},
);
(assert_c! {
#include "tests/wasmer_wasm.h"
#include <stdlib.h>
int main() {
assert(wasmer_is_engine_available(JIT) == (getenv("JIT")[0] == '1'));
assert(wasmer_is_engine_available(NATIVE) == (getenv("NATIVE")[0] == '1'));
assert(wasmer_is_engine_available(OBJECT_FILE) == (getenv("OBJECT_FILE")[0] == '1'));
return 0;
}
})
.success();
remove_var("JIT");
remove_var("NATIVE");
remove_var("OBJECT_FILE");
}
}