]> git.proxmox.com Git - qemu.git/blob - tests/libqtest.h
qga: set umask 0077 when daemonizing (CVE-2013-2007)
[qemu.git] / tests / libqtest.h
1 /*
2 * QTest
3 *
4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
6 *
7 * Authors:
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Paolo Bonzini <pbonzini@redhat.com>
10 *
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.
13 *
14 */
15 #ifndef LIBQTEST_H
16 #define LIBQTEST_H
17
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include <sys/types.h>
21
22 typedef struct QTestState QTestState;
23
24 extern QTestState *global_qtest;
25
26 /**
27 * qtest_init:
28 * @extra_args: other arguments to pass to QEMU.
29 */
30 QTestState *qtest_init(const char *extra_args);
31
32 /**
33 * qtest_quit:
34 * @s: QTestState instance to operate on.
35 *
36 * Shut down the QEMU process associated to @s.
37 */
38 void qtest_quit(QTestState *s);
39
40 /**
41 * qtest_qmp:
42 * @s: QTestState instance to operate on.
43 * @fmt...: QMP message to send to qemu
44 *
45 * Sends a QMP message to QEMU
46 */
47 void qtest_qmp(QTestState *s, const char *fmt, ...);
48
49 /**
50 * qtest_get_irq:
51 * @s: QTestState instance to operate on.
52 * @num: Interrupt to observe.
53 *
54 * Return the level of the @num interrupt.
55 */
56 bool qtest_get_irq(QTestState *s, int num);
57
58 /**
59 * qtest_irq_intercept_in:
60 * @s: QTestState instance to operate on.
61 * @string: QOM path of a device.
62 *
63 * Associate qtest irqs with the GPIO-in pins of the device
64 * whose path is specified by @string.
65 */
66 void qtest_irq_intercept_in(QTestState *s, const char *string);
67
68 /**
69 * qtest_irq_intercept_out:
70 * @s: QTestState instance to operate on.
71 * @string: QOM path of a device.
72 *
73 * Associate qtest irqs with the GPIO-out pins of the device
74 * whose path is specified by @string.
75 */
76 void qtest_irq_intercept_out(QTestState *s, const char *string);
77
78 /**
79 * qtest_outb:
80 * @s: QTestState instance to operate on.
81 * @addr: I/O port to write to.
82 * @value: Value being written.
83 *
84 * Write an 8-bit value to an I/O port.
85 */
86 void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
87
88 /**
89 * qtest_outw:
90 * @s: QTestState instance to operate on.
91 * @addr: I/O port to write to.
92 * @value: Value being written.
93 *
94 * Write a 16-bit value to an I/O port.
95 */
96 void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
97
98 /**
99 * qtest_outl:
100 * @s: QTestState instance to operate on.
101 * @addr: I/O port to write to.
102 * @value: Value being written.
103 *
104 * Write a 32-bit value to an I/O port.
105 */
106 void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
107
108 /**
109 * qtest_inb:
110 * @s: QTestState instance to operate on.
111 * @addr: I/O port to read from.
112 *
113 * Returns an 8-bit value from an I/O port.
114 */
115 uint8_t qtest_inb(QTestState *s, uint16_t addr);
116
117 /**
118 * qtest_inw:
119 * @s: QTestState instance to operate on.
120 * @addr: I/O port to read from.
121 *
122 * Returns a 16-bit value from an I/O port.
123 */
124 uint16_t qtest_inw(QTestState *s, uint16_t addr);
125
126 /**
127 * qtest_inl:
128 * @s: QTestState instance to operate on.
129 * @addr: I/O port to read from.
130 *
131 * Returns a 32-bit value from an I/O port.
132 */
133 uint32_t qtest_inl(QTestState *s, uint16_t addr);
134
135 /**
136 * qtest_memread:
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.
141 *
142 * Read guest memory into a buffer.
143 */
144 void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
145
146 /**
147 * qtest_memwrite:
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.
152 *
153 * Write a buffer to guest memory.
154 */
155 void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
156
157 /**
158 * qtest_clock_step_next:
159 * @s: QTestState instance to operate on.
160 *
161 * Advance the vm_clock to the next deadline. Return the current
162 * value of the vm_clock in nanoseconds.
163 */
164 int64_t qtest_clock_step_next(QTestState *s);
165
166 /**
167 * qtest_clock_step:
168 * @s: QTestState instance to operate on.
169 * @step: Number of nanoseconds to advance the clock by.
170 *
171 * Advance the vm_clock by @step nanoseconds. Return the current
172 * value of the vm_clock in nanoseconds.
173 */
174 int64_t qtest_clock_step(QTestState *s, int64_t step);
175
176 /**
177 * qtest_clock_set:
178 * @s: QTestState instance to operate on.
179 * @val: Nanoseconds value to advance the clock to.
180 *
181 * Advance the vm_clock to @val nanoseconds since the VM was launched.
182 * Return the current value of the vm_clock in nanoseconds.
183 */
184 int64_t qtest_clock_set(QTestState *s, int64_t val);
185
186 /**
187 * qtest_get_arch:
188 *
189 * Returns the architecture for the QEMU executable under test.
190 */
191 const char *qtest_get_arch(void);
192
193 /**
194 * qtest_add_func:
195 * @str: Test case path.
196 * @fn: Test case function
197 *
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.
201 */
202 void qtest_add_func(const char *str, void (*fn));
203
204 /**
205 * qtest_start:
206 * @args: other arguments to pass to QEMU
207 *
208 * Start QEMU and assign the resulting QTestState to a global variable.
209 * The global variable is used by "shortcut" macros documented below.
210 */
211 #define qtest_start(args) ( \
212 global_qtest = qtest_init((args)) \
213 )
214
215 /**
216 * qmp:
217 * @fmt...: QMP message to send to qemu
218 *
219 * Sends a QMP message to QEMU
220 */
221 #define qmp(fmt, ...) qtest_qmp(global_qtest, fmt, ## __VA_ARGS__)
222
223 /**
224 * get_irq:
225 * @num: Interrupt to observe.
226 *
227 * Return the level of the @num interrupt.
228 */
229 #define get_irq(num) qtest_get_irq(global_qtest, num)
230
231 /**
232 * irq_intercept_in:
233 * @string: QOM path of a device.
234 *
235 * Associate qtest irqs with the GPIO-in pins of the device
236 * whose path is specified by @string.
237 */
238 #define irq_intercept_in(string) qtest_irq_intercept_in(global_qtest, string)
239
240 /**
241 * qtest_irq_intercept_out:
242 * @string: QOM path of a device.
243 *
244 * Associate qtest irqs with the GPIO-out pins of the device
245 * whose path is specified by @string.
246 */
247 #define irq_intercept_out(string) qtest_irq_intercept_out(global_qtest, string)
248
249 /**
250 * outb:
251 * @addr: I/O port to write to.
252 * @value: Value being written.
253 *
254 * Write an 8-bit value to an I/O port.
255 */
256 #define outb(addr, val) qtest_outb(global_qtest, addr, val)
257
258 /**
259 * outw:
260 * @addr: I/O port to write to.
261 * @value: Value being written.
262 *
263 * Write a 16-bit value to an I/O port.
264 */
265 #define outw(addr, val) qtest_outw(global_qtest, addr, val)
266
267 /**
268 * outl:
269 * @addr: I/O port to write to.
270 * @value: Value being written.
271 *
272 * Write a 32-bit value to an I/O port.
273 */
274 #define outl(addr, val) qtest_outl(global_qtest, addr, val)
275
276 /**
277 * inb:
278 * @addr: I/O port to read from.
279 *
280 * Returns an 8-bit value from an I/O port.
281 */
282 #define inb(addr) qtest_inb(global_qtest, addr)
283
284 /**
285 * inw:
286 * @addr: I/O port to read from.
287 *
288 * Returns a 16-bit value from an I/O port.
289 */
290 #define inw(addr) qtest_inw(global_qtest, addr)
291
292 /**
293 * inl:
294 * @addr: I/O port to read from.
295 *
296 * Returns a 32-bit value from an I/O port.
297 */
298 #define inl(addr) qtest_inl(global_qtest, addr)
299
300 /**
301 * memread:
302 * @addr: Guest address to read from.
303 * @data: Pointer to where memory contents will be stored.
304 * @size: Number of bytes to read.
305 *
306 * Read guest memory into a buffer.
307 */
308 #define memread(addr, data, size) qtest_memread(global_qtest, addr, data, size)
309
310 /**
311 * memwrite:
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.
315 *
316 * Write a buffer to guest memory.
317 */
318 #define memwrite(addr, data, size) qtest_memwrite(global_qtest, addr, data, size)
319
320 /**
321 * clock_step_next:
322 *
323 * Advance the vm_clock to the next deadline. Return the current
324 * value of the vm_clock in nanoseconds.
325 */
326 #define clock_step_next() qtest_clock_step_next(global_qtest)
327
328 /**
329 * clock_step:
330 * @step: Number of nanoseconds to advance the clock by.
331 *
332 * Advance the vm_clock by @step nanoseconds. Return the current
333 * value of the vm_clock in nanoseconds.
334 */
335 #define clock_step(step) qtest_clock_step(global_qtest, step)
336
337 /**
338 * clock_set:
339 * @val: Nanoseconds value to advance the clock to.
340 *
341 * Advance the vm_clock to @val nanoseconds since the VM was launched.
342 * Return the current value of the vm_clock in nanoseconds.
343 */
344 #define clock_set(val) qtest_clock_set(global_qtest, val)
345
346 #endif