master
c 74 lines 2.22 KB
Raw
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(void *userdata)
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, NULL);
28 }
29
30 static void tb_trans_after_reset(struct qemu_plugin_tb *tb, void *userdata)
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(void *userdata)
38 {
39 qemu_plugin_id_t id = (qemu_plugin_id_t) userdata;
40 g_assert(!was_reset && !was_uninstalled);
41 qemu_plugin_outs("reset done\n");
42 was_reset = true;
43 qemu_plugin_register_vcpu_tb_trans_cb(id, tb_trans_after_reset, NULL);
44 }
45
46 static void tb_exec_before_reset(unsigned int vcpu_index, void *userdata)
47 {
48 g_assert(!was_reset && !was_uninstalled);
49 qemu_plugin_reset(plugin_id, after_reset, (void *) plugin_id);
50 }
51
52 static void tb_trans_before_reset(struct qemu_plugin_tb *tb, void *userdata)
53 {
54 g_assert(!was_reset && !was_uninstalled);
55 qemu_plugin_register_vcpu_tb_exec_cb(tb, tb_exec_before_reset,
56 QEMU_PLUGIN_CB_NO_REGS, NULL);
57 }
58
59 QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
60 const qemu_info_t *info,
61 int argc, char **argv)
62 {
63 plugin_id = id;
64 qemu_plugin_register_vcpu_tb_trans_cb(id, tb_trans_before_reset, NULL);
65 return 0;
66 }
67
68 /* Since we uninstall the plugin, we can't use qemu_plugin_register_atexit_cb,
69 * so we use destructor attribute instead. */
70 static void __attribute__((destructor)) on_plugin_exit(void)
71 {
72 g_assert(was_reset && was_uninstalled);
73 qemu_plugin_outs("plugin exit\n");
74 }