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 QTestState
*qtest_init(const char *extra_args
);
34 * @s: QTestState instance to operate on.
36 * Shut down the QEMU process associated to @s.
38 void qtest_quit(QTestState
*s
);
42 * @s: QTestState instance to operate on.
43 * @fmt...: QMP message to send to qemu
45 * Sends a QMP message to QEMU
47 void qtest_qmp(QTestState
*s
, const char *fmt
, ...);
51 * @s: QTestState instance to operate on.
52 * @num: Interrupt to observe.
54 * Return the level of the @num interrupt.
56 bool qtest_get_irq(QTestState
*s
, int num
);
59 * qtest_irq_intercept_in:
60 * @s: QTestState instance to operate on.
61 * @string: QOM path of a device.
63 * Associate qtest irqs with the GPIO-in pins of the device
64 * whose path is specified by @string.
66 void qtest_irq_intercept_in(QTestState
*s
, const char *string
);
69 * qtest_irq_intercept_out:
70 * @s: QTestState instance to operate on.
71 * @string: QOM path of a device.
73 * Associate qtest irqs with the GPIO-out pins of the device
74 * whose path is specified by @string.
76 void qtest_irq_intercept_out(QTestState
*s
, const char *string
);
80 * @s: QTestState instance to operate on.
81 * @addr: I/O port to write to.
82 * @value: Value being written.
84 * Write an 8-bit value to an I/O port.
86 void qtest_outb(QTestState
*s
, uint16_t addr
, uint8_t value
);
90 * @s: QTestState instance to operate on.
91 * @addr: I/O port to write to.
92 * @value: Value being written.
94 * Write a 16-bit value to an I/O port.
96 void qtest_outw(QTestState
*s
, uint16_t addr
, uint16_t value
);
100 * @s: QTestState instance to operate on.
101 * @addr: I/O port to write to.
102 * @value: Value being written.
104 * Write a 32-bit value to an I/O port.
106 void qtest_outl(QTestState
*s
, uint16_t addr
, uint32_t value
);
110 * @s: QTestState instance to operate on.
111 * @addr: I/O port to read from.
113 * Returns an 8-bit value from an I/O port.
115 uint8_t qtest_inb(QTestState
*s
, uint16_t addr
);
119 * @s: QTestState instance to operate on.
120 * @addr: I/O port to read from.
122 * Returns a 16-bit value from an I/O port.
124 uint16_t qtest_inw(QTestState
*s
, uint16_t addr
);
128 * @s: QTestState instance to operate on.
129 * @addr: I/O port to read from.
131 * Returns a 32-bit value from an I/O port.
133 uint32_t qtest_inl(QTestState
*s
, uint16_t addr
);
137 * @s: QTestState instance to operate on.
138 * @addr: Guest address to read from.
139 * @data: Pointer to where memory contents will be stored.
140 * @size: Number of bytes to read.
142 * Read guest memory into a buffer.
144 void qtest_memread(QTestState
*s
, uint64_t addr
, void *data
, size_t size
);
148 * @s: QTestState instance to operate on.
149 * @addr: Guest address to write to.
150 * @data: Pointer to the bytes that will be written to guest memory.
151 * @size: Number of bytes to write.
153 * Write a buffer to guest memory.
155 void qtest_memwrite(QTestState
*s
, uint64_t addr
, const void *data
, size_t size
);
158 * qtest_clock_step_next:
159 * @s: QTestState instance to operate on.
161 * Advance the vm_clock to the next deadline. Return the current
162 * value of the vm_clock in nanoseconds.
164 int64_t qtest_clock_step_next(QTestState
*s
);
168 * @s: QTestState instance to operate on.
169 * @step: Number of nanoseconds to advance the clock by.
171 * Advance the vm_clock by @step nanoseconds. Return the current
172 * value of the vm_clock in nanoseconds.
174 int64_t qtest_clock_step(QTestState
*s
, int64_t step
);
178 * @s: QTestState instance to operate on.
179 * @val: Nanoseconds value to advance the clock to.
181 * Advance the vm_clock to @val nanoseconds since the VM was launched.
182 * Return the current value of the vm_clock in nanoseconds.
184 int64_t qtest_clock_set(QTestState
*s
, int64_t val
);
189 * Returns the architecture for the QEMU executable under test.
191 const char *qtest_get_arch(void);
195 * @str: Test case path.
196 * @fn: Test case function
198 * Add a GTester testcase with the given name and function.
199 * The path is prefixed with the architecture under test, as
200 * returned by qtest_get_arch.
202 void qtest_add_func(const char *str
, void (*fn
));
206 * @args: other arguments to pass to QEMU
208 * Start QEMU and assign the resulting QTestState to a global variable.
209 * The global variable is used by "shortcut" macros documented below.
211 #define qtest_start(args) ( \
212 global_qtest = qtest_init((args)) \
217 * @fmt...: QMP message to send to qemu
219 * Sends a QMP message to QEMU
221 #define qmp(fmt, ...) qtest_qmp(global_qtest, fmt, ## __VA_ARGS__)
225 * @num: Interrupt to observe.
227 * Return the level of the @num interrupt.
229 #define get_irq(num) qtest_get_irq(global_qtest, num)
233 * @string: QOM path of a device.
235 * Associate qtest irqs with the GPIO-in pins of the device
236 * whose path is specified by @string.
238 #define irq_intercept_in(string) qtest_irq_intercept_in(global_qtest, string)
241 * qtest_irq_intercept_out:
242 * @string: QOM path of a device.
244 * Associate qtest irqs with the GPIO-out pins of the device
245 * whose path is specified by @string.
247 #define irq_intercept_out(string) qtest_irq_intercept_out(global_qtest, string)
251 * @addr: I/O port to write to.
252 * @value: Value being written.
254 * Write an 8-bit value to an I/O port.
256 #define outb(addr, val) qtest_outb(global_qtest, addr, val)
260 * @addr: I/O port to write to.
261 * @value: Value being written.
263 * Write a 16-bit value to an I/O port.
265 #define outw(addr, val) qtest_outw(global_qtest, addr, val)
269 * @addr: I/O port to write to.
270 * @value: Value being written.
272 * Write a 32-bit value to an I/O port.
274 #define outl(addr, val) qtest_outl(global_qtest, addr, val)
278 * @addr: I/O port to read from.
280 * Returns an 8-bit value from an I/O port.
282 #define inb(addr) qtest_inb(global_qtest, addr)
286 * @addr: I/O port to read from.
288 * Returns a 16-bit value from an I/O port.
290 #define inw(addr) qtest_inw(global_qtest, addr)
294 * @addr: I/O port to read from.
296 * Returns a 32-bit value from an I/O port.
298 #define inl(addr) qtest_inl(global_qtest, addr)
302 * @addr: Guest address to read from.
303 * @data: Pointer to where memory contents will be stored.
304 * @size: Number of bytes to read.
306 * Read guest memory into a buffer.
308 #define memread(addr, data, size) qtest_memread(global_qtest, addr, data, size)
312 * @addr: Guest address to write to.
313 * @data: Pointer to the bytes that will be written to guest memory.
314 * @size: Number of bytes to write.
316 * Write a buffer to guest memory.
318 #define memwrite(addr, data, size) qtest_memwrite(global_qtest, addr, data, size)
323 * Advance the vm_clock to the next deadline. Return the current
324 * value of the vm_clock in nanoseconds.
326 #define clock_step_next() qtest_clock_step_next(global_qtest)
330 * @step: Number of nanoseconds to advance the clock by.
332 * Advance the vm_clock by @step nanoseconds. Return the current
333 * value of the vm_clock in nanoseconds.
335 #define clock_step(step) qtest_clock_step(global_qtest, step)
339 * @val: Nanoseconds value to advance the clock to.
341 * Advance the vm_clock to @val nanoseconds since the VM was launched.
342 * Return the current value of the vm_clock in nanoseconds.
344 #define clock_set(val) qtest_clock_set(global_qtest, val)