macro_rules! impl_benchmark_test_suite { ( $bench_module:ident, $new_test_ext:expr, $test:path $(, $( $rest:tt )* )? ) => { ... }; }
Expand description
This creates a test suite which runs the module’s benchmarks.
When called in pallet_example_basic as
impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::Test);It expands to the equivalent of:
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::{new_test_ext, Test};
use frame_support::assert_ok;
#[test]
fn test_benchmarks() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_accumulate_dummy::<Test>());
assert_ok!(test_benchmark_set_dummy::<Test>());
assert_ok!(test_benchmark_sort_vector::<Test>());
});
}
}When called inside the benchmarks macro of the pallet_example_basic as
benchmarks! {
// Benchmarks omitted for brevity
impl_benchmark_test_suite!(Pallet, crate::tests::new_test_ext(), crate::tests::Test);
}It expands to the equivalent of:
#[cfg(test)]
mod benchmarking {
use super::*;
use crate::tests::{new_test_ext, Test};
use frame_support::assert_ok;
#[test]
fn bench_accumulate_dummy() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_accumulate_dummy::<Test>());
})
}
#[test]
fn bench_set_dummy() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_set_dummy::<Test>());
})
}
#[test]
fn bench_sort_vector() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_sort_vector::<Test>());
})
}
}Arguments
The first argument, module, must be the path to this crate’s module.
The second argument, new_test_ext, must be a function call which returns either a
sp_io::TestExternalities, or some other type with a similar interface.
Note that this function call is not evaluated at compile time, but is instead copied textually into each appropriate invocation site.
The third argument, test, must be the path to the runtime. The item to which this must refer
will generally take the form:
frame_support::construct_runtime!(
pub enum Test where ...
{ ... }
);There is an optional fourth argument, with keyword syntax: benchmarks_path = path_to_benchmarks_invocation. In the typical case in which this macro is in the same module as
the benchmarks! invocation, you don’t need to supply this. However, if the
impl_benchmark_test_suite! invocation is in a different module than the benchmarks!
invocation, then you should provide the path to the module containing the benchmarks!
invocation:
mod benches {
benchmarks!{
...
}
}
mod tests {
// because of macro syntax limitations, neither Pallet nor benches can be paths, but both have
// to be idents in the scope of `impl_benchmark_test_suite`.
use crate::{benches, Pallet};
impl_benchmark_test_suite!(Pallet, new_test_ext(), Test, benchmarks_path = benches);
// new_test_ext and the Test item are defined later in this module
}There is an optional fifth argument, with keyword syntax: extra = true or extra = false.
By default, this generates a test suite which iterates over all benchmarks, including those
marked with the #[extra] annotation. Setting extra = false excludes those.
There is an optional sixth argument, with keyword syntax: exec_name = custom_exec_name.
By default, this macro uses execute_with for this parameter. This argument, if set, is subject
to these restrictions:
- It must be the name of a method applied to the output of the
new_test_extargument. - That method must have a signature capable of receiving a single argument of the form
impl FnOnce().