macro_rules! impl_benchmark_test_suite {
(
$new_test_ext:expr,
$(, $( $rest:tt )* )?
) => { ... };
(
@selected:
$new_test_ext:expr,
benchmarks_path = $old:ident,
extra = $extra:expr,
exec_name = $exec_name:ident,
@user:
benchmarks_path = $benchmarks_path:ident
$(, $( $rest:tt )* )?
) => { ... };
(
@selected:
$new_test_ext:expr,
benchmarks_path = $benchmarks_path:ident,
extra = $old:expr,
exec_name = $exec_name:ident,
@user:
extra = $extra:expr
$(, $( $rest:tt )* )?
) => { ... };
(
@selected:
$new_test_ext:expr,
benchmarks_path = $benchmarks_path:ident,
extra = $extra:expr,
exec_name = $old:ident,
@user:
exec_name = $exec_name:ident
$(, $( $rest:tt )* )?
) => { ... };
(
@selected:
$new_test_ext:expr,
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!(crate::tests::new_test_ext());
It expands to the equivalent of:
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::new_test_ext;
use frame_support::assert_ok;
#[test]
fn test_benchmarks() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_accumulate_dummy());
assert_ok!(test_benchmark_set_dummy());
assert_ok!(test_benchmark_another_set_dummy());
assert_ok!(test_benchmark_sort_vector());
});
}
}
Arguments
The first 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.
There is an optional second 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 runtime_benchmarks!
invocation, then you should
provide the path to the module containing the benchmarks!
invocation:
mod benches {
runtime_benchmarks!{
...
}
}
mod tests {
// because of macro syntax limitations, benches can't be paths, but has
// to be idents in the scope of `impl_benchmark_test_suite`.
use crate::benches;
impl_benchmark_test_suite!(new_test_ext(), benchmarks_path = benches);
// new_test_ext are defined later in this module
}
There is an optional 3rd 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 4th 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()
.