1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 // This file is auto-generated by gen_target.sh based on target_template.txt
11 // To modify it, modify target_template.txt and run gen_target.sh instead.
13 #![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
14 #![cfg_attr(rustfmt, rustfmt_skip)]
17 compile_error!("Fuzz targets need cfg=fuzzing");
19 #[cfg(not(hashes_fuzz))]
20 compile_error!("Fuzz targets need cfg=hashes_fuzz");
22 #[cfg(not(secp256k1_fuzz))]
23 compile_error!("Fuzz targets need cfg=secp256k1_fuzz");
25 extern crate lightning_fuzz;
26 use lightning_fuzz::msg_targets::msg_splice_ack::*;
28 #[cfg(feature = "afl")]
29 #[macro_use] extern crate afl;
30 #[cfg(feature = "afl")]
33 msg_splice_ack_run(data.as_ptr(), data.len());
37 #[cfg(feature = "honggfuzz")]
38 #[macro_use] extern crate honggfuzz;
39 #[cfg(feature = "honggfuzz")]
43 msg_splice_ack_run(data.as_ptr(), data.len());
48 #[cfg(feature = "libfuzzer_fuzz")]
49 #[macro_use] extern crate libfuzzer_sys;
50 #[cfg(feature = "libfuzzer_fuzz")]
51 fuzz_target!(|data: &[u8]| {
52 msg_splice_ack_run(data.as_ptr(), data.len());
55 #[cfg(feature = "stdin_fuzz")]
59 let mut data = Vec::with_capacity(8192);
60 std::io::stdin().read_to_end(&mut data).unwrap();
61 msg_splice_ack_run(data.as_ptr(), data.len());
68 use lightning_fuzz::utils::test_logger::StringBuffer;
70 use std::sync::{atomic, Arc};
72 let data: Vec<u8> = vec![0];
73 msg_splice_ack_run(data.as_ptr(), data.len());
75 let mut threads = Vec::new();
76 let threads_running = Arc::new(atomic::AtomicUsize::new(0));
77 if let Ok(tests) = fs::read_dir("test_cases/msg_splice_ack") {
79 let mut data: Vec<u8> = Vec::new();
80 let path = test.unwrap().path();
81 fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
82 threads_running.fetch_add(1, atomic::Ordering::AcqRel);
84 let thread_count_ref = Arc::clone(&threads_running);
85 let main_thread_ref = std::thread::current();
86 threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
87 std::thread::spawn(move || {
88 let string_logger = StringBuffer::new();
90 let panic_logger = string_logger.clone();
91 let res = if ::std::panic::catch_unwind(move || {
92 msg_splice_ack_test(&data, panic_logger);
94 Some(string_logger.into_string())
96 thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
97 main_thread_ref.unpark();
101 while threads_running.load(atomic::Ordering::Acquire) > 32 {
106 let mut failed_outputs = Vec::new();
107 for (test, thread) in threads.drain(..) {
108 if let Some(output) = thread.join().unwrap() {
109 println!("\nOutput of {}:\n{}\n", test, output);
110 failed_outputs.push(test);
113 if !failed_outputs.is_empty() {
114 println!("Test cases which failed: ");
115 for case in failed_outputs {
116 println!("{}", case);