Skip to content

Commit d832ff9

Browse files
pbo-linarostsquad
authored andcommitted
tests/tcg/plugins: add plugin to test reset and uninstall
We perform a plugin reset, uninstall, and make sure we went through those steps. Signed-off-by: Pierrick Bouvier <[email protected]> Message-Id: <[email protected]> Signed-off-by: Alex Bennée <[email protected]>
1 parent c07cd11 commit d832ff9

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

tests/tcg/plugins/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
t = []
22
if get_option('plugins')
3-
foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'syscall']
3+
foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'reset', 'syscall']
44
if host_os == 'windows'
55
t += shared_module(i, files(i + '.c') + '../../../contrib/plugins/win32_linker.c',
66
include_directories: '../../../include/qemu',

tests/tcg/plugins/reset.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2025 Linaro Ltd
3+
*
4+
* Test the reset/uninstall cycle of a plugin.
5+
*
6+
* SPDX-License-Identifier: GPL-2.0-or-later
7+
*/
8+
#include <glib.h>
9+
10+
#include <qemu-plugin.h>
11+
12+
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
13+
static qemu_plugin_id_t plugin_id;
14+
static bool was_reset;
15+
static bool was_uninstalled;
16+
17+
static void after_uninstall(qemu_plugin_id_t id)
18+
{
19+
g_assert(was_reset && !was_uninstalled);
20+
qemu_plugin_outs("uninstall done\n");
21+
was_uninstalled = true;
22+
}
23+
24+
static void tb_exec_after_reset(unsigned int vcpu_index, void *userdata)
25+
{
26+
g_assert(was_reset && !was_uninstalled);
27+
qemu_plugin_uninstall(plugin_id, after_uninstall);
28+
}
29+
30+
static void tb_trans_after_reset(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
31+
{
32+
g_assert(was_reset && !was_uninstalled);
33+
qemu_plugin_register_vcpu_tb_exec_cb(tb, tb_exec_after_reset,
34+
QEMU_PLUGIN_CB_NO_REGS, NULL);
35+
}
36+
37+
static void after_reset(qemu_plugin_id_t id)
38+
{
39+
g_assert(!was_reset && !was_uninstalled);
40+
qemu_plugin_outs("reset done\n");
41+
was_reset = true;
42+
qemu_plugin_register_vcpu_tb_trans_cb(id, tb_trans_after_reset);
43+
}
44+
45+
static void tb_exec_before_reset(unsigned int vcpu_index, void *userdata)
46+
{
47+
g_assert(!was_reset && !was_uninstalled);
48+
qemu_plugin_reset(plugin_id, after_reset);
49+
}
50+
51+
static void tb_trans_before_reset(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
52+
{
53+
g_assert(!was_reset && !was_uninstalled);
54+
qemu_plugin_register_vcpu_tb_exec_cb(tb, tb_exec_before_reset,
55+
QEMU_PLUGIN_CB_NO_REGS, NULL);
56+
}
57+
58+
QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
59+
const qemu_info_t *info,
60+
int argc, char **argv)
61+
{
62+
plugin_id = id;
63+
qemu_plugin_register_vcpu_tb_trans_cb(id, tb_trans_before_reset);
64+
return 0;
65+
}
66+
67+
/* Since we uninstall the plugin, we can't use qemu_plugin_register_atexit_cb,
68+
* so we use destructor attribute instead. */
69+
static void __attribute__((destructor)) on_plugin_exit(void)
70+
{
71+
g_assert(was_reset && was_uninstalled);
72+
qemu_plugin_outs("plugin exit\n");
73+
}

0 commit comments

Comments
 (0)