From 37d33c894103a59b52c0e7887c3cdd5da82f713f Mon Sep 17 00:00:00 2001 From: rachguo Date: Tue, 11 Jul 2023 10:59:13 -0700 Subject: [PATCH] exclude test/ --- objectivec/test/assert_arc_enabled.mm | 4 - objectivec/test/assertion_utils.h | 46 --- objectivec/test/ort_checkpoint_test.mm | 117 ------ objectivec/test/ort_env_test.mm | 30 -- objectivec/test/ort_session_test.mm | 264 ------------- objectivec/test/ort_training_session_test.mm | 359 ------------------ objectivec/test/ort_training_utils_test.mm | 26 -- objectivec/test/ort_value_test.mm | 79 ---- objectivec/test/test_utils.h | 21 - objectivec/test/test_utils.mm | 44 --- objectivec/test/testdata/gen_models.sh | 12 - objectivec/test/testdata/single_add.basic.ort | Bin 1296 -> 0 bytes objectivec/test/testdata/single_add.onnx | Bin 93 -> 0 bytes objectivec/test/testdata/single_add_gen.py | 19 - 14 files changed, 1021 deletions(-) delete mode 100644 objectivec/test/assert_arc_enabled.mm delete mode 100644 objectivec/test/assertion_utils.h delete mode 100644 objectivec/test/ort_checkpoint_test.mm delete mode 100644 objectivec/test/ort_env_test.mm delete mode 100644 objectivec/test/ort_session_test.mm delete mode 100644 objectivec/test/ort_training_session_test.mm delete mode 100644 objectivec/test/ort_training_utils_test.mm delete mode 100644 objectivec/test/ort_value_test.mm delete mode 100644 objectivec/test/test_utils.h delete mode 100644 objectivec/test/test_utils.mm delete mode 100755 objectivec/test/testdata/gen_models.sh delete mode 100644 objectivec/test/testdata/single_add.basic.ort delete mode 100644 objectivec/test/testdata/single_add.onnx delete mode 100644 objectivec/test/testdata/single_add_gen.py diff --git a/objectivec/test/assert_arc_enabled.mm b/objectivec/test/assert_arc_enabled.mm deleted file mode 100644 index 9aa0bad..0000000 --- a/objectivec/test/assert_arc_enabled.mm +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -static_assert(__has_feature(objc_arc), "Objective-C ARC must be enabled."); diff --git a/objectivec/test/assertion_utils.h b/objectivec/test/assertion_utils.h deleted file mode 100644 index 2b72435..0000000 --- a/objectivec/test/assertion_utils.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#import - -NS_ASSUME_NONNULL_BEGIN - -#define ORTAssertNullableResultSuccessful(result, error) \ - do { \ - XCTAssertNotNil(result, @"Expected non-nil result but got nil. Error: %@", error); \ - XCTAssertNil(error); \ - } while (0) - -#define ORTAssertBoolResultSuccessful(result, error) \ - do { \ - XCTAssertTrue(result, @"Expected true result but got false. Error: %@", error); \ - XCTAssertNil(error); \ - } while (0) - -#define ORTAssertNullableResultUnsuccessful(result, error) \ - do { \ - XCTAssertNil(result); \ - XCTAssertNotNil(error); \ - } while (0) - -#define ORTAssertBoolResultUnsuccessful(result, error) \ - do { \ - XCTAssertFalse(result); \ - XCTAssertNotNil(error); \ - } while (0) - -#define ORTAssertEqualFloatAndNoError(expected, result, error) \ - do { \ - XCTAssertEqualWithAccuracy(expected, result, 1e-3f, @"Expected %f but got %f. Error:%@", expected, result, error); \ - XCTAssertNil(error); \ - } while (0) - -#define ORTAssertEqualFloatArrays(expected, result) \ - do { \ - XCTAssertEqual(expected.count, result.count); \ - for (size_t i = 0; i < expected.count; ++i) { \ - XCTAssertEqualWithAccuracy([expected[i] floatValue], [result[i] floatValue], 1e-3f); \ - } \ - } while (0) - -NS_ASSUME_NONNULL_END diff --git a/objectivec/test/ort_checkpoint_test.mm b/objectivec/test/ort_checkpoint_test.mm deleted file mode 100644 index 9b2196f..0000000 --- a/objectivec/test/ort_checkpoint_test.mm +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#import - -#import "ort_checkpoint.h" -#import "ort_training_session.h" -#import "ort_env.h" -#import "ort_session.h" - -#import "test/test_utils.h" -#import "test/assertion_utils.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface ORTCheckpointTest : XCTestCase -@property(readonly, nullable) ORTEnv* ortEnv; -@end - -@implementation ORTCheckpointTest - -- (void)setUp { - [super setUp]; - - self.continueAfterFailure = NO; - - NSError* err = nil; - _ortEnv = [[ORTEnv alloc] initWithLoggingLevel:ORTLoggingLevelWarning - error:&err]; - ORTAssertNullableResultSuccessful(_ortEnv, err); -} - -+ (NSString*)getCheckpointPath { - NSBundle* bundle = [NSBundle bundleForClass:[ORTCheckpointTest class]]; - NSString* path = [[bundle resourcePath] stringByAppendingPathComponent:@"checkpoint.ckpt"]; - return path; -} - -+ (NSString*)getTrainingModelPath { - NSBundle* bundle = [NSBundle bundleForClass:[ORTCheckpointTest class]]; - NSString* path = [[bundle resourcePath] stringByAppendingPathComponent:@"training_model.onnx"]; - return path; -} - -- (void)testSaveCheckpoint { - NSError* error = nil; - ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error]; - ORTAssertNullableResultSuccessful(checkpoint, error); - - // save checkpoint - NSString* path = [test_utils::createTemporaryDirectory(self) stringByAppendingPathComponent:@"save_checkpoint.ckpt"]; - XCTAssertNotNil(path); - BOOL result = [checkpoint saveCheckpointToPath:path withOptimizerState:NO error:&error]; - - ORTAssertBoolResultSuccessful(result, error); -} - -- (void)testInitCheckpoint { - NSError* error = nil; - ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error]; - ORTAssertNullableResultSuccessful(checkpoint, error); -} - -- (void)testIntProperty { - NSError* error = nil; - // Load checkpoint - ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error]; - ORTAssertNullableResultSuccessful(checkpoint, error); - - // Add property - BOOL result = [checkpoint addIntPropertyWithName:@"test" value:314 error:&error]; - ORTAssertBoolResultSuccessful(result, error); - - // Get property - int64_t value = [checkpoint getIntPropertyWithName:@"test" error:&error]; - XCTAssertEqual(value, 314); -} - -- (void)testFloatProperty { - NSError* error = nil; - // Load checkpoint - ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error]; - ORTAssertNullableResultSuccessful(checkpoint, error); - - // Add property - BOOL result = [checkpoint addFloatPropertyWithName:@"test" value:3.14f error:&error]; - ORTAssertBoolResultSuccessful(result, error); - - // Get property - float value = [checkpoint getFloatPropertyWithName:@"test" error:&error]; - XCTAssertEqual(value, 3.14f); -} - -- (void)testStringProperty { - NSError* error = nil; - // Load checkpoint - ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error]; - ORTAssertNullableResultSuccessful(checkpoint, error); - - // Add property - BOOL result = [checkpoint addStringPropertyWithName:@"test" value:@"hello" error:&error]; - ORTAssertBoolResultSuccessful(result, error); - - // Get property - NSString* value = [checkpoint getStringPropertyWithName:@"test" error:&error]; - XCTAssertEqualObjects(value, @"hello"); -} - -- (void)tearDown { - _ortEnv = nil; - - [super tearDown]; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/objectivec/test/ort_env_test.mm b/objectivec/test/ort_env_test.mm deleted file mode 100644 index 420f55f..0000000 --- a/objectivec/test/ort_env_test.mm +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#import - -#import "ort_env.h" - -#import "test/assertion_utils.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface ORTEnvTest : XCTestCase -@end - -@implementation ORTEnvTest -- (void)testGetOrtVersion { - NSString* ver = ORTVersion(); - XCTAssertNotNil(ver); -} - -- (void)testInitOk { - NSError* err = nil; - ORTEnv* env = [[ORTEnv alloc] initWithLoggingLevel:ORTLoggingLevelWarning - error:&err]; - ORTAssertNullableResultSuccessful(env, err); -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/objectivec/test/ort_session_test.mm b/objectivec/test/ort_session_test.mm deleted file mode 100644 index 57b92fd..0000000 --- a/objectivec/test/ort_session_test.mm +++ /dev/null @@ -1,264 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#import - -#import "ort_coreml_execution_provider.h" -#import "ort_xnnpack_execution_provider.h" -#import "ort_env.h" -#import "ort_session.h" -#import "ort_value.h" - -#import "test/assertion_utils.h" - -#include - -NS_ASSUME_NONNULL_BEGIN - -@interface ORTSessionTest : XCTestCase - -@property(readonly, nullable) ORTEnv* ortEnv; - -@end - -@implementation ORTSessionTest - -- (void)setUp { - [super setUp]; - - self.continueAfterFailure = NO; - - NSError* err = nil; - _ortEnv = [[ORTEnv alloc] initWithLoggingLevel:ORTLoggingLevelWarning - error:&err]; - ORTAssertNullableResultSuccessful(_ortEnv, err); -} - -- (void)tearDown { - _ortEnv = nil; - - [super tearDown]; -} - -// model with an Add op -// inputs: A, B -// output: C = A + B -+ (NSString*)getAddModelPath { - NSBundle* bundle = [NSBundle bundleForClass:[ORTSessionTest class]]; - NSString* path = [bundle pathForResource:@"single_add.basic" - ofType:@"ort"]; - return path; -} - -+ (NSMutableData*)dataWithScalarFloat:(float)value { - NSMutableData* data = [[NSMutableData alloc] initWithBytes:&value length:sizeof(value)]; - return data; -} - -+ (ORTValue*)ortValueWithScalarFloatData:(NSMutableData*)data { - NSArray* shape = @[ @1 ]; - NSError* err = nil; - ORTValue* ortValue = [[ORTValue alloc] initWithTensorData:data - elementType:ORTTensorElementDataTypeFloat - shape:shape - error:&err]; - ORTAssertNullableResultSuccessful(ortValue, err); - return ortValue; -} - -+ (ORTSessionOptions*)makeSessionOptions { - NSError* err = nil; - ORTSessionOptions* sessionOptions = [[ORTSessionOptions alloc] initWithError:&err]; - ORTAssertNullableResultSuccessful(sessionOptions, err); - return sessionOptions; -} - -+ (ORTRunOptions*)makeRunOptions { - NSError* err = nil; - ORTRunOptions* runOptions = [[ORTRunOptions alloc] initWithError:&err]; - ORTAssertNullableResultSuccessful(runOptions, err); - return runOptions; -} - -- (void)testInitAndRunWithPreallocatedOutputOk { - NSMutableData* aData = [ORTSessionTest dataWithScalarFloat:1.0f]; - NSMutableData* bData = [ORTSessionTest dataWithScalarFloat:2.0f]; - NSMutableData* cData = [ORTSessionTest dataWithScalarFloat:0.0f]; - - ORTValue* a = [ORTSessionTest ortValueWithScalarFloatData:aData]; - ORTValue* b = [ORTSessionTest ortValueWithScalarFloatData:bData]; - ORTValue* c = [ORTSessionTest ortValueWithScalarFloatData:cData]; - - NSError* err = nil; - ORTSession* session = [[ORTSession alloc] initWithEnv:self.ortEnv - modelPath:[ORTSessionTest getAddModelPath] - sessionOptions:[ORTSessionTest makeSessionOptions] - error:&err]; - ORTAssertNullableResultSuccessful(session, err); - - BOOL runResult = [session runWithInputs:@{@"A" : a, @"B" : b} - outputs:@{@"C" : c} - runOptions:[ORTSessionTest makeRunOptions] - error:&err]; - ORTAssertBoolResultSuccessful(runResult, err); - - const float cExpected = 3.0f; - float cActual; - memcpy(&cActual, cData.bytes, sizeof(float)); - XCTAssertEqual(cActual, cExpected); -} - -- (void)testInitAndRunOk { - NSMutableData* aData = [ORTSessionTest dataWithScalarFloat:1.0f]; - NSMutableData* bData = [ORTSessionTest dataWithScalarFloat:2.0f]; - - ORTValue* a = [ORTSessionTest ortValueWithScalarFloatData:aData]; - ORTValue* b = [ORTSessionTest ortValueWithScalarFloatData:bData]; - - NSError* err = nil; - ORTSession* session = [[ORTSession alloc] initWithEnv:self.ortEnv - modelPath:[ORTSessionTest getAddModelPath] - sessionOptions:[ORTSessionTest makeSessionOptions] - error:&err]; - ORTAssertNullableResultSuccessful(session, err); - - NSDictionary* outputs = - [session runWithInputs:@{@"A" : a, @"B" : b} - outputNames:[NSSet setWithArray:@[ @"C" ]] - runOptions:[ORTSessionTest makeRunOptions] - error:&err]; - ORTAssertNullableResultSuccessful(outputs, err); - - ORTValue* cOutput = outputs[@"C"]; - XCTAssertNotNil(cOutput); - - NSData* cData = [cOutput tensorDataWithError:&err]; - ORTAssertNullableResultSuccessful(cData, err); - - const float cExpected = 3.0f; - float cActual; - memcpy(&cActual, cData.bytes, sizeof(float)); - XCTAssertEqual(cActual, cExpected); -} - -- (void)testGetNamesOk { - NSError* err = nil; - ORTSession* session = [[ORTSession alloc] initWithEnv:self.ortEnv - modelPath:[ORTSessionTest getAddModelPath] - sessionOptions:[ORTSessionTest makeSessionOptions] - error:&err]; - ORTAssertNullableResultSuccessful(session, err); - - NSArray* inputNames = [session inputNamesWithError:&err]; - ORTAssertNullableResultSuccessful(inputNames, err); - XCTAssertEqualObjects(inputNames, (@[ @"A", @"B" ])); - - NSArray* overridableInitializerNames = [session overridableInitializerNamesWithError:&err]; - ORTAssertNullableResultSuccessful(overridableInitializerNames, err); - XCTAssertEqualObjects(overridableInitializerNames, (@[])); - - NSArray* outputNames = [session outputNamesWithError:&err]; - ORTAssertNullableResultSuccessful(outputNames, err); - XCTAssertEqualObjects(outputNames, (@[ @"C" ])); -} - -- (void)testInitFailsWithInvalidPath { - NSString* invalidModelPath = @"invalid/path/to/model.ort"; - NSError* err = nil; - ORTSession* session = [[ORTSession alloc] initWithEnv:self.ortEnv - modelPath:invalidModelPath - sessionOptions:[ORTSessionTest makeSessionOptions] - error:&err]; - ORTAssertNullableResultUnsuccessful(session, err); -} - -- (void)testRunFailsWithInvalidInput { - NSMutableData* dData = [ORTSessionTest dataWithScalarFloat:1.0f]; - NSMutableData* cData = [ORTSessionTest dataWithScalarFloat:0.0f]; - - ORTValue* d = [ORTSessionTest ortValueWithScalarFloatData:dData]; - ORTValue* c = [ORTSessionTest ortValueWithScalarFloatData:cData]; - - NSError* err = nil; - ORTSession* session = [[ORTSession alloc] initWithEnv:self.ortEnv - modelPath:[ORTSessionTest getAddModelPath] - sessionOptions:[ORTSessionTest makeSessionOptions] - error:&err]; - ORTAssertNullableResultSuccessful(session, err); - - BOOL runResult = [session runWithInputs:@{@"D" : d} - outputs:@{@"C" : c} - runOptions:[ORTSessionTest makeRunOptions] - error:&err]; - ORTAssertBoolResultUnsuccessful(runResult, err); -} - -- (void)testAppendCoreMLEP { - NSError* err = nil; - ORTSessionOptions* sessionOptions = [ORTSessionTest makeSessionOptions]; - ORTCoreMLExecutionProviderOptions* coreMLOptions = [[ORTCoreMLExecutionProviderOptions alloc] init]; - coreMLOptions.enableOnSubgraphs = YES; // set an arbitrary option - - BOOL appendResult = [sessionOptions appendCoreMLExecutionProviderWithOptions:coreMLOptions - error:&err]; - - if (!ORTIsCoreMLExecutionProviderAvailable()) { - ORTAssertBoolResultUnsuccessful(appendResult, err); - return; - } - - ORTAssertBoolResultSuccessful(appendResult, err); - - ORTSession* session = [[ORTSession alloc] initWithEnv:self.ortEnv - modelPath:[ORTSessionTest getAddModelPath] - sessionOptions:sessionOptions - error:&err]; - ORTAssertNullableResultSuccessful(session, err); -} - -- (void)testAppendXnnpackEP { - NSError* err = nil; - ORTSessionOptions* sessionOptions = [ORTSessionTest makeSessionOptions]; - ORTXnnpackExecutionProviderOptions* XnnpackOptions = [[ORTXnnpackExecutionProviderOptions alloc] init]; - XnnpackOptions.intra_op_num_threads = 2; - - BOOL appendResult = [sessionOptions appendXnnpackExecutionProviderWithOptions:XnnpackOptions - error:&err]; - // Without xnnpack EP in building also can pass the test - NSString* err_msg = [err localizedDescription]; - if (!appendResult && [err_msg containsString:@"XNNPACK execution provider is not supported in this build. "]) { - return; - } - - ORTAssertBoolResultSuccessful(appendResult, err); - - ORTSession* session = [[ORTSession alloc] initWithEnv:self.ortEnv - modelPath:[ORTSessionTest getAddModelPath] - sessionOptions:sessionOptions - error:&err]; - ORTAssertNullableResultSuccessful(session, err); -} - -static bool gDummyRegisterCustomOpsFnCalled = false; - -static OrtStatus* _Nullable DummyRegisterCustomOpsFn(OrtSessionOptions* /*session_options*/, - const OrtApiBase* /*api*/) { - gDummyRegisterCustomOpsFnCalled = true; - return nullptr; -} - -- (void)testRegisterCustomOpsUsingFunctionPointer { - NSError* err = nil; - ORTSessionOptions* sessionOptions = [ORTSessionTest makeSessionOptions]; - - gDummyRegisterCustomOpsFnCalled = false; - BOOL registerResult = [sessionOptions registerCustomOpsUsingFunctionPointer:&DummyRegisterCustomOpsFn - error:&err]; - ORTAssertBoolResultSuccessful(registerResult, err); - - XCTAssertEqual(gDummyRegisterCustomOpsFnCalled, true); -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/objectivec/test/ort_training_session_test.mm b/objectivec/test/ort_training_session_test.mm deleted file mode 100644 index 683965d..0000000 --- a/objectivec/test/ort_training_session_test.mm +++ /dev/null @@ -1,359 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#import - -#import "ort_checkpoint.h" -#import "ort_training_session.h" -#import "ort_env.h" -#import "ort_session.h" -#import "ort_value.h" - -#import "test/test_utils.h" -#import "test/assertion_utils.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface ORTTrainingSessionTest : XCTestCase -@property(readonly, nullable) ORTEnv* ortEnv; -@property(readonly, nullable) ORTCheckpoint* checkpoint; -@property(readonly, nullable) ORTTrainingSession* session; -@end - -@implementation ORTTrainingSessionTest - -- (void)setUp { - [super setUp]; - - self.continueAfterFailure = NO; - - NSError* err = nil; - _ortEnv = [[ORTEnv alloc] initWithLoggingLevel:ORTLoggingLevelWarning - error:&err]; - ORTAssertNullableResultSuccessful(_ortEnv, err); - _checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTTrainingSessionTest - getFilePathFromName:@"checkpoint.ckpt"] - error:&err]; - ORTAssertNullableResultSuccessful(_checkpoint, err); - _session = [self makeTrainingSessionWithCheckpoint:_checkpoint]; -} - -+ (NSString*)getFilePathFromName:(NSString*)name { - NSBundle* bundle = [NSBundle bundleForClass:[ORTTrainingSessionTest class]]; - NSString* path = [[bundle resourcePath] stringByAppendingPathComponent:name]; - return path; -} - -+ (NSMutableData*)loadTensorDataFromFile:(NSString*)filePath skipHeader:(BOOL)skipHeader { - NSError* error = nil; - NSString* fileContents = [NSString stringWithContentsOfFile:filePath - encoding:NSUTF8StringEncoding - error:&error]; - ORTAssertNullableResultSuccessful(fileContents, error); - - NSArray* lines = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]; - - if (skipHeader) { - lines = [lines subarrayWithRange:NSMakeRange(1, lines.count - 1)]; - } - - NSArray* dataArray = [lines[0] componentsSeparatedByCharactersInSet: - [NSCharacterSet characterSetWithCharactersInString:@",[] "]]; - NSMutableData* tensorData = [NSMutableData data]; - - for (NSString* str in dataArray) { - if (str.length > 0) { - float value = [str floatValue]; - [tensorData appendBytes:&value length:sizeof(float)]; - } - } - - return tensorData; -} - -- (ORTTrainingSession*)makeTrainingSessionWithCheckpoint:(ORTCheckpoint*)checkpoint { - NSError* error = nil; - ORTSessionOptions* sessionOptions = [[ORTSessionOptions alloc] initWithError:&error]; - ORTAssertNullableResultSuccessful(sessionOptions, error); - - ORTTrainingSession* session = [[ORTTrainingSession alloc] - initWithEnv:self.ortEnv - sessionOptions:sessionOptions - checkpoint:checkpoint - trainModelPath:[ORTTrainingSessionTest getFilePathFromName:@"training_model.onnx"] - evalModelPath:[ORTTrainingSessionTest getFilePathFromName:@"eval_model.onnx"] - optimizerModelPath:[ORTTrainingSessionTest getFilePathFromName:@"adamw.onnx"] - error:&error]; - - ORTAssertNullableResultSuccessful(session, error); - return session; -} - -- (void)testInitTrainingSession { - NSError* error = nil; - - // check that inputNames contains input-0 - NSArray* inputNames = [self.session getTrainInputNamesWithError:&error]; - ORTAssertNullableResultSuccessful(inputNames, error); - - XCTAssertTrue(inputNames.count > 0); - XCTAssertTrue([inputNames containsObject:@"input-0"]); - - // check that outNames contains onnx::loss::21273 - NSArray* outputNames = [self.session getTrainOutputNamesWithError:&error]; - ORTAssertNullableResultSuccessful(outputNames, error); - - XCTAssertTrue(outputNames.count > 0); - XCTAssertTrue([outputNames containsObject:@"onnx::loss::21273"]); -} - -- (void)testInitTrainingSessionWithEval { - NSError* error = nil; - - // check that inputNames contains input-0 - NSArray* inputNames = [self.session getEvalInputNamesWithError:&error]; - ORTAssertNullableResultSuccessful(inputNames, error); - - XCTAssertTrue(inputNames.count > 0); - XCTAssertTrue([inputNames containsObject:@"input-0"]); - - // check that outNames contains onnx::loss::21273 - NSArray* outputNames = [self.session getEvalOutputNamesWithError:&error]; - ORTAssertNullableResultSuccessful(outputNames, error); - - XCTAssertTrue(outputNames.count > 0); - XCTAssertTrue([outputNames containsObject:@"onnx::loss::21273"]); -} - -- (void)runTrainStep { - // load input and expected output - NSError* error = nil; - NSMutableData* expectedOutput = [ORTTrainingSessionTest loadTensorDataFromFile:[ORTTrainingSessionTest - getFilePathFromName:@"loss_1.out"] - skipHeader:YES]; - - NSMutableData* input = [ORTTrainingSessionTest loadTensorDataFromFile:[ORTTrainingSessionTest - getFilePathFromName:@"input-0.in"] - skipHeader:YES]; - - int32_t labels[] = {1, 1}; - - // create ORTValue array for input and labels - NSMutableArray* inputValues = [NSMutableArray array]; - - ORTValue* inputTensor = [[ORTValue alloc] initWithTensorData:input - elementType:ORTTensorElementDataTypeFloat - shape:@[ @2, @784 ] - error:&error]; - ORTAssertNullableResultSuccessful(inputTensor, error); - [inputValues addObject:inputTensor]; - - ORTValue* labelTensor = [[ORTValue alloc] initWithTensorData:[NSMutableData dataWithBytes:labels - length:sizeof(labels)] - elementType:ORTTensorElementDataTypeInt32 - shape:@[ @2 ] - error:&error]; - - ORTAssertNullableResultSuccessful(labelTensor, error); - [inputValues addObject:labelTensor]; - - NSArray* outputs = [self.session trainStepWithInputValues:inputValues error:&error]; - ORTAssertNullableResultSuccessful(outputs, error); - XCTAssertTrue(outputs.count > 0); - - BOOL result = [self.session lazyResetGradWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - - outputs = [self.session trainStepWithInputValues:inputValues error:&error]; - ORTAssertNullableResultSuccessful(outputs, error); - XCTAssertTrue(outputs.count > 0); - - ORTValue* outputValue = outputs[0]; - ORTValueTypeInfo* typeInfo = [outputValue typeInfoWithError:&error]; - ORTAssertNullableResultSuccessful(typeInfo, error); - XCTAssertEqual(typeInfo.type, ORTValueTypeTensor); - XCTAssertNotNil(typeInfo.tensorTypeAndShapeInfo); - - ORTTensorTypeAndShapeInfo* tensorInfo = [outputValue tensorTypeAndShapeInfoWithError:&error]; - ORTAssertNullableResultSuccessful(tensorInfo, error); - XCTAssertEqual(tensorInfo.elementType, ORTTensorElementDataTypeFloat); - - NSMutableData* tensorData = [outputValue tensorDataWithError:&error]; - ORTAssertNullableResultSuccessful(tensorData, error); - ORTAssertEqualFloatArrays(test_utils::getFloatArrayFromData(tensorData), - test_utils::getFloatArrayFromData(expectedOutput)); -} - -- (void)testTrainStepOutput { - [self runTrainStep]; -} - -- (void)testOptimizerStep { - // load input and expected output - NSError* error = nil; - NSMutableData* expectedOutput1 = [ORTTrainingSessionTest loadTensorDataFromFile:[ORTTrainingSessionTest - getFilePathFromName:@"loss_1.out"] - skipHeader:YES]; - - NSMutableData* expectedOutput2 = [ORTTrainingSessionTest loadTensorDataFromFile:[ORTTrainingSessionTest - getFilePathFromName:@"loss_2.out"] - skipHeader:YES]; - - NSMutableData* input = [ORTTrainingSessionTest loadTensorDataFromFile:[ORTTrainingSessionTest - getFilePathFromName:@"input-0.in"] - skipHeader:YES]; - - int32_t labels[] = {1, 1}; - - // create ORTValue array for input and labels - NSMutableArray* inputValues = [NSMutableArray array]; - - ORTValue* inputTensor = [[ORTValue alloc] initWithTensorData:input - elementType:ORTTensorElementDataTypeFloat - shape:@[ @2, @784 ] - error:&error]; - ORTAssertNullableResultSuccessful(inputTensor, error); - [inputValues addObject:inputTensor]; - - ORTValue* labelTensor = [[ORTValue alloc] initWithTensorData:[NSMutableData dataWithBytes:labels - length:sizeof(labels)] - elementType:ORTTensorElementDataTypeInt32 - shape:@[ @2 ] - error:&error]; - ORTAssertNullableResultSuccessful(labelTensor, error); - [inputValues addObject:labelTensor]; - - // run train step, optimizer steps and check loss - NSArray* outputs = [self.session trainStepWithInputValues:inputValues error:&error]; - ORTAssertNullableResultSuccessful(outputs, error); - - NSMutableData* loss = [outputs[0] tensorDataWithError:&error]; - ORTAssertNullableResultSuccessful(loss, error); - ORTAssertEqualFloatArrays(test_utils::getFloatArrayFromData(loss), - test_utils::getFloatArrayFromData(expectedOutput1)); - - BOOL result = [self.session lazyResetGradWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - - outputs = [self.session trainStepWithInputValues:inputValues error:&error]; - ORTAssertNullableResultSuccessful(outputs, error); - - loss = [outputs[0] tensorDataWithError:&error]; - ORTAssertNullableResultSuccessful(loss, error); - ORTAssertEqualFloatArrays(test_utils::getFloatArrayFromData(loss), - test_utils::getFloatArrayFromData(expectedOutput1)); - - result = [self.session optimizerStepWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - - outputs = [self.session trainStepWithInputValues:inputValues error:&error]; - ORTAssertNullableResultSuccessful(outputs, error); - loss = [outputs[0] tensorDataWithError:&error]; - ORTAssertNullableResultSuccessful(loss, error); - ORTAssertEqualFloatArrays(test_utils::getFloatArrayFromData(loss), - test_utils::getFloatArrayFromData(expectedOutput2)); -} - -- (void)testSetLearningRate { - NSError* error = nil; - - float learningRate = 0.1f; - BOOL result = [self.session setLearningRate:learningRate error:&error]; - ORTAssertBoolResultSuccessful(result, error); - - float actualLearningRate = [self.session getLearningRateWithError:&error]; - ORTAssertEqualFloatAndNoError(learningRate, actualLearningRate, error); -} - -- (void)testLinearLRScheduler { - NSError* error = nil; - - float learningRate = 0.1f; - BOOL result = [self.session registerLinearLRSchedulerWithWarmupStepCount:2 - totalStepCount:4 - initialLr:learningRate - error:&error]; - - ORTAssertBoolResultSuccessful(result, error); - - [self runTrainStep]; - - result = [self.session optimizerStepWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - result = [self.session schedulerStepWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - ORTAssertEqualFloatAndNoError(0.05f, [self.session getLearningRateWithError:&error], error); - - result = [self.session optimizerStepWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - result = [self.session schedulerStepWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - ORTAssertEqualFloatAndNoError(0.1f, [self.session getLearningRateWithError:&error], error); - - result = [self.session optimizerStepWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - result = [self.session schedulerStepWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - ORTAssertEqualFloatAndNoError(0.05f, [self.session getLearningRateWithError:&error], error); - - result = [self.session optimizerStepWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - result = [self.session schedulerStepWithError:&error]; - ORTAssertBoolResultSuccessful(result, error); - ORTAssertEqualFloatAndNoError(0.0f, [self.session getLearningRateWithError:&error], error); -} - -- (void)testExportModelForInference { - NSError* error = nil; - - NSString* inferenceModelPath = [test_utils::createTemporaryDirectory(self) - stringByAppendingPathComponent:@"inference_model.onnx"]; - XCTAssertNotNil(inferenceModelPath); - - NSArray* graphOutputNames = [NSArray arrayWithObjects:@"output-0", nil]; - - BOOL result = [self.session exportModelForInferenceWithOutputPath:inferenceModelPath - graphOutputNames:graphOutputNames - error:&error]; - - ORTAssertBoolResultSuccessful(result, error); - XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:inferenceModelPath]); - - [self addTeardownBlock:^{ - NSError* error = nil; - [[NSFileManager defaultManager] removeItemAtPath:inferenceModelPath error:&error]; - }]; -} - -- (void)testToBuffer { - NSError* error = nil; - ORTValue* buffer = [self.session toBufferWithTrainable:YES error:&error]; - ORTAssertNullableResultSuccessful(buffer, error); - - ORTValueTypeInfo* typeInfo = [buffer typeInfoWithError:&error]; - ORTAssertNullableResultSuccessful(typeInfo, error); - XCTAssertEqual(typeInfo.type, ORTValueTypeTensor); - XCTAssertNotNil(typeInfo.tensorTypeAndShapeInfo); -} - -- (void)testFromBuffer { - NSError* error = nil; - - ORTValue* buffer = [self.session toBufferWithTrainable:YES error:&error]; - ORTAssertNullableResultSuccessful(buffer, error); - - BOOL result = [self.session fromBufferWithValue:buffer error:&error]; - ORTAssertBoolResultSuccessful(result, error); -} - -- (void)tearDown { - _session = nil; - _checkpoint = nil; - _ortEnv = nil; - - [super tearDown]; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/objectivec/test/ort_training_utils_test.mm b/objectivec/test/ort_training_utils_test.mm deleted file mode 100644 index 1695ddc..0000000 --- a/objectivec/test/ort_training_utils_test.mm +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#import -#import "ort_training_session.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface ORTTrainingUtilsTest : XCTestCase -@end - -@implementation ORTTrainingUtilsTest - -- (void)setUp { - [super setUp]; - - self.continueAfterFailure = NO; -} - -- (void)testSetSeed { - ORTSetSeed(2718); -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/objectivec/test/ort_value_test.mm b/objectivec/test/ort_value_test.mm deleted file mode 100644 index 734ad39..0000000 --- a/objectivec/test/ort_value_test.mm +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#import - -#import "ort_value.h" - -#include - -#import "test/assertion_utils.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface ORTValueTest : XCTestCase -@end - -@implementation ORTValueTest - -- (void)setUp { - [super setUp]; - - self.continueAfterFailure = NO; -} - -- (void)testInitTensorOk { - int32_t value = 42; - NSMutableData* data = [[NSMutableData alloc] initWithBytes:&value - length:sizeof(int32_t)]; - NSArray* shape = @[ @1 ]; - - const ORTTensorElementDataType elementType = ORTTensorElementDataTypeInt32; - - NSError* err = nil; - ORTValue* ortValue = [[ORTValue alloc] initWithTensorData:data - elementType:elementType - shape:shape - error:&err]; - ORTAssertNullableResultSuccessful(ortValue, err); - - auto checkTensorInfo = [&](ORTTensorTypeAndShapeInfo* tensorInfo) { - XCTAssertEqual(tensorInfo.elementType, elementType); - XCTAssertEqualObjects(tensorInfo.shape, shape); - }; - - ORTValueTypeInfo* typeInfo = [ortValue typeInfoWithError:&err]; - ORTAssertNullableResultSuccessful(typeInfo, err); - XCTAssertEqual(typeInfo.type, ORTValueTypeTensor); - XCTAssertNotNil(typeInfo.tensorTypeAndShapeInfo); - checkTensorInfo(typeInfo.tensorTypeAndShapeInfo); - - ORTTensorTypeAndShapeInfo* tensorInfo = [ortValue tensorTypeAndShapeInfoWithError:&err]; - ORTAssertNullableResultSuccessful(tensorInfo, err); - checkTensorInfo(tensorInfo); - - NSData* actualData = [ortValue tensorDataWithError:&err]; - ORTAssertNullableResultSuccessful(actualData, err); - XCTAssertEqual(actualData.length, sizeof(int32_t)); - int32_t actualValue; - memcpy(&actualValue, actualData.bytes, sizeof(int32_t)); - XCTAssertEqual(actualValue, value); -} - -- (void)testInitTensorFailsWithDataSmallerThanShape { - std::vector values{1, 2, 3, 4}; - NSMutableData* data = [[NSMutableData alloc] initWithBytes:values.data() - length:values.size() * sizeof(int32_t)]; - NSArray* shape = @[ @2, @3 ]; // too large - - NSError* err = nil; - ORTValue* ortValue = [[ORTValue alloc] initWithTensorData:data - elementType:ORTTensorElementDataTypeInt32 - shape:shape - error:&err]; - ORTAssertNullableResultUnsuccessful(ortValue, err); -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/objectivec/test/test_utils.h b/objectivec/test/test_utils.h deleted file mode 100644 index 8a5e6e4..0000000 --- a/objectivec/test/test_utils.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#import -#import - -#import "ort_session.h" -#import "ort_env.h" -#import "ort_value.h" - -NS_ASSUME_NONNULL_BEGIN - -namespace test_utils { - -NSString* _Nullable createTemporaryDirectory(XCTestCase* testCase); - -NSArray* getFloatArrayFromData(NSData* data); - -} // namespace test_utils - -NS_ASSUME_NONNULL_END diff --git a/objectivec/test/test_utils.mm b/objectivec/test/test_utils.mm deleted file mode 100644 index ef8e8c5..0000000 --- a/objectivec/test/test_utils.mm +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#import "test_utils.h" - -NS_ASSUME_NONNULL_BEGIN - -namespace test_utils { - -NSString* createTemporaryDirectory(XCTestCase* testCase) { - NSString* temporaryDirectory = NSTemporaryDirectory(); - NSString* directoryPath = [temporaryDirectory stringByAppendingPathComponent:@"ort-objective-c-test"]; - - NSError* error = nil; - [[NSFileManager defaultManager] createDirectoryAtPath:directoryPath - withIntermediateDirectories:YES - attributes:nil - error:&error]; - - XCTAssertNil(error, @"Error creating temporary directory: %@", error.localizedDescription); - - // add teardown block to delete the temporary directory - [testCase addTeardownBlock:^{ - NSError* error = nil; - [[NSFileManager defaultManager] removeItemAtPath:directoryPath error:&error]; - XCTAssertNil(error, @"Error removing temporary directory: %@", error.localizedDescription); - }]; - - return directoryPath; -} - -NSArray* getFloatArrayFromData(NSData* data) { - NSMutableArray* array = [NSMutableArray array]; - float value; - for (size_t i = 0; i < data.length / sizeof(float); ++i) { - [data getBytes:&value range:NSMakeRange(i * sizeof(float), sizeof(float))]; - [array addObject:[NSNumber numberWithFloat:value]]; - } - return array; -} - -} // namespace test_utils - -NS_ASSUME_NONNULL_END diff --git a/objectivec/test/testdata/gen_models.sh b/objectivec/test/testdata/gen_models.sh deleted file mode 100755 index 0a58ca8..0000000 --- a/objectivec/test/testdata/gen_models.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -# Get directory this script is in -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -cd ${DIR} - -python3 ./single_add_gen.py - -ORT_CONVERT_ONNX_MODELS_TO_ORT_OPTIMIZATION_LEVEL=basic python3 -m onnxruntime.tools.convert_onnx_models_to_ort --optimization_style=Fixed . diff --git a/objectivec/test/testdata/single_add.basic.ort b/objectivec/test/testdata/single_add.basic.ort deleted file mode 100644 index f622784b35366ea8f0c33ccbdb513b5d6f7df7c1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1296 zcmaJ=L2DCH5T59w+gK&qP=ZMC5X6H#a!@S6gSGW228qz?vUxTO&D*eD(+Gkdq9fHT2w9Z|5JC$eX^YH( zlR%{XYq5Zk8bCRK-6(YKQNIB6HiyIBeUTjJWFiO82f%rt3)}>_&xlYiY8;GOSmb7$ z&l6~_CL&tWWB~H``e>1B;n$lD6g595VDqaf9Yo#GIDe}^8Mfg=^Z{}(59JBa!5-}v zK)DTw)V0wS&J3ry_RPrw0VxVu)->>nX{L6ljZwugT zn6K>BBj`Na1Xh4|F#13TU_ZV9N5By10*w3i+xH!++T=^KT{C%=r&&BQQEna2_~=2S zi*eV1I31gD5@+dt`XV=WHnCYUwl0tMa9HtY5MwR_r($65RQ%|}{~$_C>fFpsGCNJ| zfyuKdaf#c-k-R_S&w5M$s^44qU1dPA$jzB){(Y0U+-5G?Gj4Pc)8#w-`Bu5;%UPDZ nW85dyzl#&~J%&)fHONzUGA<@%sQ;t)_p@e%kMWx4xd-D9DJ`oI diff --git a/objectivec/test/testdata/single_add.onnx b/objectivec/test/testdata/single_add.onnx deleted file mode 100644 index 82e8fe669e0d84b6111f678b0742a552d820269b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 93 zcmd;Jw+iMG=3;c@VssK>be3XvOi57!5kj27nR)3ssX%5FKTuwXi;IJUQHX_$iGvX& U;DjuY1Qc*a7I0$WVi4c~0E&7GKL7v# diff --git a/objectivec/test/testdata/single_add_gen.py b/objectivec/test/testdata/single_add_gen.py deleted file mode 100644 index 15b4372..0000000 --- a/objectivec/test/testdata/single_add_gen.py +++ /dev/null @@ -1,19 +0,0 @@ -import onnx -from onnx import TensorProto, helper - -graph = helper.make_graph( - [ # nodes - helper.make_node("Add", ["A", "B"], ["C"], "Add"), - ], - "SingleAdd", # name - [ # inputs - helper.make_tensor_value_info("A", TensorProto.FLOAT, [1]), - helper.make_tensor_value_info("B", TensorProto.FLOAT, [1]), - ], - [ # outputs - helper.make_tensor_value_info("C", TensorProto.FLOAT, [1]), - ], -) - -model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 12)]) -onnx.save(model, r"single_add.onnx")