Skip to content

Add error-path tests for InferenceSession Run/Load/Initialize validation - #29555

Merged
Gopalakrishnan Nallasamy (GopalakrishnanN) merged 2 commits into
mainfrom
GopalakrishnanN/session-error-path-tests
Jul 9, 2026
Merged

Add error-path tests for InferenceSession Run/Load/Initialize validation#29555
Gopalakrishnan Nallasamy (GopalakrishnanN) merged 2 commits into
mainfrom
GopalakrishnanN/session-error-path-tests

Conversation

@GopalakrishnanN

Copy link
Copy Markdown
Contributor

Description

Adds error-path unit tests for InferenceSession validation / early-return branches, which were under-covered (only failure/kExpectFailure-style assertions were a small fraction of the suite). All nine target previously-untested branches and are verified passing against a local Release build.

Test Branch exercised Asserted message
RunBeforeInitializeReturnsError Run when not initialized Session not initialized
InitializeBeforeLoadReturnsError Initialize with no model loaded Model was not loaded
RunWithInvalidOutputNameReturnsError ValidateOutputs unknown output Invalid output name
RunWithWrongInputTypeReturnsError CheckTypes (input) Unexpected input data type
RunWithWrongInputRankReturnsError CheckShapes (input rank) Invalid rank for input
RunWithMismatchedFeedCountReturnsError feed/name count mismatch feed names has ...
RunWithWrongOutputTypeReturnsError CheckTypes (output) Unexpected output data type
LoadMalformedModelFromArrayReturnsError malformed model bytes graceful failure
LoadNonexistentModelReturnsError missing model file graceful failure

Motivation and Context

Error/validation paths in InferenceSession::Run / Initialize / Load were thinly tested relative to the numeric happy-path bulk. These tests lock in the failure contracts (both the non-OK Status and the message substring, via ASSERT_STATUS_NOT_OK_AND_HAS_SUBSTR) so a regression that changes the behavior or the message surfaces clearly.

Notes

  • "Invalid input name" is already covered by TestOptionalInputs, so it is intentionally not duplicated.
  • Test-only change (onnxruntime/test/framework/inference_session_test.cc); no product/runtime code is touched.

…ion (audit T8)

Nine tests covering previously-untested validation / early-return branches: Run-before-Initialize ('Session not initialized'), Initialize-before-Load ('Model was not loaded'), invalid output name, wrong input type (CheckTypes), wrong input rank (CheckShapes), mismatched feed count, wrong output type, malformed-model ingestion via Load(const void*, int), and nonexistent-file load. 'Invalid input name' is already covered by TestOptionalInputs. All nine verified passing against a local Release build.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens ONNX Runtime’s InferenceSession unit test coverage by adding targeted tests for validation and early-return error paths in Load, Initialize, and Run, ensuring these failure contracts (Status + message substrings) are guarded against regressions.

Changes:

  • Add new unit tests covering Run before Initialize, Initialize before Load, and invalid output-name validation.
  • Add new unit tests covering input/output type and shape validation failures, plus feed-name/value count mismatch.
  • Add new unit tests ensuring malformed model bytes and nonexistent model paths fail gracefully.

Comment thread onnxruntime/test/framework/inference_session_test.cc Outdated
@GopalakrishnanN
Gopalakrishnan Nallasamy (GopalakrishnanN) merged commit 780d714 into main Jul 9, 2026
87 checks passed
@GopalakrishnanN
Gopalakrishnan Nallasamy (GopalakrishnanN) deleted the GopalakrishnanN/session-error-path-tests branch July 9, 2026 18:15
This was referenced Aug 12, 2026
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.

3 participants