Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 64 additions & 23 deletions .github/workflows/build-codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,18 @@ jobs:

- name: Build must-fix driver suite
shell: cmd
run: .\codeql-cli\codeql.cmd query compile --check-only mustfix.qls
run: .\codeql-cli\codeql.cmd query compile --check-only --threads=0 mustfix.qls

- name: Build recommended driver suite
shell: cmd
run: .\codeql-cli\codeql.cmd query compile --check-only recommended.qls

- name: Build CA ported queries
shell: cmd
run: .\codeql-cli\codeql.cmd query compile --check-only ported_driver_ca_checks.qls
run: .\codeql-cli\codeql.cmd query compile --check-only --threads=0 recommended.qls

- name: Build all Windows queries
shell: cmd
run: .\codeql-cli\codeql.cmd query compile --check-only .\src
run: .\codeql-cli\codeql.cmd query compile --check-only --threads=0 .\src

test-query-health:
runs-on: windows-latest
needs: build
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -111,13 +106,15 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Azure Login
if: github.event_name != 'pull_request'
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: Download previous results
if: github.event_name != 'pull_request'
uses: azure/powershell@v2
with:
azPSVersion: latest
Expand All @@ -127,24 +124,40 @@ jobs:
Get-AzStorageFileContent -ShareName "$env:SHARE_NAME" -Path "detailedfunctiontestresults.xlsx" -Destination $destination -Context $context
- name: Run test script
shell: pwsh
run: python src\drivers\test\build_create_analyze_test.py --codeql_path .\codeql-cli\codeql.exe --no_build --compare_results -v
run: |
# Run per-test build/analyze in parallel inside the script. Default is
# one worker per logical CPU (--jobs <N>); each worker is isolated to
# its own working/, TestDB/, and AnalysisFiles/<name>.sarif paths.
$pyArgs = @('src\drivers\test\build_create_analyze_test.py', '--codeql_path', '.\codeql-cli\codeql.exe', '--no_build', '-v', '--jobs', "$env:NUMBER_OF_PROCESSORS")
if ("${{ github.event_name }}" -ne "pull_request") {
$pyArgs += '--compare_results'
}
python @pyArgs
- name: Upload result diff
if: ${{ hashFiles('diffdetailedfunctiontestresults.xlsx') != '' }} # Only upload if there are changes
if: github.event_name != 'pull_request' && hashFiles('diffdetailedfunctiontestresults.xlsx') != ''
uses: azure/powershell@v2
with:
azPSVersion: latest
inlineScript: |
Update-AzConfig -DisplayBreakingChangeWarning $false
$context = New-AzStorageContext -StorageAccountName "$env:ACCOUNT_NAME" -UseConnectedAccount -EnableFileBackupRequestIntent
Set-AzStorageFileContent -ShareName "$env:SHARE_NAME" -Source "diffdetailedfunctiontestresults.xlsx" -Path "health-diffdetailedfunctiontestresults.xlsx" -Context $context -Force
exit 1
- name: Fail if result diff detected
if: github.event_name != 'pull_request' && hashFiles('diffdetailedfunctiontestresults.xlsx') != ''
shell: pwsh
run: |
Write-Host "::error::Test results differ from the stored baseline. The diff has been uploaded to Azure Storage as 'health-diffdetailedfunctiontestresults.xlsx'. Please review."
exit 1


test-codeql-latest-vs-current:
# Tests if the latest codeql version produces the same results as the current version.
# Tests if the latest codeql version produces the same results as the current version.
# Runs in parallel with `test-query-health` (no `needs:` dependency) to halve the
# pipeline's wall-clock time. It is independent: it downloads its own (latest)
# CodeQL CLI and runs the same per-test build/analyze cycle. `continue-on-error`
# below means failures here never block the workflow regardless of order.
runs-on: windows-latest
continue-on-error: true # Allow script to return non-zero exit code
needs: [build,test-query-health]
permissions:
contents: read
packages: write
Expand All @@ -153,10 +166,6 @@ jobs:
ACCOUNT_NAME: ${{ secrets.ACCOUNT_NAME }}
SHARE_NAME: ${{ secrets.SHARE_NAME }}
steps:
- name: Check Prev Job
if: ${{ needs.test-query-health.result == 'failure' }}
shell: pwsh
run: exit 1
- name: Enable long git paths
shell: cmd
run: git config --global core.longpaths true
Expand Down Expand Up @@ -194,13 +203,15 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Azure Login
if: github.event_name != 'pull_request'
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: Download previous results
if: github.event_name != 'pull_request'
uses: azure/powershell@v2
with:
azPSVersion: latest
Expand All @@ -210,16 +221,29 @@ jobs:
Get-AzStorageFileContent -ShareName "$env:SHARE_NAME" -Path "detailedfunctiontestresults.xlsx" -Destination $destination -Context $context
- name: Run test script
shell: pwsh
run: python src\drivers\test\build_create_analyze_test.py --codeql_path .\codeql-cli\codeql.exe --no_build --compare_results -v
run: |
# Run per-test build/analyze in parallel inside the script. Default is
# one worker per logical CPU (--jobs <N>); each worker is isolated to
# its own working/, TestDB/, and AnalysisFiles/<name>.sarif paths.
$pyArgs = @('src\drivers\test\build_create_analyze_test.py', '--codeql_path', '.\codeql-cli\codeql.exe', '--no_build', '-v', '--jobs', "$env:NUMBER_OF_PROCESSORS")
if ("${{ github.event_name }}" -ne "pull_request") {
$pyArgs += '--compare_results'
}
python @pyArgs
- name: Upload result diff
if: ${{ hashFiles('diffdetailedfunctiontestresults.xlsx') != '' }} # Only upload if there are changes
if: github.event_name != 'pull_request' && hashFiles('diffdetailedfunctiontestresults.xlsx') != ''
uses: azure/powershell@v2
with:
azPSVersion: latest
inlineScript: |
$context = New-AzStorageContext -StorageAccountName "$env:ACCOUNT_NAME" -UseConnectedAccount -EnableFileBackupRequestIntent
Set-AzStorageFileContent -ShareName "$env:SHARE_NAME" -Source "diffdetailedfunctiontestresults.xlsx" -Path "version-diffdetailedfunctiontestresults.xlsx" -Context $context -Force
exit 1
- name: Fail if result diff detected
if: github.event_name != 'pull_request' && hashFiles('diffdetailedfunctiontestresults.xlsx') != ''
shell: pwsh
run: |
Write-Host "::error::Test results from latest CodeQL version differ from the stored baseline. The diff has been uploaded to Azure Storage as 'version-diffdetailedfunctiontestresults.xlsx'. Please review."
exit 1
- name: Save Latest Version
if: ${{ hashFiles('diffdetailedfunctiontestresults.xlsx') == '' }} # Only if there were no differences
uses: actions/upload-artifact@v4
Expand All @@ -230,7 +254,13 @@ jobs:

test-pack-version-update:
runs-on: windows-latest
needs: build
# Only enforce qlpack version bumps when the change is actually heading to
# `main`. We routinely stage many commits in `development` and bump the
# qlpack version once when promoting to `main`, so requiring a bump on
# every `development`-targeted PR/push is noise.
if: |
(github.event_name == 'pull_request' && github.base_ref == 'main') ||
(github.event_name != 'pull_request' && github.ref == 'refs/heads/main')
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -272,7 +302,6 @@ jobs:
}
test-create-dvl:
runs-on: windows-latest
needs: build
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -319,7 +348,19 @@ jobs:
publish:
runs-on: windows-latest
continue-on-error: true
needs: [build, test-pack-version-update, test-query-health]
needs: [build, test-pack-version-update, test-query-health, test-codeql-latest-vs-current, test-create-dvl]
# Run when all required gates pass. `test-pack-version-update` is skipped
# for non-`main` targets (see its `if:` above), so allow `success` *or*
# `skipped`. `test-codeql-latest-vs-current` is `continue-on-error: true`,
# which already produces a `success` result for `needs`, so we don't need
# special handling for it here -- listing it in `needs` just makes publish
# wait for it to finish before running.
if: |
always() &&
needs.build.result == 'success' &&
needs.test-query-health.result == 'success' &&
needs.test-create-dvl.result == 'success' &&
(needs.test-pack-version-update.result == 'success' || needs.test-pack-version-update.result == 'skipped')
permissions:
contents: read
packages: write
Expand Down
23 changes: 23 additions & 0 deletions src/drivers/test/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project>
<!--
Auto-imported by MSBuild for every project under src\drivers\test\ (both the
TestTemplates\ originals and the generated working\ copies used by
build_create_analyze_test.py). Wires the WDK and Windows SDK CPP NuGet
packages restored by the workflow's `nuget restore ... -PackagesDirectory
.\packages\` step into the driver template projects so they can find wdm.h,
ntifs.h, wdf.h, etc.

Mirrors the pattern used by microsoft/Windows-driver-samples
(see https://github.com/microsoft/Windows-driver-samples/blob/main/Directory.Build.props),
keeping the package set and versions in sync with packages.config in this
same directory.
-->
<PropertyGroup>
<WdkNuGetPackagesDir>$(MSBuildThisFileDirectory)..\..\..\packages\</WdkNuGetPackagesDir>
</PropertyGroup>
<Import Project="$(WdkNuGetPackagesDir)Microsoft.Windows.WDK.x64.10.0.26100.6584\build\native\Microsoft.Windows.WDK.x64.props" Condition="Exists('$(WdkNuGetPackagesDir)Microsoft.Windows.WDK.x64.10.0.26100.6584\build\native\Microsoft.Windows.WDK.x64.props') and '$(Platform)' == 'x64'" />
<Import Project="$(WdkNuGetPackagesDir)Microsoft.Windows.WDK.arm64.10.0.26100.6584\build\native\Microsoft.Windows.WDK.arm64.props" Condition="Exists('$(WdkNuGetPackagesDir)Microsoft.Windows.WDK.arm64.10.0.26100.6584\build\native\Microsoft.Windows.WDK.arm64.props') and '$(Platform)' == 'ARM64'" />
<Import Project="$(WdkNuGetPackagesDir)Microsoft.Windows.SDK.CPP.x64.10.0.26100.6584\build\native\Microsoft.Windows.SDK.cpp.x64.props" Condition="Exists('$(WdkNuGetPackagesDir)Microsoft.Windows.SDK.CPP.x64.10.0.26100.6584\build\native\Microsoft.Windows.SDK.cpp.x64.props') and '$(Platform)' == 'x64'" />
<Import Project="$(WdkNuGetPackagesDir)Microsoft.Windows.SDK.CPP.arm64.10.0.26100.6584\build\native\Microsoft.Windows.SDK.cpp.arm64.props" Condition="Exists('$(WdkNuGetPackagesDir)Microsoft.Windows.SDK.CPP.arm64.10.0.26100.6584\build\native\Microsoft.Windows.SDK.cpp.arm64.props') and '$(Platform)' == 'ARM64'" />
<Import Project="$(WdkNuGetPackagesDir)Microsoft.Windows.SDK.CPP.10.0.26100.6584\build\native\Microsoft.Windows.SDK.cpp.props" Condition="Exists('$(WdkNuGetPackagesDir)Microsoft.Windows.SDK.CPP.10.0.26100.6584\build\native\Microsoft.Windows.SDK.cpp.props')" />
</Project>
28 changes: 28 additions & 0 deletions src/drivers/test/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project>
<!--
Auto-imported by MSBuild AFTER each project's main targets (including the
WDK targets pulled in by Directory.Build.props), for every project under
src\drivers\test\.

Override the WDK's `ApiValidator` post-build target with an empty target.
The WDK NuGet packages restored by the CI workflow do not ship the
`ApiValidator.exe` binary even though they reference its path in
`WindowsDriver.common.targets`. Without this override the target fails
with:

error MSB3721: The command "...\ApiValidator.exe -DriverPackagePath:..."
exited with code 1

breaking the `codeql database create` invocation for tests built with the
Universal driver target platform (UnsafeCallInGlobalInit,
MultithreadedAVCondition, StaticInitializer, DeviceInitApi, FloatSafeExit,
FloatUnsafeExit, ...).

API validation is irrelevant to the CodeQL static analysis these tests
perform, so replacing the target with a no-op is safe here. Setting
`ApiValidatorExePath` to an empty value would still leave the target
running an empty exec; replacing the target itself is the most reliable
suppression.
-->
<Target Name="ApiValidator" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
<ClInclude Include="Queue.h" />
<ClInclude Include="Trace.h" />
</ItemGroup>
<ItemGroup>
<Inf Include="CppKMDFTestTemplate.inf" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{0B59834A-7319-449C-822B-09B4CFAC9752}</ProjectGuid>
<TemplateGuid>{8c0e3d8b-df43-455b-815a-4a0e72973bc6}</TemplateGuid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
<ClInclude Include="Queue.h" />
<ClInclude Include="Trace.h" />
</ItemGroup>
<ItemGroup>
<Inf Include="KMDFTestTemplate.inf" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{AD97E1A9-DDBC-4BC2-B3B8-95D11062B471}</ProjectGuid>
<TemplateGuid>{8c0e3d8b-df43-455b-815a-4a0e72973bc6}</TemplateGuid>
Expand Down
Loading
Loading