Skip to content

Commit

Permalink
Fix and run queue fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AljoschaMeyer committed Aug 8, 2024
1 parent f619389 commit ff86a25
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 130 deletions.
23 changes: 22 additions & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,25 @@ name = "queues_fixed_bulk"
path = "fuzz_targets/queues/fixed_bulk.rs"
test = false
doc = false
bench = false
bench = false

[[bin]]
name = "queues_fixed_enqueue_dequeue"
path = "fuzz_targets/queues/fixed_enqueue_dequeue.rs"
test = false
doc = false
bench = false

[[bin]]
name = "queues_static_bulk"
path = "fuzz_targets/queues/static_bulk.rs"
test = false
doc = false
bench = false

[[bin]]
name = "queues_static_enqueue_dequeue"
path = "fuzz_targets/queues/static_enqueue_dequeue.rs"
test = false
doc = false
bench = false
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![no_main]
use std::collections::VecDeque;

use libfuzzer_sys::arbitrary;
use arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![no_main]

use libfuzzer_sys::arbitrary;
use arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![no_main]
use std::collections::VecDeque;

use libfuzzer_sys::arbitrary;
use arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;

Expand Down
4 changes: 0 additions & 4 deletions ufotofu_queues/fuzz/.gitignore

This file was deleted.

43 changes: 0 additions & 43 deletions ufotofu_queues/fuzz/Cargo.toml

This file was deleted.

77 changes: 0 additions & 77 deletions ufotofu_queues/fuzz/fuzz_targets/fixed_bulk.rs

This file was deleted.

10 changes: 5 additions & 5 deletions ufotofu_queues/src/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<T> Fixed<T> {
}

/// Return a slice containing the next items that should be read.
fn readable_slice(&mut self) -> &[MaybeUninit<T>] {
fn readable_slice(&mut self) -> &[T] {
if self.is_data_contiguous() {
&self.data[self.read..self.write_to()]
} else {
Expand All @@ -81,7 +81,7 @@ impl<T> Fixed<T> {
}

/// Return a slice containing the next slots that should be written to.
fn writeable_slice(&mut self) -> &mut [MaybeUninit<T>] {
fn writeable_slice(&mut self) -> &mut [T] {
let capacity = self.capacity();
let write_to = self.write_to();
if self.is_data_contiguous() {
Expand Down Expand Up @@ -217,7 +217,7 @@ impl<T: Copy> Queue for Fixed<T> {
/// exposed to contain initialized memory after this call, even if the memory it exposed was
/// originally uninitialized. Violating the invariants will cause the queue to read undefined
/// memory, which triggers undefined behavior.
unsafe fn consider_enqueued(&mut self, amount: usize) {
fn consider_enqueued(&mut self, amount: usize) {
self.amount += amount;
}

Expand All @@ -233,7 +233,7 @@ impl<T: Copy> Queue for Fixed<T> {
self.read = (self.read + 1) % self.capacity();
self.amount -= 1;

Some(unsafe { self.data[previous_read].assume_init() })
Some(self.data[previous_read])
}
}

Expand All @@ -244,7 +244,7 @@ impl<T: Copy> Queue for Fixed<T> {
if self.amount == 0 {
None
} else {
Some(unsafe { crate::slice_assume_init_ref(self.readable_slice()) })
Some(self.readable_slice())
}
}

Expand Down

0 comments on commit ff86a25

Please sign in to comment.