test: check the range's QueryInterface contract #1724

Merged
ChazY11 merged 1 commit from upstream-pr/1731 into main 2026-11-24 18:08:42 +00:00
ChazY11 commented 2026-11-24 17:55:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T17:55:35Z.


What

src/d3d12_xs_range.cpp implements QueryInterface as:

if (!out) return E_POINTER;
*out = nullptr;
if (iid != __uuidof(IUnknown) && iid != __uuidof(IX2WGpuRange)) return E_NOINTERFACE;
*out = static_cast<IX2WGpuRange*>(this);
AddRef();
return S_OK;

The device-free check never calls it on the range object, so both halves can be removed without a failure. Two mutations,
each rebuilt and reverted:

IID test replaced with `if (false)`      d3d12_xs_range FAILED   before this change: passed
`*out = nullptr` removed                 d3d12_xs_range FAILED   before this change: passed

The second one is the reason the case seeds the output with a sentinel before each call: a refusal that leaves the pointer
alone is a caller-visible bug even though the HRESULT is right.

Change

Four assertions after the range is created: IX2WGpuRange and IUnknown return the range, ID3D12Device is refused with
E_NOINTERFACE and a cleared output, and a null output is E_POINTER.

+        void* queried = reinterpret_cast<void*>(std::uintptr_t{1});
+        expect(range->QueryInterface(__uuidof(IX2WGpuRange), &queried) == S_OK && queried == range, ...);
+        ...
+        // Each successful query takes a reference the way COM does; give both back so the release
+        // accounting below still sees the count the rest of the fixture expects.
+        range->Release();
+        range->Release();

That pair of releases is not decoration: without it the fixture fails later, because the counted windows and the
live_windows accounting assume the range holds exactly the references it took. Worth knowing for anyone extending this
block.

Tested

cmake --preset dev
cmake --build --preset dev --target d3d12_xs_range_check
ctest --preset dev --no-tests=error -R '^d3d12_xs_range' -V
with the cases, source untouched        d3d12_xs_range Passed, d3d12_xs_range_full_last_window_control Passed
IID test removed                        d3d12_xs_range FAILED
out-pointer clear removed               d3d12_xs_range FAILED
reverted, rebuilt                       both Passed

Scope

One test file, no behaviour change. This is the second of the three unwitnessed guards in create/the range object from
#1727; the remaining one is the window-count limit, which I do not think can be witnessed — the UINT bound rejects a
count long before windows_.max_size() could fire, so that second comparison is unreachable and its mutation is
equivalent. I am not going to add a case that cannot distinguish anything.

Notes

  • AI-assisted.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588086312 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1731). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T17:55:35Z. --- ## What `src/d3d12_xs_range.cpp` implements `QueryInterface` as: ```cpp if (!out) return E_POINTER; *out = nullptr; if (iid != __uuidof(IUnknown) && iid != __uuidof(IX2WGpuRange)) return E_NOINTERFACE; *out = static_cast<IX2WGpuRange*>(this); AddRef(); return S_OK; ``` The device-free check never calls it on the range object, so both halves can be removed without a failure. Two mutations, each rebuilt and reverted: ```text IID test replaced with `if (false)` d3d12_xs_range FAILED before this change: passed `*out = nullptr` removed d3d12_xs_range FAILED before this change: passed ``` The second one is the reason the case seeds the output with a sentinel before each call: a refusal that leaves the pointer alone is a caller-visible bug even though the HRESULT is right. ## Change Four assertions after the range is created: `IX2WGpuRange` and `IUnknown` return the range, `ID3D12Device` is refused with `E_NOINTERFACE` and a cleared output, and a null output is `E_POINTER`. ```diff + void* queried = reinterpret_cast<void*>(std::uintptr_t{1}); + expect(range->QueryInterface(__uuidof(IX2WGpuRange), &queried) == S_OK && queried == range, ...); + ... + // Each successful query takes a reference the way COM does; give both back so the release + // accounting below still sees the count the rest of the fixture expects. + range->Release(); + range->Release(); ``` That pair of releases is not decoration: without it the fixture fails later, because the counted windows and the `live_windows` accounting assume the range holds exactly the references it took. Worth knowing for anyone extending this block. ## Tested ```powershell cmake --preset dev cmake --build --preset dev --target d3d12_xs_range_check ctest --preset dev --no-tests=error -R '^d3d12_xs_range' -V ``` ```text with the cases, source untouched d3d12_xs_range Passed, d3d12_xs_range_full_last_window_control Passed IID test removed d3d12_xs_range FAILED out-pointer clear removed d3d12_xs_range FAILED reverted, rebuilt both Passed ``` ## Scope One test file, no behaviour change. This is the second of the three unwitnessed guards in `create`/the range object from #1727; the remaining one is the window-count limit, which I do not think can be witnessed — the `UINT` bound rejects a count long before `windows_.max_size()` could fire, so that second comparison is unreachable and its mutation is equivalent. I am not going to add a case that cannot distinguish anything. ## Notes - AI-assisted.
upstream-sync closed this pull request 2026-11-24 19:01:08 +00:00
tedin7 commented 2026-11-24 19:01:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:04:12Z.

Review: COMMENTED


Reviewed commit 50625c8ca5955097765ce742e4ecd89e7d8e4752.

One formatting defect to fix before merging:

  • P2 — Missing newline after closing brace (tests/d3d12_xs_range_check.cpp:212):
        }    expect(range->GetSize() == size && range->GetWindowSize() == window32 && range->GetWindowCount() == 3,
    
    Please add a newline between } and expect(...).

Optional tightening (non-blocking):

  • Checking the returned refcounts on the two Release() calls (expect(range->Release() == 2 && range->Release() == 1, ...)) would catch a missing AddRef() in QueryInterface cleanly as a test failure instead of hitting use-after-free on the second Release().

Local verification

  • Linux checks (git diff --check, docs_links_check.py, bidi_controls_check.py): PASS
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): cmake --build --preset dev --target d3d12_xs_range_check -- -j 6 + ctest --preset dev -R '^(d3d12_xs_range|d3d12_xs_range_full_last_window_control)$' --parallel 4 --no-tests=error --output-on-failure -> 2/2 passed
    • Release /O2 (--preset release): cmake --build --preset release --target d3d12_xs_range_check -- -j 6 + ctest --preset release -R '^(d3d12_xs_range|d3d12_xs_range_full_last_window_control)$' --parallel 4 --no-tests=error --output-on-failure -> 2/2 passed

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044697619 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1731#pullrequestreview-6044697619). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:04:12Z. **Review:** COMMENTED --- Reviewed commit `50625c8ca5955097765ce742e4ecd89e7d8e4752`. One formatting defect to fix before merging: - **P2 — Missing newline after closing brace (`tests/d3d12_xs_range_check.cpp:212`)**: ```cpp } expect(range->GetSize() == size && range->GetWindowSize() == window32 && range->GetWindowCount() == 3, ``` Please add a newline between `}` and `expect(...)`. Optional tightening (non-blocking): - Checking the returned refcounts on the two `Release()` calls (`expect(range->Release() == 2 && range->Release() == 1, ...)`) would catch a missing `AddRef()` in `QueryInterface` cleanly as a test failure instead of hitting use-after-free on the second `Release()`. ### Local verification - Linux checks (`git diff --check`, `docs_links_check.py`, `bidi_controls_check.py`): PASS - Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP): - Debug (`--preset dev`): `cmake --build --preset dev --target d3d12_xs_range_check -- -j 6` + `ctest --preset dev -R '^(d3d12_xs_range|d3d12_xs_range_full_last_window_control)$' --parallel 4 --no-tests=error --output-on-failure` -> **2/2 passed** - Release `/O2` (`--preset release`): `cmake --build --preset release --target d3d12_xs_range_check -- -j 6` + `ctest --preset release -R '^(d3d12_xs_range|d3d12_xs_range_full_last_window_control)$' --parallel 4 --no-tests=error --output-on-failure` -> **2/2 passed** AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1724
No description provided.