Testing QEMU
Testing QEMU
Who am I?
Computer Science student
Worked on QEMU in GSoC project
Other hacking activities:
• Satellite software
• Android Real Time Operating System
Marc Marí – Testing QEMU emulated devices using qtest 3
Index
• Introduction
• What is a QTest? What is libqos?
• How are devices accessed?
• Basic test structure
• Libqos API functions
• Debugging and testing
• Conclusion
Marc Marí – Testing QEMU emulated devices using qtest 5
Index
• Introduction
• What is a QTest? What is libqos?
• How are devices accessed?
• Basic test structure
• Libqos API functions
• Debugging and testing
• Conclusion
Marc Marí – Testing QEMU emulated devices using qtest 8
GLib tests
• GLib provides a unit testing framework
• QTests are based on GLib testing framework
• GLib provides:
– Test cases: methods
– Test suite: group of test cases
Source: https://developer.gnome.org/glib/unstable/glib-Testing.html
Marc Marí – Testing QEMU emulated devices using qtest 9
Libqtest
• API to control QEMU
• Expands GLib test framework:
– Wraps QEMU init
– Enables debugging functions
– Performs a clean exit
• Adds basic operations:
– Clock
– Memory and I/O
– IRQ
– QMP (QEMU machine protocol)
Marc Marí – Testing QEMU emulated devices using qtest 10
LibQOS
• Device driver framework for writing qtest
cases
• Bus wrappers
• Contains functions specific to each bus
• Simplifies the device developer work
• Standarizes access to devices
Marc Marí – Testing QEMU emulated devices using qtest 11
Objective
• Have a complete test suite
• Each device implemented has one test suite
• LibQOS has a implementation for each bus
• Create a full testing enviroment:
– Can detect loaded devices
– Can check automatically and autonomously
Source: http://www.linux-kvm.org/wiki/images/8/89/2012-forum-Liguori-qtest.pdf
Marc Marí – Testing QEMU emulated devices using qtest 12
Index
• Introduction
• What is a QTest? What is libqos?
• How are devices accessed?
• Basic test structure
• Libqos API functions
• Debugging and testing
• Conclusion
Marc Marí – Testing QEMU emulated devices using qtest 13
GUEST MACHINE
QEMU
Bus (emulated)
Device (emulated)
HOST MACHINE
Bus (real)
Device (real)
Marc Marí – Testing QEMU emulated devices using qtest 14
GUEST MACHINE
(qtest mode)
TEST QEMU
HOST MACHINE
Bus (real)
Device (real)
Marc Marí – Testing QEMU emulated devices using qtest 15
Index
• Introduction
• What is a QTest? What is libqos?
• How are devices accessed?
• Basic test structure
• Libqos API functions
• Debugging and testing
• Conclusion
Marc Marí – Testing QEMU emulated devices using qtest 16
g_test_add_func() or qtest_add_func()
qtest_add_func() adds the architecture in front
of the path:
qtest_add_func("/ac97/nop", nop);
if (strcmp(arch, "i386") == 0 ||
strcmp(arch, "x86_64") == 0) {
qtest_add_func("/virtio/blk/pci/basic",
pci_basic);
} else if (strcmp(arch, "arm") == 0) {
qtest_add_func("/virtio/blk/mmio/basic",
mmio_basic);
}
Marc Marí – Testing QEMU emulated devices using qtest 29
Index
• Introduction
• What is a QTest? What is libqos?
• How are devices accessed?
• Basic test structure
• Libqos API functions
• Debugging and testing
• Conclusion
Marc Marí – Testing QEMU emulated devices using qtest 31
PCI functionalities
• Device operations (qpci_device_find,
qpci_device_enable…)
• Config operations (qpci_config_readb,
qpci_config_writel…)
• I/O operations (qpci_iomap,
qpci_io_readw, qpci_io_writeb…)
• MSIX functionalities (qpci_msix_enable,
qpci_msix_pending…)
Marc Marí – Testing QEMU emulated devices using qtest 33
VirtIO functionalities
• Device operations
(qvirtio_pci_device_enable,
qvirtio_set_features…)
• Config operations (qvirtio_config_readb,
qvirtio_config_writel…)
• Virtqueues (qvirtqueue_setup,
qvirtqueue_add…)
• Interruptions (qvirtio_wait_queue_isr…)
Marc Marí – Testing QEMU emulated devices using qtest 34
Index
• Introduction
• What is a QTest? What is libqos?
• How are devices accessed?
• Basic test structure
• Libqos API functions
• Debugging and testing
• Conclusion
Marc Marí – Testing QEMU emulated devices using qtest 35
Debugging
QTEST_LOG=1 QTEST_STOP=1 \
QTEST_QEMU_BINARY=\
i386-softmmu/qemu-system-i386 \
tests/new-test
Marc Marí – Testing QEMU emulated devices using qtest 39
Debugging
• QTEST_LOG=1: write to stderr all operations
[R +0.025815] outl 0xcf8 0x80000000
[S +0.025852] OK
[R +0.025881] inw 0xcfc
[S +0.025900] OK 0x8086
[R +0.025927] outl 0xcf8 0x80000000
[S +0.025940] OK
[R +0.025963] inw 0xcfc
[S +0.025974] OK 0x8086
Marc Marí – Testing QEMU emulated devices using qtest 40
Debugging
• QTEST_STOP=1: stop to connect the debugger
– Attach GDB:
gdb --pid=$(pidof new-test)
– Continue executing:
kill -SIGCONT \
$(pidof qemu-system-i386)
Marc Marí – Testing QEMU emulated devices using qtest 41
Index
• Introduction
• What is a QTest? What is libqos?
• How are devices accessed?
• Basic test structure
• Libqos API functions
• Debugging and testing
• Conclusion
Marc Marí – Testing QEMU emulated devices using qtest 42
Conclusion
• Testing in QEMU is essential to maintain
integrity
• Libqtest and libqos make developing device
tests in QEMU easier.
• There is a lack of tests for devices
Thanks to
• Stefan Hajnoczi
• Paolo Bonzini
• All the QEMU people that is open to questions
every day at any hour
Marc Marí – Testing QEMU emulated devices using qtest 44
Questions?