aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs4
-rw-r--r--src/test_macros.rs21
-rw-r--r--src/uuid.rs4
-rw-r--r--src/v1_15_2.rs2
4 files changed, 15 insertions, 16 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6342c41..1a41cce 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,9 +1,9 @@
-#![feature(test)]
+#![cfg_attr(feature = "bench", feature(test))]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
-#[cfg(all(test, feature = "std"))]
+#[cfg(all(test, feature = "std", feature = "bench"))]
extern crate test;
mod deserialize;
diff --git a/src/test_macros.rs b/src/test_macros.rs
index ead3208..1ab1716 100644
--- a/src/test_macros.rs
+++ b/src/test_macros.rs
@@ -1,6 +1,3 @@
-use crate::{SerializeResult, Serializer};
-use alloc::vec::Vec;
-
#[cfg(all(test, feature = "std"))]
#[macro_export]
macro_rules! packet_test_cases {
@@ -33,8 +30,9 @@ macro_rules! packet_test_cases {
}
}
+ #[cfg(feature = "bench")]
#[bench]
- fn $benchnams(b: &mut Bencher) {
+ fn $benchnams(b: &mut test::Bencher) {
let packet = $pnam::$varnam($bodnam::test_gen_random());
let mut serializer = BenchSerializer::default();
packet
@@ -51,8 +49,9 @@ macro_rules! packet_test_cases {
})
}
+ #[cfg(feature = "bench")]
#[bench]
- fn $benchnamd(b: &mut Bencher) {
+ fn $benchnamd(b: &mut test::Bencher) {
let packet = $pnam::$varnam($bodnam::test_gen_random());
let mut serializer = BytesSerializer::default();
packet
@@ -72,21 +71,21 @@ macro_rules! packet_test_cases {
};
}
-#[cfg(all(test, feature = "std"))]
+#[cfg(all(test, feature = "std", feature = "bench"))]
#[derive(Clone, Debug, Default, PartialEq)]
pub struct BenchSerializer {
- data: Vec<u8>,
+ data: alloc::vec::Vec<u8>,
}
-#[cfg(all(test, feature = "std"))]
-impl Serializer for BenchSerializer {
- fn serialize_bytes(&mut self, data: &[u8]) -> SerializeResult {
+#[cfg(all(test, feature = "std", feature = "bench"))]
+impl crate::Serializer for BenchSerializer {
+ fn serialize_bytes(&mut self, data: &[u8]) -> crate::SerializeResult {
self.data.extend_from_slice(data);
Ok(())
}
}
-#[cfg(all(test, feature = "std"))]
+#[cfg(all(test, feature = "std", feature = "bench"))]
impl BenchSerializer {
pub fn reset(&mut self) {
self.data.clear();
diff --git a/src/uuid.rs b/src/uuid.rs
index 9fcdacd..8e72c26 100644
--- a/src/uuid.rs
+++ b/src/uuid.rs
@@ -261,7 +261,7 @@ mod tests {
assert_eq!(deserialized, id);
}
- #[cfg(feature = "std")]
+ #[cfg(all(feature = "std", feature = "bench"))]
#[bench]
fn bench_parse_uuid4(b: &mut test::Bencher) {
let rand = UUID4::random();
@@ -272,7 +272,7 @@ mod tests {
})
}
- #[cfg(feature = "std")]
+ #[cfg(all(feature = "std", feature = "bench"))]
#[bench]
fn bench_uuid4_to_str(b: &mut test::Bencher) {
let rand = UUID4::random();
diff --git a/src/v1_15_2.rs b/src/v1_15_2.rs
index 245d20e..661fcac 100644
--- a/src/v1_15_2.rs
+++ b/src/v1_15_2.rs
@@ -2953,9 +2953,9 @@ pub mod tests {
use super::*;
use crate::packet_test_cases;
use crate::protocol::{Packet, RawPacket};
+ #[cfg(feature = "bench")]
use crate::test_macros::BenchSerializer;
use crate::types::BytesSerializer;
- use test::Bencher;
packet_test_cases!(Packet578, Handshake, HandshakeSpec,
test_handshake, bench_write_handshake, bench_read_handshake);