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)]
15 extern crate lightning_fuzz;
16 use lightning_fuzz::msg_targets::msg_init::*;
18 #[cfg(feature = "afl")]
19 #[macro_use] extern crate afl;
20 #[cfg(feature = "afl")]
23 msg_init_run(data.as_ptr(), data.len());
27 #[cfg(feature = "honggfuzz")]
28 #[macro_use] extern crate honggfuzz;
29 #[cfg(feature = "honggfuzz")]
33 msg_init_run(data.as_ptr(), data.len());
38 #[cfg(feature = "libfuzzer_fuzz")]
39 #[macro_use] extern crate libfuzzer_sys;
40 #[cfg(feature = "libfuzzer_fuzz")]
41 fuzz_target!(|data: &[u8]| {
42 msg_init_run(data.as_ptr(), data.len());
45 #[cfg(feature = "stdin_fuzz")]
49 let mut data = Vec::with_capacity(8192);
50 std::io::stdin().read_to_end(&mut data).unwrap();
51 msg_init_run(data.as_ptr(), data.len());
58 use lightning_fuzz::utils::test_logger::StringBuffer;
60 use std::sync::{atomic, Arc};
62 let data: Vec<u8> = vec![0];
63 msg_init_run(data.as_ptr(), data.len());
65 let mut threads = Vec::new();
66 let threads_running = Arc::new(atomic::AtomicUsize::new(0));
67 if let Ok(tests) = fs::read_dir("test_cases/msg_init") {
69 let mut data: Vec<u8> = Vec::new();
70 let path = test.unwrap().path();
71 fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
72 threads_running.fetch_add(1, atomic::Ordering::AcqRel);
74 let thread_count_ref = Arc::clone(&threads_running);
75 let main_thread_ref = std::thread::current();
76 threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
77 std::thread::spawn(move || {
78 let string_logger = StringBuffer::new();
80 let panic_logger = string_logger.clone();
81 let res = if ::std::panic::catch_unwind(move || {
82 msg_init_test(&data, panic_logger);
84 Some(string_logger.into_string())
86 thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
87 main_thread_ref.unpark();
91 while threads_running.load(atomic::Ordering::Acquire) > 32 {
96 for (test, thread) in threads.drain(..) {
97 if let Some(output) = thread.join().unwrap() {
98 println!("Output of {}:\n{}", test, output);