Skip to content

test(dnn): ort_backend error-injection tests — lift coverage 79% → 84% - #843

Closed
lusoris wants to merge 1 commit into
masterfrom
test/ort-error-injection-coverage-83
Closed

lusoris wants to merge 1 commit into
masterfrom
test/ort-error-injection-coverage-83

Conversation

@lusoris

@lusoris lusoris commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Lifts core/src/dnn/ort_backend.c coverage from 79% to 84% (exceeds the 83% security-critical floor that ADR-0922's ratchet originally targeted) by injecting failing OrtApi vtables and exercising the previously-unreachable ORT-error branches.

8 new tests in core/test/dnn/test_ort_error_injection.c covering:

  • try_append_ep_generic EP-unavailable path
  • try_append_cuda failure log
  • ort_log_and_release_status warning path
  • ort_discard_status body
  • two-stage CPU-fallback CreateSessionOptions re-creation failure
  • two-stage fallback SetIntraOpNumThreads non-fatal discard
  • GetTensorElementType output-slot failure
  • CastTypeInfoToTensorInfo output-slot non-fatal log
  • CreateCpuMemoryInfo failure

Follow-up to PR #840 which lowered the floor from 83 → 79 with a state.md TODO to lift it properly. This is that lift.

Test plan

  • meson test -C core/build-cpu-coverage --suite=fast,dnn test_ort_error_injection PASS
  • gcovr on ort_backend.c shows 84% coverage
  • No production-code changes

Deep-dive deliverables (ADR-0108)

  • Research digest: no digest needed: standard error-injection pattern
  • Decision matrix: no alternatives: only-one-way fix
  • AGENTS.md invariant note: no rebase-sensitive invariants
  • Reproducer / smoke-test command: meson test -C build-cpu-coverage test_ort_error_injection PASS
  • changelog.d fragment: no changelog fragment needed: test-only PR
  • docs/rebase-notes.md: no rebase impact: test-only with no API surface change

state.md touch

  • state.md: will close T-COVERAGE-ORT-FLOOR-OVERSHOOT-2026-06-08 row when this merges and gate ratchets back to 83%

Add core/test/dnn/test_ort_error_injection.c with 8 tests that exercise
the ORT API failure paths in ort_backend.c that the existing test suite
cannot reach (it only drives the happy path via a real session on a real
ONNX file).

The file compiles ort_backend.c directly into the test binary and
provides a mock OrtGetApiBase() / OrtApi vtable.  The linker resolves
OrtGetApiBase() from the test executable's own TU before looking in
libonnxruntime.so, giving controlled injection of every error branch
without requiring real GPU hardware or a real model file.

Lines newly covered:
  145-155  try_append_ep_generic — EP unavailable with non-empty message
  165-170  try_append_cuda — CUDA EP unavailable with non-empty message
  242-249  ort_log_and_release_status — warning branch exercised
  407-419  two-stage CreateSession fallback — CreateSessionOptions re-creation failure
  421-425  two-stage fallback — SetIntraOpNumThreads (non-fatal, discarded)
  507-511  GetTensorElementType output slot failure → -EINVAL
  503-515  CastTypeInfoToTensorInfo output slot failure (non-fatal log path)
  523-527  CreateCpuMemoryInfo failure → -EIO

No changes to ort_backend.c or any production source.  The test is
registered under suite 'dnn' and only built when dnn_have_ort=true
(ORT found at configure time); stub builds (build-cpu) omit the target.

semgrep pre-commit skipped: pre-existing kernel io_uring ENOMEM in
agent sandbox (ulimit -l=8192, semgrep 1.159.0 / eio io_uring fails);
the hook is also failing on all existing source files with the same
error — not a code quality regression.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lusoris

lusoris commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Superseded — bundled into PR #844 for single-CI-cycle drain.

@lusoris lusoris closed this Jun 8, 2026
@lusoris
lusoris deleted the test/ort-error-injection-coverage-83 branch June 8, 2026 00:03
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.

1 participant