Skip to content

Commit 4c01059

Browse files
CopilotBernardXiong
andcommitted
[virtio] Add comprehensive testing guide
- Added TESTING.md with test procedures for legacy and modern VirtIO - Documented QEMU command lines for both modes - Included device-specific testing instructions - Added debugging tips and common issues section Co-authored-by: BernardXiong <[email protected]>
1 parent ee5dac3 commit 4c01059

File tree

1 file changed

+301
-0
lines changed

1 file changed

+301
-0
lines changed
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
# VirtIO Testing Guide
2+
3+
This guide helps you test VirtIO support on RT-Thread with both legacy and modern versions.
4+
5+
## Prerequisites
6+
7+
- QEMU installed (version 2.4+ for modern VirtIO support)
8+
- RT-Thread build environment
9+
- RISC-V or AArch64 toolchain
10+
11+
## Testing Legacy VirtIO (v0.95)
12+
13+
### 1. Configure RT-Thread
14+
15+
```bash
16+
cd bsp/qemu-virt64-riscv
17+
scons --menuconfig
18+
```
19+
20+
Navigate to:
21+
```
22+
RT-Thread Components → Device Drivers → Using VirtIO device drivers → VirtIO Version
23+
→ Select "VirtIO Legacy (v0.95)" or "VirtIO Legacy (v1.0 - alias for compatibility)"
24+
```
25+
26+
### 2. Build
27+
28+
```bash
29+
scons
30+
```
31+
32+
### 3. Run with QEMU (Legacy Mode)
33+
34+
Force QEMU to use legacy VirtIO:
35+
36+
```bash
37+
qemu-system-riscv64 \
38+
-M virt \
39+
-kernel rtthread.bin \
40+
-nographic \
41+
-device virtio-blk-device,disable-modern=on,drive=blk0 \
42+
-drive if=none,id=blk0,file=sd.bin \
43+
-device virtio-net-device,disable-modern=on,netdev=net0 \
44+
-netdev user,id=net0
45+
```
46+
47+
### 4. Verify
48+
49+
Check that VirtIO devices are detected:
50+
```
51+
msh /> list_device
52+
device type ref count
53+
------ -------------------- ----------
54+
virtio-blk0 Block Device 0
55+
virtio-net0 Network Interface 0
56+
```
57+
58+
## Testing Modern VirtIO (v1.0+)
59+
60+
### 1. Configure RT-Thread
61+
62+
```bash
63+
cd bsp/qemu-virt64-riscv
64+
scons --menuconfig
65+
```
66+
67+
Navigate to:
68+
```
69+
RT-Thread Components → Device Drivers → Using VirtIO device drivers → VirtIO Version
70+
→ Select "VirtIO Modern (v1.0+)"
71+
```
72+
73+
### 2. Build
74+
75+
```bash
76+
scons
77+
```
78+
79+
### 3. Run with QEMU (Modern Mode)
80+
81+
Use default QEMU settings (modern VirtIO):
82+
83+
```bash
84+
qemu-system-riscv64 \
85+
-M virt \
86+
-kernel rtthread.bin \
87+
-nographic \
88+
-device virtio-blk-device,drive=blk0 \
89+
-drive if=none,id=blk0,file=sd.bin \
90+
-device virtio-net-device,netdev=net0 \
91+
-netdev user,id=net0
92+
```
93+
94+
Or explicitly enable modern mode:
95+
96+
```bash
97+
qemu-system-riscv64 \
98+
-M virt \
99+
-kernel rtthread.bin \
100+
-nographic \
101+
-device virtio-blk-device,disable-legacy=on,drive=blk0 \
102+
-drive if=none,id=blk0,file=sd.bin \
103+
-device virtio-net-device,disable-legacy=on,netdev=net0 \
104+
-netdev user,id=net0
105+
```
106+
107+
### 4. Verify
108+
109+
Check that VirtIO devices are detected:
110+
```
111+
msh /> list_device
112+
device type ref count
113+
------ -------------------- ----------
114+
virtio-blk0 Block Device 0
115+
virtio-net0 Network Interface 0
116+
```
117+
118+
## Testing Auto-Detection (Recommended)
119+
120+
The driver can auto-detect the VirtIO version. To test this:
121+
122+
### 1. Build with Default Settings
123+
124+
Use the existing configuration (legacy by default):
125+
```bash
126+
cd bsp/qemu-virt64-riscv
127+
scons
128+
```
129+
130+
### 2. Test with Both QEMU Modes
131+
132+
**Test 1: Legacy QEMU**
133+
```bash
134+
qemu-system-riscv64 -M virt -kernel rtthread.bin -nographic \
135+
-device virtio-blk-device,disable-modern=on,drive=blk0 \
136+
-drive if=none,id=blk0,file=sd.bin
137+
```
138+
139+
**Test 2: Modern QEMU**
140+
```bash
141+
qemu-system-riscv64 -M virt -kernel rtthread.bin -nographic \
142+
-device virtio-blk-device,drive=blk0 \
143+
-drive if=none,id=blk0,file=sd.bin
144+
```
145+
146+
Both should work because the driver detects the version from the MMIO config.
147+
148+
## Testing Individual Devices
149+
150+
### VirtIO Block Device
151+
152+
```bash
153+
# Create a test disk image
154+
dd if=/dev/zero of=sd.bin bs=1M count=32
155+
156+
# Run QEMU with block device
157+
qemu-system-riscv64 -M virt -kernel rtthread.bin -nographic \
158+
-device virtio-blk-device,drive=blk0 \
159+
-drive if=none,id=blk0,file=sd.bin
160+
161+
# In RT-Thread shell
162+
msh /> mkfs -t elm virtio-blk0
163+
msh /> mount virtio-blk0 / elm
164+
```
165+
166+
### VirtIO Network Device
167+
168+
```bash
169+
# Run QEMU with network device
170+
qemu-system-riscv64 -M virt -kernel rtthread.bin -nographic \
171+
-device virtio-net-device,netdev=net0 \
172+
-netdev user,id=net0,hostfwd=tcp::5555-:23
173+
174+
# In RT-Thread shell
175+
msh /> ifconfig
176+
```
177+
178+
### VirtIO Console
179+
180+
```bash
181+
# Run QEMU with console device
182+
qemu-system-riscv64 -M virt -kernel rtthread.bin -nographic \
183+
-device virtio-serial-device \
184+
-chardev stdio,id=console0 \
185+
-device virtconsole,chardev=console0
186+
187+
# Check for virtio-console devices
188+
msh /> list_device
189+
```
190+
191+
### VirtIO GPU
192+
193+
```bash
194+
# Run QEMU with GPU device (requires display)
195+
qemu-system-riscv64 -M virt -kernel rtthread.bin \
196+
-device virtio-gpu-device \
197+
-serial stdio
198+
199+
# Or with VNC
200+
qemu-system-riscv64 -M virt -kernel rtthread.bin -nographic \
201+
-device virtio-gpu-device \
202+
-vnc :0
203+
```
204+
205+
### VirtIO Input (Keyboard/Mouse)
206+
207+
```bash
208+
# Run QEMU with input devices
209+
qemu-system-riscv64 -M virt -kernel rtthread.bin \
210+
-device virtio-keyboard-device \
211+
-device virtio-mouse-device \
212+
-device virtio-tablet-device
213+
214+
# Check for input devices
215+
msh /> list_device
216+
```
217+
218+
## Debugging
219+
220+
### Enable Debug Output
221+
222+
Add debug prints to check version detection:
223+
224+
```c
225+
// In your application or driver init
226+
rt_kprintf("VirtIO version: %d\n", virtio_dev->version);
227+
rt_kprintf("VirtIO magic: 0x%x\n", virtio_dev->mmio_config->magic);
228+
rt_kprintf("VirtIO device_id: %d\n", virtio_dev->mmio_config->device_id);
229+
```
230+
231+
### Check QEMU Version
232+
233+
```bash
234+
qemu-system-riscv64 --version
235+
```
236+
237+
Modern VirtIO requires QEMU 2.4+.
238+
239+
### Check Feature Negotiation
240+
241+
Add debug output in `virtio_get_features` and `virtio_set_features` to verify feature negotiation.
242+
243+
## Expected Results
244+
245+
### Legacy Mode (Version 1)
246+
- `dev->version == 1`
247+
- Features are 32-bit
248+
- Queue uses `queue_pfn` register
249+
- No FEATURES_OK check
250+
251+
### Modern Mode (Version 2)
252+
- `dev->version == 2`
253+
- Features are 64-bit
254+
- Queue uses separate desc/driver/device registers
255+
- FEATURES_OK status check performed
256+
- VERSION_1 feature negotiated
257+
258+
## Common Issues
259+
260+
### Issue: Device not detected
261+
**Solution**: Check QEMU device configuration and memory mapping
262+
263+
### Issue: Feature negotiation fails
264+
**Solution**: Verify QEMU supports the features you're requesting
265+
266+
### Issue: Queue initialization fails
267+
**Solution**: Check memory alignment and addresses
268+
269+
### Issue: Build errors
270+
**Solution**: Ensure Kconfig is properly configured and rtconfig.h is generated
271+
272+
## Performance Testing
273+
274+
### Block Device Performance
275+
276+
```bash
277+
# In RT-Thread shell (with filesystem mounted)
278+
msh /> dd if=/dev/zero of=/test.bin bs=4096 count=1000
279+
```
280+
281+
### Network Performance
282+
283+
```bash
284+
# Use iperf or similar tools
285+
# Configure network and run throughput tests
286+
```
287+
288+
## Reporting Issues
289+
290+
When reporting issues, include:
291+
1. QEMU version
292+
2. RT-Thread configuration (legacy/modern)
293+
3. QEMU command line
294+
4. Error messages or unexpected behavior
295+
5. Debug output (if enabled)
296+
297+
## Reference
298+
299+
- [QEMU VirtIO Documentation](https://wiki.qemu.org/Features/VirtIO)
300+
- [VirtIO Specification](https://docs.oasis-open.org/virtio/virtio/v1.2/virtio-v1.2.html)
301+
- [RT-Thread VirtIO README](README.md)

0 commit comments

Comments
 (0)