Collect each target-info-def.c object in target_info_def_objects, keyed by target dir. Link every value so constructors fill the list. Assert target_info() is not NULL and target_info_list() has one entry per linked object.
Signed-off-by: Yonggang Luo <[email protected]> --- meson.build | 6 +++++- tests/unit/meson.build | 4 ++++ tests/unit/test-target-info.c | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test-target-info.c diff --git a/meson.build b/meson.build index c404d222d9f..93237429713 100644 --- a/meson.build +++ b/meson.build @@ -4259,6 +4259,8 @@ endif traceable = [] emulators = {} +target_info_def = files('target-info-def.c') +target_info_def_objects = {} foreach target : target_dirs config_target = config_target_mak[target] target_name = config_target['TARGET_NAME'] @@ -4330,7 +4332,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) @@ -4408,6 +4410,8 @@ foreach target : target_dirs c_args: c_args, build_by_default: false) + target_info_def_objects += {target: lib.extract_objects(target_info_def)} + if target.endswith('-softmmu') execs = [{ 'name': 'qemu-system-' + target_name, diff --git a/tests/unit/meson.build b/tests/unit/meson.build index e47bc7225ab..dc980a35955 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: target_info_def_objects.values(), + compile_args: ['-DTARGET_INFO_DEF_COUNT=@0@'.format( + target_info_def_objects.values().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.52.0.windows.1
