Skip to content

Commit

Permalink
Move get/set points used to middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Jun 2, 2019
1 parent e533a8a commit c020c39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
23 changes: 17 additions & 6 deletions lib/middleware-common/src/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use wasmer_runtime_core::{
module::ModuleInfo,
vm::InternalField,
wasmparser::{Operator, Type as WpType},
Instance,
};

static INTERNAL_FIELD: InternalField = InternalField::allocate();
Expand Down Expand Up @@ -98,9 +99,19 @@ impl FunctionMiddleware for Metering {
}
}

/// Returns the number of points used by a function call for metering
pub fn get_points_used(_instance: &Instance) -> u64 {
unimplemented!()
}

/// Sets the value of points used
pub fn set_points_used(_instance: &mut Instance, _value: u64) {
unimplemented!()
}

#[cfg(test)]
mod tests {

use super::*;
use wabt::wat2wasm;
use wasmer_runtime_core::{
backend::{Compiler, CompilerConfig},
Expand Down Expand Up @@ -204,7 +215,7 @@ mod tests {
let import_object = imports! {};
let mut instance = module.instantiate(&import_object).unwrap();

instance.context_mut().set_points_used(0u64);
set_points_used(&mut instance, 0u64);

let add_to: Func<(i32, i32), i32> = instance.func("add_to").unwrap();
let value = add_to.call(3, 4).unwrap();
Expand All @@ -213,7 +224,7 @@ mod tests {
assert_eq!(value, 7);

// verify is uses the correct number of points
assert_eq!(instance.context().get_points_used(), 42); // TODO need to update assertion to actual points used.
assert_eq!(get_points_used(&instance), 42); // TODO need to update assertion to actual points used.
}

#[test]
Expand All @@ -235,7 +246,7 @@ mod tests {
let import_object = imports! {};
let mut instance = module.instantiate(&import_object).unwrap();

instance.context_mut().set_points_used(0u64);
set_points_used(&mut instance, 0u64);

let add_to: Func<(i32, i32), i32> = instance.func("add_to").unwrap();
let result = add_to.call(10_000_000, 4);
Expand All @@ -244,8 +255,8 @@ mod tests {
assert_eq!(result.is_err(), true); // TODO assert that the trap is caused by PointsExausted

// verify is uses the correct number of points
assert_eq!(instance.context().get_points_used(), 99); // TODO need to update assertion to actual points used.
// TODO should points used be close to limit or at limit when trapping
assert_eq!(get_points_used(&instance), 99); // TODO need to update assertion to actual points used.
// TODO should points used be close to limit or at limit when trapping
}

}
10 changes: 0 additions & 10 deletions lib/runtime-core/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,6 @@ impl Ctx {
pub fn dynamic_sigindice_count(&self) -> usize {
unsafe { (*self.local_backing).dynamic_sigindices.len() }
}

/// Returns the number of points used by a function call for metering
pub fn get_points_used(&self) -> u64 {
unimplemented!()
}

/// Sets the value of points used
pub fn set_points_used(&mut self, _value: u64) {
unimplemented!()
}
}

#[doc(hidden)]
Expand Down

0 comments on commit c020c39

Please sign in to comment.