QTest 设备模拟测试框架
- QTest 驱动框架
- QGraph 概念
- 创建驱动及其接口
- 添加测试
- Qgraph API 参考
QOSGraphEdgeOptionsQOSGraphTestOptionsQOSGraphObjectqos_graph_init()qos_graph_destroy()qos_node_destroy()qos_edge_destroy()qos_add_test()qos_node_create_machine()qos_node_create_machine_args()qos_node_create_driver()qos_node_create_driver_named()qos_node_contains()qos_node_produces()qos_node_consumes()qos_invalidate_command_line()qos_get_current_command_line()qos_allocate_objects()qos_object_destroy()qos_object_queue_destroy()qos_object_start_hw()qos_machine_new()qos_driver_new()qos_dump_graph()
QTest 是用于测试设备模型的框架,还能通过专用 qtest 协议 控制 QEMU 的一些行为,例如步进虚拟时钟。协议详见 QTest 协议。
运行用例:
make check-qtest
库实现位于 tests/qtest/libqtest.c,API 定义在 tests/qtest/libqtest.h。
新增虚拟硬件时,应考虑新增 QTest;扩展已有设备功能时,也应考虑扩展测试。
libqtest 之上的 libqos 封装了驱动常见工作,例如内存管理及系统总线、设备通信。 许多设备测试使用 libqos,而非直接调用 libqtest。 它还提供 Qgraph API,提高每个测试的覆盖范围,自动配置 QEMU 命令行和设备。 详见 QTest 驱动框架。
添加用例的步骤如下:
创建测试源文件,必要时可以多个,例如
tests/qtest/foo-test.c。使用 GLib 和 libqtest/libqos API 编写代码,参考现有测试及库头文件。
在
tests/qtest/meson.build注册。 将可执行文件名加入适当的qtests_*变量。 每个架构有专用变量,跨架构测试则放入 qtests_generic,例如::qtests_generic = [ ... 'foo-test', ... ]
如果有多个源文件,或需要 qemuutil、qos 之外的链接依赖, 则加入 qtests 字典。例如,需要 QIO 的测试::
{ ... 'foo-test': [io], ... }
排查 QTest 比单元测试稍难,因为它从 QTEST_QEMU_BINARY、QTEST_QEMU_IMG 等环境变量 获取 QEMU 程序名称,而且不易向测试派生的 QEMU 进程附加 GDB。 不过手动调用测试并使用 GDB 仍很简单,可以先从以下输出找到实际命令,再手动运行:
make check-qtest V=1
QTest 协议
Line based protocol, request/response based. Server can send async messages so clients should always handle many async messages before the response comes in.
Extra ASCII space characters in command inputs are permitted and ignored. Lines containing only spaces are permitted and ignored. Lines that start with a '#' character (comments) are permitted and ignored.
Valid requests
Clock management:
The qtest client is completely in charge of the QEMU_CLOCK_VIRTUAL. qtest commands let you adjust the value of the clock (monotonically). All the commands return the current value of the clock in nanoseconds.
If the commands FAIL then time wasn't advanced which is likely because the machine was in a paused state or no timer events exist in the future. This will cause qtest to abort and the test will need to check its assumptions.
> clock_step
< OK VALUE
Advance the clock to the next deadline. Useful when waiting for asynchronous events.
> clock_step NS
< OK VALUE
Advance the clock by NS nanoseconds.
> clock_set NS
< OK VALUE
Advance the clock to NS nanoseconds (do nothing if it's already past).
PIO and memory access:
> outb ADDR VALUE
< OK
> outw ADDR VALUE
< OK
> outl ADDR VALUE
< OK
> inb ADDR
< OK VALUE
> inw ADDR
< OK VALUE
> inl ADDR
< OK VALUE
> writeb ADDR VALUE
< OK
> writew ADDR VALUE
< OK
> writel ADDR VALUE
< OK
> writeq ADDR VALUE
< OK
> readb ADDR
< OK VALUE
> readw ADDR
< OK VALUE
> readl ADDR
< OK VALUE
> readq ADDR
< OK VALUE
> read ADDR SIZE
< OK DATA
> write ADDR SIZE DATA
< OK
> b64read ADDR SIZE
< OK B64_DATA
> b64write ADDR SIZE B64_DATA
< OK
> memset ADDR SIZE VALUE
< OK
ADDR, SIZE, VALUE are all integers parsed with strtoul() with a base of 0. For 'memset' a zero size is permitted and does nothing.
DATA is an arbitrarily long hex number prefixed with '0x'. If it's smaller than the expected size, the value will be zero filled at the end of the data sequence.
B64_DATA is an arbitrarily long base64 encoded string. If the sizes do not match, the data will be truncated.
IRQ management:
> irq_intercept_in QOM-PATH
< OK
> irq_intercept_out QOM-PATH
< OK
Attach to the gpio-in (resp. gpio-out) pins exported by the device at QOM-PATH. When the pin is triggered, one of the following async messages will be printed to the qtest stream:
IRQ raise NUM
IRQ lower NUM
where NUM is an IRQ number. For the PC, interrupts can be intercepted simply with "irq_intercept_in ioapic" (note that IRQ0 comes out with NUM=0 even though it is remapped to GSI 2).
Setting interrupt level:
> set_irq_in QOM-PATH NAME NUM LEVEL
< OK
where NAME is the name of the irq/gpio list, NUM is an IRQ number and LEVEL is an signed integer IRQ level.
Forcibly set the given interrupt pin to the given level.
libqtest API 参考
-
QTestState *qtest_initf(const char *fmt, ...)
Parameters
const char *fmtFormat for creating other arguments to pass to QEMU, formatted like sprintf().
...variable arguments
Description
Convenience wrapper around qtest_init().
Return
QTestState instance.
-
QTestState *qtest_vinitf(const char *fmt, va_list ap)
Parameters
const char *fmtFormat for creating other arguments to pass to QEMU, formatted like vsprintf().
va_list apFormat arguments.
Description
Convenience wrapper around qtest_init().
Return
QTestState instance.
-
const char *qtest_qemu_binary(const char *var)
Parameters
const char *varenvironment variable name
Description
Look up var and return its value as the qemu binary path. If var is NULL, look up the default var name.
-
QTestState *qtest_init_after_exec(QTestState *qts)
Parameters
QTestState *qtsthe previous QEMU state
Description
Return a test state representing new QEMU after qts exec's it.
-
gchar *qtest_qemu_args(const char *extra_args)
Parameters
const char *extra_argsOther arguments to pass to QEMU.
Description
Return the command line used to start QEMU, sans binary.
-
QTestState *qtest_init(const char *extra_args)
Parameters
const char *extra_argsother arguments to pass to QEMU. CAUTION: these arguments are subject to word splitting and shell evaluation.
Return
QTestState instance.
-
QTestState *qtest_init_ext(const char *var, const char *extra_args, QList *capabilities, bool do_connect)
Parameters
const char *varEnvironment variable from where to take the QEMU binary
const char *extra_argsOther arguments to pass to QEMU. CAUTION: these arguments are subject to word splitting and shell evaluation.
QList *capabilitieslist of QMP capabilities (strings) to enable
bool do_connectconnect to qemu monitor and qtest socket.
Description
Like qtest_init(), but use a different environment variable for the QEMU binary, allow specify capabilities and skip connecting to QEMU monitor.
Return
QTestState instance.
-
QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
Parameters
const char *extra_argsother arguments to pass to QEMU. CAUTION: these arguments are subject to word splitting and shell evaluation.
Return
QTestState instance.
-
void qtest_connect(QTestState *s)
Parameters
QTestState *sQTestStateinstance to connect Connect to qemu monitor and qtest socket, after skipping them in qtest_init_ext. Does not handshake with the monitor.
-
void qtest_qmp_handshake(QTestState *s, QList *capabilities)
Parameters
QTestState *sQTestStateinstance to operate on.QList *capabilitieslist of QMP capabilities (strings) to enable Perform handshake after connecting to qemu monitor.
-
QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd)
Parameters
const char *extra_argsother arguments to pass to QEMU. CAUTION: these arguments are subject to word splitting and shell evaluation.
int *sock_fdpointer to store the socket file descriptor for connection with serial.
Return
QTestState instance.
-
void qtest_system_reset(QTestState *s)
Parameters
QTestState *sQTestStateinstance to operate on.
Description
Send a "system_reset" command to the QEMU under test, and wait for the reset to complete before returning.
-
void qtest_system_reset_nowait(QTestState *s)
Parameters
QTestState *sQTestStateinstance to operate on.
Description
Send a "system_reset" command to the QEMU under test, but do not wait for the reset to complete before returning. The caller is responsible for waiting for either the RESET event or some other event of interest to them before proceeding.
This function should only be used if you're specifically testing for some other event; in that case you can't use qtest_system_reset() because it will read and discard any other QMP events that arrive before the RESET event.
-
void qtest_wait_qemu(QTestState *s)
Parameters
QTestState *sQTestStateinstance to operate on.
Description
Wait for the QEMU process to terminate. It is safe to call this function multiple times.
-
void qtest_kill_qemu(QTestState *s)
Parameters
QTestState *sQTestStateinstance to operate on.
Description
Kill the QEMU process and wait for it to terminate. It is safe to call this function multiple times. Normally qtest_quit() is used instead because it also frees QTestState. Use qtest_kill_qemu() when you just want to kill QEMU and qtest_quit() will be called later.
-
void qtest_quit(QTestState *s)
Parameters
QTestState *sQTestStateinstance to operate on.
Description
Shut down the QEMU process associated to s.
-
QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num, const char *fmt, ...)
Parameters
QTestState *sQTestStateinstance to operate on.int *fdsarray of file descriptors
size_t fds_numnumber of elements in fds
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
...variable arguments
Description
Sends a QMP message to QEMU with fds and returns the response.
-
QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
Parameters
QTestState *sQTestStateinstance to operate on.const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
...variable arguments
Description
Sends a QMP message to QEMU and returns the response.
-
void qtest_qmp_send(QTestState *s, const char *fmt, ...)
Parameters
QTestState *sQTestStateinstance to operate on.const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
...variable arguments
Description
Sends a QMP message to QEMU and leaves the response in the stream.
-
void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
Parameters
QTestState *sQTestStateinstance to operate on.const char *fmttext to send, formatted like sprintf()
...variable arguments
Description
Sends text to the QMP monitor verbatim. Need not be valid JSON; this is useful for negative tests.
-
int qtest_socket_server(const char *socket_path)
Parameters
const char *socket_paththe UNIX domain socket path
Description
Create and return a listen socket file descriptor, or abort on failure.
-
QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num, const char *fmt, va_list ap)
Parameters
QTestState *sQTestStateinstance to operate on.int *fdsarray of file descriptors
size_t fds_numnumber of elements in fds
const char *fmtQMP message to send to QEMU, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
va_list apQMP message arguments
Description
Sends a QMP message to QEMU with fds and returns the response.
-
QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
Parameters
QTestState *sQTestStateinstance to operate on.const char *fmtQMP message to send to QEMU, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
va_list apQMP message arguments
Description
Sends a QMP message to QEMU and returns the response.
-
void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num, const char *fmt, va_list ap)
Parameters
QTestState *sQTestStateinstance to operate on.int *fdsarray of file descriptors
size_t fds_numnumber of elements in fds
const char *fmtQMP message to send to QEMU, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
va_list apQMP message arguments
Description
Sends a QMP message to QEMU and leaves the response in the stream.
-
void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
Parameters
QTestState *sQTestStateinstance to operate on.const char *fmtQMP message to send to QEMU, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
va_list apQMP message arguments
Description
Sends a QMP message to QEMU and leaves the response in the stream.
-
QDict *qtest_qmp_receive_dict(QTestState *s)
Parameters
QTestState *sQTestStateinstance to operate on.
Description
Reads a QMP message from QEMU and returns the response.
-
QDict *qtest_qmp_receive(QTestState *s)
Parameters
QTestState *sQTestStateinstance to operate on.
Description
Reads a QMP message from QEMU and returns the response.
If a callback is registered with qtest_qmp_set_event_callback, it will be invoked for every event seen, otherwise events will be buffered until a call to one of the qtest_qmp_eventwait family of functions.
-
void qtest_qmp_set_event_callback(QTestState *s, QTestQMPEventCallback cb, void *opaque)
Parameters
QTestState *sQTestSTateinstance to operate onQTestQMPEventCallback cbcallback to invoke for events
void *opaquedata to pass to cb
Description
Register a callback to be invoked whenever an event arrives
-
void qtest_qmp_eventwait(QTestState *s, const char *event)
Parameters
QTestState *sQTestStateinstance to operate on.const char *eventevent to wait for.
Description
Continuously polls for QMP responses until it receives the desired event.
Any callback registered with qtest_qmp_set_event_callback will be invoked for every event seen.
-
QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event)
Parameters
QTestState *sQTestStateinstance to operate on.const char *eventevent to wait for.
Description
Continuously polls for QMP responses until it receives the desired event.
Any callback registered with qtest_qmp_set_event_callback will be invoked for every event seen.
Returns a copy of the event for further investigation.
-
QDict *qtest_qmp_event_ref(QTestState *s, const char *event)
Parameters
QTestState *sQTestStateinstance to operate on.const char *eventevent to return.
Description
Removes non-matching events from the buffer that was set by qtest_qmp_receive, until an event bearing the given name is found, and returns it. If no event matches, clears the buffer and returns NULL.
-
char *qtest_hmp(QTestState *s, const char *fmt, ...)
Parameters
QTestState *sQTestStateinstance to operate on.const char *fmtHMP command to send to QEMU, formats arguments like sprintf().
...variable arguments
Description
Send HMP command to QEMU via QMP's human-monitor-command. QMP events are discarded.
Return
the command's output. The caller should g_free() it.
-
char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
Parameters
QTestState *sQTestStateinstance to operate on.const char *fmtHMP command to send to QEMU, formats arguments like vsprintf().
va_list apHMP command arguments
Description
Send HMP command to QEMU via QMP's human-monitor-command. QMP events are discarded.
Return
the command's output. The caller should g_free() it.
-
void qtest_qom_tests(QTestState *s)
Parameters
QTestState *sQTestStateinstance to operate on.
Description
Run QOM property get/set round-trip tests on all non-abstract types.
-
bool qtest_get_irq(QTestState *s, int num)
Parameters
QTestState *sQTestStateinstance to operate on.int numInterrupt to observe.
Return
The level of the num interrupt.
-
uint64_t qtest_get_irq_raise_count(QTestState *s, int num)
Parameters
QTestState *sQTestStateinstance to operate on.int numInterrupt to observe.
Return
The number of raise notifications seen for the num interrupt.
-
void qtest_irq_intercept_in(QTestState *s, const char *string)
Parameters
QTestState *sQTestStateinstance to operate on.const char *stringQOM path of a device.
Description
Associate qtest irqs with the GPIO-in pins of the device whose path is specified by string.
-
void qtest_irq_intercept_out(QTestState *s, const char *string)
Parameters
QTestState *sQTestStateinstance to operate on.const char *stringQOM path of a device.
Description
Associate qtest irqs with the GPIO-out pins of the device whose path is specified by string.
-
void qtest_irq_intercept_out_named(QTestState *s, const char *qom_path, const char *name)
Parameters
QTestState *sQTestStateinstance to operate on.const char *qom_pathQOM path of a device.
const char *nameName of the GPIO out pin
Description
Associate a qtest irq with the named GPIO-out pin of the device whose path is specified by string and whose name is name.
-
void qtest_set_irq_in(QTestState *s, const char *string, const char *name, int irq, int level)
Parameters
QTestState *sQTestState instance to operate on.
const char *stringQOM path of a device
const char *nameIRQ name
int irqIRQ number
int levelIRQ level
Description
Force given device/irq GPIO-in pin to the given level.
-
void qtest_outb(QTestState *s, uint16_t addr, uint8_t value)
Parameters
QTestState *sQTestStateinstance to operate on.uint16_t addrI/O port to write to.
uint8_t valueValue being written.
Description
Write an 8-bit value to an I/O port.
-
void qtest_outw(QTestState *s, uint16_t addr, uint16_t value)
Parameters
QTestState *sQTestStateinstance to operate on.uint16_t addrI/O port to write to.
uint16_t valueValue being written.
Description
Write a 16-bit value to an I/O port.
-
void qtest_outl(QTestState *s, uint16_t addr, uint32_t value)
Parameters
QTestState *sQTestStateinstance to operate on.uint16_t addrI/O port to write to.
uint32_t valueValue being written.
Description
Write a 32-bit value to an I/O port.
-
uint8_t qtest_inb(QTestState *s, uint16_t addr)
Parameters
QTestState *sQTestStateinstance to operate on.uint16_t addrI/O port to read from.
Description
Returns an 8-bit value from an I/O port.
-
uint16_t qtest_inw(QTestState *s, uint16_t addr)
Parameters
QTestState *sQTestStateinstance to operate on.uint16_t addrI/O port to read from.
Description
Returns a 16-bit value from an I/O port.
-
uint32_t qtest_inl(QTestState *s, uint16_t addr)
Parameters
QTestState *sQTestStateinstance to operate on.uint16_t addrI/O port to read from.
Description
Returns a 32-bit value from an I/O port.
-
void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to write to.
uint8_t valueValue being written.
Description
Writes an 8-bit value to memory.
-
void qtest_writew(QTestState *s, uint64_t addr, uint16_t value)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to write to.
uint16_t valueValue being written.
Description
Writes a 16-bit value to memory.
-
void qtest_writel(QTestState *s, uint64_t addr, uint32_t value)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to write to.
uint32_t valueValue being written.
Description
Writes a 32-bit value to memory.
-
void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to write to.
uint64_t valueValue being written.
Description
Writes a 64-bit value to memory.
-
uint8_t qtest_readb(QTestState *s, uint64_t addr)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to read from.
Description
Reads an 8-bit value from memory.
Return
Value read.
-
uint16_t qtest_readw(QTestState *s, uint64_t addr)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to read from.
Description
Reads a 16-bit value from memory.
Return
Value read.
-
uint32_t qtest_readl(QTestState *s, uint64_t addr)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to read from.
Description
Reads a 32-bit value from memory.
Return
Value read.
-
uint64_t qtest_readq(QTestState *s, uint64_t addr)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to read from.
Description
Reads a 64-bit value from memory.
Return
Value read.
-
void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to read from.
void *dataPointer to where memory contents will be stored.
size_t sizeNumber of bytes to read.
Description
Read guest memory into a buffer.
-
uint64_t qtest_rtas_call(QTestState *s, const char *name, uint32_t nargs, uint64_t args, uint32_t nret, uint64_t ret)
Parameters
QTestState *sQTestStateinstance to operate on.const char *namename of the command to call.
uint32_t nargsNumber of args.
uint64_t argsGuest address to read args from.
uint32_t nretNumber of return value.
uint64_t retGuest address to write return values to.
Description
Call an RTAS function
-
uint64_t qtest_csr_call(QTestState *s, const char *name, uint64_t cpu, int csr, uint64_t *val)
Parameters
QTestState *sQTestStateinstance to operate on.const char *namename of the command to call.
uint64_t cpuhart number.
int csrCSR number.
uint64_t *valValue for reading/writing.
Description
Call an RISC-V CSR read/write function
-
void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to read from.
void *dataPointer to where memory contents will be stored.
size_t sizeNumber of bytes to read.
Description
Read guest memory into a buffer and receive using a base64 encoding.
-
void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to write to.
const void *dataPointer to the bytes that will be written to guest memory.
size_t sizeNumber of bytes to write.
Description
Write a buffer to guest memory.
-
void qtest_bufwrite(QTestState *s, uint64_t addr, const void *data, size_t size)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to write to.
const void *dataPointer to the bytes that will be written to guest memory.
size_t sizeNumber of bytes to write.
Description
Write a buffer to guest memory and transmit using a base64 encoding.
-
void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size)
Parameters
QTestState *sQTestStateinstance to operate on.uint64_t addrGuest address to write to.
uint8_t pattByte pattern to fill the guest memory region with.
size_t sizeNumber of bytes to write.
Description
Write a pattern to guest memory.
-
int64_t qtest_clock_step_next(QTestState *s)
Parameters
QTestState *sQTestStateinstance to operate on.
Description
Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
Return
The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
-
int64_t qtest_clock_step(QTestState *s, int64_t step)
Parameters
QTestState *sQTestState instance to operate on.
int64_t stepNumber of nanoseconds to advance the clock by.
Description
Advance the QEMU_CLOCK_VIRTUAL by step nanoseconds.
Return
The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
-
int64_t qtest_clock_set(QTestState *s, int64_t val)
Parameters
QTestState *sQTestState instance to operate on.
int64_t valNanoseconds value to advance the clock to.
Description
Advance the QEMU_CLOCK_VIRTUAL to val nanoseconds since the VM was launched.
Return
The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
-
bool qtest_big_endian(QTestState *s)
Parameters
QTestState *sQTestState instance to operate on.
Return
True if the architecture under test has a big endian configuration.
-
const char *qtest_get_arch(void)
Parameters
voidno arguments
Return
The architecture for the QEMU executable under test.
-
bool qtest_has_accel(const char *accel_name)
Parameters
const char *accel_nameAccelerator name to check for.
Return
true if the accelerator is built in.
-
void qtest_add_func(const char *str, void (*fn)(void))
Parameters
const char *strTest case path.
void (*fn)(void)Test case function
Description
Add a GTester testcase with the given name and function. The path is prefixed with the architecture under test, as returned by qtest_get_arch().
-
void qtest_add_data_func(const char *str, const void *data, void (*fn)(const void*))
Parameters
const char *strTest case path.
const void *dataTest case data
void (*fn)(const void *)Test case function
Description
Add a GTester testcase with the given name, data and function. The path is prefixed with the architecture under test, as returned by qtest_get_arch().
-
void qtest_add_data_func_full(const char *str, void *data, void (*fn)(const void*), GDestroyNotify data_free_func)
Parameters
const char *strTest case path.
void *dataTest case data
void (*fn)(const void *)Test case function
GDestroyNotify data_free_funcGDestroyNotify for data
Description
Add a GTester testcase with the given name, data and function. The path is prefixed with the architecture under test, as returned by qtest_get_arch().
data is passed to data_free_func() on test completion.
-
qtest_add
qtest_add (testpath, Fixture, tdata, fsetup, ftest, fteardown)
Parameters
testpathTest case path
FixtureFixture type
tdataTest case data
fsetupTest case setup function
ftestTest case function
fteardownTest case teardown function
Description
Add a GTester testcase with the given name, data and functions. The path is prefixed with the architecture under test, as returned by qtest_get_arch().
-
void qtest_add_abrt_handler(GHookFunc fn, const void *data)
Parameters
GHookFunc fnHandler function
const void *dataArgument that is passed to the handler
Description
Add a handler function that is invoked on SIGABRT. This can be used to terminate processes and perform other cleanup. The handler can be removed with qtest_remove_abrt_handler().
-
void qtest_remove_abrt_handler(void *data)
Parameters
void *dataArgument previously passed to qtest_add_abrt_handler()
Description
Remove an abrt handler that was previously added with qtest_add_abrt_handler().
-
QDict *qtest_vqmp_assert_success_ref(QTestState *qts, const char *fmt, va_list args)
Parameters
QTestState *qtsQTestState instance to operate on
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
va_list argsvariable arguments for fmt
Description
Sends a QMP message to QEMU, asserts that a 'return' key is present in the response, and returns the response.
-
void qtest_vqmp_assert_success(QTestState *qts, const char *fmt, va_list args)
Parameters
QTestState *qtsQTestState instance to operate on
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
va_list argsvariable arguments for fmt
Description
Sends a QMP message to QEMU and asserts that a 'return' key is present in the response.
-
QDict *qtest_vqmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds, const char *fmt, va_list args)
Parameters
QTestState *qtsQTestState instance to operate on
int *fdsthe file descriptors to send
size_t nfdsnumber of fds to send
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
va_list argsvariable arguments for fmt
Description
Sends a QMP message with file descriptors to QEMU, asserts that a 'return' key is present in the response, and returns the response.
-
void qtest_vqmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds, const char *fmt, va_list args)
Parameters
QTestState *qtsQTestState instance to operate on
int *fdsthe file descriptors to send
size_t nfdsnumber of fds to send
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
va_list argsvariable arguments for fmt
Description
Sends a QMP message with file descriptors to QEMU and asserts that a 'return' key is present in the response.
-
QDict *qtest_qmp_assert_failure_ref(QTestState *qts, const char *fmt, ...)
Parameters
QTestState *qtsQTestState instance to operate on
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
...variable arguments
Description
Sends a QMP message to QEMU, asserts that an 'error' key is present in the response, and returns the response.
-
QDict *qtest_vqmp_assert_failure_ref(QTestState *qts, const char *fmt, va_list args)
Parameters
QTestState *qtsQTestState instance to operate on
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
va_list argsvariable arguments for fmt
Description
Sends a QMP message to QEMU, asserts that an 'error' key is present in the response, and returns the response.
-
QDict *qtest_qmp_assert_success_ref(QTestState *qts, const char *fmt, ...)
Parameters
QTestState *qtsQTestState instance to operate on
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
...variable arguments
Description
Sends a QMP message to QEMU, asserts that a 'return' key is present in the response, and returns the response.
-
void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
Parameters
QTestState *qtsQTestState instance to operate on
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
...variable arguments
Description
Sends a QMP message to QEMU and asserts that a 'return' key is present in the response.
-
QDict *qtest_qmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds, const char *fmt, ...)
Parameters
QTestState *qtsQTestState instance to operate on
int *fdsthe file descriptors to send
size_t nfdsnumber of fds to send
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
...variable arguments
Description
Sends a QMP message with file descriptors to QEMU, asserts that a 'return' key is present in the response, and returns the response.
-
void qtest_qmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds, const char *fmt, ...)
Parameters
QTestState *qtsQTestState instance to operate on
int *fdsthe file descriptors to send
size_t nfdsnumber of fds to send
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
...variable arguments
Description
Sends a QMP message with file descriptors to QEMU and asserts that a 'return' key is present in the response.
-
void qtest_cb_for_every_machine(void (*cb)(const char *machine), bool skip_old_versioned)
Parameters
void (*cb)(const char *machine)Pointer to the callback function
bool skip_old_versionedtrue if versioned old machine types should be skipped
Description
Call a callback function for every name of all available machines.
-
char *qtest_resolve_machine_alias(const char *var, const char *alias)
Parameters
const char *varEnvironment variable from where to take the QEMU binary
const char *aliasThe alias to resolve
Return
the machine type corresponding to the alias if any, otherwise NULL.
-
bool qtest_has_machine(const char *machine)
Parameters
const char *machineThe machine to look for
Return
true if the machine is available in the target binary.
-
bool qtest_has_machine_with_env(const char *var, const char *machine)
Parameters
const char *varEnvironment variable from where to take the QEMU binary
const char *machineThe machine to look for
Return
true if the machine is available in the specified binary.
-
bool qtest_has_cpu_model(const char *cpu)
Parameters
const char *cpuThe cpu to look for
Return
true if the cpu is available in the target binary.
-
bool qtest_has_device(const char *device)
Parameters
const char *deviceThe device to look for
Return
true if the device is available in the target binary.
-
void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv, const QDict *arguments)
Parameters
QTestState *qtsQTestState instance to operate on
const char *drvName of the device that should be added
const QDict *argumentsQDict with properties for the device to initialize
Description
Generic hot-plugging test via the device_add QMP command with properties supplied in form of QDict. Use NULL for empty properties list.
-
void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id, const char *fmt, ...)
Parameters
QTestState *qtsQTestState instance to operate on
const char *driverName of the device that should be added
const char *idIdentification string
const char *fmtQMP message to send to qemu, formatted like qobject_from_jsonf_nofail(). See parse_interpolation() for what's supported after '%'.
...variable arguments
Description
Generic hot-plugging test via the device_add QMP command.
-
void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd)
Parameters
QTestState *qtsQTestState instance to operate on
const char *protocolthe protocol to add to
int fdthe client file-descriptor
Description
Call QMP getfd (on Windows get-win32-socket) followed by
add_client with the given fd.
-
void qtest_qmp_device_del_send(QTestState *qts, const char *id)
Parameters
QTestState *qtsQTestState instance to operate on
const char *idIdentification string
Description
Generic hot-unplugging test via the device_del QMP command.
-
void qtest_qmp_device_del(QTestState *qts, const char *id)
Parameters
QTestState *qtsQTestState instance to operate on
const char *idIdentification string
Description
Generic hot-unplugging test via the device_del QMP command. Waiting for command completion event.
-
bool qtest_probe_child(QTestState *s)
Parameters
QTestState *sQTestState instance to operate on.
Return
true if the child is still alive.
-
void qtest_set_expected_status(QTestState *s, int status)
Parameters
QTestState *sQTestState instance to operate on.
int statusan expected exit status.
Description
Set expected exit status of the child.
-
void qtest_qom_set_bool(QTestState *s, const char *path, const char *property, bool value)
Parameters
QTestState *sQTestState instance to operate on.
const char *pathPath to the property being set.
const char *propertyProperty being set.
bool valueValue to set the property.
Description
Set the property with passed in value.
-
bool qtest_qom_get_bool(QTestState *s, const char *path, const char *property)
Parameters
QTestState *sQTestState instance to operate on.
const char *pathPath to the property being retrieved.
const char *propertyProperty from where the value is being retrieved.
Return
Value retrieved from property.
-
pid_t qtest_pid(QTestState *s)
Parameters
QTestState *sQTestState instance to operate on.
Return
the PID of the QEMU process, or <= 0
-
bool have_qemu_img(void)
Parameters
voidno arguments
Return
true if "qemu-img" is available.
-
bool mkimg(const char *file, const char *fmt, unsigned size_mb)
Parameters
const char *fileFile name of the image that should be created
const char *fmtFormat, e.g. "qcow2" or "raw"
unsigned size_mbSize of the image in megabytes
Description
Create a disk image with qemu-img. Note that the QTEST_QEMU_IMG environment variable must point to the qemu-img file.
Return
true if the image has been created successfully.
-
bool qtest_verbose(const char *domain)
Parameters
const char *domainThe logging domain
Description
Read the QTEST_LOG environment variable and return whether the specified domain is enabled for verbose logging. Enable specific logging domains with QTEST_LOG=<domain> or use QTEST_LOG=-<domain> to enable all domains except for the specific one.
QTest 支持的环境变量
部分环境变量指定测试使用的产物,主要是 QEMU 二进制文件,或控制测试行为。 构建系统会自动设置,但手动测试时修改它们可能很有用。 除各测试专用变量外,QTest 识别以下变量:
QTEST_QEMU_BINARYQEMU 程序本身,通常为 qemu-system-<arch>。
QTEST_QEMU_ARGSQEMU 命令行的额外参数。
QTEST_QEMU_IMGqemu-img 程序。
QTEST_QEMU_STORAGE_DAEMON_BINARYqemu-storage-daemon 程序。
QTEST_STOP在继续执行前,使用 SIGSTOP 暂停 QEMU 进程。
QTEST_LOG以逗号分隔的详细日志域列表,目前包括:
qmpQMP 命令调用的详细输出。
qtestQTest 操作的详细输出。
test测试自身的详细输出。
在域名前加
-,表示启用其他所有域的详细日志,同时禁用指定域。