Add error-path tests for InferenceSession Run/Load/Initialize validation - #29555
Merged
Gopalakrishnan Nallasamy (GopalakrishnanN) merged 2 commits intoJul 9, 2026
Conversation
…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 started reviewing on behalf of
Gopalakrishnan Nallasamy (GopalakrishnanN)
July 6, 2026 02:53
View session
Contributor
There was a problem hiding this comment.
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
RunbeforeInitialize,InitializebeforeLoad, 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.
Xavier Dupré (xadupre)
previously approved these changes
Jul 7, 2026
Gopalakrishnan Nallasamy (GopalakrishnanN)
requested a review
from Xavier Dupré (xadupre)
July 8, 2026 23:00
Xavier Dupré (xadupre)
approved these changes
Jul 9, 2026
Gopalakrishnan Nallasamy (GopalakrishnanN)
merged commit Jul 9, 2026
780d714
into
main
87 checks passed
Gopalakrishnan Nallasamy (GopalakrishnanN)
deleted the
GopalakrishnanN/session-error-path-tests
branch
July 9, 2026 18:15
This was referenced Aug 12, 2026
This was referenced Aug 17, 2026
Closed
Closed
This was referenced Aug 25, 2026
This was referenced Sep 1, 2026
This was referenced Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds error-path unit tests for
InferenceSessionvalidation / 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.RunBeforeInitializeReturnsErrorRunwhen not initializedSession not initializedInitializeBeforeLoadReturnsErrorInitializewith no model loadedModel was not loadedRunWithInvalidOutputNameReturnsErrorValidateOutputsunknown outputInvalid output nameRunWithWrongInputTypeReturnsErrorCheckTypes(input)Unexpected input data typeRunWithWrongInputRankReturnsErrorCheckShapes(input rank)Invalid rank for inputRunWithMismatchedFeedCountReturnsErrorfeed names has ...RunWithWrongOutputTypeReturnsErrorCheckTypes(output)Unexpected output data typeLoadMalformedModelFromArrayReturnsErrorLoadNonexistentModelReturnsErrorMotivation and Context
Error/validation paths in
InferenceSession::Run/Initialize/Loadwere thinly tested relative to the numeric happy-path bulk. These tests lock in the failure contracts (both the non-OKStatusand the message substring, viaASSERT_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 byTestOptionalInputs, so it is intentionally not duplicated.onnxruntime/test/framework/inference_session_test.cc); no product/runtime code is touched.