Skip to content

Introducing host based unit tests on AArch64 systems#12070

Open
kuqin12 wants to merge 14 commits intotianocore:masterfrom
kuqin12:arm64_test
Open

Introducing host based unit tests on AArch64 systems#12070
kuqin12 wants to merge 14 commits intotianocore:masterfrom
kuqin12:arm64_test

Conversation

@kuqin12
Copy link
Copy Markdown
Contributor

@kuqin12 kuqin12 commented Jan 28, 2026

Description

This change adds the support for building and running host based unit tests on AArch64 Linux systems.

The change currently only supports the operations using GCC as the compiler. Support for CLANG is pending.

Known issues:

  • Subhook does not support AArch64 binaries, thus function pointer patching are not supported when building on AArch64 platforms.

  • RngLib for AArch64 target will check on to determine the availability of RDRAND instruction, which may or may not be supported depending on . It is suggested to use the timer based RngLib for host tests.

  • We might need a legit TimerLib for host based unit test to resolve the issue above.

  • The packages that depends on RngLib are not onboarded to support AArch64 host tests. Including CryptoPkg, SecurityPkg, and UefiCpuPkg.

  • Breaking change?

    • Breaking change - Does this PR cause a break in build or boot behavior?
    • Examples: Does it add a new library class or move a module to a different repo.
  • Impacts security?

    • Security - Does this PR have a direct security impact?
    • Examples: Crypto algorithm change or buffer overflow fix.
  • Includes tests?

    • Tests - Does this PR include any explicit test code?
    • Examples: Unit tests or integration tests.

How This Was Tested

This was tested on a AArch64 host system running Ubuntu 24.04.

Integration Instructions

N/A

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had activity in 60 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions.

@github-actions github-actions Bot added the stale Due to lack of updates, this item is pending deletion. label Mar 29, 2026
@mergify
Copy link
Copy Markdown

mergify Bot commented Mar 29, 2026

PR can not be merged due to conflict. Please rebase and resubmit

@kuqin12
Copy link
Copy Markdown
Contributor Author

kuqin12 commented Mar 30, 2026

Not stale

@github-actions github-actions Bot removed the stale Due to lack of updates, this item is pending deletion. label Mar 30, 2026
Comment thread UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp Outdated
@kuqin12 kuqin12 force-pushed the arm64_test branch 2 times, most recently from 1f0fc95 to 08ddeaa Compare April 16, 2026 23:09
@kuqin12 kuqin12 force-pushed the arm64_test branch 3 times, most recently from 5d5cc39 to 3eb6d07 Compare April 29, 2026 23:14
Copy link
Copy Markdown
Contributor

@pierregondois pierregondois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Kun,
Just a few comments, otherwise I tried the branch locally and it seems to work well.


[Sources.AARCH64]
AArch64/InternalSwitchStack.c
AArch64/Unaligned.c
Copy link
Copy Markdown
Contributor

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:

  1. Add preprocessor for AArch64 instances
  2. Cleanup some unnecessary files

Maybe this patch should be split in 2 and also remove the following unused sections:

  • [Sources.RISCV64]
  • [Sources.EBC]

NIT2:
The following function are not supported by the UnitTestHost BaseLib implementation:

  • AArch64/ArmReadCntPctReg.S
  • AArch64/ArmReadIdAA64Isar0Reg.S

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_ARCHITECTURES might be updated to add AARCH64

Copy link
Copy Markdown
Contributor Author

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.

/**
Sample unit test that performs a divide by 0
**/
TEST (SanitizerTests, DivideByZeroDeathTest) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the same division by 0 test exists in:
UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/ampleGoogleTestGenerateException.cpp

The test should generate an exception, but instead it should fail as the result is 0 (checked against MAX_UINTN). Maybe the test should be IA32/X64 only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

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.

kuqin12 added 14 commits May 1, 2026 14:04
This change updates the iasl binary to the 20230628 release.

The updated release also adds support for execution on ARM host machines.

Signed-off-by: Kun Qin <[email protected]>
This change adds a few preprocessors to build AArch64 host based unit
tests properly.

An AArch64 specific instance of `gUnitTestHostBaseLib` is created to
abstract the reference of arch specific special instructions.

Signed-off-by: Kun Qin <[email protected]>
The existing UnitTestHostBaseLib has some source entries that are either
redundant or for unsupported architectures.

This change consolidated the redundant entries and removed the entries
for unsupported architectures.

Signed-off-by: Kun Qin <[email protected]>
…rch64

AArch64 does not have divide-by-zero exception.

This change modifies the corresponding test to work with AArch64.

Signed-off-by: Kun Qin <[email protected]>
This change adds the support of float operations for AArch64 host based
unit tests by overriding the compiler flags.

Signed-off-by: Kun Qin <[email protected]>
This change adds the GCC compiler flag for AArch64 targets.

Signed-off-by: Kun Qin <[email protected]>
Current FunctionMockLib is relying on the subhoob module to support the
backend operation by bitbanging the binary post-disassembly.

However subhook module is a x64 centric module and does not support
AArch64 usage.

This change removes the mock function support for AArch64. The
functionality will need other solutions to be properly supported.

Signed-off-by: Kun Qin <[email protected]>
This change adds the AArch64 target for host based unit tests.

Signed-off-by: Kun Qin <[email protected]>
This change adds the AArch64 target for host based unit tests.

Signed-off-by: Kun Qin <[email protected]>
This change adds the AArch64 target for host based unit tests.

Signed-off-by: Kun Qin <[email protected]>
This change adds the AArch64 target for host based unit tests.

Signed-off-by: Kun Qin <[email protected]>
The current instance does not support host based test on AArch64 host
system due to its dependency on hardware UART library.

This change created a new instance that does not initialize the serial
port for host based test applications.

Signed-off-by: Kun Qin <[email protected]>
This change adds the AArch64 target for host based unit tests.

Signed-off-by: Kun Qin <[email protected]>
This change adds the AArch64 target for host based unit tests.

Signed-off-by: Kun Qin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants