diff --git a/onnxruntime/test/platform/ios/ios_package_test/.gitignore b/onnxruntime/test/platform/ios/ios_package_test/.gitignore new file mode 100644 index 0000000000..910554681a --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/.gitignore @@ -0,0 +1,26 @@ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Gcc Patch +/*.gcno diff --git a/onnxruntime/test/platform/ios/ios_package_test/Podfile b/onnxruntime/test/platform/ios/ios_package_test/Podfile new file mode 100644 index 0000000000..78a2390f85 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/Podfile @@ -0,0 +1,15 @@ +platform :ios, '13.0' + +target 'ios_package_test' do + # Comment the next line if you don't want to use dynamic frameworks + use_frameworks! + + # Pods for ios_package_test + pod 'onnxruntime-mobile', :podspec => './onnxruntime-mobile.podspec' + + target 'ios_package_testTests' do + inherit! :search_paths + # Pods for testing + end + +end diff --git a/onnxruntime/test/platform/ios/ios_package_test/README.md b/onnxruntime/test/platform/ios/ios_package_test/README.md new file mode 100644 index 0000000000..980804b708 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/README.md @@ -0,0 +1,47 @@ +# iOS End-to-End Test App for ORT-Mobile + +This End-to-End test app for iOS will test ORT Mobile C/C++ API framework using XCode and CocoaPods + +## Requirements + +- [Prerequisites for building ORT-Mobile for iOS](http://www.onnxruntime.ai/docs/how-to/build/android-ios.html#prerequisites-1) +- [CocoaPods](https://cocoapods.org/) + +## iOS End-to-End Test App Overview + +The iOS End-to-End Test App will use CocoaPods to install the Onnx Runtime C/C++ framework, and run basic End-to-End tests of Onnx Runtime C and C++ API. + +### Model used +- [sigmoid ONNX model](https://github.com/onnx/onnx/blob/f9b0cc99344869c246b8f4011b8586a39841284c/onnx/backend/test/data/node/test_sigmoid/model.onnx) converted to ORT format + + Here's the [document](http://www.onnxruntime.ai/docs/how-to/deploy-on-mobile.html#1-create-ort-format-model-and-configuration-file-with-required-operators) about how you can convert an ONNX model into ORT format. + +### Tests +- [Tests for C API ](./ios_package_testTests/ios_package_test_c_api.m) +- [Tests for C++ API ](./ios_package_testTests/ios_package_test_cpp_api.mm) + +## Build and Test iOS Framework using [build.py](../../../../../tools/ci_build/build.py) + +Use the [build for iOS simulator](http://www.onnxruntime.ai/docs/how-to/build/android-ios.html#cross-build-for-ios-simulator) with `--build_apple_framework` + +## Run the iOS End-to-End Test App standalone + +### Requirements + +- A pre-built ORT Mobile iOS framework, which can be built using the [instruction](#build-and-test-ios-framework-using-buildpy) above. The framework can be found as `/iOS//-iphonesimulator/onnxruntime.framework` + +### Steps + +1. Go to this folder +2. Copy the [onnxruntime-mobile.podspec.template](./onnxruntime-mobile.podspec.template) to `onnxruntime-mobile.podspec` +3. Update the `onnxruntime-mobile.podspec`, replace `${ORT_BASE_FRAMEWORK_ARCHIVE}` with the path of a zip archive contains the pre-built ORT Mobile iOS framework +4. Run `pod install` to install the pre-built ORT Mobile iOS framework +5. Run the following command to perform the test + +``` + xcrun xcodebuild \ + -workspace ./ios_package_test.xcworkspace \ + -destination '' \ + -scheme ios_package_test \ + test +``` \ No newline at end of file diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.pbxproj b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..f76b6c01dd --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.pbxproj @@ -0,0 +1,474 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 229E5921265869BF006E41AE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 229E5920265869BF006E41AE /* AppDelegate.m */; }; + 229E592A265869BF006E41AE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 229E5928265869BF006E41AE /* Main.storyboard */; }; + 229E592F265869C2006E41AE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 229E592D265869C2006E41AE /* LaunchScreen.storyboard */; }; + 229E5932265869C2006E41AE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 229E5931265869C2006E41AE /* main.m */; }; + 229E593C265869C2006E41AE /* ios_package_test_cpp_api.mm in Sources */ = {isa = PBXBuildFile; fileRef = 229E593B265869C2006E41AE /* ios_package_test_cpp_api.mm */; }; + 229E595926586B4A006E41AE /* sigmoid.ort in Resources */ = {isa = PBXBuildFile; fileRef = 229E595826586B4A006E41AE /* sigmoid.ort */; }; + 229E595A26586B4A006E41AE /* sigmoid.ort in Resources */ = {isa = PBXBuildFile; fileRef = 229E595826586B4A006E41AE /* sigmoid.ort */; }; + 22DEADEE265905A7005CBD1C /* ios_package_test_c_api.m in Sources */ = {isa = PBXBuildFile; fileRef = 22DEADED265905A7005CBD1C /* ios_package_test_c_api.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 229E5938265869C2006E41AE /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 229E5914265869BF006E41AE /* Project object */; + proxyType = 1; + remoteGlobalIDString = 229E591B265869BF006E41AE; + remoteInfo = ios_package_test; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 229E591C265869BF006E41AE /* ios_package_test.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ios_package_test.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 229E591F265869BF006E41AE /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 229E5920265869BF006E41AE /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 229E5929265869BF006E41AE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 229E592E265869C2006E41AE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 229E5930265869C2006E41AE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 229E5931265869C2006E41AE /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 229E5937265869C2006E41AE /* ios_package_testTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ios_package_testTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 229E593B265869C2006E41AE /* ios_package_test_cpp_api.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ios_package_test_cpp_api.mm; sourceTree = ""; }; + 229E593D265869C2006E41AE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 229E595826586B4A006E41AE /* sigmoid.ort */ = {isa = PBXFileReference; lastKnownFileType = file; path = sigmoid.ort; sourceTree = ""; }; + 22DEADED265905A7005CBD1C /* ios_package_test_c_api.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ios_package_test_c_api.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 229E5919265869BF006E41AE /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 229E5934265869C2006E41AE /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 229E5913265869BF006E41AE = { + isa = PBXGroup; + children = ( + 229E595426586A77006E41AE /* models */, + 229E591E265869BF006E41AE /* ios_package_test */, + 229E593A265869C2006E41AE /* ios_package_testTests */, + 229E591D265869BF006E41AE /* Products */, + ); + sourceTree = ""; + }; + 229E591D265869BF006E41AE /* Products */ = { + isa = PBXGroup; + children = ( + 229E591C265869BF006E41AE /* ios_package_test.app */, + 229E5937265869C2006E41AE /* ios_package_testTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 229E591E265869BF006E41AE /* ios_package_test */ = { + isa = PBXGroup; + children = ( + 229E591F265869BF006E41AE /* AppDelegate.h */, + 229E5920265869BF006E41AE /* AppDelegate.m */, + 229E5928265869BF006E41AE /* Main.storyboard */, + 229E592D265869C2006E41AE /* LaunchScreen.storyboard */, + 229E5930265869C2006E41AE /* Info.plist */, + 229E5931265869C2006E41AE /* main.m */, + ); + path = ios_package_test; + sourceTree = ""; + }; + 229E593A265869C2006E41AE /* ios_package_testTests */ = { + isa = PBXGroup; + children = ( + 229E593B265869C2006E41AE /* ios_package_test_cpp_api.mm */, + 229E593D265869C2006E41AE /* Info.plist */, + 22DEADED265905A7005CBD1C /* ios_package_test_c_api.m */, + ); + path = ios_package_testTests; + sourceTree = ""; + }; + 229E595426586A77006E41AE /* models */ = { + isa = PBXGroup; + children = ( + 229E595826586B4A006E41AE /* sigmoid.ort */, + ); + path = models; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 229E591B265869BF006E41AE /* ios_package_test */ = { + isa = PBXNativeTarget; + buildConfigurationList = 229E594B265869C2006E41AE /* Build configuration list for PBXNativeTarget "ios_package_test" */; + buildPhases = ( + 229E5918265869BF006E41AE /* Sources */, + 229E5919265869BF006E41AE /* Frameworks */, + 229E591A265869BF006E41AE /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ios_package_test; + productName = ios_package_test; + productReference = 229E591C265869BF006E41AE /* ios_package_test.app */; + productType = "com.apple.product-type.application"; + }; + 229E5936265869C2006E41AE /* ios_package_testTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 229E594E265869C2006E41AE /* Build configuration list for PBXNativeTarget "ios_package_testTests" */; + buildPhases = ( + 229E5933265869C2006E41AE /* Sources */, + 229E5934265869C2006E41AE /* Frameworks */, + 229E5935265869C2006E41AE /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 229E5939265869C2006E41AE /* PBXTargetDependency */, + ); + name = ios_package_testTests; + productName = ios_package_testTests; + productReference = 229E5937265869C2006E41AE /* ios_package_testTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 229E5914265869BF006E41AE /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1250; + TargetAttributes = { + 229E591B265869BF006E41AE = { + CreatedOnToolsVersion = 12.5; + }; + 229E5936265869C2006E41AE = { + CreatedOnToolsVersion = 12.5; + TestTargetID = 229E591B265869BF006E41AE; + }; + }; + }; + buildConfigurationList = 229E5917265869BF006E41AE /* Build configuration list for PBXProject "ios_package_test" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 229E5913265869BF006E41AE; + productRefGroup = 229E591D265869BF006E41AE /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 229E591B265869BF006E41AE /* ios_package_test */, + 229E5936265869C2006E41AE /* ios_package_testTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 229E591A265869BF006E41AE /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 229E592F265869C2006E41AE /* LaunchScreen.storyboard in Resources */, + 229E595926586B4A006E41AE /* sigmoid.ort in Resources */, + 229E592A265869BF006E41AE /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 229E5935265869C2006E41AE /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 229E595A26586B4A006E41AE /* sigmoid.ort in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 229E5918265869BF006E41AE /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 229E5921265869BF006E41AE /* AppDelegate.m in Sources */, + 229E5932265869C2006E41AE /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 229E5933265869C2006E41AE /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 229E593C265869C2006E41AE /* ios_package_test_cpp_api.mm in Sources */, + 22DEADEE265905A7005CBD1C /* ios_package_test_c_api.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 229E5939265869C2006E41AE /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 229E591B265869BF006E41AE /* ios_package_test */; + targetProxy = 229E5938265869C2006E41AE /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 229E5928265869BF006E41AE /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 229E5929265869BF006E41AE /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 229E592D265869C2006E41AE /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 229E592E265869C2006E41AE /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 229E5949265869C2006E41AE /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 229E594A265869C2006E41AE /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 229E594C265869C2006E41AE /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = ios_package_test/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "ai.onnxruntime.tests.ios-package-test"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 229E594D265869C2006E41AE /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = ios_package_test/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "ai.onnxruntime.tests.ios-package-test"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 229E594F265869C2006E41AE /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = ios_package_testTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "ai.onnxruntime.tests.ios-package-testTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ios_package_test.app/ios_package_test"; + }; + name = Debug; + }; + 229E5950265869C2006E41AE /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = ios_package_testTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "ai.onnxruntime.tests.ios-package-testTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ios_package_test.app/ios_package_test"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 229E5917265869BF006E41AE /* Build configuration list for PBXProject "ios_package_test" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 229E5949265869C2006E41AE /* Debug */, + 229E594A265869C2006E41AE /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 229E594B265869C2006E41AE /* Build configuration list for PBXNativeTarget "ios_package_test" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 229E594C265869C2006E41AE /* Debug */, + 229E594D265869C2006E41AE /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 229E594E265869C2006E41AE /* Build configuration list for PBXNativeTarget "ios_package_testTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 229E594F265869C2006E41AE /* Debug */, + 229E5950265869C2006E41AE /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 229E5914265869BF006E41AE /* Project object */; +} diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..919434a625 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.h b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.h new file mode 100644 index 0000000000..63c992ff83 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.h @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// AppDelegate.h +// ios_package_test +// + +#import + +@interface AppDelegate : UIResponder + + +@end + diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.m b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.m new file mode 100644 index 0000000000..c060260927 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/AppDelegate.m @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// AppDelegate.m +// ios_package_test +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + + +#pragma mark - UISceneSession lifecycle + + +- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; +} + + +- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. +} + + +@end diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/LaunchScreen.storyboard b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000000..865e9329f3 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/Main.storyboard b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/Main.storyboard new file mode 100644 index 0000000000..808a21ce77 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Info.plist b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Info.plist new file mode 100644 index 0000000000..72bf2c4f59 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/Info.plist @@ -0,0 +1,66 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + SceneDelegate + UISceneStoryboardFile + Main + + + + + UIApplicationSupportsIndirectInputEvents + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/main.m b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/main.m new file mode 100644 index 0000000000..a4fe174a60 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_test/main.m @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// main.m +// ios_package_test +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + NSString * appDelegateClassName; + @autoreleasepool { + // Setup code that might create autoreleased objects goes here. + appDelegateClassName = NSStringFromClass([AppDelegate class]); + } + return UIApplicationMain(argc, argv, nil, appDelegateClassName); +} diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_testTests/Info.plist b/onnxruntime/test/platform/ios/ios_package_test/ios_package_testTests/Info.plist new file mode 100644 index 0000000000..64d65ca495 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_testTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_testTests/ios_package_test_c_api.m b/onnxruntime/test/platform/ios/ios_package_test/ios_package_testTests/ios_package_test_c_api.m new file mode 100644 index 0000000000..5210469f59 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_testTests/ios_package_test_c_api.m @@ -0,0 +1,97 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// ios_package_test_c_api.m +// ios_package_testTests +// +// This file hosts the tests of ORT C API, for tests of ORT C++ API, please see ios_package_test_cpp_api.mm +// + +#import +#include +#include + +#define ASSERT_ON_ERROR(expr) \ + do { \ + OrtStatus* status = (expr); \ + XCTAssertEqual(NULL, status, @"Failed with error message: %@", \ + @(ort_env_->GetErrorMessage(status))); \ + } while (0) + +@interface ios_package_test_c_api : XCTestCase { + const OrtApi* ort_env_; +} + +@end + +@implementation ios_package_test_c_api + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. + ort_env_ = OrtGetApiBase()->GetApi(ORT_API_VERSION); +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + +- (void)testCAPI { + // This is an e2e test for ORT C API + OrtEnv* env = NULL; + ASSERT_ON_ERROR(ort_env_->CreateEnv(ORT_LOGGING_LEVEL_WARNING, "testCAPI", &env)); + + // initialize session options if needed + OrtSessionOptions* session_options; + ASSERT_ON_ERROR(ort_env_->CreateSessionOptions(&session_options)); + ASSERT_ON_ERROR(ort_env_->SetIntraOpNumThreads(session_options, 1)); + + OrtSession* session; + NSString* ns_model_path = [[NSBundle mainBundle] pathForResource:@"sigmoid" ofType:@"ort"]; + ASSERT_ON_ERROR(ort_env_->CreateSession(env, ns_model_path.UTF8String, session_options, &session)); + + size_t input_tensor_size = 3 * 4 * 5; + float input_tensor_values[input_tensor_size]; + float expected_output_values[input_tensor_size]; + const char* input_node_names[] = {"x"}; + const char* output_node_names[] = {"y"}; + const int64_t input_node_dims[] = {3, 4, 5}; + + for (size_t i = 0; i < input_tensor_size; i++) { + input_tensor_values[i] = (float)i - 30; + expected_output_values[i] = 1.0f / (1 + exp(-input_tensor_values[i])); + } + + OrtMemoryInfo* memory_info; + ASSERT_ON_ERROR(ort_env_->CreateCpuMemoryInfo(OrtArenaAllocator, OrtMemTypeDefault, &memory_info)); + OrtValue* input_tensor = NULL; + ASSERT_ON_ERROR(ort_env_->CreateTensorWithDataAsOrtValue( + memory_info, input_tensor_values, input_tensor_size * sizeof(float), + input_node_dims, 3, ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, &input_tensor)); + int is_tensor; + ASSERT_ON_ERROR(ort_env_->IsTensor(input_tensor, &is_tensor)); + XCTAssertNotEqual(is_tensor, 0); + ort_env_->ReleaseMemoryInfo(memory_info); + + OrtValue* output_tensor = NULL; + ASSERT_ON_ERROR(ort_env_->Run(session, NULL, input_node_names, + (const OrtValue* const*)&input_tensor, 1, + output_node_names, 1, &output_tensor)); + ASSERT_ON_ERROR(ort_env_->IsTensor(output_tensor, &is_tensor)); + XCTAssertNotEqual(is_tensor, 0); + + // Get pointer to output tensor float values + float* output_values; + ASSERT_ON_ERROR(ort_env_->GetTensorMutableData(output_tensor, (void**)&output_values)); + + for (size_t i = 0; i < input_tensor_size; i++) { + XCTAssertEqualWithAccuracy(expected_output_values[i], output_values[i], 1e-6); + } + + ort_env_->ReleaseValue(output_tensor); + ort_env_->ReleaseValue(input_tensor); + ort_env_->ReleaseSession(session); + ort_env_->ReleaseSessionOptions(session_options); + ort_env_->ReleaseEnv(env); +} + +@end diff --git a/onnxruntime/test/platform/ios/ios_package_test/ios_package_testTests/ios_package_test_cpp_api.mm b/onnxruntime/test/platform/ios/ios_package_test/ios_package_testTests/ios_package_test_cpp_api.mm new file mode 100644 index 0000000000..2b0bc887ee --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/ios_package_testTests/ios_package_test_cpp_api.mm @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// +// ios_package_test_cpp_api.mm +// ios_package_testTests +// +// This file hosts the tests of ORT C++ API, for tests of ORT C API, please see ios_package_test_c_api.mm +// + +#import +#include +#include + +@interface ios_package_test_cpp_api : XCTestCase + +@end + +@implementation ios_package_test_cpp_api + +- (void)setUp { + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. +} + +- (void)testCppAPI { + // This is an e2e test for ORT C++ API + Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "testCppAPI"); + + // initialize session options if needed + Ort::SessionOptions session_options; + session_options.SetIntraOpNumThreads(1); + + NSString* ns_model_path = [[NSBundle mainBundle] pathForResource:@"sigmoid" ofType:@"ort"]; + Ort::Session session(env, ns_model_path.UTF8String, session_options); + + size_t input_tensor_size = 3 * 4 * 5; + float input_tensor_values[input_tensor_size]; + float expected_output_values[input_tensor_size]; + const char* input_node_names[] = {"x"}; + const char* output_node_names[] = {"y"}; + const int64_t input_node_dims[] = {3, 4, 5}; + + for (size_t i = 0; i < input_tensor_size; i++) { + input_tensor_values[i] = (float)i - 30; + expected_output_values[i] = 1.0f / (1 + exp(-input_tensor_values[i])); + } + + auto memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); + Ort::Value input_tensor = + Ort::Value::CreateTensor(memory_info, input_tensor_values, input_tensor_size, input_node_dims, 3); + XCTAssert(input_tensor.IsTensor()); + + auto output_tensors = session.Run(Ort::RunOptions{nullptr}, input_node_names, + &input_tensor, 1, output_node_names, 1); + XCTAssertEqual(output_tensors.size(), 1); + XCTAssert(output_tensors.front().IsTensor()); + + // Get pointer to output tensor float values + float* output_values = output_tensors.front().GetTensorMutableData(); + for (size_t i = 0; i < input_tensor_size; i++) { + XCTAssertEqualWithAccuracy(expected_output_values[i], output_values[i], 1e-6); + } +} + +@end diff --git a/onnxruntime/test/platform/ios/ios_package_test/models/sigmoid.ort b/onnxruntime/test/platform/ios/ios_package_test/models/sigmoid.ort new file mode 100644 index 0000000000..6336fed141 Binary files /dev/null and b/onnxruntime/test/platform/ios/ios_package_test/models/sigmoid.ort differ diff --git a/onnxruntime/test/platform/ios/ios_package_test/onnxruntime-mobile.podspec.template b/onnxruntime/test/platform/ios/ios_package_test/onnxruntime-mobile.podspec.template new file mode 100644 index 0000000000..d3263e7d50 --- /dev/null +++ b/onnxruntime/test/platform/ios/ios_package_test/onnxruntime-mobile.podspec.template @@ -0,0 +1,18 @@ +# This pod spec template is used to generate podspec file for running ios_package_test project, +# this is not a podspec template used by onnxruntime-mobile official CocoaPods package +Pod::Spec.new do |spec| + spec.name = "onnxruntime-mobile" + spec.version = "${ORT_VERSION}" + spec.summary = "Onnx Runtime C/C++ Package" + spec.description = <<-DESC + Onnx Runtime C/C++ framework pod. + DESC + + spec.homepage = "https://github.com/microsoft/onnxruntime" + spec.license = { :type => 'MIT' } + spec.authors = { "ONNX Runtime" => "onnxruntime@microsoft.com" } + spec.platform = :ios, '13.0' + # if you are going to use a file as the spec.source, add 'file:' before your file path + spec.source = { :http => '${ORT_BASE_FRAMEWORK_ARCHIVE}' } + spec.vendored_frameworks = 'onnxruntime.framework' +end diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index ec19f79f51..decac8cb95 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -1257,16 +1257,20 @@ def run_android_tests(args, source_dir, build_dir, config, cwd): def run_ios_tests(args, source_dir, config, cwd): - cpr = run_subprocess(["xcodebuild", "test-without-building", "-project", "./onnxruntime.xcodeproj", - "-configuration", config, - "-scheme", "onnxruntime_test_all_xc", "-destination", - "platform=iOS Simulator,OS=latest,name=iPhone SE (2nd generation)"], cwd=cwd) - if cpr.returncode == 0: - cpr = run_subprocess(["xcodebuild", "test-without-building", "-project", "./onnxruntime.xcodeproj", - "-configuration", config, - "-scheme", "onnxruntime_shared_lib_test_xc", "-destination", - "platform=iOS Simulator,OS=latest,name=iPhone SE (2nd generation)"], cwd=cwd) - cpr.check_returncode() + run_subprocess(["xcodebuild", "test-without-building", "-project", "./onnxruntime.xcodeproj", + "-configuration", config, + "-scheme", "onnxruntime_test_all_xc", "-destination", + "platform=iOS Simulator,OS=latest,name=iPhone SE (2nd generation)"], cwd=cwd) + + run_subprocess(["xcodebuild", "test-without-building", "-project", "./onnxruntime.xcodeproj", + "-configuration", config, + "-scheme", "onnxruntime_shared_lib_test_xc", "-destination", + "platform=iOS Simulator,OS=latest,name=iPhone SE (2nd generation)"], cwd=cwd) + + if args.build_apple_framework: + package_test_py = os.path.join(source_dir, 'tools', 'ci_build', 'github', 'apple', 'test_ios_packages.py') + framework_dir = os.path.join(cwd, config + '-' + args.ios_sysroot) + run_subprocess([sys.executable, package_test_py, '--c_framework_dir', framework_dir], cwd=cwd) def run_orttraining_test_orttrainer_frontend_separately(cwd): diff --git a/tools/ci_build/github/apple/test_ios_packages.py b/tools/ci_build/github/apple/test_ios_packages.py new file mode 100644 index 0000000000..aab81364b5 --- /dev/null +++ b/tools/ci_build/github/apple/test_ios_packages.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import argparse +import os +import pathlib +import shutil +import subprocess + +SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) +REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "..", "..", "..")) + + +def _test_ios_packages(args): + # check if CocoaPods is installed + if shutil.which('pod') is None: + if args.fail_if_cocoapods_missing: + raise ValueError('CocoaPods is required for this test') + else: + print('CocoaPods is not installed, ignore this test') + return + + # Now we need to create a zip file contains the framework and the podspec file, both of these 2 files + # should be under the c_framework_dir + c_framework_dir = args.c_framework_dir.resolve() + if not c_framework_dir.is_dir(): + raise FileNotFoundError('c_framework_dir {} is not a folder.'.format(c_framework_dir)) + + framework_path = os.path.join(c_framework_dir, 'onnxruntime.framework') + if not pathlib.Path(framework_path).exists(): + raise FileNotFoundError('{} does not have onnxruntime.framework'.format(c_framework_dir)) + + # create a temp folder + import tempfile + with tempfile.TemporaryDirectory() as temp_dir: + # create a zip file contains the framework + # TODO, move this into a util function + local_pods_dir = os.path.join(temp_dir, 'local_pods') + os.makedirs(local_pods_dir, exist_ok=True) + # shutil.make_archive require target file as full path without extension + zip_base_filename = os.path.join(local_pods_dir, 'onnxruntime-mobile') + zip_file_path = zip_base_filename + '.zip' + shutil.make_archive(zip_base_filename, 'zip', root_dir=c_framework_dir, base_dir='onnxruntime.framework') + + # copy the test project to the temp_dir + test_proj_path = os.path.join(REPO_DIR, 'onnxruntime', 'test', 'platform', 'ios', 'ios_package_test') + target_proj_path = os.path.join(temp_dir, 'ios_package_test') + shutil.copytree(test_proj_path, target_proj_path) + + # update the podspec to point to the local framework zip file + local_podspec_path = os.path.join(target_proj_path, 'onnxruntime-mobile.podspec') + local_podspec_template = os.path.join(target_proj_path, 'onnxruntime-mobile.podspec.template') + with open(local_podspec_template, 'r') as file: + file_data = file.read() + + # replace the target strings + file_data = file_data.replace('${ORT_BASE_FRAMEWORK_ARCHIVE}', 'file:' + zip_file_path) + with open(os.path.join(REPO_DIR, 'VERSION_NUMBER')) as version_file: + file_data = file_data.replace('${ORT_VERSION}', version_file.readline().strip()) + + # write the updated podspec + with open(local_podspec_path, 'w') as file: + file.write(file_data) + + # install pods first + subprocess.run(['pod', 'install'], shell=False, check=True, cwd=target_proj_path) + + # run the tests + subprocess.run(['xcrun', 'xcodebuild', 'test', + '-workspace', './ios_package_test.xcworkspace', + '-scheme', 'ios_package_test', + '-destination', 'platform=iOS Simulator,OS=latest,name=iPhone SE (2nd generation)'], + shell=False, check=True, cwd=target_proj_path) + + +def parse_args(): + parser = argparse.ArgumentParser( + os.path.basename(__file__), + description='Test iOS framework using CocoaPods package.' + ) + + parser.add_argument('--fail_if_cocoapods_missing', action='store_true', + help='This script will fail if CocoaPods is not installed, ' + 'will not throw error unless fail_if_cocoapod_missing is set.') + + parser.add_argument('--c_framework_dir', type=pathlib.Path, required=True, + help='Provide the parent directory for C/C++ framework') + + return parser.parse_args() + + +def main(): + args = parse_args() + _test_ios_packages(args) + + +if __name__ == '__main__': + main() diff --git a/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml index 750aa525ac..b31ab975fa 100644 --- a/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-ios-ci-pipeline.yml @@ -13,6 +13,7 @@ jobs: --apple_deploy_target 12.1 \ --use_xcode \ --config RelWithDebInfo \ + --build_apple_framework \ --parallel displayName: (CPU EP) Build onnxruntime for iOS x86_64 and run tests using simulator - script: | @@ -25,5 +26,6 @@ jobs: --apple_deploy_target 12.1 \ --use_xcode \ --config RelWithDebInfo \ + --build_apple_framework \ --parallel displayName: (CoreML EP) Build onnxruntime for iOS x86_64 and run tests using simulator