mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
update tests to use backend as in cache key gen
This commit is contained in:
parent
b746a88138
commit
f45d523012
@ -6,6 +6,7 @@ use wasmer_runtime::{
|
|||||||
cache::{Cache, FileSystemCache, WasmHash},
|
cache::{Cache, FileSystemCache, WasmHash},
|
||||||
compile, validate,
|
compile, validate,
|
||||||
};
|
};
|
||||||
|
use wasmer_runtime_core::backend::Backend;
|
||||||
|
|
||||||
static NGINX_WASM: &'static [u8] = include_bytes!("../../../examples/nginx/nginx.wasm");
|
static NGINX_WASM: &'static [u8] = include_bytes!("../../../examples/nginx/nginx.wasm");
|
||||||
|
|
||||||
@ -18,7 +19,9 @@ fn load_module(hash: WasmHash, cache: &impl Cache) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn hashing_benchmark(c: &mut Criterion) {
|
fn hashing_benchmark(c: &mut Criterion) {
|
||||||
c.bench_function("nginx HASH", |b| b.iter(|| WasmHash::generate(NGINX_WASM)));
|
c.bench_function("nginx HASH", |b| {
|
||||||
|
b.iter(|| WasmHash::generate(NGINX_WASM, Backend::Cranelift))
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_benchmark(c: &mut Criterion) {
|
fn validate_benchmark(c: &mut Criterion) {
|
||||||
@ -36,7 +39,7 @@ fn load_benchmark(c: &mut Criterion) {
|
|||||||
FileSystemCache::new(tempdir.path()).expect("unable to create file system cache")
|
FileSystemCache::new(tempdir.path()).expect("unable to create file system cache")
|
||||||
};
|
};
|
||||||
let module = compile(NGINX_WASM).unwrap();
|
let module = compile(NGINX_WASM).unwrap();
|
||||||
let wasm_hash = WasmHash::generate(NGINX_WASM);
|
let wasm_hash = WasmHash::generate(NGINX_WASM, Backend::Cranelift);
|
||||||
cache
|
cache
|
||||||
.store(wasm_hash, module)
|
.store(wasm_hash, module)
|
||||||
.expect("unable to store into cache");
|
.expect("unable to store into cache");
|
||||||
|
@ -20,6 +20,7 @@ pub use wasmer_runtime_core::cache::{Artifact, Cache, WasmHash, WASMER_VERSION_H
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use wasmer_runtime::cache::{Cache, FileSystemCache, WasmHash};
|
/// use wasmer_runtime::cache::{Cache, FileSystemCache, WasmHash};
|
||||||
|
/// use wasmer_runtime_core::backend::Backend;
|
||||||
///
|
///
|
||||||
/// # use wasmer_runtime::{Module, error::CacheError};
|
/// # use wasmer_runtime::{Module, error::CacheError};
|
||||||
/// fn store_module(module: Module) -> Result<Module, CacheError> {
|
/// fn store_module(module: Module) -> Result<Module, CacheError> {
|
||||||
@ -28,7 +29,7 @@ pub use wasmer_runtime_core::cache::{Artifact, Cache, WasmHash, WASMER_VERSION_H
|
|||||||
/// // corrupted or tampered with.
|
/// // corrupted or tampered with.
|
||||||
/// let mut fs_cache = unsafe { FileSystemCache::new("some/directory/goes/here")? };
|
/// let mut fs_cache = unsafe { FileSystemCache::new("some/directory/goes/here")? };
|
||||||
/// // Compute a key for a given WebAssembly binary
|
/// // Compute a key for a given WebAssembly binary
|
||||||
/// let key = WasmHash::generate(&[]);
|
/// let key = WasmHash::generate(&[], Backend::Cranelift);
|
||||||
/// // Store a module into the cache given a key
|
/// // Store a module into the cache given a key
|
||||||
/// fs_cache.store(key, module.clone())?;
|
/// fs_cache.store(key, module.clone())?;
|
||||||
/// Ok(module)
|
/// Ok(module)
|
||||||
@ -119,6 +120,7 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use wasmer_runtime_core::backend::Backend;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_system_cache_run() {
|
fn test_file_system_cache_run() {
|
||||||
@ -147,7 +149,7 @@ mod tests {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
// store module
|
// store module
|
||||||
let key = WasmHash::generate(&wasm);
|
let key = WasmHash::generate(&wasm, Backend::Cranelift);
|
||||||
fs_cache.store(key, module.clone()).unwrap();
|
fs_cache.store(key, module.clone()).unwrap();
|
||||||
|
|
||||||
// load module
|
// load module
|
||||||
|
Loading…
Reference in New Issue
Block a user