Skip to content

Add CI coverage for edlcodegen out-param codegen - #208

Merged
Branden Bonaby (bbonaby) merged 3 commits into
mainfrom
user/gudge/edlcodegen/codegen-ci-coverage
Aug 3, 2026
Merged

Add CI coverage for edlcodegen out-param codegen#208
Branden Bonaby (bbonaby) merged 3 commits into
mainfrom
user/gudge/edlcodegen/codegen-ci-coverage

Conversation

@MGudgin

@MGudgin Gudge (MGudgin) commented Jul 15, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #207. That PR fixed the Rust out-only struct/wstring out-param codegen (panic-loop on None, plus a symmetric result-extraction DoS). This PR adds the regression protection that was called out as missing: an executable test of the generator and a CI gate against baseline drift.

Changes

1. Generator unit test (executable, catches a revert)

tests/UnitTests/ToolingExecutableTests/CodeGenerationRustOutParamTests.cpp parses TestFiles/OutParamCodeGenTest.edl and asserts the Rust emit functions produce the panic-safe forms:

  • Dispatch closure (GetClosureFunctionStatement): out-only struct/wstring params emit insert(Default::default()) — never .as_mut().expect(...) or get_or_insert_with.
  • Extraction (GetMoveFromAbiStructToParamStatements): out-only struct/wstring emit ok_or(<crate>::AbiError::Hresult(0x80070057u32 as i32))? — never .expect(...), with the crate-appropriate error path (edlcodegen_enclave vs edlcodegen_host).
  • An [in, out] struct is included as a contrast case (plain borrow / plain move), so the test also pins that these paths are not over-applied.

Reverting either fix in CodeGenerationHelpers.h fails this test. It runs in the existing cpp_ci EdlCodeGen unit-test job (no new infra).

2. Baseline drift gate

A cpp_ci step runs after the build (which regenerates CurrentCodeGenerationState) and fails if the checked-in baselines differ from the freshly-built generator's output — catching a forgotten regeneration or an unexpected codegen change in review. x64 only, since the generator only runs on x64.

Testing

  • Built UnitTests via the solution and ran the new tests with vstest: 3/3 pass (Dispatch_OutStructAndWString_UseInsert_NotExpect, Extract_OutStructAndWString_UseOkOr_NotExpect, Extract_HostDirection_UsesHostCrate).
  • Verified the baseline drift gate passes on the current tree (no drift).

Gudge (MGudgin) and others added 2 commits July 15, 2026 14:20
This commit fixes a code-generation bug that made every Rust enclave ecall (or
host callback) with an out-only, non-array struct or wstring parameter fault,
hardens the symmetric result-extraction path against malformed input, and adds
regression coverage for both.

Details:
- Inbound dispatch: the enclave/host closure borrowed a struct/wstring [out]
  param from an ABI Option<T> that is None on entry (the caller never sends an
  out value) via .as_mut().expect(...). That panicked; in a no_std enclave the
  panic handler is loop {}, so the call spun at ~99% CPU. Generate
  abi_type.m_x.insert(Default::default()) instead: it inserts a default so the
  closure can borrow &mut T, and because it overwrites unconditionally it also
  discards any value the other side of the ABI supplied for an out-only param,
  so caller-controlled contents never reach the implementation.
- Result extraction: the caller stub copied a returned struct/wstring out param
  back with result.m_x.expect(...). When an enclave unpacks a host callback's
  result this runs on untrusted, host-controlled data, so a host omitting the
  field would re-trigger the same panic/loop inside the enclave. Generate
  result.m_x.ok_or(<crate>::AbiError::Hresult(0x80070057u32 as i32))? instead
  (0x80070057 is E_INVALIDARG; the u32-to-i32 cast matches the library, as the
  value does not fit in i32), so a missing field fails the call as an ABI error
  rather than faulting the caller.
- Only non-array, out-only struct and wstring params take these Option<T> ABI
  paths; string, arrays, vectors, and in/inout params are unaffected and already
  correct. Scalar/optional out-params were also unaffected.
- Extend CurrentCodeGenerationState/CodeGenerationState.edl with [out]
  TestStruct1 and [out] wstring params (trusted and untrusted). The prior test
  EDL had no out-only non-array struct/wstring param, so these codegen paths
  were never captured in the checked-in baselines, which is why the bug shipped.
- Regenerate the CurrentCodeGenerationState baselines so the fixed dispatch and
  extraction code is locked in against regression.

Test:
- Rebuilt ToolingExecutable; its post-build GenerateCodeGenCurrentState target
  regenerated the C++ and Rust baselines with no errors.
- Confirmed the regenerated Rust dispatch closures emit insert(Default::default())
  and the extraction stubs emit
  ok_or(<crate>::AbiError::Hresult(0x80070057u32 as i32))? for the new
  struct/wstring out-params.
- Type-checked both generated patterns with rustc: insert yields &mut T for the
  closure, and ok_or(...)? returns Err on a missing (None) field
  (0x80070057u32 as i32 == -2147024809).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3f90c337-7087-44f5-98d7-c0534d1f49b1
This commit adds regression protection for the Rust out-only struct/wstring
code-generation paths fixed in the parent commit: a generator unit test that
fails if the fix is reverted, and a CI gate that fails if the checked-in
generated baselines drift from the generator.

Details:
- Add tests/UnitTests/ToolingExecutableTests/CodeGenerationRustOutParamTests.cpp,
  a unit test that parses TestFiles/OutParamCodeGenTest.edl and asserts the Rust
  emit functions produce the panic-safe forms: the dispatch closure inserts a
  default for out-only struct/wstring params (never .as_mut().expect(...) or
  get_or_insert_with), and the extraction stub surfaces a missing field via
  ok_or(<crate>::AbiError::Hresult(0x80070057u32 as i32))? (never .expect(...)).
  An [in, out] struct is included as a contrast case (plain borrow / move). The
  test runs in the existing cpp_ci EdlCodeGen unit-test job.
- Add a cpp_ci step that, after the build regenerates
  src/ToolingSharedLibrary/CurrentCodeGenerationState, fails if those baselines
  differ from the freshly-built generator output (x64 only; the generator only
  runs on x64). This catches a forgotten regeneration or unexpected codegen
  change in review rather than shipping silently.

Test:
- Built UnitTests via the solution (Debug and Release x64) and ran the new tests
  with vstest: all 3 pass (Dispatch_OutStructAndWString_UseInsert_NotExpect,
  Extract_OutStructAndWString_UseOkOr_NotExpect, Extract_HostDirection_UsesHostCrate).
- Verified the baseline drift gate passes on the current tree (no drift).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3f90c337-7087-44f5-98d7-c0534d1f49b1
@MGudgin
Gudge (MGudgin) force-pushed the user/gudge/edlcodegen/codegen-ci-coverage branch from f1bf8bd to 9c303bb Compare July 15, 2026 22:02
@MGudgin
Gudge (MGudgin) changed the base branch from user/gudge/edlcodegen/fix-struct-out-param to main July 31, 2026 23:18
@MGudgin
Gudge (MGudgin) dismissed Branden Bonaby (bbonaby)’s stale review July 31, 2026 23:18

The base branch was changed.

@bbonaby
Branden Bonaby (bbonaby) merged commit de1c245 into main Aug 3, 2026
15 checks passed
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.

2 participants