From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web11.7355.1581042782437090075 for ; Thu, 06 Feb 2020 18:33:02 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: bob.c.feng@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 18:33:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,411,1574150400"; d="scan'208";a="225234140" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga008.jf.intel.com with ESMTP; 06 Feb 2020 18:33:01 -0800 Received: from shsmsx602.ccr.corp.intel.com (10.109.6.142) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 6 Feb 2020 18:33:00 -0800 Received: from shsmsx601.ccr.corp.intel.com (10.109.6.141) by SHSMSX602.ccr.corp.intel.com (10.109.6.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Fri, 7 Feb 2020 10:32:59 +0800 Received: from shsmsx601.ccr.corp.intel.com ([10.109.6.141]) by SHSMSX601.ccr.corp.intel.com ([10.109.6.141]) with mapi id 15.01.1713.004; Fri, 7 Feb 2020 10:32:59 +0800 From: "Bob Feng" To: "Kinney, Michael D" , "devel@edk2.groups.io" CC: Sean Brogan , Bret Barkelew , "Gao, Liming" Subject: Re: [Patch 02/11] BaseTools/Plugin: Add HostBasedUnitTestRunner plugin Thread-Topic: [Patch 02/11] BaseTools/Plugin: Add HostBasedUnitTestRunner plugin Thread-Index: AQHV0lt50Me5zN+WLUKdWTX9GSozf6gPGOsA Date: Fri, 7 Feb 2020 02:32:58 +0000 Message-ID: <1f433e3299d74868b28ce900415b8666@intel.com> References: <20200124021032.13808-1-michael.d.kinney@intel.com> <20200124021032.13808-3-michael.d.kinney@intel.com> In-Reply-To: <20200124021032.13808-3-michael.d.kinney@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiOTI4NjVmNWEtYzViOC00NTc4LTlkM2ItNmVmYzczOTI2ZmExIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiVDh3cG5sMnA2RnFUTHlZMWhJZHpWaG9cLzZsWTFxTlBaUXNDMnF0VitybmxBWjBvS0FseGlWYURXeWhMa1Y0Q1IifQ== dlp-version: 11.2.0.6 dlp-product: dlpe-windows x-ctpclassification: CTP_NT dlp-reaction: no-action x-originating-ip: [10.239.127.36] MIME-Version: 1.0 Return-Path: bob.c.feng@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Acked-by: Bob Feng -----Original Message----- From: Kinney, Michael D =20 Sent: Friday, January 24, 2020 10:10 AM To: devel@edk2.groups.io Cc: Sean Brogan ; Bret Barkelew ; Feng, Bob C ; Gao, Liming Subject: [Patch 02/11] BaseTools/Plugin: Add HostBasedUnitTestRunner plugin 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 --- .../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.p +++ y @@ -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=20 +logging import glob import xml.etree.ElementTree from=20 +edk2toolext.environment.plugintypes.uefi_build_plugin import=20 +IUefiBuildPlugin from edk2toolext import edk2_logging import=20 +edk2toollib.windows.locate_tools as locate_tools from=20 +edk2toolext.environment import shell_environment from=20 +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 +=20 + ".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_p +++ lug_in.yaml @@ -0,0 +1,12 @@ +## +# IUefiBuildPlugin used to run any unittests that # were built on this=20 +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" +} -- 2.21.0.windows.1