]> git.bitcoin.ninja Git - rust-lightning/blob - fuzz/src/bin/msg_funding_created_target.rs
WIP
[rust-lightning] / fuzz / src / bin / msg_funding_created_target.rs
1 // This file is auto-generated by gen_target.sh based on target_template.txt
2 // To modify it, modify target_template.txt and run gen_target.sh instead.
3
4 #![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
5
6 extern crate lightning_fuzz;
7 use lightning_fuzz::msg_targets::msg_funding_created::*;
8
9 #[cfg(feature = "afl")]
10 #[macro_use] extern crate afl;
11 #[cfg(feature = "afl")]
12 fn main() {
13         fuzz!(|data| {
14                 msg_funding_created_run(data.as_ptr(), data.len());
15         });
16 }
17
18 #[cfg(feature = "honggfuzz")]
19 #[macro_use] extern crate honggfuzz;
20 #[cfg(feature = "honggfuzz")]
21 fn main() {
22         loop {
23                 fuzz!(|data| {
24                         msg_funding_created_run(data.as_ptr(), data.len());
25                 });
26         }
27 }
28
29 #[cfg(feature = "libfuzzer_fuzz")]
30 #[macro_use] extern crate libfuzzer_sys;
31 #[cfg(feature = "libfuzzer_fuzz")]
32 fuzz_target!(|data: &[u8]| {
33         msg_funding_created_run(data.as_ptr(), data.len());
34 });
35
36 #[cfg(feature = "stdin_fuzz")]
37 fn main() {
38         use std::io::Read;
39
40         let mut data = Vec::with_capacity(8192);
41         std::io::stdin().read_to_end(&mut data).unwrap();
42         msg_funding_created_run(data.as_ptr(), data.len());
43 }
44
45 #[test]
46 fn run_test_cases() {
47         use std::fs;
48         use std::io::Read;
49         use lightning_fuzz::utils::test_logger::StringBuffer;
50
51         use std::sync::{atomic, Arc};
52         {
53                 let data: Vec<u8> = vec![0];
54                 msg_funding_created_run(data.as_ptr(), data.len());
55         }
56         let mut threads = Vec::new();
57         let threads_running = Arc::new(atomic::AtomicUsize::new(0));
58         if let Ok(tests) = fs::read_dir("test_cases/msg_funding_created") {
59                 for test in tests {
60                         let mut data: Vec<u8> = Vec::new();
61                         let path = test.unwrap().path();
62                         fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
63                         threads_running.fetch_add(1, atomic::Ordering::AcqRel);
64
65                         let thread_count_ref = Arc::clone(&threads_running);
66                         let main_thread_ref = std::thread::current();
67                         threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
68                                 std::thread::spawn(move || {
69                                         let string_logger = StringBuffer::new();
70
71                                         let panic_logger = string_logger.clone();
72                                         let res = if ::std::panic::catch_unwind(move || {
73                                                 msg_funding_created_test(&data, panic_logger);
74                                         }).is_err() {
75                                                 Some(string_logger.into_string())
76                                         } else { None };
77                                         thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
78                                         main_thread_ref.unpark();
79                                         res
80                                 })
81                         ));
82                         while threads_running.load(atomic::Ordering::Acquire) > 32 {
83                                 std::thread::park();
84                         }
85                 }
86         }
87         for (test, thread) in threads.drain(..) {
88                 if let Some(output) = thread.join().unwrap() {
89                         println!("Output of {}:\n{}", test, output);
90                         panic!();
91                 }
92         }
93 }