interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / bitflags / src / external / arbitrary.rs

33 lines · 779 bytes Raw Blame History
1//! Specialized fuzzing for flags types using `arbitrary`.
2
3use crate::Flags;
4
5/**
6Generate some arbitrary flags value with only known bits set.
7*/
8pub fn arbitrary<'a, B: Flags>(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<B>
9where
10 B::Bits: arbitrary::Arbitrary<'a>,
11{
12 B::from_bits(u.arbitrary()?).ok_or(arbitrary::Error::IncorrectFormat)
13}
14
15#[cfg(test)]
16mod tests {
17 use arbitrary::Arbitrary;
18
19 bitflags! {
20 #[derive(Arbitrary)]
21 struct Color: u32 {
22 const RED = 0x1;
23 const GREEN = 0x2;
24 const BLUE = 0x4;
25 }
26 }
27
28 #[test]
29 fn test_arbitrary() {
30 let mut unstructured = arbitrary::Unstructured::new(&[0_u8; 256]);
31 let _color = Color::arbitrary(&mut unstructured);
32 }
33}