From 49a9a5e309d420f421421d1f8d39c045eb4df4ff Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 19 Jan 2020 15:38:34 -0500 Subject: [PATCH] Drop individual fuzz target duplicate_crash tests for file reader Previously, in each of our fuzz tests we had a dummy test which had a hard-coded hex string which it passed into the fuzz target so that when a failing test case was found, its hex could be copied into the test and you could run cargo test to analyze the failure. However, this was somewhat unwieldy as converting large tests back and forth between hex and raw files is quite annoying. Instead, we replace each of those tests with a test in each target that looks for files in fuzz/test_cases and runs each file it finds. Since we're editing every bin target anyway, we also automate adding no_main to libfuzzer builds with #![cfg_attr]. --- fuzz/src/bin/chanmon_consistency_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/chanmon_deser_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/full_stack_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_accept_channel_target.rs | 19 +++++++++++++++++-- .../bin/msg_announcement_signatures_target.rs | 19 +++++++++++++++++-- .../bin/msg_channel_announcement_target.rs | 19 +++++++++++++++++-- .../src/bin/msg_channel_reestablish_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_channel_update_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_closing_signed_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_commitment_signed_target.rs | 19 +++++++++++++++++-- .../msg_decoded_onion_error_packet_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_error_message_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_funding_created_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_funding_locked_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_funding_signed_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_init_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_node_announcement_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_onion_hop_data_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_open_channel_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_ping_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_pong_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_revoke_and_ack_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_shutdown_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_update_add_htlc_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_update_fail_htlc_target.rs | 19 +++++++++++++++++-- .../msg_update_fail_malformed_htlc_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/msg_update_fee_target.rs | 19 +++++++++++++++++-- .../src/bin/msg_update_fulfill_htlc_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/peer_crypt_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/router_target.rs | 19 +++++++++++++++++-- fuzz/src/bin/target_template.txt | 19 +++++++++++++++++-- fuzz/src/chanmon_consistency.rs | 8 -------- fuzz/src/chanmon_deser.rs | 8 -------- fuzz/src/full_stack.rs | 6 ------ fuzz/src/msg_targets/msg_accept_channel.rs | 8 -------- .../msg_announcement_signatures.rs | 8 -------- .../msg_targets/msg_channel_announcement.rs | 8 -------- .../msg_targets/msg_channel_reestablish.rs | 8 -------- fuzz/src/msg_targets/msg_channel_update.rs | 8 -------- fuzz/src/msg_targets/msg_closing_signed.rs | 8 -------- fuzz/src/msg_targets/msg_commitment_signed.rs | 8 -------- .../msg_decoded_onion_error_packet.rs | 8 -------- fuzz/src/msg_targets/msg_error_message.rs | 8 -------- fuzz/src/msg_targets/msg_funding_created.rs | 8 -------- fuzz/src/msg_targets/msg_funding_locked.rs | 8 -------- fuzz/src/msg_targets/msg_funding_signed.rs | 8 -------- fuzz/src/msg_targets/msg_init.rs | 8 -------- fuzz/src/msg_targets/msg_node_announcement.rs | 8 -------- fuzz/src/msg_targets/msg_onion_hop_data.rs | 8 -------- fuzz/src/msg_targets/msg_open_channel.rs | 8 -------- fuzz/src/msg_targets/msg_ping.rs | 8 -------- fuzz/src/msg_targets/msg_pong.rs | 8 -------- fuzz/src/msg_targets/msg_revoke_and_ack.rs | 8 -------- fuzz/src/msg_targets/msg_shutdown.rs | 8 -------- fuzz/src/msg_targets/msg_target_template.txt | 8 -------- fuzz/src/msg_targets/msg_update_add_htlc.rs | 8 -------- fuzz/src/msg_targets/msg_update_fail_htlc.rs | 8 -------- .../msg_update_fail_malformed_htlc.rs | 8 -------- fuzz/src/msg_targets/msg_update_fee.rs | 8 -------- .../msg_targets/msg_update_fulfill_htlc.rs | 8 -------- fuzz/src/peer_crypt.rs | 8 -------- fuzz/src/router.rs | 8 -------- 62 files changed, 527 insertions(+), 308 deletions(-) diff --git a/fuzz/src/bin/chanmon_consistency_target.rs b/fuzz/src/bin/chanmon_consistency_target.rs index a4a0bf23b..a6d3ff061 100644 --- a/fuzz/src/bin/chanmon_consistency_target.rs +++ b/fuzz/src/bin/chanmon_consistency_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::chanmon_consistency::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); chanmon_consistency_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + chanmon_consistency_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/chanmon_consistency") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + chanmon_consistency_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/chanmon_deser_target.rs b/fuzz/src/bin/chanmon_deser_target.rs index 91bc66c19..91d5f1e11 100644 --- a/fuzz/src/bin/chanmon_deser_target.rs +++ b/fuzz/src/bin/chanmon_deser_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::chanmon_deser::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); chanmon_deser_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + chanmon_deser_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/chanmon_deser") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + chanmon_deser_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/full_stack_target.rs b/fuzz/src/bin/full_stack_target.rs index 4dbf0cc91..955202d24 100644 --- a/fuzz/src/bin/full_stack_target.rs +++ b/fuzz/src/bin/full_stack_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::full_stack::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); full_stack_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + full_stack_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/full_stack") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + full_stack_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_accept_channel_target.rs b/fuzz/src/bin/msg_accept_channel_target.rs index c23560110..8112ebf94 100644 --- a/fuzz/src/bin/msg_accept_channel_target.rs +++ b/fuzz/src/bin/msg_accept_channel_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_accept_channel::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_accept_channel_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_accept_channel_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_accept_channel") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_accept_channel_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_announcement_signatures_target.rs b/fuzz/src/bin/msg_announcement_signatures_target.rs index 54f3d823d..f234dadfd 100644 --- a/fuzz/src/bin/msg_announcement_signatures_target.rs +++ b/fuzz/src/bin/msg_announcement_signatures_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_announcement_signatures::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_announcement_signatures_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_announcement_signatures_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_announcement_signatures") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_announcement_signatures_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_channel_announcement_target.rs b/fuzz/src/bin/msg_channel_announcement_target.rs index 5ab797f67..a2a63643f 100644 --- a/fuzz/src/bin/msg_channel_announcement_target.rs +++ b/fuzz/src/bin/msg_channel_announcement_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_channel_announcement::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_channel_announcement_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_channel_announcement_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_channel_announcement") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_channel_announcement_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_channel_reestablish_target.rs b/fuzz/src/bin/msg_channel_reestablish_target.rs index 79b23e409..908d20676 100644 --- a/fuzz/src/bin/msg_channel_reestablish_target.rs +++ b/fuzz/src/bin/msg_channel_reestablish_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_channel_reestablish::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_channel_reestablish_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_channel_reestablish_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_channel_reestablish") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_channel_reestablish_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_channel_update_target.rs b/fuzz/src/bin/msg_channel_update_target.rs index f9dffda2d..6eb7ba190 100644 --- a/fuzz/src/bin/msg_channel_update_target.rs +++ b/fuzz/src/bin/msg_channel_update_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_channel_update::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_channel_update_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_channel_update_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_channel_update") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_channel_update_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_closing_signed_target.rs b/fuzz/src/bin/msg_closing_signed_target.rs index eee7145c7..3377ffd6a 100644 --- a/fuzz/src/bin/msg_closing_signed_target.rs +++ b/fuzz/src/bin/msg_closing_signed_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_closing_signed::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_closing_signed_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_closing_signed_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_closing_signed") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_closing_signed_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_commitment_signed_target.rs b/fuzz/src/bin/msg_commitment_signed_target.rs index 6ce13f47b..a9cef5fe2 100644 --- a/fuzz/src/bin/msg_commitment_signed_target.rs +++ b/fuzz/src/bin/msg_commitment_signed_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_commitment_signed::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_commitment_signed_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_commitment_signed_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_commitment_signed") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_commitment_signed_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_decoded_onion_error_packet_target.rs b/fuzz/src/bin/msg_decoded_onion_error_packet_target.rs index c5c9d4a53..cefcf06bd 100644 --- a/fuzz/src/bin/msg_decoded_onion_error_packet_target.rs +++ b/fuzz/src/bin/msg_decoded_onion_error_packet_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_decoded_onion_error_packet::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_decoded_onion_error_packet_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_decoded_onion_error_packet_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_decoded_onion_error_packet") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_decoded_onion_error_packet_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_error_message_target.rs b/fuzz/src/bin/msg_error_message_target.rs index 1fa04d961..c8706d21a 100644 --- a/fuzz/src/bin/msg_error_message_target.rs +++ b/fuzz/src/bin/msg_error_message_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_error_message::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_error_message_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_error_message_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_error_message") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_error_message_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_funding_created_target.rs b/fuzz/src/bin/msg_funding_created_target.rs index e9fedc3ce..f51caf57e 100644 --- a/fuzz/src/bin/msg_funding_created_target.rs +++ b/fuzz/src/bin/msg_funding_created_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_funding_created::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_funding_created_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_funding_created_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_funding_created") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_funding_created_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_funding_locked_target.rs b/fuzz/src/bin/msg_funding_locked_target.rs index 3665ce995..14954096a 100644 --- a/fuzz/src/bin/msg_funding_locked_target.rs +++ b/fuzz/src/bin/msg_funding_locked_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_funding_locked::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_funding_locked_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_funding_locked_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_funding_locked") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_funding_locked_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_funding_signed_target.rs b/fuzz/src/bin/msg_funding_signed_target.rs index 057cc6fe6..dcd5dd9d9 100644 --- a/fuzz/src/bin/msg_funding_signed_target.rs +++ b/fuzz/src/bin/msg_funding_signed_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_funding_signed::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_funding_signed_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_funding_signed_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_funding_signed") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_funding_signed_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_init_target.rs b/fuzz/src/bin/msg_init_target.rs index 0bcbeda10..4dd75f2e3 100644 --- a/fuzz/src/bin/msg_init_target.rs +++ b/fuzz/src/bin/msg_init_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_init::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_init_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_init_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_init") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_init_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_node_announcement_target.rs b/fuzz/src/bin/msg_node_announcement_target.rs index e3dde9fb6..ae778b679 100644 --- a/fuzz/src/bin/msg_node_announcement_target.rs +++ b/fuzz/src/bin/msg_node_announcement_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_node_announcement::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_node_announcement_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_node_announcement_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_node_announcement") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_node_announcement_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_onion_hop_data_target.rs b/fuzz/src/bin/msg_onion_hop_data_target.rs index ea2b6e4d4..95453bc95 100644 --- a/fuzz/src/bin/msg_onion_hop_data_target.rs +++ b/fuzz/src/bin/msg_onion_hop_data_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_onion_hop_data::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_onion_hop_data_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_onion_hop_data_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_onion_hop_data") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_onion_hop_data_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_open_channel_target.rs b/fuzz/src/bin/msg_open_channel_target.rs index 690db561e..fa385e564 100644 --- a/fuzz/src/bin/msg_open_channel_target.rs +++ b/fuzz/src/bin/msg_open_channel_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_open_channel::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_open_channel_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_open_channel_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_open_channel") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_open_channel_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_ping_target.rs b/fuzz/src/bin/msg_ping_target.rs index 871c8e147..e8b0a5983 100644 --- a/fuzz/src/bin/msg_ping_target.rs +++ b/fuzz/src/bin/msg_ping_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_ping::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_ping_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_ping_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_ping") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_ping_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_pong_target.rs b/fuzz/src/bin/msg_pong_target.rs index c4fc46167..f7408ec52 100644 --- a/fuzz/src/bin/msg_pong_target.rs +++ b/fuzz/src/bin/msg_pong_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_pong::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_pong_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_pong_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_pong") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_pong_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_revoke_and_ack_target.rs b/fuzz/src/bin/msg_revoke_and_ack_target.rs index 2c844c2aa..47f125a44 100644 --- a/fuzz/src/bin/msg_revoke_and_ack_target.rs +++ b/fuzz/src/bin/msg_revoke_and_ack_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_revoke_and_ack::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_revoke_and_ack_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_revoke_and_ack_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_revoke_and_ack") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_revoke_and_ack_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_shutdown_target.rs b/fuzz/src/bin/msg_shutdown_target.rs index ea1678ce2..fb400f773 100644 --- a/fuzz/src/bin/msg_shutdown_target.rs +++ b/fuzz/src/bin/msg_shutdown_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_shutdown::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_shutdown_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_shutdown_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_shutdown") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_shutdown_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_update_add_htlc_target.rs b/fuzz/src/bin/msg_update_add_htlc_target.rs index cc8f67306..e433a4468 100644 --- a/fuzz/src/bin/msg_update_add_htlc_target.rs +++ b/fuzz/src/bin/msg_update_add_htlc_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_update_add_htlc::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_update_add_htlc_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_update_add_htlc_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_update_add_htlc") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_update_add_htlc_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_update_fail_htlc_target.rs b/fuzz/src/bin/msg_update_fail_htlc_target.rs index 5099fed19..ee8bb3af1 100644 --- a/fuzz/src/bin/msg_update_fail_htlc_target.rs +++ b/fuzz/src/bin/msg_update_fail_htlc_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_update_fail_htlc::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_update_fail_htlc_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_update_fail_htlc_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_update_fail_htlc") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_update_fail_htlc_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs b/fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs index 9eea92797..06eb31d32 100644 --- a/fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs +++ b/fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_update_fail_malformed_htlc::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_update_fail_malformed_htlc_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_update_fail_malformed_htlc_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_update_fail_malformed_htlc") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_update_fail_malformed_htlc_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_update_fee_target.rs b/fuzz/src/bin/msg_update_fee_target.rs index 50a96aa0b..12e5c384f 100644 --- a/fuzz/src/bin/msg_update_fee_target.rs +++ b/fuzz/src/bin/msg_update_fee_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_update_fee::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_update_fee_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_update_fee_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_update_fee") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_update_fee_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/msg_update_fulfill_htlc_target.rs b/fuzz/src/bin/msg_update_fulfill_htlc_target.rs index 35bf38e9a..a5a8bda33 100644 --- a/fuzz/src/bin/msg_update_fulfill_htlc_target.rs +++ b/fuzz/src/bin/msg_update_fulfill_htlc_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::msg_targets::msg_update_fulfill_htlc::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); msg_update_fulfill_htlc_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + msg_update_fulfill_htlc_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/msg_update_fulfill_htlc") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + msg_update_fulfill_htlc_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/peer_crypt_target.rs b/fuzz/src/bin/peer_crypt_target.rs index 8c1f7b018..b32854f05 100644 --- a/fuzz/src/bin/peer_crypt_target.rs +++ b/fuzz/src/bin/peer_crypt_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::peer_crypt::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); peer_crypt_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + peer_crypt_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/peer_crypt") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + peer_crypt_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/router_target.rs b/fuzz/src/bin/router_target.rs index 9b26a176b..3e82b196a 100644 --- a/fuzz/src/bin/router_target.rs +++ b/fuzz/src/bin/router_target.rs @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::router::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); router_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + router_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/router") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + router_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/bin/target_template.txt b/fuzz/src/bin/target_template.txt index 3ebb480df..9815e9ccc 100644 --- a/fuzz/src/bin/target_template.txt +++ b/fuzz/src/bin/target_template.txt @@ -1,12 +1,12 @@ // This file is auto-generated by gen_target.sh based on target_template.txt // To modify it, modify target_template.txt and run gen_target.sh instead. -//Uncomment this for libfuzzer builds: -//#![no_main] +#![cfg_attr(feature = "libfuzzer_fuzz", no_main)] extern crate lightning_fuzz; use lightning_fuzz::TARGET_MOD::*; +use std::fs; use std::io::Read; #[cfg(feature = "afl")] @@ -42,3 +42,18 @@ fn main() { std::io::stdin().read_to_end(&mut data).unwrap(); TARGET_NAME_run(data.as_ptr(), data.len()); } + +#[test] +fn run_test_cases() { + let mut data: Vec = vec![0]; + TARGET_NAME_run(data.as_ptr(), data.len()); + if let Ok(tests) = fs::read_dir("test_cases/TARGET_NAME") { + for test in tests { + data.clear(); + let path = test.unwrap().path(); + println!("Running test {}...", path.file_name().unwrap().to_str().unwrap()); + fs::File::open(path).unwrap().read_to_end(&mut data).unwrap(); + TARGET_NAME_run(data.as_ptr(), data.len()); + } + } +} diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index c2f4ebf47..95def807b 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -791,11 +791,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn chanmon_consistency_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/chanmon_deser.rs b/fuzz/src/chanmon_deser.rs index 5dde4a2ea..5d15f718f 100644 --- a/fuzz/src/chanmon_deser.rs +++ b/fuzz/src/chanmon_deser.rs @@ -40,11 +40,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn chanmon_deser_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index c7d1d1686..4d1bf5e0b 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -542,12 +542,6 @@ mod tests { use std::collections::HashMap; use std::sync::{Arc, Mutex}; - #[test] - fn duplicate_crash() { - let logger: Arc = Arc::new(test_logger::TestLogger::new("".to_owned())); - super::do_test(&::hex::decode("00").unwrap(), &logger); - } - struct TrackingLogger { /// (module, message) -> count pub lines: Mutex>, diff --git a/fuzz/src/msg_targets/msg_accept_channel.rs b/fuzz/src/msg_targets/msg_accept_channel.rs index 04e3cc245..94baec595 100644 --- a/fuzz/src/msg_targets/msg_accept_channel.rs +++ b/fuzz/src/msg_targets/msg_accept_channel.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_accept_channel_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_announcement_signatures.rs b/fuzz/src/msg_targets/msg_announcement_signatures.rs index 1df6aeca3..065295b9e 100644 --- a/fuzz/src/msg_targets/msg_announcement_signatures.rs +++ b/fuzz/src/msg_targets/msg_announcement_signatures.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_announcement_signatures_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_channel_announcement.rs b/fuzz/src/msg_targets/msg_channel_announcement.rs index 9e2363eab..dafcdafed 100644 --- a/fuzz/src/msg_targets/msg_channel_announcement.rs +++ b/fuzz/src/msg_targets/msg_channel_announcement.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_channel_announcement_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_channel_reestablish.rs b/fuzz/src/msg_targets/msg_channel_reestablish.rs index a81f0aebf..8d05450e7 100644 --- a/fuzz/src/msg_targets/msg_channel_reestablish.rs +++ b/fuzz/src/msg_targets/msg_channel_reestablish.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_channel_reestablish_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_channel_update.rs b/fuzz/src/msg_targets/msg_channel_update.rs index aaef33ea2..0d3edfe88 100644 --- a/fuzz/src/msg_targets/msg_channel_update.rs +++ b/fuzz/src/msg_targets/msg_channel_update.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_channel_update_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_closing_signed.rs b/fuzz/src/msg_targets/msg_closing_signed.rs index 9a959d58c..8043d9de0 100644 --- a/fuzz/src/msg_targets/msg_closing_signed.rs +++ b/fuzz/src/msg_targets/msg_closing_signed.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_closing_signed_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_commitment_signed.rs b/fuzz/src/msg_targets/msg_commitment_signed.rs index e84c98714..319f46c59 100644 --- a/fuzz/src/msg_targets/msg_commitment_signed.rs +++ b/fuzz/src/msg_targets/msg_commitment_signed.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_commitment_signed_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_decoded_onion_error_packet.rs b/fuzz/src/msg_targets/msg_decoded_onion_error_packet.rs index e49d22b3a..d6e5a829d 100644 --- a/fuzz/src/msg_targets/msg_decoded_onion_error_packet.rs +++ b/fuzz/src/msg_targets/msg_decoded_onion_error_packet.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_decoded_onion_error_packet_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_error_message.rs b/fuzz/src/msg_targets/msg_error_message.rs index 6b5bcccf2..16594953e 100644 --- a/fuzz/src/msg_targets/msg_error_message.rs +++ b/fuzz/src/msg_targets/msg_error_message.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_error_message_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_funding_created.rs b/fuzz/src/msg_targets/msg_funding_created.rs index 8e468a85a..cc322cbb0 100644 --- a/fuzz/src/msg_targets/msg_funding_created.rs +++ b/fuzz/src/msg_targets/msg_funding_created.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_funding_created_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_funding_locked.rs b/fuzz/src/msg_targets/msg_funding_locked.rs index 29e9c8a6a..a546ed8bb 100644 --- a/fuzz/src/msg_targets/msg_funding_locked.rs +++ b/fuzz/src/msg_targets/msg_funding_locked.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_funding_locked_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_funding_signed.rs b/fuzz/src/msg_targets/msg_funding_signed.rs index 412558fe9..0210b5ec6 100644 --- a/fuzz/src/msg_targets/msg_funding_signed.rs +++ b/fuzz/src/msg_targets/msg_funding_signed.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_funding_signed_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_init.rs b/fuzz/src/msg_targets/msg_init.rs index dbc074585..52b92acd0 100644 --- a/fuzz/src/msg_targets/msg_init.rs +++ b/fuzz/src/msg_targets/msg_init.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_init_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_node_announcement.rs b/fuzz/src/msg_targets/msg_node_announcement.rs index 95de73ba7..bb09f87e7 100644 --- a/fuzz/src/msg_targets/msg_node_announcement.rs +++ b/fuzz/src/msg_targets/msg_node_announcement.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_node_announcement_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_onion_hop_data.rs b/fuzz/src/msg_targets/msg_onion_hop_data.rs index 7db90a690..9d7ad6025 100644 --- a/fuzz/src/msg_targets/msg_onion_hop_data.rs +++ b/fuzz/src/msg_targets/msg_onion_hop_data.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_onion_hop_data_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_open_channel.rs b/fuzz/src/msg_targets/msg_open_channel.rs index 2688b4181..9c700c2b2 100644 --- a/fuzz/src/msg_targets/msg_open_channel.rs +++ b/fuzz/src/msg_targets/msg_open_channel.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_open_channel_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_ping.rs b/fuzz/src/msg_targets/msg_ping.rs index 21b74ad9f..67e2382f0 100644 --- a/fuzz/src/msg_targets/msg_ping.rs +++ b/fuzz/src/msg_targets/msg_ping.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_ping_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_pong.rs b/fuzz/src/msg_targets/msg_pong.rs index c8fc4c59d..cec5c5adf 100644 --- a/fuzz/src/msg_targets/msg_pong.rs +++ b/fuzz/src/msg_targets/msg_pong.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_pong_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_revoke_and_ack.rs b/fuzz/src/msg_targets/msg_revoke_and_ack.rs index ca5412f5c..6df64e3e4 100644 --- a/fuzz/src/msg_targets/msg_revoke_and_ack.rs +++ b/fuzz/src/msg_targets/msg_revoke_and_ack.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_revoke_and_ack_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_shutdown.rs b/fuzz/src/msg_targets/msg_shutdown.rs index c249ffcec..d70d9a6a7 100644 --- a/fuzz/src/msg_targets/msg_shutdown.rs +++ b/fuzz/src/msg_targets/msg_shutdown.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_shutdown_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_target_template.txt b/fuzz/src/msg_targets/msg_target_template.txt index 6877918a5..ea785ff4e 100644 --- a/fuzz/src/msg_targets/msg_target_template.txt +++ b/fuzz/src/msg_targets/msg_target_template.txt @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn TARGET_NAME_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_update_add_htlc.rs b/fuzz/src/msg_targets/msg_update_add_htlc.rs index 960399abb..13b648f0a 100644 --- a/fuzz/src/msg_targets/msg_update_add_htlc.rs +++ b/fuzz/src/msg_targets/msg_update_add_htlc.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_update_add_htlc_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_update_fail_htlc.rs b/fuzz/src/msg_targets/msg_update_fail_htlc.rs index 8eb2870d3..e21d2146c 100644 --- a/fuzz/src/msg_targets/msg_update_fail_htlc.rs +++ b/fuzz/src/msg_targets/msg_update_fail_htlc.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_update_fail_htlc_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_update_fail_malformed_htlc.rs b/fuzz/src/msg_targets/msg_update_fail_malformed_htlc.rs index 4d1ab282f..e27b85281 100644 --- a/fuzz/src/msg_targets/msg_update_fail_malformed_htlc.rs +++ b/fuzz/src/msg_targets/msg_update_fail_malformed_htlc.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_update_fail_malformed_htlc_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_update_fee.rs b/fuzz/src/msg_targets/msg_update_fee.rs index 8d3bb8941..5051bb87d 100644 --- a/fuzz/src/msg_targets/msg_update_fee.rs +++ b/fuzz/src/msg_targets/msg_update_fee.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_update_fee_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/msg_targets/msg_update_fulfill_htlc.rs b/fuzz/src/msg_targets/msg_update_fulfill_htlc.rs index ab7277084..b8b3d98a9 100644 --- a/fuzz/src/msg_targets/msg_update_fulfill_htlc.rs +++ b/fuzz/src/msg_targets/msg_update_fulfill_htlc.rs @@ -14,11 +14,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn msg_update_fulfill_htlc_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} diff --git a/fuzz/src/peer_crypt.rs b/fuzz/src/peer_crypt.rs index 8e6164464..e0ff02f04 100644 --- a/fuzz/src/peer_crypt.rs +++ b/fuzz/src/peer_crypt.rs @@ -79,11 +79,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn peer_crypt_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("01").unwrap()); - } -} diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index 075c900ab..b0d7b6031 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -237,11 +237,3 @@ pub fn do_test(data: &[u8]) { pub extern "C" fn router_run(data: *const u8, datalen: usize) { do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); } - -#[cfg(test)] -mod tests { - #[test] - fn duplicate_crash() { - super::do_test(&::hex::decode("00").unwrap()); - } -} -- 2.39.5