From 02e84b3a54d53715ce0825527b6b024d679ce2c6 Mon Sep 17 00:00:00 2001 From: "G. Endignoux" Date: Thu, 5 Mar 2020 23:31:46 +0100 Subject: [PATCH 1/3] Gate logging behind an opt-in feature. $ cargo bench --features enable_logging running 8 tests test compress_65536 ... bench: 4,330,374 ns/iter (+/- 79,850) test compress_empty ... bench: 2,221 ns/iter (+/- 370) test compress_hello ... bench: 3,217 ns/iter (+/- 225) test decompress_after_compress_65536 ... bench: 5,835,689 ns/iter (+/- 96,176) test decompress_after_compress_empty ... bench: 10,845 ns/iter (+/- 553) test decompress_after_compress_hello ... bench: 12,425 ns/iter (+/- 689) test decompress_big_file ... bench: 9,750,036 ns/iter (+/- 460,925) test decompress_huge_dict ... bench: 12,619 ns/iter (+/- 424) $ cargo bench running 8 tests test compress_65536 ... bench: 2,377,692 ns/iter (+/- 15,781) test compress_empty ... bench: 2,067 ns/iter (+/- 64) test compress_hello ... bench: 2,733 ns/iter (+/- 358) test decompress_after_compress_65536 ... bench: 3,815,474 ns/iter (+/- 72,097) test decompress_after_compress_empty ... bench: 10,760 ns/iter (+/- 5,275) test decompress_after_compress_hello ... bench: 11,865 ns/iter (+/- 75) test decompress_big_file ... bench: 7,416,332 ns/iter (+/- 40,416) test decompress_huge_dict ... bench: 12,082 ns/iter (+/- 238) --- .travis.yml | 4 ++++ Cargo.toml | 7 ++++--- benches/lzma.rs | 9 +++++++++ src/decode/lzbuffer.rs | 6 +++--- src/decode/lzma.rs | 8 ++++---- src/decode/lzma2.rs | 13 +++++++------ src/decode/rangecoder.rs | 8 ++++---- src/decode/xz.rs | 36 +++++++++++++++++++--------------- src/encode/dumbencoder.rs | 8 ++++---- src/encode/rangecoder.rs | 24 ++++++++++++++--------- src/encode/xz.rs | 5 +++-- src/lib.rs | 4 ++++ src/macros.rs | 41 +++++++++++++++++++++++++++++++++++++++ tests/lzma.rs | 19 ++++++++++++++---- tests/lzma2.rs | 11 ++++++++--- tests/xz.rs | 14 ++++++++++--- 16 files changed, 156 insertions(+), 61 deletions(-) create mode 100644 src/macros.rs diff --git a/.travis.yml b/.travis.yml index 03e3fdc..15e931d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,4 +35,8 @@ script: - cargo clippy -- -D warnings -W clippy::match-same-arms - cargo clippy --tests -- -D warnings -W clippy::match-same-arms - cargo build --verbose + - cargo build --verbose --features enable_logging - cargo test --verbose + - cargo test --verbose --features enable_logging + - cargo bench --verbose + - cargo bench --verbose --features enable_logging diff --git a/Cargo.toml b/Cargo.toml index 5cf9a6b..69f77b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,11 @@ edition = "2018" [dependencies] byteorder = "^1.0.0" crc = "^1.0.0" -log = "^0.4.0" +log = { version = "^0.4.0", optional = true } +env_logger = { version = "^0.6.0", optional = true } -[dev-dependencies] -env_logger = "^0.6.0" +[features] +enable_logging = ["env_logger", "log"] [badges] travis-ci = { repository = "gendx/lzma-rs", branch = "master" } diff --git a/benches/lzma.rs b/benches/lzma.rs index 3c4c3c4..d919e3d 100644 --- a/benches/lzma.rs +++ b/benches/lzma.rs @@ -1,5 +1,6 @@ #![feature(test)] +#[cfg(feature = "enable_logging")] extern crate env_logger; extern crate lzma_rs; extern crate test; @@ -42,48 +43,56 @@ fn decompress_bench_file(compfile: &str, b: &mut Bencher) { #[bench] fn compress_empty(b: &mut Bencher) { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); compress_bench(b"", b); } #[bench] fn decompress_after_compress_empty(b: &mut Bencher) { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); decompress_after_compress_bench(b"", b); } #[bench] fn compress_hello(b: &mut Bencher) { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); compress_bench(b"Hello world", b); } #[bench] fn decompress_after_compress_hello(b: &mut Bencher) { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); decompress_after_compress_bench(b"Hello world", b); } #[bench] fn compress_65536(b: &mut Bencher) { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); compress_bench(&[0; 0x10000], b); } #[bench] fn decompress_after_compress_65536(b: &mut Bencher) { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); decompress_after_compress_bench(&[0; 0x10000], b); } #[bench] fn decompress_big_file(b: &mut Bencher) { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); decompress_bench_file("tests/files/foo.txt.lzma", b); } #[bench] fn decompress_huge_dict(b: &mut Bencher) { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); let compressed: &[u8] = b"\x5d\x7f\x7f\x7f\x7f\xff\xff\xff\ \xff\xff\xff\xff\xff\x00\x24\x19\ diff --git a/src/decode/lzbuffer.rs b/src/decode/lzbuffer.rs index dba08ad..a25e95f 100644 --- a/src/decode/lzbuffer.rs +++ b/src/decode/lzbuffer.rs @@ -92,7 +92,7 @@ where // Fetch an LZ sequence (length, distance) from inside the buffer fn append_lz(&mut self, len: usize, dist: usize) -> error::Result<()> { - debug!("LZ {{ len: {}, dist: {} }}", len, dist); + lzma_debug!("LZ {{ len: {}, dist: {} }}", len, dist); let buf_len = self.buf.len(); if dist > buf_len { return Err(error::Error::LZMAError(format!( @@ -136,7 +136,7 @@ where W: io::Write, { pub fn from_stream(stream: &'a mut W, dict_size: usize) -> Self { - info!("Dict size in LZ buffer: {}", dict_size); + lzma_info!("Dict size in LZ buffer: {}", dict_size); Self { stream, buf: Vec::new(), @@ -211,7 +211,7 @@ where // Fetch an LZ sequence (length, distance) from inside the buffer fn append_lz(&mut self, len: usize, dist: usize) -> error::Result<()> { - debug!("LZ {{ len: {}, dist: {} }}", len, dist); + lzma_debug!("LZ {{ len: {}, dist: {} }}", len, dist); if dist > self.dict_size { return Err(error::Error::LZMAError(format!( "LZ distance {} is beyond dictionary size {}", diff --git a/src/decode/lzma.rs b/src/decode/lzma.rs index a9f487e..184d0a2 100644 --- a/src/decode/lzma.rs +++ b/src/decode/lzma.rs @@ -43,7 +43,7 @@ impl LZMAParams { let lp: u32 = pb % 5; pb /= 5; - info!("Properties {{ lc: {}, lp: {}, pb: {} }}", lc, lp, pb); + lzma_info!("Properties {{ lc: {}, lp: {}, pb: {} }}", lc, lp, pb); // Dictionary let dict_size_provided = input.read_u32::().or_else(|e| { @@ -58,7 +58,7 @@ impl LZMAParams { dict_size_provided }; - info!("Dict size: {}", dict_size); + lzma_info!("Dict size: {}", dict_size); // Unpacked size let unpacked_size: Option = match options.unpacked_size { @@ -83,7 +83,7 @@ impl LZMAParams { UnpackedSize::UseProvided(x) => x, }; - info!("Unpacked size: {:?}", unpacked_size); + lzma_info!("Unpacked size: {:?}", unpacked_size); let params = LZMAParams { lc, @@ -241,7 +241,7 @@ where &mut self.is_match[(self.state << 4) + pos_state], )? { let byte: u8 = self.decode_literal(rangecoder)?; - debug!("Literal: {}", byte); + lzma_debug!("Literal: {}", byte); self.output.append_literal(byte)?; self.state = if self.state < 4 { diff --git a/src/decode/lzma2.rs b/src/decode/lzma2.rs index dad9f6d..a50b9fd 100644 --- a/src/decode/lzma2.rs +++ b/src/decode/lzma2.rs @@ -23,10 +23,10 @@ where ))) })?; - info!("LZMA2 status: {}", status); + lzma_info!("LZMA2 status: {}", status); if status == 0 { - info!("LZMA2 end of input"); + lzma_info!("LZMA2 end of input"); break; } else if status == 1 { // uncompressed reset dict @@ -97,7 +97,7 @@ where })?; let packed_size = (packed_size as u64) + 1; - info!( + lzma_info!( "LZMA2 compressed block {{ unpacked_size: {}, packed_size: {}, reset_dict: {}, reset_state: {}, reset_props: {} }}", unpacked_size, packed_size, @@ -143,7 +143,7 @@ where ))); } - info!("Properties {{ lc: {}, lp: {}, pb: {} }}", lc, lp, pb); + lzma_info!("Properties {{ lc: {}, lp: {}, pb: {} }}", lc, lp, pb); } else { lc = decoder.lc; lp = decoder.lp; @@ -182,9 +182,10 @@ where })?; let unpacked_size = (unpacked_size as usize) + 1; - info!( + lzma_info!( "LZMA2 uncompressed block {{ unpacked_size: {}, reset_dict: {} }}", - unpacked_size, reset_dict + unpacked_size, + reset_dict ); if reset_dict { diff --git a/src/decode/rangecoder.rs b/src/decode/rangecoder.rs index c4af27b..7643ea1 100644 --- a/src/decode/rangecoder.rs +++ b/src/decode/rangecoder.rs @@ -24,7 +24,7 @@ where }; let _ = dec.stream.read_u8()?; dec.code = dec.stream.read_u32::()?; - debug!("0 {{ range: {:08x}, code: {:08x} }}", dec.range, dec.code); + lzma_debug!("0 {{ range: {:08x}, code: {:08x} }}", dec.range, dec.code); Ok(dec) } @@ -35,12 +35,12 @@ where #[inline] fn normalize(&mut self) -> io::Result<()> { - trace!(" {{ range: {:08x}, code: {:08x} }}", self.range, self.code); + lzma_trace!(" {{ range: {:08x}, code: {:08x} }}", self.range, self.code); if self.range < 0x0100_0000 { self.range <<= 8; self.code = (self.code << 8) ^ (self.stream.read_u8()? as u32); - debug!("+ {{ range: {:08x}, code: {:08x} }}", self.range, self.code); + lzma_debug!("+ {{ range: {:08x}, code: {:08x} }}", self.range, self.code); } Ok(()) } @@ -70,7 +70,7 @@ where pub fn decode_bit(&mut self, prob: &mut u16) -> io::Result { let bound: u32 = (self.range >> 11) * (*prob as u32); - trace!( + lzma_trace!( " bound: {:08x}, prob: {:04x}, bit: {}", bound, prob, diff --git a/src/decode/xz.rs b/src/decode/xz.rs index 940f83b..dd5acc4 100644 --- a/src/decode/xz.rs +++ b/src/decode/xz.rs @@ -55,7 +55,7 @@ where digested.read_u16::()? }; let check_method = get_check_method(flags)?; - info!("XZ check method: {:?}", check_method); + lzma_info!("XZ check method: {:?}", check_method); let digest_crc32 = digest.sum32(); @@ -71,10 +71,10 @@ where let index_size = loop { let mut count_input = util::CountBufRead::new(input); let header_size = count_input.read_u8()?; - info!("XZ block header_size byte: 0x{:02x}", header_size); + lzma_info!("XZ block header_size byte: 0x{:02x}", header_size); if header_size == 0 { - info!("XZ records: {:?}", records); + lzma_info!("XZ records: {:?}", records); check_index(&mut count_input, &records)?; let index_size = count_input.count(); break index_size; @@ -160,7 +160,7 @@ where } for (i, record) in records.iter().enumerate() { - info!("XZ index checking record {}: {:?}", i, record); + lzma_info!("XZ index checking record {}: {:?}", i, record); let unpadded_size = get_multibyte(&mut digested)?; if unpadded_size != record.unpadded_size as u64 { @@ -183,9 +183,10 @@ where // TODO: create padding parser function let count = count_input.count(); let padding_size = ((count ^ 0x03) + 1) & 0x03; - info!( + lzma_info!( "XZ index: {} byte(s) read, {} byte(s) of padding", - count, padding_size + count, + padding_size ); { @@ -201,7 +202,7 @@ where } let digest_crc32 = digest.sum32(); - info!("XZ index checking digest 0x{:08x}", digest_crc32); + lzma_info!("XZ index checking digest 0x{:08x}", digest_crc32); let crc32 = count_input.read_u32::()?; if crc32 != digest_crc32 { @@ -294,7 +295,7 @@ where } let unpacked_size = tmpbuf.len(); - info!("XZ block decompressed to {} byte(s)", tmpbuf.len()); + lzma_info!("XZ block decompressed to {} byte(s)", tmpbuf.len()); if let Some(expected_unpacked_size) = block_header.unpacked_size { if (unpacked_size as u64) != expected_unpacked_size { @@ -307,9 +308,10 @@ where let count = count_input.count(); let padding_size = ((count ^ 0x03) + 1) & 0x03; - info!( + lzma_info!( "XZ block: {} byte(s) read, {} byte(s) of padding", - count, padding_size + count, + padding_size ); for _ in 0..padding_size { let byte = count_input.read_u8()?; @@ -395,7 +397,7 @@ where let has_packed_size = flags & 0x40 != 0; let has_unpacked_size = flags & 0x80 != 0; - info!( + lzma_info!( "XZ block header: {{ header_size: {}, flags: {}, num_filters: {}, has_packed_size: {}, has_unpacked_size: {} }}", header_size, flags, @@ -423,9 +425,10 @@ where None }; - info!( + lzma_info!( "XZ block header: {{ packed_size: {:?}, unpacked_size: {:?} }}", - packed_size, unpacked_size + packed_size, + unpacked_size ); let mut filters: Vec = vec![]; @@ -433,9 +436,10 @@ where let filter_id = get_filter_id(get_multibyte(input)?)?; let size_of_properties = get_multibyte(input)?; - info!( + lzma_info!( "XZ filter: {{ filter_id: {:?}, size_of_properties: {} }}", - filter_id, size_of_properties + filter_id, + size_of_properties ); // Early abort to avoid allocating a large vector @@ -454,7 +458,7 @@ where ))) })?; - info!("XZ filter properties: {:?}", buf); + lzma_info!("XZ filter properties: {:?}", buf); filters.push(Filter { filter_id, diff --git a/src/encode/dumbencoder.rs b/src/encode/dumbencoder.rs index 369e482..f1574c5 100644 --- a/src/encode/dumbencoder.rs +++ b/src/encode/dumbencoder.rs @@ -26,11 +26,11 @@ where // Properties let props = (LC + 9 * (LP + 5 * PB)) as u8; - info!("Properties {{ lc: {}, lp: {}, pb: {} }}", LC, LP, PB); + lzma_info!("Properties {{ lc: {}, lp: {}, pb: {} }}", LC, LP, PB); stream.write_u8(props)?; // Dictionary - info!("Dict size: {}", dict_size); + lzma_info!("Dict size: {}", dict_size); stream.write_u32::(dict_size)?; // Unpacked size @@ -38,11 +38,11 @@ where UnpackedSize::WriteToHeader(unpacked_size) => { let value: u64 = match unpacked_size { None => { - info!("Unpacked size: unknown"); + lzma_info!("Unpacked size: unknown"); 0xFFFF_FFFF_FFFF_FFFF } Some(x) => { - info!("Unpacked size: {}", x); + lzma_info!("Unpacked size: {}", x); *x } }; diff --git a/src/encode/rangecoder.rs b/src/encode/rangecoder.rs index 2fbdd07..601ecb9 100644 --- a/src/encode/rangecoder.rs +++ b/src/encode/rangecoder.rs @@ -24,7 +24,7 @@ where cache: 0, cachesz: 1, }; - debug!("0 {{ range: {:08x}, low: {:010x} }}", enc.range, enc.low); + lzma_debug!("0 {{ range: {:08x}, low: {:010x} }}", enc.range, enc.low); enc } @@ -34,7 +34,7 @@ where loop { let byte = tmp.wrapping_add((self.low >> 32) as u8); self.stream.write_u8(byte)?; - debug!("> byte: {:02x}", byte); + lzma_debug!("> byte: {:02x}", byte); tmp = 0xFF; self.cachesz -= 1; if self.cachesz == 0 { @@ -53,31 +53,37 @@ where for _ in 0..5 { self.write_low()?; - debug!("$ {{ range: {:08x}, low: {:010x} }}", self.range, self.low); + lzma_debug!("$ {{ range: {:08x}, low: {:010x} }}", self.range, self.low); } Ok(()) } fn normalize(&mut self) -> io::Result<()> { while self.range < 0x0100_0000 { - debug!( + lzma_debug!( "+ {{ range: {:08x}, low: {:010x}, cache: {:02x}, {} }}", - self.range, self.low, self.cache, self.cachesz + self.range, + self.low, + self.cache, + self.cachesz ); self.range <<= 8; self.write_low()?; - debug!( + lzma_debug!( "* {{ range: {:08x}, low: {:010x}, cache: {:02x}, {} }}", - self.range, self.low, self.cache, self.cachesz + self.range, + self.low, + self.cache, + self.cachesz ); } - trace!(" {{ range: {:08x}, low: {:010x} }}", self.range, self.low); + lzma_trace!(" {{ range: {:08x}, low: {:010x} }}", self.range, self.low); Ok(()) } pub fn encode_bit(&mut self, prob: &mut u16, bit: bool) -> io::Result<()> { let bound: u32 = (self.range >> 11) * (*prob as u32); - trace!( + lzma_trace!( " bound: {:08x}, prob: {:04x}, bit: {}", bound, prob, diff --git a/src/encode/xz.rs b/src/encode/xz.rs index 4045eec..6baaf7a 100644 --- a/src/encode/xz.rs +++ b/src/encode/xz.rs @@ -100,9 +100,10 @@ where lzma2::encode_stream(&mut count_input, &mut count_output)?; (count_output.count(), count_input.count()) }; - info!( + lzma_info!( "Unpadded size = {}, unpacked_size = {}", - unpadded_size, unpacked_size + unpadded_size, + unpacked_size ); let padding_size = ((unpadded_size ^ 0x03) + 1) & 0x03; diff --git a/src/lib.rs b/src/lib.rs index 1b7fb3f..d392c93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,12 @@ extern crate byteorder; +#[cfg(feature = "enable_logging")] #[macro_use] extern crate log; extern crate crc; +#[macro_use] +mod macros; + mod decode; mod encode; pub mod error; diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..21724ae --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,41 @@ +#[cfg(feature = "enable_logging")] +#[macro_export] +macro_rules! lzma_trace { + ($($arg:tt)+) => { + trace!($($arg)+); + } +} + +#[cfg(feature = "enable_logging")] +#[macro_export] +macro_rules! lzma_debug { + ($($arg:tt)+) => { + debug!($($arg)+); + } +} + +#[cfg(feature = "enable_logging")] +#[macro_export] +macro_rules! lzma_info { + ($($arg:tt)+) => { + info!($($arg)+); + } +} + +#[cfg(not(feature = "enable_logging"))] +#[macro_export] +macro_rules! lzma_trace { + ($($arg:tt)+) => {}; +} + +#[cfg(not(feature = "enable_logging"))] +#[macro_export] +macro_rules! lzma_debug { + ($($arg:tt)+) => {}; +} + +#[cfg(not(feature = "enable_logging"))] +#[macro_export] +macro_rules! lzma_info { + ($($arg:tt)+) => {}; +} diff --git a/tests/lzma.rs b/tests/lzma.rs index 6695868..ef54b87 100644 --- a/tests/lzma.rs +++ b/tests/lzma.rs @@ -1,13 +1,16 @@ +#[cfg(feature = "enable_logging")] extern crate env_logger; +#[macro_use] extern crate lzma_rs; +#[cfg(feature = "enable_logging")] #[macro_use] extern crate log; fn round_trip(x: &[u8]) { let mut compressed: Vec = Vec::new(); lzma_rs::lzma_compress(&mut std::io::BufReader::new(x), &mut compressed).unwrap(); - info!("Compressed {} -> {} bytes", x.len(), compressed.len()); - debug!("Compressed content: {:?}", compressed); + lzma_info!("Compressed {} -> {} bytes", x.len(), compressed.len()); + lzma_debug!("Compressed content: {:?}", compressed); let mut bf = std::io::BufReader::new(compressed.as_slice()); let mut decomp: Vec = Vec::new(); lzma_rs::lzma_decompress(&mut bf, &mut decomp).unwrap(); @@ -26,8 +29,8 @@ fn round_trip_with_options( encode_options, ) .unwrap(); - info!("Compressed {} -> {} bytes", x.len(), compressed.len()); - debug!("Compressed content: {:?}", compressed); + lzma_info!("Compressed {} -> {} bytes", x.len(), compressed.len()); + lzma_debug!("Compressed content: {:?}", compressed); let mut bf = std::io::BufReader::new(compressed.as_slice()); let mut decomp: Vec = Vec::new(); lzma_rs::lzma_decompress_with_options(&mut bf, &mut decomp, decode_options).unwrap(); @@ -70,6 +73,7 @@ fn decomp_big_file(compfile: &str, plainfile: &str) { #[test] fn decompress_short_header() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); let mut decomp: Vec = Vec::new(); // TODO: compare io::Errors? @@ -84,6 +88,7 @@ fn decompress_short_header() { #[test] fn round_trip_basics() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); round_trip(b""); // Note: we use vec! to avoid storing the slice in the binary @@ -93,12 +98,14 @@ fn round_trip_basics() { #[test] fn round_trip_hello() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); round_trip(b"Hello world"); } #[test] fn round_trip_files() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); round_trip_file("tests/files/foo.txt"); round_trip_file("tests/files/range-coder-edge-case"); @@ -106,6 +113,7 @@ fn round_trip_files() { #[test] fn big_file() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); decomp_big_file("tests/files/foo.txt.lzma", "tests/files/foo.txt"); decomp_big_file("tests/files/hugedict.txt.lzma", "tests/files/foo.txt"); @@ -117,6 +125,7 @@ fn big_file() { #[test] fn decompress_empty_world() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); let mut x: &[u8] = b"\x5d\x00\x00\x80\x00\xff\xff\xff\xff\xff\xff\xff\xff\x00\x83\xff\ \xfb\xff\xff\xc0\x00\x00\x00"; @@ -127,6 +136,7 @@ fn decompress_empty_world() { #[test] fn decompress_hello_world() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); let mut x: &[u8] = b"\x5d\x00\x00\x80\x00\xff\xff\xff\xff\xff\xff\xff\xff\x00\x24\x19\ \x49\x98\x6f\x10\x19\xc6\xd7\x31\xeb\x36\x50\xb2\x98\x48\xff\xfe\ @@ -139,6 +149,7 @@ fn decompress_hello_world() { #[test] fn decompress_huge_dict() { // Hello world with a dictionary of size 0x7F7F7F7F + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); let mut x: &[u8] = b"\x5d\x7f\x7f\x7f\x7f\xff\xff\xff\xff\xff\xff\xff\xff\x00\x24\x19\ \x49\x98\x6f\x10\x19\xc6\xd7\x31\xeb\x36\x50\xb2\x98\x48\xff\xfe\ diff --git a/tests/lzma2.rs b/tests/lzma2.rs index 0534506..38bf41f 100644 --- a/tests/lzma2.rs +++ b/tests/lzma2.rs @@ -1,14 +1,16 @@ +#[cfg(feature = "enable_logging")] extern crate env_logger; +#[macro_use] extern crate lzma_rs; - +#[cfg(feature = "enable_logging")] #[macro_use] extern crate log; fn round_trip(x: &[u8]) { let mut compressed: Vec = Vec::new(); lzma_rs::lzma2_compress(&mut std::io::BufReader::new(x), &mut compressed).unwrap(); - info!("Compressed {} -> {} bytes", x.len(), compressed.len()); - debug!("Compressed content: {:?}", compressed); + lzma_info!("Compressed {} -> {} bytes", x.len(), compressed.len()); + lzma_debug!("Compressed content: {:?}", compressed); let mut bf = std::io::BufReader::new(compressed.as_slice()); let mut decomp: Vec = Vec::new(); lzma_rs::lzma2_decompress(&mut bf, &mut decomp).unwrap(); @@ -28,6 +30,7 @@ fn round_trip_file(filename: &str) { #[test] fn round_trip_basics() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); round_trip(b""); // Note: we use vec! to avoid storing the slice in the binary @@ -37,12 +40,14 @@ fn round_trip_basics() { #[test] fn round_trip_hello() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); round_trip(b"Hello world"); } #[test] fn round_trip_files() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); round_trip_file("tests/files/foo.txt"); } diff --git a/tests/xz.rs b/tests/xz.rs index d09f437..768966f 100644 --- a/tests/xz.rs +++ b/tests/xz.rs @@ -1,14 +1,16 @@ +#[cfg(feature = "enable_logging")] extern crate env_logger; +#[macro_use] extern crate lzma_rs; - +#[cfg(feature = "enable_logging")] #[macro_use] extern crate log; fn round_trip(x: &[u8]) { let mut compressed: Vec = Vec::new(); lzma_rs::xz_compress(&mut std::io::BufReader::new(x), &mut compressed).unwrap(); - info!("Compressed {} -> {} bytes", x.len(), compressed.len()); - debug!("Compressed content: {:?}", compressed); + lzma_info!("Compressed {} -> {} bytes", x.len(), compressed.len()); + lzma_debug!("Compressed content: {:?}", compressed); let mut bf = std::io::BufReader::new(compressed.as_slice()); let mut decomp: Vec = Vec::new(); lzma_rs::xz_decompress(&mut bf, &mut decomp).unwrap(); @@ -28,6 +30,7 @@ fn round_trip_file(filename: &str) { #[test] fn round_trip_basics() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); round_trip(b""); // Note: we use vec! to avoid storing the slice in the binary @@ -37,12 +40,14 @@ fn round_trip_basics() { #[test] fn round_trip_hello() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); round_trip(b"Hello world"); } #[test] fn round_trip_files() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); round_trip_file("tests/files/foo.txt"); } @@ -63,12 +68,14 @@ fn decomp_big_file(compfile: &str, plainfile: &str) { #[test] fn big_file() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); decomp_big_file("tests/files/foo.txt.xz", "tests/files/foo.txt"); } #[test] fn decompress_empty_world() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); let mut x: &[u8] = b"\xfd\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x00\x00\x00\x00\ \x1c\xdf\x44\x21\x1f\xb6\xf3\x7d\x01\x00\x00\x00\x00\x04\x59\x5a\ @@ -80,6 +87,7 @@ fn decompress_empty_world() { #[test] fn decompress_hello_world() { + #[cfg(feature = "enable_logging")] let _ = env_logger::try_init(); let mut x: &[u8] = b"\xfd\x37\x7a\x58\x5a\x00\x00\x04\xe6\xd6\xb4\x46\x02\x00\x21\x01\ \x16\x00\x00\x00\x74\x2f\xe5\xa3\x01\x00\x0b\x48\x65\x6c\x6c\x6f\ From 1aaf727ad80b8da551384d698d03068332ae95f7 Mon Sep 17 00:00:00 2001 From: "G. Endignoux" Date: Thu, 5 Mar 2020 23:46:21 +0100 Subject: [PATCH 2/3] Blacklist clippy false positive due to empty macro. --- src/encode/rangecoder.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/encode/rangecoder.rs b/src/encode/rangecoder.rs index 601ecb9..5ab8582 100644 --- a/src/encode/rangecoder.rs +++ b/src/encode/rangecoder.rs @@ -16,6 +16,7 @@ impl<'a, W> RangeEncoder<'a, W> where W: io::Write, { + #[allow(clippy::let_and_return)] pub fn new(stream: &'a mut W) -> Self { let enc = Self { stream, From 800c3775870921b911f9ce9ceb87dec4f4929125 Mon Sep 17 00:00:00 2001 From: "G. Endignoux" Date: Thu, 5 Mar 2020 23:48:18 +0100 Subject: [PATCH 3/3] Remove benchmarks from Travis, as they require an unstable feature. --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 15e931d..d6d3298 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,5 +38,3 @@ script: - cargo build --verbose --features enable_logging - cargo test --verbose - cargo test --verbose --features enable_logging - - cargo bench --verbose - - cargo bench --verbose --features enable_logging