acpitable: open the data file in binary mode
[qemu/ar7.git] / tests / libqtest.h
blobc8ade856fc739e5e15a111f2c091d39b8b318355
1 /*
2 * QTest
4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
7 * Authors:
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.
15 #ifndef LIBQTEST_H
16 #define LIBQTEST_H
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include <sys/types.h>
22 typedef struct QTestState QTestState;
24 extern QTestState *global_qtest;
26 /**
27 * qtest_init:
28 * @extra_args: other arguments to pass to QEMU.
30 QTestState *qtest_init(const char *extra_args);
32 /**
33 * qtest_quit:
34 * @s: QTestState instance to operate on.
36 * Shut down the QEMU process associated to @s.
38 void qtest_quit(QTestState *s);
40 /**
41 * qtest_qmp:
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, ...);
49 /**
50 * qtest_get_irq:
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);
58 /**
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);
68 /**
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);
78 /**
79 * qtest_outb:
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);
88 /**
89 * qtest_outw:
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);
98 /**
99 * qtest_outl:
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);
109 * qtest_inb:
110 * @s: QTestState instance to operate on.
111 * @addr: I/O port to read from.
112 * @value: Value being written.
114 * Returns an 8-bit value from an I/O port.
116 uint8_t qtest_inb(QTestState *s, uint16_t addr);
119 * qtest_inw:
120 * @s: QTestState instance to operate on.
121 * @addr: I/O port to read from.
122 * @value: Value being written.
124 * Returns a 16-bit value from an I/O port.
126 uint16_t qtest_inw(QTestState *s, uint16_t addr);
129 * qtest_inl:
130 * @s: QTestState instance to operate on.
131 * @addr: I/O port to read from.
132 * @value: Value being written.
134 * Returns a 32-bit value from an I/O port.
136 uint32_t qtest_inl(QTestState *s, uint16_t addr);
139 * qtest_memread:
140 * @s: QTestState instance to operate on.
141 * @addr: Guest address to read from.
142 * @data: Pointer to where memory contents will be stored.
143 * @size: Number of bytes to read.
145 * Read guest memory into a buffer.
147 void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
150 * qtest_memwrite:
151 * @s: QTestState instance to operate on.
152 * @addr: Guest address to write to.
153 * @data: Pointer to the bytes that will be written to guest memory.
154 * @size: Number of bytes to write.
156 * Write a buffer to guest memory.
158 void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
161 * qtest_clock_step_next:
162 * @s: QTestState instance to operate on.
164 * Advance the vm_clock to the next deadline. Return the current
165 * value of the vm_clock in nanoseconds.
167 int64_t qtest_clock_step_next(QTestState *s);
170 * qtest_clock_step:
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. Return the current
175 * value of the vm_clock in nanoseconds.
177 int64_t qtest_clock_step(QTestState *s, int64_t step);
180 * qtest_clock_set:
181 * @s: QTestState instance to operate on.
182 * @val: Nanoseconds value to advance the clock to.
184 * Advance the vm_clock to @val nanoseconds since the VM was launched.
185 * Return the current value of the vm_clock in nanoseconds.
187 int64_t qtest_clock_set(QTestState *s, int64_t val);
190 * qtest_get_arch:
192 * Returns the architecture for the QEMU executable under test.
194 const char *qtest_get_arch(void);
197 * qtest_add_func:
198 * @str: Test case path.
199 * @fn: Test case function
201 * Add a GTester testcase with the given name and function.
202 * The path is prefixed with the architecture under test, as
203 * returned by qtest_get_arch.
205 void qtest_add_func(const char *str, void (*fn));
208 * qtest_start:
209 * @args: other arguments to pass to QEMU
211 * Start QEMU and assign the resulting QTestState to a global variable.
212 * The global variable is used by "shortcut" macros documented below.
214 #define qtest_start(args) ( \
215 global_qtest = qtest_init((args)) \
219 * qmp:
220 * @fmt...: QMP message to send to qemu
222 * Sends a QMP message to QEMU
224 #define qmp(fmt, ...) qtest_qmp(global_qtest, fmt, ## __VA_ARGS__)
227 * get_irq:
228 * @num: Interrupt to observe.
230 * Return the level of the @num interrupt.
232 #define get_irq(num) qtest_get_irq(global_qtest, num)
235 * irq_intercept_in:
236 * @string: QOM path of a device.
238 * Associate qtest irqs with the GPIO-in pins of the device
239 * whose path is specified by @string.
241 #define irq_intercept_in(string) qtest_irq_intercept_in(global_qtest, string)
244 * qtest_irq_intercept_out:
245 * @string: QOM path of a device.
247 * Associate qtest irqs with the GPIO-out pins of the device
248 * whose path is specified by @string.
250 #define irq_intercept_out(string) qtest_irq_intercept_out(global_qtest, string)
253 * outb:
254 * @addr: I/O port to write to.
255 * @value: Value being written.
257 * Write an 8-bit value to an I/O port.
259 #define outb(addr, val) qtest_outb(global_qtest, addr, val)
262 * outw:
263 * @addr: I/O port to write to.
264 * @value: Value being written.
266 * Write a 16-bit value to an I/O port.
268 #define outw(addr, val) qtest_outw(global_qtest, addr, val)
271 * outl:
272 * @addr: I/O port to write to.
273 * @value: Value being written.
275 * Write a 32-bit value to an I/O port.
277 #define outl(addr, val) qtest_outl(global_qtest, addr, val)
280 * inb:
281 * @addr: I/O port to read from.
282 * @value: Value being written.
284 * Returns an 8-bit value from an I/O port.
286 #define inb(addr) qtest_inb(global_qtest, addr)
289 * inw:
290 * @addr: I/O port to read from.
291 * @value: Value being written.
293 * Returns a 16-bit value from an I/O port.
295 #define inw(addr) qtest_inw(global_qtest, addr)
298 * inl:
299 * @addr: I/O port to read from.
300 * @value: Value being written.
302 * Returns a 32-bit value from an I/O port.
304 #define inl(addr) qtest_inl(global_qtest, addr)
307 * memread:
308 * @addr: Guest address to read from.
309 * @data: Pointer to where memory contents will be stored.
310 * @size: Number of bytes to read.
312 * Read guest memory into a buffer.
314 #define memread(addr, data, size) qtest_memread(global_qtest, addr, data, size)
317 * memwrite:
318 * @addr: Guest address to write to.
319 * @data: Pointer to the bytes that will be written to guest memory.
320 * @size: Number of bytes to write.
322 * Write a buffer to guest memory.
324 #define memwrite(addr, data, size) qtest_memwrite(global_qtest, addr, data, size)
327 * clock_step_next:
329 * Advance the vm_clock to the next deadline. Return the current
330 * value of the vm_clock in nanoseconds.
332 #define clock_step_next() qtest_clock_step_next(global_qtest)
335 * clock_step:
336 * @step: Number of nanoseconds to advance the clock by.
338 * Advance the vm_clock by @step nanoseconds. Return the current
339 * value of the vm_clock in nanoseconds.
341 #define clock_step(step) qtest_clock_step(global_qtest, step)
344 * clock_set:
345 * @val: Nanoseconds value to advance the clock to.
347 * Advance the vm_clock to @val nanoseconds since the VM was launched.
348 * Return the current value of the vm_clock in nanoseconds.
350 #define clock_set(val) qtest_clock_set(global_qtest, val)
352 #endif