From 9b3cb86459386ca4d4255d590367ff5366415444 Mon Sep 17 00:00:00 2001 From: Shakti Suman Date: Tue, 24 Mar 2026 21:03:38 -0700 Subject: [PATCH] Add qemu for x86-64 tests in lit config. Signed-off-by: Shakti Suman --- .github/workflows/ci-win.yml | 55 ++++++++++++++++++- test/lit.cfg | 6 ++ .../DefaultImageBase/DefaultImageBase.test | 20 ++++--- 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-win.yml b/.github/workflows/ci-win.yml index 064f293e2..51534f6b1 100644 --- a/.github/workflows/ci-win.yml +++ b/.github/workflows/ci-win.yml @@ -1,7 +1,7 @@ name: Windows Arm64/x86_64 Nightly on: - # pull_request: {} # Uncomment only to test this WF file update. + pull_request: {} # Uncomment only to test this WF file update. schedule: # 9:00 PM Central - cron: '0 2 * * *' @@ -33,6 +33,59 @@ jobs: name: Windows-Arm64 steps: + - name: Install QEMU with winget + shell: pwsh + run: | + $qemuInstallDirs = @( + 'C:\Program Files\qemu', + 'C:\Program Files\QEMU', + 'C:\Program Files (x86)\qemu' + ) + + foreach ($qemuDir in $qemuInstallDirs) { + if ((Test-Path $qemuDir) -and -not (($env:Path -split ';') -contains $qemuDir)) { + $env:Path = "$qemuDir;$env:Path" + } + } + + if (-not (Get-Command qemu-system-x86_64 -ErrorAction SilentlyContinue)) { + winget install -e --id SoftwareFreedomConservancy.QEMU --silent --accept-package-agreements --accept-source-agreements + $machinePath = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + $userPath = [System.Environment]::GetEnvironmentVariable("Path", "User") + $env:Path = "$machinePath;$userPath" + + foreach ($qemuDir in $qemuInstallDirs) { + if ((Test-Path $qemuDir) -and -not (($env:Path -split ';') -contains $qemuDir)) { + $env:Path = "$qemuDir;$env:Path" + } + } + } + + $qemu = Get-Command qemu-system-x86_64 -ErrorAction SilentlyContinue + if (-not $qemu) { + $qemu = Get-Command qemu-system-x86_64.exe -ErrorAction SilentlyContinue + } + + if (-not $qemu) { + foreach ($qemuDir in $qemuInstallDirs) { + $qemuExePath = Join-Path $qemuDir 'qemu-system-x86_64.exe' + if (Test-Path $qemuExePath) { + $qemu = Get-Item $qemuExePath + break + } + } + } + + if (-not $qemu) { + throw 'qemu-system-x86_64.exe not found. Ensure one of these is on PATH: C:\Program Files\qemu, C:\Program Files\QEMU, or C:\Program Files (x86)\qemu.' + } + + Split-Path $qemu.Path | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + - name: Verify QEMU installation + shell: pwsh + run: qemu-system-x86_64 --help + - name: Map Git usr/bin to a space-free drive and prepend to PATH shell: pwsh run: | diff --git a/test/lit.cfg b/test/lit.cfg index fda4dde2b..b85b4d2ab 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -209,11 +209,13 @@ run="" clangnorvcopts = '' filecheck = 'FileCheck' python = 'python' +qemu_x86_64 = None if platform.system() == 'Windows': rm = which("rm") + " -rf" mkdir = which("mkdir") + " -p" grep = 'findstr' + qemu_x86_64 = which('qemu-system-x86_64') config.available_features.add('windows') elif platform.system() == 'Linux': rm = 'rm -rf' @@ -555,6 +557,8 @@ lit_config.note('using cmake: {}'.format(cmake)) lit_config.note('using git: {}'.format(git)) lit_config.note('using dirname: {}'.format(dirname)) lit_config.note('using test templates directory: {}'.format(test_templates_dir)) +if platform.system() == 'Windows': + lit_config.note('using qemu_x86_64: {}'.format(qemu_x86_64)) if muslclang is not None: lit_config.note('using musl-clang: {}'.format(muslclang)) else: @@ -655,5 +659,7 @@ config.substitutions.append( ("%mcpu","".join(mcpu)) ) config.substitutions.append( ("%dirname","".join(dirname)) ) config.substitutions.append( ("%emulation","".join(config.emulation)) ) config.substitutions.append( ("%run","".join(run)) ) +if platform.system() == 'Windows': + config.substitutions.append( ("%qemu_x86_64", "".join(qemu_x86_64)) ) if muslclang is not None: config.substitutions.append( ("%musl-clang","".join(muslclang)) ) diff --git a/test/x86_64/linux/DefaultImageBase/DefaultImageBase.test b/test/x86_64/linux/DefaultImageBase/DefaultImageBase.test index c0cb4834a..50df123bc 100644 --- a/test/x86_64/linux/DefaultImageBase/DefaultImageBase.test +++ b/test/x86_64/linux/DefaultImageBase/DefaultImageBase.test @@ -1,16 +1,20 @@ -#UNSUPPORTED: windows #---DefaultImageBase.test-----Executable--------# BEGIN_COMMENT # Test x86_64 default image address # This test verifies that eld uses the correct default image base (0x400000) -# without requiring manual --image-base=0x400000 flag. +# without requiring manual --image-base=0x400000 flag and allows overriding it. #END_COMMENT #START_TEST RUN: %clang %clangopts -c %p/Inputs/1.c -o %t.1.o -RUN: %link %linkopts -o %t.1.out %t.1.o -RUN: %t.1.out; echo $? > %t.code -RUN: %filecheck --input-file=%t.code %s --check-prefix=EXITCODE -RUN: %readelf -l %t.1.out | %grep LOAD | %filecheck %s --check-prefix=IMAGEBASE +RUN: %link %linkopts -o %t.default.out %t.1.o +RUN: %if windows %{ %qemu_x86_64 %t.default.out %} %else %{ %t.default.out %}; echo $? > %t.default.code +RUN: %filecheck --input-file=%t.default.code %s --check-prefix=EXITCODE +RUN: %readelf -l %t.default.out | %grep LOAD | %filecheck %s --check-prefix=IMAGEBASE-DEFAULT +RUN: %link %linkopts --image-base=0x500000 -o %t.custom.out %t.1.o +RUN: %if windows %{ %qemu_x86_64 %t.custom.out %} %else %{ %t.custom.out %}; echo $? > %t.custom.code +RUN: %filecheck --input-file=%t.custom.code %s --check-prefix=EXITCODE +RUN: %readelf -l %t.custom.out | %grep LOAD | %filecheck %s --check-prefix=IMAGEBASE-CUSTOM EXITCODE: 7 -IMAGEBASE: {{.*}}400000{{.*}} -#END_TEST \ No newline at end of file +IMAGEBASE-DEFAULT: {{.*}}400000{{.*}} +IMAGEBASE-CUSTOM: {{.*}}500000{{.*}} +#END_TEST