Skip to content

Add model-ingestion error-path tests for InferenceSession#29558

Open
GopalakrishnanN wants to merge 2 commits into
mainfrom
GopalakrishnanN/more-error-path-tests
Open

Add model-ingestion error-path tests for InferenceSession#29558
GopalakrishnanN wants to merge 2 commits into
mainfrom
GopalakrishnanN/more-error-path-tests

Conversation

@GopalakrishnanN

Copy link
Copy Markdown
Contributor

Description

Extends error-path / negative test coverage for InferenceSession model ingestion (continuation of the audit's "thin error-path coverage" finding). Adds two tests to inference_session_test.cc:

  • LoadModelTwiceReturnsError — a second Load() on a session that already holds a model must be rejected with MODEL_LOADED ("This session already contains a loaded model").
  • LoadInvalidGraphReturnsError — a model whose only node consumes an input that is never defined (not a graph input, initializer, or another node's output) is constructed via the ONNX proto API, serialized, and loaded. Graph Resolve must reject it gracefully (error at Load or Initialize) rather than crash or silently accept it.

Motivation and Context

Failure/validation paths are under-tested relative to the numeric happy-path bulk. These cover the double-load guard and the graph-resolve rejection path for a malformed graph.

Verification

Built onnxruntime_test_all (Release, CPU) and ran both tests locally — both pass:

[ OK ] InferenceSessionTests.LoadModelTwiceReturnsError
[ OK ] InferenceSessionTests.LoadInvalidGraphReturnsError
[ PASSED ] 2 tests.

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 extends ONNX Runtime’s InferenceSession negative/error-path test coverage around model ingestion, ensuring common misuse/malformed-model scenarios are rejected cleanly.

Changes:

  • Adds a test that a second Load() call on the same InferenceSession is rejected.
  • Adds a test that loading/initializing a malformed ONNX model (node consumes an undefined input) fails gracefully.

Comment thread onnxruntime/test/framework/inference_session_test.cc Outdated
Comment thread onnxruntime/test/framework/inference_session_test.cc
Two tests: double-Load rejection ('already contains a loaded model') and invalid-graph rejection (a node consuming an undefined input, built via ONNX proto, rejected at Load/Initialize). Verified passing against a local Release build.
@GopalakrishnanN
GopalakrishnanN force-pushed the GopalakrishnanN/more-error-path-tests branch from 65108e8 to c10bb09 Compare July 10, 2026 17:23
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