rustls/
test_macros.rs

1/// Macros used for unit testing.
2
3/// Instantiate the given test functions once for each built-in provider.
4///
5/// The selected provider module is bound as `provider`; you can rely on this
6/// having the union of the items common to the `crypto::ring` and
7/// `crypto::aws_lc_rs` modules.
8macro_rules! test_for_each_provider {
9    ($($tt:tt)+) => {
10        #[cfg(all(test, feature = "ring"))]
11        mod test_with_ring {
12            use crate::crypto::ring as provider;
13            $($tt)+
14        }
15
16        #[cfg(all(test, feature = "aws_lc_rs"))]
17        mod test_with_aws_lc_rs {
18            use crate::crypto::aws_lc_rs as provider;
19            $($tt)+
20        }
21    };
22}
23
24/// Instantiate the given benchmark functions once for each built-in provider.
25///
26/// The selected provider module is bound as `provider`; you can rely on this
27/// having the union of the items common to the `crypto::ring` and
28/// `crypto::aws_lc_rs` modules.
29macro_rules! bench_for_each_provider {
30    ($($tt:tt)+) => {
31        #[cfg(all(bench, feature = "ring"))]
32        mod bench_with_ring {
33            use crate::crypto::ring as provider;
34            $($tt)+
35        }
36
37        #[cfg(all(bench, feature = "aws_lc_rs"))]
38        mod bench_with_aws_lc_rs {
39            use crate::crypto::aws_lc_rs as provider;
40            $($tt)+
41        }
42    };
43}
44
45test_for_each_provider! {
46    #[test]
47    fn test_each_provider() {
48        std::println!("provider is {:?}", provider::default_provider());
49    }
50}
51
52bench_for_each_provider! {
53    #[bench]
54    fn bench_each_provider(b: &mut test::Bencher) {
55        b.iter(|| provider::default_provider());
56    }
57}