diff --git a/.github/workflows/ci-driver.yml b/.github/workflows/ci-driver.yml new file mode 100644 index 0000000..e13b1bd --- /dev/null +++ b/.github/workflows/ci-driver.yml @@ -0,0 +1,206 @@ +--- +name: CI-Driver +permissions: {} + +on: + workflow_call: + inputs: + azure_signing_account: + type: string + default: '' + azure_signing_cert_profile: + type: string + default: '' + azure_signing_endpoint: + type: string + default: '' + publish_release: + type: string + required: true + release_commit: + type: string + required: true + release_version: + type: string + required: true + secrets: + AZURE_CLIENT_ID: + required: false + AZURE_CLIENT_SECRET: + required: false + AZURE_TENANT_ID: + required: false + +env: + DRIVER_PACKAGE: cmake-build-driver/src/driver/windows_driver/Release/driver-package + WINDOWS_ARCHIVE_NAME: libvirtualdisplay-Windows-AMD64-driver + +jobs: + package: + name: Windows WDK Package + runs-on: windows-2025-vs2026 + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.release_commit }} + persist-credentials: false + + - name: Set up Windows Driver Kit + shell: pwsh + run: | + $installedRoots = 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots' + $kitRoot = (Get-ItemProperty -Path $installedRoots -Name KitsRoot10).KitsRoot10 + + function Find-UsableSdkVersion($root) { + $versions = Get-ChildItem -LiteralPath (Join-Path $root 'Lib') -Directory | + Where-Object { $_.Name -match '^\d+\.\d+\.\d+\.\d+$' } | + Sort-Object { [version]$_.Name } -Descending + + foreach ($version in $versions.Name) { + $required = @( + 'Include\wdf\umdf\2.25' + 'Lib\wdf\umdf\x64\2.25\WdfDriverStubUm.lib' + "Lib\$version\um\x64\iddcx\1.10\IddCxStub.lib" + ) + if (-not ($required | Where-Object { -not (Test-Path -LiteralPath (Join-Path $root $_)) })) { + return $version + } + } + } + + $sdkVersion = Find-UsableSdkVersion $kitRoot + if (-not $sdkVersion) { + winget install --id Microsoft.WindowsWDK.10.0.26100 --exact --silent ` + --accept-package-agreements --accept-source-agreements --disable-interactivity + $sdkVersion = Find-UsableSdkVersion $kitRoot + } + if (-not $sdkVersion) { + throw 'Unable to find Windows Driver Kit with UMDF 2.25 and IddCx 1.10.' + } + "WindowsSdkDir=$kitRoot" >> $env:GITHUB_ENV + "WindowsSDKVersion=$sdkVersion" >> $env:GITHUB_ENV + + - name: Configure Windows driver + shell: pwsh + env: + PACKAGE_VERSION: ${{ inputs.release_version }} + run: >- + cmake -S . -B cmake-build-driver + -G "Visual Studio 18 2026" + -A "x64,version=$env:WindowsSDKVersion" + -DBUILD_TESTS=OFF + -DBUILD_SUNSHINE_VIRTUAL_DISPLAY_DRIVER=ON + -DBUILD_VIRTUALDISPLAY_TOOLS=ON + -DBUILD_VIRTUALDISPLAY_PROBE=ON + "-DLIBVIRTUALDISPLAY_PACKAGE_VERSION=$env:PACKAGE_VERSION" + + - name: Build Windows driver and tools + shell: pwsh + run: cmake --build cmake-build-driver --config Release --parallel + + - name: Locate Windows driver catalog + id: driver_catalog + shell: pwsh + run: | + $catalog = Resolve-Path -LiteralPath (Join-Path $env:DRIVER_PACKAGE 'sunshinevirtualdisplaydriver.cat') + "path=$($catalog.Path)" >> $env:GITHUB_OUTPUT + + - name: Sign CI driver catalog with a local test certificate + if: inputs.publish_release != 'true' + shell: pwsh + env: + DRIVER_CATALOG: ${{ steps.driver_catalog.outputs.path }} + run: | + $certificate = New-SelfSignedCertificate ` + -Subject 'CN=libvirtualdisplay CI Test Driver Signing' ` + -Type CodeSigningCert ` + -CertStoreLocation 'Cert:\CurrentUser\My' ` + -KeyAlgorithm RSA ` + -KeyLength 3072 ` + -KeyUsage DigitalSignature ` + -HashAlgorithm SHA256 ` + -NotAfter (Get-Date).AddDays(7) + try { + $kitsBin = Join-Path $env:WindowsSdkDir "bin\$env:WindowsSDKVersion" + $signtool = Join-Path $kitsBin 'x64\signtool.exe' + & $signtool sign /fd SHA256 /sha1 $certificate.Thumbprint /s My $env:DRIVER_CATALOG + if ($LASTEXITCODE -ne 0) { + throw "signtool sign failed with exit code $LASTEXITCODE" + } + } finally { + Remove-Item -LiteralPath "Cert:\CurrentUser\My\$($certificate.Thumbprint)" -Force + } + + - name: Sign release driver catalog with Azure Trusted Signing + if: inputs.publish_release == 'true' + uses: azure/trusted-signing-action@c7ab2a863ab5f9a846ddb8265964877ef296ee82 # v2.0.0 + with: + azure-client-id: ${{ secrets.AZURE_CLIENT_ID }} + azure-client-secret: ${{ secrets.AZURE_CLIENT_SECRET }} + azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} + certificate-profile-name: ${{ inputs.azure_signing_cert_profile }} + endpoint: ${{ inputs.azure_signing_endpoint }} + files: ${{ steps.driver_catalog.outputs.path }} + signing-account-name: ${{ inputs.azure_signing_account }} + + - name: Validate driver signature and export public certificate + shell: pwsh + env: + DRIVER_CATALOG: ${{ steps.driver_catalog.outputs.path }} + PUBLISH_RELEASE: ${{ inputs.publish_release }} + run: | + $signature = Get-AuthenticodeSignature -LiteralPath $env:DRIVER_CATALOG + if (!$signature.SignerCertificate -or + ($env:PUBLISH_RELEASE -eq 'true' -and $signature.Status -ne 'Valid')) { + throw "Windows driver catalog signature is invalid: $($signature.StatusMessage)" + } + + $cer = Join-Path $env:DRIVER_PACKAGE 'SunshineVirtualDisplayDriver.cer' + Export-Certificate -Cert $signature.SignerCertificate -FilePath $cer | Out-Null + + - name: Package driver and tools + shell: pwsh + run: >- + cpack --config cmake-build-driver/CPackConfig.cmake + -C Release -B artifacts + -D "CPACK_PACKAGE_FILE_NAME=$env:WINDOWS_ARCHIVE_NAME" + + - name: Verify Windows package contents + shell: pwsh + run: | + $expected = @( + 'LICENSE' + 'README.md' + 'driver/' + 'driver/SunshineVirtualDisplayDriver.cat' + 'driver/SunshineVirtualDisplayDriver.cer' + 'driver/SunshineVirtualDisplayDriver.dll' + 'driver/SunshineVirtualDisplayDriver.inf' + 'tools/' + 'tools/virtualdisplay.exe' + 'tools/virtualdisplay_broker.exe' + 'tools/virtualdisplay_probe.exe' + 'vulkan-layer/' + 'vulkan-layer/VkLayer_sunshine_hdr.dll' + 'vulkan-layer/VkLayer_sunshine_hdr.json' + ) | ForEach-Object { "$env:WINDOWS_ARCHIVE_NAME/$_" } + + $package = Get-Item -LiteralPath "artifacts/$env:WINDOWS_ARCHIVE_NAME.zip" + $archive = [IO.Compression.ZipFile]::OpenRead($package.FullName) + try { + if (Compare-Object -ReferenceObject $expected -DifferenceObject $archive.Entries.FullName -CaseSensitive) { + throw 'The Windows package differs from the expected release file list.' + } + } finally { + $archive.Dispose() + } + + - name: Upload Windows package + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: windows-driver-package + path: artifacts/${{ env.WINDOWS_ARCHIVE_NAME }}.zip + if-no-files-found: error diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc6c0b7..efdb4e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,165 +1,267 @@ --- name: CI +permissions: {} on: pull_request: push: branches: - master - workflow_dispatch: - -permissions: - contents: read concurrency: group: "${{ github.workflow }}-${{ github.ref }}" cancel-in-progress: true +env: + PYTHON_VERSION: '3.14' + jobs: - linux-tests: - name: Linux Tests + setup_release: + name: Setup Release runs-on: ubuntu-latest + permissions: + contents: write + outputs: + publish_release: ${{ steps.setup_release.outputs.publish_release }} + release_body: ${{ steps.setup_release.outputs.release_body }} + release_commit: ${{ steps.setup_release.outputs.release_commit }} + release_generate_release_notes: ${{ steps.setup_release.outputs.release_generate_release_notes }} + release_tag: ${{ steps.setup_release.outputs.release_tag }} + release_version: ${{ steps.setup_release.outputs.release_version }} + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Setup Release + id: setup_release + uses: LizardByte/actions/actions/release_setup@81873587bacc6842098865a35bbb32f2f21cee3b # v2026.1123.33249 + with: + dotnet: true + github_token: ${{ secrets.GITHUB_TOKEN }} + test: + name: Test (${{ matrix.name }}) + permissions: + contents: read + runs-on: ${{ matrix.os }} + defaults: + run: + shell: ${{ matrix.shell }} + strategy: + fail-fast: false + matrix: + include: + - name: Linux-GCC + os: ubuntu-latest + shell: bash + cmake_flags: -G Ninja + coverage: true + - name: Windows-UCRT64 + os: windows-latest + shell: msys2 {0} + cmake_flags: -G Ninja + coverage: true + - name: Windows-MSVC + os: windows-2025-vs2026 + shell: pwsh + cmake_flags: -G "Visual Studio 18 2026" -A x64 + coverage: false steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: recursive - - name: Install Linux test dependencies + - name: Install Linux DRM headers + if: runner.os == 'Linux' run: | sudo apt-get update sudo apt-get install --no-install-recommends --yes libdrm-dev - - name: Configure - run: cmake -S . -B build-linux -G Ninja -DBUILD_TESTS=ON + - name: Set up UCRT64 + if: matrix.name == 'Windows-UCRT64' + uses: msys2/setup-msys2@3c51bf698df1e37b2261f53cb67797b97761185c # v2.34.0 + with: + msystem: ucrt64 + update: true + install: >- + mingw-w64-ucrt-x86_64-cmake + mingw-w64-ucrt-x86_64-gcc + mingw-w64-ucrt-x86_64-ninja + + - name: Configure tests + run: >- + cmake -S . -B cmake-build-ci + -DBUILD_TESTS=ON + ${{ matrix.cmake_flags }} - name: Build tests - run: cmake --build build-linux --target test_libvirtualdisplay --parallel 2 + run: cmake --build cmake-build-ci --config Release --parallel + + - name: Set up Python + if: matrix.coverage + id: setup-python + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Set up uv + if: matrix.coverage + uses: astral-sh/setup-uv@36300bab3f61b84e19f32b6bd26b7897f3c7e951 # v10.4.2 + with: + enable-cache: true + cache-dependency-glob: third-party/lizardbyte-common/uv.lock - name: Run tests - run: ctest --test-dir build-linux --output-on-failure -j2 + id: tests + working-directory: cmake-build-ci + run: ctest -C Release --output-on-failure --output-junit junit.xml --parallel 4 - unit-tests: - name: Unit Tests - runs-on: windows-latest + - name: Generate coverage report + if: >- + !cancelled() && matrix.coverage && + (steps.tests.outcome == 'success' || steps.tests.outcome == 'failure') + env: + MSYS2_PATH_TYPE: inherit + UV_PYTHON: ${{ steps.setup-python.outputs.python-path }} + run: | + uv sync --project third-party/lizardbyte-common --locked --only-group test-c \ + --no-python-downloads \ + --no-install-project + uv run --project third-party/lizardbyte-common --locked --no-sync gcovr cmake-build-ci \ + --root . \ + --filter '^src/driver/' \ + --exclude-noncode-lines \ + --exclude-throw-branches \ + --exclude-unreachable-branches \ + --cobertura-pretty \ + --output cmake-build-ci/coverage.xml + - name: Upload reports + if: >- + !cancelled() && + (steps.tests.outcome == 'success' || steps.tests.outcome == 'failure') + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: reports-${{ matrix.name }} + path: | + cmake-build-ci/junit.xml + cmake-build-ci/coverage.xml + if-no-files-found: error + + codecov: + name: Codecov (${{ matrix.name }}) + if: github.repository_owner == 'LizardByte' + needs: test + runs-on: ubuntu-latest + permissions: + contents: read + strategy: + fail-fast: false + matrix: + include: + - name: Linux-GCC + coverage: true + - name: Windows-UCRT64 + coverage: true + - name: Windows-MSVC + coverage: false steps: - name: Checkout - uses: actions/checkout@v4 - - - name: Configure MSVC - uses: ilammy/msvc-dev-cmd@v1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - arch: x64 + persist-credentials: false - - name: Configure - run: cmake -S . -B build -G Ninja -DBUILD_TESTS=ON + - name: Download reports + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: reports-${{ matrix.name }} + path: _reports - - name: Build tests - run: cmake --build build --target test_libvirtualdisplay --parallel + - name: Upload coverage + if: matrix.coverage + uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 + with: + disable_search: true + fail_ci_if_error: true + files: ./_reports/coverage.xml + flags: ${{ matrix.name }} + token: ${{ secrets.CODECOV_TOKEN }} - - name: Run tests - run: ctest --test-dir build --output-on-failure + - name: Upload test results + uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 + with: + disable_search: true + fail_ci_if_error: true + files: ./_reports/junit.xml + flags: ${{ matrix.name }} + report_type: test_results + token: ${{ secrets.CODECOV_TOKEN }} - windows-package: - name: Windows Package - runs-on: windows-latest + windows_driver: + name: Windows Driver + needs: setup_release + permissions: + contents: read + uses: ./.github/workflows/ci-driver.yml + with: + azure_signing_account: ${{ vars.AZURE_SIGNING_ACCOUNT }} + azure_signing_cert_profile: ${{ vars.AZURE_SIGNING_CERT_PROFILE }} + azure_signing_endpoint: ${{ vars.AZURE_SIGNING_ENDPOINT }} + publish_release: ${{ needs.setup_release.outputs.publish_release }} + release_commit: ${{ needs.setup_release.outputs.release_commit }} + release_version: ${{ needs.setup_release.outputs.release_version }} + secrets: + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + release: + name: Release + if: >- + github.repository_owner == 'LizardByte' && + needs.setup_release.outputs.publish_release == 'true' + needs: + - setup_release + - test + - windows_driver + permissions: + contents: read + runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Configure MSVC - uses: ilammy/msvc-dev-cmd@v1 + - name: Download Windows package + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: - arch: x64 + name: windows-driver-package + path: artifacts - - name: Install WDK - shell: pwsh + - name: Validate release metadata + env: + RELEASE_COMMIT: ${{ needs.setup_release.outputs.release_commit }} + RELEASE_TAG: ${{ needs.setup_release.outputs.release_tag }} + RELEASE_VERSION: ${{ needs.setup_release.outputs.release_version }} run: | - $ErrorActionPreference = 'Stop' - $defaultKitRoot = 'C:\Program Files (x86)\Windows Kits\10\' - - function Find-UsableSdkVersion($root) { - if ([string]::IsNullOrWhiteSpace($root) -or -not (Test-Path (Join-Path $root 'Lib'))) { - return $null - } - $versions = Get-ChildItem (Join-Path $root 'Lib') -Directory | - Where-Object { $_.Name -match '^\d+\.\d+\.\d+\.\d+$' } | - Sort-Object { [version]$_.Name } -Descending | - Select-Object -ExpandProperty Name - - foreach ($version in $versions) { - $required = @( - Join-Path $root 'Include\wdf\umdf\2.25' - Join-Path $root 'Lib\wdf\umdf\x64\2.25\WdfDriverStubUm.lib' - Join-Path $root "Lib\$version\um\x64\iddcx\1.10\IddCxStub.lib" - ) - if (($required | Where-Object { -not (Test-Path $_) }).Count -eq 0) { - return $version - } - } - return $null - } - - $kitRoot = if ($env:WindowsSdkDir) { $env:WindowsSdkDir } else { $defaultKitRoot } - $sdkVersion = Find-UsableSdkVersion $kitRoot - if (-not $sdkVersion -and $kitRoot -ne $defaultKitRoot) { - $kitRoot = $defaultKitRoot - $sdkVersion = Find-UsableSdkVersion $kitRoot - } - if (-not $sdkVersion) { - winget install --id Microsoft.WindowsWDK.10.0.26100 --exact --silent ` - --accept-package-agreements --accept-source-agreements --disable-interactivity - $kitRoot = $defaultKitRoot - $sdkVersion = Find-UsableSdkVersion $kitRoot - } - if (-not $sdkVersion) { - throw 'Unable to find a WDK/SDK version with required WDF and IddCx files.' - } - "WindowsSdkDir=$kitRoot" >> $env:GITHUB_ENV - "WindowsSDKVersion=$sdkVersion" >> $env:GITHUB_ENV - - - name: Verify WDK paths - shell: pwsh - run: | - $defaultKitRoot = 'C:\Program Files (x86)\Windows Kits\10\' - $kitRoot = if ($env:WindowsSdkDir) { $env:WindowsSdkDir } else { $defaultKitRoot } - $sdkVersion = if ($env:WindowsSDKVersion) { $env:WindowsSDKVersion.TrimEnd('\') } else { - Get-ChildItem (Join-Path $defaultKitRoot 'Lib') -Directory | - Where-Object { $_.Name -match '^\d+\.\d+\.\d+\.\d+$' } | - Sort-Object Name -Descending | - Select-Object -First 1 -ExpandProperty Name - } - $iddcxPath = "Lib\$sdkVersion\um\x64\iddcx\1.10\IddCxStub.lib" - if (-not (Test-Path (Join-Path $kitRoot $iddcxPath)) -and - (Test-Path (Join-Path $defaultKitRoot $iddcxPath))) { - $kitRoot = $defaultKitRoot - } - $required = @( - Join-Path $kitRoot 'Include\wdf\umdf\2.25' - Join-Path $kitRoot 'Lib\wdf\umdf\x64\2.25\WdfDriverStubUm.lib' - Join-Path $kitRoot $iddcxPath - ) - foreach ($path in $required) { - if (-not (Test-Path $path)) { - throw "Required WDK path is missing: $path" - } - } - - - name: Configure - run: > - cmake -S . -B build-driver -G Ninja - -DBUILD_TESTS=OFF - -DBUILD_SUNSHINE_VIRTUAL_DISPLAY_DRIVER=ON - -DBUILD_VIRTUALDISPLAY_TOOLS=ON - -DBUILD_VIRTUALDISPLAY_PROBE=ON - - - name: Build package - run: cmake --build build-driver --target package --parallel - - - name: Upload package artifact - uses: actions/upload-artifact@v4 + test -n "${RELEASE_TAG}" + test -n "${RELEASE_VERSION}" + test "${RELEASE_COMMIT}" = "${GITHUB_SHA}" + shopt -s dotglob nullglob + release_assets=(*artifacts/*) + test "${#release_assets[@]}" -eq 1 + test "${release_assets[0]}" = artifacts/libvirtualdisplay-Windows-AMD64-driver.zip + test -s artifacts/libvirtualdisplay-Windows-AMD64-driver.zip + + - name: Create draft GitHub release + uses: LizardByte/actions/actions/release_create@81873587bacc6842098865a35bbb32f2f21cee3b # v2026.1123.33249 with: - name: libvirtualdisplay-windows-x64 - path: build-driver/libvirtualdisplay-*-windows-x64.zip - if-no-files-found: error + allowUpdates: false + artifactErrorsFailBuild: true + body: ${{ needs.setup_release.outputs.release_body }} + draft: true + generateReleaseNotes: ${{ needs.setup_release.outputs.release_generate_release_notes }} + name: ${{ needs.setup_release.outputs.release_tag }} + prerelease: true + tag: ${{ needs.setup_release.outputs.release_tag }} + token: ${{ secrets.GH_BOT_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index b726923..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,301 +0,0 @@ ---- -name: Release - -on: - push: - tags: - - 'v*' - workflow_dispatch: - inputs: - version: - description: 'Release version, for example v0.1.0' - required: true - type: string - -permissions: - contents: write - -concurrency: - group: "${{ github.workflow }}-${{ github.ref }}" - cancel-in-progress: false - -jobs: - windows-release: - name: Windows Release - runs-on: windows-latest - - steps: - - name: Checkout - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 - - - name: Configure MSVC - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 - with: - arch: x64 - - - name: Install WDK - shell: pwsh - run: | - $ErrorActionPreference = 'Stop' - $defaultKitRoot = 'C:\Program Files (x86)\Windows Kits\10\' - - function Find-UsableSdkVersion($root) { - if ([string]::IsNullOrWhiteSpace($root) -or -not (Test-Path (Join-Path $root 'Lib'))) { - return $null - } - $versions = Get-ChildItem (Join-Path $root 'Lib') -Directory | - Where-Object { $_.Name -match '^\d+\.\d+\.\d+\.\d+$' } | - Sort-Object { [version]$_.Name } -Descending | - Select-Object -ExpandProperty Name - - foreach ($version in $versions) { - $required = @( - Join-Path $root 'Include\wdf\umdf\2.25' - Join-Path $root 'Lib\wdf\umdf\x64\2.25\WdfDriverStubUm.lib' - Join-Path $root "Lib\$version\um\x64\iddcx\1.10\IddCxStub.lib" - ) - if (($required | Where-Object { -not (Test-Path $_) }).Count -eq 0) { - return $version - } - } - return $null - } - - $kitRoot = if ($env:WindowsSdkDir) { $env:WindowsSdkDir } else { $defaultKitRoot } - $sdkVersion = Find-UsableSdkVersion $kitRoot - if (-not $sdkVersion -and $kitRoot -ne $defaultKitRoot) { - $kitRoot = $defaultKitRoot - $sdkVersion = Find-UsableSdkVersion $kitRoot - } - if (-not $sdkVersion) { - winget install --id Microsoft.WindowsWDK.10.0.26100 --exact --silent ` - --accept-package-agreements --accept-source-agreements --disable-interactivity - $kitRoot = $defaultKitRoot - $sdkVersion = Find-UsableSdkVersion $kitRoot - } - if (-not $sdkVersion) { - throw 'Unable to find a WDK/SDK version with required WDF and IddCx files.' - } - "WindowsSdkDir=$kitRoot" >> $env:GITHUB_ENV - "WindowsSDKVersion=$sdkVersion" >> $env:GITHUB_ENV - - - name: Resolve release version - id: version - shell: pwsh - run: | - $version = '${{ github.event.inputs.version }}' - if ([string]::IsNullOrWhiteSpace($version)) { - $version = '${{ github.ref_name }}' - } - $semverPattern = '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)' + - '(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$' - if ($version -notmatch $semverPattern) { - throw "Release version must be a v-prefixed semantic version tag: $version" - } - git fetch --force --tags origin $version - $commit = git rev-list -n 1 $version -- - if ([string]::IsNullOrWhiteSpace($commit)) { - throw "Release tag does not exist: $version" - } - git checkout --detach $version - $packageVersion = $version.TrimStart('v') - "version=$version" >> $env:GITHUB_OUTPUT - "package_version=$packageVersion" >> $env:GITHUB_OUTPUT - "commit=$commit" >> $env:GITHUB_OUTPUT - - - name: Verify WDK paths - shell: pwsh - run: | - $defaultKitRoot = 'C:\Program Files (x86)\Windows Kits\10\' - $kitRoot = if ($env:WindowsSdkDir) { $env:WindowsSdkDir } else { $defaultKitRoot } - $sdkVersion = if ($env:WindowsSDKVersion) { $env:WindowsSDKVersion.TrimEnd('\') } else { - Get-ChildItem (Join-Path $defaultKitRoot 'Lib') -Directory | - Where-Object { $_.Name -match '^\d+\.\d+\.\d+\.\d+$' } | - Sort-Object Name -Descending | - Select-Object -First 1 -ExpandProperty Name - } - $iddcxPath = "Lib\$sdkVersion\um\x64\iddcx\1.10\IddCxStub.lib" - if (-not (Test-Path (Join-Path $kitRoot $iddcxPath)) -and - (Test-Path (Join-Path $defaultKitRoot $iddcxPath))) { - $kitRoot = $defaultKitRoot - } - $required = @( - Join-Path $kitRoot 'Include\wdf\umdf\2.25' - Join-Path $kitRoot 'Lib\wdf\umdf\x64\2.25\WdfDriverStubUm.lib' - Join-Path $kitRoot $iddcxPath - ) - foreach ($path in $required) { - if (-not (Test-Path $path)) { - throw "Required WDK path is missing: $path" - } - } - - - name: Import release signing certificate - id: signing_cert - shell: pwsh - env: - VDD_SIGNING_CERT_PFX_BASE64: ${{ secrets.VDD_SIGNING_CERT_PFX_BASE64 }} - VDD_SIGNING_CERT_PASSWORD: ${{ secrets.VDD_SIGNING_CERT_PASSWORD }} - run: | - $ErrorActionPreference = 'Stop' - - if ([string]::IsNullOrWhiteSpace($env:VDD_SIGNING_CERT_PFX_BASE64)) { - throw 'VDD_SIGNING_CERT_PFX_BASE64 is required for release driver catalog signing.' - } - if ([string]::IsNullOrWhiteSpace($env:VDD_SIGNING_CERT_PASSWORD)) { - throw 'VDD_SIGNING_CERT_PASSWORD is required for release driver catalog signing.' - } - - $pfxPath = Join-Path $env:RUNNER_TEMP 'sunshine-virtual-display-driver-release-signing.pfx' - [System.IO.File]::WriteAllBytes($pfxPath, [Convert]::FromBase64String($env:VDD_SIGNING_CERT_PFX_BASE64)) - - $password = ConvertTo-SecureString $env:VDD_SIGNING_CERT_PASSWORD -AsPlainText -Force - $cert = Import-PfxCertificate -FilePath $pfxPath -CertStoreLocation Cert:\CurrentUser\My -Password $password - Remove-Item -LiteralPath $pfxPath -Force - - if (-not $cert.HasPrivateKey) { - throw 'Imported release signing certificate does not include a private key.' - } - - $cerPath = Join-Path $env:RUNNER_TEMP 'sunshine-virtual-display-driver-release-signing.cer' - Export-Certificate -Cert $cert -FilePath $cerPath | Out-Null - - "thumbprint=$($cert.Thumbprint)" >> $env:GITHUB_OUTPUT - "cert_path=$cerPath" >> $env:GITHUB_OUTPUT - - - name: Configure - run: > - cmake -S . -B build-driver -G Ninja - -DBUILD_TESTS=OFF - -DBUILD_SUNSHINE_VIRTUAL_DISPLAY_DRIVER=ON - -DBUILD_VIRTUALDISPLAY_TOOLS=ON - -DBUILD_VIRTUALDISPLAY_PROBE=ON - '-DLIBVIRTUALDISPLAY_PACKAGE_VERSION=${{ steps.version.outputs.package_version }}' - - - name: Build driver package files - run: cmake --build build-driver --target SunshineVirtualDisplayDriverPackageFiles --parallel - - - name: Sign driver catalog - shell: pwsh - run: | - $ErrorActionPreference = 'Stop' - - $installedRoots = 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots' - $kitsRoot = (Get-ItemProperty -Path $installedRoots -Name KitsRoot10).KitsRoot10 - $kitsBin = Join-Path $kitsRoot 'bin' - $signtool = Get-ChildItem -LiteralPath $kitsBin -Recurse -Filter signtool.exe -File ` - -ErrorAction SilentlyContinue | - Sort-Object -Property FullName -Descending | - Select-Object -First 1 - if (-not $signtool) { - throw "signtool.exe was not found under $kitsRoot." - } - - # The catalog is generated under the per-config package directory - # (e.g. .../windows_driver/Release/driver-package/), so locate it by - # search rather than a fixed path that breaks when the layout changes. - $driverBuild = 'build-driver/src/driver/windows_driver' - $catalogFile = Get-ChildItem -Path $driverBuild -Recurse -Filter 'sunshinevirtualdisplaydriver.cat' -File | - Sort-Object -Property LastWriteTime -Descending | - Select-Object -First 1 - if (-not $catalogFile) { - throw "Driver catalog sunshinevirtualdisplaydriver.cat was not found under $driverBuild." - } - $catalog = $catalogFile.FullName - & $signtool.FullName sign /fd SHA256 /sha1 '${{ steps.signing_cert.outputs.thumbprint }}' $catalog - if ($LASTEXITCODE -ne 0) { - throw "signtool sign failed with exit code $LASTEXITCODE" - } - - $verifyOutput = & $signtool.FullName verify /pa $catalog 2>&1 - $verifyExitCode = $LASTEXITCODE - $verifyText = ($verifyOutput | ForEach-Object { [string]$_ }) -join "`n" - $untrustedRoot = 'terminated in a root\s+certificate which is not trusted' - if ($verifyExitCode -ne 0 -and $verifyText -notmatch $untrustedRoot) { - throw "signtool verify failed with exit code $verifyExitCode`n$verifyText" - } - $verifyText - exit 0 - - - name: Build release package - run: cmake --build build-driver --target package --parallel - - - name: Add signing certificate to release package - shell: pwsh - run: | - $ErrorActionPreference = 'Stop' - - $package = @(Get-ChildItem -Path 'build-driver/libvirtualdisplay-*-windows-x64.zip' -File) - if ($package.Count -ne 1) { - throw "Expected exactly one release package, found $($package.Count)." - } - - $extractRoot = Join-Path $env:RUNNER_TEMP 'libvirtualdisplay-release-package' - if (Test-Path -LiteralPath $extractRoot) { - Remove-Item -LiteralPath $extractRoot -Recurse -Force - } - - Expand-Archive -LiteralPath $package[0].FullName -DestinationPath $extractRoot - $driverDirectory = Get-ChildItem -LiteralPath $extractRoot -Recurse -Directory -Filter driver | - Select-Object -First 1 - if (-not $driverDirectory) { - throw 'Release package driver directory was not found.' - } - - $certificate = Join-Path $driverDirectory.FullName 'SunshineVirtualDisplayDriver.cer' - Copy-Item -LiteralPath '${{ steps.signing_cert.outputs.cert_path }}' -Destination $certificate -Force - Remove-Item -LiteralPath $package[0].FullName -Force - Compress-Archive -Path (Join-Path $extractRoot '*') -DestinationPath $package[0].FullName -Force - - - name: Generate package evidence - shell: pwsh - run: | - $package = @(Get-ChildItem -Path 'build-driver/libvirtualdisplay-*-windows-x64.zip' -File) - if ($package.Count -ne 1) { - throw "Expected exactly one release package, found $($package.Count)." - } - - $hash = (Get-FileHash -LiteralPath $package[0].FullName -Algorithm SHA256).Hash.ToLowerInvariant() - $evidence = [ordered] @{ - tag = '${{ steps.version.outputs.version }}' - commit_sha = '${{ steps.version.outputs.commit }}' - package = $package[0].Name - package_sha256 = $hash - package_size = $package[0].Length - windows_sdk_version = $env:WindowsSDKVersion - wdk_umdf_version = '2.25' - signing = [ordered] @{ - channel = 'self-signed' - certificate_thumbprint = '${{ steps.signing_cert.outputs.thumbprint }}' - } - driver_catalog = 'self-signed' - } - $evidenceFile = "libvirtualdisplay-${{ steps.version.outputs.package_version }}-evidence.json" - $evidencePath = Join-Path 'build-driver' $evidenceFile - $evidence | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $evidencePath -Encoding utf8 - - $releaseNotesPath = Join-Path 'build-driver' 'release-notes.md' - $releaseNotes = @( - 'CI-built libvirtualdisplay package.' - '' - 'This package was built by GitHub Actions from `${{ steps.version.outputs.commit }}`.' - '' - 'Driver package signing model: self-signed catalog.' - '' - 'Driver catalog certificate thumbprint: `${{ steps.signing_cert.outputs.thumbprint }}`.' - '' - "Package SHA256: $hash" - ) - $releaseNotes | Set-Content -LiteralPath $releaseNotesPath -Encoding utf8 - - - name: Create GitHub release - uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 - with: - tag_name: ${{ steps.version.outputs.version }} - name: libvirtualdisplay ${{ steps.version.outputs.version }} - body_path: build-driver/release-notes.md - prerelease: false - overwrite_files: true - files: | - build-driver/libvirtualdisplay-*-windows-x64.zip - build-driver/libvirtualdisplay-*-evidence.json diff --git a/.gitignore b/.gitignore index da60f6f..7c7722b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ # Build outputs build/ build-*/ +cmake-build-*/ # Generated Linux DRM module build outputs. /linux/vibeshine-drm/*.o diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..8115b51 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,19 @@ +# Repository guidance + +## Build and tests + +- Initialize `third-party/lizardbyte-common` recursively before building tests or the optional KWin bridge. +- Use build directories prefixed with `cmake-build-`. Run tests with CTest. The GoogleTest executable is + `test_libvirtualdisplay` in the build's `tests` directory, with a configuration subdirectory for multi-config builds. +- Use MSYS2 UCRT64 for normal Windows builds. On Windows, prefix UCRT64 commands with + `C:\msys64\msys2_shell.cmd -defterm -here -no-start -ucrt64 -c`. Use MSVC and the WDK for the Windows driver package. +- Use `` for GoogleTest and the shared fixtures. Add regression tests for changes in behavior + and aim for full coverage of changed code. Standalone GNU test builds enable coverage automatically. + +## Style and workflows + +- Follow the repository's clang-format configuration. The VKMS-derived subtree follows the upstream kernel configuration. +- Document new and changed C/C++ APIs with Doxygen comments. Keep platform-specific tests under the applicable guards. +- Pin external GitHub Actions to full commit hashes. Declare empty workflow permissions and grant required permissions + per job. Keep the centrally managed workflows synchronized with LizardByte's templates. +- Use the LizardByte pull request template and report the validation performed. diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f9c297..1cb2117 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,9 +36,33 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) option(BUILD_TESTS "Build tests" ON) endif() -add_subdirectory(src) +option(BUILD_VIBESHINE_KWIN_GPU_BRIDGE + "Build and install the KWin GPU-association bridge for Vibeshine DRM" OFF) +set(_libvirtualdisplay_build_kwin_bridge OFF) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BUILD_VIBESHINE_KWIN_GPU_BRIDGE AND + NOT SUNSHINE_BUILD_APPIMAGE AND NOT SUNSHINE_BUILD_FLATPAK) + set(_libvirtualdisplay_build_kwin_bridge ON) +endif() +set(_libvirtualdisplay_build_tests OFF) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTS) + set(_libvirtualdisplay_build_tests ON) +endif() + +if((_libvirtualdisplay_build_tests OR _libvirtualdisplay_build_kwin_bridge) AND NOT TARGET lizardbyte::common) + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third-party/lizardbyte-common/CMakeLists.txt") + message(FATAL_ERROR "Initialize lizardbyte-common with git submodule update --init --recursive") + endif() + set(LIZARDBYTE_COMMON_BUILD_TEST_SUPPORT ${_libvirtualdisplay_build_tests}) + add_subdirectory(third-party/lizardbyte-common EXCLUDE_FROM_ALL) +endif() +if(_libvirtualdisplay_build_kwin_bridge AND TARGET lizardbyte_common) + set_property(TARGET lizardbyte_common PROPERTY POSITION_INDEPENDENT_CODE ON) +endif() + +add_subdirectory(src) + +if(_libvirtualdisplay_build_tests) enable_testing() add_subdirectory(tests) endif() diff --git a/README.md b/README.md index 01d23b1..c1caea3 100644 --- a/README.md +++ b/README.md @@ -41,17 +41,19 @@ its GPL SPDX licensing and provenance. ## Build -The core library and unit tests build with CMake and a C++20 compiler: +Initialize the shared dependencies before building the test suite or the optional KWin bridge: -```powershell -cmake -S . -B build -G Ninja -DBUILD_TESTS=ON -cmake --build build -j 10 -.\build\tests\test_libvirtualdisplay.exe +```sh +git submodule update --init --recursive +cmake -S . -B cmake-build-tests -G Ninja -DBUILD_TESTS=ON +cmake --build cmake-build-tests --parallel +ctest --test-dir cmake-build-tests --output-on-failure ``` -CMake fetches googletest automatically when no local source directory is -provided. To use an existing checkout instead, pass -`-DLIBVIRTUALDISPLAY_GOOGLETEST_SOURCE_DIR=`. +The test suite uses lizardbyte-common's pinned GoogleTest and shared test helpers. +On Windows, use the MSYS2 UCRT64 shell for Ninja builds. With MSVC, configure +with `-G "Visual Studio 17 2022" -A x64`, build with `--config Release`, +and pass `-C Release` to CTest. Standalone GNU test builds enable coverage automatically. On Linux, the same build also tests the connector broker, module installer, kernel-source contract, deterministic HDR EDID, and the public @@ -60,6 +62,9 @@ out-of-tree DRM module derived from upstream VKMS; its source files retain the upstream SPDX identifiers. Service and installer assets live under `linux/packaging`. +The optional KWin bridge (`-DBUILD_VIBESHINE_KWIN_GPU_BRIDGE=ON`) requires +libdrm 2.4.127 or newer and the GBM development package. + To build only the Windows driver, CLI, and runtime probe: ```powershell @@ -85,18 +90,12 @@ The ZIP contains: - `driver/SunshineVirtualDisplayDriver.inf` - `driver/SunshineVirtualDisplayDriver.cat` - `driver/SunshineVirtualDisplayDriver.dll` -- `driver/SunshineVirtualDisplayDriver.pdb` when generated by the toolchain - `tools/virtualdisplay.exe` - `tools/virtualdisplay_broker.exe` - `tools/virtualdisplay_probe.exe` - `vulkan-layer/VkLayer_sunshine_hdr.dll` and `vulkan-layer/VkLayer_sunshine_hdr.json` - `README.md` and `LICENSE` -GitHub Actions publishes the same Windows x64 ZIP when a `v*` tag is pushed, -for example `v0.1.0`. - -Production driver releases must satisfy the gates in -`docs/release-validation.md` before they are treated as supported builds. Support traces and Event Log capture should follow `docs/support-diagnostics.md`. diff --git a/docs/release-validation.md b/docs/release-validation.md deleted file mode 100644 index 5925e3d..0000000 --- a/docs/release-validation.md +++ /dev/null @@ -1,51 +0,0 @@ -# Release Validation - -libvirtualdisplay release packages are CI-built driver/tool bundles for the -Sunshine virtual display stack. - -## Signing Channel - -- Release packages use the project's self-signed driver package. -- Consumers must install the driver in environments that accept this package - signing model. - -## Release Evidence - -Keep these artifacts with each release record: - -- Driver package with INF, CAT, DLL, and PDB. -- Tool package with `virtualdisplay.exe`, `virtualdisplay_broker.exe`, and - `virtualdisplay_probe.exe`, plus the Vulkan layer (`VkLayer_sunshine_hdr.dll` - and `VkLayer_sunshine_hdr.json`). -- Exact commit SHA, tag, Windows SDK version, WDK version, and ZIP SHA256. -- Generated evidence JSON attached to the GitHub release. - -## Validation - -Run functional validation for each supported release candidate: - -- Install the package. -- Create and remove a permanent virtual display. -- Create, feed, and release a temporary virtual display. -- Run the probe tools for the relevant display mode and HDR scenarios. - -## Functional Matrix - -At minimum, release validation must cover: - -- Windows 10 22H2 SDR behavior. -- Windows 11 23H2 or newer HDR-capable behavior. -- Fresh install. -- Upgrade install from the previous released package. -- Driver disable/enable or PnP stop/start. -- Permanent display identity retention across restart. -- Temporary display lease expiry and explicit release. - -## Release Blockers - -A production release is blocked until resolved when any of these are true: - -- The shipped package contains sample identifiers, a permissive control - interface ACL, or undocumented protocol/ABI changes. -- CI packaging fails or the release ZIP/evidence JSON is missing. -- Functional install, upgrade, identity-retention, or cleanup validation fails. diff --git a/linux/kwin_gpu_interposer.cpp b/linux/kwin_gpu_interposer.cpp index 08d4872..90fa27e 100644 --- a/linux/kwin_gpu_interposer.cpp +++ b/linux/kwin_gpu_interposer.cpp @@ -4,11 +4,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include @@ -135,12 +135,18 @@ namespace { std::tie(right.domain, right.bus, right.dev, right.func); } + /** + * @brief Find the NVIDIA renderer, honoring the configured PCI address when set. + * @param devices Enumerated DRM devices. + * @param count Number of enumerated devices. + * @return The selected device, or nullptr when it cannot be selected unambiguously. + */ drmDevicePtr select_render_device(drmDevicePtr devices[], const int count) { - const auto *configured_value = std::getenv(kRenderPciEnvironment.data()); - const auto configured = configured_value && *configured_value ? - parse_pci_device(configured_value) : + const auto configured_value = lizardbyte::common::get_env(kRenderPciEnvironment.data()); + const auto configured = !configured_value.empty() ? + parse_pci_device(configured_value.c_str()) : std::optional {}; - if (configured_value && *configured_value && !configured) { + if (!configured_value.empty() && !configured) { if (!ambiguous_gpu_logged.exchange(true, std::memory_order_relaxed)) { constexpr char message[] = "[vibeshine-kwin-gpu] invalid VIBESHINE_KWIN_RENDER_PCI; refusing virtual GPU association\n"; @@ -260,8 +266,8 @@ namespace { native_hooks_enabled.store(native_supported, std::memory_order_release); hooks_enabled.store((legacy_allocator && !native_allocator) || native_supported, std::memory_order_release); // Always clear the preload, including when the native KMS allocator wins. - (void) unsetenv("LD_PRELOAD"); - (void) unsetenv(kPreloadActiveEnvironment.data()); + (void) lizardbyte::common::unset_env("LD_PRELOAD"); + (void) lizardbyte::common::unset_env(kPreloadActiveEnvironment.data()); if (!hooks_enabled.load(std::memory_order_acquire)) { (void) native_allocator_runtime_compatible(true); constexpr char message[] = @@ -270,8 +276,12 @@ namespace { } } + /** + * @brief Enable allocator routing when KWin starts with the preload configured. + */ __attribute__((constructor)) void stop_kwin_preload_inheritance() { - if (!std::getenv(kPreloadActiveEnvironment.data()) || !running_inside_kwin()) { + std::string preload_active; + if (!lizardbyte::common::get_env(kPreloadActiveEnvironment.data(), preload_active) || !running_inside_kwin()) { return; } configure_allocator_routing(dlsym); diff --git a/src/driver/CMakeLists.txt b/src/driver/CMakeLists.txt index 1450180..464b43c 100644 --- a/src/driver/CMakeLists.txt +++ b/src/driver/CMakeLists.txt @@ -10,6 +10,11 @@ add_library(${MODULE_ALIAS} ALIAS ${MODULE}) target_include_directories(${MODULE} PUBLIC include) target_compile_features(${MODULE} PUBLIC cxx_std_20) +if(_libvirtualdisplay_build_tests AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${MODULE} PRIVATE --coverage -O0 -g) + target_link_options(${MODULE} INTERFACE --coverage) +endif() + option(LIBVIRTUALDISPLAY_ENABLE_FRAME_TRANSPORT "Enable the experimental IddCx frame-push producer and registration IOCTLs" OFF) if(LIBVIRTUALDISPLAY_ENABLE_FRAME_TRANSPORT) @@ -29,16 +34,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") target_compile_features(vibeshine_vkms_peercred PRIVATE cxx_std_20) endif() -option(BUILD_VIBESHINE_KWIN_GPU_BRIDGE - "Build and install the KWin GPU-association bridge for Vibeshine DRM" OFF) - -if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BUILD_VIBESHINE_KWIN_GPU_BRIDGE AND - NOT SUNSHINE_BUILD_APPIMAGE AND NOT SUNSHINE_BUILD_FLATPAK) +if(_libvirtualdisplay_build_kwin_bridge) # Associate the display-only virtual KMS node with KWin's NVIDIA renderer # so GBM allocates scanout on the GPU rather than through kms_swrast. find_package(PkgConfig REQUIRED) include(GNUInstallDirs) - pkg_check_modules(LIBVIRTUALDISPLAY_KWIN_DRM REQUIRED IMPORTED_TARGET libdrm) + pkg_check_modules(LIBVIRTUALDISPLAY_KWIN_DRM REQUIRED IMPORTED_TARGET libdrm>=2.4.127) pkg_check_modules(LIBVIRTUALDISPLAY_KWIN_GBM REQUIRED IMPORTED_TARGET gbm) add_library(vibeshine_kwin_gpu SHARED @@ -49,6 +50,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BUILD_VIBESHINE_KWIN_GPU_BRIDGE AND target_link_libraries(vibeshine_kwin_gpu PRIVATE PkgConfig::LIBVIRTUALDISPLAY_KWIN_DRM PkgConfig::LIBVIRTUALDISPLAY_KWIN_GBM + lizardbyte::common ${CMAKE_DL_LIBS}) # New KWin allocators need a software-allocation scope as well as GBM @@ -216,7 +218,6 @@ if(WIN32 AND BUILD_VIRTUALDISPLAY_TOOLS) add_executable(alttab_stress "${PROJECT_SOURCE_DIR}/tools/alttab_stress.cpp") target_link_libraries(alttab_stress PRIVATE libvirtualdisplay::driver advapi32 d3d11 dxgi) target_compile_features(alttab_stress PRIVATE cxx_std_20) - install(TARGETS alttab_stress RUNTIME DESTINATION tools) list(APPEND _libvirtualdisplay_tool_targets alttab_stress) endif() diff --git a/src/driver/vulkan_layer/vk_layer_sunshine_hdr.cpp b/src/driver/vulkan_layer/vk_layer_sunshine_hdr.cpp index 1fd711d..fe34502 100644 --- a/src/driver/vulkan_layer/vk_layer_sunshine_hdr.cpp +++ b/src/driver/vulkan_layer/vk_layer_sunshine_hdr.cpp @@ -163,6 +163,7 @@ namespace { if (!hwnd) { return false; } + // Read the live Win32 environment, including host changes made through SetEnvironmentVariable. char force[8] {}; if (GetEnvironmentVariableA("SUNSHINE_VHDR_FORCE", force, sizeof(force)) > 0 && force[0] == '1') { return true; diff --git a/src/driver/windows_driver/CMakeLists.txt b/src/driver/windows_driver/CMakeLists.txt index 0e617d4..76efd35 100644 --- a/src/driver/windows_driver/CMakeLists.txt +++ b/src/driver/windows_driver/CMakeLists.txt @@ -261,6 +261,8 @@ add_custom_target(${SUNSHINE_DRIVER_TARGET}PackageFiles ALL COMMENT "Build the Windows driver package files") install(TARGETS ${SUNSHINE_DRIVER_TARGET} RUNTIME DESTINATION driver) -install(FILES "$" DESTINATION driver OPTIONAL) +install(FILES "$" DESTINATION driver + CONFIGURATIONS Debug RelWithDebInfo OPTIONAL) install(FILES "${SUNSHINE_DRIVER_PACKAGED_INF}" DESTINATION driver) install(FILES "${SUNSHINE_DRIVER_PACKAGED_CAT}" DESTINATION driver RENAME SunshineVirtualDisplayDriver.cat) +install(FILES "${SUNSHINE_DRIVER_PACKAGE_DIR}/SunshineVirtualDisplayDriver.cer" DESTINATION driver OPTIONAL) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 631baf8..d75dd0c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,20 +1,7 @@ include(GoogleTest) -set(INSTALL_GTEST OFF) -set(INSTALL_GMOCK OFF) -# GoogleTest defines this cache option with a lowercase name. -set(gtest_force_shared_crt ON CACHE BOOL "Always use msvcrt.dll" FORCE) # cmake-lint: disable=C0103 -set(LIBVIRTUALDISPLAY_GOOGLETEST_SOURCE_DIR "" CACHE PATH "Optional local googletest source directory") - -if(LIBVIRTUALDISPLAY_GOOGLETEST_SOURCE_DIR AND EXISTS "${LIBVIRTUALDISPLAY_GOOGLETEST_SOURCE_DIR}/CMakeLists.txt") - add_subdirectory("${LIBVIRTUALDISPLAY_GOOGLETEST_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/googletest") -else() - include(FetchContent) - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG 52eb8108c5bdec04579160ae17225d66034bd723) # v1.17.0 - FetchContent_MakeAvailable(googletest) +if(NOT TARGET lizardbyte::test_support) + message(FATAL_ERROR "libvirtualdisplay tests require lizardbyte::test_support") endif() file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS @@ -29,6 +16,7 @@ endif() target_link_libraries(test_libvirtualdisplay PRIVATE gmock_main + lizardbyte::test_support libvirtualdisplay::driver) if(TARGET gen_driver_inf) add_dependencies(test_libvirtualdisplay gen_driver_inf) @@ -63,7 +51,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") pkg_check_modules(LIBVIRTUALDISPLAY_TEST_KWIN REQUIRED IMPORTED_TARGET libdrm gbm) add_executable(test_kwin_gpu_routing "${PROJECT_SOURCE_DIR}/tests/linux/test-kwin-gpu-routing.cpp") target_link_libraries(test_kwin_gpu_routing PRIVATE - PkgConfig::LIBVIRTUALDISPLAY_TEST_KWIN ${CMAKE_DL_LIBS}) + PkgConfig::LIBVIRTUALDISPLAY_TEST_KWIN lizardbyte::common ${CMAKE_DL_LIBS}) add_test(NAME linux_kwin_gpu_routing COMMAND test_kwin_gpu_routing) get_target_property(_kwin_bridge_definitions vibeshine_kwin_gpu COMPILE_DEFINITIONS) if("${_kwin_bridge_definitions}" MATCHES "VIBESHINE_KWIN_NATIVE_ALLOCATOR=1") @@ -75,6 +63,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") ${_kwin_bridge_definitions}) target_link_libraries(test_kwin_gpu_routing_native PRIVATE PkgConfig::LIBVIRTUALDISPLAY_TEST_KWIN + lizardbyte::common Qt6::Core "${LIBVIRTUALDISPLAY_KWIN_LIBRARY}" Threads::Threads ${CMAKE_DL_LIBS}) add_test(NAME linux_kwin_gpu_routing_native COMMAND test_kwin_gpu_routing_native) pkg_check_modules(LIBVIRTUALDISPLAY_TEST_EGL REQUIRED IMPORTED_TARGET egl epoxy) @@ -85,6 +74,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") target_compile_definitions(test_kwin_native_allocation PRIVATE ${_kwin_bridge_definitions}) target_link_libraries(test_kwin_native_allocation PRIVATE PkgConfig::LIBVIRTUALDISPLAY_TEST_KWIN PkgConfig::LIBVIRTUALDISPLAY_TEST_EGL + lizardbyte::common Qt6::Core "${LIBVIRTUALDISPLAY_KWIN_LIBRARY}" ${CMAKE_DL_LIBS}) add_test(NAME linux_kwin_native_allocation COMMAND test_kwin_native_allocation) set_tests_properties(linux_kwin_native_allocation PROPERTIES SKIP_RETURN_CODE 77 LABELS "integration;gpu") diff --git a/tests/linux/test-kwin-gpu-bridge-contract.py b/tests/linux/test-kwin-gpu-bridge-contract.py index fa2c09f..2a0e098 100644 --- a/tests/linux/test-kwin-gpu-bridge-contract.py +++ b/tests/linux/test-kwin-gpu-bridge-contract.py @@ -30,11 +30,13 @@ def main() -> int: interposer_path = linux_root / "kwin_gpu_interposer.cpp" dropin_path = linux_root / "packaging" / "vibeshine-kwin-gpu.conf.in" login_dropin_path = linux_root / "packaging" / "vibeshine-login-kwin-gpu.conf.in" + project_cmake_path = linux_root.parent / "CMakeLists.txt" cmake_path = linux_root.parent / "src" / "driver" / "CMakeLists.txt" interposer = interposer_path.read_text(encoding="utf-8") dropin = dropin_path.read_text(encoding="utf-8") login_dropin = login_dropin_path.read_text(encoding="utf-8") + project_cmake = project_cmake_path.read_text(encoding="utf-8") cmake = cmake_path.read_text(encoding="utf-8") require_all(interposer, ( @@ -58,7 +60,7 @@ def main() -> int: "_ZN4KWin26GbmGraphicsBufferAllocatorC1EPNS_9DrmDeviceE", 'readlink("/proc/self/exe"', '"/usr/bin/kwin_wayland"', - 'unsetenv("LD_PRELOAD")', + 'lizardbyte::common::unset_env("LD_PRELOAD")', ), interposer_path.name) require('extern "C" int drmGet' not in interposer, "bridge must not rewrite libdrm device identities") @@ -89,7 +91,8 @@ def main() -> int: "Environment=KWIN_DISABLE_UDMABUF_IMPORT=1", ), login_dropin_path.name) require("ExecStart=" not in login_dropin, "login drop-in replaces the vendor KWin command") - require("BUILD_VIBESHINE_KWIN_GPU_BRIDGE" in cmake, + require("option(BUILD_VIBESHINE_KWIN_GPU_BRIDGE" in project_cmake + and "if(_libvirtualdisplay_build_kwin_bridge)" in cmake, "KWin bridge is not guarded by an explicit build option") require("plasma-login-kwin_wayland.service.d" in cmake, "KWin bridge is not installed for the Plasma login compositor") diff --git a/tests/linux/test-kwin-gpu-routing.cpp b/tests/linux/test-kwin-gpu-routing.cpp index 87abebc..0d8b5d7 100644 --- a/tests/linux/test-kwin-gpu-routing.cpp +++ b/tests/linux/test-kwin-gpu-routing.cpp @@ -172,7 +172,7 @@ namespace { renumbered_device = nullptr; reject_render_gbm = reject_render_type = false; legacy_allocator_symbol = native_allocator_symbol = false; - unsetenv("VIBESHINE_KWIN_RENDER_PCI"); + lizardbyte::common::unset_env("VIBESHINE_KWIN_RENDER_PCI"); } void require_original_devices() { @@ -227,6 +227,7 @@ extern "C" int drmGetNodeTypeFromFd(int fd) { int main() { try { + std::string env_value; device_fixture virtual_kms(DRM_BUS_FAUX, 0, 0, "vibeshine"); device_fixture virtio(DRM_BUS_PCI, 0x1af4, 3); device_fixture nvidia_one(DRM_BUS_PCI, 0x10de, 1); @@ -250,15 +251,15 @@ int main() { }); run("a preload marker cannot enable hooks in a wrapper or another process", [&] { hooks_enabled = false; - setenv("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE", "1", 1); - setenv("LD_PRELOAD", "libvibeshine-kwin-gpu.so", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE", "1"); + lizardbyte::common::set_env("LD_PRELOAD", "libvibeshine-kwin-gpu.so"); stop_kwin_preload_inheritance(); - require(!hooks_enabled && std::getenv("LD_PRELOAD"), "hook enabled outside actual KWin"); - unsetenv("LD_PRELOAD"); - unsetenv("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE"); + require(!hooks_enabled && lizardbyte::common::get_env("LD_PRELOAD", env_value), "hook enabled outside actual KWin"); + lizardbyte::common::unset_env("LD_PRELOAD"); + lizardbyte::common::unset_env("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE"); }); run("Virtio console GBM keeps its original fd despite an explicit NVIDIA choice", [&] { - setenv("VIBESHINE_KWIN_RENDER_PCI", "0000:01:00.0", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_RENDER_PCI", "0000:01:00.0"); errno = EBUSY; auto *device = gbm_create_device(virtio.fd); require(device->fd == virtio.fd && enumerations == 0 && errno == EBUSY, "physical seat allocator was routed or changed errno"); @@ -274,11 +275,11 @@ int main() { }); run("unmatched native KWin library retains its complete native allocation path", [&] { native_allocator_symbol = true; - setenv("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE", "1", 1); - setenv("LD_PRELOAD", "libvibeshine-kwin-gpu.so", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE", "1"); + lizardbyte::common::set_env("LD_PRELOAD", "libvibeshine-kwin-gpu.so"); configure_allocator_routing(lookup_allocator, false); require(!hooks_enabled, "native scanout allocator was routed to a render node"); - require(!std::getenv("LD_PRELOAD") && !std::getenv("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE"), "native allocator path leaked preload into compositor children"); + require(!lizardbyte::common::get_env("LD_PRELOAD", env_value) && !lizardbyte::common::get_env("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE", env_value), "native allocator path leaked preload into compositor children"); require_fallback(); require(lookups == 0 && enumerations == 0, "native KMS allocation inspected other GPUs"); auto *physical = gbm_create_device(nvidia_one.fd); @@ -302,12 +303,12 @@ int main() { }); run("explicit PCI chooses one of two NVIDIA devices without changing seat metadata", [&] { native_devices = {&nvidia_two, &virtio, &virtual_kms, &nvidia_one}; - setenv("VIBESHINE_KWIN_RENDER_PCI", "0000:01:00.0", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_RENDER_PCI", "0000:01:00.0"); require_routed(gbm_create_device(virtual_kms.fd), nvidia_one); }); run("the second NVIDIA can be chosen independently of enumeration order", [&] { native_devices.push_back(&nvidia_two); - setenv("VIBESHINE_KWIN_RENDER_PCI", "0000:02:00.0", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_RENDER_PCI", "0000:02:00.0"); require_routed(gbm_create_device(virtual_kms.fd), nvidia_two); }); run("multiple NVIDIA devices automatically use the lowest PCI address", [&] { @@ -330,20 +331,20 @@ int main() { }); run("empty override uses the stable automatic multi-GPU selection", [&] { native_devices = {&nvidia_two, &virtual_kms, &virtio, &nvidia_one}; - setenv("VIBESHINE_KWIN_RENDER_PCI", "", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_RENDER_PCI", ""); require_routed(gbm_create_device(virtual_kms.fd), nvidia_one); }); run("invalid PCI override safely preserves original virtual and seat allocators", [&] { - setenv("VIBESHINE_KWIN_RENDER_PCI", "0000:01:00.0junk", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_RENDER_PCI", "0000:01:00.0junk"); require_fallback(); }); run("an unmatched explicit PCI override does not silently pick another GPU", [&] { - setenv("VIBESHINE_KWIN_RENDER_PCI", "0000:02:00.0", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_RENDER_PCI", "0000:02:00.0"); require_fallback(); }); run("an unmatched explicit override also refuses the automatic multi-GPU default", [&] { native_devices.push_back(&nvidia_two); - setenv("VIBESHINE_KWIN_RENDER_PCI", "0000:03:00.0", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_RENDER_PCI", "0000:03:00.0"); require_fallback(); }); run("render-node renumbering is rejected after open", [&] { @@ -399,7 +400,7 @@ int main() { }); run("native compatibility honors PCI choice and falls back when renderer is absent", [&] { native_devices.push_back(&nvidia_two); - setenv("VIBESHINE_KWIN_RENDER_PCI", "0000:02:00.0", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_RENDER_PCI", "0000:02:00.0"); int original; unsigned calls = 0; render_device_body = [&](const void *, drmDevicePtr device) -> void * { @@ -411,7 +412,7 @@ int main() { return &original; }; require(vibeshine_kwin_render_device(nullptr, &virtual_kms.record) == &original && calls == 2, "missing render device did not preserve native virtual compatibility"); - setenv("VIBESHINE_KWIN_RENDER_PCI", "bad", 1); + lizardbyte::common::set_env("VIBESHINE_KWIN_RENDER_PCI", "bad"); calls = 0; require(vibeshine_kwin_render_device(nullptr, &virtual_kms.record) == &original && calls == 1, "invalid PCI choice did not preserve native compatibility"); require_original_devices(); diff --git a/tests/unit/driver/test_broker_contract.cpp b/tests/unit/driver/test_broker_contract.cpp index a0ebd7f..ff44de5 100644 --- a/tests/unit/driver/test_broker_contract.cpp +++ b/tests/unit/driver/test_broker_contract.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include namespace vdd = virtual_display::driver; diff --git a/tests/unit/driver/test_cli_contract.cpp b/tests/unit/driver/test_cli_contract.cpp index abe3439..ee79e70 100644 --- a/tests/unit/driver/test_cli_contract.cpp +++ b/tests/unit/driver/test_cli_contract.cpp @@ -3,7 +3,7 @@ #include "virtual_display/driver/windows_cli_utils.h" #include -#include +#include #include #include diff --git a/tests/unit/driver/test_control_client.cpp b/tests/unit/driver/test_control_client.cpp index b770175..ed17fa0 100644 --- a/tests/unit/driver/test_control_client.cpp +++ b/tests/unit/driver/test_control_client.cpp @@ -2,7 +2,7 @@ #include "virtual_display/driver/display_identity.h" #include -#include +#include #include namespace vdd = virtual_display::driver; diff --git a/tests/unit/driver/test_control_protocol.cpp b/tests/unit/driver/test_control_protocol.cpp index b282f01..6748829 100644 --- a/tests/unit/driver/test_control_protocol.cpp +++ b/tests/unit/driver/test_control_protocol.cpp @@ -4,7 +4,7 @@ #include "virtual_display/driver/windows_control_protocol.h" #include -#include +#include #include #include #include diff --git a/tests/unit/driver/test_display_identity.cpp b/tests/unit/driver/test_display_identity.cpp index 21cdb60..aaa52ff 100644 --- a/tests/unit/driver/test_display_identity.cpp +++ b/tests/unit/driver/test_display_identity.cpp @@ -1,6 +1,6 @@ #include "virtual_display/driver/display_identity.h" -#include +#include namespace vdd = virtual_display::driver; diff --git a/tests/unit/driver/test_driver_controller.cpp b/tests/unit/driver/test_driver_controller.cpp index 36844bd..34c80ff 100644 --- a/tests/unit/driver/test_driver_controller.cpp +++ b/tests/unit/driver/test_driver_controller.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/tests/unit/driver/test_edid.cpp b/tests/unit/driver/test_edid.cpp index 814c2ff..1f65373 100644 --- a/tests/unit/driver/test_edid.cpp +++ b/tests/unit/driver/test_edid.cpp @@ -1,7 +1,7 @@ #include "virtual_display/driver/edid.h" #include -#include +#include namespace vdd = virtual_display::driver; diff --git a/tests/unit/driver/test_frame_ring_lifetime.cpp b/tests/unit/driver/test_frame_ring_lifetime.cpp index 1bfe02e..0da3334 100644 --- a/tests/unit/driver/test_frame_ring_lifetime.cpp +++ b/tests/unit/driver/test_frame_ring_lifetime.cpp @@ -2,8 +2,8 @@ #include #include -#include #include +#include namespace vdd = virtual_display::driver; @@ -21,7 +21,7 @@ namespace { std::shared_ptr destroyed_; }; - class FrameRingLifetimeTest: public testing::Test { + class FrameRingLifetimeTest: public BaseTest { protected: std::chrono::steady_clock::time_point now {std::chrono::seconds {100}}; vdd::DisplayStore store {2, 2}; diff --git a/tests/unit/driver/test_frame_ring_server.cpp b/tests/unit/driver/test_frame_ring_server.cpp index 8f6e183..93c9311 100644 --- a/tests/unit/driver/test_frame_ring_server.cpp +++ b/tests/unit/driver/test_frame_ring_server.cpp @@ -1,7 +1,7 @@ #include "virtual_display/driver/frame_ring_server.h" #include -#include +#include namespace vdd = virtual_display::driver; @@ -16,7 +16,7 @@ namespace { } }; - class FrameRingServerTest: public testing::Test { + class FrameRingServerTest: public BaseTest { protected: std::chrono::steady_clock::time_point now {std::chrono::seconds {200}}; vdd::DisplayStore store {2, 2}; diff --git a/tests/unit/driver/test_frame_transport_capabilities.cpp b/tests/unit/driver/test_frame_transport_capabilities.cpp index 6c77e6c..31e891f 100644 --- a/tests/unit/driver/test_frame_transport_capabilities.cpp +++ b/tests/unit/driver/test_frame_transport_capabilities.cpp @@ -2,7 +2,7 @@ #include "virtual_display/driver/ioctl_dispatcher.h" #include -#include +#include #include #include diff --git a/tests/unit/driver/test_hdr_capabilities.cpp b/tests/unit/driver/test_hdr_capabilities.cpp index c067bad..f2357ed 100644 --- a/tests/unit/driver/test_hdr_capabilities.cpp +++ b/tests/unit/driver/test_hdr_capabilities.cpp @@ -1,6 +1,6 @@ #include "virtual_display/driver/hdr_capabilities.h" -#include +#include namespace vdd = virtual_display::driver; diff --git a/tests/unit/driver/test_ioctl_dispatcher.cpp b/tests/unit/driver/test_ioctl_dispatcher.cpp index bc844ea..3b07b14 100644 --- a/tests/unit/driver/test_ioctl_dispatcher.cpp +++ b/tests/unit/driver/test_ioctl_dispatcher.cpp @@ -1,7 +1,7 @@ #include "virtual_display/driver/ioctl_dispatcher.h" #include -#include +#include #include #include diff --git a/tests/unit/driver/test_lease_store.cpp b/tests/unit/driver/test_lease_store.cpp index e2dbdca..edbb63d 100644 --- a/tests/unit/driver/test_lease_store.cpp +++ b/tests/unit/driver/test_lease_store.cpp @@ -3,8 +3,8 @@ #include #include -#include #include +#include #include #include diff --git a/tests/unit/driver/test_probe_contract.cpp b/tests/unit/driver/test_probe_contract.cpp index a3c1852..0681762 100644 --- a/tests/unit/driver/test_probe_contract.cpp +++ b/tests/unit/driver/test_probe_contract.cpp @@ -3,8 +3,8 @@ #include #include #include -#include #include +#include #include namespace vdd = virtual_display::driver; diff --git a/tests/unit/driver/test_windows_driver_modes.cpp b/tests/unit/driver/test_windows_driver_modes.cpp index 3ac296d..f91d4d7 100644 --- a/tests/unit/driver/test_windows_driver_modes.cpp +++ b/tests/unit/driver/test_windows_driver_modes.cpp @@ -2,8 +2,8 @@ #include #include -#include #include +#include #include #include diff --git a/tests/unit/driver/test_windows_driver_state.cpp b/tests/unit/driver/test_windows_driver_state.cpp index b0fcf79..ccae8cb 100644 --- a/tests/unit/driver/test_windows_driver_state.cpp +++ b/tests/unit/driver/test_windows_driver_state.cpp @@ -1,7 +1,7 @@ #include "virtual_display/driver/windows_driver_state.h" #include -#include +#include #include namespace vdd = virtual_display::driver; diff --git a/tests/unit/linux_control_client.cpp b/tests/unit/linux_control_client.cpp index f62394a..b6ce540 100644 --- a/tests/unit/linux_control_client.cpp +++ b/tests/unit/linux_control_client.cpp @@ -4,7 +4,7 @@ #include #include - #include + #include #include #include #include diff --git a/tests/unit/linux_drm_capture_test.cpp b/tests/unit/linux_drm_capture_test.cpp index 86892c3..1381686 100644 --- a/tests/unit/linux_drm_capture_test.cpp +++ b/tests/unit/linux_drm_capture_test.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ #ifdef __linux__ - #include + #include #include #include #include diff --git a/tests/unit/linux_drm_change_test.cpp b/tests/unit/linux_drm_change_test.cpp index 0877c39..24345b7 100644 --- a/tests/unit/linux_drm_change_test.cpp +++ b/tests/unit/linux_drm_change_test.cpp @@ -2,7 +2,7 @@ #ifdef __linux__ - #include + #include #include #include #include