[block][prop test] split random_request_parse()
Move the lambda logic inside random_request_parse() to different method
for improved readability and better IDE parsing.
@@ -674,7 +674,27 @@ mod tests {
})
.prop_map(
|(sparsity, data_len, sector, request_type, virtio_request_id, coins)| {
- let coins = &mut coins.iter();
+ do_random_request_parse(
+ sparsity,
+ data_len,
+ sector,
+ request_type,
+ virtio_request_id,
+ &coins,
+ )
+ },
+ )
+ }
+
+ fn do_random_request_parse(
+ sparsity: u64,
+ data_len: u32,
+ sector: u64,
+ request_type: RequestType,
+ virtio_request_id: u32,
+ coins_arr: &[bool],
+ ) -> (Result<Request, Error>, GuestMemoryMmap, Queue) {
+ let coins = &mut coins_arr.iter();
// Randomize descriptor addresses. Assumed page size as max buffer len.
let base_addr = sparsity & 0x0000_FFFF_FFFF_F000; // 48 bit base, page aligned.
@@ -750,12 +770,7 @@ mod tests {
);
}
- vq.dtable[STATUS_DESCRIPTOR].set(
- request.status_addr.0,
- 1,
- VIRTQ_DESC_F_WRITE,
- 0,
- );
+ vq.dtable[STATUS_DESCRIPTOR].set(request.status_addr.0, 1, VIRTQ_DESC_F_WRITE, 0);
// Flip a coin - should we generate a valid request or an error.
if *coins.next().unwrap() {
@@ -781,9 +796,9 @@ mod tests {
// Flip coin - req type desc is write only.
if *coins.next().unwrap() {
- vq.dtable[REQUEST_TYPE_DESCRIPTOR].flags.set(
- vq.dtable[REQUEST_TYPE_DESCRIPTOR].flags.get() | VIRTQ_DESC_F_WRITE,
- );
+ vq.dtable[REQUEST_TYPE_DESCRIPTOR]
+ .flags
+ .set(vq.dtable[REQUEST_TYPE_DESCRIPTOR].flags.get() | VIRTQ_DESC_F_WRITE);
return (Err(Error::UnexpectedWriteOnlyDescriptor), mem, q);
}
@@ -807,8 +822,6 @@ mod tests {
// Simulate no status descriptor.
vq.dtable[REQUEST_TYPE_DESCRIPTOR].flags.set(0);
(Err(Error::DescriptorChainTooShort), mem, q)
- },
- )
}
macro_rules! assert_err {
