From aa9a848f79e11e222011d24a7a272744932c95ad Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 8 Jan 2019 15:06:43 -0500 Subject: [PATCH] Take the logger from test_utils into fuzz::test_utils --- fuzz/fuzz_targets/chanmon_deser_target.rs | 2 +- fuzz/fuzz_targets/full_stack_target.rs | 8 ++++---- fuzz/fuzz_targets/router_target.rs | 2 +- fuzz/fuzz_targets/utils/test_logger.rs | 15 +++++++++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/fuzz/fuzz_targets/chanmon_deser_target.rs b/fuzz/fuzz_targets/chanmon_deser_target.rs index 9ddf52c66..fb8f0bf6f 100644 --- a/fuzz/fuzz_targets/chanmon_deser_target.rs +++ b/fuzz/fuzz_targets/chanmon_deser_target.rs @@ -30,7 +30,7 @@ impl Writer for VecWriter { #[inline] pub fn do_test(data: &[u8]) { reset_rng_state(); - let logger = Arc::new(test_logger::TestLogger{}); + let logger = Arc::new(test_logger::TestLogger::new("".to_owned())); if let Ok((latest_block_hash, monitor)) = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(data), logger.clone()) { let mut w = VecWriter(Vec::new()); monitor.write_for_disk(&mut w).unwrap(); diff --git a/fuzz/fuzz_targets/full_stack_target.rs b/fuzz/fuzz_targets/full_stack_target.rs index 9930a44d2..a4697fd93 100644 --- a/fuzz/fuzz_targets/full_stack_target.rs +++ b/fuzz/fuzz_targets/full_stack_target.rs @@ -554,7 +554,7 @@ pub fn do_test(data: &[u8], logger: &Arc) { #[cfg(feature = "afl")] fn main() { fuzz!(|data| { - let logger: Arc = Arc::new(test_logger::TestLogger{}); + let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); do_test(data, &logger); }); } @@ -565,7 +565,7 @@ fn main() { fn main() { loop { fuzz!(|data| { - let logger: Arc = Arc::new(test_logger::TestLogger{}); + let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); do_test(data, &logger); }); } @@ -575,7 +575,7 @@ fn main() { #[macro_use] extern crate libfuzzer_sys; #[cfg(feature = "libfuzzer_fuzz")] fuzz_target!(|data: &[u8]| { - let logger: Arc = Arc::new(test_logger::TestLogger{}); + let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); do_test(data, &logger); }); @@ -589,7 +589,7 @@ mod tests { #[test] fn duplicate_crash() { - let logger: Arc = Arc::new(test_logger::TestLogger{}); + let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); super::do_test(&::hex::decode("00").unwrap(), &logger); } diff --git a/fuzz/fuzz_targets/router_target.rs b/fuzz/fuzz_targets/router_target.rs index 8938deefe..3a40d3985 100644 --- a/fuzz/fuzz_targets/router_target.rs +++ b/fuzz/fuzz_targets/router_target.rs @@ -154,7 +154,7 @@ pub fn do_test(data: &[u8]) { } } - let logger: Arc = Arc::new(test_logger::TestLogger{}); + let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); let chain_monitor = Arc::new(DummyChainWatcher { input: Arc::clone(&input), }); diff --git a/fuzz/fuzz_targets/utils/test_logger.rs b/fuzz/fuzz_targets/utils/test_logger.rs index f828d0638..097d001db 100644 --- a/fuzz/fuzz_targets/utils/test_logger.rs +++ b/fuzz/fuzz_targets/utils/test_logger.rs @@ -1,11 +1,22 @@ use lightning::util::logger::{Logger, Record}; +pub struct TestLogger { + #[cfg(test)] + id: String, +} -pub struct TestLogger {} +impl TestLogger { + pub fn new(_id: String) -> TestLogger { + TestLogger { + #[cfg(test)] + id: _id + } + } +} impl Logger for TestLogger { fn log(&self, record: &Record) { #[cfg(test)] - println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args); + println!("{:<5} {} [{} : {}, {}] {}", record.level.to_string(), self.id, record.module_path, record.file, record.line, record.args); #[cfg(not(test))] let _ = format!("{}", record.args); } -- 2.39.5