/src/arm-ffa/fuzz/fuzz_targets/partition_info.rs
Line | Count | Source |
1 | | // SPDX-FileCopyrightText: Copyright The arm-ffa Contributors. |
2 | | // SPDX-License-Identifier: MIT OR Apache-2.0 |
3 | | |
4 | | //! Unpacks memory partition info descriptors from the test data, packs them and then checks if the |
5 | | //! output matches the input. |
6 | | |
7 | | #![no_main] |
8 | | |
9 | | use arm_ffa::partition_info::PartitionInfo; |
10 | | use libfuzzer_sys::fuzz_target; |
11 | | |
12 | | fuzz_target!(|data: &[u8]| { |
13 | | if data.len() > PartitionInfo::DESC_SIZE { |
14 | | return; |
15 | | } |
16 | | |
17 | | let Ok(info) = PartitionInfo::unpack(data, 1) else { |
18 | | return; |
19 | | }; |
20 | | |
21 | 19 | let descriptors: Vec<_> = info.filter_map(|it| it.ok()).collect(); |
22 | | |
23 | | let mut buf_out = [0; PartitionInfo::DESC_SIZE]; |
24 | | PartitionInfo::pack(&descriptors, &mut buf_out); |
25 | | |
26 | | for (b_in, b_out) in data.iter().zip(buf_out) { |
27 | | assert_eq!( |
28 | | b_in & b_out, |
29 | | b_out, |
30 | | "Mismatching values: {:#x?}", |
31 | | descriptors |
32 | | ); |
33 | | } |
34 | | }); |