]>
git.proxmox.com Git - qemu.git/blob - tests/libqtest.h
a111c9cddbb5307cdf616bcec3522c84a10bd950
4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Paolo Bonzini <pbonzini@redhat.com>
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
20 #include <sys/types.h>
22 typedef struct QTestState QTestState
;
24 extern QTestState
*global_qtest
;
28 * @extra_args: other arguments to pass to QEMU.
30 * Returns: #QTestState instance.
32 QTestState
*qtest_init(const char *extra_args
);
36 * @s: #QTestState instance to operate on.
38 * Shut down the QEMU process associated to @s.
40 void qtest_quit(QTestState
*s
);
44 * @s: #QTestState instance to operate on.
45 * @fmt...: QMP message to send to qemu
47 * Sends a QMP message to QEMU
49 void qtest_qmp(QTestState
*s
, const char *fmt
, ...);
53 * @s: #QTestState instance to operate on.
54 * @num: Interrupt to observe.
56 * Returns: The level of the @num interrupt.
58 bool qtest_get_irq(QTestState
*s
, int num
);
61 * qtest_irq_intercept_in:
62 * @s: #QTestState instance to operate on.
63 * @string: QOM path of a device.
65 * Associate qtest irqs with the GPIO-in pins of the device
66 * whose path is specified by @string.
68 void qtest_irq_intercept_in(QTestState
*s
, const char *string
);
71 * qtest_irq_intercept_out:
72 * @s: #QTestState instance to operate on.
73 * @string: QOM path of a device.
75 * Associate qtest irqs with the GPIO-out pins of the device
76 * whose path is specified by @string.
78 void qtest_irq_intercept_out(QTestState
*s
, const char *string
);
82 * @s: #QTestState instance to operate on.
83 * @addr: I/O port to write to.
84 * @value: Value being written.
86 * Write an 8-bit value to an I/O port.
88 void qtest_outb(QTestState
*s
, uint16_t addr
, uint8_t value
);
92 * @s: #QTestState instance to operate on.
93 * @addr: I/O port to write to.
94 * @value: Value being written.
96 * Write a 16-bit value to an I/O port.
98 void qtest_outw(QTestState
*s
, uint16_t addr
, uint16_t value
);
102 * @s: #QTestState instance to operate on.
103 * @addr: I/O port to write to.
104 * @value: Value being written.
106 * Write a 32-bit value to an I/O port.
108 void qtest_outl(QTestState
*s
, uint16_t addr
, uint32_t value
);
112 * @s: #QTestState instance to operate on.
113 * @addr: I/O port to read from.
115 * Returns an 8-bit value from an I/O port.
117 uint8_t qtest_inb(QTestState
*s
, uint16_t addr
);
121 * @s: #QTestState instance to operate on.
122 * @addr: I/O port to read from.
124 * Returns a 16-bit value from an I/O port.
126 uint16_t qtest_inw(QTestState
*s
, uint16_t addr
);
130 * @s: #QTestState instance to operate on.
131 * @addr: I/O port to read from.
133 * Returns a 32-bit value from an I/O port.
135 uint32_t qtest_inl(QTestState
*s
, uint16_t addr
);
139 * @s: #QTestState instance to operate on.
140 * @addr: Guest address to read from.
141 * @data: Pointer to where memory contents will be stored.
142 * @size: Number of bytes to read.
144 * Read guest memory into a buffer.
146 void qtest_memread(QTestState
*s
, uint64_t addr
, void *data
, size_t size
);
150 * @s: #QTestState instance to operate on.
151 * @addr: Guest address to write to.
152 * @data: Pointer to the bytes that will be written to guest memory.
153 * @size: Number of bytes to write.
155 * Write a buffer to guest memory.
157 void qtest_memwrite(QTestState
*s
, uint64_t addr
, const void *data
, size_t size
);
160 * qtest_clock_step_next:
161 * @s: #QTestState instance to operate on.
163 * Advance the vm_clock to the next deadline.
165 * Returns: The current value of the vm_clock in nanoseconds.
167 int64_t qtest_clock_step_next(QTestState
*s
);
171 * @s: QTestState instance to operate on.
172 * @step: Number of nanoseconds to advance the clock by.
174 * Advance the vm_clock by @step nanoseconds.
176 * Returns: The current value of the vm_clock in nanoseconds.
178 int64_t qtest_clock_step(QTestState
*s
, int64_t step
);
182 * @s: QTestState instance to operate on.
183 * @val: Nanoseconds value to advance the clock to.
185 * Advance the vm_clock to @val nanoseconds since the VM was launched.
187 * Returns: The current value of the vm_clock in nanoseconds.
189 int64_t qtest_clock_set(QTestState
*s
, int64_t val
);
194 * Returns: The architecture for the QEMU executable under test.
196 const char *qtest_get_arch(void);
200 * @str: Test case path.
201 * @fn: Test case function
203 * Add a GTester testcase with the given name and function.
204 * The path is prefixed with the architecture under test, as
205 * returned by qtest_get_arch().
207 void qtest_add_func(const char *str
, void (*fn
));
211 * @args: other arguments to pass to QEMU
213 * Start QEMU and assign the resulting #QTestState to a global variable.
214 * The global variable is used by "shortcut" functions documented below.
216 * Returns: #QTestState instance.
218 static inline QTestState
*qtest_start(const char *args
)
220 global_qtest
= qtest_init(args
);
226 * @fmt...: QMP message to send to qemu
228 * Sends a QMP message to QEMU
230 #define qmp(fmt, ...) qtest_qmp(global_qtest, fmt, ## __VA_ARGS__)
234 * @num: Interrupt to observe.
236 * Returns: The level of the @num interrupt.
238 static inline bool get_irq(int num
)
240 return qtest_get_irq(global_qtest
, num
);
245 * @string: QOM path of a device.
247 * Associate qtest irqs with the GPIO-in pins of the device
248 * whose path is specified by @string.
250 static inline void irq_intercept_in(const char *string
)
252 qtest_irq_intercept_in(global_qtest
, string
);
256 * qtest_irq_intercept_out:
257 * @string: QOM path of a device.
259 * Associate qtest irqs with the GPIO-out pins of the device
260 * whose path is specified by @string.
262 static inline void irq_intercept_out(const char *string
)
264 qtest_irq_intercept_out(global_qtest
, string
);
269 * @addr: I/O port to write to.
270 * @value: Value being written.
272 * Write an 8-bit value to an I/O port.
274 static inline void outb(uint16_t addr
, uint8_t value
)
276 qtest_outb(global_qtest
, addr
, value
);
281 * @addr: I/O port to write to.
282 * @value: Value being written.
284 * Write a 16-bit value to an I/O port.
286 static inline void outw(uint16_t addr
, uint16_t value
)
288 qtest_outw(global_qtest
, addr
, value
);
293 * @addr: I/O port to write to.
294 * @value: Value being written.
296 * Write a 32-bit value to an I/O port.
298 static inline void outl(uint16_t addr
, uint32_t value
)
300 qtest_outl(global_qtest
, addr
, value
);
305 * @addr: I/O port to read from.
307 * Reads an 8-bit value from an I/O port.
309 * Returns: Value read.
311 static inline uint8_t inb(uint16_t addr
)
313 return qtest_inb(global_qtest
, addr
);
318 * @addr: I/O port to read from.
320 * Reads a 16-bit value from an I/O port.
322 * Returns: Value read.
324 static inline uint16_t inw(uint16_t addr
)
326 return qtest_inw(global_qtest
, addr
);
331 * @addr: I/O port to read from.
333 * Reads a 32-bit value from an I/O port.
335 * Returns: Value read.
337 static inline uint32_t inl(uint16_t addr
)
339 return qtest_inl(global_qtest
, addr
);
344 * @addr: Guest address to read from.
345 * @data: Pointer to where memory contents will be stored.
346 * @size: Number of bytes to read.
348 * Read guest memory into a buffer.
350 static inline void memread(uint64_t addr
, void *data
, size_t size
)
352 qtest_memread(global_qtest
, addr
, data
, size
);
357 * @addr: Guest address to write to.
358 * @data: Pointer to the bytes that will be written to guest memory.
359 * @size: Number of bytes to write.
361 * Write a buffer to guest memory.
363 static inline void memwrite(uint64_t addr
, const void *data
, size_t size
)
365 qtest_memwrite(global_qtest
, addr
, data
, size
);
371 * Advance the vm_clock to the next deadline.
373 * Returns: The current value of the vm_clock in nanoseconds.
375 static inline int64_t clock_step_next(void)
377 return qtest_clock_step_next(global_qtest
);
382 * @step: Number of nanoseconds to advance the clock by.
384 * Advance the vm_clock by @step nanoseconds.
386 * Returns: The current value of the vm_clock in nanoseconds.
388 static inline int64_t clock_step(int64_t step
)
390 return qtest_clock_step(global_qtest
, step
);
395 * @val: Nanoseconds value to advance the clock to.
397 * Advance the vm_clock to @val nanoseconds since the VM was launched.
399 * Returns: The current value of the vm_clock in nanoseconds.
401 static inline int64_t clock_set(int64_t val
)
403 return qtest_clock_set(global_qtest
, val
);