qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 8/8] tests: build and run QPP tests


From: Andrew Fasano
Subject: [PATCH 8/8] tests: build and run QPP tests
Date: Tue, 13 Dec 2022 16:37:57 -0500

From: Elysia Witham <elysia.witham@ll.mit.edu>

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.

Signed-off-by: Elysia Witham <elysia.witham@ll.mit.edu>
Signed-off-by: Andrew Fasano <fasano@mit.edu>
---
 tests/Makefile.include                    |  2 +-
 tests/meson.build                         |  1 +
 tests/plugin_qpp/meson.build              |  7 +++++
 tests/plugin_qpp/qpp_client.c             | 32 ++++++++++++++++++++
 tests/plugin_qpp/qpp_srv.c                | 37 +++++++++++++++++++++++
 tests/plugin_qpp/qpp_srv.h                | 12 ++++++++
 tests/tcg/Makefile.target                 | 29 ++++++++++++++++++
 tests/tcg/aarch64/Makefile.softmmu-target |  2 ++
 tests/tcg/arm/Makefile.softmmu-target     |  1 +
 tests/tcg/arm/Makefile.target             |  2 ++
 tests/tcg/multiarch/Makefile.target       |  2 ++
 11 files changed, 126 insertions(+), 1 deletion(-)
 create mode 100644 tests/plugin_qpp/meson.build
 create mode 100644 tests/plugin_qpp/qpp_client.c
 create mode 100644 tests/plugin_qpp/qpp_srv.c
 create mode 100644 tests/plugin_qpp/qpp_srv.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 9422ddaece..08dd667aad 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -73,7 +73,7 @@ $(TCG_TESTS_TARGETS:%=distclean-tcg-tests-%): 
distclean-tcg-tests-%:
 build-tcg: $(BUILD_TCG_TARGET_RULES)
 
 .PHONY: check-tcg
-.ninja-goals.check-tcg = all $(if $(CONFIG_PLUGIN),test-plugins)
+.ninja-goals.check-tcg = all $(if $(CONFIG_PLUGIN),test-plugins 
test-plugins-qpp)
 check-tcg: $(RUN_TCG_TARGET_RULES)
 
 .PHONY: clean-tcg
diff --git a/tests/meson.build b/tests/meson.build
index 8e318ec513..12d3ec9c4b 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -86,6 +86,7 @@ endif
 if get_option('tcg').allowed()
   if 'CONFIG_PLUGIN' in config_host
     subdir('plugin')
+    subdir('plugin_qpp')
   endif
 endif
 
diff --git a/tests/plugin_qpp/meson.build b/tests/plugin_qpp/meson.build
new file mode 100644
index 0000000000..25555d0ec2
--- /dev/null
+++ b/tests/plugin_qpp/meson.build
@@ -0,0 +1,7 @@
+t = []
+foreach i : ['qpp_srv', 'qpp_client']
+  t += shared_module(i, files(i + '.c'),
+                     include_directories: '../../include/qemu',
+                     dependencies: glib)
+endforeach
+alias_target('test-plugins-qpp', t)
diff --git a/tests/plugin_qpp/qpp_client.c b/tests/plugin_qpp/qpp_client.c
new file mode 100644
index 0000000000..69b7cc4ac5
--- /dev/null
+++ b/tests/plugin_qpp/qpp_client.c
@@ -0,0 +1,32 @@
+#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"
+
+void my_cb_exit_callback(gpointer evdata, gpointer udata);
+
+QEMU_PLUGIN_EXPORT void my_cb_exit_callback(gpointer evdata, gpointer udata)
+{
+    *(bool *)evdata = true;
+    qemu_plugin_outs("called my on exit callback\n");
+}
+
+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
+                   const qemu_info_t *info, int argc, char **argv) {
+
+    g_autoptr(GString) report = g_string_new("QPP client: Call "
+                                             "qpp_srv's do_add(0) do_sub(3) => 
");
+    g_string_append_printf(report, "%d %d\n", qpp_srv_do_add_qpp(0),
+                           qpp_srv_do_sub_qpp(3));
+    qemu_plugin_outs(report->str);
+    qemu_plugin_reg_callback("qpp_srv", "my_on_exit", &my_cb_exit_callback);
+
+    return 0;
+}
+
diff --git a/tests/plugin_qpp/qpp_srv.c b/tests/plugin_qpp/qpp_srv.c
new file mode 100644
index 0000000000..88b1907a7e
--- /dev/null
+++ b/tests/plugin_qpp/qpp_srv.c
@@ -0,0 +1,37 @@
+#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");
+  bool called = false;
+  qemu_plugin_run_callback(id, "my_on_exit", &called, NULL);
+  assert(called);
+}
+
+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_outs("qpp_srv loaded\n");
+    qemu_plugin_create_callback(id, "my_on_exit");
+    qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
+
+    return 0;
+}
diff --git a/tests/plugin_qpp/qpp_srv.h b/tests/plugin_qpp/qpp_srv.h
new file mode 100644
index 0000000000..16d9bc2df4
--- /dev/null
+++ b/tests/plugin_qpp/qpp_srv.h
@@ -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 */
diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target
index 75257f2b29..c478f1b2de 100644
--- a/tests/tcg/Makefile.target
+++ b/tests/tcg/Makefile.target
@@ -145,6 +145,9 @@ RUN_TESTS=$(patsubst %,run-%, $(TESTS))
 ifeq ($(CONFIG_PLUGIN),y)
 PLUGIN_SRC=$(SRC_PATH)/tests/plugin
 PLUGIN_LIB=../../plugin
+
+PLUGIN_LIB_QPP=../../plugin_qpp
+
 VPATH+=$(PLUGIN_LIB)
 PLUGINS=$(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))
 
@@ -156,6 +159,11 @@ $(foreach p,$(PLUGINS), \
        $(foreach t,$(TESTS),\
                $(eval run-plugin-$(t)-with-$(p): $t $p) \
                $(eval RUN_TESTS+=run-plugin-$(t)-with-$(p))))
+
+$(foreach t,$(TESTS),\
+       $(eval run-plugin-qpp-$(t): $t) \
+       $(eval RUN_TESTS+=run-plugin-qpp-$(t)))
+
 endif
 
 strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1))
@@ -167,18 +175,39 @@ ifeq ($(filter %-softmmu, $(TARGET)),)
 run-%: %
        $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<)
 
+run-plugin-qpp-%:
+       $(call run-test, $@, \
+         $(QEMU) \
+                       -plugin $(PLUGIN_LIB_QPP)/libqpp_srv.so \
+                       -plugin $(PLUGIN_LIB_QPP)/libqpp_client.so \
+                       $(call extract-plugin,$@) \
+                       -d plugin -D $*.pout \
+               $(QEMU_OPTS) $<)
+
 run-plugin-%:
        $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
                -plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
                -d plugin -D $*.pout \
                 $(call strip-plugin,$<))
+
 else
+
 run-%: %
        $(call run-test, $<, \
          $(QEMU) -monitor none -display none \
                  -chardev file$(COMMA)path=$<.out$(COMMA)id=output \
                  $(QEMU_OPTS) $<)
 
+run-plugin-qpp-%:
+       $(call run-test, $@, \
+         $(QEMU) -monitor none -display none \
+               -chardev file$(COMMA)path=$@.out$(COMMA)id=output \
+                       -plugin $(PLUGIN_LIB_QPP)/libqpp_srv.so \
+                       -plugin $(PLUGIN_LIB_QPP)/libqpp_client.so \
+                       $(call extract-plugin,$@) \
+                               -d plugin -D $*.pout \
+               $(QEMU_OPTS) $<)
+
 run-plugin-%:
        $(call run-test, $@, \
          $(QEMU) -monitor none -display none \
diff --git a/tests/tcg/aarch64/Makefile.softmmu-target 
b/tests/tcg/aarch64/Makefile.softmmu-target
index a1368905f5..f87a1a799b 100644
--- a/tests/tcg/aarch64/Makefile.softmmu-target
+++ b/tests/tcg/aarch64/Makefile.softmmu-target
@@ -45,6 +45,8 @@ QEMU_SEMIHOST=-chardev stdio,mux=on,id=stdio0 
-semihosting-config enable=on,char
 run-semiconsole: QEMU_OPTS=$(QEMU_BASE_MACHINE) $(QEMU_SEMIHOST)  -kernel
 run-semiconsole: semiconsole
        $(call skip-test, $<, "MANUAL ONLY")
+run-plugin-qpp-semiconsole: semiconsole
+       $(call skip-test, $<, "MANUAL ONLY")
 run-plugin-semiconsole-with-%: semiconsole
        $(call skip-test, $<, "MANUAL ONLY")
 
diff --git a/tests/tcg/arm/Makefile.softmmu-target 
b/tests/tcg/arm/Makefile.softmmu-target
index 7df88ddea8..f4bfab41bf 100644
--- a/tests/tcg/arm/Makefile.softmmu-target
+++ b/tests/tcg/arm/Makefile.softmmu-target
@@ -24,3 +24,4 @@ test-armv6m-undef: EXTRA_CFLAGS+=-mcpu=cortex-m0 
-mfloat-abi=soft
 
 run-test-armv6m-undef: QEMU_OPTS+=-semihosting -M microbit -kernel
 run-plugin-test-armv6m-undef-%: QEMU_OPTS+=-semihosting -M microbit -kernel
+run-plugin-qpp-test-armv6m-undef: QEMU_OPTS+=-semihosting -M microbit -kernel
diff --git a/tests/tcg/arm/Makefile.target b/tests/tcg/arm/Makefile.target
index b3b1504a1c..2aa3479952 100644
--- a/tests/tcg/arm/Makefile.target
+++ b/tests/tcg/arm/Makefile.target
@@ -62,6 +62,8 @@ semiconsole-arm: semihosting.c
 run-semiconsole-arm: semiconsole-arm
        $(call skip-test, $<, "MANUAL ONLY")
 
+run-plugin-qpp-semiconsole-arm:
+       $(call skip-test, $<, "MANUAL ONLY")
 run-plugin-semiconsole-arm-with-%:
        $(call skip-test, $<, "MANUAL ONLY")
 
diff --git a/tests/tcg/multiarch/Makefile.target 
b/tests/tcg/multiarch/Makefile.target
index 5f0fee1aad..a77b30aa94 100644
--- a/tests/tcg/multiarch/Makefile.target
+++ b/tests/tcg/multiarch/Makefile.target
@@ -108,6 +108,8 @@ semiconsole: CFLAGS+=-I$(SRC_PATH)/tests/tcg/$(TARGET_NAME)
 run-semiconsole: semiconsole
        $(call skip-test, $<, "MANUAL ONLY")
 
+run-plugin-qpp-semiconsole:
+       $(call skip-test, $<, "MANUAL ONLY")
 run-plugin-semiconsole-with-%:
        $(call skip-test, $<, "MANUAL ONLY")
 
-- 
2.34.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]