summaryrefslogtreecommitdiff
path: root/UnitTestFrameworkPkg/Library
AgeCommit message (Collapse)AuthorFilesLines
2024-02-14UnitTestFrameworkPkg/UnitTestDebugAssertLib: Add GoogleTest supportMichael D Kinney3-0/+110
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4683 Add an C++ implementation of UnitTestDebugAssert() API for host-based environments. GoogleTest based environments throw a C++ exception of type std::runtime_error when an ASSERT() is triggered with a description that contains the filename, line number, and the expression that triggered the ASSERT(). Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
2024-02-14UnitTestFrameworkPkg/UnitTestLib: GetActiveFrameworkHandle() no ASSERT()Michael D Kinney5-2/+12
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4683 Update GetActiveFrameworkHandle() to remove ASSERT() and require caller to check for NULL. This allows GetActiveFrameworkHandle() to be used to determine if the current host-based test environment is framework/cmocka or gtest. In the framework/cmocka host-based environment GetActiveFrameworkHandle() returns non-NULL. In the gtest host-based environment GetActiveFrameworkHandle() returns NULL. Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
2024-02-14UnitTestFrameworkPkg: Expand host-based exception handling and gcovMichael D Kinney1-3/+3
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4683 Update MSFT CC_FLAGS for host-based unit tests to use /EHs instead of /EHsc to support building C functions with SEH (Structured Exception Handling) enabled. This is required to build UnitTestDebugAssertLibHost.inf. Update GCC CC_FLAGS for host-based unit tests to use -fexceptions to support catching exceptions. Update GoogleTestLib.h to include Throws() APIs that enable unit tests to use EXPECT_THAT() to check for expected ASSERT() conditions for a specific ASSERT() expression. Update GCC CC_FLAGS to add --coverage for host-based builds for all GCC tool chains. Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
2024-02-14UnitTestFrameworkPkg: MSFT CC_FLAGS add /MT to for host buildsMichael D Kinney1-1/+1
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4683 Add /MT to MSFT CC_FLAGS to always use release libraries when building host-based unit tests so any exceptions generated during host-based test execution generate an error message in stderr instead of a popup window. Use /MTd when -D UNIT_TESTING_DEBUG is to use debug libraries when building host-based unit tests so any exceptions generated during host-based test execution generate a popup window with option to attach a debugger. Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
2023-07-20UnitTestFrameworkPkg: UnitTestPersistenceLib: Save Unit Test Cache OptionKun Qin1-75/+157
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4467 Current implementation of UnitTestFrameworkPkg for shell-based unit test will save the unit test cache to the same volume as the test application itself. This works as long as the test application is on a writable volume, such as USB or EFI partition. Instead of saving the files to the same file system of unit test application, this change will save the cache file to the path where the user ran this test application. This change then added an input argument to allow user to specify where to save such cache file through `--CachePath` shell argument to allow even more flexibility. This change was tested on proprietary physical hardware platforms and QEMU based virtual platform. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Kun Qin <kuqin12@gmail.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2023-06-13UnitTestFrameworkPkg: Add UnitTestPeiServicesTablePointerLibZhiguang Liu7-0/+1959
This library supports a PeiServicesTablePointerLib implementation that allows code dependent upon PeiServicesTable to operate in an isolated execution environment such as within the context of a host-based unit test framework. The unit test should initialize the PeiServicesTable database with any required elements (e.g. PPIs, Hob etc.) prior to the services being invoked by code under test. It is strongly recommended to clean any global databases by using EFI_PEI_SERVICES.ResetSystem2 after every unit test so the tests execute in a predictable manner from a clean state. Cc: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
2023-04-10UnitTestFrameworkPkg: Update to be more C11 compliant by using __func__Rebecca Cran7-25/+25
__FUNCTION__ is a pre-standard extension that gcc and Visual C++ among others support, while __func__ was standardized in C99. Since it's more standard, replace __FUNCTION__ with __func__ throughout UnitTestFrameworkPkg. Signed-off-by: Rebecca Cran <rebecca@bsdio.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
2023-04-10UnitTestFrameworkPkg: Add gmock support to GoogleTestLibChris Johnson6-16/+59
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389 * Add gmock support to GoogleTestLib * Add FunctionMockLib library class and library instance * Add GoogleTest extension to GoogleTestLib.h for CHAR16 type * Add GoogleTest extension to GoogleTestLib.h for buffer types * HOST_APPLICATION only supports IA32/X64 Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Chris Johnson <chris.n.johnson@intel.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Oliver Smith-Denny <osde@linux.microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2023-04-10UnitTestFrameworkPkg: Add subhook submodule required for gmockChris Johnson3-0/+42
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389 Add subhook submodule that is required to hook internal functions when using gmock. https://github.com/Zeex/subhook Add SubhookLib library class and SubhookLib library instance. Include the SUBHOOK_STATIC define in the SubhookLib INF file so it builds as a static library. Also include the SUBHOOK_STATIC define in SubhookLib.h so all modules using SubhookLib properly link SubhookLib as a static library. Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <quic_llindhol@quicinc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Chris Johnson <chris.n.johnson@intel.com> Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Oliver Smith-Denny <osde@linux.microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2022-12-14UnitTestFrameworkPkg/UnitTestLib: Print expected Status on ASSERT faildevel@edk2.groups.io1-1/+1
Update the UnitTestAssertStatusEqual error message to print out the expected value in addition to the seen value. Signed-off-by: Jeshua Smith <jeshuas@nvidia.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2022-12-14UnitTestFrameworkPkg: Modify APIs in UnitTestPersistenceLibLiu, Zhiguang3-13/+27
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4183 UnitTestPersistenceLib now consumes private struct definition. Modify APIs in UnitTestPersistenceLib to make it easy to become a public library. Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
2022-11-11UnitTestFrameworkPkg/Library/CmockaLib: Generate symbol informationMichael D Kinney1-1/+1
Add /Zi to CC_FLAGS in CmockaLib.inf to enable symbol information Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com>
2022-11-11UnitTestFrameworkPkg: Add googletest submodule and GoogleTestLibMichael D Kinney3-0/+50
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134 Add submodule for googletest and add GoogleTestLib that is required for GoogleTest based unit tests. Add GoogleTest documentation to Readme.md along with a port of the sample unit test to the GoogleTest style. A few typos in Readme.md are also fixed. Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <quic_llindhol@quicinc.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com> Acked-by: Leif Lindholm <quic_llindhol@quicinc.com>
2022-11-07UnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLibMichael Kubacki11-0/+3718
This library supports a Boot Services table library implementation that allows code dependent upon UefiBootServicesTableLib to operate in an isolated execution environment such as within the context of a host-based unit test framework. The unit test should initialize the Boot Services database with any required elements (e.g. protocols, events, handles, etc.) prior to the services being invoked by code under test. It is strongly recommended to clean any global databases (e.g. protocol, event, handles, etc.) after every unit test so the tests execute in a predictable manner from a clean state. This library is being moved here from PrmPkg so it can be made more generally available to other packages and improved upon for others use. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2021-12-07UnitTestFrameworkPkg: Apply uncrustify changesMichael Kubacki15-223/+278
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the UnitTestFrameworkPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>
2021-12-07UnitTestFrameworkPkg: Change OPTIONAL keyword usage styleMichael D Kinney2-2/+2
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3760 Update all use of ', OPTIONAL' to ' OPTIONAL,' for function params. Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael Kubacki <michael.kubacki@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>
2021-05-04UnitTestFrameworkPkg: Sample unit test hangs when running in OVMF/QEMUGetnat Ejigu4-0/+4
Sample unit tests in UnitTestFrameworkPkg hangs when running in OVMF/QEMU environment. Build target is X64/GCC5. Fixing this issue by adding EFIAPI to ReportPrint() function that use VA_ARGS. Signed-off-by: Getnat Ejigu <getnatejigu@gmail.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2020-12-05UnitTestFrameworkPg: Fix build failure of MdeModulePkg with UnitTestLibDivneil Rai Wadhawan1-1/+1
o LIBRARY_CLASS for UnitTestLib has been extended to support the classes required in building of MdeModulePkg Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Divneil Rai Wadhawan <divneil.r.wadhawan@intel.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2020-07-15UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()Michael D Kinney7-44/+298
REF: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2801 Add UnitTestDebugAssertLib that provides the UnitTestDebugAssert() service and the gUnitTestExpectAssertFailureJumpBuffer global variable. This NULL library is linked against all host and target unit test builds. This guarantees that the UnitTestDebugAssert() service is available to link against all libraries and modules that use the DebugLib class. EDKII_UNIT_TEST_FRAMEWORK_ENABLED must always be defined when building unit tests so the behavior of the DebugLib ASSERT() macros can be adjusted to allow the unit test framework to catch an ASSERT() if it is triggered by a function under test. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com>
2020-07-15UnitTestFrameworkPkg/UnitTestLib: Fix target mode log messagesMichael D Kinney1-32/+32
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2806 Update the log messages generated in target mode to use FileName instead of FunctionName. FunctionName is an empty string so the log messages generated do not provide enough information to know the source of a unit test failure. Using FileName combined with LineNumber provides the right information to identify the location of a unit test failure. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com>
2020-07-15UnitTestFrameworkPkg/UnitTestLib: Move print log into cleanupMichael D Kinney1-17/+16
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2805 If a unit test fails with an exception or an assert, then the CmockaUnitTestFunctionRunner() is terminated and the logic that follows the invocation of the unit test is skipped. This currently skips the logic that prints log messages. Move the print of log messages to the end of the function CmockaUnitTestTeardownFunctionRunner() that is guaranteed to be executed when a unit test completes normally or is terminated with an exception or an assert. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com>
2020-06-14UnitTestFrameworkPkg/UnitTestLib: Update SaveFrameworkState() signatureMichael Kubacki2-11/+16
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2612 Removes the FrameworkHandle parameter from SaveFrameworkState() in the UnitTestLib library instance and updates callers of the function in the library to use the new function signature. Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2020-05-27UnitTestFrameworkPkg/UnitTestResultReportLib: Use AsciiStrnCpyS()Michael Kubacki2-2/+2
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2721 The ReportOutput() function in UnitTestResultReportLib copies characters from a function input buffer to an intermediate local buffer in fixed size chunks of the maximum size of the intermediate buffer. The implementation currently calls AsciiStrCpyS() which will ASSERT on an error. This commit changes the call to AsciiStrnCpyS() to avoid the ASSERT which is not expected in the usage of the string copy in this implementation. Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>
2020-04-26UnitTestFrameworkPkg/UnitTestLib: Correct dereferred pointerkuqin1-3/+1
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2609 SavedState is not sticky, copied pointer update will not change source pointer Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Guomin Jiang <guomin.jiang@intel.com> Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>
2020-04-26UnitTestFrameworkPkg/PersistenceLib: Correct the allocated size.Guomin Jiang1-1/+1
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2608 According to logic and the practice, it is need to allocate ascii length by 2 for unicode string. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Guomin Jiang <guomin.jiang@intel.com> Reviewed-by: Sean Brogan <sean.brogan@microsoft.com>
2020-03-27UnitTestFrameworkPkg/ResultReportLib: Remove invalid index string indicatorGuomin Jiang1-2/+2
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2535 The UNIT_TEST_STATUS and FAILURE_TYPE have used 0 as status, so use 0 as unknown is confused, remove it from array enumeration but keep it location in the array. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Guomin Jiang <guomin.jiang@intel.com> Reviewed-by: Shenglei Zhang <shenglei.zhang@intel.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>
2020-03-27UnitTestFrameworkPkg/UnitTestLib: Check Suite pointer before use.GuoMinJ2-4/+4
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2530 The Suite pointer is used before check if it is valid, correct it to check the validation before use. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: GuoMinJ <newexplorerj@gmail.com> Reviewed-by: Shenglei Zhang <shenglei.zhang@intel.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>
2020-02-11UnitTestFrameworkPkg/UnitTestLib: Fix XCODE parenthesis issuesMichael D Kinney2-4/+4
https://bugzilla.tianocore.org/show_bug.cgi?id=2512 Remove extra sets of parenthesis that generate warnings on XCODE5 builds. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Sean Brogan <sean.brogan@microsoft.com>
2020-02-07UnitTestFrameworkPkg/Library: Add library instancesMichael D Kinney38-0/+4689
https://bugzilla.tianocore.org/show_bug.cgi?id=2505 Add the following library instances that are used to build unit tests for host and target environments. * CmockaLib with cmocka submodule to: https://git.cryptomilk.org/projects/cmocka.git * DebugLibPosix - Instance of DebugLib based on POSIX APIs (e.g. printf). * MemoryAllocationLibPosix - Instance of MemoryAllocationLib based on POSIX APIs (e.g. malloc/free). * UnitTestBootLibNull - Null instance of the UnitTestBootLib * UnitTestBootLibUsbClass - UnitTestBootLib instances that supports setting boot next to a USB device. * UnitTestLib - UnitTestLib instance that is designed to work with PEI, DXE, SMM, and UEFI Shell target environments. * UnitTestLibCmocka - UintTestLib instance that uses cmocka APIs and can only be use in a host environment. * UnitTestPersistenceLibNull - Null instance of the UnitTestPersistenceLib * UnitTestPersistenceLibSimpleFileSystem - UnitTestPersistenceLib instance that can safe the unit test framework state to a media device that supports the UEFI Simple File System Protocol. * UnitTestResultReportLibConOut - UnitTestResultReportLib instance that sends report results to the UEFI standard output console. * UnitTestResultReportLibDebugLib - UnitTestResultReportLib instance that sends report results to a DebugLib using DEBUG() macros. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com>