summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:17:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:17:27 +0000
commitf215e02bf85f68d3a6106c2a1f4f7f063f819064 (patch)
tree6bb5b92c046312c4e95ac2620b10ddf482d3fa8b /src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg
parentInitial commit. (diff)
downloadvirtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.tar.xz
virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.zip
Adding upstream version 7.0.14-dfsg.upstream/7.0.14-dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg')
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf35
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.uni14
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.c279
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf35
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.uni14
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.c631
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf27
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.uni14
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.c26
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.inf23
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.uni11
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.c127
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.inf34
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.uni12
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c49
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf31
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.uni11
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c571
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c403
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c200
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c186
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c277
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c856
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf37
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.uni11
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf38
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.uni11
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.c75
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.inf28
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.uni11
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.c416
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.inf47
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.uni15
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLib.c218
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c49
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.inf29
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.uni11
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c48
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.inf28
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.uni11
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestBootLib.h31
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestPersistenceLib.h76
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestResultReportLib.h27
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/UnitTestFrameworkTypes.h184
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/ReadMe.md496
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTest.c799
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestDxe.inf39
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestHost.inf33
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestPei.inf39
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestSmm.inf40
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestUefiShell.inf36
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc36
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml97
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec50
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc40
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.uni21
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc65
-rw-r--r--src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc62
58 files changed, 7120 insertions, 0 deletions
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
new file mode 100644
index 00000000..f5ae39da
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
@@ -0,0 +1,35 @@
+## @file
+# This module provides Cmocka Library implementation.
+#
+# Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = CmockaLib
+ MODULE_UNI_FILE = CmockaLib.uni
+ FILE_GUID = F1662152-3399-49AC-BE44-CAA97575FACE
+ MODULE_TYPE = BASE
+ VERSION_STRING = 0.1
+ LIBRARY_CLASS = CmockaLib|HOST_APPLICATION
+
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+ cmocka/src/cmocka.c
+
+[Packages]
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS == /c -DHAVE_VSNPRINTF -DHAVE_SNPRINTF
+ MSFT:NOOPT_*_*_CC_FLAGS = /Od
+
+ GCC:*_*_*_CC_FLAGS == -g -DHAVE_SIGNAL_H
+ GCC:NOOPT_*_*_CC_FLAGS = -O0
+ GCC:*_*_IA32_CC_FLAGS = -m32
+ GCC:*_*_X64_CC_FLAGS = -m64
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.uni
new file mode 100644
index 00000000..acdb72d0
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.uni
@@ -0,0 +1,14 @@
+// /** @file
+// This module provides Cmocka Library implementation.
+//
+// This module provides Cmocka Library implementation.
+//
+// Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Cmocka Library implementation"
+
+#string STR_MODULE_DESCRIPTION #language en-US "This module provides Cmocka Library implementation."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.c
new file mode 100644
index 00000000..8b8c8217
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.c
@@ -0,0 +1,279 @@
+/** @file
+ Instance of Debug Library based on POSIX APIs
+
+ Uses Print Library to produce formatted output strings sent to printf().
+
+ Copyright (c) 2018 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <stdio.h>
+
+#include <Base.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PrintLib.h>
+#include <Library/BaseMemoryLib.h>
+
+///
+/// Define the maximum debug and assert message length that this library supports
+///
+#define MAX_DEBUG_MESSAGE_LENGTH 0x100
+
+/**
+ Prints a debug message to the debug output device if the specified error level is enabled.
+
+ If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+ GetDebugPrintErrorLevel (), then print the message specified by Format and the
+ associated variable argument list to the debug output device.
+
+ If Format is NULL, then ASSERT().
+
+ @param ErrorLevel The error level of the debug message.
+ @param Format The format string for the debug message to print.
+ @param ... The variable argument list whose contents are accessed
+ based on the format string specified by Format.
+
+**/
+VOID
+EFIAPI
+DebugPrint (
+ IN UINTN ErrorLevel,
+ IN CONST CHAR8 *Format,
+ ...
+ )
+{
+ VA_LIST Marker;
+
+ VA_START (Marker, Format);
+ DebugVPrint (ErrorLevel, Format, Marker);
+ VA_END (Marker);
+}
+
+/**
+ Prints a debug message to the debug output device if the specified
+ error level is enabled.
+
+ If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+ GetDebugPrintErrorLevel (), then print the message specified by Format and
+ the associated variable argument list to the debug output device.
+
+ If Format is NULL, then ASSERT().
+
+ @param ErrorLevel The error level of the debug message.
+ @param Format Format string for the debug message to print.
+ @param VaListMarker VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+ IN UINTN ErrorLevel,
+ IN CONST CHAR8 *Format,
+ IN VA_LIST VaListMarker
+ )
+{
+ CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
+
+ AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
+ printf ("%s", Buffer);
+}
+
+/**
+ Prints a debug message to the debug output device if the specified
+ error level is enabled.
+ This function use BASE_LIST which would provide a more compatible
+ service than VA_LIST.
+
+ If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+ GetDebugPrintErrorLevel (), then print the message specified by Format and
+ the associated variable argument list to the debug output device.
+
+ If Format is NULL, then ASSERT().
+
+ @param ErrorLevel The error level of the debug message.
+ @param Format Format string for the debug message to print.
+ @param BaseListMarker BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+ IN UINTN ErrorLevel,
+ IN CONST CHAR8 *Format,
+ IN BASE_LIST BaseListMarker
+ )
+{
+ CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
+
+ AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
+ printf ("%s", Buffer);
+}
+
+/**
+ Prints an assert message containing a filename, line number, and description.
+ This may be followed by a breakpoint or a dead loop.
+
+ Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
+ to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
+ PcdDebugPropertyMask is set then CpuBreakpoint() is called. Otherwise, if
+ DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugPropertyMask is set then
+ CpuDeadLoop() is called. If neither of these bits are set, then this function
+ returns immediately after the message is printed to the debug output device.
+ DebugAssert() must actively prevent recursion. If DebugAssert() is called while
+ processing another DebugAssert(), then DebugAssert() must return immediately.
+
+ If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
+ If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
+
+ @param FileName The pointer to the name of the source file that generated the assert condition.
+ @param LineNumber The line number in the source file that generated the assert condition
+ @param Description The pointer to the description of the assert condition.
+
+**/
+VOID
+EFIAPI
+DebugAssert (
+ IN CONST CHAR8 *FileName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *Description
+ )
+{
+ printf ("ASSERT: %s(%d): %s\n", FileName, (INT32)(UINT32)LineNumber, Description);
+
+ //
+ // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
+ //
+ if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
+ CpuBreakpoint ();
+ } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
+ CpuDeadLoop ();
+ }
+}
+
+/**
+ Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
+
+ This function fills Length bytes of Buffer with the value specified by
+ PcdDebugClearMemoryValue, and returns Buffer.
+
+ If Buffer is NULL, then ASSERT().
+ If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+ @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
+ @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
+
+ @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
+
+**/
+VOID *
+EFIAPI
+DebugClearMemory (
+ OUT VOID *Buffer,
+ IN UINTN Length
+ )
+{
+ //
+ // If Buffer is NULL, then ASSERT().
+ //
+ ASSERT (Buffer != NULL);
+
+ //
+ // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
+ //
+ return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));
+}
+
+/**
+ Returns TRUE if ASSERT() macros are enabled.
+
+ This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
+ PcdDebugPropertyMask is set. Otherwise FALSE is returned.
+
+ @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is set.
+ @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugAssertEnabled (
+ VOID
+ )
+{
+ return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
+}
+
+/**
+ Returns TRUE if DEBUG() macros are enabled.
+
+ This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
+ PcdDebugPropertyMask is set. Otherwise FALSE is returned.
+
+ @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is set.
+ @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugPrintEnabled (
+ VOID
+ )
+{
+ return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
+}
+
+/**
+ Returns TRUE if DEBUG_CODE() macros are enabled.
+
+ This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
+ PcdDebugPropertyMask is set. Otherwise FALSE is returned.
+
+ @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is set.
+ @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugCodeEnabled (
+ VOID
+ )
+{
+ return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
+}
+
+/**
+ Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
+
+ This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
+ PcdDebugPropertyMask is set. Otherwise FALSE is returned.
+
+ @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is set.
+ @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugClearMemoryEnabled (
+ VOID
+ )
+{
+ return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
+}
+
+/**
+ Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
+
+ This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
+
+ @retval TRUE Current ErrorLevel is supported.
+ @retval FALSE Current ErrorLevel is not supported.
+
+**/
+BOOLEAN
+EFIAPI
+DebugPrintLevelEnabled (
+ IN CONST UINTN ErrorLevel
+ )
+{
+ return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf
new file mode 100644
index 00000000..3a52e9ce
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf
@@ -0,0 +1,35 @@
+## @file
+# Instance of Debug Library based on POSIX APIs
+#
+# Uses Print Library to produce formatted output strings sent to printf().
+#
+# Copyright (c) 2018 - 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DebugLibPosix
+ MODULE_UNI_FILE = DebugLibPosix.uni
+ FILE_GUID = 6A77CE89-C1B6-4A6B-9561-07D7127514A7
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = DebugLib|HOST_APPLICATION
+
+[Sources]
+ DebugLibPosix.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ BaseMemoryLib
+ PcdLib
+ PrintLib
+ BaseLib
+
+[Pcd]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue ## SOMETIMES_CONSUMES
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask ## CONSUMES
+ gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel ## CONSUMES
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.uni
new file mode 100644
index 00000000..d34f1a05
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.uni
@@ -0,0 +1,14 @@
+// /** @file
+// Instance of Debug Library based on POSIX APIs
+//
+// Uses Print Library to produce formatted output strings sent to printf().
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Instance of Debug Library based on POSIX APIs"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Uses Print Library to produce formatted output strings sent to printf()."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.c
new file mode 100644
index 00000000..0f3aefa5
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.c
@@ -0,0 +1,631 @@
+/** @file
+ Instance of Memory Allocation Library based on POSIX APIs
+
+ Uses POSIX APIs malloc() and free() to allocate and free memory.
+
+ Copyright (c) 2018 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <Uefi.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DebugLib.h>
+
+///
+/// Signature for PAGE_HEAD structure
+/// Used to verify that buffer being freed was allocated by this library.
+///
+#define PAGE_HEAD_PRIVATE_SIGNATURE SIGNATURE_32 ('P', 'H', 'D', 'R')
+
+///
+/// Structure placed immediately before an aligned allocation to store the
+/// information required to free the entire buffer allocated to support then
+/// aligned allocation.
+///
+typedef struct {
+ UINT32 Signature;
+ VOID *AllocatedBufffer;
+ UINTN TotalPages;
+ VOID *AlignedBuffer;
+ UINTN AlignedPages;
+} PAGE_HEAD;
+
+/**
+ Allocates one or more 4KB pages of type EfiBootServicesData.
+
+ Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
+ allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
+ is returned. If there is not enough memory remaining to satisfy the request, then NULL is
+ returned.
+
+ @param Pages The number of 4 KB pages to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocatePages (
+ IN UINTN Pages
+ )
+{
+ return AllocateAlignedPages (Pages, SIZE_4KB);
+}
+
+/**
+ Allocates one or more 4KB pages of type EfiRuntimeServicesData.
+
+ Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
+ allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
+ is returned. If there is not enough memory remaining to satisfy the request, then NULL is
+ returned.
+
+ @param Pages The number of 4 KB pages to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateRuntimePages (
+ IN UINTN Pages
+ )
+{
+ return AllocatePages (Pages);
+}
+
+/**
+ Allocates one or more 4KB pages of type EfiReservedMemoryType.
+
+ Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
+ allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
+ is returned. If there is not enough memory remaining to satisfy the request, then NULL is
+ returned.
+
+ @param Pages The number of 4 KB pages to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateReservedPages (
+ IN UINTN Pages
+ )
+{
+ return AllocatePages (Pages);
+}
+
+/**
+ Frees one or more 4KB pages that were previously allocated with one of the page allocation
+ functions in the Memory Allocation Library.
+
+ Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
+ must have been allocated on a previous call to the page allocation services of the Memory
+ Allocation Library. If it is not possible to free allocated pages, then this function will
+ perform no actions.
+
+ If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
+ then ASSERT().
+ If Pages is zero, then ASSERT().
+
+ @param Buffer The pointer to the buffer of pages to free.
+ @param Pages The number of 4 KB pages to free.
+
+**/
+VOID
+EFIAPI
+FreePages (
+ IN VOID *Buffer,
+ IN UINTN Pages
+ )
+{
+ FreeAlignedPages (Buffer, Pages);
+}
+
+/**
+ Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
+
+ Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
+ alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
+ returned. If there is not enough memory at the specified alignment remaining to satisfy the
+ request, then NULL is returned.
+
+ If Alignment is not a power of two and Alignment is not zero, then ASSERT().
+ If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
+
+ @param Pages The number of 4 KB pages to allocate.
+ @param Alignment The requested alignment of the allocation. Must be a power of two.
+ If Alignment is zero, then byte alignment is used.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/VOID *
+EFIAPI
+AllocateAlignedPages (
+ IN UINTN Pages,
+ IN UINTN Alignment
+ )
+{
+ PAGE_HEAD PageHead;
+ PAGE_HEAD *PageHeadPtr;
+ UINTN AlignmentMask;
+
+ ASSERT ((Alignment & (Alignment - 1)) == 0);
+
+ if (Alignment < SIZE_4KB) {
+ Alignment = SIZE_4KB;
+ }
+ AlignmentMask = Alignment - 1;
+
+ //
+ // We need reserve Alignment pages for PAGE_HEAD, as meta data.
+ //
+ PageHead.Signature = PAGE_HEAD_PRIVATE_SIGNATURE;
+ PageHead.TotalPages = Pages + EFI_SIZE_TO_PAGES (Alignment) * 2;
+ PageHead.AlignedPages = Pages;
+ PageHead.AllocatedBufffer = malloc (EFI_PAGES_TO_SIZE (PageHead.TotalPages));
+ if (PageHead.AllocatedBufffer == NULL) {
+ return NULL;
+ }
+ PageHead.AlignedBuffer = (VOID *)(((UINTN) PageHead.AllocatedBufffer + AlignmentMask) & ~AlignmentMask);
+ if ((UINTN)PageHead.AlignedBuffer - (UINTN)PageHead.AllocatedBufffer < sizeof(PAGE_HEAD)) {
+ PageHead.AlignedBuffer = (VOID *)((UINTN)PageHead.AlignedBuffer + Alignment);
+ }
+
+ PageHeadPtr = (VOID *)((UINTN)PageHead.AlignedBuffer - sizeof(PAGE_HEAD));
+ memcpy (PageHeadPtr, &PageHead, sizeof(PAGE_HEAD));
+
+ return PageHead.AlignedBuffer;
+}
+
+/**
+ Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
+
+ Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
+ alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
+ returned. If there is not enough memory at the specified alignment remaining to satisfy the
+ request, then NULL is returned.
+
+ If Alignment is not a power of two and Alignment is not zero, then ASSERT().
+ If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
+
+ @param Pages The number of 4 KB pages to allocate.
+ @param Alignment The requested alignment of the allocation. Must be a power of two.
+ If Alignment is zero, then byte alignment is used.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateAlignedRuntimePages (
+ IN UINTN Pages,
+ IN UINTN Alignment
+ )
+{
+ return AllocateAlignedPages (Pages, Alignment);
+}
+
+/**
+ Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
+
+ Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
+ alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
+ returned. If there is not enough memory at the specified alignment remaining to satisfy the
+ request, then NULL is returned.
+
+ If Alignment is not a power of two and Alignment is not zero, then ASSERT().
+ If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().
+
+ @param Pages The number of 4 KB pages to allocate.
+ @param Alignment The requested alignment of the allocation. Must be a power of two.
+ If Alignment is zero, then byte alignment is used.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateAlignedReservedPages (
+ IN UINTN Pages,
+ IN UINTN Alignment
+ )
+{
+ return AllocateAlignedPages (Pages, Alignment);
+}
+
+/**
+ Frees one or more 4KB pages that were previously allocated with one of the aligned page
+ allocation functions in the Memory Allocation Library.
+
+ Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
+ must have been allocated on a previous call to the aligned page allocation services of the Memory
+ Allocation Library. If it is not possible to free allocated pages, then this function will
+ perform no actions.
+
+ If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
+ Library, then ASSERT().
+ If Pages is zero, then ASSERT().
+
+ @param Buffer The pointer to the buffer of pages to free.
+ @param Pages The number of 4 KB pages to free.
+
+**/
+VOID
+EFIAPI
+FreeAlignedPages (
+ IN VOID *Buffer,
+ IN UINTN Pages
+ )
+{
+ PAGE_HEAD *PageHeadPtr;
+
+ //
+ // NOTE: Partial free is not supported. Just keep it.
+ //
+ PageHeadPtr = (VOID *)((UINTN)Buffer - sizeof(PAGE_HEAD));
+ if (PageHeadPtr->Signature != PAGE_HEAD_PRIVATE_SIGNATURE) {
+ return;
+ }
+ if (PageHeadPtr->AlignedPages != Pages) {
+ return;
+ }
+
+ PageHeadPtr->Signature = 0;
+ free (PageHeadPtr->AllocatedBufffer);
+}
+
+/**
+ Allocates a buffer of type EfiBootServicesData.
+
+ Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
+ pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
+ returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
+
+ @param AllocationSize The number of bytes to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/VOID *
+EFIAPI
+AllocatePool (
+ IN UINTN AllocationSize
+ )
+{
+ return malloc (AllocationSize);
+}
+
+/**
+ Allocates a buffer of type EfiRuntimeServicesData.
+
+ Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
+ a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
+ returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
+
+ @param AllocationSize The number of bytes to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateRuntimePool (
+ IN UINTN AllocationSize
+ )
+{
+ return AllocatePool (AllocationSize);
+}
+
+/**
+ Allocates a buffer of type EfiReservedMemoryType.
+
+ Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType and returns
+ a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
+ returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
+
+ @param AllocationSize The number of bytes to allocate.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateReservedPool (
+ IN UINTN AllocationSize
+ )
+{
+ return AllocatePool (AllocationSize);
+}
+
+/**
+ Allocates and zeros a buffer of type EfiBootServicesData.
+
+ Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
+ buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
+ valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
+ request, then NULL is returned.
+
+ @param AllocationSize The number of bytes to allocate and zero.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateZeroPool (
+ IN UINTN AllocationSize
+ )
+{
+ VOID *Buffer;
+
+ Buffer = malloc (AllocationSize);
+ if (Buffer == NULL) {
+ return NULL;
+ }
+ memset (Buffer, 0, AllocationSize);
+ return Buffer;
+}
+
+/**
+ Allocates and zeros a buffer of type EfiRuntimeServicesData.
+
+ Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
+ buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
+ valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
+ request, then NULL is returned.
+
+ @param AllocationSize The number of bytes to allocate and zero.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateRuntimeZeroPool (
+ IN UINTN AllocationSize
+ )
+{
+ return AllocateZeroPool (AllocationSize);
+}
+
+/**
+ Allocates and zeros a buffer of type EfiReservedMemoryType.
+
+ Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
+ buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
+ valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
+ request, then NULL is returned.
+
+ @param AllocationSize The number of bytes to allocate and zero.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateReservedZeroPool (
+ IN UINTN AllocationSize
+ )
+{
+ return AllocateZeroPool (AllocationSize);
+}
+
+/**
+ Copies a buffer to an allocated buffer of type EfiBootServicesData.
+
+ Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
+ AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
+ allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
+ is not enough memory remaining to satisfy the request, then NULL is returned.
+
+ If Buffer is NULL, then ASSERT().
+ If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+ @param AllocationSize The number of bytes to allocate and zero.
+ @param Buffer The buffer to copy to the allocated buffer.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateCopyPool (
+ IN UINTN AllocationSize,
+ IN CONST VOID *Buffer
+ )
+{
+ VOID *Memory;
+
+ Memory = malloc (AllocationSize);
+ if (Memory == NULL) {
+ return NULL;
+ }
+ memcpy (Memory, Buffer, AllocationSize);
+ return Memory;
+}
+
+/**
+ Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
+
+ Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
+ AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
+ allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
+ is not enough memory remaining to satisfy the request, then NULL is returned.
+
+ If Buffer is NULL, then ASSERT().
+ If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+ @param AllocationSize The number of bytes to allocate and zero.
+ @param Buffer The buffer to copy to the allocated buffer.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateRuntimeCopyPool (
+ IN UINTN AllocationSize,
+ IN CONST VOID *Buffer
+ )
+{
+ return AllocateCopyPool (AllocationSize, Buffer);
+}
+
+/**
+ Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
+
+ Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
+ AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
+ allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
+ is not enough memory remaining to satisfy the request, then NULL is returned.
+
+ If Buffer is NULL, then ASSERT().
+ If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+ @param AllocationSize The number of bytes to allocate and zero.
+ @param Buffer The buffer to copy to the allocated buffer.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+AllocateReservedCopyPool (
+ IN UINTN AllocationSize,
+ IN CONST VOID *Buffer
+ )
+{
+ return AllocateCopyPool (AllocationSize, Buffer);
+}
+
+/**
+ Reallocates a buffer of type EfiBootServicesData.
+
+ Allocates and zeros the number bytes specified by NewSize from memory of type
+ EfiBootServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
+ NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
+ OldBuffer is freed. A pointer to the newly allocated buffer is returned.
+ If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
+ enough memory remaining to satisfy the request, then NULL is returned.
+
+ If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
+ is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
+
+ @param OldSize The size, in bytes, of OldBuffer.
+ @param NewSize The size, in bytes, of the buffer to reallocate.
+ @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
+ parameter that may be NULL.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+ReallocatePool (
+ IN UINTN OldSize,
+ IN UINTN NewSize,
+ IN VOID *OldBuffer OPTIONAL
+ )
+{
+ VOID *NewBuffer;
+
+ NewBuffer = malloc (NewSize);
+ if (NewBuffer != NULL && OldBuffer != NULL) {
+ memcpy (NewBuffer, OldBuffer, MIN (OldSize, NewSize));
+ }
+ if (OldBuffer != NULL) {
+ FreePool(OldBuffer);
+ }
+ return NewBuffer;
+}
+
+/**
+ Reallocates a buffer of type EfiRuntimeServicesData.
+
+ Allocates and zeros the number bytes specified by NewSize from memory of type
+ EfiRuntimeServicesData. If OldBuffer is not NULL, then the smaller of OldSize and
+ NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
+ OldBuffer is freed. A pointer to the newly allocated buffer is returned.
+ If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
+ enough memory remaining to satisfy the request, then NULL is returned.
+
+ If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
+ is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
+
+ @param OldSize The size, in bytes, of OldBuffer.
+ @param NewSize The size, in bytes, of the buffer to reallocate.
+ @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
+ parameter that may be NULL.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+ReallocateRuntimePool (
+ IN UINTN OldSize,
+ IN UINTN NewSize,
+ IN VOID *OldBuffer OPTIONAL
+ )
+{
+ return ReallocatePool (OldSize, NewSize, OldBuffer);
+}
+
+/**
+ Reallocates a buffer of type EfiReservedMemoryType.
+
+ Allocates and zeros the number bytes specified by NewSize from memory of type
+ EfiReservedMemoryType. If OldBuffer is not NULL, then the smaller of OldSize and
+ NewSize bytes are copied from OldBuffer to the newly allocated buffer, and
+ OldBuffer is freed. A pointer to the newly allocated buffer is returned.
+ If NewSize is 0, then a valid buffer of 0 size is returned. If there is not
+ enough memory remaining to satisfy the request, then NULL is returned.
+
+ If the allocation of the new buffer is successful and the smaller of NewSize and OldSize
+ is greater than (MAX_ADDRESS - OldBuffer + 1), then ASSERT().
+
+ @param OldSize The size, in bytes, of OldBuffer.
+ @param NewSize The size, in bytes, of the buffer to reallocate.
+ @param OldBuffer The buffer to copy to the allocated buffer. This is an optional
+ parameter that may be NULL.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+EFIAPI
+ReallocateReservedPool (
+ IN UINTN OldSize,
+ IN UINTN NewSize,
+ IN VOID *OldBuffer OPTIONAL
+ )
+{
+ return ReallocatePool (OldSize, NewSize, OldBuffer);
+}
+
+/**
+ Frees a buffer that was previously allocated with one of the pool allocation functions in the
+ Memory Allocation Library.
+
+ Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
+ pool allocation services of the Memory Allocation Library. If it is not possible to free pool
+ resources, then this function will perform no actions.
+
+ If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
+ then ASSERT().
+
+ @param Buffer The pointer to the buffer to free.
+
+**/
+VOID
+EFIAPI
+FreePool (
+ IN VOID *Buffer
+ )
+{
+ free (Buffer);
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf
new file mode 100644
index 00000000..d26e2cae
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf
@@ -0,0 +1,27 @@
+## @file
+# Instance of Memory Allocation Library based on POSIX APIs
+#
+# Uses POSIX APIs malloc() and free() to allocate and free memory.
+#
+# Copyright (c) 2018 - 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = MemoryAllocationLibPosix
+ MODULE_UNI_FILE = MemoryAllocationLibPosix.uni
+ FILE_GUID = A1672454-A3D3-4AAC-A86B-8D63132BBB91
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = MemoryAllocationLib|HOST_APPLICATION
+
+[Sources]
+ MemoryAllocationLibPosix.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ BaseLib
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.uni
new file mode 100644
index 00000000..854b4279
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.uni
@@ -0,0 +1,14 @@
+// /** @file
+// Instance of Memory Allocation Library based on POSIX APIs
+//
+// Uses POSIX APIs malloc() and free() to allocate and free memory.
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Instance of Memory Allocation Library based on POSIX APIs"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Uses POSIX APIs malloc() and free() to allocate and free memory."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.c
new file mode 100644
index 00000000..e5423932
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.c
@@ -0,0 +1,26 @@
+/**
+ NULL implementation for UnitTestBootLib to allow simple compilation
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <PiDxe.h>
+
+/**
+ Set the boot manager to boot from a specific device on the next boot. This
+ should be set only for the next boot and shouldn't require any manual clean up
+
+ @retval EFI_SUCCESS Boot device for next boot was set.
+ @retval EFI_UNSUPPORTED Setting the boot device for the next boot is not
+ supportted.
+ @retval Other Boot device for next boot can not be set.
+**/
+EFI_STATUS
+EFIAPI
+SetBootNextDevice(
+ VOID
+ )
+{
+ return EFI_UNSUPPORTED;
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.inf
new file mode 100644
index 00000000..75c3bf82
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.inf
@@ -0,0 +1,23 @@
+## @file
+# NULL library for UnitTestBootUsb
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UnitTestBootLibNull
+ MODULE_UNI_FILE = UnitTestBootLibNull.uni
+ FILE_GUID = f143e75d-76e1-4040-b134-8f4f0bd5e3bd
+ VERSION_STRING = 1.0
+ MODULE_TYPE = DXE_DRIVER
+ LIBRARY_CLASS = UnitTestBootLib
+
+[Sources]
+ UnitTestBootLibNull.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.uni
new file mode 100644
index 00000000..1ed3b205
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.uni
@@ -0,0 +1,11 @@
+// /** @file
+// NULL library for UnitTestBootUsb
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "NULL library for UnitTestBootUsb"
+
+#string STR_MODULE_DESCRIPTION #language en-US "NULL library for UnitTestBootUsb."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.c
new file mode 100644
index 00000000..58bd21c9
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.c
@@ -0,0 +1,127 @@
+/**
+ Implement UnitTestBootLib using USB Class Boot option. This should be
+ industry standard and should work on all platforms
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <PiDxe.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/UefiBootManagerLib.h>
+#include <Library/DevicePathLib.h>
+#include <Protocol/DevicePath.h>
+#include <Library/MemoryAllocationLib.h>
+
+/**
+ Set the boot manager to boot from a specific device on the next boot. This
+ should be set only for the next boot and shouldn't require any manual clean up
+
+ @retval EFI_SUCCESS Boot device for next boot was set.
+ @retval EFI_UNSUPPORTED Setting the boot device for the next boot is not
+ supportted.
+ @retval Other Boot device for next boot can not be set.
+**/
+EFI_STATUS
+EFIAPI
+SetBootNextDevice (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
+ UINT32 Attributes;
+ UINT8 *OptionalData;
+ UINT32 OptionalDataSize;
+ UINT16 BootNextValue;
+ USB_CLASS_DEVICE_PATH UsbDp;
+ EFI_DEVICE_PATH_PROTOCOL *DpEnd;
+ EFI_DEVICE_PATH_PROTOCOL *Dp;
+ BOOLEAN NewOptionValid;
+
+ OptionalData = NULL;
+ OptionalDataSize = 0;
+ BootNextValue = 0xABCD; // this should be a safe number...
+ DpEnd = NULL;
+ Dp = NULL;
+ NewOptionValid = FALSE;
+
+ UsbDp.Header.Length[0] = (UINT8)(sizeof(USB_CLASS_DEVICE_PATH) & 0xff);
+ UsbDp.Header.Length[1] = (UINT8)(sizeof(USB_CLASS_DEVICE_PATH) >> 8);
+ UsbDp.Header.Type = MESSAGING_DEVICE_PATH;
+ UsbDp.Header.SubType = MSG_USB_CLASS_DP;
+ UsbDp.VendorId = 0xFFFF;
+ UsbDp.ProductId = 0xFFFF;
+ UsbDp.DeviceClass = 0xFF;
+ UsbDp.DeviceSubClass = 0xFF;
+ UsbDp.DeviceProtocol = 0xFF;
+
+ Attributes = LOAD_OPTION_ACTIVE;
+
+ DpEnd = AppendDevicePathNode (NULL, NULL);
+ if (DpEnd == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Unable to create device path. DpEnd is NULL.\n", __FUNCTION__));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto CLEANUP;
+ }
+
+ //@MRT --- Is this memory leak because we lose the old Dp memory
+ Dp = AppendDevicePathNode (
+ DpEnd,
+ (EFI_DEVICE_PATH_PROTOCOL *)&UsbDp
+ );
+ if (Dp == NULL) {
+ DEBUG((DEBUG_ERROR, "%a: Unable to create device path. Dp is NULL.\n", __FUNCTION__));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto CLEANUP;
+ }
+
+ Status = EfiBootManagerInitializeLoadOption (
+ &NewOption,
+ (UINTN) BootNextValue,
+ LoadOptionTypeBoot,
+ Attributes,
+ L"Generic USB Class Device",
+ Dp,
+ OptionalData,
+ OptionalDataSize
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Error creating load option. Status = %r\n", __FUNCTION__, Status));
+ goto CLEANUP;
+ }
+
+ NewOptionValid = TRUE;
+ DEBUG ((DEBUG_VERBOSE, "%a: Generic USB Class Device boot option created.\n", __FUNCTION__));
+ Status = EfiBootManagerLoadOptionToVariable (&NewOption);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Error Saving boot option NV variable. Status = %r\n", __FUNCTION__, Status));
+ goto CLEANUP;
+ }
+
+ //
+ // Set Boot Next
+ //
+ Status = gRT->SetVariable (
+ L"BootNext",
+ &gEfiGlobalVariableGuid,
+ (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE),
+ sizeof(BootNextValue),
+ &(BootNextValue)
+ );
+
+ DEBUG((DEBUG_VERBOSE, "%a - Set BootNext Status (%r)\n", __FUNCTION__, Status));
+
+CLEANUP:
+ if (Dp != NULL) {
+ FreePool (Dp);
+ }
+ if (DpEnd != NULL) {
+ FreePool (DpEnd);
+ }
+ if (NewOptionValid) {
+ EfiBootManagerFreeLoadOption (&NewOption);
+ }
+ return Status;
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.inf
new file mode 100644
index 00000000..fe00f7ed
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.inf
@@ -0,0 +1,34 @@
+## @file
+# Library to support booting to USB on the next boot
+# This instance uses the industry standard usb class boot option.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UnitTestBootLibUsbClass
+ MODULE_UNI_FILE = UnitTestBootLibUsbClass.uni
+ FILE_GUID = DFADE2A2-DB69-47DE-A37A-40FB6D52E844
+ VERSION_STRING = 1.0
+ MODULE_TYPE = UEFI_APPLICATION
+ LIBRARY_CLASS = UnitTestBootLib
+
+[Sources]
+ UnitTestBootLibUsbClass.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ UefiRuntimeServicesTableLib
+ MemoryAllocationLib
+ DevicePathLib
+ UefiBootManagerLib
+
+[Guids]
+ gEfiGlobalVariableGuid ## CONSUMES ## Used to probe boot options and set BootNext.
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.uni
new file mode 100644
index 00000000..8468b353
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.uni
@@ -0,0 +1,12 @@
+// /** @file
+// Library to support booting to USB on the next boot
+// This instance uses the industry standard usb class boot option.
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Library to support booting to USB on the next boot"
+
+#string STR_MODULE_DESCRIPTION #language en-US "This instance uses the industry standard usb class boot option.."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
new file mode 100644
index 00000000..e262e523
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
@@ -0,0 +1,49 @@
+/** @file
+ Unit Test Debug Assert Library
+
+ Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/UnitTestLib.h>
+
+///
+/// Point to jump buffer used with SetJump()/LongJump() to test if a function
+/// under test generates an expected ASSERT() condition.
+///
+BASE_LIBRARY_JUMP_BUFFER *gUnitTestExpectAssertFailureJumpBuffer = NULL;
+
+/**
+ Unit test library replacement for DebugAssert() in DebugLib.
+
+ If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
+ If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
+
+ @param FileName The pointer to the name of the source file that generated the assert condition.
+ @param LineNumber The line number in the source file that generated the assert condition
+ @param Description The pointer to the description of the assert condition.
+
+**/
+VOID
+EFIAPI
+UnitTestDebugAssert (
+ IN CONST CHAR8 *FileName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *Description
+ )
+{
+ CHAR8 Message[256];
+
+ if (gUnitTestExpectAssertFailureJumpBuffer != NULL) {
+ UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, LineNumber, Description);
+ LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1);
+ } else {
+ AsciiStrCpyS (Message, sizeof(Message), "Detected unexpected ASSERT(");
+ AsciiStrCatS (Message, sizeof(Message), Description);
+ AsciiStrCatS (Message, sizeof(Message), ")");
+ UnitTestAssertTrue (FALSE, "", LineNumber, FileName, Message);
+ }
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
new file mode 100644
index 00000000..4e9a3d95
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
@@ -0,0 +1,31 @@
+## @file
+# Unit Test Debug Assert Library
+#
+# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnitTestDebugAssertLib
+ MODULE_UNI_FILE = UnitTestDebugAssertLib.uni
+ FILE_GUID = 9D53AD0D-5416-451F-A5BF-E5420051A99B
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = NULL
+
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+ UnitTestDebugAssertLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ UnitTestLib
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.uni
new file mode 100644
index 00000000..9b794aa2
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.uni
@@ -0,0 +1,11 @@
+// /** @file
+// Unit Test Debug Assert Library
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Unit Test Debug Assert Library"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Unit Test Debug Assert Library"
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c
new file mode 100644
index 00000000..2def1318
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c
@@ -0,0 +1,571 @@
+/**
+ Implement UnitTestLib assert services
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+#include <UnitTestFrameworkTypes.h>
+#include <Library/UnitTestLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PrintLib.h>
+
+extern BASE_LIBRARY_JUMP_BUFFER gUnitTestJumpBuffer;
+
+STATIC
+EFI_STATUS
+AddUnitTestFailure (
+ IN OUT UNIT_TEST *UnitTest,
+ IN CONST CHAR8 *FailureMessage,
+ IN FAILURE_TYPE FailureType
+ )
+{
+ //
+ // Make sure that you're cooking with gas.
+ //
+ if (UnitTest == NULL || FailureMessage == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ UnitTest->FailureType = FailureType;
+ AsciiStrCpyS (
+ &UnitTest->FailureMessage[0],
+ UNIT_TEST_TESTFAILUREMSG_LENGTH,
+ FailureMessage
+ );
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+VOID
+EFIAPI
+UnitTestLogFailure (
+ IN FAILURE_TYPE FailureType,
+ IN CONST CHAR8 *Format,
+ ...
+ )
+{
+ UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle;
+ CHAR8 LogString[UNIT_TEST_TESTFAILUREMSG_LENGTH];
+ VA_LIST Marker;
+
+ //
+ // Get active Framework handle
+ //
+ FrameworkHandle = GetActiveFrameworkHandle ();
+
+ //
+ // Convert the message to an ASCII String
+ //
+ VA_START (Marker, Format);
+ AsciiVSPrint (LogString, sizeof (LogString), Format, Marker);
+ VA_END (Marker);
+
+ //
+ // Finally, add the string to the log.
+ //
+ AddUnitTestFailure (
+ ((UNIT_TEST_FRAMEWORK *)FrameworkHandle)->CurrentTest,
+ LogString,
+ FailureType
+ );
+
+ LongJump (&gUnitTestJumpBuffer, 1);
+}
+
+/**
+ If Expression is TRUE, then TRUE is returned.
+ If Expression is FALSE, then an assert is triggered and the location of the
+ assert provided by FunctionName, LineNumber, FileName, and Description are
+ recorded and FALSE is returned.
+
+ @param[in] Expression The BOOLEAN result of the expression evaluation.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] Description Null-terminated ASCII string of the expression being
+ evaluated.
+
+ @retval TRUE Expression is TRUE.
+ @retval FALSE Expression is FALSE.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertTrue (
+ IN BOOLEAN Expression,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *Description
+ )
+{
+ if (!Expression) {
+ UT_LOG_ERROR (
+ "[ASSERT FAIL] %a:%d: Expression (%a) is not TRUE!\n",
+ FileName,
+ LineNumber,
+ Description
+ );
+ UnitTestLogFailure (
+ FAILURETYPE_ASSERTTRUE,
+ "%a:%d: Expression (%a) is not TRUE!\n",
+ FileName,
+ LineNumber,
+ Description
+ );
+ }
+ return Expression;
+}
+
+/**
+ If Expression is FALSE, then TRUE is returned.
+ If Expression is TRUE, then an assert is triggered and the location of the
+ assert provided by FunctionName, LineNumber, FileName, and Description are
+ recorded and FALSE is returned.
+
+ @param[in] Expression The BOOLEAN result of the expression evaluation.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] Description Null-terminated ASCII string of the expression being
+ evaluated.
+
+ @retval TRUE Expression is FALSE.
+ @retval FALSE Expression is TRUE.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertFalse (
+ IN BOOLEAN Expression,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *Description
+ )
+{
+ if (Expression) {
+ UT_LOG_ERROR (
+ "[ASSERT FAIL] %a:%d: Expression (%a) is not FALSE!\n",
+ FileName,
+ LineNumber,
+ Description
+ );
+ UnitTestLogFailure (
+ FAILURETYPE_ASSERTFALSE,
+ "%a:%d: Expression(%a) is not FALSE!\n",
+ FileName,
+ LineNumber,
+ Description
+ );
+ }
+ return !Expression;
+}
+
+/**
+ If Status is not an EFI_ERROR(), then TRUE is returned.
+ If Status is an EFI_ERROR(), then an assert is triggered and the location of
+ the assert provided by FunctionName, LineNumber, FileName, and Description are
+ recorded and FALSE is returned.
+
+ @param[in] Status The EFI_STATUS value to evaluate.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] Description Null-terminated ASCII string of the status
+ expression being evaluated.
+
+ @retval TRUE Status is not an EFI_ERROR().
+ @retval FALSE Status is an EFI_ERROR().
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertNotEfiError (
+ IN EFI_STATUS Status,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *Description
+ )
+{
+ if (EFI_ERROR (Status)) {
+ UT_LOG_ERROR (
+ "[ASSERT FAIL] %a:%d: Status '%a' is EFI_ERROR (%r)!\n",
+ FileName,
+ LineNumber,
+ Description,
+ Status
+ );
+ UnitTestLogFailure (
+ FAILURETYPE_ASSERTNOTEFIERROR,
+ "%a:%d: Status '%a' is EFI_ERROR (%r)!\n",
+ FileName,
+ LineNumber,
+ Description,
+ Status
+ );
+ }
+ return !EFI_ERROR( Status );
+}
+
+/**
+ If ValueA is equal ValueB, then TRUE is returned.
+ If ValueA is not equal to ValueB, then an assert is triggered and the location
+ of the assert provided by FunctionName, LineNumber, FileName, DescriptionA,
+ and DescriptionB are recorded and FALSE is returned.
+
+ @param[in] ValueA 64-bit value.
+ @param[in] ValueB 64-bit value.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] DescriptionA Null-terminated ASCII string that is a description
+ of ValueA.
+ @param[in] DescriptionB Null-terminated ASCII string that is a description
+ of ValueB.
+
+ @retval TRUE ValueA is equal to ValueB.
+ @retval FALSE ValueA is not equal to ValueB.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertEqual (
+ IN UINT64 ValueA,
+ IN UINT64 ValueB,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *DescriptionA,
+ IN CONST CHAR8 *DescriptionB
+ )
+{
+ if (ValueA != ValueB) {
+ UT_LOG_ERROR (
+ "[ASSERT FAIL] %a:%d: Value %a != %a (%d != %d)!\n",
+ FileName,
+ LineNumber,
+ DescriptionA,
+ DescriptionB,
+ ValueA,
+ ValueB
+ );
+ UnitTestLogFailure (
+ FAILURETYPE_ASSERTEQUAL,
+ "%a:%d: Value %a != %a (%d != %d)!\n",
+ FileName,
+ LineNumber,
+ DescriptionA,
+ DescriptionB,
+ ValueA,
+ ValueB
+ );
+ }
+ return (ValueA == ValueB);
+}
+
+/**
+ If the contents of BufferA are identical to the contents of BufferB, then TRUE
+ is returned. If the contents of BufferA are not identical to the contents of
+ BufferB, then an assert is triggered and the location of the assert provided
+ by FunctionName, LineNumber, FileName, DescriptionA, and DescriptionB are
+ recorded and FALSE is returned.
+
+ @param[in] BufferA Pointer to a buffer for comparison.
+ @param[in] BufferB Pointer to a buffer for comparison.
+ @param[in] Length Number of bytes to compare in BufferA and BufferB.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] DescriptionA Null-terminated ASCII string that is a description
+ of BufferA.
+ @param[in] DescriptionB Null-terminated ASCII string that is a description
+ of BufferB.
+
+ @retval TRUE The contents of BufferA are identical to the contents of
+ BufferB.
+ @retval FALSE The contents of BufferA are not identical to the contents of
+ BufferB.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertMemEqual (
+ IN VOID *BufferA,
+ IN VOID *BufferB,
+ IN UINTN Length,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *DescriptionA,
+ IN CONST CHAR8 *DescriptionB
+ )
+{
+ if (CompareMem(BufferA, BufferB, Length) != 0) {
+ UT_LOG_ERROR (
+ "[ASSERT FAIL] %a:%d: Value %a != %a for length %d bytes!\n",
+ FileName,
+ LineNumber,
+ DescriptionA,
+ DescriptionB,
+ Length
+ );
+ UnitTestLogFailure (
+ FAILURETYPE_ASSERTEQUAL,
+ "%a:%d: Memory at %a != %a for length %d bytes!\n",
+ FileName,
+ LineNumber,
+ DescriptionA,
+ DescriptionB,
+ Length
+ );
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ If ValueA is not equal ValueB, then TRUE is returned.
+ If ValueA is equal to ValueB, then an assert is triggered and the location
+ of the assert provided by FunctionName, LineNumber, FileName, DescriptionA
+ and DescriptionB are recorded and FALSE is returned.
+
+ @param[in] ValueA 64-bit value.
+ @param[in] ValueB 64-bit value.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] DescriptionA Null-terminated ASCII string that is a description
+ of ValueA.
+ @param[in] DescriptionB Null-terminated ASCII string that is a description
+ of ValueB.
+
+ @retval TRUE ValueA is not equal to ValueB.
+ @retval FALSE ValueA is equal to ValueB.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertNotEqual (
+ IN UINT64 ValueA,
+ IN UINT64 ValueB,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *DescriptionA,
+ IN CONST CHAR8 *DescriptionB
+ )
+{
+ if (ValueA == ValueB) {
+ UT_LOG_ERROR (
+ "[ASSERT FAIL] %a:%d: Value %a == %a (%d == %d)!\n",
+ FileName,
+ LineNumber,
+ DescriptionA,
+ DescriptionB,
+ ValueA,
+ ValueB
+ );
+ UnitTestLogFailure (
+ FAILURETYPE_ASSERTNOTEQUAL,
+ "%a:%d: Value %a == %a (%d == %d)!\n",
+ FileName,
+ LineNumber,
+ DescriptionA,
+ DescriptionB,
+ ValueA,
+ ValueB
+ );
+ }
+ return (ValueA != ValueB);
+}
+
+/**
+ If Status is equal to Expected, then TRUE is returned.
+ If Status is not equal to Expected, then an assert is triggered and the
+ location of the assert provided by FunctionName, LineNumber, FileName, and
+ Description are recorded and FALSE is returned.
+
+ @param[in] Status EFI_STATUS value returned from an API under test.
+ @param[in] Expected The expected EFI_STATUS return value from an API
+ under test.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] Description Null-terminated ASCII string that is a description
+ of Status.
+
+ @retval TRUE Status is equal to Expected.
+ @retval FALSE Status is not equal to Expected.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertStatusEqual (
+ IN EFI_STATUS Status,
+ IN EFI_STATUS Expected,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *Description
+ )
+{
+ if (Status != Expected) {
+ UT_LOG_ERROR (
+ "[ASSERT FAIL] %a:%d: Status '%a' is %r, should be %r!\n",
+ FileName,
+ LineNumber,
+ Description,
+ Status,
+ Expected
+ );
+ UnitTestLogFailure (
+ FAILURETYPE_ASSERTSTATUSEQUAL,
+ "%a:%d: Status '%a' is %r, should be %r!\n",
+ FileName,
+ LineNumber,
+ Description,
+ Status,
+ Expected
+ );
+ }
+ return (Status == Expected);
+}
+
+/**
+ If Pointer is not equal to NULL, then TRUE is returned.
+ If Pointer is equal to NULL, then an assert is triggered and the location of
+ the assert provided by FunctionName, LineNumber, FileName, and PointerName
+ are recorded and FALSE is returned.
+
+ @param[in] Pointer Pointer value to be checked against NULL.
+ @param[in] Expected The expected EFI_STATUS return value from a function
+ under test.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] PointerName Null-terminated ASCII string that is a description
+ of Pointer.
+
+ @retval TRUE Pointer is not equal to NULL.
+ @retval FALSE Pointer is equal to NULL.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertNotNull (
+ IN VOID *Pointer,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *PointerName
+ )
+{
+ if (Pointer == NULL) {
+ UT_LOG_ERROR (
+ "[ASSERT FAIL] %a:%d: Pointer (%a) is NULL!\n",
+ FileName,
+ LineNumber,
+ PointerName
+ );
+ UnitTestLogFailure (
+ FAILURETYPE_ASSERTNOTNULL,
+ "%a:%d: Pointer (%a) is NULL!\n",
+ FileName,
+ LineNumber,
+ PointerName
+ );
+ }
+ return (Pointer != NULL);
+}
+
+/**
+ If UnitTestStatus is UNIT_TEST_PASSED, then log an info message and return
+ TRUE because an ASSERT() was expected when FunctionCall was executed and an
+ ASSERT() was triggered. If UnitTestStatus is UNIT_TEST_SKIPPED, then log a
+ warning message and return TRUE because ASSERT() macros are disabled. If
+ UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED, then log an error message and
+ return FALSE because an ASSERT() was expected when FunctionCall was executed,
+ but no ASSERT() conditions were triggered. The log messages contain
+ FunctionName, LineNumber, and FileName strings to provide the location of the
+ UT_EXPECT_ASSERT_FAILURE() macro.
+
+ @param[in] UnitTestStatus The status from UT_EXPECT_ASSERT_FAILURE() that
+ is either pass, skipped, or failed.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the UT_EXPECT_ASSERT_FAILURE() macro.
+ @param[in] LineNumber The source file line number of the the function
+ executing the UT_EXPECT_ASSERT_FAILURE() macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the UT_EXPECT_ASSERT_FAILURE() macro.
+ @param[in] FunctionCall Null-terminated ASCII string of the function call
+ executed by the UT_EXPECT_ASSERT_FAILURE() macro.
+ @param[out] ResultStatus Used to return the UnitTestStatus value to the
+ caller of UT_EXPECT_ASSERT_FAILURE(). This is
+ optional parameter that may be NULL.
+
+ @retval TRUE UnitTestStatus is UNIT_TEST_PASSED.
+ @retval TRUE UnitTestStatus is UNIT_TEST_SKIPPED.
+ @retval FALSE UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED.
+**/
+BOOLEAN
+EFIAPI
+UnitTestExpectAssertFailure (
+ IN UNIT_TEST_STATUS UnitTestStatus,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *FunctionCall,
+ OUT UNIT_TEST_STATUS *ResultStatus OPTIONAL
+ )
+{
+ if (ResultStatus != NULL) {
+ *ResultStatus = UnitTestStatus;
+ }
+ if (UnitTestStatus == UNIT_TEST_PASSED) {
+ UT_LOG_INFO (
+ "[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expected assert\n",
+ FileName,
+ LineNumber,
+ FunctionCall
+ );
+ }
+ if (UnitTestStatus == UNIT_TEST_SKIPPED) {
+ UT_LOG_WARNING (
+ "[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n",
+ FileName,
+ LineNumber,
+ FunctionCall
+ );
+ }
+ if (UnitTestStatus == UNIT_TEST_ERROR_TEST_FAILED) {
+ UT_LOG_ERROR (
+ "[ASSERT FAIL] %a:%d: Function call (%a) did not ASSERT()!\n",
+ FileName,
+ LineNumber,
+ FunctionCall
+ );
+ UnitTestLogFailure (
+ FAILURETYPE_EXPECTASSERT,
+ "%a:%d: Function call (%a) did not ASSERT()!\n",
+ FileName,
+ LineNumber,
+ FunctionCall
+ );
+ }
+ return (UnitTestStatus != UNIT_TEST_ERROR_TEST_FAILED);
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c
new file mode 100644
index 00000000..cc58909b
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c
@@ -0,0 +1,403 @@
+/** @file
+ Implement UnitTestLib assert services using cmocka services
+
+ Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <Uefi.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UnitTestLib.h>
+
+#define MAX_STRING_SIZE 1025
+
+/**
+ If Expression is TRUE, then TRUE is returned.
+ If Expression is FALSE, then an assert is triggered and the location of the
+ assert provided by FunctionName, LineNumber, FileName, and Description are
+ recorded and FALSE is returned.
+
+ @param[in] Expression The BOOLEAN result of the expression evaluation.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] Description Null-terminated ASCII string of the expression being
+ evaluated.
+
+ @retval TRUE Expression is TRUE.
+ @retval FALSE Expression is FALSE.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertTrue (
+ IN BOOLEAN Expression,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *Description
+ )
+{
+ CHAR8 TempStr[MAX_STRING_SIZE];
+
+ snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_TRUE(%s:%x)", Description, Expression);
+ _assert_true (Expression, TempStr, FileName, (INT32)LineNumber);
+
+ return Expression;
+}
+
+/**
+ If Expression is FALSE, then TRUE is returned.
+ If Expression is TRUE, then an assert is triggered and the location of the
+ assert provided by FunctionName, LineNumber, FileName, and Description are
+ recorded and FALSE is returned.
+
+ @param[in] Expression The BOOLEAN result of the expression evaluation.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] Description Null-terminated ASCII string of the expression being
+ evaluated.
+
+ @retval TRUE Expression is FALSE.
+ @retval FALSE Expression is TRUE.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertFalse (
+ IN BOOLEAN Expression,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *Description
+ )
+{
+ CHAR8 TempStr[MAX_STRING_SIZE];
+
+ snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_FALSE(%s:%x)", Description, Expression);
+ _assert_true (!Expression, TempStr, FileName, (INT32)LineNumber);
+
+ return !Expression;
+}
+
+/**
+ If Status is not an EFI_ERROR(), then TRUE is returned.
+ If Status is an EFI_ERROR(), then an assert is triggered and the location of
+ the assert provided by FunctionName, LineNumber, FileName, and Description are
+ recorded and FALSE is returned.
+
+ @param[in] Status The EFI_STATUS value to evaluate.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] Description Null-terminated ASCII string of the status
+ expression being evaluated.
+
+ @retval TRUE Status is not an EFI_ERROR().
+ @retval FALSE Status is an EFI_ERROR().
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertNotEfiError (
+ IN EFI_STATUS Status,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *Description
+ )
+{
+ CHAR8 TempStr[MAX_STRING_SIZE];
+
+ snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_NOT_EFI_ERROR(%s:%p)", Description, (void *)Status);
+ _assert_true (!EFI_ERROR (Status), TempStr, FileName, (INT32)LineNumber);
+
+ return !EFI_ERROR (Status);
+}
+
+/**
+ If ValueA is equal ValueB, then TRUE is returned.
+ If ValueA is not equal to ValueB, then an assert is triggered and the location
+ of the assert provided by FunctionName, LineNumber, FileName, DescriptionA,
+ and DescriptionB are recorded and FALSE is returned.
+
+ @param[in] ValueA 64-bit value.
+ @param[in] ValueB 64-bit value.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] DescriptionA Null-terminated ASCII string that is a description
+ of ValueA.
+ @param[in] DescriptionB Null-terminated ASCII string that is a description
+ of ValueB.
+
+ @retval TRUE ValueA is equal to ValueB.
+ @retval FALSE ValueA is not equal to ValueB.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertEqual (
+ IN UINT64 ValueA,
+ IN UINT64 ValueB,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *DescriptionA,
+ IN CONST CHAR8 *DescriptionB
+ )
+{
+ CHAR8 TempStr[MAX_STRING_SIZE];
+
+ snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_EQUAL(%s:%llx, %s:%llx)", DescriptionA, ValueA, DescriptionB, ValueB);
+ _assert_true ((ValueA == ValueB), TempStr, FileName, (INT32)LineNumber);
+
+ return (ValueA == ValueB);
+}
+
+/**
+ If the contents of BufferA are identical to the contents of BufferB, then TRUE
+ is returned. If the contents of BufferA are not identical to the contents of
+ BufferB, then an assert is triggered and the location of the assert provided
+ by FunctionName, LineNumber, FileName, DescriptionA, and DescriptionB are
+ recorded and FALSE is returned.
+
+ @param[in] BufferA Pointer to a buffer for comparison.
+ @param[in] BufferB Pointer to a buffer for comparison.
+ @param[in] Length Number of bytes to compare in BufferA and BufferB.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] DescriptionA Null-terminated ASCII string that is a description
+ of BufferA.
+ @param[in] DescriptionB Null-terminated ASCII string that is a description
+ of BufferB.
+
+ @retval TRUE The contents of BufferA are identical to the contents of
+ BufferB.
+ @retval FALSE The contents of BufferA are not identical to the contents of
+ BufferB.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertMemEqual (
+ IN VOID *BufferA,
+ IN VOID *BufferB,
+ IN UINTN Length,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *DescriptionA,
+ IN CONST CHAR8 *DescriptionB
+ )
+{
+ CHAR8 TempStr[MAX_STRING_SIZE];
+ BOOLEAN Result;
+
+ Result = (CompareMem(BufferA, BufferB, Length) == 0);
+
+ snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_MEM_EQUAL(%s:%p, %s:%p)", DescriptionA, BufferA, DescriptionB, BufferB);
+ _assert_true (Result, TempStr, FileName, (INT32)LineNumber);
+
+ return Result;
+}
+
+/**
+ If ValueA is not equal ValueB, then TRUE is returned.
+ If ValueA is equal to ValueB, then an assert is triggered and the location
+ of the assert provided by FunctionName, LineNumber, FileName, DescriptionA
+ and DescriptionB are recorded and FALSE is returned.
+
+ @param[in] ValueA 64-bit value.
+ @param[in] ValueB 64-bit value.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] DescriptionA Null-terminated ASCII string that is a description
+ of ValueA.
+ @param[in] DescriptionB Null-terminated ASCII string that is a description
+ of ValueB.
+
+ @retval TRUE ValueA is not equal to ValueB.
+ @retval FALSE ValueA is equal to ValueB.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertNotEqual (
+ IN UINT64 ValueA,
+ IN UINT64 ValueB,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *DescriptionA,
+ IN CONST CHAR8 *DescriptionB
+ )
+{
+ CHAR8 TempStr[MAX_STRING_SIZE];
+
+ snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_NOT_EQUAL(%s:%llx, %s:%llx)", DescriptionA, ValueA, DescriptionB, ValueB);
+ _assert_true ((ValueA != ValueB), TempStr, FileName, (INT32)LineNumber);
+
+ return (ValueA != ValueB);
+}
+
+/**
+ If Status is equal to Expected, then TRUE is returned.
+ If Status is not equal to Expected, then an assert is triggered and the
+ location of the assert provided by FunctionName, LineNumber, FileName, and
+ Description are recorded and FALSE is returned.
+
+ @param[in] Status EFI_STATUS value returned from an API under test.
+ @param[in] Expected The expected EFI_STATUS return value from an API
+ under test.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] Description Null-terminated ASCII string that is a description
+ of Status.
+
+ @retval TRUE Status is equal to Expected.
+ @retval FALSE Status is not equal to Expected.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertStatusEqual (
+ IN EFI_STATUS Status,
+ IN EFI_STATUS Expected,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *Description
+ )
+{
+ CHAR8 TempStr[MAX_STRING_SIZE];
+
+ snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_STATUS_EQUAL(%s:%p)", Description, (VOID *)Status);
+ _assert_true ((Status == Expected), TempStr, FileName, (INT32)LineNumber);
+
+ return (Status == Expected);
+}
+
+/**
+ If Pointer is not equal to NULL, then TRUE is returned.
+ If Pointer is equal to NULL, then an assert is triggered and the location of
+ the assert provided by FunctionName, LineNumber, FileName, and PointerName
+ are recorded and FALSE is returned.
+
+ @param[in] Pointer Pointer value to be checked against NULL.
+ @param[in] Expected The expected EFI_STATUS return value from a function
+ under test.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the assert macro.
+ @param[in] LineNumber The source file line number of the assert macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the assert macro.
+ @param[in] PointerName Null-terminated ASCII string that is a description
+ of Pointer.
+
+ @retval TRUE Pointer is not equal to NULL.
+ @retval FALSE Pointer is equal to NULL.
+**/
+BOOLEAN
+EFIAPI
+UnitTestAssertNotNull (
+ IN VOID *Pointer,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *PointerName
+ )
+{
+ CHAR8 TempStr[MAX_STRING_SIZE];
+
+ snprintf (TempStr, sizeof(TempStr), "UT_ASSERT_NOT_NULL(%s:%p)", PointerName, Pointer);
+ _assert_true ((Pointer != NULL), TempStr, FileName, (INT32)LineNumber);
+
+ return (Pointer != NULL);
+}
+
+/**
+ If UnitTestStatus is UNIT_TEST_PASSED, then log an info message and return
+ TRUE because an ASSERT() was expected when FunctionCall was executed and an
+ ASSERT() was triggered. If UnitTestStatus is UNIT_TEST_SKIPPED, then log a
+ warning message and return TRUE because ASSERT() macros are disabled. If
+ UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED, then log an error message and
+ return FALSE because an ASSERT() was expected when FunctionCall was executed,
+ but no ASSERT() conditions were triggered. The log messages contain
+ FunctionName, LineNumber, and FileName strings to provide the location of the
+ UT_EXPECT_ASSERT_FAILURE() macro.
+
+ @param[in] UnitTestStatus The status from UT_EXPECT_ASSERT_FAILURE() that
+ is either pass, skipped, or failed.
+ @param[in] FunctionName Null-terminated ASCII string of the function
+ executing the UT_EXPECT_ASSERT_FAILURE() macro.
+ @param[in] LineNumber The source file line number of the the function
+ executing the UT_EXPECT_ASSERT_FAILURE() macro.
+ @param[in] FileName Null-terminated ASCII string of the filename
+ executing the UT_EXPECT_ASSERT_FAILURE() macro.
+ @param[in] FunctionCall Null-terminated ASCII string of the function call
+ executed by the UT_EXPECT_ASSERT_FAILURE() macro.
+ @param[out] ResultStatus Used to return the UnitTestStatus value to the
+ caller of UT_EXPECT_ASSERT_FAILURE(). This is
+ optional parameter that may be NULL.
+
+ @retval TRUE UnitTestStatus is UNIT_TEST_PASSED.
+ @retval TRUE UnitTestStatus is UNIT_TEST_SKIPPED.
+ @retval FALSE UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED.
+**/
+BOOLEAN
+EFIAPI
+UnitTestExpectAssertFailure (
+ IN UNIT_TEST_STATUS UnitTestStatus,
+ IN CONST CHAR8 *FunctionName,
+ IN UINTN LineNumber,
+ IN CONST CHAR8 *FileName,
+ IN CONST CHAR8 *FunctionCall,
+ OUT UNIT_TEST_STATUS *ResultStatus OPTIONAL
+ )
+{
+ CHAR8 TempStr[MAX_STRING_SIZE];
+
+ if (ResultStatus != NULL) {
+ *ResultStatus = UnitTestStatus;
+ }
+ if (UnitTestStatus == UNIT_TEST_PASSED) {
+ UT_LOG_INFO (
+ "[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expected assert\n",
+ FileName,
+ LineNumber,
+ FunctionCall
+ );
+ }
+ if (UnitTestStatus == UNIT_TEST_SKIPPED) {
+ UT_LOG_WARNING (
+ "[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n",
+ FileName,
+ LineNumber,
+ FunctionCall
+ );
+ }
+ if (UnitTestStatus == UNIT_TEST_ERROR_TEST_FAILED) {
+ snprintf (TempStr, sizeof(TempStr), "UT_EXPECT_ASSERT_FAILURE(%s) did not trigger ASSERT()", FunctionCall);
+ _assert_true (FALSE, TempStr, FileName, (INT32)LineNumber);
+ }
+ return (UnitTestStatus != UNIT_TEST_ERROR_TEST_FAILED);
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c
new file mode 100644
index 00000000..a15694c7
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c
@@ -0,0 +1,200 @@
+/**
+ Implemnet UnitTestLib log services
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <PiDxe.h>
+#include <UnitTestFrameworkTypes.h>
+#include <Library/UnitTestLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PrintLib.h>
+#include <Library/PcdLib.h>
+
+#define UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH (512)
+#define UNIT_TEST_MAX_LOG_BUFFER SIZE_16KB
+
+struct _UNIT_TEST_LOG_PREFIX_STRING {
+ UNIT_TEST_STATUS LogLevel;
+ CHAR8 *String;
+};
+
+struct _UNIT_TEST_LOG_PREFIX_STRING mLogPrefixStrings[] = {
+ { UNIT_TEST_LOG_LEVEL_ERROR, "[ERROR] " },
+ { UNIT_TEST_LOG_LEVEL_WARN, "[WARNING] " },
+ { UNIT_TEST_LOG_LEVEL_INFO, "[INFO] " },
+ { UNIT_TEST_LOG_LEVEL_VERBOSE, "[VERBOSE] " }
+};
+
+//
+// Unit-Test Log helper functions
+//
+
+STATIC
+CONST CHAR8*
+GetStringForStatusLogPrefix (
+ IN UINTN LogLevel
+ )
+{
+ UINTN Index;
+ CHAR8 *Result;
+
+ Result = NULL;
+ for (Index = 0; Index < ARRAY_SIZE (mLogPrefixStrings); Index++) {
+ if (mLogPrefixStrings[Index].LogLevel == LogLevel) {
+ Result = mLogPrefixStrings[Index].String;
+ break;
+ }
+ }
+ return Result;
+}
+
+STATIC
+EFI_STATUS
+AddStringToUnitTestLog (
+ IN OUT UNIT_TEST *UnitTest,
+ IN CONST CHAR8 *String
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Make sure that you're cooking with gas.
+ //
+ if (UnitTest == NULL || String == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ // If this is the first log for the test allocate log space
+ if (UnitTest->Log == NULL) {
+ UnitTestLogInit (UnitTest, NULL, 0);
+ }
+
+ if (UnitTest->Log == NULL) {
+ DEBUG ((DEBUG_ERROR, "Failed to allocate space for unit test log\n"));
+ ASSERT (UnitTest->Log != NULL);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = AsciiStrnCatS (
+ UnitTest->Log,
+ UNIT_TEST_MAX_LOG_BUFFER / sizeof (CHAR8),
+ String,
+ UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH
+ );
+ if(EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to add unit test log string. Status = %r\n", Status));
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ This function is responsible for initializing the log buffer for a single test. It can
+ be used internally, but may also be consumed by the test framework to add pre-existing
+ data to a log before it's used.
+
+ @param[in,out] TestHandle A handle to the test being initialized.
+ @param[in] Buffer [Optional] A pointer to pre-existing log data that should
+ be used to initialize the log. Should include a NULL terminator.
+ @param[in] BufferSize [Optional] The size of the pre-existing log data.
+
+**/
+VOID
+EFIAPI
+UnitTestLogInit (
+ IN OUT UNIT_TEST *Test,
+ IN UINT8 *Buffer, OPTIONAL
+ IN UINTN BufferSize OPTIONAL
+ )
+{
+ //
+ // Make sure that you're cooking with gas.
+ //
+ if (Test == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a called with invalid Test parameter\n", __FUNCTION__));
+ return;
+ }
+
+ //
+ // If this is the first log for the test allocate log space
+ //
+ if (Test->Log == NULL) {
+ Test->Log = AllocateZeroPool (UNIT_TEST_MAX_LOG_BUFFER);
+ }
+
+ //
+ //check again to make sure allocate worked
+ //
+ if(Test->Log == NULL) {
+ DEBUG ((DEBUG_ERROR, "Failed to allocate memory for the log\n"));
+ return;
+ }
+
+ if((Buffer != NULL) && (BufferSize > 0) && (BufferSize <= UNIT_TEST_MAX_LOG_BUFFER)) {
+ CopyMem (Test->Log, Buffer, BufferSize);
+ }
+}
+
+/**
+ Test logging function that records a messages in the test framework log.
+ Record is associated with the currently executing test case.
+
+ @param[in] ErrorLevel The error level of the unit test log message.
+ @param[in] Format Formatting string following the format defined in the
+ MdePkg/Include/Library/PrintLib.h.
+ @param[in] ... Print args.
+**/
+VOID
+EFIAPI
+UnitTestLog (
+ IN UINTN ErrorLevel,
+ IN CONST CHAR8 *Format,
+ ...
+ )
+{
+ UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle;
+ CHAR8 NewFormatString[UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH];
+ CHAR8 LogString[UNIT_TEST_MAX_SINGLE_LOG_STRING_LENGTH];
+ CONST CHAR8 *LogTypePrefix;
+ VA_LIST Marker;
+
+ FrameworkHandle = GetActiveFrameworkHandle ();
+
+ LogTypePrefix = NULL;
+
+ //
+ // Make sure that this unit test log level is enabled.
+ //
+ if ((ErrorLevel & (UINTN)PcdGet32 (PcdUnitTestLogLevel)) == 0) {
+ return;
+ }
+
+ //
+ // If we need to define a new format string...
+ // well... get to it.
+ //
+ LogTypePrefix = GetStringForStatusLogPrefix (ErrorLevel);
+ if (LogTypePrefix != NULL) {
+ AsciiSPrint (NewFormatString, sizeof (NewFormatString), "%a%a", LogTypePrefix, Format);
+ } else {
+ AsciiStrCpyS (NewFormatString, sizeof (NewFormatString), Format);
+ }
+
+ //
+ // Convert the message to an ASCII String
+ //
+ VA_START (Marker, Format);
+ AsciiVSPrint (LogString, sizeof (LogString), NewFormatString, Marker);
+ VA_END (Marker);
+
+ //
+ // Finally, add the string to the log.
+ //
+ AddStringToUnitTestLog (((UNIT_TEST_FRAMEWORK *)FrameworkHandle)->CurrentTest, LogString);
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
new file mode 100644
index 00000000..672cca34
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
@@ -0,0 +1,186 @@
+/**
+ UnitTestLib APIs to run unit tests
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+#include <Library/UnitTestLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UnitTestResultReportLib.h>
+
+STATIC UNIT_TEST_FRAMEWORK_HANDLE mFrameworkHandle = NULL;
+
+BASE_LIBRARY_JUMP_BUFFER gUnitTestJumpBuffer;
+
+UNIT_TEST_FRAMEWORK_HANDLE
+GetActiveFrameworkHandle (
+ VOID
+ )
+{
+ ASSERT (mFrameworkHandle != NULL);
+ return mFrameworkHandle;
+}
+
+STATIC
+EFI_STATUS
+RunTestSuite (
+ IN UNIT_TEST_SUITE *Suite
+ )
+{
+ UNIT_TEST_LIST_ENTRY *TestEntry;
+ UNIT_TEST *Test;
+ UNIT_TEST_FRAMEWORK *ParentFramework;
+
+ if (Suite == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ TestEntry = NULL;
+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite->ParentFramework;
+
+ DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
+ DEBUG ((DEBUG_VERBOSE, "RUNNING TEST SUITE: %a\n", Suite->Title));
+ DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
+
+ if (Suite->Setup != NULL) {
+ Suite->Setup ();
+ }
+
+ //
+ // Iterate all tests within the suite
+ //
+ for (TestEntry = (UNIT_TEST_LIST_ENTRY *)GetFirstNode (&(Suite->TestCaseList));
+ (LIST_ENTRY*)TestEntry != &(Suite->TestCaseList);
+ TestEntry = (UNIT_TEST_LIST_ENTRY *)GetNextNode (&(Suite->TestCaseList), (LIST_ENTRY *)TestEntry)) {
+ Test = &TestEntry->UT;
+ ParentFramework->CurrentTest = Test;
+
+ DEBUG ((DEBUG_VERBOSE, "*********************************************************\n"));
+ DEBUG ((DEBUG_VERBOSE, " RUNNING TEST: %a:\n", Test->Description));
+ DEBUG ((DEBUG_VERBOSE, "**********************************************************\n"));
+
+ //
+ // First, check to see whether the test has already been run.
+ // NOTE: This would generally only be the case if a saved state was detected and loaded.
+ //
+ if (Test->Result != UNIT_TEST_PENDING && Test->Result != UNIT_TEST_RUNNING) {
+ DEBUG ((DEBUG_VERBOSE, "Test was run on a previous pass. Skipping.\n"));
+ ParentFramework->CurrentTest = NULL;
+ continue;
+ }
+
+ //
+ // Next, if we're still running, make sure that our test prerequisites are in place.
+ if (Test->Result == UNIT_TEST_PENDING && Test->Prerequisite != NULL) {
+ DEBUG ((DEBUG_VERBOSE, "PREREQ\n"));
+ if (SetJump (&gUnitTestJumpBuffer) == 0) {
+ if (Test->Prerequisite (Test->Context) != UNIT_TEST_PASSED) {
+ DEBUG ((DEBUG_ERROR, "Prerequisite Not Met\n"));
+ Test->Result = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
+ ParentFramework->CurrentTest = NULL;
+ continue;
+ }
+ } else {
+ DEBUG ((DEBUG_ERROR, "Prerequisite Not Met\n"));
+ Test->Result = UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
+ ParentFramework->CurrentTest = NULL;
+ continue;
+ }
+ }
+
+ //
+ // Now we should be ready to call the actual test.
+ // We set the status to UNIT_TEST_RUNNING in case the test needs to reboot
+ // or quit. The UNIT_TEST_RUNNING state will allow the test to resume
+ // but will prevent the Prerequisite from being dispatched a second time.
+ if (SetJump (&gUnitTestJumpBuffer) == 0) {
+ Test->Result = UNIT_TEST_RUNNING;
+ Test->Result = Test->RunTest (Test->Context);
+ } else {
+ Test->Result = UNIT_TEST_ERROR_TEST_FAILED;
+ }
+
+ //
+ // Finally, clean everything up, if need be.
+ if (Test->CleanUp != NULL) {
+ DEBUG ((DEBUG_VERBOSE, "CLEANUP\n"));
+ if (SetJump (&gUnitTestJumpBuffer) == 0) {
+ Test->CleanUp (Test->Context);
+ }
+ }
+
+ //
+ // End the test.
+ //
+ ParentFramework->CurrentTest = NULL;
+ }
+
+ if (Suite->Teardown != NULL) {
+ Suite->Teardown ();
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Execute all unit test cases in all unit test suites added to a Framework.
+
+ Once a unit test framework is initialized and all unit test suites and unit
+ test cases are registered, this function will cause the unit test framework to
+ dispatch all unit test cases in sequence and record the results for reporting.
+
+ @param[in] FrameworkHandle A handle to the current running framework that
+ dispatched the test. Necessary for recording
+ certain test events with the framework.
+
+ @retval EFI_SUCCESS All test cases were dispatched.
+ @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.
+**/
+EFI_STATUS
+EFIAPI
+RunAllTestSuites (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
+ )
+{
+ UNIT_TEST_FRAMEWORK *Framework;
+ UNIT_TEST_SUITE_LIST_ENTRY *Suite;
+ EFI_STATUS Status;
+
+ Framework = (UNIT_TEST_FRAMEWORK *)FrameworkHandle;
+ Suite = NULL;
+
+ if (Framework == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
+ DEBUG ((DEBUG_VERBOSE, "------------ RUNNING ALL TEST SUITES --------------\n"));
+ DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
+ mFrameworkHandle = FrameworkHandle;
+
+ //
+ // Iterate all suites
+ //
+ for (Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetFirstNode (&Framework->TestSuiteList);
+ (LIST_ENTRY *)Suite != &Framework->TestSuiteList;
+ Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite)) {
+ Status = RunTestSuite (&(Suite->UTS));
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Test Suite Failed with Error. %r\n", Status));
+ }
+ }
+
+ //
+ // Save current state so if test is started again it doesn't have to run. It will just report
+ //
+ SaveFrameworkState (NULL, 0);
+ OutputUnitTestFrameworkReport (FrameworkHandle);
+
+ mFrameworkHandle = NULL;
+
+ return EFI_SUCCESS;
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c
new file mode 100644
index 00000000..e3591e0b
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c
@@ -0,0 +1,277 @@
+/** @file
+ UnitTestLib APIs to run unit tests using cmocka
+
+ Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <Uefi.h>
+#include <UnitTestFrameworkTypes.h>
+#include <Library/UnitTestLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DebugLib.h>
+
+STATIC UNIT_TEST_FRAMEWORK_HANDLE mFrameworkHandle = NULL;
+
+UNIT_TEST_FRAMEWORK_HANDLE
+GetActiveFrameworkHandle (
+ VOID
+ )
+{
+ ASSERT (mFrameworkHandle != NULL);
+ return mFrameworkHandle;
+}
+
+//
+// The currently active test suite
+//
+UNIT_TEST_SUITE *mActiveUnitTestSuite = NULL;
+
+void
+CmockaUnitTestFunctionRunner (
+ void **state
+ )
+{
+ UNIT_TEST *UnitTest;
+ UNIT_TEST_SUITE *Suite;
+ UNIT_TEST_FRAMEWORK *Framework;
+
+ UnitTest = (UNIT_TEST *)(*state);
+ Suite = (UNIT_TEST_SUITE *)(UnitTest->ParentSuite);
+ Framework = (UNIT_TEST_FRAMEWORK *)(Suite->ParentFramework);
+
+ if (UnitTest->RunTest == NULL) {
+ UnitTest->Result = UNIT_TEST_SKIPPED;
+ } else {
+ UnitTest->Result = UNIT_TEST_RUNNING;
+ Framework->CurrentTest = UnitTest;
+ UnitTest->Result = UnitTest->RunTest (UnitTest->Context);
+ Framework->CurrentTest = NULL;
+ }
+}
+
+int
+CmockaUnitTestSetupFunctionRunner (
+ void **state
+ )
+{
+ UNIT_TEST *UnitTest;
+ UNIT_TEST_SUITE *Suite;
+ UNIT_TEST_FRAMEWORK *Framework;
+ UNIT_TEST_STATUS Result;
+
+ UnitTest = (UNIT_TEST *)(*state);
+ Suite = (UNIT_TEST_SUITE *)(UnitTest->ParentSuite);
+ Framework = (UNIT_TEST_FRAMEWORK *)(Suite->ParentFramework);
+
+ if (UnitTest->Prerequisite == NULL) {
+ return 0;
+ }
+
+ Framework->CurrentTest = UnitTest;
+ Result = UnitTest->Prerequisite (UnitTest->Context);
+ Framework->CurrentTest = NULL;
+
+ //
+ // Return 0 for success. Non-zero for error.
+ //
+ return (int)Result;
+}
+
+int
+CmockaUnitTestTeardownFunctionRunner (
+ void **state
+ )
+{
+ UNIT_TEST *UnitTest;
+ UNIT_TEST_SUITE *Suite;
+ UNIT_TEST_FRAMEWORK *Framework;
+
+ UnitTest = (UNIT_TEST *)(*state);
+ Suite = (UNIT_TEST_SUITE *)(UnitTest->ParentSuite);
+ Framework = (UNIT_TEST_FRAMEWORK *)(Suite->ParentFramework);
+
+ if (UnitTest->CleanUp != NULL) {
+ Framework->CurrentTest = UnitTest;
+ UnitTest->CleanUp (UnitTest->Context);
+ Framework->CurrentTest = NULL;
+ }
+
+ //
+ // Print out the log messages - This is a partial solution as it
+ // does not get the log into the XML. Need cmocka changes to support
+ // stdout and stderr in their xml format
+ //
+ if (UnitTest->Log != NULL) {
+ print_message("UnitTest: %s - %s\n", UnitTest->Name, UnitTest->Description);
+ print_message("Log Output Start\n");
+ print_message("%s", UnitTest->Log);
+ print_message("Log Output End\n");
+ }
+
+ //
+ // Return 0 for success. Non-zero for error.
+ //
+ return 0;
+}
+
+int
+CmockaUnitTestSuiteSetupFunctionRunner (
+ void **state
+ )
+{
+ if (mActiveUnitTestSuite == NULL) {
+ return -1;
+ }
+ if (mActiveUnitTestSuite->Setup == NULL) {
+ return 0;
+ }
+
+ mActiveUnitTestSuite->Setup ();
+ //
+ // Always succeed
+ //
+ return 0;
+}
+
+int
+CmockaUnitTestSuiteTeardownFunctionRunner (
+ void **state
+ )
+{
+ if (mActiveUnitTestSuite == NULL) {
+ return -1;
+ }
+ if (mActiveUnitTestSuite->Teardown == NULL) {
+ return 0;
+ }
+
+ mActiveUnitTestSuite->Teardown ();
+ //
+ // Always succeed
+ //
+ return 0;
+}
+
+STATIC
+EFI_STATUS
+RunTestSuite (
+ IN UNIT_TEST_SUITE *Suite
+ )
+{
+ UNIT_TEST_LIST_ENTRY *TestEntry;
+ UNIT_TEST *UnitTest;
+ struct CMUnitTest *Tests;
+ UINTN Index;
+
+ TestEntry = NULL;
+
+ if (Suite == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
+ DEBUG ((DEBUG_VERBOSE, "RUNNING TEST SUITE: %a\n", Suite->Title));
+ DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
+
+ //
+ // Allocate buffer of CMUnitTest entries
+ //
+ Tests = AllocateZeroPool (Suite->NumTests * sizeof (struct CMUnitTest));
+ ASSERT (Tests != NULL);
+
+ //
+ // Populate buffer of CMUnitTest entries
+ //
+ Index = 0;
+ for (TestEntry = (UNIT_TEST_LIST_ENTRY *)GetFirstNode (&(Suite->TestCaseList));
+ (LIST_ENTRY *)TestEntry != &(Suite->TestCaseList);
+ TestEntry = (UNIT_TEST_LIST_ENTRY *)GetNextNode (&(Suite->TestCaseList), (LIST_ENTRY *)TestEntry)) {
+ UnitTest = &TestEntry->UT;
+ Tests[Index].name = UnitTest->Description;
+ Tests[Index].test_func = CmockaUnitTestFunctionRunner;
+ Tests[Index].setup_func = CmockaUnitTestSetupFunctionRunner;
+ Tests[Index].teardown_func = CmockaUnitTestTeardownFunctionRunner;
+ Tests[Index].initial_state = UnitTest;
+ Index++;
+ }
+ ASSERT (Index == Suite->NumTests);
+
+ //
+ // Run all unit tests in a test suite
+ //
+ mActiveUnitTestSuite = Suite;
+ _cmocka_run_group_tests (
+ Suite->Title,
+ Tests,
+ Suite->NumTests,
+ CmockaUnitTestSuiteSetupFunctionRunner,
+ CmockaUnitTestSuiteTeardownFunctionRunner
+ );
+ mActiveUnitTestSuite = NULL;
+ FreePool (Tests);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Execute all unit test cases in all unit test suites added to a Framework.
+
+ Once a unit test framework is initialized and all unit test suites and unit
+ test cases are registered, this function will cause the unit test framework to
+ dispatch all unit test cases in sequence and record the results for reporting.
+
+ @param[in] FrameworkHandle A handle to the current running framework that
+ dispatched the test. Necessary for recording
+ certain test events with the framework.
+
+ @retval EFI_SUCCESS All test cases were dispatched.
+ @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.
+**/
+EFI_STATUS
+EFIAPI
+RunAllTestSuites (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
+ )
+{
+ UNIT_TEST_FRAMEWORK *Framework;
+ UNIT_TEST_SUITE_LIST_ENTRY *Suite;
+ EFI_STATUS Status;
+
+ Framework = (UNIT_TEST_FRAMEWORK *)FrameworkHandle;
+ Suite = NULL;
+
+ if (Framework == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ DEBUG((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
+ DEBUG((DEBUG_VERBOSE, "------------ RUNNING ALL TEST SUITES --------------\n"));
+ DEBUG((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
+ mFrameworkHandle = FrameworkHandle;
+
+ //
+ // Iterate all suites
+ //
+ for (Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetFirstNode (&Framework->TestSuiteList);
+ (LIST_ENTRY *)Suite != &Framework->TestSuiteList;
+ Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite)) {
+ Status = RunTestSuite (&(Suite->UTS));
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Test Suite Failed with Error. %r\n", Status));
+ }
+ }
+
+ mFrameworkHandle = NULL;
+
+ return EFI_SUCCESS;
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
new file mode 100644
index 00000000..a240de55
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
@@ -0,0 +1,856 @@
+/**
+ Implement UnitTestLib
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+#include <Library/UnitTestLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UnitTestPersistenceLib.h>
+#include <Library/UnitTestResultReportLib.h>
+
+///
+/// Forward declaration of prototype
+///
+STATIC
+VOID
+UpdateTestFromSave (
+ IN OUT UNIT_TEST *Test,
+ IN UNIT_TEST_SAVE_HEADER *SavedState
+ );
+
+/**
+ This function will determine whether the short name violates any rules that would
+ prevent it from being used as a reporting name or as a serialization name.
+
+ Example: If the name cannot be serialized to a filesystem file name.
+
+ @param[in] ShortTitleString A pointer to the short title string to be evaluated.
+
+ @retval TRUE The string is acceptable.
+ @retval FALSE The string should not be used.
+
+**/
+STATIC
+BOOLEAN
+IsFrameworkShortNameValid (
+ IN CHAR8 *ShortTitleString
+ )
+{
+ // TODO: Finish this function.
+ return TRUE;
+}
+
+STATIC
+CHAR8*
+AllocateAndCopyString (
+ IN CHAR8 *StringToCopy
+ )
+{
+ CHAR8 *NewString;
+ UINTN NewStringLength;
+
+ NewString = NULL;
+ NewStringLength = AsciiStrnLenS (StringToCopy, UNIT_TEST_MAX_STRING_LENGTH) + 1;
+ NewString = AllocatePool (NewStringLength * sizeof( CHAR8 ));
+ if (NewString != NULL) {
+ AsciiStrCpyS (NewString, NewStringLength, StringToCopy);
+ }
+ return NewString;
+}
+
+STATIC
+VOID
+SetFrameworkFingerprint (
+ OUT UINT8 *Fingerprint,
+ IN UNIT_TEST_FRAMEWORK *Framework
+ )
+{
+ UINT32 NewFingerprint;
+
+ // For this one we'll just use the title and version as the unique fingerprint.
+ NewFingerprint = CalculateCrc32( Framework->Title, (AsciiStrLen( Framework->Title ) * sizeof( CHAR8 )) );
+ NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Framework->VersionString, (AsciiStrLen( Framework->VersionString ) * sizeof( CHAR8 )) );
+
+ CopyMem( Fingerprint, &NewFingerprint, UNIT_TEST_FINGERPRINT_SIZE );
+ return;
+}
+
+STATIC
+VOID
+SetSuiteFingerprint (
+ OUT UINT8 *Fingerprint,
+ IN UNIT_TEST_FRAMEWORK *Framework,
+ IN UNIT_TEST_SUITE *Suite
+ )
+{
+ UINT32 NewFingerprint;
+
+ // For this one, we'll use the fingerprint from the framework, and the title of the suite.
+ NewFingerprint = CalculateCrc32( &Framework->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE );
+ NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Suite->Title, (AsciiStrLen( Suite->Title ) * sizeof( CHAR8 )) );
+ NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Suite->Name, (AsciiStrLen(Suite->Name) * sizeof(CHAR8)) );
+
+ CopyMem( Fingerprint, &NewFingerprint, UNIT_TEST_FINGERPRINT_SIZE );
+ return;
+}
+
+STATIC
+VOID
+SetTestFingerprint (
+ OUT UINT8 *Fingerprint,
+ IN UNIT_TEST_SUITE *Suite,
+ IN UNIT_TEST *Test
+ )
+{
+ UINT32 NewFingerprint;
+
+ // For this one, we'll use the fingerprint from the suite, and the description and classname of the test.
+ NewFingerprint = CalculateCrc32( &Suite->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE );
+ NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Test->Description, (AsciiStrLen( Test->Description ) * sizeof( CHAR8 )) );
+ NewFingerprint = (NewFingerprint >> 8) ^ CalculateCrc32( Test->Name, (AsciiStrLen(Test->Name) * sizeof(CHAR8)) );
+
+ CopyMem( Fingerprint, &NewFingerprint, UNIT_TEST_FINGERPRINT_SIZE );
+ return;
+}
+
+STATIC
+BOOLEAN
+CompareFingerprints (
+ IN UINT8 *FingerprintA,
+ IN UINT8 *FingerprintB
+ )
+{
+ return (CompareMem( FingerprintA, FingerprintB, UNIT_TEST_FINGERPRINT_SIZE ) == 0);
+}
+
+/**
+ Cleanup a test framework.
+
+ After tests are run, this will teardown the entire framework and free all
+ allocated data within.
+
+ @param[in] FrameworkHandle A handle to the current running framework that
+ dispatched the test. Necessary for recording
+ certain test events with the framework.
+
+ @retval EFI_SUCCESS All resources associated with framework were
+ freed.
+ @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.
+**/
+EFI_STATUS
+EFIAPI
+FreeUnitTestFramework (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
+ )
+{
+ // TODO: Finish this function.
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+FreeUnitTestSuiteEntry (
+ IN UNIT_TEST_SUITE_LIST_ENTRY *SuiteEntry
+ )
+{
+ // TODO: Finish this function.
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+FreeUnitTestTestEntry (
+ IN UNIT_TEST_LIST_ENTRY *TestEntry
+ )
+{
+ // TODO: Finish this function.
+ return EFI_SUCCESS;
+}
+
+/**
+ Method to Initialize the Unit Test framework. This function registers the
+ test name and also initializes the internal state of the test framework to
+ receive any new suites and tests.
+
+ @param[out] FrameworkHandle Unit test framework to be created.
+ @param[in] Title Null-terminated ASCII string that is the user
+ friendly name of the framework. String is
+ copied.
+ @param[in] ShortTitle Null-terminated ASCII short string that is the
+ short name of the framework with no spaces.
+ String is copied.
+ @param[in] VersionString Null-terminated ASCII version string for the
+ framework. String is copied.
+
+ @retval EFI_SUCCESS The unit test framework was initialized.
+ @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.
+ @retval EFI_INVALID_PARAMETER Title is NULL.
+ @retval EFI_INVALID_PARAMETER ShortTitle is NULL.
+ @retval EFI_INVALID_PARAMETER VersionString is NULL.
+ @retval EFI_INVALID_PARAMETER ShortTitle is invalid.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
+ initialize the unit test framework.
+**/
+EFI_STATUS
+EFIAPI
+InitUnitTestFramework (
+ OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle,
+ IN CHAR8 *Title,
+ IN CHAR8 *ShortTitle,
+ IN CHAR8 *VersionString
+ )
+{
+ EFI_STATUS Status;
+ UNIT_TEST_FRAMEWORK_HANDLE NewFrameworkHandle;
+ UNIT_TEST_FRAMEWORK *NewFramework;
+
+ Status = EFI_SUCCESS;
+ NewFramework = NULL;
+
+ //
+ // First, check all pointers and make sure nothing's broked.
+ //
+ if (FrameworkHandle == NULL || Title == NULL ||
+ ShortTitle == NULL || VersionString == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Next, determine whether all of the strings are good to use.
+ //
+ if (!IsFrameworkShortNameValid (ShortTitle)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Next, set aside some space to start messing with the framework.
+ //
+ NewFramework = AllocateZeroPool (sizeof (UNIT_TEST_FRAMEWORK));
+ if (NewFramework == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Next, set up all the test data.
+ //
+ NewFrameworkHandle = (UNIT_TEST_FRAMEWORK_HANDLE)NewFramework;
+ NewFramework->Title = AllocateAndCopyString (Title);
+ NewFramework->ShortTitle = AllocateAndCopyString (ShortTitle);
+ NewFramework->VersionString = AllocateAndCopyString (VersionString);
+ NewFramework->Log = NULL;
+ NewFramework->CurrentTest = NULL;
+ NewFramework->SavedState = NULL;
+ if (NewFramework->Title == NULL ||
+ NewFramework->ShortTitle == NULL ||
+ NewFramework->VersionString == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Exit;
+ }
+ InitializeListHead (&(NewFramework->TestSuiteList));
+
+ //
+ // Create the framework fingerprint.
+ //
+ SetFrameworkFingerprint (&NewFramework->Fingerprint[0], NewFramework);
+
+ //
+ // If there is a persisted context, load it now.
+ //
+ if (DoesCacheExist (NewFrameworkHandle)) {
+ Status = LoadUnitTestCache (NewFrameworkHandle, (UNIT_TEST_SAVE_HEADER**)(&NewFramework->SavedState));
+ if (EFI_ERROR (Status)) {
+ //
+ // Don't actually report it as an error, but emit a warning.
+ //
+ DEBUG (( DEBUG_ERROR, "%a - Cache was detected, but failed to load.\n", __FUNCTION__ ));
+ Status = EFI_SUCCESS;
+ }
+ }
+
+Exit:
+ //
+ // If we're good, then let's copy the framework.
+ //
+ if (!EFI_ERROR (Status)) {
+ *FrameworkHandle = NewFrameworkHandle;
+ } else {
+ //
+ // Otherwise, we need to undo this horrible thing that we've done.
+ //
+ FreeUnitTestFramework (NewFrameworkHandle);
+ }
+
+ return Status;
+}
+
+/**
+ Registers a Unit Test Suite in the Unit Test Framework.
+ At least one test suite must be registered, because all test cases must be
+ within a unit test suite.
+
+ @param[out] SuiteHandle Unit test suite to create
+ @param[in] FrameworkHandle Unit test framework to add unit test suite to
+ @param[in] Title Null-terminated ASCII string that is the user
+ friendly name of the test suite. String is
+ copied.
+ @param[in] Name Null-terminated ASCII string that is the short
+ name of the test suite with no spaces. String
+ is copied.
+ @param[in] Setup Setup function, runs before suite. This is an
+ optional parameter that may be NULL.
+ @param[in] Teardown Teardown function, runs after suite. This is an
+ optional parameter that may be NULL.
+
+ @retval EFI_SUCCESS The unit test suite was created.
+ @retval EFI_INVALID_PARAMETER SuiteHandle is NULL.
+ @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.
+ @retval EFI_INVALID_PARAMETER Title is NULL.
+ @retval EFI_INVALID_PARAMETER Name is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
+ initialize the unit test suite.
+**/
+EFI_STATUS
+EFIAPI
+CreateUnitTestSuite (
+ OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle,
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
+ IN CHAR8 *Title,
+ IN CHAR8 *Name,
+ IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL,
+ IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL
+ )
+{
+ EFI_STATUS Status;
+ UNIT_TEST_SUITE_LIST_ENTRY *NewSuiteEntry;
+ UNIT_TEST_FRAMEWORK *Framework;
+
+ Status = EFI_SUCCESS;
+ Framework = (UNIT_TEST_FRAMEWORK *)FrameworkHandle;
+
+ //
+ // First, let's check to make sure that our parameters look good.
+ //
+ if ((SuiteHandle == NULL) || (Framework == NULL) || (Title == NULL) || (Name == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Create the new entry.
+ //
+ NewSuiteEntry = AllocateZeroPool (sizeof (UNIT_TEST_SUITE_LIST_ENTRY));
+ if (NewSuiteEntry == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Copy the fields we think we need.
+ //
+ NewSuiteEntry->UTS.NumTests = 0;
+ NewSuiteEntry->UTS.Title = AllocateAndCopyString (Title);
+ NewSuiteEntry->UTS.Name = AllocateAndCopyString (Name);
+ NewSuiteEntry->UTS.Setup = Setup;
+ NewSuiteEntry->UTS.Teardown = Teardown;
+ NewSuiteEntry->UTS.ParentFramework = FrameworkHandle;
+ InitializeListHead (&(NewSuiteEntry->Entry)); // List entry for sibling suites.
+ InitializeListHead (&(NewSuiteEntry->UTS.TestCaseList)); // List entry for child tests.
+ if (NewSuiteEntry->UTS.Title == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Exit;
+ }
+
+ if (NewSuiteEntry->UTS.Name == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Exit;
+ }
+
+ //
+ // Create the suite fingerprint.
+ //
+ SetSuiteFingerprint( &NewSuiteEntry->UTS.Fingerprint[0], Framework, &NewSuiteEntry->UTS );
+
+Exit:
+ //
+ // If everything is going well, add the new suite to the tail list for the framework.
+ //
+ if (!EFI_ERROR( Status )) {
+ InsertTailList (&(Framework->TestSuiteList), (LIST_ENTRY *)NewSuiteEntry);
+ *SuiteHandle = (UNIT_TEST_SUITE_HANDLE)(&NewSuiteEntry->UTS);
+ } else {
+ //
+ // Otherwise, make with the destruction.
+ //
+ FreeUnitTestSuiteEntry (NewSuiteEntry);
+ }
+
+ return Status;
+}
+
+/**
+ Adds test case to Suite
+
+ @param[in] SuiteHandle Unit test suite to add test to.
+ @param[in] Description Null-terminated ASCII string that is the user
+ friendly description of a test. String is copied.
+ @param[in] Name Null-terminated ASCII string that is the short name
+ of the test with no spaces. String is copied.
+ @param[in] Function Unit test function.
+ @param[in] Prerequisite Prerequisite function, runs before test. This is
+ an optional parameter that may be NULL.
+ @param[in] CleanUp Clean up function, runs after test. This is an
+ optional parameter that may be NULL.
+ @param[in] Context Pointer to context. This is an optional parameter
+ that may be NULL.
+
+ @retval EFI_SUCCESS The unit test case was added to Suite.
+ @retval EFI_INVALID_PARAMETER SuiteHandle is NULL.
+ @retval EFI_INVALID_PARAMETER Description is NULL.
+ @retval EFI_INVALID_PARAMETER Name is NULL.
+ @retval EFI_INVALID_PARAMETER Function is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
+ add the unit test case to Suite.
+**/
+EFI_STATUS
+EFIAPI
+AddTestCase (
+ IN UNIT_TEST_SUITE_HANDLE SuiteHandle,
+ IN CHAR8 *Description,
+ IN CHAR8 *Name,
+ IN UNIT_TEST_FUNCTION Function,
+ IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL,
+ IN UNIT_TEST_CLEANUP CleanUp OPTIONAL,
+ IN UNIT_TEST_CONTEXT Context OPTIONAL
+ )
+{
+ EFI_STATUS Status;
+ UNIT_TEST_LIST_ENTRY *NewTestEntry;
+ UNIT_TEST_FRAMEWORK *ParentFramework;
+ UNIT_TEST_SUITE *Suite;
+
+ Status = EFI_SUCCESS;
+ Suite = (UNIT_TEST_SUITE *)SuiteHandle;
+
+ //
+ // First, let's check to make sure that our parameters look good.
+ //
+ if ((Suite == NULL) || (Description == NULL) || (Name == NULL) || (Function == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite->ParentFramework;
+ //
+ // Create the new entry.
+ NewTestEntry = AllocateZeroPool (sizeof( UNIT_TEST_LIST_ENTRY ));
+ if (NewTestEntry == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Copy the fields we think we need.
+ NewTestEntry->UT.Description = AllocateAndCopyString (Description);
+ NewTestEntry->UT.Name = AllocateAndCopyString (Name);
+ NewTestEntry->UT.FailureType = FAILURETYPE_NOFAILURE;
+ NewTestEntry->UT.FailureMessage[0] = '\0';
+ NewTestEntry->UT.Log = NULL;
+ NewTestEntry->UT.Prerequisite = Prerequisite;
+ NewTestEntry->UT.CleanUp = CleanUp;
+ NewTestEntry->UT.RunTest = Function;
+ NewTestEntry->UT.Context = Context;
+ NewTestEntry->UT.Result = UNIT_TEST_PENDING;
+ NewTestEntry->UT.ParentSuite = SuiteHandle;
+ InitializeListHead (&(NewTestEntry->Entry)); // List entry for sibling tests.
+ if (NewTestEntry->UT.Description == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Exit;
+ }
+ if (NewTestEntry->UT.Name == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Exit;
+ }
+
+ //
+ // Create the test fingerprint.
+ //
+ SetTestFingerprint (&NewTestEntry->UT.Fingerprint[0], Suite, &NewTestEntry->UT);
+
+ // TODO: Make sure that duplicate fingerprints cannot be created.
+
+ //
+ // If there is saved test data, update this record.
+ //
+ if (ParentFramework->SavedState != NULL) {
+ UpdateTestFromSave (&NewTestEntry->UT, ParentFramework->SavedState);
+ }
+
+Exit:
+ //
+ // If everything is going well, add the new suite to the tail list for the framework.
+ //
+ if (!EFI_ERROR (Status)) {
+ InsertTailList (&(Suite->TestCaseList), (LIST_ENTRY*)NewTestEntry);
+ Suite->NumTests++;
+ } else {
+ //
+ // Otherwise, make with the destruction.
+ //
+ FreeUnitTestTestEntry (NewTestEntry);
+ }
+
+ return Status;
+}
+
+STATIC
+VOID
+UpdateTestFromSave (
+ IN OUT UNIT_TEST *Test,
+ IN UNIT_TEST_SAVE_HEADER *SavedState
+ )
+{
+ UNIT_TEST_SAVE_TEST *CurrentTest;
+ UNIT_TEST_SAVE_TEST *MatchingTest;
+ UINT8 *FloatingPointer;
+ UNIT_TEST_SAVE_CONTEXT *SavedContext;
+ UINTN Index;
+
+ //
+ // First, evaluate the inputs.
+ //
+ if (Test == NULL || SavedState == NULL) {
+ return;
+ }
+ if (SavedState->TestCount == 0) {
+ return;
+ }
+
+ //
+ // Next, determine whether a matching test can be found.
+ // Start at the beginning.
+ //
+ MatchingTest = NULL;
+ FloatingPointer = (UINT8 *)SavedState + sizeof (*SavedState);
+ for (Index = 0; Index < SavedState->TestCount; Index++) {
+ CurrentTest = (UNIT_TEST_SAVE_TEST *)FloatingPointer;
+ if (CompareFingerprints (&Test->Fingerprint[0], &CurrentTest->Fingerprint[0])) {
+ MatchingTest = CurrentTest;
+ //
+ // If there's a saved context, it's important that we iterate through the entire list.
+ //
+ if (!SavedState->HasSavedContext) {
+ break;
+ }
+ }
+
+ //
+ // If we didn't find it, we have to increment to the next test.
+ //
+ FloatingPointer = (UINT8 *)CurrentTest + CurrentTest->Size;
+ }
+
+ //
+ // If a matching test was found, copy the status.
+ //
+ if (MatchingTest) {
+ //
+ // Override the test status with the saved status.
+ //
+ Test->Result = MatchingTest->Result;
+
+ Test->FailureType = MatchingTest->FailureType;
+ AsciiStrnCpyS (
+ &Test->FailureMessage[0],
+ UNIT_TEST_TESTFAILUREMSG_LENGTH,
+ &MatchingTest->FailureMessage[0],
+ UNIT_TEST_TESTFAILUREMSG_LENGTH
+ );
+
+ //
+ // If there is a log string associated, grab that.
+ // We can tell that there's a log string because the "size" will be larger than
+ // the structure size.
+ // IMPORTANT NOTE: There are security implications here.
+ // This data is user-supplied and we're about to play kinda
+ // fast and loose with data buffers.
+ //
+ if (MatchingTest->Size > sizeof (UNIT_TEST_SAVE_TEST)) {
+ UnitTestLogInit (Test, (UINT8 *)MatchingTest->Log, MatchingTest->Size - sizeof (UNIT_TEST_SAVE_TEST));
+ }
+ }
+
+ //
+ // If the saved context exists and matches this test, grab it, too.
+ //
+ if (SavedState->HasSavedContext) {
+ //
+ // If there was a saved context, the "matching test" loop will have placed the FloatingPointer
+ // at the beginning of the context structure.
+ //
+ SavedContext = (UNIT_TEST_SAVE_CONTEXT *)FloatingPointer;
+ if ((SavedContext->Size - sizeof (UNIT_TEST_SAVE_CONTEXT)) > 0 &&
+ CompareFingerprints (&Test->Fingerprint[0], &SavedContext->Fingerprint[0])) {
+ //
+ // Override the test context with the saved context.
+ //
+ Test->Context = (VOID*)SavedContext->Data;
+ }
+ }
+}
+
+STATIC
+UNIT_TEST_SAVE_HEADER*
+SerializeState (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
+ IN UNIT_TEST_CONTEXT ContextToSave, OPTIONAL
+ IN UINTN ContextToSaveSize
+ )
+{
+ UNIT_TEST_FRAMEWORK *Framework;
+ UNIT_TEST_SAVE_HEADER *Header;
+ LIST_ENTRY *SuiteListHead;
+ LIST_ENTRY *Suite;
+ LIST_ENTRY *TestListHead;
+ LIST_ENTRY *Test;
+ UINT32 TestCount;
+ UINT32 TotalSize;
+ UINTN LogSize;
+ UNIT_TEST_SAVE_TEST *TestSaveData;
+ UNIT_TEST_SAVE_CONTEXT *TestSaveContext;
+ UNIT_TEST *UnitTest;
+ UINT8 *FloatingPointer;
+
+ Framework = (UNIT_TEST_FRAMEWORK *)FrameworkHandle;
+ Header = NULL;
+
+ //
+ // First, let's not make assumptions about the parameters.
+ //
+ if (Framework == NULL ||
+ (ContextToSave != NULL && ContextToSaveSize == 0) ||
+ ContextToSaveSize > MAX_UINT32) {
+ return NULL;
+ }
+
+ //
+ // Next, we've gotta figure out the resources that will be required to serialize the
+ // the framework state so that we can persist it.
+ // To start with, we're gonna need a header.
+ //
+ TotalSize = sizeof (UNIT_TEST_SAVE_HEADER);
+ //
+ // Now we need to figure out how many tests there are.
+ //
+ TestCount = 0;
+ //
+ // Iterate all suites.
+ //
+ SuiteListHead = &Framework->TestSuiteList;
+ for (Suite = GetFirstNode (SuiteListHead); Suite != SuiteListHead; Suite = GetNextNode (SuiteListHead, Suite)) {
+ //
+ // Iterate all tests within the suite.
+ //
+ TestListHead = &((UNIT_TEST_SUITE_LIST_ENTRY *)Suite)->UTS.TestCaseList;
+ for (Test = GetFirstNode (TestListHead); Test != TestListHead; Test = GetNextNode (TestListHead, Test)) {
+ UnitTest = &((UNIT_TEST_LIST_ENTRY *)Test)->UT;
+ //
+ // Account for the size of a test structure.
+ //
+ TotalSize += sizeof( UNIT_TEST_SAVE_TEST );
+ //
+ // If there's a log, make sure to account for the log size.
+ //
+ if (UnitTest->Log != NULL) {
+ //
+ // The +1 is for the NULL character. Can't forget the NULL character.
+ //
+ LogSize = (AsciiStrLen (UnitTest->Log) + 1) * sizeof (CHAR8);
+ ASSERT (LogSize < MAX_UINT32);
+ TotalSize += (UINT32)LogSize;
+ }
+ //
+ // Increment the test count.
+ //
+ TestCount++;
+ }
+ }
+ //
+ // If there are no tests, we're done here.
+ //
+ if (TestCount == 0) {
+ return NULL;
+ }
+ //
+ // Add room for the context, if there is one.
+ //
+ if (ContextToSave != NULL) {
+ TotalSize += sizeof (UNIT_TEST_SAVE_CONTEXT) + (UINT32)ContextToSaveSize;
+ }
+
+ //
+ // Now that we know the size, we need to allocate space for the serialized output.
+ //
+ Header = AllocateZeroPool (TotalSize);
+ if (Header == NULL) {
+ return NULL;
+ }
+
+ //
+ // Alright, let's start setting up some data.
+ //
+ Header->Version = UNIT_TEST_PERSISTENCE_LIB_VERSION;
+ Header->SaveStateSize = TotalSize;
+ CopyMem (&Header->Fingerprint[0], &Framework->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE);
+ CopyMem (&Header->StartTime, &Framework->StartTime, sizeof (EFI_TIME));
+ Header->TestCount = TestCount;
+ Header->HasSavedContext = FALSE;
+
+ //
+ // Start adding all of the test cases.
+ // Set the floating pointer to the start of the current test save buffer.
+ //
+ FloatingPointer = (UINT8*)Header + sizeof( UNIT_TEST_SAVE_HEADER );
+ //
+ // Iterate all suites.
+ //
+ SuiteListHead = &Framework->TestSuiteList;
+ for (Suite = GetFirstNode (SuiteListHead); Suite != SuiteListHead; Suite = GetNextNode (SuiteListHead, Suite)) {
+ //
+ // Iterate all tests within the suite.
+ //
+ TestListHead = &((UNIT_TEST_SUITE_LIST_ENTRY *)Suite)->UTS.TestCaseList;
+ for (Test = GetFirstNode (TestListHead); Test != TestListHead; Test = GetNextNode (TestListHead, Test)) {
+ TestSaveData = (UNIT_TEST_SAVE_TEST *)FloatingPointer;
+ UnitTest = &((UNIT_TEST_LIST_ENTRY *)Test)->UT;
+
+ //
+ // Save the fingerprint.
+ //
+ CopyMem (&TestSaveData->Fingerprint[0], &UnitTest->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE);
+
+ //
+ // Save the result.
+ //
+ TestSaveData->Result = UnitTest->Result;
+ TestSaveData->FailureType = UnitTest->FailureType;
+ AsciiStrnCpyS (&TestSaveData->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH, &UnitTest->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH);
+
+
+ //
+ // If there is a log, save the log.
+ //
+ FloatingPointer += sizeof (UNIT_TEST_SAVE_TEST);
+ if (UnitTest->Log != NULL) {
+ //
+ // The +1 is for the NULL character. Can't forget the NULL character.
+ //
+ LogSize = (AsciiStrLen (UnitTest->Log) + 1) * sizeof (CHAR8);
+ CopyMem (FloatingPointer, UnitTest->Log, LogSize);
+ FloatingPointer += LogSize;
+ }
+
+ //
+ // Update the size once the structure is complete.
+ // NOTE: Should this be a straight cast without validation?
+ //
+ TestSaveData->Size = (UINT32)(FloatingPointer - (UINT8 *)TestSaveData);
+ }
+ }
+
+ //
+ // If there is a context to save, let's do that now.
+ //
+ if (ContextToSave != NULL && Framework->CurrentTest != NULL) {
+ TestSaveContext = (UNIT_TEST_SAVE_CONTEXT*)FloatingPointer;
+ TestSaveContext->Size = (UINT32)ContextToSaveSize + sizeof (UNIT_TEST_SAVE_CONTEXT);
+ CopyMem (&TestSaveContext->Fingerprint[0], &Framework->CurrentTest->Fingerprint[0], UNIT_TEST_FINGERPRINT_SIZE);
+ CopyMem (((UINT8 *)TestSaveContext + sizeof (UNIT_TEST_SAVE_CONTEXT)), ContextToSave, ContextToSaveSize);
+ Header->HasSavedContext = TRUE;
+ }
+
+ return Header;
+}
+
+/**
+ Leverages a framework-specific mechanism (see UnitTestPersistenceLib if you're
+ a framework author) to save the state of the executing framework along with
+ any allocated data so that the test may be resumed upon reentry. A test case
+ should pass any needed context (which, to prevent an infinite loop, should be
+ at least the current execution count) which will be saved by the framework and
+ passed to the test case upon resume.
+
+ This should be called while the current test framework is valid and active. It is
+ generally called from within a test case prior to quitting or rebooting.
+
+ @param[in] ContextToSave A buffer of test case-specific data to be saved
+ along with framework state. Will be passed as
+ "Context" to the test case upon resume. This
+ is an optional parameter that may be NULL.
+ @param[in] ContextToSaveSize Size of the ContextToSave buffer.
+
+ @retval EFI_SUCCESS The framework state and context were saved.
+ @retval EFI_NOT_FOUND An active framework handle was not found.
+ @retval EFI_INVALID_PARAMETER ContextToSave is not NULL and
+ ContextToSaveSize is 0.
+ @retval EFI_INVALID_PARAMETER ContextToSave is >= 4GB.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
+ save the framework and context state.
+ @retval EFI_DEVICE_ERROR The framework and context state could not be
+ saved to a persistent storage device due to a
+ device error.
+**/
+EFI_STATUS
+EFIAPI
+SaveFrameworkState (
+ IN UNIT_TEST_CONTEXT ContextToSave OPTIONAL,
+ IN UINTN ContextToSaveSize
+ )
+{
+ EFI_STATUS Status;
+ UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle;
+ UNIT_TEST_SAVE_HEADER *Header;
+
+ Header = NULL;
+ FrameworkHandle = GetActiveFrameworkHandle ();
+
+ //
+ // Return a unique error code if the framework is not set.
+ //
+ if (FrameworkHandle == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // First, let's not make assumptions about the parameters.
+ //
+ if ((ContextToSave != NULL && ContextToSaveSize == 0) ||
+ ContextToSaveSize > MAX_UINT32) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Now, let's package up all the data for saving.
+ //
+ Header = SerializeState (FrameworkHandle, ContextToSave, ContextToSaveSize);
+ if (Header == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // All that should be left to do is save it using the associated persistence lib.
+ //
+ Status = SaveUnitTestCache (FrameworkHandle, Header);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a - Could not save state! %r\n", __FUNCTION__, Status));
+ Status = EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Free data that was used.
+ //
+ FreePool (Header);
+
+ return Status;
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf
new file mode 100644
index 00000000..6c03766d
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf
@@ -0,0 +1,37 @@
+## @file
+# Library to support Unit Testing from PEI, DXE, SMM, and UEFI Applications.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UnitTestLib
+ MODULE_UNI_FILE = UnitTestLib.uni
+ FILE_GUID = 98CEF9CA-15CE-40A3-ADE8-C299953CD0F6
+ VERSION_STRING = 1.0
+ MODULE_TYPE = UEFI_DRIVER
+ LIBRARY_CLASS = UnitTestLib|PEI_CORE PEIM DXE_CORE MM_STANDALONE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER SMM_CORE UEFI_DRIVER UEFI_APPLICATION
+
+[Sources]
+ UnitTestLib.c
+ RunTests.c
+ Assert.c
+ Log.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ PcdLib
+ DebugLib
+ MemoryAllocationLib
+ UnitTestPersistenceLib
+ UnitTestResultReportLib
+
+[Pcd]
+ gUnitTestFrameworkPkgTokenSpaceGuid.PcdUnitTestLogLevel ## CONSUMES
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.uni
new file mode 100644
index 00000000..fe7c9c7f
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.uni
@@ -0,0 +1,11 @@
+// /** @file
+// Library to support Unit Testing from PEI, DXE, SMM, and UEFI Applications.
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Library to support Unit Testing from PEI, DXE, SMM, and UEFI Applications"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Library to support Unit Testing from PEI, DXE, SMM, and UEFI Applications."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf
new file mode 100644
index 00000000..a65916c4
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf
@@ -0,0 +1,38 @@
+## @file
+# Library to support Unit Testing from host environments using Cmocka services.
+#
+# Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UnitTestLibCmocka
+ MODULE_UNI_FILE = UnitTestLibCmocka.uni
+ FILE_GUID = C800595F-45A3-45A1-8B50-28F01C2A5A4F
+ VERSION_STRING = 1.0
+ MODULE_TYPE = UEFI_DRIVER
+ LIBRARY_CLASS = UnitTestLib|HOST_APPLICATION
+
+[Sources]
+ UnitTestLib.c
+ RunTestsCmocka.c
+ AssertCmocka.c
+ Log.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ PcdLib
+ DebugLib
+ MemoryAllocationLib
+ UnitTestPersistenceLib
+ UnitTestResultReportLib
+ CmockaLib
+
+[Pcd]
+ gUnitTestFrameworkPkgTokenSpaceGuid.PcdUnitTestLogLevel ## CONSUMES
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.uni
new file mode 100644
index 00000000..aa25a44e
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.uni
@@ -0,0 +1,11 @@
+// /** @file
+// Library to support Unit Testing from host environments using Cmocka services.
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Library to support Unit Testing from host environments using Cmocka services"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Library to support Unit Testing from host environments using Cmocka services."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.c
new file mode 100644
index 00000000..bea780c5
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.c
@@ -0,0 +1,75 @@
+/** @file
+ This is an instance of the Unit Test Persistence Lib that does nothing.
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+#include <Library/UnitTestPersistenceLib.h>
+
+/**
+ Determines whether a persistence cache already exists for
+ the given framework.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+
+ @retval TRUE
+ @retval FALSE Cache doesn't exist or an error occurred.
+
+**/
+BOOLEAN
+EFIAPI
+DoesCacheExist (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
+ )
+{
+ return FALSE;
+}
+
+/**
+ Will save the data associated with an internal Unit Test Framework
+ state in a manner that can persist a Unit Test Application quit or
+ even a system reboot.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+ @param[in] SaveData A pointer to the buffer containing the serialized
+ framework internal state.
+
+ @retval EFI_SUCCESS Data is persisted and the test can be safely quit.
+ @retval Others Data is not persisted and test cannot be resumed upon exit.
+
+**/
+EFI_STATUS
+EFIAPI
+SaveUnitTestCache (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
+ IN UNIT_TEST_SAVE_HEADER *SaveData
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
+/**
+ Will retrieve any cached state associated with the given framework.
+ Will allocate a buffer to hold the loaded data.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+ @param[in] SaveData A pointer pointer that will be updated with the address
+ of the loaded data buffer.
+
+ @retval EFI_SUCCESS Data has been loaded successfully and SaveData is updated
+ with a pointer to the buffer.
+ @retval Others An error has occurred and no data has been loaded. SaveData
+ is set to NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+LoadUnitTestCache (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
+ OUT UNIT_TEST_SAVE_HEADER **SaveData
+ )
+{
+ return EFI_UNSUPPORTED;
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.inf
new file mode 100644
index 00000000..11a9d173
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.inf
@@ -0,0 +1,28 @@
+## @file
+# This is an instance of the Unit Test Persistence Lib does nothing.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UnitTestPersistenceLibNull
+ MODULE_UNI_FILE = UnitTestPersistenceLibNull.uni
+ FILE_GUID = B8553C7A-0B0B-4BBD-9DF3-825804BF26AB
+ VERSION_STRING = 1.0
+ MODULE_TYPE = UEFI_DRIVER
+ LIBRARY_CLASS = UnitTestPersistenceLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ UnitTestPersistenceLibNull.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.uni
new file mode 100644
index 00000000..00f7d8d7
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.uni
@@ -0,0 +1,11 @@
+// /** @file
+// NULL library for Unit Test Persistence Lib.
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "NULL library for Unit Test Persistence Lib"
+
+#string STR_MODULE_DESCRIPTION #language en-US "NULL library for Unit Test Persistence Lib."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.c
new file mode 100644
index 00000000..7f7c54b0
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.c
@@ -0,0 +1,416 @@
+/** @file
+ This is an instance of the Unit Test Persistence Lib that will utilize
+ the filesystem that a test application is running from to save a serialized
+ version of the internal test state in case the test needs to quit and restore.
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <PiDxe.h>
+#include <Library/UnitTestPersistenceLib.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/ShellLib.h>
+#include <Protocol/LoadedImage.h>
+
+#define CACHE_FILE_SUFFIX L"_Cache.dat"
+
+/**
+ Generate the device path to the cache file.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+
+ @retval !NULL A pointer to the EFI_FILE protocol instance for the filesystem.
+ @retval NULL Filesystem could not be found or an error occurred.
+
+**/
+STATIC
+EFI_DEVICE_PATH_PROTOCOL*
+GetCacheFileDevicePath (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
+ )
+{
+ EFI_STATUS Status;
+ UNIT_TEST_FRAMEWORK *Framework;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+ CHAR16 *AppPath;
+ CHAR16 *CacheFilePath;
+ CHAR16 *TestName;
+ UINTN DirectorySlashOffset;
+ UINTN CacheFilePathLength;
+ EFI_DEVICE_PATH_PROTOCOL *CacheFileDevicePath;
+
+ Framework = (UNIT_TEST_FRAMEWORK*)FrameworkHandle;
+ AppPath = NULL;
+ CacheFilePath = NULL;
+ TestName = NULL;
+ CacheFileDevicePath = NULL;
+
+ //
+ // First, we need to get some information from the loaded image.
+ //
+ Status = gBS->HandleProtocol (
+ gImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ (VOID**)&LoadedImage
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_WARN, "%a - Failed to locate DevicePath for loaded image. %r\n", __FUNCTION__, Status));
+ return NULL;
+ }
+
+ //
+ // Before we can start, change test name from ASCII to Unicode.
+ //
+ CacheFilePathLength = AsciiStrLen (Framework->ShortTitle) + 1;
+ TestName = AllocatePool (CacheFilePathLength * sizeof(CHAR16));
+ if (!TestName) {
+ goto Exit;
+ }
+ AsciiStrToUnicodeStrS (Framework->ShortTitle, TestName, CacheFilePathLength);
+
+ //
+ // Now we should have the device path of the root device and a file path for the rest.
+ // In order to target the directory for the test application, we must process
+ // the file path a little.
+ //
+ // NOTE: This may not be necessary... Path processing functions exist...
+ // PathCleanUpDirectories (FileNameCopy);
+ // if (PathRemoveLastItem (FileNameCopy)) {
+ //
+ AppPath = ConvertDevicePathToText (LoadedImage->FilePath, TRUE, TRUE); // NOTE: This must be freed.
+ DirectorySlashOffset = StrLen (AppPath);
+ //
+ // Make sure we didn't get any weird data.
+ //
+ if (DirectorySlashOffset == 0) {
+ DEBUG ((DEBUG_ERROR, "%a - Weird 0-length string when processing app path.\n", __FUNCTION__));
+ goto Exit;
+ }
+
+ //
+ // Now that we know we have a decent string, let's take a deeper look.
+ //
+ do {
+ if (AppPath[DirectorySlashOffset] == L'\\') {
+ break;
+ }
+ DirectorySlashOffset--;
+ } while (DirectorySlashOffset > 0);
+
+ //
+ // After that little maneuver, DirectorySlashOffset should be pointing at the last '\' in AppString.
+ // That would be the path to the parent directory that the test app is executing from.
+ // Let's check and make sure that's right.
+ //
+ if (AppPath[DirectorySlashOffset] != L'\\') {
+ DEBUG ((DEBUG_ERROR, "%a - Could not find a single directory separator in app path.\n", __FUNCTION__));
+ goto Exit;
+ }
+
+ //
+ // Now we know some things, we're ready to produce our output string, I think.
+ //
+ CacheFilePathLength = DirectorySlashOffset + 1;
+ CacheFilePathLength += StrLen (TestName);
+ CacheFilePathLength += StrLen (CACHE_FILE_SUFFIX);
+ CacheFilePathLength += 1; // Don't forget the NULL terminator.
+ CacheFilePath = AllocateZeroPool (CacheFilePathLength * sizeof (CHAR16));
+ if (!CacheFilePath) {
+ goto Exit;
+ }
+
+ //
+ // Let's produce our final path string, shall we?
+ //
+ StrnCpyS (CacheFilePath, CacheFilePathLength, AppPath, DirectorySlashOffset + 1); // Copy the path for the parent directory.
+ StrCatS (CacheFilePath, CacheFilePathLength, TestName); // Copy the base name for the test cache.
+ StrCatS (CacheFilePath, CacheFilePathLength, CACHE_FILE_SUFFIX); // Copy the file suffix.
+
+ //
+ // Finally, try to create the device path for the thing thing.
+ //
+ CacheFileDevicePath = FileDevicePath (LoadedImage->DeviceHandle, CacheFilePath);
+
+Exit:
+ //
+ // Free allocated buffers.
+ //
+ if (AppPath != NULL) {
+ FreePool (AppPath);
+ }
+ if (CacheFilePath != NULL) {
+ FreePool (CacheFilePath);
+ }
+ if (TestName != NULL) {
+ FreePool (TestName);
+ }
+
+ return CacheFileDevicePath;
+}
+
+/**
+ Determines whether a persistence cache already exists for
+ the given framework.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+
+ @retval TRUE
+ @retval FALSE Cache doesn't exist or an error occurred.
+
+**/
+BOOLEAN
+EFIAPI
+DoesCacheExist (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;
+ EFI_STATUS Status;
+ SHELL_FILE_HANDLE FileHandle;
+
+ //
+ // NOTE: This devpath is allocated and must be freed.
+ //
+ FileDevicePath = GetCacheFileDevicePath (FrameworkHandle);
+
+ //
+ // Check to see whether the file exists. If the file can be opened for
+ // reading, it exists. Otherwise, probably not.
+ //
+ Status = ShellOpenFileByDevicePath (
+ &FileDevicePath,
+ &FileHandle,
+ EFI_FILE_MODE_READ,
+ 0
+ );
+ if (!EFI_ERROR (Status)) {
+ ShellCloseFile (&FileHandle);
+ }
+
+ if (FileDevicePath != NULL) {
+ FreePool (FileDevicePath);
+ }
+
+ DEBUG ((DEBUG_VERBOSE, "%a - Returning %d\n", __FUNCTION__, !EFI_ERROR (Status)));
+
+ return (!EFI_ERROR (Status));
+}
+
+/**
+ Will save the data associated with an internal Unit Test Framework
+ state in a manner that can persist a Unit Test Application quit or
+ even a system reboot.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+ @param[in] SaveData A pointer to the buffer containing the serialized
+ framework internal state.
+
+ @retval EFI_SUCCESS Data is persisted and the test can be safely quit.
+ @retval Others Data is not persisted and test cannot be resumed upon exit.
+
+**/
+EFI_STATUS
+EFIAPI
+SaveUnitTestCache (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
+ IN UNIT_TEST_SAVE_HEADER *SaveData
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;
+ EFI_STATUS Status;
+ SHELL_FILE_HANDLE FileHandle;
+ UINTN WriteCount;
+
+ //
+ // Check the inputs for sanity.
+ //
+ if (FrameworkHandle == NULL || SaveData == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Determine the path for the cache file.
+ // NOTE: This devpath is allocated and must be freed.
+ //
+ FileDevicePath = GetCacheFileDevicePath (FrameworkHandle);
+
+ //
+ //First lets open the file if it exists so we can delete it...This is the work around for truncation
+ //
+ Status = ShellOpenFileByDevicePath (
+ &FileDevicePath,
+ &FileHandle,
+ (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE),
+ 0
+ );
+
+ if (!EFI_ERROR (Status)) {
+ //
+ // If file handle above was opened it will be closed by the delete.
+ //
+ Status = ShellDeleteFile (&FileHandle);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a failed to delete file %r\n", __FUNCTION__, Status));
+ }
+ }
+
+ //
+ // Now that we know the path to the file... let's open it for writing.
+ //
+ Status = ShellOpenFileByDevicePath (
+ &FileDevicePath,
+ &FileHandle,
+ (EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE),
+ 0
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a - Opening file for writing failed! %r\n", __FUNCTION__, Status));
+ goto Exit;
+ }
+
+ //
+ // Write the data to the file.
+ //
+ WriteCount = SaveData->SaveStateSize;
+ DEBUG ((DEBUG_INFO, "%a - Writing %d bytes to file...\n", __FUNCTION__, WriteCount));
+ Status = ShellWriteFile (
+ FileHandle,
+ &WriteCount,
+ SaveData
+ );
+
+ if (EFI_ERROR (Status) || WriteCount != SaveData->SaveStateSize) {
+ DEBUG ((DEBUG_ERROR, "%a - Writing to file failed! %r\n", __FUNCTION__, Status));
+ } else {
+ DEBUG ((DEBUG_INFO, "%a - SUCCESS!\n", __FUNCTION__));
+ }
+
+ //
+ // No matter what, we should probably close the file.
+ //
+ ShellCloseFile (&FileHandle);
+
+Exit:
+ if (FileDevicePath != NULL) {
+ FreePool (FileDevicePath);
+ }
+
+ return Status;
+}
+
+/**
+ Will retrieve any cached state associated with the given framework.
+ Will allocate a buffer to hold the loaded data.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+ @param[in] SaveData A pointer pointer that will be updated with the address
+ of the loaded data buffer.
+
+ @retval EFI_SUCCESS Data has been loaded successfully and SaveData is updated
+ with a pointer to the buffer.
+ @retval Others An error has occurred and no data has been loaded. SaveData
+ is set to NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+LoadUnitTestCache (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
+ OUT UNIT_TEST_SAVE_HEADER **SaveData
+ )
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;
+ SHELL_FILE_HANDLE FileHandle;
+ BOOLEAN IsFileOpened;
+ UINT64 LargeFileSize;
+ UINTN FileSize;
+ UNIT_TEST_SAVE_HEADER *Buffer;
+
+ IsFileOpened = FALSE;
+ Buffer = NULL;
+
+ //
+ // Check the inputs for sanity.
+ //
+ if (FrameworkHandle == NULL || SaveData == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Determine the path for the cache file.
+ // NOTE: This devpath is allocated and must be freed.
+ //
+ FileDevicePath = GetCacheFileDevicePath (FrameworkHandle);
+
+ //
+ // Now that we know the path to the file... let's open it for writing.
+ //
+ Status = ShellOpenFileByDevicePath (
+ &FileDevicePath,
+ &FileHandle,
+ EFI_FILE_MODE_READ,
+ 0
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a - Opening file for writing failed! %r\n", __FUNCTION__, Status));
+ goto Exit;
+ } else {
+ IsFileOpened = TRUE;
+ }
+
+ //
+ // Now that the file is opened, we need to determine how large a buffer we need.
+ //
+ Status = ShellGetFileSize (FileHandle, &LargeFileSize);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a - Failed to determine file size! %r\n", __FUNCTION__, Status));
+ goto Exit;
+ }
+
+ //
+ // Now that we know the size, let's allocated a buffer to hold the contents.
+ //
+ FileSize = (UINTN)LargeFileSize; // You know what... if it's too large, this lib don't care.
+ Buffer = AllocatePool (FileSize);
+ if (Buffer == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a - Failed to allocate a pool to hold the file contents! %r\n", __FUNCTION__, Status));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Exit;
+ }
+
+ //
+ // Finally, let's read the data.
+ //
+ Status = ShellReadFile (FileHandle, &FileSize, Buffer);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a - Failed to read the file contents! %r\n", __FUNCTION__, Status));
+ }
+
+Exit:
+ //
+ // Free allocated buffers
+ //
+ if (FileDevicePath != NULL) {
+ FreePool (FileDevicePath);
+ }
+ if (IsFileOpened) {
+ ShellCloseFile (&FileHandle);
+ }
+
+ //
+ // If we're returning an error, make sure
+ // the state is sane.
+ if (EFI_ERROR (Status) && Buffer != NULL) {
+ FreePool (Buffer);
+ Buffer = NULL;
+ }
+
+ *SaveData = Buffer;
+ return Status;
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.inf
new file mode 100644
index 00000000..1b212b20
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.inf
@@ -0,0 +1,47 @@
+## @file
+# UEFI Simple File System based version of the Unit Test Persistence Lib
+#
+# Instance of the Unit Test Persistence Lib that utilizes the UEFI filesystem
+# that a test application is running from to save a serialized version of the
+# internal test state in case the test needs to quit and restore.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UnitTestPersistenceLibSimpleFileSystem
+ MODULE_UNI_FILE = UnitTestPersistenceLibSimpleFileSystem.uni
+ FILE_GUID = 9200844A-CDFD-4368-B4BD-106354702605
+ VERSION_STRING = 1.0
+ MODULE_TYPE = UEFI_APPLICATION
+ LIBRARY_CLASS = UnitTestPersistenceLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ UnitTestPersistenceLibSimpleFileSystem.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ UefiBootServicesTableLib
+ BaseLib
+ ShellLib
+
+[Protocols]
+ gEfiLoadedImageProtocolGuid
+ gEfiSimpleFileSystemProtocolGuid
+
+[Guids]
+ gEfiFileInfoGuid
+ gEfiFileSystemInfoGuid
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.uni
new file mode 100644
index 00000000..e6593be1
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.uni
@@ -0,0 +1,15 @@
+// /** @file
+// UEFI Simple File System based version of the Unit Test Persistence Lib
+//
+// Instance of the Unit Test Persistence Lib that utilizes the UEFI filesystem
+// that a test application is running from to save a serialized version of the
+// internal test state in case the test needs to quit and restore.
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "UEFI Simple File System based version of the Unit Test Persistence Lib"
+
+#string STR_MODULE_DESCRIPTION #language en-US "UEFI Simple File System based version of the Unit Test Persistence Lib."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLib.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLib.c
new file mode 100644
index 00000000..c31ee7cd
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLib.c
@@ -0,0 +1,218 @@
+/** @file
+ Implement UnitTestResultReportLib doing plain txt out to console
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+#include <Library/UnitTestResultReportLib.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+
+VOID
+EFIAPI
+ReportPrint (
+ IN CONST CHAR8 *Format,
+ ...
+ );
+
+VOID
+ReportOutput (
+ IN CONST CHAR8 *Output
+ );
+
+struct _UNIT_TEST_STATUS_STRING {
+ UNIT_TEST_STATUS Status;
+ CHAR8 *String;
+};
+
+struct _UNIT_TEST_FAILURE_TYPE_STRING {
+ FAILURE_TYPE Type;
+ CHAR8 *String;
+};
+
+struct _UNIT_TEST_STATUS_STRING mStatusStrings[] = {
+ { UNIT_TEST_PASSED, "PASSED"},
+ { UNIT_TEST_ERROR_PREREQUISITE_NOT_MET, "NOT RUN - PREREQUISITE FAILED"},
+ { UNIT_TEST_ERROR_TEST_FAILED, "FAILED"},
+ { UNIT_TEST_RUNNING, "RUNNING"},
+ { UNIT_TEST_PENDING, "PENDING"},
+ { 0, "**UNKNOWN**"}
+};
+
+struct _UNIT_TEST_FAILURE_TYPE_STRING mFailureTypeStrings[] = {
+ { FAILURETYPE_NOFAILURE, "NO FAILURE"},
+ { FAILURETYPE_OTHER, "OTHER FAILURE"},
+ { FAILURETYPE_ASSERTTRUE, "ASSERT_TRUE FAILURE"},
+ { FAILURETYPE_ASSERTFALSE, "ASSERT_FALSE FAILURE"},
+ { FAILURETYPE_ASSERTEQUAL, "ASSERT_EQUAL FAILURE"},
+ { FAILURETYPE_ASSERTNOTEQUAL, "ASSERT_NOTEQUAL FAILURE"},
+ { FAILURETYPE_ASSERTNOTEFIERROR, "ASSERT_NOTEFIERROR FAILURE"},
+ { FAILURETYPE_ASSERTSTATUSEQUAL, "ASSERT_STATUSEQUAL FAILURE"},
+ { FAILURETYPE_ASSERTNOTNULL, "ASSERT_NOTNULL FAILURE"},
+ { FAILURETYPE_EXPECTASSERT, "EXPECT_ASSERT FAILURE"},
+ { 0, "*UNKNOWN* Failure"}
+};
+
+//
+// TEST REPORTING FUNCTIONS
+//
+
+STATIC
+CONST CHAR8*
+GetStringForUnitTestStatus (
+ IN UNIT_TEST_STATUS Status
+ )
+{
+ UINTN Index;
+
+ for (Index = 0; Index < ARRAY_SIZE (mStatusStrings) - 1; Index++) {
+ if (mStatusStrings[Index].Status == Status) {
+ //
+ // Return string from matching entry
+ //
+ return mStatusStrings[Index].String;
+ }
+ }
+ //
+ // Return last entry if no match found.
+ //
+ return mStatusStrings[Index].String;
+}
+
+STATIC
+CONST CHAR8*
+GetStringForFailureType (
+ IN FAILURE_TYPE Failure
+ )
+{
+ UINTN Index;
+
+ for (Index = 0; Index < ARRAY_SIZE (mFailureTypeStrings) - 1; Index++) {
+ if (mFailureTypeStrings[Index].Type == Failure) {
+ //
+ // Return string from matching entry
+ //
+ return mFailureTypeStrings[Index].String;
+ }
+ }
+ //
+ // Return last entry if no match found.
+ //
+ DEBUG((DEBUG_INFO, "%a Failure Type does not have string defined 0x%X\n", __FUNCTION__, (UINT32)Failure));
+ return mFailureTypeStrings[Index].String;
+}
+
+/*
+ Method to print the Unit Test run results
+
+ @retval Success
+*/
+EFI_STATUS
+EFIAPI
+OutputUnitTestFrameworkReport (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
+ )
+{
+ UNIT_TEST_FRAMEWORK *Framework;
+ INTN Passed;
+ INTN Failed;
+ INTN NotRun;
+ UNIT_TEST_SUITE_LIST_ENTRY *Suite;
+ UNIT_TEST_LIST_ENTRY *Test;
+ INTN SPassed;
+ INTN SFailed;
+ INTN SNotRun;
+
+ Passed = 0;
+ Failed = 0;
+ NotRun = 0;
+ Suite = NULL;
+
+ Framework = (UNIT_TEST_FRAMEWORK *)FrameworkHandle;
+ if (Framework == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ReportPrint ("---------------------------------------------------------\n");
+ ReportPrint ("------------- UNIT TEST FRAMEWORK RESULTS ---------------\n");
+ ReportPrint ("---------------------------------------------------------\n");
+
+ //print the version and time
+
+ //
+ // Iterate all suites
+ //
+ for (Suite = (UNIT_TEST_SUITE_LIST_ENTRY*)GetFirstNode(&Framework->TestSuiteList);
+ (LIST_ENTRY*)Suite != &Framework->TestSuiteList;
+ Suite = (UNIT_TEST_SUITE_LIST_ENTRY*)GetNextNode(&Framework->TestSuiteList, (LIST_ENTRY*)Suite)) {
+
+ Test = NULL;
+ SPassed = 0;
+ SFailed = 0;
+ SNotRun = 0;
+
+ ReportPrint ("/////////////////////////////////////////////////////////\n");
+ ReportPrint (" SUITE: %a\n", Suite->UTS.Title);
+ ReportPrint (" PACKAGE: %a\n", Suite->UTS.Name);
+ ReportPrint ("/////////////////////////////////////////////////////////\n");
+
+ //
+ // Iterate all tests within the suite
+ //
+ for (Test = (UNIT_TEST_LIST_ENTRY*)GetFirstNode(&(Suite->UTS.TestCaseList));
+ (LIST_ENTRY*)Test != &(Suite->UTS.TestCaseList);
+ Test = (UNIT_TEST_LIST_ENTRY*)GetNextNode(&(Suite->UTS.TestCaseList), (LIST_ENTRY*)Test)) {
+
+ ReportPrint ("*********************************************************\n");
+ ReportPrint (" CLASS NAME: %a\n", Test->UT.Name);
+ ReportPrint (" TEST: %a\n", Test->UT.Description);
+ ReportPrint (" STATUS: %a\n", GetStringForUnitTestStatus (Test->UT.Result));
+ ReportPrint (" FAILURE: %a\n", GetStringForFailureType (Test->UT.FailureType));
+ ReportPrint (" FAILURE MESSAGE:\n%a\n", Test->UT.FailureMessage);
+
+ if (Test->UT.Log != NULL) {
+ ReportPrint (" LOG:\n");
+ ReportOutput (Test->UT.Log);
+ }
+
+ switch (Test->UT.Result) {
+ case UNIT_TEST_PASSED:
+ SPassed++;
+ break;
+ case UNIT_TEST_ERROR_TEST_FAILED:
+ SFailed++;
+ break;
+ case UNIT_TEST_PENDING: // Fall through...
+ case UNIT_TEST_RUNNING: // Fall through...
+ case UNIT_TEST_ERROR_PREREQUISITE_NOT_MET:
+ SNotRun++;
+ break;
+ default:
+ break;
+ }
+ ReportPrint ("**********************************************************\n");
+ } //End Test iteration
+
+ ReportPrint ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+ ReportPrint ("Suite Stats\n");
+ ReportPrint (" Passed: %d (%d%%)\n", SPassed, (SPassed * 100)/(SPassed+SFailed+SNotRun));
+ ReportPrint (" Failed: %d (%d%%)\n", SFailed, (SFailed * 100) / (SPassed + SFailed + SNotRun));
+ ReportPrint (" Not Run: %d (%d%%)\n", SNotRun, (SNotRun * 100) / (SPassed + SFailed + SNotRun));
+ ReportPrint ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" );
+
+ Passed += SPassed; //add to global counters
+ Failed += SFailed; //add to global counters
+ NotRun += SNotRun; //add to global counters
+ }//End Suite iteration
+
+ ReportPrint ("=========================================================\n");
+ ReportPrint ("Total Stats\n");
+ ReportPrint (" Passed: %d (%d%%)\n", Passed, (Passed * 100) / (Passed + Failed + NotRun));
+ ReportPrint (" Failed: %d (%d%%)\n", Failed, (Failed * 100) / (Passed + Failed + NotRun));
+ ReportPrint (" Not Run: %d (%d%%)\n", NotRun, (NotRun * 100) / (Passed + Failed + NotRun));
+ ReportPrint ("=========================================================\n" );
+
+ return EFI_SUCCESS;
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c
new file mode 100644
index 00000000..569e5578
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.c
@@ -0,0 +1,49 @@
+/** @file
+ Implement UnitTestResultReportLib doing plain txt out to console
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/PrintLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+
+VOID
+EFIAPI
+ReportPrint (
+ IN CONST CHAR8 *Format,
+ ...
+ )
+{
+ VA_LIST Marker;
+ CHAR16 String[256];
+ UINTN Length;
+
+ VA_START (Marker, Format);
+ Length = UnicodeVSPrintAsciiFormat (String, sizeof (String), Format, Marker);
+ if (Length == 0) {
+ DEBUG ((DEBUG_ERROR, "%a formatted string is too long\n", __FUNCTION__));
+ } else {
+ gST->ConOut->OutputString (gST->ConOut, String);
+ }
+ VA_END (Marker);
+}
+
+VOID
+ReportOutput (
+ IN CONST CHAR8 *Output
+ )
+{
+ CHAR8 AsciiString[128];
+ UINTN Length;
+ UINTN Index;
+
+ Length = AsciiStrLen (Output);
+ for (Index = 0; Index < Length; Index += (sizeof (AsciiString) - 1)) {
+ AsciiStrnCpyS (AsciiString, sizeof (AsciiString), &Output[Index], sizeof (AsciiString) - 1);
+ ReportPrint ("%a", AsciiString);
+ }
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.inf
new file mode 100644
index 00000000..619593be
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.inf
@@ -0,0 +1,29 @@
+## @file
+# Library to support printing out the unit test report to a UEFI console
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UnitTestResultReportLibConOut
+ MODULE_UNI_FILE = UnitTestResultReportLibConOut.uni
+ FILE_GUID = C659641D-BA1F-4B58-946E-B1E1103903F9
+ VERSION_STRING = 1.0
+ MODULE_TYPE = UEFI_DRIVER
+ LIBRARY_CLASS = UnitTestResultReportLib
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ UefiBootServicesTableLib
+ PrintLib
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[Sources]
+ UnitTestResultReportLib.c
+ UnitTestResultReportLibConOut.c
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.uni
new file mode 100644
index 00000000..92ba1b84
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.uni
@@ -0,0 +1,11 @@
+// /** @file
+// Library to support printing out the unit test report to a UEFI console
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Library to support printing out the unit test report to a UEFI console"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Library to support printing out the unit test report to a UEFI console."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c
new file mode 100644
index 00000000..b0ef12a5
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.c
@@ -0,0 +1,48 @@
+/** @file
+ Implement UnitTestResultReportLib doing plain txt out to console
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/PrintLib.h>
+#include <Library/DebugLib.h>
+
+VOID
+EFIAPI
+ReportPrint (
+ IN CONST CHAR8 *Format,
+ ...
+ )
+{
+ VA_LIST Marker;
+ CHAR8 String[256];
+ UINTN Length;
+
+ VA_START (Marker, Format);
+ Length = AsciiVSPrint (String, sizeof (String), Format, Marker);
+ if (Length == 0) {
+ DEBUG ((DEBUG_ERROR, "%a formatted string is too long\n", __FUNCTION__));
+ } else {
+ DEBUG ((DEBUG_INFO, String));
+ }
+ VA_END (Marker);
+}
+
+VOID
+ReportOutput (
+ IN CONST CHAR8 *Output
+ )
+{
+ CHAR8 AsciiString[128];
+ UINTN Length;
+ UINTN Index;
+
+ Length = AsciiStrLen (Output);
+ for (Index = 0; Index < Length; Index += (sizeof (AsciiString) - 1)) {
+ AsciiStrnCpyS (AsciiString, sizeof (AsciiString), &Output[Index], sizeof (AsciiString) - 1);
+ DEBUG ((DEBUG_INFO, AsciiString));
+ }
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.inf
new file mode 100644
index 00000000..1a2f925e
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.inf
@@ -0,0 +1,28 @@
+## @file
+# Library to support printing out the unit test report using DEBUG() macros.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UnitTestResultReportLibDebugLib
+ MODULE_UNI_FILE = UnitTestResultReportLibDebugLib.uni
+ FILE_GUID = BED736D4-D197-475F-B7CE-0D828FF2C9A6
+ VERSION_STRING = 1.0
+ MODULE_TYPE = UEFI_DRIVER
+ LIBRARY_CLASS = UnitTestResultReportLib
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ PrintLib
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[Sources]
+ UnitTestResultReportLib.c
+ UnitTestResultReportLibDebugLib.c
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.uni
new file mode 100644
index 00000000..4f199341
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.uni
@@ -0,0 +1,11 @@
+// /** @file
+// Library to support printing out the unit test report using DEBUG() macros.
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Library to support printing out the unit test report using DEBUG() macros"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Library to support printing out the unit test report using DEBUG() macros."
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestBootLib.h b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestBootLib.h
new file mode 100644
index 00000000..0b834d20
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestBootLib.h
@@ -0,0 +1,31 @@
+/** @file
+ Provides a library function that can be customized to set the platform to boot
+ from USB on the next boot. This allows the test framework to reboot back to
+ USB. Since boot managers are not all the same creating a lib to support
+ platform customization will make porting to new code base/platform easier.
+
+ Copyright (c) Microsoft Corporation.<BR>
+ Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __UNIT_TEST_BOOT_LIB_H__
+#define __UNIT_TEST_BOOT_LIB_H__
+
+/**
+ Set the boot manager to boot from a specific device on the next boot. This
+ should be set only for the next boot and shouldn't require any manual clean up
+
+ @retval EFI_SUCCESS Boot device for next boot was set.
+ @retval EFI_UNSUPPORTED Setting the boot device for the next boot is not
+ supportted.
+ @retval Other Boot device for next boot can not be set.
+**/
+EFI_STATUS
+EFIAPI
+SetBootNextDevice (
+ VOID
+ );
+
+#endif
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestPersistenceLib.h b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestPersistenceLib.h
new file mode 100644
index 00000000..2bec0b52
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestPersistenceLib.h
@@ -0,0 +1,76 @@
+/** @file
+ This header file describes a library that contains functions to save and
+ restore unit test internal state, in case the test needs to pause and resume
+ (eg. a reboot-based test).
+
+ Copyright (c) Microsoft Corporation.<BR>
+ Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _UNIT_TEST_PERSISTENCE_LIB_H_
+#define _UNIT_TEST_PERSISTENCE_LIB_H_
+
+#include <UnitTestFrameworkTypes.h>
+
+#define UNIT_TEST_PERSISTENCE_LIB_VERSION 1
+
+/**
+ Determines whether a persistence cache already exists for
+ the given framework.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+
+ @retval TRUE
+ @retval FALSE Cache doesn't exist or an error occurred.
+
+**/
+BOOLEAN
+EFIAPI
+DoesCacheExist (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
+ );
+
+/**
+ Will save the data associated with an internal Unit Test Framework
+ state in a manner that can persist a Unit Test Application quit or
+ even a system reboot.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+ @param[in] SaveData A pointer to the buffer containing the serialized
+ framework internal state.
+
+ @retval EFI_SUCCESS Data is persisted and the test can be safely quit.
+ @retval Others Data is not persisted and test cannot be resumed upon exit.
+
+**/
+EFI_STATUS
+EFIAPI
+SaveUnitTestCache (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
+ IN UNIT_TEST_SAVE_HEADER *SaveData
+ );
+
+/**
+ Will retrieve any cached state associated with the given framework.
+ Will allocate a buffer to hold the loaded data.
+
+ @param[in] FrameworkHandle A pointer to the framework that is being persisted.
+ @param[in] SaveData A pointer pointer that will be updated with the address
+ of the loaded data buffer.
+
+ @retval EFI_SUCCESS Data has been loaded successfully and SaveData is updated
+ with a pointer to the buffer.
+ @retval Others An error has occurred and no data has been loaded. SaveData
+ is set to NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+LoadUnitTestCache (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,
+ OUT UNIT_TEST_SAVE_HEADER **SaveData
+ );
+
+#endif
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestResultReportLib.h b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestResultReportLib.h
new file mode 100644
index 00000000..80d17cb6
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/Library/UnitTestResultReportLib.h
@@ -0,0 +1,27 @@
+/** @file
+ Provides a unit test result report. This allows new result output formats to
+ be easily customized.
+
+ Copyright (c) Microsoft Corporation.<BR>
+ Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __UNIT_TEST_RESULT_REPORT_LIB_H__
+#define __UNIT_TEST_RESULT_REPORT_LIB_H__
+
+#include <UnitTestFrameworkTypes.h>
+
+/**
+Method to produce the Unit Test run results
+
+@retval Success
+**/
+EFI_STATUS
+EFIAPI
+OutputUnitTestFrameworkReport (
+ IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
+ );
+
+#endif
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/UnitTestFrameworkTypes.h b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/UnitTestFrameworkTypes.h
new file mode 100644
index 00000000..25d5c9c4
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/PrivateInclude/UnitTestFrameworkTypes.h
@@ -0,0 +1,184 @@
+/** @file
+ Provides the basic types and common elements of the unit test framework
+
+ Copyright (c) Microsoft Corporation.<BR>
+ Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __UNIT_TEST_TYPES_H__
+#define __UNIT_TEST_TYPES_H__
+
+#include <Library/UnitTestLib.h>
+
+///
+/// The maximum length of a string stored in the unit test framework
+///
+#define UNIT_TEST_MAX_STRING_LENGTH (120)
+
+///
+/// The size of a firngerprint used to save/resume execution of a unit test
+/// framework. This is the size of a CRC32 value which is 32-bit value.
+///
+///
+#define UNIT_TEST_FINGERPRINT_SIZE (sizeof (UINT32))
+
+///
+/// The maximum length of a test failure message stored in the unit test
+/// framework
+///
+#define UNIT_TEST_TESTFAILUREMSG_LENGTH (120)
+
+///
+/// FAILURE_TYPE used to record the type of assert that was triggered by a unit
+/// test.
+///
+typedef UINT32 FAILURE_TYPE;
+#define FAILURETYPE_NOFAILURE (0)
+#define FAILURETYPE_OTHER (1)
+#define FAILURETYPE_ASSERTTRUE (2)
+#define FAILURETYPE_ASSERTFALSE (3)
+#define FAILURETYPE_ASSERTEQUAL (4)
+#define FAILURETYPE_ASSERTNOTEQUAL (5)
+#define FAILURETYPE_ASSERTNOTEFIERROR (6)
+#define FAILURETYPE_ASSERTSTATUSEQUAL (7)
+#define FAILURETYPE_ASSERTNOTNULL (8)
+#define FAILURETYPE_EXPECTASSERT (9)
+
+///
+/// Unit Test context structure tracked by the unit test framework.
+///
+typedef struct {
+ CHAR8 *Description;
+ CHAR8 *Name; //can't have spaces and should be short
+ CHAR8 *Log;
+ FAILURE_TYPE FailureType;
+ CHAR8 FailureMessage[UNIT_TEST_TESTFAILUREMSG_LENGTH];
+ UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE];
+ UNIT_TEST_STATUS Result;
+ UNIT_TEST_FUNCTION RunTest;
+ UNIT_TEST_PREREQUISITE Prerequisite;
+ UNIT_TEST_CLEANUP CleanUp;
+ UNIT_TEST_CONTEXT Context;
+ UNIT_TEST_SUITE_HANDLE ParentSuite;
+} UNIT_TEST;
+
+///
+/// Structure used to store the set of unit tests in a unit test suite as a list.
+///
+typedef struct {
+ LIST_ENTRY Entry;
+ UNIT_TEST UT;
+} UNIT_TEST_LIST_ENTRY;
+
+///
+/// Unit Test Suite context structure tracked by the unit test framework.
+///
+typedef struct {
+ UINTN NumTests;
+ CHAR8 *Title;
+ CHAR8 *Name;
+ UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE];
+ UNIT_TEST_SUITE_SETUP Setup;
+ UNIT_TEST_SUITE_TEARDOWN Teardown;
+ LIST_ENTRY TestCaseList; // UNIT_TEST_LIST_ENTRY
+ UNIT_TEST_FRAMEWORK_HANDLE ParentFramework;
+} UNIT_TEST_SUITE;
+
+///
+/// Structure used to store the set of unit test suites in a unit test framework
+/// as a list.
+///
+typedef struct {
+ LIST_ENTRY Entry;
+ UNIT_TEST_SUITE UTS;
+} UNIT_TEST_SUITE_LIST_ENTRY;
+
+///
+/// Unit Test Framework context structure tracked by the unit test framework.
+///
+typedef struct {
+ CHAR8 *Title;
+ CHAR8 *ShortTitle; // This title should contain NO spaces or non-filename characters. Is used in reporting and serialization.
+ CHAR8 *VersionString;
+ CHAR8 *Log;
+ UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE];
+ LIST_ENTRY TestSuiteList; // UNIT_TEST_SUITE_LIST_ENTRY
+ EFI_TIME StartTime;
+ EFI_TIME EndTime;
+ UNIT_TEST *CurrentTest;
+ VOID *SavedState; // This is an instance of UNIT_TEST_SAVE_HEADER*, if present.
+} UNIT_TEST_FRAMEWORK;
+
+///
+/// Serialized version of a unit test
+///
+typedef struct {
+ UINT32 Size; // Size of the UNIT_TEST_SAVE_TEST including Log[]
+ UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE]; // Fingerprint of the test itself.
+ CHAR8 FailureMessage[UNIT_TEST_TESTFAILUREMSG_LENGTH];
+ FAILURE_TYPE FailureType;
+ UNIT_TEST_STATUS Result;
+ CHAR8 Log[];
+} UNIT_TEST_SAVE_TEST;
+
+///
+/// Serialized version of a unit test context
+///
+typedef struct {
+ UINT32 Size; // Size of the UNIT_TEST_SAVE_CONTEXT including Data[]
+ UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE]; // Fingerprint of the corresponding test.
+ UINT8 Data[]; // Actual data of the context.
+} UNIT_TEST_SAVE_CONTEXT;
+
+///
+/// Serialized version of unit test framework
+///
+typedef struct {
+ UINT8 Version;
+ UINT32 SaveStateSize; // Size of the entire serialized buffer.
+ UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE]; // Fingerprint of the framework that has been saved.
+ EFI_TIME StartTime;
+ UINT32 TestCount;
+ BOOLEAN HasSavedContext;
+ // UNIT_TEST_SAVE_TEST Tests[]; // Array of structures starts here.
+ // UNIT_TEST_SAVE_CONTEXT SavedContext[]; // Saved context for the currently running test.
+ // CHAR8 Log[]; // NOTE: Not yet implemented!!
+} UNIT_TEST_SAVE_HEADER;
+
+/**
+ This function is responsible for initializing the log buffer for a single test. It can
+ be used internally, but may also be consumed by the test framework to add pre-existing
+ data to a log before it's used.
+
+ @param[in,out] TestHandle A handle to the test being initialized.
+ @param[in] Buffer [Optional] A pointer to pre-existing log data that should
+ be used to initialize the log. Should include a NULL terminator.
+ @param[in] BufferSize [Optional] The size of the pre-existing log data.
+
+**/
+VOID
+EFIAPI
+UnitTestLogInit (
+ IN OUT UNIT_TEST *Test,
+ IN UINT8 *Buffer OPTIONAL,
+ IN UINTN BufferSize OPTIONAL
+ );
+
+/**
+ Internal helper function to return a handle to the currently executing framework.
+ This function is generally used for communication within the UnitTest framework, but is
+ defined here so that it can be consumed by the Assertion and Logging macros.
+
+ There should be no need to consume as a test writer, but it's there if you need it.
+
+ @retval Handle to the currently executing test framework.
+
+**/
+UNIT_TEST_FRAMEWORK_HANDLE
+GetActiveFrameworkHandle (
+ VOID
+ );
+
+#endif
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/ReadMe.md b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/ReadMe.md
new file mode 100644
index 00000000..8b338142
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/ReadMe.md
@@ -0,0 +1,496 @@
+# Unit Test Framework Package
+
+## About
+
+This package adds a unit test framework capable of building tests for multiple contexts including
+the UEFI shell environment and host-based environments. It allows for unit test development to focus
+on the tests and leave error logging, result formatting, context persistance, and test running to the framework.
+The unit test framework works well for low level unit tests as well as system level tests and
+fits easily in automation frameworks.
+
+### UnitTestLib
+
+The main "framework" library. The core of the framework is the Framework object, which can have any number
+of test cases and test suites registered with it. The Framework object is also what drives test execution.
+
+The Framework also provides helper macros and functions for checking test conditions and
+reporting errors. Status and error info will be logged into the test context. There are a number
+of Assert macros that make the unit test code friendly to view and easy to understand.
+
+Finally, the Framework also supports logging strings during the test execution. This data is logged
+to the test context and will be available in the test reporting phase. This should be used for
+logging test details and helpful messages to resolve test failures.
+
+### UnitTestPersistenceLib
+
+Persistence lib has the main job of saving and restoring test context to a storage medium so that for tests
+that require exiting the active process and then resuming state can be maintained. This is critical
+in supporting a system reboot in the middle of a test run.
+
+### UnitTestResultReportLib
+
+Library provides function to run at the end of a framework test run and handles formatting the report.
+This is a common customization point and allows the unit test framework to fit its output reports into
+other test infrastructure. In this package a simple library instances has been supplied to output test
+results to the console as plain text.
+
+## Samples
+
+There is a sample unit test provided as both an example of how to write a unit test and leverage
+many of the features of the framework. This sample can be found in the `Test/UnitTest/Sample/SampleUnitTest`
+directory.
+
+The sample is provided in PEI, SMM, DXE, and UEFI App flavors. It also has a flavor for the HOST_APPLICATION
+build type, which can be run on a host system without needing a target.
+
+## Usage
+
+This section is built a lot like a "Getting Started". We'll go through some of the components that are needed
+when constructing a unit test and some of the decisions that are made by the test writer. We'll also describe
+how to check for expected conditions in test cases and a bit of the logging characteristics.
+
+Most of these examples will refer to the SampleUnitTestUefiShell app found in this package.
+
+### Requirements - INF
+
+In our INF file, we'll need to bring in the `UnitTestLib` library. Conveniently, the interface
+header for the `UnitTestLib` is located in `MdePkg`, so you shouldn't need to depend on any other
+packages. As long as your DSC file knows where to find the lib implementation that you want to use,
+you should be good to go.
+
+See this example in 'SampleUnitTestUefiShell.inf'...
+
+```
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ BaseLib
+ DebugLib
+ UnitTestLib
+ PrintLib
+```
+
+Also, if you want you test to automatically be picked up by the Test Runner plugin, you will need
+to make sure that the module `BASE_NAME` contains the word `Test`...
+
+```
+[Defines]
+ BASE_NAME = SampleUnitTestUefiShell
+```
+
+### Requirements - Code
+
+Not to state the obvious, but let's make sure we have the following include before getting too far along...
+
+```c
+#include <Library/UnitTestLib.h>
+```
+
+Now that we've got that squared away, let's look at our 'Main()'' routine (or DriverEntryPoint() or whatever).
+
+### Configuring the Framework
+
+Everything in the UnitTestPkg framework is built around an object called -- conveniently -- the Framework.
+This Framework object will contain all the information about our test, the test suites and test cases associated
+with it, the current location within the test pass, and any results that have been recorded so far.
+
+To get started with a test, we must first create a Framework instance. The function for this is
+`InitUnitTestFramework`. It takes in `CHAR8` strings for the long name, short name, and test version.
+The long name and version strings are just for user presentation and relatively flexible. The short name
+will be used to name any cache files and/or test results, so should be a name that makes sense in that context.
+These strings are copied internally to the Framework, so using stack-allocated or literal strings is fine.
+
+In the 'SampleUnitTestUefiShell' app, the module name is used as the short name, so the init looks like this.
+
+```c
+DEBUG(( DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION ));
+
+//
+// Start setting up the test framework for running the tests.
+//
+Status = InitUnitTestFramework( &Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION );
+```
+
+The `&Framework` returned here is the handle to the Framework. If it's successfully returned, we can start adding
+test suites and test cases.
+
+Test suites exist purely to help organize test cases and to differentiate the results in reports. If you're writing
+a small unit test, you can conceivably put all test cases into a single suite. However, if you end up with 20+ test
+cases, it may be beneficial to organize them according to purpose. You _must_ have at least one test suite, even if
+it's just a catch-all. The function to create a test suite is `CreateUnitTestSuite`. It takes in a handle to
+the Framework object, a `CHAR8` string for the suite title and package name, and optional function pointers for
+a setup function and a teardown function.
+
+The suite title is for user presentation. The package name is for xUnit type reporting and uses a '.'-separated
+hierarchical format (see 'SampleUnitTestApp' for example). If provided, the setup and teardown functions will be
+called once at the start of the suite (before _any_ tests have run) and once at the end of the suite (after _all_
+tests have run), respectively. If either or both of these are unneeded, pass `NULL`. The function prototypes are
+`UNIT_TEST_SUITE_SETUP` and `UNIT_TEST_SUITE_TEARDOWN`.
+
+Looking at 'SampleUnitTestUefiShell' app, you can see that the first test suite is created as below...
+
+```c
+//
+// Populate the SimpleMathTests Unit Test Suite.
+//
+Status = CreateUnitTestSuite( &SimpleMathTests, Fw, "Simple Math Tests", "Sample.Math", NULL, NULL );
+```
+
+This test suite has no setup or teardown functions. The `&SimpleMathTests` returned here is a handle to the suite and
+will be used when adding test cases.
+
+Great! Now we've finished some of the cruft, red tape, and busy work. We're ready to add some tests. Adding a test
+to a test suite is accomplished with the -- you guessed it -- `AddTestCase` function. It takes in the suite handle;
+a `CHAR8` string for the description and class name; a function pointer for the test case itself; additional, optional
+function pointers for prerequisite check and cleanup routines; and and optional pointer to a context structure.
+
+Okay, that's a lot. Let's take it one piece at a time. The description and class name strings are very similar in
+usage to the suite title and package name strings in the test suites. The former is for user presentation and the
+latter is for xUnit parsing. The test case function pointer is what is actually executed as the "test" and the
+prototype should be `UNIT_TEST_FUNCTION`. The last three parameters require a little bit more explaining.
+
+The prerequisite check function has a prototype of `UNIT_TEST_PREREQUISITE` and -- if provided -- will be called
+immediately before the test case. If this function returns any error, the test case will not be run and will be
+recorded as `UNIT_TEST_ERROR_PREREQUISITE_NOT_MET`. The cleanup function (prototype `UNIT_TEST_CLEANUP`) will be called
+immediately after the test case to provide an opportunity to reset any global state that may have been changed in the
+test case. In the event of a prerequisite failure, the cleanup function will also be skipped. If either of these
+functions is not needed, pass `NULL`.
+
+The context pointer is entirely case-specific. It will be passed to the test case upon execution. One of the purposes
+of the context pointer is to allow test case reuse with different input data. (Another use is for testing that wraps
+around a system reboot, but that's beyond the scope of this guide.) The test case must know how to interpret the context
+pointer, so it could be a simple value, or it could be a complex structure. If unneeded, pass `NULL`.
+
+In 'SampleUnitTestUefiShell' app, the first test case is added using the code below...
+
+```c
+AddTestCase( SimpleMathTests, "Adding 1 to 1 should produce 2", "Addition", OnePlusOneShouldEqualTwo, NULL, NULL, NULL );
+```
+
+This test case calls the function `OnePlusOneShouldEqualTwo` and has no prerequisite, cleanup, or context.
+
+Once all the suites and cases are added, it's time to run the Framework.
+
+```c
+//
+// Execute the tests.
+//
+Status = RunAllTestSuites( Framework );
+```
+
+### A Simple Test Case
+
+We'll take a look at the below test case from 'SampleUnitTestApp'...
+
+```c
+UNIT_TEST_STATUS
+EFIAPI
+OnePlusOneShouldEqualTwo (
+ IN UNIT_TEST_FRAMEWORK_HANDLE Framework,
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UINTN A, B, C;
+
+ A = 1;
+ B = 1;
+ C = A + B;
+
+ UT_ASSERT_EQUAL(C, 2);
+ return UNIT_TEST_PASSED;
+} // OnePlusOneShouldEqualTwo()
+```
+
+The prototype for this function matches the `UNIT_TEST_FUNCTION` prototype. It takes in a handle to the Framework
+itself and the context pointer. The context pointer could be cast and interpreted as anything within this test case,
+which is why it's important to configure contexts carefully. The test case returns a value of `UNIT_TEST_STATUS`, which
+will be recorded in the Framework and reported at the end of all suites.
+
+In this test case, the `UT_ASSERT_EQUAL` assertion is being used to establish that the business logic has functioned
+correctly. There are several assertion macros, and you are encouraged to use one that matches as closely to your
+intended test criterium as possible, because the logging is specific to the macro and more specific macros have more
+detailed logs. When in doubt, there are always `UT_ASSERT_TRUE` and `UT_ASSERT_FALSE`. Assertion macros that fail their
+test criterium will immediately return from the test case with `UNIT_TEST_ERROR_TEST_FAILED` and log an error string.
+_Note_ that this early return can have implications for memory leakage.
+
+At the end, if all test criteria pass, you should return `UNIT_TEST_PASSED`.
+
+### More Complex Cases
+
+To write more advanced tests, first take a look at all the Assertion and Logging macros provided in the framework.
+
+Beyond that, if you're writing host-based tests and want to take a dependency on the UnitTestFrameworkPkg, you can
+leverage the `cmocka.h` interface and write tests with all the features of the Cmocka framework.
+
+Documentation for Cmocka can be found here:
+https://api.cmocka.org/
+
+## Development
+
+### Iterating on a Single Test
+
+When using the EDK2 Pytools for CI testing, the host-based unit tests will be built and run on any build that includes
+the `NOOPT` build target.
+
+If you are trying to iterate on a single test, a convenient pattern is to build only that test module. For example,
+the following command will build only the SafeIntLib host-based test from the MdePkg...
+
+```bash
+stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=VS2017 -p MdePkg -t NOOPT BUILDMODULE=MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.inf
+```
+
+### Hooking BaseLib
+
+Most unit test mocking can be performed by the functions provided in the UnitTestFramework libraries, but since
+BaseLib is consumed by the Framework itself, it requires different techniques to substitute parts of the
+functionality.
+
+To solve some of this, the UnitTestFramework consumes a special implementation of BaseLib for host-based tests.
+This implementation contains a [hook table](https://github.com/tianocore/edk2/blob/e188ecc8b4aed8fdd26b731d43883861f5e5e7b4/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h#L507)
+that can be used to substitute test functionality for any of the BaseLib functions. By default, this implementation
+will use the underlying BaseLib implementation, so the unit test writer only has to supply minimal code to test a
+particular case.
+
+### Debugging the Framework Itself
+
+While most of the tests that are produced by the UnitTestFramework are easy to step through in a debugger, the Framework
+itself consumes code (mostly Cmocka) that sets its own build flags. These flags cause parts of the Framework to not
+export symbols and captures exceptions, and as such are harder to debug. We have provided a Stuart parameter to force
+symbolic debugging to be enabled.
+
+You can run a build by adding the `BLD_*_UNIT_TESTING_DEBUG=TRUE` parameter to enable this build option.
+
+```bash
+stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=VS2019 -p MdePkg -t NOOPT BLD_*_UNIT_TESTING_DEBUG=TRUE
+```
+
+## Building and Running Host-Based Tests
+
+The EDK2 CI infrastructure provides a convenient way to run all host-based tests -- in the the entire tree or just
+selected packages -- and aggregate all the the reports, including highlighting any failures. This functionality is
+provided through the Stuart build system (published by EDK2-PyTools) and the `NOOPT` build target.
+
+### Building Locally
+
+First, to make sure you're working with the latest PyTools, run the following command:
+
+```bash
+# Would recommend to run this in a Python venv, but that's out of scope for this doc.
+python -m pip install --upgrade -r ./pip-requirements.txt
+```
+
+After that, the following commands will set up the build and run the host-based tests.
+
+```bash
+# Setup repo for building
+# stuart_setup -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC5, VS2019, etc.>
+stuart_setup -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2019
+
+# Update all binary dependencies
+# stuart_update -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC5, VS2019, etc.>
+stuart_update -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2019
+
+# Build and run the tests
+# stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC5, VS2019, etc.> -t NOOPT [-p <Package Name>]
+stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2019 -t NOOPT -p MdePkg
+```
+
+### Evaluating the Results
+
+In your immediate output, any build failures will be highlighted. You can see these below as "WARNING" and "ERROR" messages.
+
+```text
+(edk_env) PS C:\_uefi\edk2> stuart_ci_build -c .\.pytool\CISettings.py TOOL_CHAIN_TAG=VS2019 -t NOOPT -p MdePkg
+
+SECTION - Init SDE
+SECTION - Loading Plugins
+SECTION - Start Invocable Tool
+SECTION - Getting Environment
+SECTION - Loading plugins
+SECTION - Building MdePkg Package
+PROGRESS - --Running MdePkg: Host Unit Test Compiler Plugin NOOPT --
+WARNING - Allowing Override for key TARGET_ARCH
+PROGRESS - Start time: 2020-07-27 17:18:08.521672
+PROGRESS - Setting up the Environment
+PROGRESS - Running Pre Build
+PROGRESS - Running Build NOOPT
+PROGRESS - Running Post Build
+SECTION - Run Host based Unit Tests
+SUBSECTION - Testing for architecture: X64
+WARNING - TestBaseSafeIntLibHost.exe Test Failed
+WARNING - Test SafeInt8ToUint8 - UT_ASSERT_EQUAL(0x5b:5b, Result:5c)
+c:\_uefi\edk2\MdePkg\Test\UnitTest\Library\BaseSafeIntLib\TestBaseSafeIntLib.c:35: error: Failure!
+ERROR - Plugin Failed: Host-Based Unit Test Runner returned 1
+CRITICAL - Post Build failed
+PROGRESS - End time: 2020-07-27 17:18:19.792313 Total time Elapsed: 0:00:11
+ERROR - --->Test Failed: Host Unit Test Compiler Plugin NOOPT returned 1
+ERROR - Overall Build Status: Error
+PROGRESS - There were 1 failures out of 1 attempts
+SECTION - Summary
+ERROR - Error
+
+(edk_env) PS C:\_uefi\edk2>
+```
+
+If a test fails, you can run it manually to get more details...
+
+```text
+(edk_env) PS C:\_uefi\edk2> .\Build\MdePkg\HostTest\NOOPT_VS2019\X64\TestBaseSafeIntLibHost.exe
+
+Int Safe Lib Unit Test Application v0.1
+---------------------------------------------------------
+------------ RUNNING ALL TEST SUITES --------------
+---------------------------------------------------------
+---------------------------------------------------------
+RUNNING TEST SUITE: Int Safe Conversions Test Suite
+---------------------------------------------------------
+[==========] Running 71 test(s).
+[ RUN ] Test SafeInt8ToUint8
+[ ERROR ] --- UT_ASSERT_EQUAL(0x5b:5b, Result:5c)
+[ LINE ] --- c:\_uefi\edk2\MdePkg\Test\UnitTest\Library\BaseSafeIntLib\TestBaseSafeIntLib.c:35: error: Failure!
+[ FAILED ] Test SafeInt8ToUint8
+[ RUN ] Test SafeInt8ToUint16
+[ OK ] Test SafeInt8ToUint16
+[ RUN ] Test SafeInt8ToUint32
+[ OK ] Test SafeInt8ToUint32
+[ RUN ] Test SafeInt8ToUintn
+[ OK ] Test SafeInt8ToUintn
+...
+```
+
+You can also, if you are so inclined, read the output from the exact instance of the test that was run during
+`stuart_ci_build`. The ouput file can be found on a path that looks like:
+
+`Build/<Package>/HostTest/<Arch>/<TestName>.<TestSuiteName>.<Arch>.result.xml`
+
+A sample of this output looks like:
+
+```xml
+<!--
+ Excerpt taken from:
+ Build\MdePkg\HostTest\NOOPT_VS2019\X64\TestBaseSafeIntLibHost.exe.Int Safe Conversions Test Suite.X64.result.xml
+ -->
+<?xml version="1.0" encoding="UTF-8" ?>
+<testsuites>
+ <testsuite name="Int Safe Conversions Test Suite" time="0.000" tests="71" failures="1" errors="0" skipped="0" >
+ <testcase name="Test SafeInt8ToUint8" time="0.000" >
+ <failure><![CDATA[UT_ASSERT_EQUAL(0x5c:5c, Result:5b)
+c:\_uefi\MdePkg\Test\UnitTest\Library\BaseSafeIntLib\TestBaseSafeIntLib.c:35: error: Failure!]]></failure>
+ </testcase>
+ <testcase name="Test SafeInt8ToUint16" time="0.000" >
+ </testcase>
+ <testcase name="Test SafeInt8ToUint32" time="0.000" >
+ </testcase>
+ <testcase name="Test SafeInt8ToUintn" time="0.000" >
+ </testcase>
+```
+
+### XML Reporting Mode
+
+Since these applications are built using the CMocka framework, they can also use the following env variables to output
+in a structured XML rather than text:
+
+```text
+CMOCKA_MESSAGE_OUTPUT=xml
+CMOCKA_XML_FILE=<absolute or relative path to output file>
+```
+
+This mode is used by the test running plugin to aggregate the results for CI test status reporting in the web view.
+
+### Important Note
+
+This works on both Windows and Linux, but is currently limited to x64 architectures. Working on getting others, but we
+also welcome contributions.
+
+## Known Limitations
+
+### PEI, DXE, SMM
+
+While sample tests have been provided for these execution environments, only cursory build validation
+has been performed. Care has been taken while designing the frameworks to allow for execution during
+boot phases, but only UEFI Shell and host-based tests have been thoroughly evaluated. Full support for
+PEI, DXE, and SMM is forthcoming, but should be considered beta/staging for now.
+
+### Host-Based Support vs Other Tests
+
+The host-based test framework is powered internally by the Cmocka framework. As such, it has abilities
+that the target-based tests don't (yet). It would be awesome if this meant that it was a super set of
+the target-based tests, and it worked just like the target-based tests but with more features. Unfortunately,
+this is not the case. While care has been taken to keep them as close a possible, there are a few known
+inconsistencies that we're still ironing out. For example, the logging messages in the target-based tests
+are cached internally and associated with the running test case. They can be saved later as part of the
+reporting lib. This isn't currently possible with host-based. Only the assertion failures are logged.
+
+We will continue trying to make these as similar as possible.
+
+## Unit Test Location/Layout Rules
+
+Code/Test | Location
+--------- | --------
+Host-Based Unit Tests for a Library/Protocol/PPI/GUID Interface | If what's being tested is an interface (e.g. a library with a public header file, like DebugLib), the test should be scoped to the parent package.<br/>Example: `MdePkg/Test/UnitTest/[Library/Protocol/Ppi/Guid]/`<br/><br/>A real-world example of this is the BaseSafeIntLib test in MdePkg.<br/>`MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost.inf`
+Host-Based Unit Tests for a Library/Driver (PEI/DXE/SMM) implementation | If what's being tested is a specific implementation (e.g. BaseDebugLibSerialPort for DebugLib), the test should be scoped to the implementation directory itself, in a UnitTest subdirectory.<br/><br/>Module Example: `MdeModulePkg/Universal/EsrtFmpDxe/UnitTest/`<br/>Library Example: `MdePkg/Library/BaseMemoryLib/UnitTest/`
+Host-Based Tests for a Functionality or Feature | If you're writing a functional test that operates at the module level (i.e. if it's more than a single file or library), the test should be located in the package-level Tests directory under the HostFuncTest subdirectory.<br/>For example, if you were writing a test for the entire FMP Device Framework, you might put your test in:<br/>`FmpDevicePkg/Test/HostFuncTest/FmpDeviceFramework`<br/><br/>If the feature spans multiple packages, it's location should be determined by the package owners related to the feature.
+Non-Host-Based (PEI/DXE/SMM/Shell) Tests for a Functionality or Feature | Similar to Host-Based, if the feature is in one package, should be located in the `*Pkg/Test/[Shell/Dxe/Smm/Pei]Test` directory.<br/><br/>If the feature spans multiple packages, it's location should be determined by the package owners related to the feature.<br/><br/>USAGE EXAMPLES<br/>PEI Example: MP_SERVICE_PPI. Or check MTRR configuration in a notification function.<br/> SMM Example: a test in a protocol callback function. (It is different with the solution that SmmAgent+ShellApp)<br/>DXE Example: a test in a UEFI event call back to check SPI/SMRAM status. <br/> Shell Example: the SMM handler audit test has a shell-based app that interacts with an SMM handler to get information. The SMM paging audit test gathers information about both DXE and SMM. And the SMM paging functional test actually forces errors into SMM via a DXE driver.
+
+### Example Directory Tree
+
+```text
+<PackageName>Pkg/
+ ComponentY/
+ ComponentY.inf
+ ComponentY.c
+ UnitTest/
+ ComponentYHostUnitTest.inf # Host-Based Test for Driver Module
+ ComponentYUnitTest.c
+
+ Library/
+ GeneralPurposeLibBase/
+ ...
+
+ GeneralPurposeLibSerial/
+ ...
+
+ SpecificLibDxe/
+ SpecificLibDxe.c
+ SpecificLibDxe.inf
+ UnitTest/ # Host-Based Test for Specific Library Implementation
+ SpecificLibDxeHostUnitTest.c
+ SpecificLibDxeHostUnitTest.inf
+ Test/
+ <Package>HostTest.dsc # Host-Based Test Apps
+ UnitTest/
+ InterfaceX
+ InterfaceXHostUnitTest.inf # Host-Based App (should be in Test/<Package>HostTest.dsc)
+ InterfaceXPeiUnitTest.inf # PEIM Target-Based Test (if applicable)
+ InterfaceXDxeUnitTest.inf # DXE Target-Based Test (if applicable)
+ InterfaceXSmmUnitTest.inf # SMM Target-Based Test (if applicable)
+ InterfaceXShellUnitTest.inf # Shell App Target-Based Test (if applicable)
+ InterfaceXUnitTest.c # Test Logic
+
+ GeneralPurposeLib/ # Host-Based Test for any implementation of GeneralPurposeLib
+ GeneralPurposeLibTest.c
+ GeneralPurposeLibHostUnitTest.inf
+
+ <Package>Pkg.dsc # Standard Modules and any Target-Based Test Apps (including in Test/)
+
+```
+
+### Future Locations in Consideration
+
+We don't know if these types will exist or be applicable yet, but if you write a support library or module that matches the following, please make sure they live in the correct place.
+
+Code/Test | Location
+--------- | --------
+Host-Based Library Implementations | Host-Based Implementations of common libraries (eg. MemoryAllocationLibHost) should live in the same package that declares the library interface in its .DEC file in the `*Pkg/HostLibrary` directory. Should have 'Host' in the name.
+Host-Based Mocks and Stubs | Mock and Stub libraries should live in the `UefiTestFrameworkPkg/StubLibrary` with either 'Mock' or 'Stub' in the library name.
+
+### If still in doubt...
+
+Hop on GitHub and ask @corthon, @mdkinney, or @spbrogan. ;)
+
+## Copyright
+
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTest.c b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTest.c
new file mode 100644
index 00000000..1ece8090
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTest.c
@@ -0,0 +1,799 @@
+/** @file
+ This is a sample to demostrate the usage of the Unit Test Library that
+ supports the PEI, DXE, SMM, UEFI SHell, and host execution environments.
+
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include <PiPei.h>
+#include <Uefi.h>
+#include <Library/UefiLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UnitTestLib.h>
+#include <Library/PrintLib.h>
+
+#define UNIT_TEST_NAME "Sample Unit Test"
+#define UNIT_TEST_VERSION "0.1"
+
+///
+/// Global variables used in unit tests
+///
+BOOLEAN mSampleGlobalTestBoolean = FALSE;
+VOID *mSampleGlobalTestPointer = NULL;
+
+/**
+ Sample Unit-Test Prerequisite Function that checks to make sure the global
+ pointer used in the test is already set to NULL.
+
+ Functions with this prototype are registered to be dispatched by the unit test
+ framework prior to a given test case. If this prereq function returns
+ UNIT_TEST_ERROR_PREREQUISITE_NOT_MET, the test case will be skipped.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED Unit test case prerequisites
+ are met.
+ @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped.
+
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MakeSureThatPointerIsNull (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UT_ASSERT_EQUAL ((UINTN)mSampleGlobalTestPointer, (UINTN)NULL);
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample Unit-Test Cleanup (after) function that resets the global pointer to
+ NULL.
+
+ Functions with this prototype are registered to be dispatched by the
+ unit test framework after a given test case. This will be called even if the
+ test case returns an error, but not if the prerequisite fails and the test is
+ skipped. The purpose of this function is to clean up any global state or
+ test data.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED Test case cleanup succeeded.
+ @retval UNIT_TEST_ERROR_CLEANUP_FAILED Test case cleanup failed.
+
+**/
+VOID
+EFIAPI
+ClearThePointer (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ mSampleGlobalTestPointer = NULL;
+}
+
+/**
+ Sample unit test that verifies the expected result of an unsigned integer
+ addition operation.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+OnePlusOneShouldEqualTwo (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UINTN A;
+ UINTN B;
+ UINTN C;
+
+ A = 1;
+ B = 1;
+ C = A + B;
+
+ UT_ASSERT_EQUAL (C, 2);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test that verifies that a global BOOLEAN is updatable.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+GlobalBooleanShouldBeChangeable (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ mSampleGlobalTestBoolean = TRUE;
+ UT_ASSERT_TRUE (mSampleGlobalTestBoolean);
+
+ mSampleGlobalTestBoolean = FALSE;
+ UT_ASSERT_FALSE (mSampleGlobalTestBoolean);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test that logs a warning message and verifies that a global
+ pointer is updatable.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+GlobalPointerShouldBeChangeable (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ //
+ // Example of logging.
+ //
+ UT_LOG_WARNING ("About to change a global pointer! Current value is 0x%X\n", mSampleGlobalTestPointer);
+
+ mSampleGlobalTestPointer = (VOID *)-1;
+ UT_ASSERT_EQUAL ((UINTN)mSampleGlobalTestPointer, (UINTN)((VOID *)-1));
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Unit-Test Test Suite Setup (before) function that enables ASSERT() macros.
+**/
+VOID
+EFIAPI
+TestSuiteEnableAsserts (
+ VOID
+ )
+{
+ //
+ // Set BIT0 (DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED)
+ //
+ PatchPcdSet8 (PcdDebugPropertyMask, PcdGet8 (PcdDebugPropertyMask) | BIT0);
+}
+
+/**
+ Unit-Test Test Suite Setup (before) function that disables ASSERT() macros.
+**/
+VOID
+EFIAPI
+TestSuiteDisableAsserts (
+ VOID
+ )
+{
+ //
+ // Clear BIT0 (DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED)
+ //
+ PatchPcdSet8 (PcdDebugPropertyMask, PcdGet8 (PcdDebugPropertyMask) & (~BIT0));
+}
+
+/**
+ Sample unit test using the UT_ASSERT_TRUE() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtAssertTrue (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UINT64 Result;
+
+ //
+ // This test passes because expression always evaluated to TRUE.
+ //
+ UT_ASSERT_TRUE (TRUE);
+
+ //
+ // This test passes because expression always evaluates to TRUE.
+ //
+ Result = LShiftU64 (BIT0, 1);
+ UT_ASSERT_TRUE (Result == BIT1);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_ASSERT_FALSE() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtAssertFalse (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UINT64 Result;
+
+ //
+ // This test passes because expression always evaluated to FALSE.
+ //
+ UT_ASSERT_FALSE (FALSE);
+
+ //
+ // This test passes because expression always evaluates to FALSE.
+ //
+ Result = LShiftU64 (BIT0, 1);
+ UT_ASSERT_FALSE (Result == BIT0);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_ASSERT_EQUAL() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtAssertEqual (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UINT64 Result;
+
+ //
+ // This test passes because both values are always equal.
+ //
+ UT_ASSERT_EQUAL (1, 1);
+
+ //
+ // This test passes because both values are always equal.
+ //
+ Result = LShiftU64 (BIT0, 1);
+ UT_ASSERT_EQUAL (Result, BIT1);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_ASSERT_MEM_EQUAL() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtAssertMemEqual (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ CHAR8 *String1;
+ CHAR8 *String2;
+ UINTN Length;
+
+ //
+ // This test passes because String1 and String2 are the same.
+ //
+ String1 = "Hello";
+ String2 = "Hello";
+ Length = sizeof ("Hello");
+ UT_ASSERT_MEM_EQUAL (String1, String2, Length);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_ASSERT_NOT_EQUAL() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtAssertNotEqual (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UINT64 Result;
+
+ //
+ // This test passes because both values are never equal.
+ //
+ UT_ASSERT_NOT_EQUAL (0, 1);
+
+ //
+ // This test passes because both values are never equal.
+ //
+ Result = LShiftU64 (BIT0, 1);
+ UT_ASSERT_NOT_EQUAL (Result, BIT0);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_ASSERT_NOT_EFI_ERROR() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtAssertNotEfiError (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ //
+ // This test passes because the status is not an EFI error.
+ //
+ UT_ASSERT_NOT_EFI_ERROR (EFI_SUCCESS);
+
+ //
+ // This test passes because the status is not an EFI error.
+ //
+ UT_ASSERT_NOT_EFI_ERROR (EFI_WARN_BUFFER_TOO_SMALL);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_ASSERT_STATUS_EQUAL() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtAssertStatusEqual (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ //
+ // This test passes because the status value are always equal.
+ //
+ UT_ASSERT_STATUS_EQUAL (EFI_SUCCESS, EFI_SUCCESS);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_ASSERT_NOT_NULL() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtAssertNotNull (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UINT64 Result;
+
+ //
+ // This test passes because the pointer is never NULL.
+ //
+ UT_ASSERT_NOT_NULL (&Result);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_EXPECT_ASSERT_FAILURE() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtExpectAssertFailure (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ //
+ // This test passes because it directly triggers an ASSERT().
+ //
+ UT_EXPECT_ASSERT_FAILURE (ASSERT (FALSE), NULL);
+
+ //
+ // This test passes because DecimalToBcd() generates an ASSERT() if the
+ // value passed in is >= 100. The expected ASSERT() is caught by the unit
+ // test framework and UT_EXPECT_ASSERT_FAILURE() returns without an error.
+ //
+ UT_EXPECT_ASSERT_FAILURE (DecimalToBcd8 (101), NULL);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_LOG_ERROR() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtLogError (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ //
+ // Example of logging.
+ //
+ UT_LOG_ERROR ("UT_LOG_ERROR() message\n");
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_LOG_WARNING() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtLogWarning (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ //
+ // Example of logging.
+ //
+ UT_LOG_WARNING ("UT_LOG_WARNING() message\n");
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_LOG_INFO() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtLogInfo (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ //
+ // Example of logging.
+ //
+ UT_LOG_INFO ("UT_LOG_INFO() message\n");
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Sample unit test using the UT_LOG_VERBOSE() macro.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+MacroUtLogVerbose (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ //
+ // Example of logging.
+ //
+ UT_LOG_VERBOSE ("UT_LOG_VERBOSE() message\n");
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Initialize the unit test framework, suite, and unit tests for the
+ sample unit tests and run the unit tests.
+
+ @retval EFI_SUCCESS All test cases were dispatched.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
+ initialize the unit tests.
+**/
+EFI_STATUS
+EFIAPI
+UefiTestMain (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ UNIT_TEST_FRAMEWORK_HANDLE Framework;
+ UNIT_TEST_SUITE_HANDLE SimpleMathTests;
+ UNIT_TEST_SUITE_HANDLE GlobalVarTests;
+ UNIT_TEST_SUITE_HANDLE MacroTestsAssertsEnabled;
+ UNIT_TEST_SUITE_HANDLE MacroTestsAssertsDisabled;
+
+ Framework = NULL;
+
+ DEBUG(( DEBUG_INFO, "%a v%a\n", UNIT_TEST_NAME, UNIT_TEST_VERSION ));
+
+ //
+ // Start setting up the test framework for running the tests.
+ //
+ Status = InitUnitTestFramework (&Framework, UNIT_TEST_NAME, gEfiCallerBaseName, UNIT_TEST_VERSION);
+ if (EFI_ERROR (Status)) {
+ DEBUG((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
+ goto EXIT;
+ }
+
+ //
+ // Populate the SimpleMathTests Unit Test Suite.
+ //
+ Status = CreateUnitTestSuite (&SimpleMathTests, Framework, "Simple Math Tests", "Sample.Math", NULL, NULL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for SimpleMathTests\n"));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto EXIT;
+ }
+ AddTestCase (SimpleMathTests, "Adding 1 to 1 should produce 2", "Addition", OnePlusOneShouldEqualTwo, NULL, NULL, NULL);
+
+ //
+ // Populate the GlobalVarTests Unit Test Suite.
+ //
+ Status = CreateUnitTestSuite (&GlobalVarTests, Framework, "Global Variable Tests", "Sample.Globals", NULL, NULL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for GlobalVarTests\n"));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto EXIT;
+ }
+ AddTestCase (GlobalVarTests, "You should be able to change a global BOOLEAN", "Boolean", GlobalBooleanShouldBeChangeable, NULL, NULL, NULL);
+ AddTestCase (GlobalVarTests, "You should be able to change a global pointer", "Pointer", GlobalPointerShouldBeChangeable, MakeSureThatPointerIsNull, ClearThePointer, NULL);
+
+ //
+ // Populate the Macro Tests with ASSERT() enabled
+ //
+ Status = CreateUnitTestSuite (&MacroTestsAssertsEnabled, Framework, "Macro Tests with ASSERT() enabled", "Sample.MacroAssertsEnabled", TestSuiteEnableAsserts, NULL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MacroTestsAssertsEnabled\n"));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto EXIT;
+ }
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_TRUE() macro", "MacroUtAssertTrue", MacroUtAssertTrue, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_FALSE() macro", "MacroUtAssertFalse", MacroUtAssertFalse, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_EQUAL() macro", "MacroUtAssertEqual", MacroUtAssertEqual, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_MEM_EQUAL() macro", "MacroUtAssertMemEqual", MacroUtAssertMemEqual, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_NOT_EQUAL() macro", "MacroUtAssertNotEqual", MacroUtAssertNotEqual, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_NOT_EFI_ERROR() macro", "MacroUtAssertNotEfiError", MacroUtAssertNotEfiError, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_STATUS_EQUAL() macro", "MacroUtAssertStatusEqual", MacroUtAssertStatusEqual, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_ASSERT_NOT_NULL() macro", "MacroUtAssertNotNull", MacroUtAssertNotNull, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_EXPECT_ASSERT_FAILURE() macro", "MacroUtExpectAssertFailure", MacroUtExpectAssertFailure, NULL, NULL, NULL);
+
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_LOG_ERROR() macro", "MacroUtLogError", MacroUtLogError, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_LOG_WARNING() macro", "MacroUtLogWarning", MacroUtLogWarning, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_LOG_INFO() macro", "MacroUtLogInfo", MacroUtLogInfo, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsEnabled, "Test UT_LOG_VERBOSE() macro", "MacroUtLogVerbose", MacroUtLogVerbose, NULL, NULL, NULL);
+
+ //
+ // Populate the Macro Tests with ASSERT() disabled
+ //
+ Status = CreateUnitTestSuite (&MacroTestsAssertsDisabled, Framework, "Macro Tests with ASSERT() disabled", "Sample.MacroAssertsDisables", TestSuiteDisableAsserts, NULL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MacroTestsAssertsDisabled\n"));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto EXIT;
+ }
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_TRUE() macro", "MacroUtAssertTrue", MacroUtAssertTrue, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_FALSE() macro", "MacroUtAssertFalse", MacroUtAssertFalse, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_EQUAL() macro", "MacroUtAssertEqual", MacroUtAssertEqual, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_MEM_EQUAL() macro", "MacroUtAssertMemEqual", MacroUtAssertMemEqual, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_NOT_EQUAL() macro", "MacroUtAssertNotEqual", MacroUtAssertNotEqual, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_NOT_EFI_ERROR() macro", "MacroUtAssertNotEfiError", MacroUtAssertNotEfiError, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_STATUS_EQUAL() macro", "MacroUtAssertStatusEqual", MacroUtAssertStatusEqual, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_ASSERT_NOT_NULL() macro", "MacroUtAssertNotNull", MacroUtAssertNotNull, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_EXPECT_ASSERT_FAILURE() macro", "MacroUtExpectAssertFailure", MacroUtExpectAssertFailure, NULL, NULL, NULL);
+
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_LOG_ERROR() macro", "MacroUtLogError", MacroUtLogError, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_LOG_WARNING() macro", "MacroUtLogWarning", MacroUtLogWarning, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_LOG_INFO() macro", "MacroUtLogInfo", MacroUtLogInfo, NULL, NULL, NULL);
+ AddTestCase (MacroTestsAssertsDisabled, "Test UT_LOG_VERBOSE() macro", "MacroUtLogVerbose", MacroUtLogVerbose, NULL, NULL, NULL);
+
+ //
+ // Execute the tests.
+ //
+ Status = RunAllTestSuites (Framework);
+
+EXIT:
+ if (Framework) {
+ FreeUnitTestFramework (Framework);
+ }
+
+ return Status;
+}
+
+/**
+ Standard PEIM entry point for target based unit test execution from PEI.
+**/
+EFI_STATUS
+EFIAPI
+PeiEntryPoint (
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
+ )
+{
+ return UefiTestMain ();
+}
+
+/**
+ Standard UEFI entry point for target based unit test execution from DXE, SMM,
+ UEFI Shell.
+**/
+EFI_STATUS
+EFIAPI
+DxeEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return UefiTestMain ();
+}
+
+/**
+ Standard POSIX C entry point for host based unit test execution.
+**/
+int
+main (
+ int argc,
+ char *argv[]
+ )
+{
+ return UefiTestMain ();
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestDxe.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestDxe.inf
new file mode 100644
index 00000000..32c29a62
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestDxe.inf
@@ -0,0 +1,39 @@
+## @file
+# Sample UnitTest built for execution in DXE.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = SampleUnitTestDxe
+ FILE_GUID = 96BB18BD-FF2B-4B51-B683-0DC9A4BF12CF
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = DxeEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ SampleUnitTest.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiDriverEntryPoint
+ BaseLib
+ DebugLib
+ UnitTestLib
+ PrintLib
+
+[Pcd]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask
+
+[Depex]
+ TRUE
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestHost.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestHost.inf
new file mode 100644
index 00000000..4a64ab16
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestHost.inf
@@ -0,0 +1,33 @@
+## @file
+# Sample UnitTest built for execution on a Host/Dev machine.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = SampleUnitTestHost
+ FILE_GUID = CC0EA77E-BF2D-4134-B419-0C02E15CE08E
+ MODULE_TYPE = HOST_APPLICATION
+ VERSION_STRING = 1.0
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ SampleUnitTest.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ UnitTestLib
+
+[Pcd]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestPei.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestPei.inf
new file mode 100644
index 00000000..bb747f71
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestPei.inf
@@ -0,0 +1,39 @@
+## @file
+# Sample UnitTest built for execution in PEI.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = SampleUnitTestPei
+ FILE_GUID = B9BD9451-3DC8-48EA-A6F0-55753BF186F1
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ ENTRY_POINT = PeiEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ SampleUnitTest.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ PeimEntryPoint
+ BaseLib
+ DebugLib
+ UnitTestLib
+ PrintLib
+
+[Pcd]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask
+
+[Depex]
+ gEfiPeiMemoryDiscoveredPpiGuid
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestSmm.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestSmm.inf
new file mode 100644
index 00000000..46370dad
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestSmm.inf
@@ -0,0 +1,40 @@
+## @file
+# Sample UnitTest built for execution in SMM.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = SampleUnitTestSmm
+ FILE_GUID = 389B16DB-F622-424C-9000-9E43C69CBF71
+ MODULE_TYPE = DXE_SMM_DRIVER
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x0001000A
+ ENTRY_POINT = DxeEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ SampleUnitTest.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiDriverEntryPoint
+ BaseLib
+ DebugLib
+ UnitTestLib
+ PrintLib
+
+[Pcd]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask
+
+[Depex]
+ gEfiSmmCpuProtocolGuid
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestUefiShell.inf b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestUefiShell.inf
new file mode 100644
index 00000000..12fd3c0e
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestUefiShell.inf
@@ -0,0 +1,36 @@
+## @file
+# Sample UnitTest built for execution in UEFI Shell.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = SampleUnitTestUefiShell
+ FILE_GUID = 9E8F461A-17E1-4312-B49C-E66F0A88EA8B
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = DxeEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ SampleUnitTest.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ BaseLib
+ DebugLib
+ UnitTestLib
+ PrintLib
+
+[Pcd]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc
new file mode 100644
index 00000000..32c6d7a3
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc
@@ -0,0 +1,36 @@
+## @file
+# UnitTestFrameworkPkg DSC file used to build host-based unit tests.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ PLATFORM_NAME = UnitTestFrameworkPkgHostTest
+ PLATFORM_GUID = C7F97D6D-54AC-45A9-8197-CC99B20CC7EC
+ PLATFORM_VERSION = 0.1
+ DSC_SPECIFICATION = 0x00010005
+ OUTPUT_DIRECTORY = Build/UnitTestFrameworkPkg/HostTest
+ SUPPORTED_ARCHITECTURES = IA32|X64
+ BUILD_TARGETS = NOOPT
+ SKUID_IDENTIFIER = DEFAULT
+
+!include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
+
+[PcdsPatchableInModule]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17
+
+[Components]
+ #
+ # Build HOST_APPLICATION that tests the SampleUnitTest
+ #
+ UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestHost.inf
+
+ #
+ # Build HOST_APPLICATION Libraries
+ #
+ UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
+ UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf
+ UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf
+ UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml
new file mode 100644
index 00000000..14876275
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml
@@ -0,0 +1,97 @@
+## @file
+# CI configuration for UnitTestFrameworkPkg
+#
+# Copyright (c) Microsoft Corporation
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+{
+ ## options defined .pytool/Plugin/LicenseCheck
+ "LicenseCheck": {
+ "IgnoreFiles": []
+ },
+ "EccCheck": {
+ ## Exception sample looks like below:
+ ## "ExceptionList": [
+ ## "<ErrorID>", "<KeyWord>"
+ ## ]
+ "ExceptionList": [
+ ],
+ ## Both file path and directory path are accepted.
+ "IgnoreFiles": [
+ "Library/CmockaLib/cmocka"
+ ]
+ },
+ ## options defined .pytool/Plugin/CompilerPlugin
+ "CompilerPlugin": {
+ "DscPath": "UnitTestFrameworkPkg.dsc"
+ },
+ ## options defined .pytool/Plugin/HostUnitTestCompilerPlugin
+ "HostUnitTestCompilerPlugin": {
+ "DscPath": "Test/UnitTestFrameworkPkgHostTest.dsc"
+ },
+ ## options defined .pytool/Plugin/CharEncodingCheck
+ "CharEncodingCheck": {
+ "IgnoreFiles": []
+ },
+
+ ## options defined .pytool/Plugin/DependencyCheck
+ "DependencyCheck": {
+ "AcceptableDependencies": [
+ "MdePkg/MdePkg.dec",
+ "UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec"
+ ],
+ # For host based unit tests
+ "AcceptableDependencies-HOST_APPLICATION":[],
+ # For UEFI shell based apps
+ "AcceptableDependencies-UEFI_APPLICATION":[
+ "MdeModulePkg/MdeModulePkg.dec",
+ "ShellPkg/ShellPkg.dec"
+ ],
+ "IgnoreInf": []
+ },
+ ## options defined .pytool/Plugin/DscCompleteCheck
+ "DscCompleteCheck": {
+ "DscPath": "UnitTestFrameworkPkg.dsc",
+ "IgnoreInf": []
+ },
+ ## options defined .pytool/Plugin/HostUnitTestDscCompleteCheck
+ "HostUnitTestDscCompleteCheck": {
+ "IgnoreInf": [],
+ "DscPath": "Test/UnitTestFrameworkPkgHostTest.dsc"
+ },
+ ## options defined .pytool/Plugin/GuidCheck
+ "GuidCheck": {
+ "IgnoreGuidName": [],
+ "IgnoreGuidValue": [],
+ "IgnoreFoldersAndFiles": [],
+ "IgnoreDuplicates": []
+ },
+ ## options defined .pytool/Plugin/LibraryClassCheck
+ "LibraryClassCheck": {
+ "IgnoreHeaderFile": []
+ },
+
+ ## options defined .pytool/Plugin/SpellCheck
+ "SpellCheck": {
+ "AuditOnly": False, # Fails test but run in AuditOnly mode to collect log
+ "IgnoreFiles": [ # use gitignore syntax to ignore errors in matching files
+ "Library/CmockaLib/cmocka/**/*.*" # not going to spell check a submodule
+ ],
+ "ExtendWords": [ # words to extend to the dictionary for this package
+ "testcase",
+ "testsuites",
+ "cmocka",
+ "buildmodule",
+ "criterium",
+ "pytool",
+ "pytools",
+ "NOFAILURE",
+ "DHAVE", # build flag for cmocka in the INF
+ "corthon", # Contact GitHub account in Readme
+ "mdkinney", # Contact GitHub account in Readme
+ "spbrogan" # Contact GitHub account in Readme
+ ],
+ "IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore
+ "AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported)
+ }
+}
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
new file mode 100644
index 00000000..c6009c53
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
@@ -0,0 +1,50 @@
+## @file
+# This Package provides all definitions (including functions, MACROs,
+# structures library classes, and PCDs) and libraries instances, which are used
+# to support unit testing and interface testing.
+#
+# Copyright (c) Microsoft Corporation.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ DEC_SPECIFICATION = 0x00010005
+ PACKAGE_NAME = UnitTestFrameworkPkg
+ PACKAGE_UNI_FILE = UnitTestFrameworkPkg.uni
+ PACKAGE_GUID = 4A70C4A0-D72C-4D3F-9943-BE7C41C50BA3
+ PACKAGE_VERSION = 1.00
+
+[Includes]
+ Library/CmockaLib/cmocka/include
+
+[Includes.Common.Private]
+ PrivateInclude
+ Library/CmockaLib/cmocka/include/cmockery
+
+[LibraryClasses.Common.Private]
+ ## @libraryclass Allows save and restore unit test internal state
+ #
+ UnitTestPersistenceLib|PrivateInclude/Library/UnitTestPersistenceLib.h
+
+ ## @libraryclass Provides a unit test result report
+ #
+ UnitTestResultReportLib|PrivateInclude/Library/UnitTestResultReportLib.h
+
+ ## @libraryclass Provides boot-option routines useful in shell-based tests.
+ #
+ UnitTestBootLib|PrivateInclude/Library/UnitTestBootLib.h
+
+[Guids]
+ gUnitTestFrameworkPkgTokenSpaceGuid = { 0x833d3aba, 0x39b4, 0x43a2, { 0xb9, 0x30, 0x7a, 0x34, 0x53, 0x39, 0x31, 0xb3 } }
+
+[PcdsFixedAtBuild]
+ ## This flag is used to control build time optimization based on unit test
+ # log level. The default value is 0xFFFFFFFF to enable all unit test log
+ # messages.
+ # BIT0 - Error unit test log messages.<BR>
+ # BIT1 - Warning unit test log messages.<BR>
+ # BIT2 - Informational unit test log messages.<BR>
+ # BIT3 - Verbose unit test log messages.<BR>
+ # @Prompt Unit Test Log Message Level
+ gUnitTestFrameworkPkgTokenSpaceGuid.PcdUnitTestLogLevel|0xFFFFFFFF|UINT32|0x00000001
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc
new file mode 100644
index 00000000..b49bde9e
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc
@@ -0,0 +1,40 @@
+## @file
+# UnitTestFrameworkPkg
+#
+# Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ PLATFORM_NAME = UnitTestFrameworkPkg
+ PLATFORM_GUID = 7420CC7E-334E-4EFF-B974-A39613455168
+ PLATFORM_VERSION = 1.00
+ DSC_SPECIFICATION = 0x00010005
+ OUTPUT_DIRECTORY = Build/UnitTestFrameworkPkg
+ SUPPORTED_ARCHITECTURES = IA32|X64|ARM|AARCH64|RISCV64
+ BUILD_TARGETS = DEBUG|RELEASE|NOOPT
+ SKUID_IDENTIFIER = DEFAULT
+
+!include UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc
+!include MdePkg/MdeLibs.dsc.inc
+
+[PcdsPatchableInModule]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17
+
+[Components]
+ UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf
+ UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.inf
+ UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.inf
+ UnitTestFrameworkPkg/Library/UnitTestBootLibNull/UnitTestBootLibNull.inf
+ UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.inf
+ UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsbClass.inf
+ UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/UnitTestPersistenceLibSimpleFileSystem.inf
+ UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
+
+ UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestDxe.inf
+ UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestPei.inf
+ UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestSmm.inf
+ UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestUefiShell.inf
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.uni b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.uni
new file mode 100644
index 00000000..180675ae
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkg.uni
@@ -0,0 +1,21 @@
+// /** @file
+// This Package provides all definitions (including functions, MACROs,
+// structures library classes, and PCDs) and libraries instances, which are used
+// to support unit testing and interface testing.
+//
+// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_PACKAGE_ABSTRACT #language en-US "This Package provides all definitions (including functions, MACROs, structures library classes, and PCDs) and libraries instances, which are used to support unit testing and interface testing."
+
+#string STR_PACKAGE_DESCRIPTION #language en-US "This Package provides all definitions (including functions, MACROs, structures library classes, and PCDs) and libraries instances, which are used to support unit testing and interface testing."
+
+#string STR_gUnitTestFrameworkPkgTokenSpaceGuid_PcdUnitTestLogLevel_PROMPT #language en-US "Unit Test Log Message Level"
+
+#string STR_gUnitTestFrameworkPkgTokenSpaceGuid_PcdUnitTestLogLevel_HELP #language en-US "This flag is used to control build time optimization based on unit test log level. The default value is 0xFFFFFFFF to enable all unit test log messages.<BR><BR>\n"
+ "BIT0 - Error unit test log messages.<BR>\n"
+ "BIT1 - Warning unit test log messages.<BR>\n"
+ "BIT2 - Informational unit test log messages.<BR>\n"
+ "BIT3 - Verbose unit test log messages.<BR>\n"
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
new file mode 100644
index 00000000..dbeb5f60
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
@@ -0,0 +1,65 @@
+## @file
+# UnitTestFrameworkPkg DSC include file for host based test DSC
+#
+# Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+!include UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc
+
+[LibraryClasses.common.HOST_APPLICATION]
+ BaseLib|MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
+ UnitTestHostBaseLib|MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
+ CpuLib|MdePkg/Library/BaseCpuLibNull/BaseCpuLibNull.inf
+ CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLibNull/BaseCacheMaintenanceLibNull.inf
+ CmockaLib|UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
+ UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf
+ DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf
+ MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf
+
+[BuildOptions]
+ GCC:*_*_*_CC_FLAGS = -fno-pie
+!ifdef $(UNIT_TESTING_DEBUG)
+ MSFT:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1
+ GCC:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1
+ XCODE:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1
+!endif
+
+[BuildOptions.common.EDKII.HOST_APPLICATION]
+ #
+ # MSFT
+ #
+ MSFT:*_*_*_DLINK_FLAGS == /out:"$(BIN_DIR)\$(BASE_NAME).exe" /pdb:"$(BIN_DIR)\$(BASE_NAME).pdb" /IGNORE:4001 /NOLOGO /SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /NODEFAULTLIB:libcmt.lib libcmtd.lib
+ MSFT:*_*_IA32_DLINK_FLAGS = /MACHINE:I386
+ MSFT:*_*_X64_DLINK_FLAGS = /MACHINE:AMD64
+
+ MSFT:*_VS2015_IA32_DLINK_FLAGS = /LIBPATH:"%VS2015_PREFIX%Lib" /LIBPATH:"%VS2015_PREFIX%VC\Lib" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x86" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x86"
+ MSFT:*_VS2015x86_IA32_DLINK_FLAGS = /LIBPATH:"%VS2015_PREFIX%Lib" /LIBPATH:"%VS2015_PREFIX%VC\Lib" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x86" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x86"
+ MSFT:*_VS2017_IA32_DLINK_FLAGS = /LIBPATH:"%VCToolsInstallDir%lib\x86" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x86" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x86"
+ MSFT:*_VS2019_IA32_DLINK_FLAGS = /LIBPATH:"%VCToolsInstallDir%lib\x86" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x86" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x86"
+
+ MSFT:*_VS2015_X64_DLINK_FLAGS = /LIBPATH:"%VS2015_PREFIX%VC\Lib\AMD64" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x64" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x64"
+ MSFT:*_VS2015x86_X64_DLINK_FLAGS = /LIBPATH:"%VS2015_PREFIX%VC\Lib\AMD64" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x64" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x64"
+ MSFT:*_VS2017_X64_DLINK_FLAGS = /LIBPATH:"%VCToolsInstallDir%lib\x64" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x64" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x64"
+ MSFT:*_VS2019_X64_DLINK_FLAGS = /LIBPATH:"%VCToolsInstallDir%lib\x64" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x64" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x64"
+
+ #
+ # GCC
+ #
+ GCC:*_*_IA32_DLINK_FLAGS == -o $(BIN_DIR)/$(BASE_NAME) -m32 -no-pie
+ GCC:*_*_X64_DLINK_FLAGS == -o $(BIN_DIR)/$(BASE_NAME) -m64 -no-pie
+ GCC:*_*_*_DLINK2_FLAGS == -lgcov
+
+ #
+ # Need to do this link via gcc and not ld as the pathing to libraries changes from OS version to OS version
+ #
+ XCODE:*_*_IA32_DLINK_PATH == gcc
+ XCODE:*_*_IA32_CC_FLAGS = -I$(WORKSPACE)/EmulatorPkg/Unix/Host/X11IncludeHack
+ XCODE:*_*_IA32_DLINK_FLAGS == -arch i386 -o $(BIN_DIR)/Host -L/usr/X11R6/lib -lXext -lX11 -framework Carbon
+ XCODE:*_*_IA32_ASM_FLAGS == -arch i386 -g
+
+ XCODE:*_*_X64_DLINK_PATH == gcc
+ XCODE:*_*_X64_DLINK_FLAGS == -o $(BIN_DIR)/Host -L/usr/X11R6/lib -lXext -lX11 -framework Carbon -Wl,-no_pie
+ XCODE:*_*_X64_ASM_FLAGS == -g
+ XCODE:*_*_X64_CC_FLAGS = -O0 -target x86_64-apple-darwin -I$(WORKSPACE)/EmulatorPkg/Unix/Host/X11IncludeHack "-DEFIAPI=__attribute__((ms_abi))"
diff --git a/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc
new file mode 100644
index 00000000..b014914f
--- /dev/null
+++ b/src/VBox/Devices/EFI/Firmware/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc
@@ -0,0 +1,62 @@
+## @file
+# UnitTestFrameworkPkg DSC include file for target based test DSC
+#
+# Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[LibraryClasses]
+ #
+ # Entry point
+ #
+ PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
+ UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+ UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
+
+ BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
+ BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+ DebugLib|MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+ ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
+ DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
+ MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
+ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf
+ PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
+ PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
+ UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+
+ UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf
+ UnitTestPersistenceLib|UnitTestFrameworkPkg/Library/UnitTestPersistenceLibNull/UnitTestPersistenceLibNull.inf
+ UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibDebugLib.inf
+ NULL|UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
+
+[LibraryClasses.ARM, LibraryClasses.AARCH64]
+ #
+ # It is not possible to prevent ARM compiler calls to generic intrinsic functions.
+ # This library provides the instrinsic functions generated by a given compiler.
+ # [LibraryClasses.ARM] and NULL mean link this library into all ARM images.
+ #
+ NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+
+ #
+ # Since software stack checking may be heuristically enabled by the compiler
+ # include BaseStackCheckLib unconditionally.
+ #
+ NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
+
+[LibraryClasses.common.PEIM]
+ HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
+ MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
+ PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
+
+[LibraryClasses.common.UEFI_APPLICATION]
+ UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.inf
+
+[PcdsFixedAtBuild]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17
+
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES -D EDKII_UNIT_TEST_FRAMEWORK_ENABLED
+ GCC:*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES -D EDKII_UNIT_TEST_FRAMEWORK_ENABLED
+ XCODE:*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES -D EDKII_UNIT_TEST_FRAMEWORK_ENABLED