Skip to content

[Objective-C] Add encrypted compiled EPContext inference coverage - #33223

Draft
Gopalakrishnan Nallasamy (GopalakrishnanN) wants to merge 8 commits into
mainfrom
GopalakrishnanN/test-encrypted-epcontext-objectivec
Draft

Gopalakrishnan Nallasamy (GopalakrishnanN) wants to merge 8 commits into
mainfrom
GopalakrishnanN/test-encrypted-epcontext-objectivec

Conversation

@GopalakrishnanN

@GopalakrishnanN Gopalakrishnan Nallasamy (GopalakrishnanN) commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add a standalone macOS Objective-C XCTest target for the complete compiled-model/context workflow:

  • Compile the two-input Mul fixture through the executable example plugin EP.
  • Encrypt and persist the compiled ONNX and external context using AES-256-CBC with encrypt-then-HMAC-SHA256, independent random keys, random IVs, and authenticated asset names.
  • Release compilation state, decrypt stored assets, restore context through the public Objective-C read block, and check numerical inference for two input sets.
  • Reject wrong authentication keys, changed ciphertext, mismatched authenticated names, missing callbacks, callback authentication failures, and invalid context payloads.
  • Keep plugin-dependent sources outside the objectivec/ tree copied to the Swift package repository. The separate onnxruntime_objc_encryption_test target owns its plugin dependency, Security framework, model resource, and CTest environment; ordinary Objective-C tests have none of those extra dependencies.
  • Confine native registration, device selection, and compilation to a test-only fixture adapter. Loading, read-block registration, tensors, and inference use public Objective-C APIs. Public compilation and provider-library registration APIs are not added by this test PR.
  • Use explicit provider-options types for Apple Clang, and always remove the temporary directory even when native unregistration throws. Add testCleanupRemovesPlaintextWhenUnregisterThrows to cover that failure path.

The public Objective-C session constructor is path-only. Decrypted compiled ONNX is temporarily persisted during loading and removed during cleanup; external context plaintext remains in memory. This does not establish no-plaintext-at-any-time coverage.

Dependency: #33216. This branch contains the identical shared fixture prerequisite commit so it can receive normal PR CI against main. Merge #33216 first; its changes should then disappear from this PR's diff.

Validation

  • clang-format --dry-run --Werror onnxruntime\test\platform\apple\ort_encrypted_ep_context_test.mm onnxruntime\test\platform\apple\ort_ep_context_fixture.h onnxruntime\test\platform\apple\ort_ep_context_fixture.mm: passed.
  • git diff --check: passed.
  • CMake configuration-branch harness for full macOS, minimal macOS, and iOS: 3 passed. It verifies source isolation, ordinary-test dependencies/resources, and separate-target CTest/plugin/model wiring. Apple targets/framework discovery are mocked; this is not an Apple build.
  • Apple compilation and XCTest execution: NOT RUN locally. This Windows workspace has no Xcode or Apple runtime. Fresh PR CI must provide runtime confirmation.
  • Required Apple validation after building: ctest --test-dir <Apple build directory> -C Release -R '^XCTest.onnxruntime_objc_encryption_test$' --output-on-failure. Both the encrypted-inference test and unregister-failure cleanup regression must execute successfully. The target fails rather than skips if its required plugin path is missing.

Existing macOS full-build CTest execution discovers the separate target automatically. No encrypted-workflow execution is claimed for ordinary XCTest runs, iOS, or the Swift package.

Motivation and Context

Follow up the APIs from #32265 and merged Objective-C binding #32309 with real compiled-state transport and numerical inference coverage. Ordinary model loads and callback-only tests do not prove restored external EPContext execution.

The isolation addresses the Swift package synchronization constraint without adding new public APIs or requiring the copied Objective-C test suite to depend on ORT's example plugin target.

Gopalakrishnan Nallasamy and others added 3 commits October 8, 2026 14:56
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ture

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread onnxruntime/test/testdata/encrypted_ep_context_mul.py Fixed

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.

🟡 Changes recommended

The tamper control modifies the HMAC tag rather than ciphertext, so the stated altered-ciphertext case is not covered.

2 open findings
What changed in this PR

Adds Objective-C end-to-end coverage for encrypted compiled EPContext model restoration and inference, building on #33216.

Changes:

  • Adds an executable Mul EPContext fixture and generated model.
  • Adds encrypted Objective-C compilation, restoration, negative, and inference tests.
  • Provisions the plugin/model for macOS XCTest and documents the workflow.
File Description
.gitignore Tracks the generated ONNX fixture.
cmake/​onnxruntime_objectivec.cmake Links Security.framework and provisions test assets/plugin.
docs/​design/​Compiled_Model_Encryption.md Documents binding workflows and Objective-C coverage.
objectivec/​test/​ort_encrypted_ep_context_test.mm Implements encrypted EPContext integration testing.
onnxruntime/​test/​autoep/​library/​example_plugin_ep/​ep.cc Serializes and restores executable Mul context.
onnxruntime/​test/​autoep/​library/​example_plugin_ep/​ep.h Adds restored-kernel state and configuration.
onnxruntime/​test/​autoep/​library/​example_plugin_ep/​ep_factory.cc Parses the execution-test option.
onnxruntime/​test/​testdata/​encrypted_ep_context_mul.py Generates the two-input Mul model.
onnxruntime/​test/​testdata/​encrypted_ep_context_mul.onnx Provides the bundled source-model fixture.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread objectivec/test/ort_encrypted_ep_context_test.mm Outdated
Comment thread docs/design/Compiled_Model_Encryption.md Outdated
Gopalakrishnan Nallasamy and others added 4 commits October 8, 2026 15:32
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the existing unordered-map overload explicitly so GCC and Clang do not have to choose between the map and parallel-vector options overloads.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Match NSUInteger operands to avoid Clang -Werror=sign-compare failures in the macOS Debug matrix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@GopalakrishnanN

Copy link
Copy Markdown
Contributor Author

Fixed both macOS Debug -Werror=sign-compare errors by making expected XCTest counts NSUInteger, plus the shared Linux fixture overload ambiguity. Pushed 8de1640. Corrected C++ fixture call passed MSVC C++17 /W4 /WX syntax validation; Apple XCTest compilation requires the newly triggered macOS CI. No old-head runs were manually retriggered.

@GopalakrishnanN

Copy link
Copy Markdown
Contributor Author

Retried only the confirmed DNS-failed current-head iPhone simulator job after the macOS workflow completed. Original setup error: getaddrinfo ENOTFOUND github.com while downloading CMake. No stale-head or green jobs were retriggered.

@tianleiwu Tianlei Wu (tianleiwu) 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.

The Objective-C XCTest (ort_encrypted_ep_context_test.mm) and CMake wiring are well structured, with a clean AES-256-CBC + encrypt-then-HMAC-SHA256 construction and thorough negative controls.

Requesting changes for one blocking compile issue on Apple Clang: objectivec/test/ort_encrypted_ep_context_test.mm line 147 still calls native.AppendExecutionProvider_V2(nativeEnv, {*device}, {}) with {} as the third argument, which is ambiguous on Clang (the same issue fixed for test_execution.cc in fcdaaa40eb).

Comment thread objectivec/test/ort_encrypted_ep_context_test.mm Outdated
Comment thread objectivec/test/ort_encrypted_ep_context_test.mm Outdated
Comment thread cmake/onnxruntime_objectivec.cmake Outdated
Comment thread objectivec/test/ort_encrypted_ep_context_test.mm Outdated
Move plugin-dependent tests outside the Swift package source tree into a separate macOS XCTest target. Confine native setup to a fixture adapter, disambiguate provider options, and verify plaintext cleanup after an unregister exception.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

5 participants