From e74f4fc4a9f5cda45e96821cc82aa2dd9a795942 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Wed, 26 Apr 2023 19:28:35 -0400 Subject: [PATCH] [CHERRY-PICK] BaseTools/Plugin: Clarify code coverage failure message (#375) ## Description HostBasedUnitTestRunner.py is a build plugin responsible for locating and executing host-based unit tests. Recently, commit 6bb00aa introduced support for the plugin to generate code coverage reports via lcov and OpenCppCoverage. The plugin has discovered unit tests by searching for executables with "Test" in the name for a while. However, the test coverage change makes assumptions about test presence when crafting the OpenCppCoverage command that ultimately fails with an ambiguous error message if no host-based unit tests are discovered (see "ERROR"). ``` SECTION - Run Host based Unit Tests SUBSECTION - Testing for architecture: X64 ERROR - UnitTest Coverage: Failed to generate cobertura format xml in single package. PROGRESS - --->Test Success: Host Unit Test Compiler Plugin NOOPT ``` This change preempts that message with a check in the plugin to determine if any host-based tests were discovered. If not, a message is printed with more guidance about how the developer should proceed to either (1) fix their tests so code coverage is generated as expected or (2) prevent the error message. New message: ``` SECTION - Run Host based Unit Tests SUBSECTION - Testing for architecture: X64 WARNING - UnitTest Coverage: No unit tests discovered. Test coverage will not be generated. Prevent this message by: 1. Adding host-based unit tests to this package 2. Ensuring tests have the word "Test" in their name 3. Disabling HostUnitTestCompilerPlugin in the package CI YAML file PROGRESS - --->Test Success: Host Unit Test Compiler Plugin NOOPT ``` Cc: Rebecca Cran Cc: Liming Gao Cc: Bob Feng Cc: Yuwei Chen Cc: Michael D Kinney Cc: Sean Brogan Signed-off-by: Michael Kubacki Reviewed-by: Liming Gao Reviewed-by: Rebecca Cran (cherry picked from commit 3163f34a42a5dacaf63499e69bf0fefdc409d89e) - [ ] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [x] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested Local and server CI. ## Integration Instructions N/A - No major change in functionality --- .../HostBasedUnitTestRunner.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py index 388aa19fa9..11807f784c 100644 --- a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py +++ b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py @@ -16,6 +16,7 @@ from edk2toolext.environment import shell_environment from edk2toollib.utility_functions import RunCmd from edk2toollib.utility_functions import GetHostInfo +from textwrap import dedent class HostBasedUnitTestRunner(IUefiBuildPlugin): @@ -84,6 +85,18 @@ def do_post_build(self, thebuilder): else: raise NotImplementedError("Unsupported Operating System") + if not testList: + logging.warning(dedent(""" + UnitTest Coverage: + No unit tests discovered. Test coverage will not be generated. + + Prevent this message by: + 1. Adding host-based unit tests to this package + 2. Ensuring tests have the word "Test" in their name + 3. Disabling HostUnitTestCompilerPlugin in the package CI YAML file + """).strip()) + return 0 + for test in testList: # Configure output name if test uses cmocka. shell_env.set_shell_var(