e1000e: Combine rx traces
[qemu/kevin.git] / tests / qtest / libqtest-single.h
blob851724cbcb8dea905562cda134f63b60b187dafa
1 /*
2 * QTest - wrappers for test with single QEMU instances
4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
6 * Copyright SUSE LINUX Products GmbH 2013
8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 * See the COPYING file in the top-level directory.
11 #ifndef LIBQTEST_SINGLE_H
12 #define LIBQTEST_SINGLE_H
14 #include "libqtest.h"
16 #ifndef _WIN32
17 QTestState *global_qtest __attribute__((common, weak));
18 #else
19 __declspec(selectany) QTestState *global_qtest;
20 #endif
22 /**
23 * qtest_start:
24 * @args: other arguments to pass to QEMU
26 * Start QEMU and assign the resulting #QTestState to a global variable.
27 * The global variable is used by "shortcut" functions documented below.
29 * Returns: #QTestState instance.
31 static inline QTestState *qtest_start(const char *args)
33 global_qtest = qtest_init(args);
34 return global_qtest;
37 /**
38 * qtest_end:
40 * Shut down the QEMU process started by qtest_start().
42 static inline void qtest_end(void)
44 if (!global_qtest) {
45 return;
47 qtest_quit(global_qtest);
48 global_qtest = NULL;
51 /**
52 * qmp:
53 * @fmt...: QMP message to send to qemu, formatted like
54 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
55 * supported after '%'.
57 * Sends a QMP message to QEMU and returns the response.
59 G_GNUC_PRINTF(1, 2)
60 static inline QDict *qmp(const char *fmt, ...)
62 va_list ap;
63 QDict *response;
65 va_start(ap, fmt);
66 response = qtest_vqmp(global_qtest, fmt, ap);
67 va_end(ap);
68 return response;
71 /**
72 * qmp_eventwait:
73 * @s: #event event to wait for.
75 * Continuously polls for QMP responses until it receives the desired event.
77 static inline void qmp_eventwait(const char *event)
79 return qtest_qmp_eventwait(global_qtest, event);
82 /**
83 * get_irq:
84 * @num: Interrupt to observe.
86 * Returns: The level of the @num interrupt.
88 static inline bool get_irq(int num)
90 return qtest_get_irq(global_qtest, num);
93 /**
94 * outb:
95 * @addr: I/O port to write to.
96 * @value: Value being written.
98 * Write an 8-bit value to an I/O port.
100 static inline void outb(uint16_t addr, uint8_t value)
102 qtest_outb(global_qtest, addr, value);
106 * outw:
107 * @addr: I/O port to write to.
108 * @value: Value being written.
110 * Write a 16-bit value to an I/O port.
112 static inline void outw(uint16_t addr, uint16_t value)
114 qtest_outw(global_qtest, addr, value);
118 * outl:
119 * @addr: I/O port to write to.
120 * @value: Value being written.
122 * Write a 32-bit value to an I/O port.
124 static inline void outl(uint16_t addr, uint32_t value)
126 qtest_outl(global_qtest, addr, value);
130 * inb:
131 * @addr: I/O port to read from.
133 * Reads an 8-bit value from an I/O port.
135 * Returns: Value read.
137 static inline uint8_t inb(uint16_t addr)
139 return qtest_inb(global_qtest, addr);
143 * inw:
144 * @addr: I/O port to read from.
146 * Reads a 16-bit value from an I/O port.
148 * Returns: Value read.
150 static inline uint16_t inw(uint16_t addr)
152 return qtest_inw(global_qtest, addr);
156 * inl:
157 * @addr: I/O port to read from.
159 * Reads a 32-bit value from an I/O port.
161 * Returns: Value read.
163 static inline uint32_t inl(uint16_t addr)
165 return qtest_inl(global_qtest, addr);
169 * writeb:
170 * @addr: Guest address to write to.
171 * @value: Value being written.
173 * Writes an 8-bit value to guest memory.
175 static inline void writeb(uint64_t addr, uint8_t value)
177 qtest_writeb(global_qtest, addr, value);
181 * writew:
182 * @addr: Guest address to write to.
183 * @value: Value being written.
185 * Writes a 16-bit value to guest memory.
187 static inline void writew(uint64_t addr, uint16_t value)
189 qtest_writew(global_qtest, addr, value);
193 * writel:
194 * @addr: Guest address to write to.
195 * @value: Value being written.
197 * Writes a 32-bit value to guest memory.
199 static inline void writel(uint64_t addr, uint32_t value)
201 qtest_writel(global_qtest, addr, value);
205 * writeq:
206 * @addr: Guest address to write to.
207 * @value: Value being written.
209 * Writes a 64-bit value to guest memory.
211 static inline void writeq(uint64_t addr, uint64_t value)
213 qtest_writeq(global_qtest, addr, value);
217 * readb:
218 * @addr: Guest address to read from.
220 * Reads an 8-bit value from guest memory.
222 * Returns: Value read.
224 static inline uint8_t readb(uint64_t addr)
226 return qtest_readb(global_qtest, addr);
230 * readw:
231 * @addr: Guest address to read from.
233 * Reads a 16-bit value from guest memory.
235 * Returns: Value read.
237 static inline uint16_t readw(uint64_t addr)
239 return qtest_readw(global_qtest, addr);
243 * readl:
244 * @addr: Guest address to read from.
246 * Reads a 32-bit value from guest memory.
248 * Returns: Value read.
250 static inline uint32_t readl(uint64_t addr)
252 return qtest_readl(global_qtest, addr);
256 * readq:
257 * @addr: Guest address to read from.
259 * Reads a 64-bit value from guest memory.
261 * Returns: Value read.
263 static inline uint64_t readq(uint64_t addr)
265 return qtest_readq(global_qtest, addr);
269 * memread:
270 * @addr: Guest address to read from.
271 * @data: Pointer to where memory contents will be stored.
272 * @size: Number of bytes to read.
274 * Read guest memory into a buffer.
276 static inline void memread(uint64_t addr, void *data, size_t size)
278 qtest_memread(global_qtest, addr, data, size);
282 * memwrite:
283 * @addr: Guest address to write to.
284 * @data: Pointer to the bytes that will be written to guest memory.
285 * @size: Number of bytes to write.
287 * Write a buffer to guest memory.
289 static inline void memwrite(uint64_t addr, const void *data, size_t size)
291 qtest_memwrite(global_qtest, addr, data, size);
295 * clock_step_next:
297 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
299 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
301 static inline int64_t clock_step_next(void)
303 return qtest_clock_step_next(global_qtest);
307 * clock_step:
308 * @step: Number of nanoseconds to advance the clock by.
310 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
312 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
314 static inline int64_t clock_step(int64_t step)
316 return qtest_clock_step(global_qtest, step);
319 #endif