public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/3] Expand Ovmf PlatformCI to enable CI for Shell UnitTest
@ 2022-11-22 11:47 duntan
  2022-11-22 11:47 ` [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI " duntan
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: duntan @ 2022-11-22 11:47 UTC (permalink / raw)
  To: devel

OvmfPkg/PlatformCI: Expand Ovmf PlatformCI python files for Shell UnitTest
OvmfPkg/PlatformCI: Add new JOB in .yml of OvmfPkg PlatformCI yml files
.azurepipelines: Expand PlatformCI template yml files for Shell UnitTest

Dun Tan (3):
  OvmfPkg/PlatformCI: Expand Ovmf PlatformCI for Shell UnitTest
  OvmfPkg/PlatformCI: Add new JOB in .yml of OvmfPkg PlatformCI
  .azurepipelines: Expand PlatformCI template for Shell UnitTest

 .azurepipelines/templates/platform-build-run-steps.yml |  21 +++++++++++++++++----
 OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml     |  11 +++++++++++
 OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml  |  11 +++++++++++
 OvmfPkg/PlatformCI/PlatformBuild.py                    | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/PlatformCI/PlatformBuildLib.py                 |  51 +++++++++++++++++++++++++++++++++++++++++++++------
 5 files changed, 196 insertions(+), 10 deletions(-)

-- 
2.31.1.windows.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI for Shell UnitTest
  2022-11-22 11:47 [PATCH 0/3] Expand Ovmf PlatformCI to enable CI for Shell UnitTest duntan
@ 2022-11-22 11:47 ` duntan
  2022-11-22 11:47 ` [PATCH 2/3] OvmfPkg/PlatformCI: Add new JOB in .yml of OvmfPkg PlatformCI duntan
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: duntan @ 2022-11-22 11:47 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Jiewen Yao, Jordan Justen, Gerd Hoffmann, Ray Ni

Expand Ovmf PlatformBuild.py and PlatformBuildLib.py to support
building and running specific Shell target UnitTest modules.
In the new CommonPlatform class:
It provides new class attributes and new methods to support
build and run specific Shell Unit Test modules.

In the new SettingsManager class for stuart_pr_eval:
It calls new API in CommonPlatform to updates PackagesSupported
based on -u ShellUnitTestList input from cmd. The package which
contains the module in ShellUnitTestList will be added into
PackagesSupported for further evaluation.

In the new PlatformBuilder class for stuart_build:
1.In PlatformPostBuild(), it conditionally calls new API in
CommonPlatform to build -u ShellUnitTestList in -p PkgsToBuild
and copy them to VirtualDrive folder. If no -p option, all the
modules in -u ShellUnitTestList will be built.
2.In FlashRomImage(), it conditionally calls the new API in
CommonPlatform to write all efi files name in VirtualDrive into
startup.nsh and output UnitTest log into ShellUnitTestLog.
3. After the boot process, it conditionally calls new API in
CommonPlatform to check the UnitTest boot log.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Ray Ni <ray.ni@intel.com>
---
 OvmfPkg/PlatformCI/PlatformBuild.py    | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/PlatformCI/PlatformBuildLib.py |  51 +++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 157 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/PlatformCI/PlatformBuild.py b/OvmfPkg/PlatformCI/PlatformBuild.py
index 6c541cdea4..72cb7e0e9e 100644
--- a/OvmfPkg/PlatformCI/PlatformBuild.py
+++ b/OvmfPkg/PlatformCI/PlatformBuild.py
@@ -6,6 +6,11 @@
 ##
 import os
 import sys
+import shutil
+import logging
+import re
+from edk2toolext.environment import shell_environment
+from edk2toolext.environment.multiple_workspace import MultipleWorkspace
 
 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 from PlatformBuildLib import SettingsManager
@@ -24,6 +29,10 @@ class CommonPlatform():
     Scopes = ('ovmf', 'edk2-build')
     WorkspaceRoot = os.path.realpath(os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "..", ".."))
+    # Support build and run Shell Unit Test modules
+    UnitTestModuleList = {}
+    RunShellUnitTest   = False
+    ShellUnitTestLog   = ''
 
     @classmethod
     def GetDscName(cls, ArchCsv: str) -> str:
@@ -39,5 +48,108 @@ class CommonPlatform():
         dsc += ".dsc"
         return dsc
 
+    @classmethod
+    def UpdatePackagesSupported(cls, ShellUnitTestListArg):
+        ''' Update PackagesSupported by -u ShellUnitTestList from cmd line. '''
+        UnitTestModuleListStr = ','.join(ShellUnitTestListArg)
+        if not re.search(r'.+.inf:.+.dsc', UnitTestModuleListStr):
+            raise Exception('No valid ModulePath:DscPath in the -u {}'.format(UnitTestModuleListStr))
+        UnitTestModuleList = UnitTestModuleListStr.split(',')
+        PackagesSupported = []
+        for KeyValue in UnitTestModuleList:
+            PkgName = KeyValue.split("Pkg")[0] + 'Pkg'
+            if PkgName not in PackagesSupported:
+                PackagesSupported.append(PkgName)
+        cls.PackagesSupported = tuple(PackagesSupported)
+        print('PackagesSupported for UnitTest is {}'.format(cls.PackagesSupported))
+
+    @classmethod
+    def UpdateUnitTestConfig(cls, args):
+        ''' Update UnitTest config by -u ShellUnitTestList and -p PkgsToBuildForUT from cmd line.
+            ShellUnitTestList is in this format: {module1:dsc1, module2:dsc2, module3:dsc2...}.
+            Only the modules which are in the PkgsToBuildForUT list are added into self.UnitTestModuleList.
+        '''
+        UnitTestModuleListStr = ','.join(args.ShellUnitTestList)
+        if not re.search(r'.+.inf:.+.dsc', UnitTestModuleListStr):
+            raise Exception('No valid ModulePath:DscPath in the -u {}'.format(args.ShellUnitTestList))
+        UnitTestModuleList = UnitTestModuleListStr.split(',')
+        if args.PkgsToBuildForUT is None or all(['Pkg' not in Pkg for Pkg in args.PkgsToBuildForUT]):
+            # No invalid Pkgs from input. Build all modules in -u UnitTestModuleList.
+            for KeyValue in UnitTestModuleList:
+                UnitTestPath = os.path.normpath(KeyValue.split(":")[0])
+                DscPath      = os.path.normpath(KeyValue.split(":")[1])
+                cls.UnitTestModuleList[UnitTestPath] = DscPath
+        else:
+            PkgsToBuildForUT = ','.join(args.PkgsToBuildForUT).split(',')
+            for KeyValue in UnitTestModuleList:
+                UnitTestPath = os.path.normpath(KeyValue.split(":")[0])
+                DscPath      = os.path.normpath(KeyValue.split(":")[1])
+                PkgName      = UnitTestPath.split("Pkg")[0] + 'Pkg'
+                if PkgName in PkgsToBuildForUT:
+                    cls.UnitTestModuleList[UnitTestPath] = DscPath
+        if len(cls.UnitTestModuleList) > 0:
+            cls.RunShellUnitTest = True
+            cls.ShellUnitTestLog = os.path.join(cls.WorkspaceRoot, 'Build', "BUILDLOG_UnitTest.txt")
+            print('UnitTestModuleList is {}'.format(cls.UnitTestModuleList))
+
+    def BuildUnitTest(self):
+        ''' Build specific DSC for modules in UnitTestModuleList '''
+        self.env = shell_environment.GetBuildVars()
+        self.ws  = PlatformBuilder.GetWorkspaceRoot(self)
+        self.mws = MultipleWorkspace()
+        self.pp  = ''
+        VirtualDrive = os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"), "VirtualDrive")
+        os.makedirs(VirtualDrive, exist_ok=True)
+
+        # DSC by self.GetDscName() should have been built in BUILD process.
+        BuiltDsc = [CommonPlatform.GetDscName(",".join(self.env.GetValue("TARGET_ARCH").split(' ')))]
+        for UnitTestPath, DscPath in CommonPlatform.UnitTestModuleList.items():
+            if DscPath not in BuiltDsc:
+                ModuleName = os.path.split(UnitTestPath)[1].split('.inf')[0]
+                logging.info('Build {0} for {1}'.format(DscPath, ModuleName))
+                BuiltDsc.append(DscPath)
+                Arch = self.env.GetValue("TARGET_ARCH").split(" ")
+                if 'X64' in Arch:
+                    UTArch = 'X64'
+                else:
+                    UTArch = 'IA32'
+                self.env.AllowOverride("ACTIVE_PLATFORM")
+                self.env.SetValue("ACTIVE_PLATFORM", DscPath, "For UnitTest")
+                self.env.AllowOverride("TARGET_ARCH")
+                self.env.SetValue("TARGET_ARCH", UTArch, "For UnitTest") # Set UnitTest arch the same as Ovmf Shell module.
+                ret = PlatformBuilder.Build(self)                        # Build specific dsc for UnitTest modules
+                if (ret != 0):
+                    return ret
+            ret = PlatformBuilder.ParseDscFile(self) # Parse OUTPUT_DIRECTORY from dsc files
+            if(ret != 0):
+                return ret
+            OutputPath = os.path.normpath(os.path.join(self.ws, self.env.GetValue("OUTPUT_DIRECTORY")))
+            EfiPath    = os.path.join(OutputPath, self.env.GetValue("TARGET") + "_" + self.env.GetValue("TOOL_CHAIN_TAG"),
+                         UTArch, UnitTestPath.split('.inf')[0], "OUTPUT", ModuleName + '.efi')
+            logging.info('Copy {0}.efi from:{1}'.format(ModuleName, EfiPath))
+            shutil.copy(EfiPath, VirtualDrive)
+        return 0
+
+    @staticmethod
+    def WriteEfiToStartup(EfiFolder, FileObj):
+        ''' Write all the .efi files' name in VirtualDrive into Startup.nsh '''
+        for Root,Dirs,Files in os.walk(EfiFolder):
+            for File in Files:
+                if os.path.splitext(File)[1] == '.efi':
+                    FileObj.write("{0} \n".format(File))
+
+    @classmethod
+    def CheckUnitTestLog(cls):
+        ''' Check the boot log for UnitTest '''
+        File        = open(cls.ShellUnitTestLog, "r")
+        FileContent = File.readlines()
+        logging.info('Check the UnitTest boot log:{0}'.format(cls.ShellUnitTestLog))
+        for Index in range(len(FileContent)):
+            if 'FAILURE MESSAGE:' in FileContent[Index]:
+                if FileContent[Index + 1].strip() != '':
+                    FailureMessage = FileContent[Index + 1] + FileContent[Index + 2]
+                    return FailureMessage
+        return 0
+
 import PlatformBuildLib
 PlatformBuildLib.CommonPlatform = CommonPlatform
diff --git a/OvmfPkg/PlatformCI/PlatformBuildLib.py b/OvmfPkg/PlatformCI/PlatformBuildLib.py
index bfef9849c7..b42235b2ac 100644
--- a/OvmfPkg/PlatformCI/PlatformBuildLib.py
+++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py
@@ -103,15 +103,28 @@ class SettingsManager(UpdateSettingsManager, SetupSettingsManager, PrEvalSetting
 
         return build_these_packages
 
+    def AddCommandLineOptions(self, parserObj):
+        parserObj.add_argument('-u', '--UnitTest', dest='ShellUnitTestList', type=str,
+            help='Optional - Key:Value that contains Shell UnitTest list and corresponding DscPath you want to test.(workspace relative)'
+            'Can list multiple by doing -u <UTPath1:DscPath1>,<UTPath2:DscPath2> or -u <UTPath3:DscPath3> -u <UTPath4:DscPath4>',
+            action="append", default=None)
+
+    def RetrieveCommandLineOptions(self, args):
+        if args.ShellUnitTestList:
+            CommonPlatform.UpdatePackagesSupported(args.ShellUnitTestList)
+
     def GetPlatformDscAndConfig(self) -> tuple:
         ''' If a platform desires to provide its DSC then Policy 4 will evaluate if
         any of the changes will be built in the dsc.
 
         The tuple should be (<workspace relative path to dsc file>, <input dictionary of dsc key value pairs>)
+        This Policy 4 can only be applied when PackagesSupported only contains OvmfPkg Since it doesn't support
+        mutiple packages evaluation.
         '''
-        dsc = CommonPlatform.GetDscName(",".join(self.ActualArchitectures))
-        return (f"OvmfPkg/{dsc}", {})
-
+        if (len(CommonPlatform.PackagesSupported) == 1) and (CommonPlatform.PackagesSupported[0] == 'OvmfPkg'):
+            dsc = CommonPlatform.GetDscName(",".join(self.ActualArchitectures))
+            return (f"OvmfPkg/{dsc}", {})
+        return None
 
     # ####################################################################################### #
     #                         Actual Configuration for Platform Build                         #
@@ -126,6 +139,14 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
             help="Optional - CSV of architecture to build.  IA32 will use IA32 for Pei & Dxe. "
             "X64 will use X64 for both PEI and DXE.  IA32,X64 will use IA32 for PEI and "
             "X64 for DXE. default is IA32,X64")
+        parserObj.add_argument('-p', '--pkg', '--pkg-dir', dest='PkgsToBuildForUT', type=str,
+            help='Optional - Package list you want to build for UnitTest.efi. (workspace relative).'
+            'Can list multiple by doing -p <pkg1>,<pkg2> or -p <pkg3> -p <pkg4>.If no valid input -p, build and run all -u UnitTest',
+            action="append", default=None)
+        parserObj.add_argument('-u', '--UnitTest', dest='ShellUnitTestList', type=str,
+            help='Optional - Key:Value that contains Shell UnitTest list and corresponding DscPath you want to test.(workspace relative)'
+            'Can list multiple by doing -u <UTPath1:DscPath1>,<UTPath2:DscPath2> or -u <UTPath3:DscPath3> -u <UTPath4:DscPath4>',
+            action="append", default=None)
 
     def RetrieveCommandLineOptions(self, args):
         '''  Retrieve command line options from the argparser '''
@@ -133,6 +154,10 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
         shell_environment.GetBuildVars().SetValue("TARGET_ARCH"," ".join(args.build_arch.upper().split(",")), "From CmdLine")
         dsc = CommonPlatform.GetDscName(args.build_arch)
         shell_environment.GetBuildVars().SetValue("ACTIVE_PLATFORM", f"OvmfPkg/{dsc}", "From CmdLine")
+        self.RunShellUnitTest = False
+        if args.ShellUnitTestList:
+            CommonPlatform.UpdateUnitTestConfig(args)
+            self.RunShellUnitTest = CommonPlatform.RunShellUnitTest
 
     def GetWorkspaceRoot(self):
         ''' get WorkspacePath '''
@@ -176,6 +201,11 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
         return 0
 
     def PlatformPostBuild(self):
+        if self.RunShellUnitTest:
+            ret = CommonPlatform.BuildUnitTest(self)
+            if ret !=0:
+                logging.critical("Build UnitTest failed")
+                return ret
         return 0
 
     def FlashRomImage(self):
@@ -210,9 +240,13 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
         else:
             args += " -pflash " + os.path.join(OutputPath_FV, "OVMF.fd")    # path to firmware
 
-
         if (self.env.GetValue("MAKE_STARTUP_NSH").upper() == "TRUE"):
             f = open(os.path.join(VirtualDrive, "startup.nsh"), "w")
+            if self.RunShellUnitTest:
+                # When RunShellUnitTest is True, write all efi files name into startup.nsh.
+                CommonPlatform.WriteEfiToStartup(VirtualDrive, f)
+                # Output UnitTest log into ShellUnitTestLog.
+                args += " -serial file:{}".format(CommonPlatform.ShellUnitTestLog)
             f.write("BOOT SUCCESS !!! \n")
             ## add commands here
             f.write("reset -s\n")
@@ -222,6 +256,11 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
 
         if ret == 0xc0000005:
             #for some reason getting a c0000005 on successful return
-            return 0
-
+            ret = 0
+        if self.RunShellUnitTest and ret == 0:
+            # Check the UnitTest boot log.
+            UnitTestResult = CommonPlatform.CheckUnitTestLog()
+            if (UnitTestResult):
+                logging.info("UnitTest failed with this FAILURE MESSAGE:\n{}".format(UnitTestResult))
+                return UnitTestResult
         return ret
-- 
2.31.1.windows.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/3] OvmfPkg/PlatformCI: Add new JOB in .yml of OvmfPkg PlatformCI
  2022-11-22 11:47 [PATCH 0/3] Expand Ovmf PlatformCI to enable CI for Shell UnitTest duntan
  2022-11-22 11:47 ` [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI " duntan
@ 2022-11-22 11:47 ` duntan
  2022-11-22 11:47 ` [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest duntan
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: duntan @ 2022-11-22 11:47 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Jiewen Yao, Jordan Justen, Gerd Hoffmann, Ray Ni

Add new job like OVMF_X64_DEBUG_UNIT_TEST in OvmfPkg PlatformCI
.yml file. New parameter unit_test_list is used to specify Shell
Unit Test list which needs to build and run. Format for this
input should be:'-u ModulePath1:DscPath1,ModulePath2:DscPath2'
or '-u ModulePath1:DscPath1 -u ModulePath2:DscPath2'.
(Path is edk2 workspace relative)

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Ray Ni <ray.ni@intel.com>
---
 OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml    | 11 +++++++++++
 OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml b/OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml
index 7160d95f7e..2242ffebb5 100644
--- a/OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml
+++ b/OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml
@@ -22,6 +22,7 @@ jobs:
       vm_image: 'ubuntu-18.04'
       should_run: true
       run_flags: "MAKE_STARTUP_NSH=TRUE QEMU_HEADLESS=TRUE"
+      unit_test_list: ''
 
     #Use matrix to speed up the build process
     strategy:
@@ -55,6 +56,15 @@ jobs:
             Build.Target: "DEBUG"
             Run.Flags: $(run_flags)
             Run: $(should_run)
+          OVMF_X64_DEBUG_UNIT_TEST:
+            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
+            Build.Arch: "X64"
+            Build.Flags: ""
+            Build.Target: "DEBUG"
+            Run.Flags: $(run_flags)
+            Run: $(should_run)
+            # unit_test_list should be the format: '-u ModulePath1:DscPath1,ModulePath2:DscPath2' or '-u ModulePath1:DscPath1 -u ModulePath2:DscPath2'.(Path is workspace relative)
+            unit_test_list: ''
           OVMF_X64_RELEASE:
             Build.File: "$(package)/PlatformCI/PlatformBuild.py"
             Build.Arch: "X64"
@@ -187,6 +197,7 @@ jobs:
         build_file: $(Build.File)
         build_flags: $(Build.Flags)
         run_flags: $(Run.Flags)
+        unit_test_list: $(unit_test_list)
         extra_install_step:
         - bash: sudo apt-get install qemu
           displayName: Install qemu
diff --git a/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml b/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml
index 7d6344d638..881db9eb27 100644
--- a/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml
+++ b/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml
@@ -21,6 +21,7 @@ jobs:
       vm_image: 'windows-2019'
       should_run: true
       run_flags: "MAKE_STARTUP_NSH=TRUE QEMU_HEADLESS=TRUE"
+      unit_test_list : ''
 
     #Use matrix to speed up the build process
     strategy:
@@ -54,6 +55,15 @@ jobs:
             Build.Target: "DEBUG"
             Run.Flags: $(run_flags)
             Run: $(should_run)
+          OVMF_X64_DEBUG_UNIT_TEST:
+            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
+            Build.Arch: "X64"
+            Build.Flags: ""
+            Build.Target: "DEBUG"
+            Run.Flags: $(run_flags)
+            Run: $(should_run)
+            # unit_test_list should be the format: '-u ModulePath1:DscPath1,ModulePath2:DscPath2' or '-u ModulePath1:DscPath1 -u ModulePath2:DscPath2'.(Path is workspace relative)
+            unit_test_list: ''
           OVMF_X64_RELEASE:
             Build.File: "$(package)/PlatformCI/PlatformBuild.py"
             Build.Arch: "X64"
@@ -133,6 +143,7 @@ jobs:
         build_file: $(Build.File)
         build_flags: $(Build.Flags)
         run_flags: $(Run.Flags)
+        unit_test_list: $(unit_test_list)
         extra_install_step:
         - powershell: choco install qemu --version=2021.5.5; Write-Host "##vso[task.prependpath]c:\Program Files\qemu"
           displayName: Install QEMU and Set QEMU on path # friendly name displayed in the UI
-- 
2.31.1.windows.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
  2022-11-22 11:47 [PATCH 0/3] Expand Ovmf PlatformCI to enable CI for Shell UnitTest duntan
  2022-11-22 11:47 ` [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI " duntan
  2022-11-22 11:47 ` [PATCH 2/3] OvmfPkg/PlatformCI: Add new JOB in .yml of OvmfPkg PlatformCI duntan
@ 2022-11-22 11:47 ` duntan
       [not found] ` <1729E5AF924ED134.5511@groups.io>
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: duntan @ 2022-11-22 11:47 UTC (permalink / raw)
  To: devel; +Cc: Sean Brogan, Michael Kubacki, Michael D Kinney, Liming Gao,
	Ray Ni

Expand PlatformCI build and run steps template for Shell
UnitTest. Add a new parameter unit_test_list to support
building and running specific Shell UnitTest modules.

In stuart_pr_eval step, if the unit_test_list passed from
platform yml file is not null, it will select some packages
from the packages which contain the module in unit_test_list
and set them into a new variable pkgs_to_build base on its
evaluation rule.
In stuart_build step, if unit_test_list is not null,
'${{ parameters.unit_test_list}} -p $(pkgs_to_build)' will be
added into the arguments to build specific UnitTest modules in
pkgs_to_build.
In 'Run to shell' step, if unit_test_list is not null, all the
UnitTest modules built in stuart_build step will runs in shell.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.com>
---
 .azurepipelines/templates/platform-build-run-steps.yml | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/.azurepipelines/templates/platform-build-run-steps.yml b/.azurepipelines/templates/platform-build-run-steps.yml
index 40a31a509f..51503287c4 100644
--- a/.azurepipelines/templates/platform-build-run-steps.yml
+++ b/.azurepipelines/templates/platform-build-run-steps.yml
@@ -30,6 +30,9 @@ parameters:
 - name: run_flags
   type: string
   default: ''
+- name: unit_test_list
+  type: string
+  default: ''
 
 - name: extra_install_step
   type: stepList
@@ -49,7 +52,9 @@ steps:
   displayName: 'Install/Upgrade pip modules'
 
 # Set default
-- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
+- bash: |
+    echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
+    echo "##vso[task.setvariable variable=pkgs_to_build]${{ 'all' }}"
 
 # Fetch the target branch so that pr_eval can diff them.
 # Seems like azure pipelines/github changed checkout process in nov 2020.
@@ -62,7 +67,7 @@ steps:
   displayName: Check if ${{ parameters.build_pkg }} need testing
   inputs:
     filename: stuart_pr_eval
-    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
+    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}" --output-csv-format-string "##vso[task.setvariable variable=pkgs_to_build]{pkgcsv}" ${{ parameters.unit_test_list}}
   condition: eq(variables['Build.Reason'], 'PullRequest')
 
  # Setup repo
@@ -97,14 +102,22 @@ steps:
   inputs:
     filename: stuart_build
     arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}}
-  condition: and(gt(variables.pkg_count, 0), succeeded())
+  condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables.unit_test_list, ''))
+
+# Build specific pkg for UnitTest
+- task: CmdLine@1
+  displayName: Build UnitTest
+  inputs:
+    filename: stuart_build
+    arguments: ${{ parameters.unit_test_list}} -p $(pkgs_to_build) -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}}
+  condition: and(and(gt(variables.pkg_count, 0), succeeded()), not(eq(variables.unit_test_list, '')))
 
 # Run
 - task: CmdLine@1
   displayName: Run to shell
   inputs:
     filename: stuart_build
-    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
+    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly ${{ parameters.unit_test_list}}
   condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
   timeoutInMinutes: 1
 
-- 
2.31.1.windows.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI for Shell UnitTest
       [not found] ` <1729E5AF924ED134.5511@groups.io>
@ 2022-11-28  9:33   ` duntan
  2022-12-05  3:57     ` duntan
  0 siblings, 1 reply; 16+ messages in thread
From: duntan @ 2022-11-28  9:33 UTC (permalink / raw)
  To: devel@edk2.groups.io, Tan, Dun
  Cc: Ard Biesheuvel, Yao, Jiewen, Justen, Jordan L, Gerd Hoffmann,
	Ni, Ray

Hi all,
Could you please help to review this patch? Thanks a lot!

Thanks,
Dun

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
Sent: Tuesday, November 22, 2022 7:48 PM
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Yao, Jiewen <jiewen.yao@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; Ni, Ray <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI for Shell UnitTest

Expand Ovmf PlatformBuild.py and PlatformBuildLib.py to support building and running specific Shell target UnitTest modules.
In the new CommonPlatform class:
It provides new class attributes and new methods to support build and run specific Shell Unit Test modules.

In the new SettingsManager class for stuart_pr_eval:
It calls new API in CommonPlatform to updates PackagesSupported based on -u ShellUnitTestList input from cmd. The package which contains the module in ShellUnitTestList will be added into PackagesSupported for further evaluation.

In the new PlatformBuilder class for stuart_build:
1.In PlatformPostBuild(), it conditionally calls new API in CommonPlatform to build -u ShellUnitTestList in -p PkgsToBuild and copy them to VirtualDrive folder. If no -p option, all the modules in -u ShellUnitTestList will be built.
2.In FlashRomImage(), it conditionally calls the new API in CommonPlatform to write all efi files name in VirtualDrive into startup.nsh and output UnitTest log into ShellUnitTestLog.
3. After the boot process, it conditionally calls new API in CommonPlatform to check the UnitTest boot log.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Ray Ni <ray.ni@intel.com>
---
 OvmfPkg/PlatformCI/PlatformBuild.py    | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/PlatformCI/PlatformBuildLib.py |  51 +++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 157 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/PlatformCI/PlatformBuild.py b/OvmfPkg/PlatformCI/PlatformBuild.py
index 6c541cdea4..72cb7e0e9e 100644
--- a/OvmfPkg/PlatformCI/PlatformBuild.py
+++ b/OvmfPkg/PlatformCI/PlatformBuild.py
@@ -6,6 +6,11 @@
 ##
 import os
 import sys
+import shutil
+import logging
+import re
+from edk2toolext.environment import shell_environment from 
+edk2toolext.environment.multiple_workspace import MultipleWorkspace
 
 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 from PlatformBuildLib import SettingsManager @@ -24,6 +29,10 @@ class CommonPlatform():
     Scopes = ('ovmf', 'edk2-build')
     WorkspaceRoot = os.path.realpath(os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "..", ".."))
+    # Support build and run Shell Unit Test modules
+    UnitTestModuleList = {}
+    RunShellUnitTest   = False
+    ShellUnitTestLog   = ''
 
     @classmethod
     def GetDscName(cls, ArchCsv: str) -> str:
@@ -39,5 +48,108 @@ class CommonPlatform():
         dsc += ".dsc"
         return dsc
 
+    @classmethod
+    def UpdatePackagesSupported(cls, ShellUnitTestListArg):
+        ''' Update PackagesSupported by -u ShellUnitTestList from cmd line. '''
+        UnitTestModuleListStr = ','.join(ShellUnitTestListArg)
+        if not re.search(r'.+.inf:.+.dsc', UnitTestModuleListStr):
+            raise Exception('No valid ModulePath:DscPath in the -u {}'.format(UnitTestModuleListStr))
+        UnitTestModuleList = UnitTestModuleListStr.split(',')
+        PackagesSupported = []
+        for KeyValue in UnitTestModuleList:
+            PkgName = KeyValue.split("Pkg")[0] + 'Pkg'
+            if PkgName not in PackagesSupported:
+                PackagesSupported.append(PkgName)
+        cls.PackagesSupported = tuple(PackagesSupported)
+        print('PackagesSupported for UnitTest is 
+ {}'.format(cls.PackagesSupported))
+
+    @classmethod
+    def UpdateUnitTestConfig(cls, args):
+        ''' Update UnitTest config by -u ShellUnitTestList and -p PkgsToBuildForUT from cmd line.
+            ShellUnitTestList is in this format: {module1:dsc1, module2:dsc2, module3:dsc2...}.
+            Only the modules which are in the PkgsToBuildForUT list are added into self.UnitTestModuleList.
+        '''
+        UnitTestModuleListStr = ','.join(args.ShellUnitTestList)
+        if not re.search(r'.+.inf:.+.dsc', UnitTestModuleListStr):
+            raise Exception('No valid ModulePath:DscPath in the -u {}'.format(args.ShellUnitTestList))
+        UnitTestModuleList = UnitTestModuleListStr.split(',')
+        if args.PkgsToBuildForUT is None or all(['Pkg' not in Pkg for Pkg in args.PkgsToBuildForUT]):
+            # No invalid Pkgs from input. Build all modules in -u UnitTestModuleList.
+            for KeyValue in UnitTestModuleList:
+                UnitTestPath = os.path.normpath(KeyValue.split(":")[0])
+                DscPath      = os.path.normpath(KeyValue.split(":")[1])
+                cls.UnitTestModuleList[UnitTestPath] = DscPath
+        else:
+            PkgsToBuildForUT = ','.join(args.PkgsToBuildForUT).split(',')
+            for KeyValue in UnitTestModuleList:
+                UnitTestPath = os.path.normpath(KeyValue.split(":")[0])
+                DscPath      = os.path.normpath(KeyValue.split(":")[1])
+                PkgName      = UnitTestPath.split("Pkg")[0] + 'Pkg'
+                if PkgName in PkgsToBuildForUT:
+                    cls.UnitTestModuleList[UnitTestPath] = DscPath
+        if len(cls.UnitTestModuleList) > 0:
+            cls.RunShellUnitTest = True
+            cls.ShellUnitTestLog = os.path.join(cls.WorkspaceRoot, 'Build', "BUILDLOG_UnitTest.txt")
+            print('UnitTestModuleList is 
+ {}'.format(cls.UnitTestModuleList))
+
+    def BuildUnitTest(self):
+        ''' Build specific DSC for modules in UnitTestModuleList '''
+        self.env = shell_environment.GetBuildVars()
+        self.ws  = PlatformBuilder.GetWorkspaceRoot(self)
+        self.mws = MultipleWorkspace()
+        self.pp  = ''
+        VirtualDrive = os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"), "VirtualDrive")
+        os.makedirs(VirtualDrive, exist_ok=True)
+
+        # DSC by self.GetDscName() should have been built in BUILD process.
+        BuiltDsc = [CommonPlatform.GetDscName(",".join(self.env.GetValue("TARGET_ARCH").split(' ')))]
+        for UnitTestPath, DscPath in CommonPlatform.UnitTestModuleList.items():
+            if DscPath not in BuiltDsc:
+                ModuleName = os.path.split(UnitTestPath)[1].split('.inf')[0]
+                logging.info('Build {0} for {1}'.format(DscPath, ModuleName))
+                BuiltDsc.append(DscPath)
+                Arch = self.env.GetValue("TARGET_ARCH").split(" ")
+                if 'X64' in Arch:
+                    UTArch = 'X64'
+                else:
+                    UTArch = 'IA32'
+                self.env.AllowOverride("ACTIVE_PLATFORM")
+                self.env.SetValue("ACTIVE_PLATFORM", DscPath, "For UnitTest")
+                self.env.AllowOverride("TARGET_ARCH")
+                self.env.SetValue("TARGET_ARCH", UTArch, "For UnitTest") # Set UnitTest arch the same as Ovmf Shell module.
+                ret = PlatformBuilder.Build(self)                        # Build specific dsc for UnitTest modules
+                if (ret != 0):
+                    return ret
+            ret = PlatformBuilder.ParseDscFile(self) # Parse OUTPUT_DIRECTORY from dsc files
+            if(ret != 0):
+                return ret
+            OutputPath = os.path.normpath(os.path.join(self.ws, self.env.GetValue("OUTPUT_DIRECTORY")))
+            EfiPath    = os.path.join(OutputPath, self.env.GetValue("TARGET") + "_" + self.env.GetValue("TOOL_CHAIN_TAG"),
+                         UTArch, UnitTestPath.split('.inf')[0], "OUTPUT", ModuleName + '.efi')
+            logging.info('Copy {0}.efi from:{1}'.format(ModuleName, EfiPath))
+            shutil.copy(EfiPath, VirtualDrive)
+        return 0
+
+    @staticmethod
+    def WriteEfiToStartup(EfiFolder, FileObj):
+        ''' Write all the .efi files' name in VirtualDrive into Startup.nsh '''
+        for Root,Dirs,Files in os.walk(EfiFolder):
+            for File in Files:
+                if os.path.splitext(File)[1] == '.efi':
+                    FileObj.write("{0} \n".format(File))
+
+    @classmethod
+    def CheckUnitTestLog(cls):
+        ''' Check the boot log for UnitTest '''
+        File        = open(cls.ShellUnitTestLog, "r")
+        FileContent = File.readlines()
+        logging.info('Check the UnitTest boot log:{0}'.format(cls.ShellUnitTestLog))
+        for Index in range(len(FileContent)):
+            if 'FAILURE MESSAGE:' in FileContent[Index]:
+                if FileContent[Index + 1].strip() != '':
+                    FailureMessage = FileContent[Index + 1] + FileContent[Index + 2]
+                    return FailureMessage
+        return 0
+
 import PlatformBuildLib
 PlatformBuildLib.CommonPlatform = CommonPlatform diff --git a/OvmfPkg/PlatformCI/PlatformBuildLib.py b/OvmfPkg/PlatformCI/PlatformBuildLib.py
index bfef9849c7..b42235b2ac 100644
--- a/OvmfPkg/PlatformCI/PlatformBuildLib.py
+++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py
@@ -103,15 +103,28 @@ class SettingsManager(UpdateSettingsManager, SetupSettingsManager, PrEvalSetting
 
         return build_these_packages
 
+    def AddCommandLineOptions(self, parserObj):
+        parserObj.add_argument('-u', '--UnitTest', dest='ShellUnitTestList', type=str,
+            help='Optional - Key:Value that contains Shell UnitTest list and corresponding DscPath you want to test.(workspace relative)'
+            'Can list multiple by doing -u <UTPath1:DscPath1>,<UTPath2:DscPath2> or -u <UTPath3:DscPath3> -u <UTPath4:DscPath4>',
+            action="append", default=None)
+
+    def RetrieveCommandLineOptions(self, args):
+        if args.ShellUnitTestList:
+            
+ CommonPlatform.UpdatePackagesSupported(args.ShellUnitTestList)
+
     def GetPlatformDscAndConfig(self) -> tuple:
         ''' If a platform desires to provide its DSC then Policy 4 will evaluate if
         any of the changes will be built in the dsc.
 
         The tuple should be (<workspace relative path to dsc file>, <input dictionary of dsc key value pairs>)
+        This Policy 4 can only be applied when PackagesSupported only contains OvmfPkg Since it doesn't support
+        mutiple packages evaluation.
         '''
-        dsc = CommonPlatform.GetDscName(",".join(self.ActualArchitectures))
-        return (f"OvmfPkg/{dsc}", {})
-
+        if (len(CommonPlatform.PackagesSupported) == 1) and (CommonPlatform.PackagesSupported[0] == 'OvmfPkg'):
+            dsc = CommonPlatform.GetDscName(",".join(self.ActualArchitectures))
+            return (f"OvmfPkg/{dsc}", {})
+        return None
 
     # ####################################################################################### #
     #                         Actual Configuration for Platform Build                         #
@@ -126,6 +139,14 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
             help="Optional - CSV of architecture to build.  IA32 will use IA32 for Pei & Dxe. "
             "X64 will use X64 for both PEI and DXE.  IA32,X64 will use IA32 for PEI and "
             "X64 for DXE. default is IA32,X64")
+        parserObj.add_argument('-p', '--pkg', '--pkg-dir', dest='PkgsToBuildForUT', type=str,
+            help='Optional - Package list you want to build for UnitTest.efi. (workspace relative).'
+            'Can list multiple by doing -p <pkg1>,<pkg2> or -p <pkg3> -p <pkg4>.If no valid input -p, build and run all -u UnitTest',
+            action="append", default=None)
+        parserObj.add_argument('-u', '--UnitTest', dest='ShellUnitTestList', type=str,
+            help='Optional - Key:Value that contains Shell UnitTest list and corresponding DscPath you want to test.(workspace relative)'
+            'Can list multiple by doing -u <UTPath1:DscPath1>,<UTPath2:DscPath2> or -u <UTPath3:DscPath3> -u <UTPath4:DscPath4>',
+            action="append", default=None)
 
     def RetrieveCommandLineOptions(self, args):
         '''  Retrieve command line options from the argparser '''
@@ -133,6 +154,10 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
         shell_environment.GetBuildVars().SetValue("TARGET_ARCH"," ".join(args.build_arch.upper().split(",")), "From CmdLine")
         dsc = CommonPlatform.GetDscName(args.build_arch)
         shell_environment.GetBuildVars().SetValue("ACTIVE_PLATFORM", f"OvmfPkg/{dsc}", "From CmdLine")
+        self.RunShellUnitTest = False
+        if args.ShellUnitTestList:
+            CommonPlatform.UpdateUnitTestConfig(args)
+            self.RunShellUnitTest = CommonPlatform.RunShellUnitTest
 
     def GetWorkspaceRoot(self):
         ''' get WorkspacePath '''
@@ -176,6 +201,11 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
         return 0
 
     def PlatformPostBuild(self):
+        if self.RunShellUnitTest:
+            ret = CommonPlatform.BuildUnitTest(self)
+            if ret !=0:
+                logging.critical("Build UnitTest failed")
+                return ret
         return 0
 
     def FlashRomImage(self):
@@ -210,9 +240,13 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
         else:
             args += " -pflash " + os.path.join(OutputPath_FV, "OVMF.fd")    # path to firmware
 
-
         if (self.env.GetValue("MAKE_STARTUP_NSH").upper() == "TRUE"):
             f = open(os.path.join(VirtualDrive, "startup.nsh"), "w")
+            if self.RunShellUnitTest:
+                # When RunShellUnitTest is True, write all efi files name into startup.nsh.
+                CommonPlatform.WriteEfiToStartup(VirtualDrive, f)
+                # Output UnitTest log into ShellUnitTestLog.
+                args += " -serial 
+ file:{}".format(CommonPlatform.ShellUnitTestLog)
             f.write("BOOT SUCCESS !!! \n")
             ## add commands here
             f.write("reset -s\n")
@@ -222,6 +256,11 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
 
         if ret == 0xc0000005:
             #for some reason getting a c0000005 on successful return
-            return 0
-
+            ret = 0
+        if self.RunShellUnitTest and ret == 0:
+            # Check the UnitTest boot log.
+            UnitTestResult = CommonPlatform.CheckUnitTestLog()
+            if (UnitTestResult):
+                logging.info("UnitTest failed with this FAILURE MESSAGE:\n{}".format(UnitTestResult))
+                return UnitTestResult
         return ret
--
2.31.1.windows.1







^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
       [not found] ` <1729E5B1AD6A86B6.31464@groups.io>
@ 2022-11-28  9:34   ` duntan
  2022-12-05  3:57     ` duntan
  0 siblings, 1 reply; 16+ messages in thread
From: duntan @ 2022-11-28  9:34 UTC (permalink / raw)
  To: devel@edk2.groups.io, Tan, Dun
  Cc: Sean Brogan, Michael Kubacki, Kinney, Michael D, Gao, Liming,
	Ni, Ray

Hi all,
Could you please help to review this patch? Thanks a lot!

Thanks,
Dun

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
Sent: Tuesday, November 22, 2022 7:48 PM
To: devel@edk2.groups.io
Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Expand PlatformCI build and run steps template for Shell UnitTest. Add a new parameter unit_test_list to support building and running specific Shell UnitTest modules.

In stuart_pr_eval step, if the unit_test_list passed from platform yml file is not null, it will select some packages from the packages which contain the module in unit_test_list and set them into a new variable pkgs_to_build base on its evaluation rule.
In stuart_build step, if unit_test_list is not null, '${{ parameters.unit_test_list}} -p $(pkgs_to_build)' will be added into the arguments to build specific UnitTest modules in pkgs_to_build.
In 'Run to shell' step, if unit_test_list is not null, all the UnitTest modules built in stuart_build step will runs in shell.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.com>
---
 .azurepipelines/templates/platform-build-run-steps.yml | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/.azurepipelines/templates/platform-build-run-steps.yml b/.azurepipelines/templates/platform-build-run-steps.yml
index 40a31a509f..51503287c4 100644
--- a/.azurepipelines/templates/platform-build-run-steps.yml
+++ b/.azurepipelines/templates/platform-build-run-steps.yml
@@ -30,6 +30,9 @@ parameters:
 - name: run_flags
   type: string
   default: ''
+- name: unit_test_list
+  type: string
+  default: ''
 
 - name: extra_install_step
   type: stepList
@@ -49,7 +52,9 @@ steps:
   displayName: 'Install/Upgrade pip modules'
 
 # Set default
-- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
+- bash: |
+    echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
+    echo "##vso[task.setvariable variable=pkgs_to_build]${{ 'all' }}"
 
 # Fetch the target branch so that pr_eval can diff them.
 # Seems like azure pipelines/github changed checkout process in nov 2020.
@@ -62,7 +67,7 @@ steps:
   displayName: Check if ${{ parameters.build_pkg }} need testing
   inputs:
     filename: stuart_pr_eval
-    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
+    arguments: -c ${{ parameters.build_file }} -t ${{ 
+ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target 
+ origin/$(System.PullRequest.targetBranch) --output-count-format-string 
+ "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}" 
+ --output-csv-format-string "##vso[task.setvariable 
+ variable=pkgs_to_build]{pkgcsv}" ${{ parameters.unit_test_list}}
   condition: eq(variables['Build.Reason'], 'PullRequest')
 
  # Setup repo
@@ -97,14 +102,22 @@ steps:
   inputs:
     filename: stuart_build
     arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}}
-  condition: and(gt(variables.pkg_count, 0), succeeded())
+  condition: and(and(gt(variables.pkg_count, 0), succeeded()), 
+ eq(variables.unit_test_list, ''))
+
+# Build specific pkg for UnitTest
+- task: CmdLine@1
+  displayName: Build UnitTest
+  inputs:
+    filename: stuart_build
+    arguments: ${{ parameters.unit_test_list}} -p $(pkgs_to_build) -c 
+${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
+parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ 
+parameters.build_arch}} ${{ parameters.build_flags}}
+  condition: and(and(gt(variables.pkg_count, 0), succeeded()), 
+not(eq(variables.unit_test_list, '')))
 
 # Run
 - task: CmdLine@1
   displayName: Run to shell
   inputs:
     filename: stuart_build
-    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
+    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
+ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a 
+ ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ 
+ parameters.run_flags }} --FlashOnly ${{ parameters.unit_test_list}}
   condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
   timeoutInMinutes: 1
 
--
2.31.1.windows.1







^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 2/3] OvmfPkg/PlatformCI: Add new JOB in .yml of OvmfPkg PlatformCI
       [not found] ` <1729E5B0889AD806.5511@groups.io>
@ 2022-11-28  9:36   ` duntan
  0 siblings, 0 replies; 16+ messages in thread
From: duntan @ 2022-11-28  9:36 UTC (permalink / raw)
  To: devel@edk2.groups.io, Tan, Dun
  Cc: Ard Biesheuvel, Yao, Jiewen, Justen, Jordan L, Gerd Hoffmann,
	Ni, Ray

Hi all,
Could you please help to review this patch? Thanks a lot!

Thanks,
Dun

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
Sent: Tuesday, November 22, 2022 7:48 PM
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Yao, Jiewen <jiewen.yao@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; Ni, Ray <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH 2/3] OvmfPkg/PlatformCI: Add new JOB in .yml of OvmfPkg PlatformCI

Add new job like OVMF_X64_DEBUG_UNIT_TEST in OvmfPkg PlatformCI .yml file. New parameter unit_test_list is used to specify Shell Unit Test list which needs to build and run. Format for this input should be:'-u ModulePath1:DscPath1,ModulePath2:DscPath2'
or '-u ModulePath1:DscPath1 -u ModulePath2:DscPath2'.
(Path is edk2 workspace relative)

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Ray Ni <ray.ni@intel.com>
---
 OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml    | 11 +++++++++++
 OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml b/OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml
index 7160d95f7e..2242ffebb5 100644
--- a/OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml
+++ b/OvmfPkg/PlatformCI/.azurepipelines/Ubuntu-GCC5.yml
@@ -22,6 +22,7 @@ jobs:
       vm_image: 'ubuntu-18.04'
       should_run: true
       run_flags: "MAKE_STARTUP_NSH=TRUE QEMU_HEADLESS=TRUE"
+      unit_test_list: ''
 
     #Use matrix to speed up the build process
     strategy:
@@ -55,6 +56,15 @@ jobs:
             Build.Target: "DEBUG"
             Run.Flags: $(run_flags)
             Run: $(should_run)
+          OVMF_X64_DEBUG_UNIT_TEST:
+            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
+            Build.Arch: "X64"
+            Build.Flags: ""
+            Build.Target: "DEBUG"
+            Run.Flags: $(run_flags)
+            Run: $(should_run)
+            # unit_test_list should be the format: '-u ModulePath1:DscPath1,ModulePath2:DscPath2' or '-u ModulePath1:DscPath1 -u ModulePath2:DscPath2'.(Path is workspace relative)
+            unit_test_list: ''
           OVMF_X64_RELEASE:
             Build.File: "$(package)/PlatformCI/PlatformBuild.py"
             Build.Arch: "X64"
@@ -187,6 +197,7 @@ jobs:
         build_file: $(Build.File)
         build_flags: $(Build.Flags)
         run_flags: $(Run.Flags)
+        unit_test_list: $(unit_test_list)
         extra_install_step:
         - bash: sudo apt-get install qemu
           displayName: Install qemu
diff --git a/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml b/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml
index 7d6344d638..881db9eb27 100644
--- a/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml
+++ b/OvmfPkg/PlatformCI/.azurepipelines/Windows-VS2019.yml
@@ -21,6 +21,7 @@ jobs:
       vm_image: 'windows-2019'
       should_run: true
       run_flags: "MAKE_STARTUP_NSH=TRUE QEMU_HEADLESS=TRUE"
+      unit_test_list : ''
 
     #Use matrix to speed up the build process
     strategy:
@@ -54,6 +55,15 @@ jobs:
             Build.Target: "DEBUG"
             Run.Flags: $(run_flags)
             Run: $(should_run)
+          OVMF_X64_DEBUG_UNIT_TEST:
+            Build.File: "$(package)/PlatformCI/PlatformBuild.py"
+            Build.Arch: "X64"
+            Build.Flags: ""
+            Build.Target: "DEBUG"
+            Run.Flags: $(run_flags)
+            Run: $(should_run)
+            # unit_test_list should be the format: '-u ModulePath1:DscPath1,ModulePath2:DscPath2' or '-u ModulePath1:DscPath1 -u ModulePath2:DscPath2'.(Path is workspace relative)
+            unit_test_list: ''
           OVMF_X64_RELEASE:
             Build.File: "$(package)/PlatformCI/PlatformBuild.py"
             Build.Arch: "X64"
@@ -133,6 +143,7 @@ jobs:
         build_file: $(Build.File)
         build_flags: $(Build.Flags)
         run_flags: $(Run.Flags)
+        unit_test_list: $(unit_test_list)
         extra_install_step:
         - powershell: choco install qemu --version=2021.5.5; Write-Host "##vso[task.prependpath]c:\Program Files\qemu"
           displayName: Install QEMU and Set QEMU on path # friendly name displayed in the UI
--
2.31.1.windows.1







^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI for Shell UnitTest
  2022-11-28  9:33   ` [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI " duntan
@ 2022-12-05  3:57     ` duntan
  2022-12-09  7:03       ` Yao, Jiewen
  0 siblings, 1 reply; 16+ messages in thread
From: duntan @ 2022-12-05  3:57 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: Ard Biesheuvel, Yao, Jiewen, Justen, Jordan L, Gerd Hoffmann,
	Ni, Ray, Sean Brogan, Kinney, Michael D

Hi all,
Is there anything else I can do to speed up the review process for this patch set? Looking forward to your reply.

Thanks,
Dun

-----Original Message-----
From: Tan, Dun 
Sent: Monday, November 28, 2022 5:34 PM
To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Yao, Jiewen <jiewen.yao@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; Ni, Ray <ray.ni@intel.com>
Subject: RE: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI for Shell UnitTest

Hi all,
Could you please help to review this patch? Thanks a lot!

Thanks,
Dun

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
Sent: Tuesday, November 22, 2022 7:48 PM
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Yao, Jiewen <jiewen.yao@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; Ni, Ray <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI for Shell UnitTest

Expand Ovmf PlatformBuild.py and PlatformBuildLib.py to support building and running specific Shell target UnitTest modules.
In the new CommonPlatform class:
It provides new class attributes and new methods to support build and run specific Shell Unit Test modules.

In the new SettingsManager class for stuart_pr_eval:
It calls new API in CommonPlatform to updates PackagesSupported based on -u ShellUnitTestList input from cmd. The package which contains the module in ShellUnitTestList will be added into PackagesSupported for further evaluation.

In the new PlatformBuilder class for stuart_build:
1.In PlatformPostBuild(), it conditionally calls new API in CommonPlatform to build -u ShellUnitTestList in -p PkgsToBuild and copy them to VirtualDrive folder. If no -p option, all the modules in -u ShellUnitTestList will be built.
2.In FlashRomImage(), it conditionally calls the new API in CommonPlatform to write all efi files name in VirtualDrive into startup.nsh and output UnitTest log into ShellUnitTestLog.
3. After the boot process, it conditionally calls new API in CommonPlatform to check the UnitTest boot log.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Ray Ni <ray.ni@intel.com>
---
 OvmfPkg/PlatformCI/PlatformBuild.py    | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 OvmfPkg/PlatformCI/PlatformBuildLib.py |  51 +++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 157 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/PlatformCI/PlatformBuild.py b/OvmfPkg/PlatformCI/PlatformBuild.py
index 6c541cdea4..72cb7e0e9e 100644
--- a/OvmfPkg/PlatformCI/PlatformBuild.py
+++ b/OvmfPkg/PlatformCI/PlatformBuild.py
@@ -6,6 +6,11 @@
 ##
 import os
 import sys
+import shutil
+import logging
+import re
+from edk2toolext.environment import shell_environment from 
+edk2toolext.environment.multiple_workspace import MultipleWorkspace
 
 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
 from PlatformBuildLib import SettingsManager @@ -24,6 +29,10 @@ class CommonPlatform():
     Scopes = ('ovmf', 'edk2-build')
     WorkspaceRoot = os.path.realpath(os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "..", ".."))
+    # Support build and run Shell Unit Test modules
+    UnitTestModuleList = {}
+    RunShellUnitTest   = False
+    ShellUnitTestLog   = ''
 
     @classmethod
     def GetDscName(cls, ArchCsv: str) -> str:
@@ -39,5 +48,108 @@ class CommonPlatform():
         dsc += ".dsc"
         return dsc
 
+    @classmethod
+    def UpdatePackagesSupported(cls, ShellUnitTestListArg):
+        ''' Update PackagesSupported by -u ShellUnitTestList from cmd line. '''
+        UnitTestModuleListStr = ','.join(ShellUnitTestListArg)
+        if not re.search(r'.+.inf:.+.dsc', UnitTestModuleListStr):
+            raise Exception('No valid ModulePath:DscPath in the -u {}'.format(UnitTestModuleListStr))
+        UnitTestModuleList = UnitTestModuleListStr.split(',')
+        PackagesSupported = []
+        for KeyValue in UnitTestModuleList:
+            PkgName = KeyValue.split("Pkg")[0] + 'Pkg'
+            if PkgName not in PackagesSupported:
+                PackagesSupported.append(PkgName)
+        cls.PackagesSupported = tuple(PackagesSupported)
+        print('PackagesSupported for UnitTest is
+ {}'.format(cls.PackagesSupported))
+
+    @classmethod
+    def UpdateUnitTestConfig(cls, args):
+        ''' Update UnitTest config by -u ShellUnitTestList and -p PkgsToBuildForUT from cmd line.
+            ShellUnitTestList is in this format: {module1:dsc1, module2:dsc2, module3:dsc2...}.
+            Only the modules which are in the PkgsToBuildForUT list are added into self.UnitTestModuleList.
+        '''
+        UnitTestModuleListStr = ','.join(args.ShellUnitTestList)
+        if not re.search(r'.+.inf:.+.dsc', UnitTestModuleListStr):
+            raise Exception('No valid ModulePath:DscPath in the -u {}'.format(args.ShellUnitTestList))
+        UnitTestModuleList = UnitTestModuleListStr.split(',')
+        if args.PkgsToBuildForUT is None or all(['Pkg' not in Pkg for Pkg in args.PkgsToBuildForUT]):
+            # No invalid Pkgs from input. Build all modules in -u UnitTestModuleList.
+            for KeyValue in UnitTestModuleList:
+                UnitTestPath = os.path.normpath(KeyValue.split(":")[0])
+                DscPath      = os.path.normpath(KeyValue.split(":")[1])
+                cls.UnitTestModuleList[UnitTestPath] = DscPath
+        else:
+            PkgsToBuildForUT = ','.join(args.PkgsToBuildForUT).split(',')
+            for KeyValue in UnitTestModuleList:
+                UnitTestPath = os.path.normpath(KeyValue.split(":")[0])
+                DscPath      = os.path.normpath(KeyValue.split(":")[1])
+                PkgName      = UnitTestPath.split("Pkg")[0] + 'Pkg'
+                if PkgName in PkgsToBuildForUT:
+                    cls.UnitTestModuleList[UnitTestPath] = DscPath
+        if len(cls.UnitTestModuleList) > 0:
+            cls.RunShellUnitTest = True
+            cls.ShellUnitTestLog = os.path.join(cls.WorkspaceRoot, 'Build', "BUILDLOG_UnitTest.txt")
+            print('UnitTestModuleList is
+ {}'.format(cls.UnitTestModuleList))
+
+    def BuildUnitTest(self):
+        ''' Build specific DSC for modules in UnitTestModuleList '''
+        self.env = shell_environment.GetBuildVars()
+        self.ws  = PlatformBuilder.GetWorkspaceRoot(self)
+        self.mws = MultipleWorkspace()
+        self.pp  = ''
+        VirtualDrive = os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"), "VirtualDrive")
+        os.makedirs(VirtualDrive, exist_ok=True)
+
+        # DSC by self.GetDscName() should have been built in BUILD process.
+        BuiltDsc = [CommonPlatform.GetDscName(",".join(self.env.GetValue("TARGET_ARCH").split(' ')))]
+        for UnitTestPath, DscPath in CommonPlatform.UnitTestModuleList.items():
+            if DscPath not in BuiltDsc:
+                ModuleName = os.path.split(UnitTestPath)[1].split('.inf')[0]
+                logging.info('Build {0} for {1}'.format(DscPath, ModuleName))
+                BuiltDsc.append(DscPath)
+                Arch = self.env.GetValue("TARGET_ARCH").split(" ")
+                if 'X64' in Arch:
+                    UTArch = 'X64'
+                else:
+                    UTArch = 'IA32'
+                self.env.AllowOverride("ACTIVE_PLATFORM")
+                self.env.SetValue("ACTIVE_PLATFORM", DscPath, "For UnitTest")
+                self.env.AllowOverride("TARGET_ARCH")
+                self.env.SetValue("TARGET_ARCH", UTArch, "For UnitTest") # Set UnitTest arch the same as Ovmf Shell module.
+                ret = PlatformBuilder.Build(self)                        # Build specific dsc for UnitTest modules
+                if (ret != 0):
+                    return ret
+            ret = PlatformBuilder.ParseDscFile(self) # Parse OUTPUT_DIRECTORY from dsc files
+            if(ret != 0):
+                return ret
+            OutputPath = os.path.normpath(os.path.join(self.ws, self.env.GetValue("OUTPUT_DIRECTORY")))
+            EfiPath    = os.path.join(OutputPath, self.env.GetValue("TARGET") + "_" + self.env.GetValue("TOOL_CHAIN_TAG"),
+                         UTArch, UnitTestPath.split('.inf')[0], "OUTPUT", ModuleName + '.efi')
+            logging.info('Copy {0}.efi from:{1}'.format(ModuleName, EfiPath))
+            shutil.copy(EfiPath, VirtualDrive)
+        return 0
+
+    @staticmethod
+    def WriteEfiToStartup(EfiFolder, FileObj):
+        ''' Write all the .efi files' name in VirtualDrive into Startup.nsh '''
+        for Root,Dirs,Files in os.walk(EfiFolder):
+            for File in Files:
+                if os.path.splitext(File)[1] == '.efi':
+                    FileObj.write("{0} \n".format(File))
+
+    @classmethod
+    def CheckUnitTestLog(cls):
+        ''' Check the boot log for UnitTest '''
+        File        = open(cls.ShellUnitTestLog, "r")
+        FileContent = File.readlines()
+        logging.info('Check the UnitTest boot log:{0}'.format(cls.ShellUnitTestLog))
+        for Index in range(len(FileContent)):
+            if 'FAILURE MESSAGE:' in FileContent[Index]:
+                if FileContent[Index + 1].strip() != '':
+                    FailureMessage = FileContent[Index + 1] + FileContent[Index + 2]
+                    return FailureMessage
+        return 0
+
 import PlatformBuildLib
 PlatformBuildLib.CommonPlatform = CommonPlatform diff --git a/OvmfPkg/PlatformCI/PlatformBuildLib.py b/OvmfPkg/PlatformCI/PlatformBuildLib.py
index bfef9849c7..b42235b2ac 100644
--- a/OvmfPkg/PlatformCI/PlatformBuildLib.py
+++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py
@@ -103,15 +103,28 @@ class SettingsManager(UpdateSettingsManager, SetupSettingsManager, PrEvalSetting
 
         return build_these_packages
 
+    def AddCommandLineOptions(self, parserObj):
+        parserObj.add_argument('-u', '--UnitTest', dest='ShellUnitTestList', type=str,
+            help='Optional - Key:Value that contains Shell UnitTest list and corresponding DscPath you want to test.(workspace relative)'
+            'Can list multiple by doing -u <UTPath1:DscPath1>,<UTPath2:DscPath2> or -u <UTPath3:DscPath3> -u <UTPath4:DscPath4>',
+            action="append", default=None)
+
+    def RetrieveCommandLineOptions(self, args):
+        if args.ShellUnitTestList:
+            
+ CommonPlatform.UpdatePackagesSupported(args.ShellUnitTestList)
+
     def GetPlatformDscAndConfig(self) -> tuple:
         ''' If a platform desires to provide its DSC then Policy 4 will evaluate if
         any of the changes will be built in the dsc.
 
         The tuple should be (<workspace relative path to dsc file>, <input dictionary of dsc key value pairs>)
+        This Policy 4 can only be applied when PackagesSupported only contains OvmfPkg Since it doesn't support
+        mutiple packages evaluation.
         '''
-        dsc = CommonPlatform.GetDscName(",".join(self.ActualArchitectures))
-        return (f"OvmfPkg/{dsc}", {})
-
+        if (len(CommonPlatform.PackagesSupported) == 1) and (CommonPlatform.PackagesSupported[0] == 'OvmfPkg'):
+            dsc = CommonPlatform.GetDscName(",".join(self.ActualArchitectures))
+            return (f"OvmfPkg/{dsc}", {})
+        return None
 
     # ####################################################################################### #
     #                         Actual Configuration for Platform Build                         #
@@ -126,6 +139,14 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
             help="Optional - CSV of architecture to build.  IA32 will use IA32 for Pei & Dxe. "
             "X64 will use X64 for both PEI and DXE.  IA32,X64 will use IA32 for PEI and "
             "X64 for DXE. default is IA32,X64")
+        parserObj.add_argument('-p', '--pkg', '--pkg-dir', dest='PkgsToBuildForUT', type=str,
+            help='Optional - Package list you want to build for UnitTest.efi. (workspace relative).'
+            'Can list multiple by doing -p <pkg1>,<pkg2> or -p <pkg3> -p <pkg4>.If no valid input -p, build and run all -u UnitTest',
+            action="append", default=None)
+        parserObj.add_argument('-u', '--UnitTest', dest='ShellUnitTestList', type=str,
+            help='Optional - Key:Value that contains Shell UnitTest list and corresponding DscPath you want to test.(workspace relative)'
+            'Can list multiple by doing -u <UTPath1:DscPath1>,<UTPath2:DscPath2> or -u <UTPath3:DscPath3> -u <UTPath4:DscPath4>',
+            action="append", default=None)
 
     def RetrieveCommandLineOptions(self, args):
         '''  Retrieve command line options from the argparser '''
@@ -133,6 +154,10 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
         shell_environment.GetBuildVars().SetValue("TARGET_ARCH"," ".join(args.build_arch.upper().split(",")), "From CmdLine")
         dsc = CommonPlatform.GetDscName(args.build_arch)
         shell_environment.GetBuildVars().SetValue("ACTIVE_PLATFORM", f"OvmfPkg/{dsc}", "From CmdLine")
+        self.RunShellUnitTest = False
+        if args.ShellUnitTestList:
+            CommonPlatform.UpdateUnitTestConfig(args)
+            self.RunShellUnitTest = CommonPlatform.RunShellUnitTest
 
     def GetWorkspaceRoot(self):
         ''' get WorkspacePath '''
@@ -176,6 +201,11 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
         return 0
 
     def PlatformPostBuild(self):
+        if self.RunShellUnitTest:
+            ret = CommonPlatform.BuildUnitTest(self)
+            if ret !=0:
+                logging.critical("Build UnitTest failed")
+                return ret
         return 0
 
     def FlashRomImage(self):
@@ -210,9 +240,13 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
         else:
             args += " -pflash " + os.path.join(OutputPath_FV, "OVMF.fd")    # path to firmware
 
-
         if (self.env.GetValue("MAKE_STARTUP_NSH").upper() == "TRUE"):
             f = open(os.path.join(VirtualDrive, "startup.nsh"), "w")
+            if self.RunShellUnitTest:
+                # When RunShellUnitTest is True, write all efi files name into startup.nsh.
+                CommonPlatform.WriteEfiToStartup(VirtualDrive, f)
+                # Output UnitTest log into ShellUnitTestLog.
+                args += " -serial
+ file:{}".format(CommonPlatform.ShellUnitTestLog)
             f.write("BOOT SUCCESS !!! \n")
             ## add commands here
             f.write("reset -s\n")
@@ -222,6 +256,11 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
 
         if ret == 0xc0000005:
             #for some reason getting a c0000005 on successful return
-            return 0
-
+            ret = 0
+        if self.RunShellUnitTest and ret == 0:
+            # Check the UnitTest boot log.
+            UnitTestResult = CommonPlatform.CheckUnitTestLog()
+            if (UnitTestResult):
+                logging.info("UnitTest failed with this FAILURE MESSAGE:\n{}".format(UnitTestResult))
+                return UnitTestResult
         return ret
--
2.31.1.windows.1







^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
  2022-11-28  9:34   ` [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template " duntan
@ 2022-12-05  3:57     ` duntan
  2022-12-06  1:23       ` Michael Kubacki
  0 siblings, 1 reply; 16+ messages in thread
From: duntan @ 2022-12-05  3:57 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: Sean Brogan, Michael Kubacki, Kinney, Michael D, Gao, Liming,
	Ni, Ray

Hi all,
Is there anything else I can do to speed up the review process for this patch set? Looking forward to your reply.

Thanks,
Dun
-----Original Message-----
From: Tan, Dun 
Sent: Monday, November 28, 2022 5:34 PM
To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: RE: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Hi all,
Could you please help to review this patch? Thanks a lot!

Thanks,
Dun

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
Sent: Tuesday, November 22, 2022 7:48 PM
To: devel@edk2.groups.io
Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Expand PlatformCI build and run steps template for Shell UnitTest. Add a new parameter unit_test_list to support building and running specific Shell UnitTest modules.

In stuart_pr_eval step, if the unit_test_list passed from platform yml file is not null, it will select some packages from the packages which contain the module in unit_test_list and set them into a new variable pkgs_to_build base on its evaluation rule.
In stuart_build step, if unit_test_list is not null, '${{ parameters.unit_test_list}} -p $(pkgs_to_build)' will be added into the arguments to build specific UnitTest modules in pkgs_to_build.
In 'Run to shell' step, if unit_test_list is not null, all the UnitTest modules built in stuart_build step will runs in shell.

Signed-off-by: Dun Tan <dun.tan@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.com>
---
 .azurepipelines/templates/platform-build-run-steps.yml | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/.azurepipelines/templates/platform-build-run-steps.yml b/.azurepipelines/templates/platform-build-run-steps.yml
index 40a31a509f..51503287c4 100644
--- a/.azurepipelines/templates/platform-build-run-steps.yml
+++ b/.azurepipelines/templates/platform-build-run-steps.yml
@@ -30,6 +30,9 @@ parameters:
 - name: run_flags
   type: string
   default: ''
+- name: unit_test_list
+  type: string
+  default: ''
 
 - name: extra_install_step
   type: stepList
@@ -49,7 +52,9 @@ steps:
   displayName: 'Install/Upgrade pip modules'
 
 # Set default
-- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
+- bash: |
+    echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
+    echo "##vso[task.setvariable variable=pkgs_to_build]${{ 'all' }}"
 
 # Fetch the target branch so that pr_eval can diff them.
 # Seems like azure pipelines/github changed checkout process in nov 2020.
@@ -62,7 +67,7 @@ steps:
   displayName: Check if ${{ parameters.build_pkg }} need testing
   inputs:
     filename: stuart_pr_eval
-    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
+    arguments: -c ${{ parameters.build_file }} -t ${{ 
+ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target
+ origin/$(System.PullRequest.targetBranch) --output-count-format-string 
+ "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
+ --output-csv-format-string "##vso[task.setvariable 
+ variable=pkgs_to_build]{pkgcsv}" ${{ parameters.unit_test_list}}
   condition: eq(variables['Build.Reason'], 'PullRequest')
 
  # Setup repo
@@ -97,14 +102,22 @@ steps:
   inputs:
     filename: stuart_build
     arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}}
-  condition: and(gt(variables.pkg_count, 0), succeeded())
+  condition: and(and(gt(variables.pkg_count, 0), succeeded()), 
+ eq(variables.unit_test_list, ''))
+
+# Build specific pkg for UnitTest
+- task: CmdLine@1
+  displayName: Build UnitTest
+  inputs:
+    filename: stuart_build
+    arguments: ${{ parameters.unit_test_list}} -p $(pkgs_to_build) -c 
+${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
+parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ 
+parameters.build_arch}} ${{ parameters.build_flags}}
+  condition: and(and(gt(variables.pkg_count, 0), succeeded()), 
+not(eq(variables.unit_test_list, '')))
 
 # Run
 - task: CmdLine@1
   displayName: Run to shell
   inputs:
     filename: stuart_build
-    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
+    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
+ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a 
+ ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ 
+ parameters.run_flags }} --FlashOnly ${{ parameters.unit_test_list}}
   condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
   timeoutInMinutes: 1
 
--
2.31.1.windows.1







^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
  2022-12-05  3:57     ` duntan
@ 2022-12-06  1:23       ` Michael Kubacki
  2022-12-06  4:46         ` duntan
  0 siblings, 1 reply; 16+ messages in thread
From: Michael Kubacki @ 2022-12-06  1:23 UTC (permalink / raw)
  To: devel, dun.tan; +Cc: Sean Brogan, Kinney, Michael D, Gao, Liming, Ni, Ray

Sorry for the delay Dun. Can you please share an edk2 pull request with 
this change?

Thanks,
Michael

On 12/4/2022 10:57 PM, duntan wrote:
> Hi all,
> Is there anything else I can do to speed up the review process for this patch set? Looking forward to your reply.
> 
> Thanks,
> Dun
> -----Original Message-----
> From: Tan, Dun
> Sent: Monday, November 28, 2022 5:34 PM
> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
> Subject: RE: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
> 
> Hi all,
> Could you please help to review this patch? Thanks a lot!
> 
> Thanks,
> Dun
> 
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
> Sent: Tuesday, November 22, 2022 7:48 PM
> To: devel@edk2.groups.io
> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki <mikuback@linux.microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
> Subject: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
> 
> Expand PlatformCI build and run steps template for Shell UnitTest. Add a new parameter unit_test_list to support building and running specific Shell UnitTest modules.
> 
> In stuart_pr_eval step, if the unit_test_list passed from platform yml file is not null, it will select some packages from the packages which contain the module in unit_test_list and set them into a new variable pkgs_to_build base on its evaluation rule.
> In stuart_build step, if unit_test_list is not null, '${{ parameters.unit_test_list}} -p $(pkgs_to_build)' will be added into the arguments to build specific UnitTest modules in pkgs_to_build.
> In 'Run to shell' step, if unit_test_list is not null, all the UnitTest modules built in stuart_build step will runs in shell.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Kubacki <mikuback@linux.microsoft.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Ray Ni <ray.ni@intel.com>
> ---
>   .azurepipelines/templates/platform-build-run-steps.yml | 21 +++++++++++++++++----
>   1 file changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/.azurepipelines/templates/platform-build-run-steps.yml b/.azurepipelines/templates/platform-build-run-steps.yml
> index 40a31a509f..51503287c4 100644
> --- a/.azurepipelines/templates/platform-build-run-steps.yml
> +++ b/.azurepipelines/templates/platform-build-run-steps.yml
> @@ -30,6 +30,9 @@ parameters:
>   - name: run_flags
>     type: string
>     default: ''
> +- name: unit_test_list
> +  type: string
> +  default: ''
>   
>   - name: extra_install_step
>     type: stepList
> @@ -49,7 +52,9 @@ steps:
>     displayName: 'Install/Upgrade pip modules'
>   
>   # Set default
> -- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
> +- bash: |
> +    echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
> +    echo "##vso[task.setvariable variable=pkgs_to_build]${{ 'all' }}"
>   
>   # Fetch the target branch so that pr_eval can diff them.
>   # Seems like azure pipelines/github changed checkout process in nov 2020.
> @@ -62,7 +67,7 @@ steps:
>     displayName: Check if ${{ parameters.build_pkg }} need testing
>     inputs:
>       filename: stuart_pr_eval
> -    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
> +    arguments: -c ${{ parameters.build_file }} -t ${{
> + parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target
> + origin/$(System.PullRequest.targetBranch) --output-count-format-string
> + "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
> + --output-csv-format-string "##vso[task.setvariable
> + variable=pkgs_to_build]{pkgcsv}" ${{ parameters.unit_test_list}}
>     condition: eq(variables['Build.Reason'], 'PullRequest')
>   
>    # Setup repo
> @@ -97,14 +102,22 @@ steps:
>     inputs:
>       filename: stuart_build
>       arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}}
> -  condition: and(gt(variables.pkg_count, 0), succeeded())
> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()),
> + eq(variables.unit_test_list, ''))
> +
> +# Build specific pkg for UnitTest
> +- task: CmdLine@1
> +  displayName: Build UnitTest
> +  inputs:
> +    filename: stuart_build
> +    arguments: ${{ parameters.unit_test_list}} -p $(pkgs_to_build) -c
> +${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
> +parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{
> +parameters.build_arch}} ${{ parameters.build_flags}}
> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()),
> +not(eq(variables.unit_test_list, '')))
>   
>   # Run
>   - task: CmdLine@1
>     displayName: Run to shell
>     inputs:
>       filename: stuart_build
> -    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
> +    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
> + parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
> + ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{
> + parameters.run_flags }} --FlashOnly ${{ parameters.unit_test_list}}
>     condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
>     timeoutInMinutes: 1
>   
> --
> 2.31.1.windows.1
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
  2022-12-06  1:23       ` Michael Kubacki
@ 2022-12-06  4:46         ` duntan
  2022-12-08  2:57           ` Michael Kubacki
  0 siblings, 1 reply; 16+ messages in thread
From: duntan @ 2022-12-06  4:46 UTC (permalink / raw)
  To: Michael Kubacki, devel@edk2.groups.io
  Cc: Sean Brogan, Kinney, Michael D, Gao, Liming, Ni, Ray

Hi Michael,
Thanks for the reply! In the following PR, I added an unit test list in the new OvmfPkg platform CI JOB. In  PlatformCI_OvmfPkg_Ubuntu_GCC5_PR and PlatformCI_OvmfPkg_Windows_VS2019_PR, the CI for specific unit test list was triggered.
https://github.com/tianocore/edk2/pull/3651

Thanks,
Dun

-----Original Message-----
From: Michael Kubacki <mikuback@linux.microsoft.com> 
Sent: Tuesday, December 6, 2022 9:24 AM
To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Sorry for the delay Dun. Can you please share an edk2 pull request with this change?

Thanks,
Michael

On 12/4/2022 10:57 PM, duntan wrote:
> Hi all,
> Is there anything else I can do to speed up the review process for this patch set? Looking forward to your reply.
> 
> Thanks,
> Dun
> -----Original Message-----
> From: Tan, Dun
> Sent: Monday, November 28, 2022 5:34 PM
> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki 
> <mikuback@linux.microsoft.com>; Kinney, Michael D 
> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; 
> Ni, Ray <ray.ni@intel.com>
> Subject: RE: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand 
> PlatformCI template for Shell UnitTest
> 
> Hi all,
> Could you please help to review this patch? Thanks a lot!
> 
> Thanks,
> Dun
> 
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
> Sent: Tuesday, November 22, 2022 7:48 PM
> To: devel@edk2.groups.io
> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki 
> <mikuback@linux.microsoft.com>; Kinney, Michael D 
> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; 
> Ni, Ray <ray.ni@intel.com>
> Subject: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI 
> template for Shell UnitTest
> 
> Expand PlatformCI build and run steps template for Shell UnitTest. Add a new parameter unit_test_list to support building and running specific Shell UnitTest modules.
> 
> In stuart_pr_eval step, if the unit_test_list passed from platform yml file is not null, it will select some packages from the packages which contain the module in unit_test_list and set them into a new variable pkgs_to_build base on its evaluation rule.
> In stuart_build step, if unit_test_list is not null, '${{ parameters.unit_test_list}} -p $(pkgs_to_build)' will be added into the arguments to build specific UnitTest modules in pkgs_to_build.
> In 'Run to shell' step, if unit_test_list is not null, all the UnitTest modules built in stuart_build step will runs in shell.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Kubacki <mikuback@linux.microsoft.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Ray Ni <ray.ni@intel.com>
> ---
>   .azurepipelines/templates/platform-build-run-steps.yml | 21 +++++++++++++++++----
>   1 file changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/.azurepipelines/templates/platform-build-run-steps.yml 
> b/.azurepipelines/templates/platform-build-run-steps.yml
> index 40a31a509f..51503287c4 100644
> --- a/.azurepipelines/templates/platform-build-run-steps.yml
> +++ b/.azurepipelines/templates/platform-build-run-steps.yml
> @@ -30,6 +30,9 @@ parameters:
>   - name: run_flags
>     type: string
>     default: ''
> +- name: unit_test_list
> +  type: string
> +  default: ''
>   
>   - name: extra_install_step
>     type: stepList
> @@ -49,7 +52,9 @@ steps:
>     displayName: 'Install/Upgrade pip modules'
>   
>   # Set default
> -- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
> +- bash: |
> +    echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
> +    echo "##vso[task.setvariable variable=pkgs_to_build]${{ 'all' }}"
>   
>   # Fetch the target branch so that pr_eval can diff them.
>   # Seems like azure pipelines/github changed checkout process in nov 2020.
> @@ -62,7 +67,7 @@ steps:
>     displayName: Check if ${{ parameters.build_pkg }} need testing
>     inputs:
>       filename: stuart_pr_eval
> -    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
> +    arguments: -c ${{ parameters.build_file }} -t ${{ 
> + parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target
> + origin/$(System.PullRequest.targetBranch) 
> + --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
> + --output-csv-format-string "##vso[task.setvariable 
> + variable=pkgs_to_build]{pkgcsv}" ${{ parameters.unit_test_list}}
>     condition: eq(variables['Build.Reason'], 'PullRequest')
>   
>    # Setup repo
> @@ -97,14 +102,22 @@ steps:
>     inputs:
>       filename: stuart_build
>       arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
> parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a 
> ${{ parameters.build_arch}} ${{ parameters.build_flags}}
> -  condition: and(gt(variables.pkg_count, 0), succeeded())
> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()), 
> + eq(variables.unit_test_list, ''))
> +
> +# Build specific pkg for UnitTest
> +- task: CmdLine@1
> +  displayName: Build UnitTest
> +  inputs:
> +    filename: stuart_build
> +    arguments: ${{ parameters.unit_test_list}} -p $(pkgs_to_build) -c 
> +${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
> +parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a 
> +${{ parameters.build_arch}} ${{ parameters.build_flags}}
> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()), 
> +not(eq(variables.unit_test_list, '')))
>   
>   # Run
>   - task: CmdLine@1
>     displayName: Run to shell
>     inputs:
>       filename: stuart_build
> -    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
> +    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
> + parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a 
> + ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ 
> + parameters.run_flags }} --FlashOnly ${{ parameters.unit_test_list}}
>     condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
>     timeoutInMinutes: 1
>   
> --
> 2.31.1.windows.1
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
  2022-12-06  4:46         ` duntan
@ 2022-12-08  2:57           ` Michael Kubacki
  2022-12-08  8:17             ` duntan
  0 siblings, 1 reply; 16+ messages in thread
From: Michael Kubacki @ 2022-12-08  2:57 UTC (permalink / raw)
  To: devel, dun.tan; +Cc: Sean Brogan, Kinney, Michael D, Gao, Liming, Ni, Ray

Hi Dun,

Sean Brogan and I have some feedback we'll send soon after we sync on 
it. If anything is still open as of the upcoming TianoCore tools & CI 
meeting and you're able to attend, we can talk there as well.

Thanks,
Michael

On 12/5/2022 11:46 PM, duntan wrote:
> Hi Michael,
> Thanks for the reply! In the following PR, I added an unit test list in the new OvmfPkg platform CI JOB. In  PlatformCI_OvmfPkg_Ubuntu_GCC5_PR and PlatformCI_OvmfPkg_Windows_VS2019_PR, the CI for specific unit test list was triggered.
> https://github.com/tianocore/edk2/pull/3651
> 
> Thanks,
> Dun
> 
> -----Original Message-----
> From: Michael Kubacki <mikuback@linux.microsoft.com>
> Sent: Tuesday, December 6, 2022 9:24 AM
> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
> Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
> 
> Sorry for the delay Dun. Can you please share an edk2 pull request with this change?
> 
> Thanks,
> Michael
> 
> On 12/4/2022 10:57 PM, duntan wrote:
>> Hi all,
>> Is there anything else I can do to speed up the review process for this patch set? Looking forward to your reply.
>>
>> Thanks,
>> Dun
>> -----Original Message-----
>> From: Tan, Dun
>> Sent: Monday, November 28, 2022 5:34 PM
>> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
>> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki
>> <mikuback@linux.microsoft.com>; Kinney, Michael D
>> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
>> Ni, Ray <ray.ni@intel.com>
>> Subject: RE: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand
>> PlatformCI template for Shell UnitTest
>>
>> Hi all,
>> Could you please help to review this patch? Thanks a lot!
>>
>> Thanks,
>> Dun
>>
>> -----Original Message-----
>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
>> Sent: Tuesday, November 22, 2022 7:48 PM
>> To: devel@edk2.groups.io
>> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki
>> <mikuback@linux.microsoft.com>; Kinney, Michael D
>> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
>> Ni, Ray <ray.ni@intel.com>
>> Subject: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI
>> template for Shell UnitTest
>>
>> Expand PlatformCI build and run steps template for Shell UnitTest. Add a new parameter unit_test_list to support building and running specific Shell UnitTest modules.
>>
>> In stuart_pr_eval step, if the unit_test_list passed from platform yml file is not null, it will select some packages from the packages which contain the module in unit_test_list and set them into a new variable pkgs_to_build base on its evaluation rule.
>> In stuart_build step, if unit_test_list is not null, '${{ parameters.unit_test_list}} -p $(pkgs_to_build)' will be added into the arguments to build specific UnitTest modules in pkgs_to_build.
>> In 'Run to shell' step, if unit_test_list is not null, all the UnitTest modules built in stuart_build step will runs in shell.
>>
>> Signed-off-by: Dun Tan <dun.tan@intel.com>
>> Cc: Sean Brogan <sean.brogan@microsoft.com>
>> Cc: Michael Kubacki <mikuback@linux.microsoft.com>
>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>> Cc: Ray Ni <ray.ni@intel.com>
>> ---
>>    .azurepipelines/templates/platform-build-run-steps.yml | 21 +++++++++++++++++----
>>    1 file changed, 17 insertions(+), 4 deletions(-)
>>
>> diff --git a/.azurepipelines/templates/platform-build-run-steps.yml
>> b/.azurepipelines/templates/platform-build-run-steps.yml
>> index 40a31a509f..51503287c4 100644
>> --- a/.azurepipelines/templates/platform-build-run-steps.yml
>> +++ b/.azurepipelines/templates/platform-build-run-steps.yml
>> @@ -30,6 +30,9 @@ parameters:
>>    - name: run_flags
>>      type: string
>>      default: ''
>> +- name: unit_test_list
>> +  type: string
>> +  default: ''
>>    
>>    - name: extra_install_step
>>      type: stepList
>> @@ -49,7 +52,9 @@ steps:
>>      displayName: 'Install/Upgrade pip modules'
>>    
>>    # Set default
>> -- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
>> +- bash: |
>> +    echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
>> +    echo "##vso[task.setvariable variable=pkgs_to_build]${{ 'all' }}"
>>    
>>    # Fetch the target branch so that pr_eval can diff them.
>>    # Seems like azure pipelines/github changed checkout process in nov 2020.
>> @@ -62,7 +67,7 @@ steps:
>>      displayName: Check if ${{ parameters.build_pkg }} need testing
>>      inputs:
>>        filename: stuart_pr_eval
>> -    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
>> +    arguments: -c ${{ parameters.build_file }} -t ${{
>> + parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target
>> + origin/$(System.PullRequest.targetBranch)
>> + --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
>> + --output-csv-format-string "##vso[task.setvariable
>> + variable=pkgs_to_build]{pkgcsv}" ${{ parameters.unit_test_list}}
>>      condition: eq(variables['Build.Reason'], 'PullRequest')
>>    
>>     # Setup repo
>> @@ -97,14 +102,22 @@ steps:
>>      inputs:
>>        filename: stuart_build
>>        arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
>> parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
>> ${{ parameters.build_arch}} ${{ parameters.build_flags}}
>> -  condition: and(gt(variables.pkg_count, 0), succeeded())
>> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()),
>> + eq(variables.unit_test_list, ''))
>> +
>> +# Build specific pkg for UnitTest
>> +- task: CmdLine@1
>> +  displayName: Build UnitTest
>> +  inputs:
>> +    filename: stuart_build
>> +    arguments: ${{ parameters.unit_test_list}} -p $(pkgs_to_build) -c
>> +${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
>> +parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
>> +${{ parameters.build_arch}} ${{ parameters.build_flags}}
>> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()),
>> +not(eq(variables.unit_test_list, '')))
>>    
>>    # Run
>>    - task: CmdLine@1
>>      displayName: Run to shell
>>      inputs:
>>        filename: stuart_build
>> -    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
>> +    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
>> + parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
>> + ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{
>> + parameters.run_flags }} --FlashOnly ${{ parameters.unit_test_list}}
>>      condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
>>      timeoutInMinutes: 1
>>    
>> --
>> 2.31.1.windows.1
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
  2022-12-08  2:57           ` Michael Kubacki
@ 2022-12-08  8:17             ` duntan
  2022-12-08 22:37               ` Sean Brogan
  0 siblings, 1 reply; 16+ messages in thread
From: duntan @ 2022-12-08  8:17 UTC (permalink / raw)
  To: Michael Kubacki, devel@edk2.groups.io
  Cc: Sean Brogan, Kinney, Michael D, Gao, Liming, Ni, Ray

Thank you and Sean a lot! I'll attend the CI meeting if there is any open.

Thanks,
Dun
-----Original Message-----
From: Michael Kubacki <mikuback@linux.microsoft.com> 
Sent: Thursday, December 8, 2022 10:57 AM
To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Hi Dun,

Sean Brogan and I have some feedback we'll send soon after we sync on it. If anything is still open as of the upcoming TianoCore tools & CI meeting and you're able to attend, we can talk there as well.

Thanks,
Michael

On 12/5/2022 11:46 PM, duntan wrote:
> Hi Michael,
> Thanks for the reply! In the following PR, I added an unit test list in the new OvmfPkg platform CI JOB. In  PlatformCI_OvmfPkg_Ubuntu_GCC5_PR and PlatformCI_OvmfPkg_Windows_VS2019_PR, the CI for specific unit test list was triggered.
> https://github.com/tianocore/edk2/pull/3651
> 
> Thanks,
> Dun
> 
> -----Original Message-----
> From: Michael Kubacki <mikuback@linux.microsoft.com>
> Sent: Tuesday, December 6, 2022 9:24 AM
> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>; Kinney, Michael D 
> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; 
> Ni, Ray <ray.ni@intel.com>
> Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand 
> PlatformCI template for Shell UnitTest
> 
> Sorry for the delay Dun. Can you please share an edk2 pull request with this change?
> 
> Thanks,
> Michael
> 
> On 12/4/2022 10:57 PM, duntan wrote:
>> Hi all,
>> Is there anything else I can do to speed up the review process for this patch set? Looking forward to your reply.
>>
>> Thanks,
>> Dun
>> -----Original Message-----
>> From: Tan, Dun
>> Sent: Monday, November 28, 2022 5:34 PM
>> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
>> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki 
>> <mikuback@linux.microsoft.com>; Kinney, Michael D 
>> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; 
>> Ni, Ray <ray.ni@intel.com>
>> Subject: RE: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand 
>> PlatformCI template for Shell UnitTest
>>
>> Hi all,
>> Could you please help to review this patch? Thanks a lot!
>>
>> Thanks,
>> Dun
>>
>> -----Original Message-----
>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
>> Sent: Tuesday, November 22, 2022 7:48 PM
>> To: devel@edk2.groups.io
>> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki 
>> <mikuback@linux.microsoft.com>; Kinney, Michael D 
>> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; 
>> Ni, Ray <ray.ni@intel.com>
>> Subject: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI 
>> template for Shell UnitTest
>>
>> Expand PlatformCI build and run steps template for Shell UnitTest. Add a new parameter unit_test_list to support building and running specific Shell UnitTest modules.
>>
>> In stuart_pr_eval step, if the unit_test_list passed from platform yml file is not null, it will select some packages from the packages which contain the module in unit_test_list and set them into a new variable pkgs_to_build base on its evaluation rule.
>> In stuart_build step, if unit_test_list is not null, '${{ parameters.unit_test_list}} -p $(pkgs_to_build)' will be added into the arguments to build specific UnitTest modules in pkgs_to_build.
>> In 'Run to shell' step, if unit_test_list is not null, all the UnitTest modules built in stuart_build step will runs in shell.
>>
>> Signed-off-by: Dun Tan <dun.tan@intel.com>
>> Cc: Sean Brogan <sean.brogan@microsoft.com>
>> Cc: Michael Kubacki <mikuback@linux.microsoft.com>
>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>> Cc: Ray Ni <ray.ni@intel.com>
>> ---
>>    .azurepipelines/templates/platform-build-run-steps.yml | 21 +++++++++++++++++----
>>    1 file changed, 17 insertions(+), 4 deletions(-)
>>
>> diff --git a/.azurepipelines/templates/platform-build-run-steps.yml
>> b/.azurepipelines/templates/platform-build-run-steps.yml
>> index 40a31a509f..51503287c4 100644
>> --- a/.azurepipelines/templates/platform-build-run-steps.yml
>> +++ b/.azurepipelines/templates/platform-build-run-steps.yml
>> @@ -30,6 +30,9 @@ parameters:
>>    - name: run_flags
>>      type: string
>>      default: ''
>> +- name: unit_test_list
>> +  type: string
>> +  default: ''
>>    
>>    - name: extra_install_step
>>      type: stepList
>> @@ -49,7 +52,9 @@ steps:
>>      displayName: 'Install/Upgrade pip modules'
>>    
>>    # Set default
>> -- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
>> +- bash: |
>> +    echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
>> +    echo "##vso[task.setvariable variable=pkgs_to_build]${{ 'all' }}"
>>    
>>    # Fetch the target branch so that pr_eval can diff them.
>>    # Seems like azure pipelines/github changed checkout process in nov 2020.
>> @@ -62,7 +67,7 @@ steps:
>>      displayName: Check if ${{ parameters.build_pkg }} need testing
>>      inputs:
>>        filename: stuart_pr_eval
>> -    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
>> +    arguments: -c ${{ parameters.build_file }} -t ${{ 
>> + parameters.build_target}} -a ${{ parameters.build_arch}} 
>> + --pr-target
>> + origin/$(System.PullRequest.targetBranch)
>> + --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
>> + --output-csv-format-string "##vso[task.setvariable 
>> + variable=pkgs_to_build]{pkgcsv}" ${{ parameters.unit_test_list}}
>>      condition: eq(variables['Build.Reason'], 'PullRequest')
>>    
>>     # Setup repo
>> @@ -97,14 +102,22 @@ steps:
>>      inputs:
>>        filename: stuart_build
>>        arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
>> parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a 
>> ${{ parameters.build_arch}} ${{ parameters.build_flags}}
>> -  condition: and(gt(variables.pkg_count, 0), succeeded())
>> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()), 
>> + eq(variables.unit_test_list, ''))
>> +
>> +# Build specific pkg for UnitTest
>> +- task: CmdLine@1
>> +  displayName: Build UnitTest
>> +  inputs:
>> +    filename: stuart_build
>> +    arguments: ${{ parameters.unit_test_list}} -p $(pkgs_to_build) 
>> +-c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
>> +parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a 
>> +${{ parameters.build_arch}} ${{ parameters.build_flags}}
>> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()), 
>> +not(eq(variables.unit_test_list, '')))
>>    
>>    # Run
>>    - task: CmdLine@1
>>      displayName: Run to shell
>>      inputs:
>>        filename: stuart_build
>> -    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
>> +    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ 
>> + parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a 
>> + ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ 
>> + parameters.run_flags }} --FlashOnly ${{ parameters.unit_test_list}}
>>      condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
>>      timeoutInMinutes: 1
>>    
>> --
>> 2.31.1.windows.1
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
  2022-12-08  8:17             ` duntan
@ 2022-12-08 22:37               ` Sean Brogan
  2022-12-09  7:01                 ` duntan
  0 siblings, 1 reply; 16+ messages in thread
From: Sean Brogan @ 2022-12-08 22:37 UTC (permalink / raw)
  To: Tan, Dun, Michael Kubacki, devel@edk2.groups.io
  Cc: Kinney, Michael D, Gao, Liming, Ni, Ray

[-- Attachment #1: Type: text/plain, Size: 9811 bytes --]

Dun,

I created this discussion on github hoping that others might have ideas/feedback.
Integrate target-based testing into Platform CI for Edk2 using OVMF · Discussion #3739 · tianocore/edk2 (github.com)<https://github.com/tianocore/edk2/discussions/3739>

Lets use that to discuss and then on monday we can talk more if needed.

Thanks
Sean


[https://opengraph.githubassets.com/1743f87e9d9139f88783fef5e0cdeb31d956f016a4ea69c0c5489778f4834eb7/tianocore/edk2/discussions/3739]<https://github.com/tianocore/edk2/discussions/3739>
Integrate target-based testing into Platform CI for Edk2 using OVMF · Discussion #3739 · tianocore/edk2<https://github.com/tianocore/edk2/discussions/3739>
Starting a discussion here to see if more individuals in the community have opinions on how best to integrate target-based testing into edk2 CI. There is a current proposed patch on the mailing lis...
github.com

________________________________
From: Tan, Dun <dun.tan@intel.com>
Sent: Thursday, December 8, 2022 12:17 AM
To: Michael Kubacki <mikuback@linux.microsoft.com>; devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Sean Brogan <sean.brogan@microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [EXTERNAL] RE: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Thank you and Sean a lot! I'll attend the CI meeting if there is any open.

Thanks,
Dun
-----Original Message-----
From: Michael Kubacki <mikuback@linux.microsoft.com>
Sent: Thursday, December 8, 2022 10:57 AM
To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Hi Dun,

Sean Brogan and I have some feedback we'll send soon after we sync on it. If anything is still open as of the upcoming TianoCore tools & CI meeting and you're able to attend, we can talk there as well.

Thanks,
Michael

On 12/5/2022 11:46 PM, duntan wrote:
> Hi Michael,
> Thanks for the reply! In the following PR, I added an unit test list in the new OvmfPkg platform CI JOB. In  PlatformCI_OvmfPkg_Ubuntu_GCC5_PR and PlatformCI_OvmfPkg_Windows_VS2019_PR, the CI for specific unit test list was triggered.
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F3651&data=05%7C01%7Csean.brogan%40microsoft.com%7C884211b3375b4f0618de08dad8f4bdea%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638060842928005678%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FPbU3fGHlHv5%2FlKn8tvUdEO6%2Ff2SjCAzc7u2KVRxyK0%3D&reserved=0
>
> Thanks,
> Dun
>
> -----Original Message-----
> From: Michael Kubacki <mikuback@linux.microsoft.com>
> Sent: Tuesday, December 6, 2022 9:24 AM
> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
> Ni, Ray <ray.ni@intel.com>
> Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand
> PlatformCI template for Shell UnitTest
>
> Sorry for the delay Dun. Can you please share an edk2 pull request with this change?
>
> Thanks,
> Michael
>
> On 12/4/2022 10:57 PM, duntan wrote:
>> Hi all,
>> Is there anything else I can do to speed up the review process for this patch set? Looking forward to your reply.
>>
>> Thanks,
>> Dun
>> -----Original Message-----
>> From: Tan, Dun
>> Sent: Monday, November 28, 2022 5:34 PM
>> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
>> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki
>> <mikuback@linux.microsoft.com>; Kinney, Michael D
>> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
>> Ni, Ray <ray.ni@intel.com>
>> Subject: RE: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand
>> PlatformCI template for Shell UnitTest
>>
>> Hi all,
>> Could you please help to review this patch? Thanks a lot!
>>
>> Thanks,
>> Dun
>>
>> -----Original Message-----
>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
>> Sent: Tuesday, November 22, 2022 7:48 PM
>> To: devel@edk2.groups.io
>> Cc: Sean Brogan <sean.brogan@microsoft.com>; Michael Kubacki
>> <mikuback@linux.microsoft.com>; Kinney, Michael D
>> <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
>> Ni, Ray <ray.ni@intel.com>
>> Subject: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI
>> template for Shell UnitTest
>>
>> Expand PlatformCI build and run steps template for Shell UnitTest. Add a new parameter unit_test_list to support building and running specific Shell UnitTest modules.
>>
>> In stuart_pr_eval step, if the unit_test_list passed from platform yml file is not null, it will select some packages from the packages which contain the module in unit_test_list and set them into a new variable pkgs_to_build base on its evaluation rule.
>> In stuart_build step, if unit_test_list is not null, '${{ parameters.unit_test_list}} -p $(pkgs_to_build)' will be added into the arguments to build specific UnitTest modules in pkgs_to_build.
>> In 'Run to shell' step, if unit_test_list is not null, all the UnitTest modules built in stuart_build step will runs in shell.
>>
>> Signed-off-by: Dun Tan <dun.tan@intel.com>
>> Cc: Sean Brogan <sean.brogan@microsoft.com>
>> Cc: Michael Kubacki <mikuback@linux.microsoft.com>
>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>> Cc: Ray Ni <ray.ni@intel.com>
>> ---
>>    .azurepipelines/templates/platform-build-run-steps.yml | 21 +++++++++++++++++----
>>    1 file changed, 17 insertions(+), 4 deletions(-)
>>
>> diff --git a/.azurepipelines/templates/platform-build-run-steps.yml
>> b/.azurepipelines/templates/platform-build-run-steps.yml
>> index 40a31a509f..51503287c4 100644
>> --- a/.azurepipelines/templates/platform-build-run-steps.yml
>> +++ b/.azurepipelines/templates/platform-build-run-steps.yml
>> @@ -30,6 +30,9 @@ parameters:
>>    - name: run_flags
>>      type: string
>>      default: ''
>> +- name: unit_test_list
>> +  type: string
>> +  default: ''
>>
>>    - name: extra_install_step
>>      type: stepList
>> @@ -49,7 +52,9 @@ steps:
>>      displayName: 'Install/Upgrade pip modules'
>>
>>    # Set default
>> -- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
>> +- bash: |
>> +    echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
>> +    echo "##vso[task.setvariable variable=pkgs_to_build]${{ 'all' }}"
>>
>>    # Fetch the target branch so that pr_eval can diff them.
>>    # Seems like azure pipelines/github changed checkout process in nov 2020.
>> @@ -62,7 +67,7 @@ steps:
>>      displayName: Check if ${{ parameters.build_pkg }} need testing
>>      inputs:
>>        filename: stuart_pr_eval
>> -    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
>> +    arguments: -c ${{ parameters.build_file }} -t ${{
>> + parameters.build_target}} -a ${{ parameters.build_arch}}
>> + --pr-target
>> + origin/$(System.PullRequest.targetBranch)
>> + --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
>> + --output-csv-format-string "##vso[task.setvariable
>> + variable=pkgs_to_build]{pkgcsv}" ${{ parameters.unit_test_list}}
>>      condition: eq(variables['Build.Reason'], 'PullRequest')
>>
>>     # Setup repo
>> @@ -97,14 +102,22 @@ steps:
>>      inputs:
>>        filename: stuart_build
>>        arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
>> parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
>> ${{ parameters.build_arch}} ${{ parameters.build_flags}}
>> -  condition: and(gt(variables.pkg_count, 0), succeeded())
>> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()),
>> + eq(variables.unit_test_list, ''))
>> +
>> +# Build specific pkg for UnitTest
>> +- task: CmdLine@1
>> +  displayName: Build UnitTest
>> +  inputs:
>> +    filename: stuart_build
>> +    arguments: ${{ parameters.unit_test_list}} -p $(pkgs_to_build)
>> +-c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
>> +parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
>> +${{ parameters.build_arch}} ${{ parameters.build_flags}}
>> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()),
>> +not(eq(variables.unit_test_list, '')))
>>
>>    # Run
>>    - task: CmdLine@1
>>      displayName: Run to shell
>>      inputs:
>>        filename: stuart_build
>> -    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
>> +    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
>> + parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
>> + ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{
>> + parameters.run_flags }} --FlashOnly ${{ parameters.unit_test_list}}
>>      condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
>>      timeoutInMinutes: 1
>>
>> --
>> 2.31.1.windows.1
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
> 
>
>

[-- Attachment #2: Type: text/html, Size: 17639 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest
  2022-12-08 22:37               ` Sean Brogan
@ 2022-12-09  7:01                 ` duntan
  0 siblings, 0 replies; 16+ messages in thread
From: duntan @ 2022-12-09  7:01 UTC (permalink / raw)
  To: Sean Brogan, Michael Kubacki, devel@edk2.groups.io
  Cc: Kinney, Michael D, Gao, Liming, Ni, Ray

[-- Attachment #1: Type: text/plain, Size: 11690 bytes --]

Hi Sean,
Thank you for creating this discussion. Looking forward to more feedback from community.

Thanks,
Dun

From: Sean Brogan <sean.brogan@microsoft.com>
Sent: Friday, December 9, 2022 6:37 AM
To: Tan, Dun <dun.tan@intel.com>; Michael Kubacki <mikuback@linux.microsoft.com>; devel@edk2.groups.io
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Dun,

I created this discussion on github hoping that others might have ideas/feedback.
Integrate target-based testing into Platform CI for Edk2 using OVMF * Discussion #3739 * tianocore/edk2 (github.com)<https://github.com/tianocore/edk2/discussions/3739>

Lets use that to discuss and then on monday we can talk more if needed.

Thanks
Sean


[https://opengraph.githubassets.com/1743f87e9d9139f88783fef5e0cdeb31d956f016a4ea69c0c5489778f4834eb7/tianocore/edk2/discussions/3739]<https://github.com/tianocore/edk2/discussions/3739>
Integrate target-based testing into Platform CI for Edk2 using OVMF * Discussion #3739 * tianocore/edk2<https://github.com/tianocore/edk2/discussions/3739>
Starting a discussion here to see if more individuals in the community have opinions on how best to integrate target-based testing into edk2 CI. There is a current proposed patch on the mailing lis...
github.com

________________________________
From: Tan, Dun <dun.tan@intel.com<mailto:dun.tan@intel.com>>
Sent: Thursday, December 8, 2022 12:17 AM
To: Michael Kubacki <mikuback@linux.microsoft.com<mailto:mikuback@linux.microsoft.com>>; devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>>
Cc: Sean Brogan <sean.brogan@microsoft.com<mailto:sean.brogan@microsoft.com>>; Kinney, Michael D <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>; Gao, Liming <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>; Ni, Ray <ray.ni@intel.com<mailto:ray.ni@intel.com>>
Subject: [EXTERNAL] RE: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Thank you and Sean a lot! I'll attend the CI meeting if there is any open.

Thanks,
Dun
-----Original Message-----
From: Michael Kubacki <mikuback@linux.microsoft.com<mailto:mikuback@linux.microsoft.com>>
Sent: Thursday, December 8, 2022 10:57 AM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Tan, Dun <dun.tan@intel.com<mailto:dun.tan@intel.com>>
Cc: Sean Brogan <sean.brogan@microsoft.com<mailto:sean.brogan@microsoft.com>>; Kinney, Michael D <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>; Gao, Liming <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>; Ni, Ray <ray.ni@intel.com<mailto:ray.ni@intel.com>>
Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest

Hi Dun,

Sean Brogan and I have some feedback we'll send soon after we sync on it. If anything is still open as of the upcoming TianoCore tools & CI meeting and you're able to attend, we can talk there as well.

Thanks,
Michael

On 12/5/2022 11:46 PM, duntan wrote:
> Hi Michael,
> Thanks for the reply! In the following PR, I added an unit test list in the new OvmfPkg platform CI JOB. In  PlatformCI_OvmfPkg_Ubuntu_GCC5_PR and PlatformCI_OvmfPkg_Windows_VS2019_PR, the CI for specific unit test list was triggered.
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F3651&data=05%7C01%7Csean.brogan%40microsoft.com%7C884211b3375b4f0618de08dad8f4bdea%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638060842928005678%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2FPbU3fGHlHv5%2FlKn8tvUdEO6%2Ff2SjCAzc7u2KVRxyK0%3D&reserved=0
>
> Thanks,
> Dun
>
> -----Original Message-----
> From: Michael Kubacki <mikuback@linux.microsoft.com<mailto:mikuback@linux.microsoft.com>>
> Sent: Tuesday, December 6, 2022 9:24 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Tan, Dun <dun.tan@intel.com<mailto:dun.tan@intel.com>>
> Cc: Sean Brogan <sean.brogan@microsoft.com<mailto:sean.brogan@microsoft.com>>; Kinney, Michael D
> <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>; Gao, Liming <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>;
> Ni, Ray <ray.ni@intel.com<mailto:ray.ni@intel.com>>
> Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand
> PlatformCI template for Shell UnitTest
>
> Sorry for the delay Dun. Can you please share an edk2 pull request with this change?
>
> Thanks,
> Michael
>
> On 12/4/2022 10:57 PM, duntan wrote:
>> Hi all,
>> Is there anything else I can do to speed up the review process for this patch set? Looking forward to your reply.
>>
>> Thanks,
>> Dun
>> -----Original Message-----
>> From: Tan, Dun
>> Sent: Monday, November 28, 2022 5:34 PM
>> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Tan, Dun <dun.tan@intel.com<mailto:dun.tan@intel.com>>
>> Cc: Sean Brogan <sean.brogan@microsoft.com<mailto:sean.brogan@microsoft.com>>; Michael Kubacki
>> <mikuback@linux.microsoft.com<mailto:mikuback@linux.microsoft.com>>; Kinney, Michael D
>> <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>; Gao, Liming <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>;
>> Ni, Ray <ray.ni@intel.com<mailto:ray.ni@intel.com>>
>> Subject: RE: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand
>> PlatformCI template for Shell UnitTest
>>
>> Hi all,
>> Could you please help to review this patch? Thanks a lot!
>>
>> Thanks,
>> Dun
>>
>> -----Original Message-----
>> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> On Behalf Of duntan
>> Sent: Tuesday, November 22, 2022 7:48 PM
>> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
>> Cc: Sean Brogan <sean.brogan@microsoft.com<mailto:sean.brogan@microsoft.com>>; Michael Kubacki
>> <mikuback@linux.microsoft.com<mailto:mikuback@linux.microsoft.com>>; Kinney, Michael D
>> <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>; Gao, Liming <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>;
>> Ni, Ray <ray.ni@intel.com<mailto:ray.ni@intel.com>>
>> Subject: [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI
>> template for Shell UnitTest
>>
>> Expand PlatformCI build and run steps template for Shell UnitTest. Add a new parameter unit_test_list to support building and running specific Shell UnitTest modules.
>>
>> In stuart_pr_eval step, if the unit_test_list passed from platform yml file is not null, it will select some packages from the packages which contain the module in unit_test_list and set them into a new variable pkgs_to_build base on its evaluation rule.
>> In stuart_build step, if unit_test_list is not null, '${{ parameters.unit_test_list}} -p $(pkgs_to_build)' will be added into the arguments to build specific UnitTest modules in pkgs_to_build.
>> In 'Run to shell' step, if unit_test_list is not null, all the UnitTest modules built in stuart_build step will runs in shell.
>>
>> Signed-off-by: Dun Tan <dun.tan@intel.com<mailto:dun.tan@intel.com>>
>> Cc: Sean Brogan <sean.brogan@microsoft.com<mailto:sean.brogan@microsoft.com>>
>> Cc: Michael Kubacki <mikuback@linux.microsoft.com<mailto:mikuback@linux.microsoft.com>>
>> Cc: Michael D Kinney <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>>
>> Cc: Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>
>> Cc: Ray Ni <ray.ni@intel.com<mailto:ray.ni@intel.com>>
>> ---
>>    .azurepipelines/templates/platform-build-run-steps.yml | 21 +++++++++++++++++----
>>    1 file changed, 17 insertions(+), 4 deletions(-)
>>
>> diff --git a/.azurepipelines/templates/platform-build-run-steps.yml
>> b/.azurepipelines/templates/platform-build-run-steps.yml
>> index 40a31a509f..51503287c4 100644
>> --- a/.azurepipelines/templates/platform-build-run-steps.yml
>> +++ b/.azurepipelines/templates/platform-build-run-steps.yml
>> @@ -30,6 +30,9 @@ parameters:
>>    - name: run_flags
>>      type: string
>>      default: ''
>> +- name: unit_test_list
>> +  type: string
>> +  default: ''
>>
>>    - name: extra_install_step
>>      type: stepList
>> @@ -49,7 +52,9 @@ steps:
>>      displayName: 'Install/Upgrade pip modules'
>>
>>    # Set default
>> -- bash: echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
>> +- bash: |
>> +    echo "##vso[task.setvariable variable=pkg_count]${{ 1 }}"
>> +    echo "##vso[task.setvariable variable=pkgs_to_build]${{ 'all' }}"
>>
>>    # Fetch the target branch so that pr_eval can diff them.
>>    # Seems like azure pipelines/github changed checkout process in nov 2020.
>> @@ -62,7 +67,7 @@ steps:
>>      displayName: Check if ${{ parameters.build_pkg }} need testing
>>      inputs:
>>        filename: stuart_pr_eval
>> -    arguments: -c ${{ parameters.build_file }} -t ${{ parameters.build_target}} -a ${{ parameters.build_arch}} --pr-target origin/$(System.PullRequest.targetBranch) --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
>> +    arguments: -c ${{ parameters.build_file }} -t ${{
>> + parameters.build_target}} -a ${{ parameters.build_arch}}
>> + --pr-target
>> + origin/$(System.PullRequest.targetBranch)
>> + --output-count-format-string "##vso[task.setvariable variable=pkg_count;isOutpout=true]{pkgcount}"
>> + --output-csv-format-string "##vso[task.setvariable
>> + variable=pkgs_to_build]{pkgcsv}" ${{ parameters.unit_test_list}}
>>      condition: eq(variables['Build.Reason'], 'PullRequest')
>>
>>     # Setup repo
>> @@ -97,14 +102,22 @@ steps:
>>      inputs:
>>        filename: stuart_build
>>        arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
>> parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
>> ${{ parameters.build_arch}} ${{ parameters.build_flags}}
>> -  condition: and(gt(variables.pkg_count, 0), succeeded())
>> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()),
>> + eq(variables.unit_test_list, ''))
>> +
>> +# Build specific pkg for UnitTest
>> +- task: CmdLine@1
>> +  displayName: Build UnitTest
>> +  inputs:
>> +    filename: stuart_build
>> +    arguments: ${{ parameters.unit_test_list}} -p $(pkgs_to_build)
>> +-c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
>> +parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
>> +${{ parameters.build_arch}} ${{ parameters.build_flags}}
>> +  condition: and(and(gt(variables.pkg_count, 0), succeeded()),
>> +not(eq(variables.unit_test_list, '')))
>>
>>    # Run
>>    - task: CmdLine@1
>>      displayName: Run to shell
>>      inputs:
>>        filename: stuart_build
>> -    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{ parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{ parameters.run_flags }} --FlashOnly
>> +    arguments: -c ${{ parameters.build_file }} TOOL_CHAIN_TAG=${{
>> + parameters.tool_chain_tag}} TARGET=${{ parameters.build_target}} -a
>> + ${{ parameters.build_arch}} ${{ parameters.build_flags}} ${{
>> + parameters.run_flags }} --FlashOnly ${{ parameters.unit_test_list}}
>>      condition: and(and(gt(variables.pkg_count, 0), succeeded()), eq(variables['Run'], true))
>>      timeoutInMinutes: 1
>>
>> --
>> 2.31.1.windows.1
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
> 
>
>

[-- Attachment #2: Type: text/html, Size: 21453 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI for Shell UnitTest
  2022-12-05  3:57     ` duntan
@ 2022-12-09  7:03       ` Yao, Jiewen
  0 siblings, 0 replies; 16+ messages in thread
From: Yao, Jiewen @ 2022-12-09  7:03 UTC (permalink / raw)
  To: Tan, Dun, devel@edk2.groups.io
  Cc: Ard Biesheuvel, Justen, Jordan L, Gerd Hoffmann, Ni, Ray,
	Sean Brogan, Kinney, Michael D

Thanks. I think this is good addition.

Acked-by: Jiewen Yao <Jiewen.yao@intel.com>

Need CI expert to give reviewed-by.

> -----Original Message-----
> From: Tan, Dun <dun.tan@intel.com>
> Sent: Monday, December 5, 2022 11:57 AM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Yao, Jiewen
> <jiewen.yao@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>;
> Gerd Hoffmann <kraxel@redhat.com>; Ni, Ray <ray.ni@intel.com>; Sean
> Brogan <sean.brogan@microsoft.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>
> Subject: RE: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf
> PlatformCI for Shell UnitTest
> 
> Hi all,
> Is there anything else I can do to speed up the review process for this patch
> set? Looking forward to your reply.
> 
> Thanks,
> Dun
> 
> -----Original Message-----
> From: Tan, Dun
> Sent: Monday, November 28, 2022 5:34 PM
> To: devel@edk2.groups.io; Tan, Dun <dun.tan@intel.com>
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Yao, Jiewen
> <jiewen.yao@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>;
> Gerd Hoffmann <kraxel@redhat.com>; Ni, Ray <ray.ni@intel.com>
> Subject: RE: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf
> PlatformCI for Shell UnitTest
> 
> Hi all,
> Could you please help to review this patch? Thanks a lot!
> 
> Thanks,
> Dun
> 
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of duntan
> Sent: Tuesday, November 22, 2022 7:48 PM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>; Yao, Jiewen
> <jiewen.yao@intel.com>; Justen, Jordan L <jordan.l.justen@intel.com>;
> Gerd Hoffmann <kraxel@redhat.com>; Ni, Ray <ray.ni@intel.com>
> Subject: [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf
> PlatformCI for Shell UnitTest
> 
> Expand Ovmf PlatformBuild.py and PlatformBuildLib.py to support building
> and running specific Shell target UnitTest modules.
> In the new CommonPlatform class:
> It provides new class attributes and new methods to support build and run
> specific Shell Unit Test modules.
> 
> In the new SettingsManager class for stuart_pr_eval:
> It calls new API in CommonPlatform to updates PackagesSupported based
> on -u ShellUnitTestList input from cmd. The package which contains the
> module in ShellUnitTestList will be added into PackagesSupported for
> further evaluation.
> 
> In the new PlatformBuilder class for stuart_build:
> 1.In PlatformPostBuild(), it conditionally calls new API in CommonPlatform
> to build -u ShellUnitTestList in -p PkgsToBuild and copy them to VirtualDrive
> folder. If no -p option, all the modules in -u ShellUnitTestList will be built.
> 2.In FlashRomImage(), it conditionally calls the new API in CommonPlatform
> to write all efi files name in VirtualDrive into startup.nsh and output
> UnitTest log into ShellUnitTestLog.
> 3. After the boot process, it conditionally calls new API in CommonPlatform
> to check the UnitTest boot log.
> 
> Signed-off-by: Dun Tan <dun.tan@intel.com>
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Ray Ni <ray.ni@intel.com>
> ---
>  OvmfPkg/PlatformCI/PlatformBuild.py    | 112
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  OvmfPkg/PlatformCI/PlatformBuildLib.py |  51
> +++++++++++++++++++++++++++++++++++++++++++++------
>  2 files changed, 157 insertions(+), 6 deletions(-)
> 
> diff --git a/OvmfPkg/PlatformCI/PlatformBuild.py
> b/OvmfPkg/PlatformCI/PlatformBuild.py
> index 6c541cdea4..72cb7e0e9e 100644
> --- a/OvmfPkg/PlatformCI/PlatformBuild.py
> +++ b/OvmfPkg/PlatformCI/PlatformBuild.py
> @@ -6,6 +6,11 @@
>  ##
>  import os
>  import sys
> +import shutil
> +import logging
> +import re
> +from edk2toolext.environment import shell_environment from
> +edk2toolext.environment.multiple_workspace import MultipleWorkspace
> 
>  sys.path.append(os.path.dirname(os.path.abspath(__file__)))
>  from PlatformBuildLib import SettingsManager @@ -24,6 +29,10 @@
> class CommonPlatform():
>      Scopes = ('ovmf', 'edk2-build')
>      WorkspaceRoot = os.path.realpath(os.path.join(
>          os.path.dirname(os.path.abspath(__file__)), "..", ".."))
> +    # Support build and run Shell Unit Test modules
> +    UnitTestModuleList = {}
> +    RunShellUnitTest   = False
> +    ShellUnitTestLog   = ''
> 
>      @classmethod
>      def GetDscName(cls, ArchCsv: str) -> str:
> @@ -39,5 +48,108 @@ class CommonPlatform():
>          dsc += ".dsc"
>          return dsc
> 
> +    @classmethod
> +    def UpdatePackagesSupported(cls, ShellUnitTestListArg):
> +        ''' Update PackagesSupported by -u ShellUnitTestList from cmd line. '''
> +        UnitTestModuleListStr = ','.join(ShellUnitTestListArg)
> +        if not re.search(r'.+.inf:.+.dsc', UnitTestModuleListStr):
> +            raise Exception('No valid ModulePath:DscPath in the -u
> {}'.format(UnitTestModuleListStr))
> +        UnitTestModuleList = UnitTestModuleListStr.split(',')
> +        PackagesSupported = []
> +        for KeyValue in UnitTestModuleList:
> +            PkgName = KeyValue.split("Pkg")[0] + 'Pkg'
> +            if PkgName not in PackagesSupported:
> +                PackagesSupported.append(PkgName)
> +        cls.PackagesSupported = tuple(PackagesSupported)
> +        print('PackagesSupported for UnitTest is
> + {}'.format(cls.PackagesSupported))
> +
> +    @classmethod
> +    def UpdateUnitTestConfig(cls, args):
> +        ''' Update UnitTest config by -u ShellUnitTestList and -p
> PkgsToBuildForUT from cmd line.
> +            ShellUnitTestList is in this format: {module1:dsc1, module2:dsc2,
> module3:dsc2...}.
> +            Only the modules which are in the PkgsToBuildForUT list are added
> into self.UnitTestModuleList.
> +        '''
> +        UnitTestModuleListStr = ','.join(args.ShellUnitTestList)
> +        if not re.search(r'.+.inf:.+.dsc', UnitTestModuleListStr):
> +            raise Exception('No valid ModulePath:DscPath in the -u
> {}'.format(args.ShellUnitTestList))
> +        UnitTestModuleList = UnitTestModuleListStr.split(',')
> +        if args.PkgsToBuildForUT is None or all(['Pkg' not in Pkg for Pkg in
> args.PkgsToBuildForUT]):
> +            # No invalid Pkgs from input. Build all modules in -u
> UnitTestModuleList.
> +            for KeyValue in UnitTestModuleList:
> +                UnitTestPath = os.path.normpath(KeyValue.split(":")[0])
> +                DscPath      = os.path.normpath(KeyValue.split(":")[1])
> +                cls.UnitTestModuleList[UnitTestPath] = DscPath
> +        else:
> +            PkgsToBuildForUT = ','.join(args.PkgsToBuildForUT).split(',')
> +            for KeyValue in UnitTestModuleList:
> +                UnitTestPath = os.path.normpath(KeyValue.split(":")[0])
> +                DscPath      = os.path.normpath(KeyValue.split(":")[1])
> +                PkgName      = UnitTestPath.split("Pkg")[0] + 'Pkg'
> +                if PkgName in PkgsToBuildForUT:
> +                    cls.UnitTestModuleList[UnitTestPath] = DscPath
> +        if len(cls.UnitTestModuleList) > 0:
> +            cls.RunShellUnitTest = True
> +            cls.ShellUnitTestLog = os.path.join(cls.WorkspaceRoot, 'Build',
> "BUILDLOG_UnitTest.txt")
> +            print('UnitTestModuleList is
> + {}'.format(cls.UnitTestModuleList))
> +
> +    def BuildUnitTest(self):
> +        ''' Build specific DSC for modules in UnitTestModuleList '''
> +        self.env = shell_environment.GetBuildVars()
> +        self.ws  = PlatformBuilder.GetWorkspaceRoot(self)
> +        self.mws = MultipleWorkspace()
> +        self.pp  = ''
> +        VirtualDrive = os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"),
> "VirtualDrive")
> +        os.makedirs(VirtualDrive, exist_ok=True)
> +
> +        # DSC by self.GetDscName() should have been built in BUILD process.
> +        BuiltDsc =
> [CommonPlatform.GetDscName(",".join(self.env.GetValue("TARGET_ARCH")
> .split(' ')))]
> +        for UnitTestPath, DscPath in
> CommonPlatform.UnitTestModuleList.items():
> +            if DscPath not in BuiltDsc:
> +                ModuleName = os.path.split(UnitTestPath)[1].split('.inf')[0]
> +                logging.info('Build {0} for {1}'.format(DscPath, ModuleName))
> +                BuiltDsc.append(DscPath)
> +                Arch = self.env.GetValue("TARGET_ARCH").split(" ")
> +                if 'X64' in Arch:
> +                    UTArch = 'X64'
> +                else:
> +                    UTArch = 'IA32'
> +                self.env.AllowOverride("ACTIVE_PLATFORM")
> +                self.env.SetValue("ACTIVE_PLATFORM", DscPath, "For UnitTest")
> +                self.env.AllowOverride("TARGET_ARCH")
> +                self.env.SetValue("TARGET_ARCH", UTArch, "For UnitTest") # Set
> UnitTest arch the same as Ovmf Shell module.
> +                ret = PlatformBuilder.Build(self)                        # Build specific dsc
> for UnitTest modules
> +                if (ret != 0):
> +                    return ret
> +            ret = PlatformBuilder.ParseDscFile(self) # Parse
> OUTPUT_DIRECTORY from dsc files
> +            if(ret != 0):
> +                return ret
> +            OutputPath = os.path.normpath(os.path.join(self.ws,
> self.env.GetValue("OUTPUT_DIRECTORY")))
> +            EfiPath    = os.path.join(OutputPath, self.env.GetValue("TARGET") +
> "_" + self.env.GetValue("TOOL_CHAIN_TAG"),
> +                         UTArch, UnitTestPath.split('.inf')[0], "OUTPUT",
> ModuleName + '.efi')
> +            logging.info('Copy {0}.efi from:{1}'.format(ModuleName, EfiPath))
> +            shutil.copy(EfiPath, VirtualDrive)
> +        return 0
> +
> +    @staticmethod
> +    def WriteEfiToStartup(EfiFolder, FileObj):
> +        ''' Write all the .efi files' name in VirtualDrive into Startup.nsh '''
> +        for Root,Dirs,Files in os.walk(EfiFolder):
> +            for File in Files:
> +                if os.path.splitext(File)[1] == '.efi':
> +                    FileObj.write("{0} \n".format(File))
> +
> +    @classmethod
> +    def CheckUnitTestLog(cls):
> +        ''' Check the boot log for UnitTest '''
> +        File        = open(cls.ShellUnitTestLog, "r")
> +        FileContent = File.readlines()
> +        logging.info('Check the UnitTest boot
> log:{0}'.format(cls.ShellUnitTestLog))
> +        for Index in range(len(FileContent)):
> +            if 'FAILURE MESSAGE:' in FileContent[Index]:
> +                if FileContent[Index + 1].strip() != '':
> +                    FailureMessage = FileContent[Index + 1] + FileContent[Index +
> 2]
> +                    return FailureMessage
> +        return 0
> +
>  import PlatformBuildLib
>  PlatformBuildLib.CommonPlatform = CommonPlatform diff --git
> a/OvmfPkg/PlatformCI/PlatformBuildLib.py
> b/OvmfPkg/PlatformCI/PlatformBuildLib.py
> index bfef9849c7..b42235b2ac 100644
> --- a/OvmfPkg/PlatformCI/PlatformBuildLib.py
> +++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py
> @@ -103,15 +103,28 @@ class SettingsManager(UpdateSettingsManager,
> SetupSettingsManager, PrEvalSetting
> 
>          return build_these_packages
> 
> +    def AddCommandLineOptions(self, parserObj):
> +        parserObj.add_argument('-u', '--UnitTest', dest='ShellUnitTestList',
> type=str,
> +            help='Optional - Key:Value that contains Shell UnitTest list and
> corresponding DscPath you want to test.(workspace relative)'
> +            'Can list multiple by doing -u
> <UTPath1:DscPath1>,<UTPath2:DscPath2> or -u <UTPath3:DscPath3> -u
> <UTPath4:DscPath4>',
> +            action="append", default=None)
> +
> +    def RetrieveCommandLineOptions(self, args):
> +        if args.ShellUnitTestList:
> +
> + CommonPlatform.UpdatePackagesSupported(args.ShellUnitTestList)
> +
>      def GetPlatformDscAndConfig(self) -> tuple:
>          ''' If a platform desires to provide its DSC then Policy 4 will evaluate if
>          any of the changes will be built in the dsc.
> 
>          The tuple should be (<workspace relative path to dsc file>, <input
> dictionary of dsc key value pairs>)
> +        This Policy 4 can only be applied when PackagesSupported only
> contains OvmfPkg Since it doesn't support
> +        mutiple packages evaluation.
>          '''
> -        dsc = CommonPlatform.GetDscName(",".join(self.ActualArchitectures))
> -        return (f"OvmfPkg/{dsc}", {})
> -
> +        if (len(CommonPlatform.PackagesSupported) == 1) and
> (CommonPlatform.PackagesSupported[0] == 'OvmfPkg'):
> +            dsc =
> CommonPlatform.GetDscName(",".join(self.ActualArchitectures))
> +            return (f"OvmfPkg/{dsc}", {})
> +        return None
> 
>      #
> ##########################################################
> ############################# #
>      #                         Actual Configuration for Platform Build                         #
> @@ -126,6 +139,14 @@ class PlatformBuilder( UefiBuilder,
> BuildSettingsManager):
>              help="Optional - CSV of architecture to build.  IA32 will use IA32 for
> Pei & Dxe. "
>              "X64 will use X64 for both PEI and DXE.  IA32,X64 will use IA32 for
> PEI and "
>              "X64 for DXE. default is IA32,X64")
> +        parserObj.add_argument('-p', '--pkg', '--pkg-dir',
> dest='PkgsToBuildForUT', type=str,
> +            help='Optional - Package list you want to build for UnitTest.efi.
> (workspace relative).'
> +            'Can list multiple by doing -p <pkg1>,<pkg2> or -p <pkg3> -p
> <pkg4>.If no valid input -p, build and run all -u UnitTest',
> +            action="append", default=None)
> +        parserObj.add_argument('-u', '--UnitTest', dest='ShellUnitTestList',
> type=str,
> +            help='Optional - Key:Value that contains Shell UnitTest list and
> corresponding DscPath you want to test.(workspace relative)'
> +            'Can list multiple by doing -u
> <UTPath1:DscPath1>,<UTPath2:DscPath2> or -u <UTPath3:DscPath3> -u
> <UTPath4:DscPath4>',
> +            action="append", default=None)
> 
>      def RetrieveCommandLineOptions(self, args):
>          '''  Retrieve command line options from the argparser '''
> @@ -133,6 +154,10 @@ class PlatformBuilder( UefiBuilder,
> BuildSettingsManager):
>          shell_environment.GetBuildVars().SetValue("TARGET_ARCH","
> ".join(args.build_arch.upper().split(",")), "From CmdLine")
>          dsc = CommonPlatform.GetDscName(args.build_arch)
>          shell_environment.GetBuildVars().SetValue("ACTIVE_PLATFORM",
> f"OvmfPkg/{dsc}", "From CmdLine")
> +        self.RunShellUnitTest = False
> +        if args.ShellUnitTestList:
> +            CommonPlatform.UpdateUnitTestConfig(args)
> +            self.RunShellUnitTest = CommonPlatform.RunShellUnitTest
> 
>      def GetWorkspaceRoot(self):
>          ''' get WorkspacePath '''
> @@ -176,6 +201,11 @@ class PlatformBuilder( UefiBuilder,
> BuildSettingsManager):
>          return 0
> 
>      def PlatformPostBuild(self):
> +        if self.RunShellUnitTest:
> +            ret = CommonPlatform.BuildUnitTest(self)
> +            if ret !=0:
> +                logging.critical("Build UnitTest failed")
> +                return ret
>          return 0
> 
>      def FlashRomImage(self):
> @@ -210,9 +240,13 @@ class PlatformBuilder( UefiBuilder,
> BuildSettingsManager):
>          else:
>              args += " -pflash " + os.path.join(OutputPath_FV, "OVMF.fd")    #
> path to firmware
> 
> -
>          if (self.env.GetValue("MAKE_STARTUP_NSH").upper() == "TRUE"):
>              f = open(os.path.join(VirtualDrive, "startup.nsh"), "w")
> +            if self.RunShellUnitTest:
> +                # When RunShellUnitTest is True, write all efi files name into
> startup.nsh.
> +                CommonPlatform.WriteEfiToStartup(VirtualDrive, f)
> +                # Output UnitTest log into ShellUnitTestLog.
> +                args += " -serial
> + file:{}".format(CommonPlatform.ShellUnitTestLog)
>              f.write("BOOT SUCCESS !!! \n")
>              ## add commands here
>              f.write("reset -s\n")
> @@ -222,6 +256,11 @@ class PlatformBuilder( UefiBuilder,
> BuildSettingsManager):
> 
>          if ret == 0xc0000005:
>              #for some reason getting a c0000005 on successful return
> -            return 0
> -
> +            ret = 0
> +        if self.RunShellUnitTest and ret == 0:
> +            # Check the UnitTest boot log.
> +            UnitTestResult = CommonPlatform.CheckUnitTestLog()
> +            if (UnitTestResult):
> +                logging.info("UnitTest failed with this FAILURE
> MESSAGE:\n{}".format(UnitTestResult))
> +                return UnitTestResult
>          return ret
> --
> 2.31.1.windows.1
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-12-09  7:03 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-22 11:47 [PATCH 0/3] Expand Ovmf PlatformCI to enable CI for Shell UnitTest duntan
2022-11-22 11:47 ` [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI " duntan
2022-11-22 11:47 ` [PATCH 2/3] OvmfPkg/PlatformCI: Add new JOB in .yml of OvmfPkg PlatformCI duntan
2022-11-22 11:47 ` [PATCH 3/3] .azurepipelines: Expand PlatformCI template for Shell UnitTest duntan
     [not found] ` <1729E5AF924ED134.5511@groups.io>
2022-11-28  9:33   ` [edk2-devel] [PATCH 1/3] OvmfPkg/PlatformCI: Expand Ovmf PlatformCI " duntan
2022-12-05  3:57     ` duntan
2022-12-09  7:03       ` Yao, Jiewen
     [not found] ` <1729E5B1AD6A86B6.31464@groups.io>
2022-11-28  9:34   ` [edk2-devel] [PATCH 3/3] .azurepipelines: Expand PlatformCI template " duntan
2022-12-05  3:57     ` duntan
2022-12-06  1:23       ` Michael Kubacki
2022-12-06  4:46         ` duntan
2022-12-08  2:57           ` Michael Kubacki
2022-12-08  8:17             ` duntan
2022-12-08 22:37               ` Sean Brogan
2022-12-09  7:01                 ` duntan
     [not found] ` <1729E5B0889AD806.5511@groups.io>
2022-11-28  9:36   ` [edk2-devel] [PATCH 2/3] OvmfPkg/PlatformCI: Add new JOB in .yml of OvmfPkg PlatformCI duntan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox