-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Introducing host based unit tests on AArch64 systems #12070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
805c3f4
c4b7d8f
2309302
da19c08
7cbbff3
197b990
6951758
ea5b2a6
2692a0e
1cceca5
9cbd65a
37c8dca
77a476d
b501bb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ## @file | ||
| # DBG2 Table Generator | ||
| # | ||
| # Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.<BR> | ||
| # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: BSD-2-Clause-Patent | ||
| ## | ||
|
|
||
| [Defines] | ||
| INF_VERSION = 0x00010019 | ||
| BASE_NAME = AcpiDbg2Lib | ||
| FILE_GUID = A9C39504-531B-49E1-B639-25A86B85DAA1 | ||
| VERSION_STRING = 1.0 | ||
| MODULE_TYPE = DXE_DRIVER | ||
| LIBRARY_CLASS = NULL|HOST_APPLICATION | ||
| CONSTRUCTOR = AcpiDbg2LibConstructor | ||
| DESTRUCTOR = AcpiDbg2LibDestructor | ||
|
|
||
| [Sources] | ||
| Dbg2Generator.c | ||
| Dbg2Generator.h | ||
| Dbg2GeneratorNull.c | ||
|
|
||
| [Packages.ARM, Packages.AARCH64] | ||
| ArmPlatformPkg/ArmPlatformPkg.dec | ||
|
|
||
| [Packages] | ||
| MdePkg/MdePkg.dec | ||
| MdeModulePkg/MdeModulePkg.dec | ||
| EmbeddedPkg/EmbeddedPkg.dec | ||
| DynamicTablesPkg/DynamicTablesPkg.dec | ||
|
|
||
| [LibraryClasses] | ||
| BaseLib | ||
| PrintLib | ||
| SsdtSerialPortFixupLib | ||
|
|
||
| [FixedPcd] | ||
| gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate | ||
| gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits | ||
| gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity | ||
| gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** @file | ||
| IA32/X64 specific Unit Test Host functions. | ||
|
|
||
| Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> | ||
| Copyright (c), Microsoft Corporation. | ||
| SPDX-License-Identifier: BSD-2-Clause-Patent | ||
|
|
||
| **/ | ||
|
|
||
| #include "UnitTestHost.h" | ||
|
|
||
| /// | ||
| /// Common services | ||
| /// | ||
| STATIC UNIT_TEST_HOST_BASE_LIB_COMMON mUnitTestHostBaseLibCommon = { | ||
| UnitTestHostBaseLibEnableInterrupts, | ||
| UnitTestHostBaseLibDisableInterrupts, | ||
| UnitTestHostBaseLibEnableDisableInterrupts, | ||
| UnitTestHostBaseLibGetInterruptState, | ||
| }; | ||
|
|
||
| /// | ||
| /// Structure of hook functions for BaseLib functions that can not be used from | ||
| /// a host application. A simple emulation of these function is provided by | ||
| /// default. A specific unit test can provide its own implementation for any | ||
| /// of these functions. | ||
| /// | ||
| UNIT_TEST_HOST_BASE_LIB gUnitTestHostBaseLib = { | ||
| &mUnitTestHostBaseLibCommon | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ | |
|
|
||
| [LibraryClasses] | ||
| GoogleTestLib | ||
|
|
||
| [LibraryClasses.IA32, LibraryClasses.X64] | ||
| SubhookLib | ||
|
|
||
| [Packages] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -544,28 +544,6 @@ TEST (SanitizerTests, InvalidPointerWriteDeathTest) { | |
| EXPECT_DEATH (*(volatile UINT8 *)(-1) = 0, "ERROR: AddressSanitizer: "); | ||
| } | ||
|
|
||
| UINTN | ||
| DivideWithNoParameterChecking ( | ||
| UINTN Dividend, | ||
| UINTN Divisor | ||
| ) | ||
| { | ||
| // | ||
| // Perform integer division with no check for divide by zero | ||
| // | ||
| return (Dividend / Divisor); | ||
| } | ||
|
|
||
| /** | ||
| Sample unit test that performs a divide by 0 | ||
| **/ | ||
| TEST (SanitizerTests, DivideByZeroDeathTest) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that the same division by 0 test exists in: The test should generate an exception, but instead it should fail as the result is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left this feedback out for this round of push. The test is intended to generate an exception, but divide by 0 will not trip on any exception on AArch64 platforms. Should we switch to read from a null pointer instead in this case? @mdkinney any thoughts? On the other hand, this test is not included in the unit test dsc file, so we do not have obvious way to mark this test as x86 specific, other than the inf's supported architecture, which is already configured as such.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Most of this file can work for all archs. Just this one test should be broken out into an x86 only cpp file and INF updated with main cpp file for all archs and the one special cpp file for IA32/X64 only. |
||
| // | ||
| // Divide by 0 should be caught by address sanitizer, log details, and exit | ||
| // | ||
| EXPECT_DEATH (DivideWithNoParameterChecking (10, 0), "ERROR: AddressSanitizer: "); | ||
| } | ||
|
|
||
| /** | ||
| Sample unit test that allocates and frees buffers below 4GB | ||
| **/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /** @file | ||
| This is a sample to demonstrates the use of GoogleTest that supports host | ||
| execution environments. | ||
|
|
||
| Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> | ||
| SPDX-License-Identifier: BSD-2-Clause-Patent | ||
|
|
||
| **/ | ||
|
|
||
| #include <Library/GoogleTestLib.h> | ||
| extern "C" { | ||
| #include <Uefi.h> | ||
| #include <Library/BaseLib.h> | ||
| #include <Library/DebugLib.h> | ||
| #include <Library/MemoryAllocationLib.h> | ||
| #include <Library/HostMemoryAllocationBelowAddressLib.h> | ||
| } | ||
|
|
||
| UINTN | ||
| DivideWithNoParameterChecking ( | ||
| UINTN Dividend, | ||
| UINTN Divisor | ||
| ) | ||
| { | ||
| // | ||
| // Perform integer division with no check for divide by zero | ||
| // | ||
| return (Dividend / Divisor); | ||
| } | ||
|
|
||
| /** | ||
| Sample unit test that performs a divide by 0 | ||
| **/ | ||
| TEST (SanitizerTests, DivideByZeroDeathTest) { | ||
| // | ||
| // Divide by 0 should be caught by address sanitizer, log details, and exit | ||
| // | ||
| EXPECT_DEATH (DivideWithNoParameterChecking (10, 0), "ERROR: AddressSanitizer: "); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT:
It seems that this patch does 2 things:
Maybe this patch should be split in 2 and also remove the following unused sections:
NIT2:
The following function are not supported by the UnitTestHost BaseLib implementation:
It doesn't seem it is required right now and it will still be possible to add it later if needed, so just making a note of it.
NIT3:
Also, the
VALID_ARCHITECTURESmight be updated to add AARCH64There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comments and testing this.
I have updated this patch per your feedback. Specifically, I split the majority of the inf change into a separate commit and also removed the EBC and RISCV sections.
It was a good callout, but I did not add the CntPctReg and IdAA64Isar0Reg support in this patch set. I would like to add the timer related changes in a separate PR to resolve the lack of timer support on host-based tests. But please let me know if you have other thoughts.