summaryrefslogtreecommitdiffstats
path: root/testing/iossim
diff options
context:
space:
mode:
authorlliabraa@chromium.org <lliabraa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-09 22:12:14 +0000
committerlliabraa@chromium.org <lliabraa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-09 22:12:14 +0000
commit506ceebdd613e5f0d6d0bb942871f8e4f039aa86 (patch)
treeddcbc785b5d2045ea360cf9e2e37056b710acc87 /testing/iossim
parentfd98b61111df70659bdee313c12601d9531df077 (diff)
downloadchromium_src-506ceebdd613e5f0d6d0bb942871f8e4f039aa86.zip
chromium_src-506ceebdd613e5f0d6d0bb942871f8e4f039aa86.tar.gz
chromium_src-506ceebdd613e5f0d6d0bb942871f8e4f039aa86.tar.bz2
In iossim, use default home directory if no -u override is given.
With Xcode 6, the home directory of the iOS Simulator and iossim processes must match so that the iOS Simulator can find the SimDevice object created by iossim. Since the existing behavior of iossim is to create a new, random, home directory on each run (if no -u value is specified on the command line), the home directories will be mismatched if iossim is launched multiple times without killing the iOS Simulator in between runs. The fix here is to only override the home directory in iossim if -u is specified. Since this will often reuse the default SimDeviceSet (at ~/Library/Developer/CoreSimulator/Devices), functionality is also changed to reuse an existing SimDevice if possible (though iossim will create a SimDevice if necessary). BUG=None TBR=rohitrao Review URL: https://codereview.chromium.org/382563002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282139 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'testing/iossim')
-rw-r--r--testing/iossim/iossim.mm69
1 files changed, 43 insertions, 26 deletions
diff --git a/testing/iossim/iossim.mm b/testing/iossim/iossim.mm
index 1593a5a1..b5cbd51 100644
--- a/testing/iossim/iossim.mm
+++ b/testing/iossim/iossim.mm
@@ -609,16 +609,34 @@ DTiPhoneSimulatorSessionConfig* BuildSessionConfig(
NSString* identifier = systemRoot.runtime.identifier;
id simRuntime = [simRuntimeClass supportedRuntimesByIdentifier][identifier];
+ // Attempt to use an existing device, but create one if a suitable match can't
+ // be found. For example, if the simulator is running with a non-default home
+ // directory (e.g. via iossim's -u command line arg) then there won't be any
+ // devices so one will have to be created.
Class simDeviceSetClass = FindClassByName(@"SimDeviceSet");
- NSError* error = nil;
- id simDevice =
- [[simDeviceSetClass defaultSet] createDeviceWithType:simDeviceType
- runtime:simRuntime
- name:@"iossim"
- error:&error];
- if (error) {
- LogError(@"Failed to create device: %@", error);
- exit(kExitInitializationFailure);
+ id deviceSet =
+ [simDeviceSetClass setForSetPath:[simDeviceSetClass defaultSetPath]];
+ id simDevice = nil;
+ for (id device in [deviceSet availableDevices]) {
+ if ([device runtime] == simRuntime &&
+ [device deviceType] == simDeviceType) {
+ simDevice = device;
+ break;
+ }
+ }
+ if (!simDevice) {
+ NSError* error = nil;
+ // n.b. only the device name is necessary because the iOS Simulator menu
+ // already splits devices by runtime version.
+ NSString* name = [NSString stringWithFormat:@"iossim - %@ ", deviceName];
+ simDevice = [deviceSet createDeviceWithType:simDeviceType
+ runtime:simRuntime
+ name:name
+ error:&error];
+ if (error) {
+ LogError(@"Failed to create device: %@", error);
+ exit(kExitInitializationFailure);
+ }
}
sessionConfig.device = simDevice;
#endif
@@ -866,14 +884,21 @@ int main(int argc, char* const argv[]) {
// Determine the deviceFamily based on the deviceName
NSNumber* deviceFamily = nil;
+// TODO(lliabraa): Once all builders are on Xcode 6 this ifdef can be removed
+// (crbug.com/385030).
+#if defined(IOSSIM_USE_XCODE_6)
+ Class simDeviceTypeClass = FindClassByName(@"SimDeviceType");
+ if ([simDeviceTypeClass supportedDeviceTypesByName][deviceName] == nil) {
+ LogError(@"Invalid device name: %@.", deviceName);
+ PrintSupportedDevices();
+ exit(kExitInvalidArguments);
+ }
+#else
if (!deviceName || CaseInsensitivePrefixSearch(deviceName, @"iPhone")) {
deviceFamily = [NSNumber numberWithInt:kIPhoneFamily];
} else if (CaseInsensitivePrefixSearch(deviceName, @"iPad")) {
deviceFamily = [NSNumber numberWithInt:kIPadFamily];
}
-// TODO(lliabraa): Once all builders are on Xcode 6 this ifdef can be removed
-// (crbug.com/385030).
-#if !defined(IOSSIM_USE_XCODE_6)
else {
LogError(@"Invalid device name: %@. Must begin with 'iPhone' or 'iPad'",
deviceName);
@@ -881,24 +906,16 @@ int main(int argc, char* const argv[]) {
}
#endif // !defined(IOSSIM_USE_XCODE_6)
- // Set up the user home directory for the simulator
- if (!simHomePath) {
- NSString* dirNameTemplate =
- [NSString stringWithFormat:@"iossim-%@-%@-XXXXXX", appName, deviceName];
- simHomePath = CreateTempDirectory(dirNameTemplate);
- if (!simHomePath) {
- LogError(@"Unable to create unique directory for template %@",
- dirNameTemplate);
+ // Set up the user home directory for the simulator only if a non-default
+ // value was specified.
+ if (simHomePath) {
+ if (!InitializeSimulatorUserHome(simHomePath)) {
+ LogError(@"Unable to initialize home directory for simulator: %@",
+ simHomePath);
exit(kExitInitializationFailure);
}
}
- if (!InitializeSimulatorUserHome(simHomePath)) {
- LogError(@"Unable to initialize home directory for simulator: %@",
- simHomePath);
- exit(kExitInitializationFailure);
- }
-
// Create the config and simulator session.
DTiPhoneSimulatorSessionConfig* config = BuildSessionConfig(appSpec,
systemRoot,