Link target-info-def.c objects from supported multi-target libraries into
test-target-info. Verify target_info() is non-NULL and that
target_info_list() contains one entry for each linked target.

Signed-off-by: Yonggang Luo <[email protected]>
---
 MAINTAINERS                   |  1 +
 meson.build                   |  5 ++++-
 tests/unit/meson.build        |  4 ++++
 tests/unit/test-target-info.c | 38 +++++++++++++++++++++++++++++++++++
 4 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 tests/unit/test-target-info.c

diff --git a/MAINTAINERS b/MAINTAINERS
index cfe39dc2883..418c4e472a9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2149,6 +2149,7 @@ S: Supported
 F: include/qemu/target-info*.h
 F: target-info*.c
 F: tests/unit/test-multi-targets.c
+F: tests/unit/test-target-info.c
 
 Xtensa Machines
 ---------------
diff --git a/meson.build b/meson.build
index 4097784e7a2..fd7a4f68389 100644
--- a/meson.build
+++ b/meson.build
@@ -4259,6 +4259,7 @@ endif
 traceable = []
 multi_target_libs = []
 multi_target_deps = []
+multi_target_target_info_objects = []
 multi_target_crates = []
 multi_target_supported_targets = [
   'aarch64-softmmu',
@@ -4274,6 +4275,7 @@ multi_target_supported_targets = [
 ]
 
 emulators = {}
+target_info_def = files('target-info-def.c')
 foreach target : target_dirs
   config_target = config_target_mak[target]
   target_name = config_target['TARGET_NAME']
@@ -4345,7 +4347,7 @@ foreach target : target_dirs
     endif
   endif
 
-  arch_srcs += files('target-info-def.c')
+  arch_srcs += target_info_def
 
   if target_base_arch in target_arch
     t = target_arch[target_base_arch].apply(config_target, strict: false)
@@ -4428,6 +4430,7 @@ foreach target : target_dirs
       multi_target_libs += lib
       multi_target_deps += arch_deps
       multi_target_deps += target_stubs
+      multi_target_target_info_objects += lib.extract_objects(target_info_def)
       multi_target_crates += main_rs
     endif
     execs = [{
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
index d17435c1877..b2e8be24b05 100644
--- a/tests/unit/meson.build
+++ b/tests/unit/meson.build
@@ -43,6 +43,10 @@ tests = {
   'test-qgraph': ['../qtest/libqos/qgraph.c'],
   'check-qom-interface': [qom],
   'check-qom-proplist': [qom],
+  'test-target-info': [qom, declare_dependency(
+    objects: multi_target_target_info_objects,
+    compile_args: ['-DTARGET_INFO_DEF_COUNT=@0@'.format(
+      multi_target_target_info_objects.length())])],
   'test-qemu-opts': [],
   'test-keyval': [testqapi],
   'test-logging': [],
diff --git a/tests/unit/test-target-info.c b/tests/unit/test-target-info.c
new file mode 100644
index 00000000000..e6de9b259e8
--- /dev/null
+++ b/tests/unit/test-target-info.c
@@ -0,0 +1,38 @@
+/*
+ * TargetInfo unit tests
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/target-info.h"
+#include "qemu/target-info-def.h"
+
+static int target_info_list_count(void)
+{
+    TargetInfoNode *node;
+    int n = 0;
+
+    QLIST_FOREACH(node, target_info_list(), next) {
+        n++;
+    }
+    return n;
+}
+
+static void test_target_info_not_null(void)
+{
+    g_assert_nonnull(target_info());
+}
+
+static void test_target_info_list_count(void)
+{
+    g_assert_cmpint(target_info_list_count(), ==, TARGET_INFO_DEF_COUNT);
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+    g_test_add_func("/target-info/not-null", test_target_info_not_null);
+    g_test_add_func("/target-info/list-count", test_target_info_list_count);
+    return g_test_run();
+}
-- 
2.55.0.windows.3


Reply via email to