• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

google / alioth / 16871256879

11 Aug 2025 04:57AM UTC coverage: 10.366% (+1.6%) from 8.754%
16871256879

push

github

Lencerf
test(virtio): inject errors in queue handler tests

Signed-off-by: Changyuan Lyu <changyuanl@google.com>

30 of 56 new or added lines in 1 file covered. (53.57%)

26 existing lines in 5 files now uncovered.

710 of 6849 relevant lines covered (10.37%)

16.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/alioth/src/virtio/queue/split_test.rs
1
// Copyright 2025 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
use std::ptr::eq as ptr_eq;
16
use std::sync::atomic::Ordering;
17

18
use assert_matches::assert_matches;
19
use rstest::rstest;
20

21
use crate::mem::mapped::RamBus;
22
use crate::virtio::VirtioFeature;
23
use crate::virtio::queue::split::{Desc, DescFlag, SplitQueue};
24
use crate::virtio::queue::{Queue, VirtQueue};
25

26
use crate::virtio::queue::tests::{DATA_ADDR, QUEUE_SIZE, fixture_queue, fixture_ram_bus};
27

28
impl<'q, 'm> SplitQueue<'q, 'm> {
29
    pub fn add_desc(&mut self, id: u16, readable: &[(u64, u32)], writable: &[(u64, u32)]) {
17✔
30
        let readable_count = readable.len();
49✔
31
        let total_count = readable.len() + writable.len();
65✔
32
        for (i, (addr, len)) in readable.iter().chain(writable.iter()).enumerate() {
121✔
UNCOV
33
            let mut flag = DescFlag::empty();
1✔
34
            if i < total_count - 1 {
8✔
35
                flag |= DescFlag::NEXT;
7✔
36
            }
37
            if i >= readable_count {
11✔
38
                flag |= DescFlag::WRITE;
11✔
39
            }
40
            let desc = Desc {
UNCOV
41
                addr: *addr,
1✔
UNCOV
42
                len: *len,
1✔
UNCOV
43
                flag: flag.bits(),
1✔
UNCOV
44
                next: id + i as u16 + 1,
2✔
45
            };
UNCOV
46
            *unsafe { &mut *self.desc.offset((id + i as u16) as isize) } = desc;
5✔
47
        }
48
        let avail_idx = self.avail_index();
50✔
49
        *unsafe { &mut *self.avail_ring.offset((avail_idx % self.size) as isize) } = id;
49✔
50
        unsafe { &mut *self.avail_hdr }.idx = avail_idx.wrapping_add(1);
35✔
51
    }
52
}
53

54
#[rstest]
55
fn disabled_queue(fixture_ram_bus: RamBus, fixture_queue: Queue) {
56
    let ram = fixture_ram_bus.lock_layout();
57
    fixture_queue.enabled.store(false, Ordering::Relaxed);
58
    let split_queue = SplitQueue::new(&fixture_queue, &*ram, 0);
59
    assert_matches!(split_queue, Ok(None));
60
}
61

62
#[rstest]
63
fn enabled_queue(fixture_ram_bus: RamBus, fixture_queue: Queue) {
64
    let ram = fixture_ram_bus.lock_layout();
65
    let mut q = SplitQueue::new(&fixture_queue, &*ram, 0).unwrap().unwrap();
66
    assert!(ptr_eq(q.reg(), &fixture_queue));
67
    assert_eq!(q.size(), QUEUE_SIZE);
68

69
    let str_0 = "Hello, World!";
70
    let str_1 = "Goodbye, World!";
71
    let str_2 = "Bose-Einstein condensate";
72
    let addr_0 = DATA_ADDR;
73
    let addr_1 = addr_0 + str_0.len() as u64;
74
    let addr_2 = addr_1 + str_1.len() as u64;
75
    ram.write(addr_0, str_0.as_bytes()).unwrap();
76
    ram.write(addr_1, str_1.as_bytes()).unwrap();
77

78
    q.add_desc(
79
        0,
80
        &[(addr_0, str_0.len() as u32), (addr_1, str_1.len() as u32)],
81
        &[],
82
    );
83

84
    assert_eq!(q.avail_index(), 1);
85
    assert_eq!(q.read_avail(0), 0);
86
    assert!(q.has_next_desc());
87
    let desc = q.next_desc().unwrap().unwrap();
88
    assert_eq!(desc.id, 0);
89
    assert_eq!(&*desc.readable[0], str_0.as_bytes());
90
    assert_eq!(&*desc.readable[1], str_1.as_bytes());
91
    assert_eq!(desc.writable.len(), 0);
92
    q.push_used(desc, 0);
93
    assert!(!q.has_next_desc());
94

95
    q.add_desc(2, &[], &[(addr_2, str_2.len() as u32)]);
96
    let mut desc = q.next_desc().unwrap().unwrap();
97
    assert_eq!(desc.id, 2);
98
    assert_eq!(desc.readable.len(), 0);
99
    let buffer = desc.writable[0].as_mut();
100
    buffer.copy_from_slice(str_2.as_bytes());
101
    q.push_used(desc, str_2.len());
102
    let mut b = vec![0u8; str_2.len()];
103
    ram.read(addr_2, b.as_mut()).unwrap();
104
    assert_eq!(&b, str_2.as_bytes());
105
}
106

107
#[rstest]
108
fn event_idx_enabled(fixture_ram_bus: RamBus, fixture_queue: Queue) {
109
    let ram = fixture_ram_bus.lock_layout();
110
    let q = SplitQueue::new(&fixture_queue, &*ram, VirtioFeature::EVENT_IDX.bits())
111
        .unwrap()
112
        .unwrap();
113
    unsafe { *q.used_event.unwrap() = 1 };
114
    assert_eq!(q.used_event(), Some(1));
115

116
    assert_eq!(q.set_avail_event(12), Some(()));
117
    assert_eq!(unsafe { *q.avail_event.unwrap() }, 12);
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc