aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-10-07 15:14:34 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-12 07:41:30 +0100
commitabd9a7679e5da78a51ed5eb488ae081a2bcb2b6c (patch)
tree45c4064fec80df52359cc5e4a7c73596fb6021f0 /lib
parent9e148a4b216f349eb277aa029397139ba9d4994e (diff)
downloadtools.nes-abd9a7679e5da78a51ed5eb488ae081a2bcb2b6c.tar.gz
tools.nes-abd9a7679e5da78a51ed5eb488ae081a2bcb2b6c.zip
ci: Add fuzzy testing to the parser
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/xixanta/fuzz/.gitignore4
-rw-r--r--lib/xixanta/fuzz/Cargo.lock79
-rw-r--r--lib/xixanta/fuzz/Cargo.toml24
-rw-r--r--lib/xixanta/fuzz/fuzz_targets/fuzz_target_1.rs8
-rw-r--r--lib/xixanta/src/parser.rs2
5 files changed, 115 insertions, 2 deletions
diff --git a/lib/xixanta/fuzz/.gitignore b/lib/xixanta/fuzz/.gitignore
new file mode 100644
index 0000000..1a45eee
--- /dev/null
+++ b/lib/xixanta/fuzz/.gitignore
@@ -0,0 +1,4 @@
+target
+corpus
+artifacts
+coverage
diff --git a/lib/xixanta/fuzz/Cargo.lock b/lib/xixanta/fuzz/Cargo.lock
new file mode 100644
index 0000000..d06a484
--- /dev/null
+++ b/lib/xixanta/fuzz/Cargo.lock
@@ -0,0 +1,79 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "arbitrary"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110"
+
+[[package]]
+name = "cc"
+version = "1.1.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1"
+dependencies = [
+ "jobserver",
+ "libc",
+ "shlex",
+]
+
+[[package]]
+name = "jobserver"
+version = "0.1.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "lazy_static"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
+
+[[package]]
+name = "libc"
+version = "0.2.159"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
+
+[[package]]
+name = "libfuzzer-sys"
+version = "0.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a96cfd5557eb82f2b83fed4955246c988d331975a002961b07c81584d107e7f7"
+dependencies = [
+ "arbitrary",
+ "cc",
+ "once_cell",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.20.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
+
+[[package]]
+name = "shlex"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
+
+[[package]]
+name = "xixanta"
+version = "0.1.0"
+dependencies = [
+ "lazy_static",
+]
+
+[[package]]
+name = "xixanta-fuzz"
+version = "0.0.0"
+dependencies = [
+ "libfuzzer-sys",
+ "xixanta",
+]
diff --git a/lib/xixanta/fuzz/Cargo.toml b/lib/xixanta/fuzz/Cargo.toml
new file mode 100644
index 0000000..3b3498d
--- /dev/null
+++ b/lib/xixanta/fuzz/Cargo.toml
@@ -0,0 +1,24 @@
+[package]
+name = "xixanta-fuzz"
+version = "0.0.0"
+publish = false
+edition = "2021"
+
+[workspace]
+members = []
+
+[package.metadata]
+cargo-fuzz = true
+
+[dependencies]
+libfuzzer-sys = "0.4"
+
+[dependencies.xixanta]
+path = ".."
+
+[[bin]]
+name = "fuzz_target_1"
+path = "fuzz_targets/fuzz_target_1.rs"
+test = false
+doc = false
+bench = false
diff --git a/lib/xixanta/fuzz/fuzz_targets/fuzz_target_1.rs b/lib/xixanta/fuzz/fuzz_targets/fuzz_target_1.rs
new file mode 100644
index 0000000..6a28b46
--- /dev/null
+++ b/lib/xixanta/fuzz/fuzz_targets/fuzz_target_1.rs
@@ -0,0 +1,8 @@
+#![no_main]
+
+use libfuzzer_sys::fuzz_target;
+
+fuzz_target!(|data: &[u8]| {
+ let mut parser = xixanta::parser::Parser::new();
+ let _ = parser.parse(data);
+});
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs
index d11e98c..d532841 100644
--- a/lib/xixanta/src/parser.rs
+++ b/lib/xixanta/src/parser.rs
@@ -4,8 +4,6 @@ use crate::opcodes::{CONTROL_FUNCTIONS, INSTRUCTIONS};
use std::io::{self, BufRead, Read};
use std::ops::Range;
-// TODO: add cargo-fuzz
-
type Result<T> = std::result::Result<T, ParseError>;
#[derive(Debug, Clone, PartialEq)]