Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: testing/iossim/iossim.mm

Issue 10831111: - When reporting errors from the simulator framework always include the error (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/iossim/iossim.mm
===================================================================
--- testing/iossim/iossim.mm (revision 149406)
+++ testing/iossim/iossim.mm (working copy)
@@ -76,7 +76,13 @@
@"iPhoneSimulatorRemoteClient.framework";
NSString* const kDevToolsFoundationRelativePath =
@"../OtherFrameworks/DevToolsFoundation.framework";
+NSString* const kSimulatorRelativePath =
+ @"Platforms/iPhoneSimulator.platform/Developer/Applications/"
+ @"iPhone Simulator.app";
+// Simulator Error String Key
stuartmorgan 2012/08/01 14:26:17 Explain in the comment where this comes from?
TVL 2012/08/01 14:35:16 Done.
+NSString* const kSimulatorAppQuitErrorKey = @"The simulated application quit.";
+
const char* gToolName = "iossim";
void LogError(NSString* format, ...) {
@@ -111,8 +117,10 @@
// simulator.
@interface SimulatorDelegate : NSObject <DTiPhoneSimulatorSessionDelegate> {
@private
- NSString* stdioPath_; // weak
+ NSString* stdioPath_;
+ NSString* developerDir_;
NSThread* outputThread_;
+ NSBundle* simulatorBundle_;
BOOL appRunning_;
}
@end
@@ -129,16 +137,21 @@
@implementation SimulatorDelegate
// Specifies the file locations of the simulated app's stdout and stderr.
-- (SimulatorDelegate*)initWithStdioPath:(NSString*)stdioPath {
+- (SimulatorDelegate*)initWithStdioPath:(NSString*)stdioPath
+ developerDir:(NSString*)developerDir {
self = [super init];
- if (self)
+ if (self) {
stdioPath_ = [stdioPath copy];
+ developerDir_ = [developerDir copy];
+ }
return self;
}
- (void)dealloc {
[stdioPath_ release];
+ [developerDir_ release];
+ [simulatorBundle_ release];
[super dealloc];
}
@@ -168,6 +181,25 @@
[pool drain];
}
+// Fetches a localized error string from the Simulator.
+- (NSString *)localizedSimulatorErrorString:(NSString*)stringKey {
+ // Lazy load of the simulator bundle.
+ if (simulatorBundle_ == nil) {
+ NSString* simulatorPath = [developerDir_
+ stringByAppendingPathComponent:kSimulatorRelativePath];
+ simulatorBundle_ = [NSBundle bundleWithPath:simulatorPath];
+ }
+ NSString *localizedStr =
+ [simulatorBundle_ localizedStringForKey:stringKey
+ value:nil
+ table:nil];
+ if ([localizedStr length])
+ return localizedStr;
+ // Failed to get a value, follow Cocoa conventions and use the key as the
+ // string.
+ return stringKey;
+}
+
- (void)session:(DTiPhoneSimulatorSession*)session
didStart:(BOOL)started
withError:(NSError*)error {
@@ -193,7 +225,9 @@
exit(EXIT_FAILURE);
}
- LogError(@"Simulator failed to start: %@", [error localizedDescription]);
+ LogError(@"Simulator failed to start: \"%@\" (%@:%ld)",
+ [error localizedDescription],
+ [error domain], (long)[error code]);
exit(EXIT_FAILURE);
}
@@ -218,8 +252,21 @@
}
if (error) {
- LogError(@"Simulator ended with error: %@", [error localizedDescription]);
- exit(EXIT_FAILURE);
+ // There appears to be a race condition where sometimes the simulator
+ // framework will end with an error, but the error is that the simulated
+ // app cleanly shut down, try trap this error and don't fail the simulator
stuartmorgan 2012/08/01 14:26:17 s/,/;/ s/try trap/try to trap/
TVL 2012/08/01 14:35:16 Done. Also fixed in the cl description.
+ // run.
+ NSString* localizedDescription = [error localizedDescription];
+ NSString* ignorableErrorStr =
+ [self localizedSimulatorErrorString:kSimulatorAppQuitErrorKey];
+ if ([ignorableErrorStr isEqual:localizedDescription]) {
+ LogWarning(@"Ignoring that Simulator ended with: \"%@\" (%@:%ld)",
+ localizedDescription, [error domain], (long)[error code]);
stuartmorgan 2012/08/01 14:26:17 C++ cast s/long/long int/
TVL 2012/08/01 14:35:16 Done.
+ } else {
+ LogError(@"Simulator ended with error: \"%@\" (%@:%ld)",
+ localizedDescription, [error domain], (long)[error code]);
stuartmorgan 2012/08/01 14:26:17 Same
TVL 2012/08/01 14:35:16 Done.
+ exit(EXIT_FAILURE);
+ }
}
// Check if the simulated app exited abnormally by looking for system log
@@ -603,7 +650,8 @@
appEnv,
deviceFamily);
SimulatorDelegate* delegate =
- [[[SimulatorDelegate alloc] initWithStdioPath:stdioPath] autorelease];
+ [[[SimulatorDelegate alloc] initWithStdioPath:stdioPath
+ developerDir:developerDir] autorelease];
DTiPhoneSimulatorSession* session = BuildSession(delegate);
// Start the simulator session.
@@ -614,10 +662,13 @@
// Spin the runtime indefinitely. When the delegate gets the message that the
// app has quit it will exit this program.
- if (started)
+ if (started) {
[[NSRunLoop mainRunLoop] run];
- else
- LogError(@"Simulator failed to start: %@", [error localizedDescription]);
+ } else {
+ LogError(@"Simulator failed to start: \"%@\" (%@:%ld)",
+ [error localizedDescription],
+ [error domain], (long)[error code]);
stuartmorgan 2012/08/01 14:26:17 Same
TVL 2012/08/01 14:35:16 Done.
+ }
// Note that this code is only executed if the simulator fails to start
// because once the main run loop is started, only the delegate calling
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698