-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These test plugins demonstrate the QPP API changes by exporting and importing functions and creating and registering callbacks. These tests are integrated into the `make check-tcg` tests. This changes the check-tcg target to no longer have a one-to-one correspondence to plugins in the tests/tcg/plugins directory as the single qpp test involves both qpp_srv and qpp_client. Signed-off-by: Elysia Witham <[email protected]> Signed-off-by: Andrew Fasano <[email protected]>
- Loading branch information
Elysia Witham
authored and
Andrew Fasano
committed
Sep 12, 2024
1 parent
9639ee0
commit 95fa8c5
Showing
6 changed files
with
138 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <stdio.h> | ||
#include <qemu-plugin.h> | ||
#include <plugin-qpp.h> | ||
#include <glib.h> | ||
|
||
QEMU_PLUGIN_EXPORT const char *qemu_plugin_name = "qpp_client"; | ||
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; | ||
QEMU_PLUGIN_EXPORT const char *qemu_plugin_uses[] = {"qpp_srv", NULL}; | ||
|
||
#include "qpp_srv.h" | ||
static bool pass = true; | ||
|
||
void my_cb_exit_callback(gpointer evdata, gpointer udata); | ||
|
||
QEMU_PLUGIN_EXPORT void my_cb_exit_callback(gpointer evdata, gpointer udata) | ||
{ | ||
// Function is called by qpp_srv, update the evdata to be our 'pass' var | ||
*(bool *)evdata = pass; | ||
|
||
g_autoptr(GString) report = g_string_new("QPP client: my_on_exit callback triggered. "); | ||
g_string_append_printf(report, "Setting result=%d\n",pass); | ||
qemu_plugin_outs(report->str); | ||
} | ||
|
||
QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, | ||
const qemu_info_t *info, int argc, char **argv) { | ||
|
||
// Use the QPP interface to run functions in qpp_srv | ||
|
||
// Target plugin is 'qpp_srv', we're calling the 'do_add' function and | ||
// we append '_qpp' to the function name to identify it as a QPP function. | ||
// This function is defined in qpp_srv.h | ||
// Ensure that the return value is as expected | ||
if (qpp_srv_do_add_qpp(3) == 4) { | ||
pass &= true; | ||
} | ||
|
||
// Now call the 'do_sub' method from qpp_srv and checking the result. | ||
if (qpp_srv_do_sub_qpp(10) == 9) { | ||
pass &= true; | ||
} | ||
|
||
// Register a callback to run on a QPP callback provided by qpp_srv | ||
qemu_plugin_reg_callback("qpp_srv", "my_on_exit", &my_cb_exit_callback); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <stdio.h> | ||
#include <qemu-plugin.h> | ||
#include <plugin-qpp.h> | ||
#include <gmodule.h> | ||
#include <assert.h> | ||
|
||
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; | ||
QEMU_PLUGIN_EXPORT const char *qemu_plugin_name = "qpp_srv"; | ||
#include "qpp_srv.h" | ||
|
||
static void plugin_exit(qemu_plugin_id_t id, void *p) | ||
{ | ||
qemu_plugin_outs("qpp_srv: exit triggered, running all registered" | ||
" QPP callbacks\n"); | ||
|
||
// Trigger all callbacks registered with our custom on_exit callback | ||
// We expect qpp_client to set qpp_client_passed if everything worked | ||
|
||
bool qpp_client_passed = false; | ||
qemu_plugin_run_callback(id, "my_on_exit", &qpp_client_passed, NULL); | ||
|
||
if (qpp_client_passed) { | ||
qemu_plugin_outs("PASS\n"); | ||
} else { | ||
qemu_plugin_outs("FAIL\n"); | ||
} | ||
} | ||
|
||
QEMU_PLUGIN_EXPORT int qpp_srv_do_add(int x) | ||
{ | ||
return x + 1; | ||
} | ||
|
||
QEMU_PLUGIN_EXPORT int qpp_srv_do_sub(int x) | ||
{ | ||
return x - 1; | ||
} | ||
|
||
QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, | ||
const qemu_info_t *info, int argc, char **argv) { | ||
qemu_plugin_create_callback(id, "my_on_exit"); | ||
qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef QPP_SRV_H | ||
#define QPP_SRV_H | ||
|
||
|
||
/* | ||
* Prototypes for the do_add and do_sub functions. Both return an int and | ||
* take an int as an argument. | ||
*/ | ||
QPP_FUN_PROTOTYPE(qpp_srv, int, qpp_srv_do_add, int); | ||
QPP_FUN_PROTOTYPE(qpp_srv, int, qpp_srv_do_sub, int); | ||
|
||
#endif /* QPP_SRV_H */ |