Skip to content

Fuzz testing for SoAVec API - #18

Merged
aapoalas merged 4 commits into
mainfrom
fuzz_test
Sep 16, 2025
Merged

Fuzz testing for SoAVec API#18
aapoalas merged 4 commits into
mainfrom
fuzz_test

Conversation

@Reinsdyret

Copy link
Copy Markdown
Collaborator
  • feat(fuzz): implement SoAVec API fuzzer

Still needs to fuzz some structs with Drop implementation before review.

Comment thread fuzz/fuzz_targets/soavec_api.rs Outdated
let _ = vec.reserve(safe_additional);
}
SoAVecOp::Get { index } => {
let _ = vec.get(*index); // Test bounds checking in get()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: You could maybe use something like black_box on the reference to ensure the compiler doesn't optimise this down to nothing. Also consider dereferencing the value here and putting that into black_box go confirm reading works. Do the same for mut side, but there if possible also write a value through the mut reference.

@Reinsdyret

Copy link
Copy Markdown
Collaborator Author

Ok! So I've just maybe cleaned up the code a little and added black boxes.
I haven't made any structs with references because i don't understand it really, arbitrary cannot generate structs with referred values. But I am reading on something with std::borrow::Cow? Would this be correct to use like

#[derive(Arbitrary, Debug)]
struct MyStruct<'a> {
    name: Cow<'a, str>,
}

And for the custom Drop implementation structs i don't think there is a way unless the whole struct is very simple as in a struct that only has Copy types. Is this what you wanted?

@aapoalas

aapoalas commented Sep 9, 2025

Copy link
Copy Markdown
Member

Ok! So I've just maybe cleaned up the code a little and added black boxes. I haven't made any structs with references because i don't understand it really, arbitrary cannot generate structs with referred values.

Hmm... I could imagine eg. creating some static array of values of type T, and then randomly generating an index into that array and borrowing that index from the array, and thus generate &T types. But that definitely seems like it needs something more than just Arbitrary.

And for the custom Drop implementation structs i don't think there is a way unless the whole struct is very simple as in a struct that only has Copy types. Is this what you wanted?

I was thinking of something like using Box::leak or Vec::into_raw_parts to get things that must be manually dropped, and storing them inside your own custom type. Then impl Drop on that struct to perform Box::from_raw / Vec::from_raw_parts to deallocate the data on drop (Vec is a better example here); finally manually impl SoAble on that type with MUST_DROP_AS_SELF.

So for the Vec part an example would be:

struct SoableVec<T> {
  ptr: *mut T,
  length: usize,
  capacity: usize,
}

You get those fields from Vec::<T>::into_raw_parts which is nightly only; so instead you have to use as_mut_ptr, len and capacity APIs to get the field values, then you std::mem::forget the Vec to stop it from dropping itself; this combines into effectively into_raw_parts. now impl Drop for SoableVec to perform from_raw_parts.

@Reinsdyret
Reinsdyret marked this pull request as ready for review September 16, 2025 10:19
@aapoalas

Copy link
Copy Markdown
Member

LGTM, nice work! <3

@aapoalas
aapoalas merged commit 0106e92 into main Sep 16, 2025
3 checks passed
@aapoalas
aapoalas deleted the fuzz_test branch September 16, 2025 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants