Macro frame_benchmarking::impl_benchmark_test_suite [−][src]
macro_rules! impl_benchmark_test_suite { ( $bench_module:ident, $new_test_ext:expr, $test:path $(, $( $rest:tt )* )? ) => { ... }; ( @selected: $bench_module:ident, $new_test_ext:expr, $test:path, benchmarks_path = $old:ident, extra = $extra:expr, exec_name = $exec_name:ident, @user: benchmarks_path = $benchmarks_path:ident $(, $( $rest:tt )* )? ) => { ... }; ( @selected: $bench_module:ident, $new_test_ext:expr, $test:path, benchmarks_path = $benchmarks_path:ident, extra = $old:expr, exec_name = $exec_name:ident, @user: extra = $extra:expr $(, $( $rest:tt )* )? ) => { ... }; ( @selected: $bench_module:ident, $new_test_ext:expr, $test:path, benchmarks_path = $benchmarks_path:ident, extra = $extra:expr, exec_name = $old:ident, @user: exec_name = $exec_name:ident $(, $( $rest:tt )* )? ) => { ... }; ( @selected: $bench_module:ident, $new_test_ext:expr, $test:path, benchmarks_path = $path_to_benchmarks_invocation:ident, extra = $extra:expr, exec_name = $exec_name:ident, @user: $(,)? ) => { ... }; }
Expand description
This creates a test suite which runs the module’s benchmarks.
When called in pallet_example
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_another_set_dummy::<Test>()); 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_ext
argument. - That method must have a signature capable of receiving a single argument of the form
impl FnOnce()
.