Configure UT test static lib in base meson.build
Fix problem of UT GCOV converages not increasing
Signed-off-by: austinfcui <austinfcui@gmail.com>
Change-Id: I070fedf7cd268a541fd61b05aca05b9759a4a67a
diff --git a/meson.build b/meson.build
index 15673ad..8e48b26 100644
--- a/meson.build
+++ b/meson.build
@@ -140,5 +140,60 @@
build_tests = get_option('tests')
if not build_tests.disabled()
+
+ # IMPORTANT NOTE:
+ # We cannot link the test executables to `util_lib` because:
+ # - It is built without `-DTEST_TRACE` and any of the util functions that
+ # use `trace.hpp` will throw a linker error because we don't have access
+ # to phosphor-logging in test ... yet. This issue will go away once we
+ # have converted all of our trace to use the `lg2` interfaces.
+ # - Some functions related to pdbg and dbus simply cannot be built in the
+ # test environment. Instead, there are alternate implementation of those
+ # functions to simulate them for testing (see `test/*-sim-only.cpp`).
+ # Instead we will build a `test_util_lib` that will contain the `util` files
+ # that we need in test along with simulated versions of some util functions.
+
+ # IMPORTANT NOTE:
+ # When running GCOV reports, the Jenkins CI script explicitly ignores any
+ # libraries and executables built in the `test/` directory. Therefore, this
+ # `test_util_lib` library must be built here instead in order to get any GCOV
+ # credit for the code.
+
+ test_args = [
+ '-DTEST_TRACE',
+ package_args,
+ ]
+
+ test_util_srcs = [
+ files(
+ 'util/data_file.cpp',
+ 'util/ffdc_file.cpp',
+ 'util/pdbg.cpp',
+ 'util/temporary_file.cpp',
+ 'test/dbus-sim-only.cpp',
+ 'test/pdbg-sim-only.cpp',
+ ),
+ ]
+
+ test_util_deps = [
+ libhei_dep,
+ libpdbg_dep,
+ phosphor_logging_dep,
+ ]
+
+ test_util_lib = static_library('test_util_lib',
+ sources : test_util_srcs,
+ include_directories : incdir,
+ dependencies : test_util_deps,
+ cpp_args : test_args,
+ install : true,
+ )
+
+ test_libs = [
+ analyzer_lib,
+ attn_lib,
+ test_util_lib,
+ ]
+
subdir('test')
endif
diff --git a/test/meson.build b/test/meson.build
index e1ab8bb..e9b6e6e 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -33,36 +33,9 @@
################################################################################
-# IMPORTANT NOTE:
-# We cannot link to `util_lib` because:
-# - It is built without `-DTEST_TRACE` and any of the util functions that use
-# `trace.hpp` will throw a linker error because we don't have access to
-# phosphor-logging in test ... yet.
-# - Some functions related to pdbg and dbus simply cannot be built in the test
-# environment. Instead, there are alternate implementation of those
-# functions to simulate them for testing.
-
-test_args = [
- '-DTEST_TRACE',
- package_args,
-]
-
-test_util_srcs = [
- files(
- '../util/data_file.cpp',
- '../util/ffdc_file.cpp',
- '../util/pdbg.cpp',
- '../util/temporary_file.cpp',
- 'dbus-sim-only.cpp',
- 'pdbg-sim-only.cpp',
- ),
- pdbg_test_dtb
-]
-
+# Add gtest/gmock dependency to the list of test dependencies.
test_deps = [
- libhei_dep,
- libpdbg_dep,
- phosphor_logging_dep,
+ test_util_deps,
gtest_dep,
]
@@ -71,26 +44,15 @@
'LG2_FORCE_STDERR=true',
]
-test_util_lib = static_library('test_util_lib',
- sources : test_util_srcs,
- include_directories : incdir,
- dependencies : test_deps,
- cpp_args : test_args,
- install : false,
-)
-
-test_libs = [
- analyzer_lib,
- attn_lib,
- test_util_lib,
-]
-
# Additional SRCs that are not (or should not be) included in libraries.
# NOTE: Try to limit this, if possible, to prevent duplicate compilation.
test_additional_srcs = [
- '../analyzer/plugins/p10-plugins.cpp',
- '../analyzer/plugins/p10-tod-plugins.cpp',
- '../cli.cpp',
+ files(
+ '../analyzer/plugins/p10-plugins.cpp',
+ '../analyzer/plugins/p10-tod-plugins.cpp',
+ '../cli.cpp',
+ ),
+ pdbg_test_dtb
]
################################################################################