Add detailed error message for iOS test (#79140)
As title.
Tested locally.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/79140
Approved by: https://github.com/kit1980
diff --git a/ios/TestApp/TestAppTests/TestLiteInterpreter.mm b/ios/TestApp/TestAppTests/TestLiteInterpreter.mm
index 37c8692..1afe4ec 100644
--- a/ios/TestApp/TestAppTests/TestLiteInterpreter.mm
+++ b/ios/TestApp/TestAppTests/TestLiteInterpreter.mm
@@ -21,17 +21,21 @@
XCTAssertTrue(outputTensor.numel() == 1000);
}
-- (void)testModel:(NSString*)filename {
- // model generated using the current pytorch revision
- [self runModel:[NSString stringWithFormat:@"%@_temp", filename]];
- // model generated using older pyotrch revision
- [self runModel:filename];
+- (void)testModel:(NSString*)modelName {
+ NSString* modelPath = [[NSBundle bundleForClass:[self class]] pathForResource:modelName
+ ofType:@"ptl"];
+ XCTAssertNotNil(modelPath, @"Model not found. See https://github.com/pytorch/pytorch/tree/master/test/mobile/model_test#diagnose-failed-test.");
+ [self runModel:modelPath];
+
+ // model generated on the fly
+ NSString* onTheFlyModelName = [NSString stringWithFormat:@"%@", modelName];
+ NSString* onTheFlyModelPath = [[NSBundle bundleForClass:[self class]] pathForResource:onTheFlyModelName
+ ofType:@"ptl"];
+ XCTAssertNotNil(onTheFlyModelPath, @"On-the-fly model not found. Follow https://github.com/pytorch/pytorch/tree/master/test/mobile/model_test#diagnose-failed-test to generate them and run the setup.rb script again.");
+ [self runModel:onTheFlyModelPath];
}
-- (void)runModel:(NSString*)filename {
- NSString* modelPath = [[NSBundle bundleForClass:[self class]] pathForResource:filename
- ofType:@"ptl"];
- XCTAssertNotNil(modelPath);
+- (void)runModel:(NSString*)modelPath {
c10::InferenceMode mode;
auto module = torch::jit::_load_for_mobile(modelPath.UTF8String);
auto has_bundled_input = module.find_method("get_all_bundled_inputs");