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.
4 #![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
6 extern crate lightning_fuzz;
7 use lightning_fuzz::router::*;
9 #[cfg(feature = "afl")]
10 #[macro_use] extern crate afl;
11 #[cfg(feature = "afl")]
14 router_run(data.as_ptr(), data.len());
18 #[cfg(feature = "honggfuzz")]
19 #[macro_use] extern crate honggfuzz;
20 #[cfg(feature = "honggfuzz")]
24 router_run(data.as_ptr(), data.len());
29 #[cfg(feature = "libfuzzer_fuzz")]
30 #[macro_use] extern crate libfuzzer_sys;
31 #[cfg(feature = "libfuzzer_fuzz")]
32 fuzz_target!(|data: &[u8]| {
33 router_run(data.as_ptr(), data.len());
36 #[cfg(feature = "stdin_fuzz")]
40 let mut data = Vec::with_capacity(8192);
41 std::io::stdin().read_to_end(&mut data).unwrap();
42 router_run(data.as_ptr(), data.len());
49 use lightning_fuzz::utils::test_logger::StringBuffer;
51 use std::sync::{atomic, Arc};
53 let data: Vec<u8> = vec![0];
54 router_run(data.as_ptr(), data.len());
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/router") {
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);
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();
71 let panic_logger = string_logger.clone();
72 let res = if ::std::panic::catch_unwind(move || {
73 router_test(&data, panic_logger);
75 Some(string_logger.into_string())
77 thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
78 main_thread_ref.unpark();
82 while threads_running.load(atomic::Ordering::Acquire) > 32 {
87 for (test, thread) in threads.drain(..) {
88 if let Some(output) = thread.join().unwrap() {
89 println!("Output of {}:\n{}", test, output);