mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
Take the logger from test_utils into fuzz::test_utils
This commit is contained in:
parent
9a72207a16
commit
aa9a848f79
4 changed files with 19 additions and 8 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue