summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-11-16 20:31:19 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-11-16 20:31:19 +0000
commit424bd9d0720e3752c6ff252c6eb0a3425109b765 (patch)
treebfb82632bd55df717333addff11895cce6c36a5b /tests
parent7c404ca8c5d0037a17797ace2961d5424cf3a4a5 (diff)
downloadgentoo-utils-424bd9d0720e3752c6ff252c6eb0a3425109b765.tar.gz
move fuzz stuff into its own directory
Diffstat (limited to 'tests')
-rw-r--r--tests/fuzz.rs50
-rw-r--r--tests/meson.build28
2 files changed, 1 insertions, 77 deletions
diff --git a/tests/fuzz.rs b/tests/fuzz.rs
deleted file mode 100644
index 69804e8..0000000
--- a/tests/fuzz.rs
+++ /dev/null
@@ -1,50 +0,0 @@
-use core::slice;
-use gentoo_utils::{Parseable, atom::Atom};
-use mon::{Parser, ParserFinishedError, input::InputIter};
-use std::{
- io::Write,
- process::{Command, Stdio},
-};
-
-#[allow(clippy::missing_safety_doc, clippy::needless_return)]
-#[unsafe(no_mangle)]
-pub unsafe extern "C" fn LLVMFuzzerTestOneInput(input: *const u8, len: usize) -> i32 {
- let slice = unsafe { slice::from_raw_parts(input, len) };
-
- let atom = match str::from_utf8(slice) {
- Ok(str) => str.trim(),
- _ => return -1,
- };
-
- let mut proc = Command::new("atom.py")
- .stdin(Stdio::piped())
- .spawn()
- .unwrap();
-
- proc.stdin
- .as_mut()
- .unwrap()
- .write_all(atom.as_bytes())
- .unwrap();
-
- let status = proc.wait().unwrap();
-
- let result = Atom::parser().check_finished(InputIter::new(atom));
-
- match (status.success(), result) {
- (true, Ok(_)) => {
- eprintln!("agreement that {atom} is valid");
- return 0;
- }
- (true, Err(ParserFinishedError::Err(it) | ParserFinishedError::Unfinished(it))) => {
- panic!("gentoo-utils rejected valid atom: {atom}: {}", it.rest());
- }
- (false, Err(_)) => {
- eprintln!("agreement that {atom} is invalid");
- return -1;
- }
- (false, Ok(_)) => {
- panic!("gentoo-utils accepted invalid atom: {atom}");
- }
- }
-}
diff --git a/tests/meson.build b/tests/meson.build
index c4b5e8d..69052cd 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,27 +1 @@
-cbindgen = find_program('cbindgen')
-
-fuzz_h = custom_target(
- 'fuzz_h',
- input: 'fuzz.rs',
- output: 'fuzz.h',
- command: [cbindgen, '@INPUT@', '-o', '@OUTPUT'],
-)
-
-fuzz_rs = static_library(
- 'fuzz_rs',
- 'fuzz.rs',
- rust_abi: 'c',
- rust_args: [
- '-Cpasses=sancov-module',
- '-Cllvm-args=-sanitizer-coverage-level=3',
- '-Cllvm-args=-sanitizer-coverage-inline-8bit-counters',
- ],
- dependencies: [mon],
- link_with: [gentoo_utils],
-)
-
-fuzz_cpp = executable(
- 'fuzz',
- link_args: ['-fsanitize=fuzzer'],
- link_with: [fuzz_rs],
-)
+subdir('fuzz')