Skip to content

Commit

Permalink
Take the logger from test_utils into fuzz::test_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Jan 23, 2019
1 parent 1e48001 commit 0efbbd4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/chanmon_deser_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions fuzz/fuzz_targets/full_stack_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
#[cfg(feature = "afl")]
fn main() {
fuzz!(|data| {
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger{});
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger::new("".to_owned()));
do_test(data, &logger);
});
}
Expand All @@ -565,7 +565,7 @@ fn main() {
fn main() {
loop {
fuzz!(|data| {
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger{});
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger::new("".to_owned()));
do_test(data, &logger);
});
}
Expand All @@ -575,7 +575,7 @@ fn main() {
#[macro_use] extern crate libfuzzer_sys;
#[cfg(feature = "libfuzzer_fuzz")]
fuzz_target!(|data: &[u8]| {
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger{});
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger::new("".to_owned()));
do_test(data, &logger);
});

Expand All @@ -589,7 +589,7 @@ mod tests {

#[test]
fn duplicate_crash() {
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger{});
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger::new("".to_owned()));
super::do_test(&::hex::decode("00").unwrap(), &logger);
}

Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/router_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub fn do_test(data: &[u8]) {
}
}

let logger: Arc<Logger> = Arc::new(test_logger::TestLogger{});
let logger: Arc<Logger> = Arc::new(test_logger::TestLogger::new("".to_owned()));
let chain_monitor = Arc::new(DummyChainWatcher {
input: Arc::clone(&input),
});
Expand Down
15 changes: 13 additions & 2 deletions fuzz/fuzz_targets/utils/test_logger.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down

0 comments on commit 0efbbd4

Please sign in to comment.