]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Thread fuzz test cases 2020-04-par-fuzz-check
authorMatt Corallo <git@bluematt.me>
Fri, 21 Feb 2020 01:11:40 +0000 (20:11 -0500)
committerMatt Corallo <git@bluematt.me>
Fri, 24 Apr 2020 20:06:34 +0000 (16:06 -0400)
Adds threading (with logger capture) to fuzz targets so that we can
more effeciently test a failing fuzz corpus on new code changes.

66 files changed:
fuzz/Cargo.toml
fuzz/src/bin/chanmon_consistency_target.rs
fuzz/src/bin/chanmon_deser_target.rs
fuzz/src/bin/full_stack_target.rs
fuzz/src/bin/msg_accept_channel_target.rs
fuzz/src/bin/msg_announcement_signatures_target.rs
fuzz/src/bin/msg_channel_announcement_target.rs
fuzz/src/bin/msg_channel_reestablish_target.rs
fuzz/src/bin/msg_channel_update_target.rs
fuzz/src/bin/msg_closing_signed_target.rs
fuzz/src/bin/msg_commitment_signed_target.rs
fuzz/src/bin/msg_decoded_onion_error_packet_target.rs
fuzz/src/bin/msg_error_message_target.rs
fuzz/src/bin/msg_funding_created_target.rs
fuzz/src/bin/msg_funding_locked_target.rs
fuzz/src/bin/msg_funding_signed_target.rs
fuzz/src/bin/msg_init_target.rs
fuzz/src/bin/msg_node_announcement_target.rs
fuzz/src/bin/msg_onion_hop_data_target.rs
fuzz/src/bin/msg_open_channel_target.rs
fuzz/src/bin/msg_ping_target.rs
fuzz/src/bin/msg_pong_target.rs
fuzz/src/bin/msg_revoke_and_ack_target.rs
fuzz/src/bin/msg_shutdown_target.rs
fuzz/src/bin/msg_update_add_htlc_target.rs
fuzz/src/bin/msg_update_fail_htlc_target.rs
fuzz/src/bin/msg_update_fail_malformed_htlc_target.rs
fuzz/src/bin/msg_update_fee_target.rs
fuzz/src/bin/msg_update_fulfill_htlc_target.rs
fuzz/src/bin/peer_crypt_target.rs
fuzz/src/bin/router_target.rs
fuzz/src/bin/target_template.txt
fuzz/src/chanmon_consistency.rs
fuzz/src/chanmon_deser.rs
fuzz/src/full_stack.rs
fuzz/src/lib.rs
fuzz/src/msg_targets/msg_accept_channel.rs
fuzz/src/msg_targets/msg_announcement_signatures.rs
fuzz/src/msg_targets/msg_channel_announcement.rs
fuzz/src/msg_targets/msg_channel_reestablish.rs
fuzz/src/msg_targets/msg_channel_update.rs
fuzz/src/msg_targets/msg_closing_signed.rs
fuzz/src/msg_targets/msg_commitment_signed.rs
fuzz/src/msg_targets/msg_decoded_onion_error_packet.rs
fuzz/src/msg_targets/msg_error_message.rs
fuzz/src/msg_targets/msg_funding_created.rs
fuzz/src/msg_targets/msg_funding_locked.rs
fuzz/src/msg_targets/msg_funding_signed.rs
fuzz/src/msg_targets/msg_init.rs
fuzz/src/msg_targets/msg_node_announcement.rs
fuzz/src/msg_targets/msg_onion_hop_data.rs
fuzz/src/msg_targets/msg_open_channel.rs
fuzz/src/msg_targets/msg_ping.rs
fuzz/src/msg_targets/msg_pong.rs
fuzz/src/msg_targets/msg_revoke_and_ack.rs
fuzz/src/msg_targets/msg_shutdown.rs
fuzz/src/msg_targets/msg_target_template.txt
fuzz/src/msg_targets/msg_update_add_htlc.rs
fuzz/src/msg_targets/msg_update_fail_htlc.rs
fuzz/src/msg_targets/msg_update_fail_malformed_htlc.rs
fuzz/src/msg_targets/msg_update_fee.rs
fuzz/src/msg_targets/msg_update_fulfill_htlc.rs
fuzz/src/peer_crypt.rs
fuzz/src/router.rs
fuzz/src/utils/mod.rs
fuzz/src/utils/test_logger.rs

index 1cb7a8d6d925610e927b3c261ffbaa070dfd6131..5e3197f8f8f1929c1c35270dd872f6f964130bca 100644 (file)
@@ -37,6 +37,10 @@ members = ["."]
 lto = true
 codegen-units = 1
 
+# When testing a large fuzz corpus, -O1 offers a nice speedup
+[profile.dev]
+opt-level = 1
+
 [lib]
 name = "lightning_fuzz"
 path = "src/lib.rs"
index a6d3ff061abe615761f9747036ac32db669fd25b..845503da1a4827171b80f7c61181d84ed4186522 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       chanmon_consistency_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               chanmon_consistency_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/chanmon_consistency") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               chanmon_consistency_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 91d5f1e113d67029fec1b5eaa0426054e0e6db55..1677721b2ce641d369171e36d79714d71bd57e2b 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       chanmon_deser_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               chanmon_deser_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/chanmon_deser") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               chanmon_deser_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 955202d24ebb0a8adc4dafd272ae66c352d3f34f..94da2888fa8a6da5f8e8e59893daafbff7381b93 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       full_stack_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               full_stack_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/full_stack") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               full_stack_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 8112ebf947c59b006ef7272c2a7b5c30b9ef8d4a..f7bfc10d0d68898ffb2f9bba556561cdbcc428b8 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_accept_channel_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_accept_channel_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_accept_channel") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_accept_channel_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index f234dadfda7dbcb040cf816fabb37591a7a0cd50..63c6407eb26587b414306d57bf5d18f2431b3f3a 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_announcement_signatures_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_announcement_signatures_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_announcement_signatures") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_announcement_signatures_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index a2a63643f15ed813f90c6dc8fd57a4e6acbb57f5..8aae2770234a515bf0daf12ab84a68f8e2a3fd0c 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_channel_announcement_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_channel_announcement_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_channel_announcement") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_channel_announcement_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 908d20676329df58e8536a73b6c3ec1b32e0cffe..fb5e4774b8c0f80db1cd0d77251286c22dc37409 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_channel_reestablish_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_channel_reestablish_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_channel_reestablish") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_channel_reestablish_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 6eb7ba190c440169e2911f7b50fcb66a2ed701b6..78c6404f37c345ca4a53d91a7ca9b7f130065256 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_channel_update_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_channel_update_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_channel_update") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_channel_update_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 3377ffd6afb3ee38bdf307f22d6f9aa654eca7ac..97b49ca8d49aa2d8ea2ecb1d7959334e7d9ea8b2 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_closing_signed_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_closing_signed_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_closing_signed") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_closing_signed_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index a9cef5fe25a903b8c422f8ba2ccb068fb89699ad..a343e45f7d1bf0f5b9286dafe1ddae3047634f55 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_commitment_signed_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_commitment_signed_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_commitment_signed") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_commitment_signed_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index cefcf06bd60ffc1ef39de43ce85f8118e4dbabee..26e26fac9ba2388465c4217e6627e7406b5c5667 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_decoded_onion_error_packet_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_decoded_onion_error_packet_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_decoded_onion_error_packet") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_decoded_onion_error_packet_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index c8706d21a5ae7dfcbef16f07d3db329864f9a824..34facca3fa95816f8dfdae4fe110555b981d9a6b 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_error_message_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_error_message_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_error_message") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_error_message_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index f51caf57e7e913175b7021eca2bed2ae44a0d007..602f99067a011cc8f15b1e5e816514fad481a50c 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_funding_created_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_funding_created_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_funding_created") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_funding_created_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 14954096a119450265135c8b3c976a569b0dc3a4..ee44753de9847cd4d881f355669079058a355ed1 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_funding_locked_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_funding_locked_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_funding_locked") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_funding_locked_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index dcd5dd9d9c7228976ea0a25b3ab6e1979b41e0cc..d61da65fa655e275b2abd0a2322d4b1354ada505 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_funding_signed_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_funding_signed_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_funding_signed") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_funding_signed_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 4dd75f2e3412a6e957e691cdfc15665f57260040..62b4e4159d82848528e44559eb925fe17b1545e6 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_init_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_init_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_init") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_init_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index ae778b679d74c2a0f7a60ffae89771b8e37a80eb..4605f9495a847c07afd79c5aa618b9f9bed4aaf9 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_node_announcement_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_node_announcement_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_node_announcement") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_node_announcement_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 95453bc954a05873e6fe6e1b9c8d28d4d73e63a5..1dcb5c7d550b56bbf10e63d974e7fbbbf92fb9b9 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_onion_hop_data_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_onion_hop_data_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_onion_hop_data") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_onion_hop_data_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index fa385e564586b12368c42c5f5be5c936c5e6515c..96fed7f33030accaee3ee12debb37920176aef59 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_open_channel_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_open_channel_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_open_channel") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_open_channel_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index e8b0a5983aa3b445abc4fc2ca3c8520e02fcab63..cf2cacf2dcbe63ea4a018f5883b8b5f7dbb909b5 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_ping_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_ping_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_ping") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_ping_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index f7408ec52f297dd795b3aebd7083854bf7c04a47..c538d1383f22ce6a4369e25db330f3c1b6cbe947 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_pong_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_pong_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_pong") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_pong_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 47f125a44af46b7d2b74cd0e843cfae566248dc8..08fe92a2ad3c759aed9938d442bb2b4956617323 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_revoke_and_ack_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_revoke_and_ack_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_revoke_and_ack") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_revoke_and_ack_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index fb400f7730ea2e02de5bcc8a636ee069f41c90a5..647e7cc7be39530c81a4b546138ba837f6e9bcc1 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_shutdown_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_shutdown_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_shutdown") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_shutdown_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index e433a4468f0ac17aa339d5fb80827c04ca417532..abb749a68d36f32ba4846933dee688d7d09d7e1f 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_update_add_htlc_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_update_add_htlc_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_update_add_htlc") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_update_add_htlc_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index ee8bb3af1726ed0d9d5c384e204dbc8686364d47..278df1fe822b74fff883a798383b1de333a9e617 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_update_fail_htlc_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_update_fail_htlc_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_update_fail_htlc") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_update_fail_htlc_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 06eb31d32a789493d1380b077a0f5b0a927d3430..8c6b1e998e976efa675b9c0cfbecf5ec1714f67b 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_update_fail_malformed_htlc_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_update_fail_malformed_htlc_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_update_fail_malformed_htlc") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_update_fail_malformed_htlc_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 12e5c384f555277830cee5fa6ff89511c7917480..2b01b2b6b7cfab3b670de5cadc8c86609e21611e 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_update_fee_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_update_fee_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_update_fee") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_update_fee_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index a5a8bda338aacc871e8b663d4a973ab2ea0a9380..dbe56d7b57b2858054025bd898b29c84062075ae 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       msg_update_fulfill_htlc_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_update_fulfill_htlc_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/msg_update_fulfill_htlc") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_update_fulfill_htlc_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index b32854f051e25ddab9e88aa267d35353c4c65533..f68eaf1b28b004a1371517b64c8b49954aabb884 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       peer_crypt_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               peer_crypt_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/peer_crypt") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               peer_crypt_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 3e82b196a46415f2955402b326cf42d6571bf58a..8ab074b58353db9cf2935edd2c1f644f0ca0b464 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       router_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               router_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/router") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               router_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 9815e9ccc29c50b62e9af900fb631bece38332fc..ae2130a9cc2c314fb9fea28bf44578a3be33e1a7 100644 (file)
@@ -45,15 +45,48 @@ fn main() {
 
 #[test]
 fn run_test_cases() {
-       let mut data: Vec<u8> = vec![0];
-       TARGET_NAME_run(data.as_ptr(), data.len());
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               TARGET_NAME_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
        if let Ok(tests) = fs::read_dir("test_cases/TARGET_NAME") {
                for test in tests {
-                       data.clear();
+                       let mut data: Vec<u8> = Vec::new();
                        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());
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               TARGET_NAME_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("Output of {}:\n{}", test, output);
+                       panic!();
                }
        }
 }
index 3d14808b0160471ae04f6eb11ef677ada8a96393..c524eab400ee5d005f0849cd598d72b83a1ed369 100644 (file)
@@ -180,13 +180,13 @@ impl KeysInterface for KeyProvider {
 }
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
        let fee_est = Arc::new(FuzzEstimator{});
        let broadcast = Arc::new(TestBroadcaster{});
 
        macro_rules! make_node {
                ($node_id: expr) => { {
-                       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new($node_id.to_string()));
+                       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new($node_id.to_string(), out.clone()));
                        let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger)));
                        let monitor = Arc::new(TestChannelMonitor::new(watch.clone(), broadcast.clone(), logger.clone(), fee_est.clone()));
 
@@ -202,7 +202,7 @@ pub fn do_test(data: &[u8]) {
 
        macro_rules! reload_node {
                ($ser: expr, $node_id: expr, $old_monitors: expr) => { {
-                       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new($node_id.to_string()));
+                       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new($node_id.to_string(), out.clone()));
                        let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger)));
                        let monitor = Arc::new(TestChannelMonitor::new(watch.clone(), broadcast.clone(), logger.clone(), fee_est.clone()));
 
@@ -794,7 +794,11 @@ pub fn do_test(data: &[u8]) {
        }
 }
 
+pub fn chanmon_consistency_test<Out: test_logger::Output>(data: &[u8], out: Out) {
+       do_test(data, out);
+}
+
 #[no_mangle]
 pub extern "C" fn chanmon_consistency_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull{});
 }
index c9042dd41dd089f0e28180731c5f7df12abe83bf..cd8f7cde800a05b571257d253f197fb385ebe20e 100644 (file)
@@ -24,8 +24,8 @@ impl Writer for VecWriter {
 }
 
 #[inline]
-pub fn do_test(data: &[u8]) {
-       let logger = Arc::new(test_logger::TestLogger::new("".to_owned()));
+pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
+       let logger = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
        if let Ok((latest_block_hash, monitor)) = <(Sha256dHash, channelmonitor::ChannelMonitor<EnforcingChannelKeys>)>::read(&mut Cursor::new(data), logger.clone()) {
                let mut w = VecWriter(Vec::new());
                monitor.write_for_disk(&mut w).unwrap();
@@ -37,7 +37,11 @@ pub fn do_test(data: &[u8]) {
        }
 }
 
+pub fn chanmon_deser_test<Out: test_logger::Output>(data: &[u8], out: Out) {
+       do_test(data, out);
+}
+
 #[no_mangle]
 pub extern "C" fn chanmon_deser_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull{});
 }
index be2e0401bdf664cf9a55aceed33ec7d205259c90..c759094306a8e3df666963d4050c11f3fa55bb82 100644 (file)
@@ -561,15 +561,19 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
        }
 }
 
+pub fn full_stack_test<Out: test_logger::Output>(data: &[u8], out: Out) {
+       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
+       do_test(data, &logger);
+}
+
 #[no_mangle]
 pub extern "C" fn full_stack_run(data: *const u8, datalen: usize) {
-       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned()));
+       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned(), test_logger::DevNull {}));
        do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, &logger);
 }
 
 #[cfg(test)]
 mod tests {
-       use utils::test_logger;
        use lightning::util::logger::{Logger, Record};
        use std::collections::HashMap;
        use std::sync::{Arc, Mutex};
index fde5316cfebbb483a36b1f34097cd4db2965c8e0..f87c7511c13c26469b3502c3746d97e4e57d9716 100644 (file)
@@ -4,7 +4,7 @@ extern crate lightning;
 extern crate secp256k1;
 extern crate hex;
 
-mod utils;
+pub mod utils;
 
 pub mod chanmon_deser;
 pub mod chanmon_consistency;
index 94baec595e0a1b9891c959483a742d78751fcb70..0844b77f429df8b62ac505c86cd3a1ee94047a72 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_accept_channel_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::AcceptChannel, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_accept_channel_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::AcceptChannel, data);
 }
index 065295b9e12a9f17d2bff2afbf81009b672214ae..d9a1f0eaac671722b1f718a4483a227f56e0a342 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_announcement_signatures_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::AnnouncementSignatures, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_announcement_signatures_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::AnnouncementSignatures, data);
 }
index dafcdafed8278ba20af488e757b17bc1354ae2c6..073179304abb18bd98e333de95d1c9bccd8be319 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_channel_announcement_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg_exact!(msgs::ChannelAnnouncement, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_channel_announcement_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_exact!(msgs::ChannelAnnouncement, data);
 }
index 8d05450e7e5444551993b8014147ecec3a14a438..880bfe8be4e64dd3c0f39069ee68549c565b0031 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_channel_reestablish_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::ChannelReestablish, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_channel_reestablish_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::ChannelReestablish, data);
 }
index 0d3edfe88553b38b6288f18cc017e2a9e6de77d7..d0326bfa4316aa74136c7d110fc9fcb3ad922258 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_channel_update_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg_exact!(msgs::ChannelUpdate, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_channel_update_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_exact!(msgs::ChannelUpdate, data);
 }
index 8043d9de083853fc1c70145e2df2c8908c68962f..a2c01bc5653e90a6681d97ac4e341680e7c75b18 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_closing_signed_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::ClosingSigned, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_closing_signed_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::ClosingSigned, data);
 }
index 319f46c597706fbddf061e8233c696dfdd49aa50..9534c082fb9654f0df543e61ffde18b435e0b49f 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_commitment_signed_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::CommitmentSigned, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_commitment_signed_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::CommitmentSigned, data);
 }
index d6e5a829d1f9bed2dd552241e0d6547f75fa7fc9..cad0c205f35432555949fcd4b69359b747741b38 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_decoded_onion_error_packet_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::DecodedOnionErrorPacket, data);
 }
 
 #[no_mangle]
 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) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::DecodedOnionErrorPacket, data);
 }
index 16594953eb8ef90ff14301867c4e9a3ecd0663a7..ed7f454601cdfbd739a10857bac050633e993dac 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_error_message_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg_hole!(msgs::ErrorMessage, data, 32, 2);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_error_message_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_hole!(msgs::ErrorMessage, data, 32, 2);
 }
index cc322cbb09801487faeb587d358d0b652534fd65..83532bad041177bebc03541e84e975a13ad04cc1 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_funding_created_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::FundingCreated, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_funding_created_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::FundingCreated, data);
 }
index a546ed8bb604daf976faf499f56c498c9d0710db..73f84242f718403083dc04d9a01efcacbd9fad9e 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_funding_locked_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::FundingLocked, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_funding_locked_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::FundingLocked, data);
 }
index 0210b5ec61f954c0f42da199d7d0a23a76226706..f1808991dbad361a0b2e7047e6261ceb1427291e 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_funding_signed_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::FundingSigned, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_funding_signed_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::FundingSigned, data);
 }
index 52b92acd01931a581de44990c4d25466adca4cc9..be2a4f0a7d61864a8512dd71669b11b92a3ea7ab 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_init_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg_simple!(msgs::Init, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_init_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(msgs::Init, data);
 }
index bb09f87e7f97d3e7c59ada698a3fae917088e5de..d66295471c7b0c89123d412db1f3b66cf7e0ad06 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_node_announcement_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg_exact!(msgs::NodeAnnouncement, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_node_announcement_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_exact!(msgs::NodeAnnouncement, data);
 }
index 9d7ad602582fafa2a36d5cee16adefabd6d28195..79243b52e2d95d32743decc7be27d7485dc638c5 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_onion_hop_data_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg_simple!(msgs::OnionHopData, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_onion_hop_data_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(msgs::OnionHopData, data);
 }
index 9c700c2b2e44e9b49fd55742e208c69da87a2b83..f3a207deea372b11b65e926cf1d6c849441136fb 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_open_channel_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::OpenChannel, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_open_channel_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::OpenChannel, data);
 }
index 67e2382f09d3bdb28ab3421a988bb6df9b02ee5c..90065cdc1bda17748a89a6fd157574209cc15448 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_ping_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg_simple!(msgs::Ping, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_ping_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(msgs::Ping, data);
 }
index cec5c5adf68b9e2be02cf1856c4ad6726204a290..2fd1c3a8511b080d9757125021631f173a57fed5 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_pong_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg_simple!(msgs::Pong, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_pong_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(msgs::Pong, data);
 }
index 6df64e3e4d2ea36c7ed4262e5a86971bbe9018b3..ce73051073ffa6c1948a35f77baa24bba1da6f95 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_revoke_and_ack_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::RevokeAndACK, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_revoke_and_ack_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::RevokeAndACK, data);
 }
index d70d9a6a7b5ce8add19332edf9426597aecb2f01..4017db294911eb2f42958f6b29d878abd2a8b531 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_shutdown_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::Shutdown, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_shutdown_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::Shutdown, data);
 }
index ea785ff4ef314073a6e4e7baff428793abaa9c31..afb1d759d44624063249062f9f740f6af9614771 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn TARGET_NAME_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        TEST_MSG!(msgs::MSG_TARGET, dataEXTRA_ARGS);
 }
 
 #[no_mangle]
 pub extern "C" fn TARGET_NAME_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       TEST_MSG!(msgs::MSG_TARGET, dataEXTRA_ARGS);
 }
index 13b648f0af57a6ee0f7f825dad125f22f3310d1b..ac4e67474a7fd6884c9fa2ab7a72df4eaad94b88 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_update_add_htlc_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg_hole!(msgs::UpdateAddHTLC, data, 85, 33);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_update_add_htlc_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_hole!(msgs::UpdateAddHTLC, data, 85, 33);
 }
index e21d2146c4ae9db337cb1b8f05a8ca62f7658e88..3603941d0a4d1bce4e5a081559872f2e737ec388 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_update_fail_htlc_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::UpdateFailHTLC, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_update_fail_htlc_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::UpdateFailHTLC, data);
 }
index e27b85281902d35082748166274c0b75ec620ff1..78591ada404de00deab680db3797d1eb80033d10 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_update_fail_malformed_htlc_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::UpdateFailMalformedHTLC, data);
 }
 
 #[no_mangle]
 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) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::UpdateFailMalformedHTLC, data);
 }
index 5051bb87d7cac2a26e986b31935870097198734e..b106288f6a0d2d5df305abb54b1f059c3e2ddf0c 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_update_fee_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::UpdateFee, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_update_fee_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::UpdateFee, data);
 }
index b8b3d98a92c05a20d41a3c1b3edaca2e0552e95d..d97653c2df49d72e014ef9d0168b98d017efe2b7 100644 (file)
@@ -4,13 +4,15 @@
 use lightning::ln::msgs;
 
 use msg_targets::utils::VecWriter;
+use utils::test_logger;
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn msg_update_fulfill_htlc_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
        test_msg!(msgs::UpdateFulfillHTLC, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_update_fulfill_htlc_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg!(msgs::UpdateFulfillHTLC, data);
 }
index e0ff02f04ccc341a219cc9a90bf308a349224591..176a7caab6530dcbf0d6f7cf0f704a9d7e21d96c 100644 (file)
@@ -2,6 +2,8 @@ use lightning::ln::peer_channel_encryptor::PeerChannelEncryptor;
 
 use secp256k1::key::{PublicKey,SecretKey};
 
+use utils::test_logger;
+
 #[inline]
 fn slice_to_be16(v: &[u8]) -> u16 {
        ((v[0] as u16) << 8*1) |
@@ -75,6 +77,10 @@ pub fn do_test(data: &[u8]) {
        }
 }
 
+pub fn peer_crypt_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       do_test(data);
+}
+
 #[no_mangle]
 pub extern "C" fn peer_crypt_run(data: *const u8, datalen: usize) {
        do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
index b1a766ba79149b5640a080c55a625eb338424a03..7dcf1de72217c848cd70fd90497fafb9fac04648 100644 (file)
@@ -93,7 +93,7 @@ impl ChainWatchInterface for DummyChainWatcher {
 }
 
 #[inline]
-pub fn do_test(data: &[u8]) {
+pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
        let input = Arc::new(InputData {
                data: data.to_vec(),
                read_pos: AtomicUsize::new(0),
@@ -150,7 +150,7 @@ pub fn do_test(data: &[u8]) {
                }
        }
 
-       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned()));
+       let logger: Arc<dyn Logger> = Arc::new(test_logger::TestLogger::new("".to_owned(), out));
        let chain_monitor = Arc::new(DummyChainWatcher {
                input: Arc::clone(&input),
        });
@@ -232,7 +232,11 @@ pub fn do_test(data: &[u8]) {
        }
 }
 
+pub fn router_test<Out: test_logger::Output>(data: &[u8], out: Out) {
+       do_test(data, out);
+}
+
 #[no_mangle]
 pub extern "C" fn router_run(data: *const u8, datalen: usize) {
-       do_test(unsafe { std::slice::from_raw_parts(data, datalen) });
+       do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull {});
 }
index a7d7c32d5503ba455892a014c18384faf4907878..79dc5d24b5adce0291259c2b2624668232870ad1 100644 (file)
@@ -1 +1 @@
-pub(crate) mod test_logger;
+pub mod test_logger;
index 097d001dbb25f80e0049a6c1526c379365a0f49f..cd037ad8187d8c42895b1a92abd3a37dfe2b5c8f 100644 (file)
@@ -1,23 +1,55 @@
 use lightning::util::logger::{Logger, Record};
-pub struct TestLogger {
-       #[cfg(test)]
+use std::sync::{Arc, Mutex};
+use std::io::Write;
+
+pub trait Output : Clone + Sync + Send + 'static {
+       fn locked_write(&self, data: &[u8]);
+}
+
+#[derive(Clone)]
+pub struct DevNull {}
+impl Output for DevNull {
+       fn locked_write(&self, _data: &[u8]) {}
+}
+#[derive(Clone)]
+pub struct StringBuffer(Arc<Mutex<String>>);
+impl Output for StringBuffer {
+       fn locked_write(&self, data: &[u8]) {
+               self.0.lock().unwrap().push_str(&String::from_utf8(data.to_vec()).unwrap());
+       }
+}
+impl StringBuffer {
+       pub fn new() -> Self {
+               Self(Arc::new(Mutex::new(String::new())))
+       }
+       pub fn into_string(self) -> String {
+               Arc::try_unwrap(self.0).unwrap().into_inner().unwrap()
+       }
+}
+
+pub struct TestLogger<Out : Output> {
        id: String,
+       out: Out,
+}
+impl<Out: Output> TestLogger<Out> {
+       pub fn new(id: String, out: Out) -> TestLogger<Out> {
+               TestLogger { id, out }
+       }
 }
 
-impl TestLogger {
-       pub fn new(_id: String) -> TestLogger {
-               TestLogger {
-                       #[cfg(test)]
-                       id: _id
-               }
+struct LockedWriteAdapter<'a, Out: Output>(&'a Out);
+impl<'a, Out: Output> Write for LockedWriteAdapter<'a, Out> {
+       fn write(&mut self, data: &[u8]) -> Result<usize, std::io::Error> {
+               self.0.locked_write(data);
+               Ok(data.len())
        }
+       fn flush(&mut self) -> Result<(), std::io::Error> { Ok(()) }
 }
 
-impl Logger for TestLogger {
+impl<Out: Output> Logger for TestLogger<Out> {
        fn log(&self, record: &Record) {
-               #[cfg(test)]
-               println!("{:<5} {} [{} : {}, {}] {}", record.level.to_string(), self.id, record.module_path, record.file, record.line, record.args);
-               #[cfg(not(test))]
-               let _ = format!("{}", record.args);
+               write!(LockedWriteAdapter(&self.out),
+                       "{:<5} {} [{} : {}, {}] {}\n", record.level.to_string(), self.id, record.module_path, record.file, record.line, record.args)
+                       .unwrap();
        }
 }