From nobody Mon Feb 9 09:52:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+54052+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+54052+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1581099240622133.37398047311865; Fri, 7 Feb 2020 10:14:00 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id wj3QYY1788612xd7EQxrLagS; Fri, 07 Feb 2020 10:14:00 -0800 X-Received: from mga06.intel.com (mga06.intel.com []) by mx.groups.io with SMTP id smtpd.web10.8964.1581099238804041597 for ; Fri, 07 Feb 2020 10:13:59 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Feb 2020 10:13:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,414,1574150400"; d="scan'208";a="250500539" X-Received: from unknown (HELO mdkinney-MOBL2.amr.corp.intel.com) ([10.241.98.74]) by orsmga002.jf.intel.com with ESMTP; 07 Feb 2020 10:13:58 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Bob Feng , Liming Gao Subject: [edk2-devel] [Patch v2 02/11] BaseTools/Plugin: Add HostBasedUnitTestRunner plugin Date: Fri, 7 Feb 2020 10:13:45 -0800 Message-Id: <20200207181354.31632-3-michael.d.kinney@intel.com> In-Reply-To: <20200207181354.31632-1-michael.d.kinney@intel.com> References: <20200207181354.31632-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,michael.d.kinney@intel.com X-Gm-Message-State: hJxM7agIHrHMFyN83CBWpllXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1581099240; bh=Xltwht8iZ+evINFR9bgpSeZGp929jGBMqVVILY67DFo=; h=Cc:Date:From:Reply-To:Subject:To; b=Qru/iUPBYtFGhuqdWPJvKx/jSrXRchOFcGW6aCjEBtlOpLn3yXib3WHRDHye6mgmE1o 4Nks2GJ8AT8C/8ER2xMI3SGDjAekOznhJaVhoV01acK2eS+eDCZFVNIMTtH9tt2pJgSGb p6F+mwYDmTzsgCyPnrARZWa7/q12LI0AQJA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" https://bugzilla.tianocore.org/show_bug.cgi?id=3D2505 Add plugin to BaseTools to run host based unit tests. Cc: Sean Brogan Cc: Bret Barkelew Cc: Bob Feng Cc: Liming Gao Signed-off-by: Michael D Kinney Reviewed-by: Bret Barkelew Acked-by: Bob Feng --- .../HostBasedUnitTestRunner.py | 115 ++++++++++++++++++ .../HostBasedUnitTestRunner_plug_in.yaml | 12 ++ 2 files changed, 127 insertions(+) create mode 100644 BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitT= estRunner.py create mode 100644 BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitT= estRunner_plug_in.yaml diff --git a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunn= er.py b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py new file mode 100644 index 0000000000..92426760ae --- /dev/null +++ b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py @@ -0,0 +1,115 @@ +# @file HostBasedUnitTestRunner.py +# Plugin to located any host-based unit tests in the output directory and = execute them. +## +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## +import os +import logging +import glob +import xml.etree.ElementTree +from edk2toolext.environment.plugintypes.uefi_build_plugin import IUefiBui= ldPlugin +from edk2toolext import edk2_logging +import edk2toollib.windows.locate_tools as locate_tools +from edk2toolext.environment import shell_environment +from edk2toollib.utility_functions import RunCmd + + +class HostBasedUnitTestRunner(IUefiBuildPlugin): + + def do_pre_build(self, thebuilder): + ''' + Works with the compiler (either the HostBasedCompilerPlugin or an = other Builder) to set + up the environment that will be needed to build host-based unit te= sts. + + EXPECTS: + - Build Var 'CI_BUILD_TYPE' - If not set to 'host_unit_test', will= not do anything. + + UPDATES: + - Shell Var (Several) - Updates the shell with all vars listed in = interesting_keys. + - Shell Path - Updated from QueryVcVariables() + - Shell Var 'CMOCKA_MESSAGE_OUTPUT' + ''' + ci_type =3D thebuilder.env.GetValue('CI_BUILD_TYPE') + if ci_type !=3D 'host_unit_test': + return 0 + + shell_env =3D shell_environment.GetEnvironment() + # Use the tools lib to determine the correct values for the vars t= hat interest us. + interesting_keys =3D ["ExtensionSdkDir", "INCLUDE", "LIB", "LIBPAT= H", "UniversalCRTSdkDir", + "UCRTVersion", "WindowsLibPath", "WindowsSdkBi= nPath", "WindowsSdkDir", "WindowsSdkVerBinPath", + "WindowsSDKVersion", "VCToolsInstallDir"] + vs_vars =3D locate_tools.QueryVcVariables(interesting_keys, "amd64= ") + for (k, v) in vs_vars.items(): + if k.upper() =3D=3D "PATH": + shell_env.append_path(v) + else: + shell_env.set_shell_var(k, v) + + # Set up the reporting type for Cmocka. + shell_env.set_shell_var('CMOCKA_MESSAGE_OUTPUT', 'xml') + return 0 + + def do_post_build(self, thebuilder): + ''' + After a build, will automatically locate and run all host-based un= it tests. Logs any + failures with Warning severity and will return a count of the fail= ures as the return code. + + EXPECTS: + - Build Var 'CI_BUILD_TYPE' - If not set to 'host_unit_test', will= not do anything. + + UPDATES: + - Shell Var 'CMOCKA_XML_FILE' + ''' + ci_type =3D thebuilder.env.GetValue('CI_BUILD_TYPE') + if ci_type !=3D 'host_unit_test': + return 0 + + shell_env =3D shell_environment.GetEnvironment() + logging.log(edk2_logging.get_section_level(), + "Run Host based Unit Tests") + path =3D thebuilder.env.GetValue("BUILD_OUTPUT_BASE") + + failure_count =3D 0 + + for arch in thebuilder.env.GetValue("TARGET_ARCH").split(): + logging.log(edk2_logging.get_subsection_level(), + "Testing for architecture: " + arch) + cp =3D os.path.join(path, arch) + + # If any old results XML files exist, clean them up. + for old_result in glob.iglob(os.path.join(cp, "*.result.xml")): + os.remove(old_result) + + # Determine whether any tests exist. + testList =3D glob.glob(os.path.join(cp, "*Test*.exe")) + for test in testList: + # Configure output name. + shell_env.set_shell_var( + 'CMOCKA_XML_FILE', test + ".%g." + arch + ".result.xml= ") + + # Run the test. + ret =3D RunCmd('"' + test + '"', "", workingdir=3Dcp) + if(ret !=3D 0): + logging.error("UnitTest Execution Error: " + + os.path.basename(test)) + else: + logging.info("UnitTest Completed: " + + os.path.basename(test)) + file_match_pattern =3D test + ".*." + arch + ".result.= xml" + xml_results_list =3D glob.glob(file_match_pattern) + for xml_result_file in xml_results_list: + root =3D xml.etree.ElementTree.parse( + xml_result_file).getroot() + for suite in root: + for case in suite: + for result in case: + if result.tag =3D=3D 'failure': + logging.warning( + "%s Test Failed" % os.path.bas= ename(test)) + logging.warning( + " %s - %s" % (case.attrib['na= me'], result.text)) + failure_count +=3D 1 + + return failure_count diff --git a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunn= er_plug_in.yaml b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTes= tRunner_plug_in.yaml new file mode 100644 index 0000000000..d9eb852e97 --- /dev/null +++ b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner_plug= _in.yaml @@ -0,0 +1,12 @@ +## +# IUefiBuildPlugin used to run any unittests that +# were built on this build. +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## +{ + "scope": "host-test-win", + "name": "Windows Host-Based Unit Test Runner", + "module": "HostBasedUnitTestRunner" +} --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#54052): https://edk2.groups.io/g/devel/message/54052 Mute This Topic: https://groups.io/mt/71060080/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-