Commit 55087567 authored by Menglu Huang's avatar Menglu Huang Committed by Commit Bot

Let iossim to accept device udid

Change-Id: Ice14942fc6f16198a62d6aaa15d1ba5a80f9c040
Reviewed-on: https://chromium-review.googlesource.com/896369
Commit-Queue: Menglu Huang <huangml@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534219}
parent 1801b020
...@@ -14,13 +14,15 @@ void PrintUsage() { ...@@ -14,13 +14,15 @@ void PrintUsage() {
" where <app_path> is the path to the .app directory and <xctest_path> " " where <app_path> is the path to the .app directory and <xctest_path> "
"is the path to an optional xctest bundle.\n" "is the path to an optional xctest bundle.\n"
"Options:\n" "Options:\n"
" -u Specifies the device udid to use. Will use -d, -s values to get "
"devices if not specified.\n"
" -d Specifies the device (must be one of the values from the iOS " " -d Specifies the device (must be one of the values from the iOS "
"Simulator's Hardware -> Device menu. Defaults to 'iPhone 6s'.\n" "Simulator's Hardware -> Device menu. Defaults to 'iPhone 6s'.\n"
" -w Wipe the device's contents and settings before running the " " -w Wipe the device's contents and settings before running the "
"test.\n" "test.\n"
" -e Specifies an environment key=value pair that will be" " -e Specifies an environment key=value pair that will be"
" set in the simulated application's environment.\n" " set in the simulated application's environment.\n"
" -t Specifies a test or test suite that should be included in the" " -t Specifies a test or test suite that should be included in the "
"test run. All other tests will be excluded from this run.\n" "test run. All other tests will be excluded from this run.\n"
" -c Specifies command line flags to pass to application.\n" " -c Specifies command line flags to pass to application.\n"
" -p Print the device's home directory, does not run a test.\n" " -p Print the device's home directory, does not run a test.\n"
...@@ -196,6 +198,19 @@ NSString* GetDeviceBySDKAndName(NSDictionary* simctl_list, ...@@ -196,6 +198,19 @@ NSString* GetDeviceBySDKAndName(NSDictionary* simctl_list,
return nil; return nil;
} }
bool FindDeviceByUDID(NSDictionary* simctl_list, NSString* udid) {
NSDictionary* devices_table = simctl_list[@"devices"];
for (id runtimes in devices_table) {
NSArray* devices = devices_table[runtimes];
for (NSDictionary* device in devices) {
if ([device[@"udid"] isEqualToString:udid]) {
return true;
}
}
}
return false;
}
// Prints the HOME environment variable for a device. Used by the bots to // Prints the HOME environment variable for a device. Used by the bots to
// package up all the test data. // package up all the test data.
void PrintDeviceHome(NSString* udid) { void PrintDeviceHome(NSString* udid) {
...@@ -332,6 +347,7 @@ int main(int argc, char* const argv[]) { ...@@ -332,6 +347,7 @@ int main(int argc, char* const argv[]) {
NSString* app_path = nil; NSString* app_path = nil;
NSString* xctest_path = nil; NSString* xctest_path = nil;
NSString* udid = nil;
NSString* device_name = @"iPhone 6s"; NSString* device_name = @"iPhone 6s";
bool wants_wipe = false; bool wants_wipe = false;
bool wants_print_home = false; bool wants_print_home = false;
...@@ -354,6 +370,9 @@ int main(int argc, char* const argv[]) { ...@@ -354,6 +370,9 @@ int main(int argc, char* const argv[]) {
case 'd': case 'd':
device_name = [NSString stringWithUTF8String:optarg]; device_name = [NSString stringWithUTF8String:optarg];
break; break;
case 'u':
udid = [NSString stringWithUTF8String:optarg];
break;
case 'w': case 'w':
wants_wipe = true; wants_wipe = true;
break; break;
...@@ -394,13 +413,23 @@ int main(int argc, char* const argv[]) { ...@@ -394,13 +413,23 @@ int main(int argc, char* const argv[]) {
} }
} }
NSString* udid = GetDeviceBySDKAndName(simctl_list, device_name, sdk_version); if (udid == nil) {
udid = GetDeviceBySDKAndName(simctl_list, device_name, sdk_version);
if (udid == nil) { if (udid == nil) {
LogError(@"Unable to find a device %@ with SDK %@.", device_name, LogError(@"Unable to find a device %@ with SDK %@.", device_name,
sdk_version); sdk_version);
PrintSupportedDevices(simctl_list); PrintSupportedDevices(simctl_list);
exit(kExitInvalidArguments); exit(kExitInvalidArguments);
} }
} else {
if (!FindDeviceByUDID(simctl_list, udid)) {
LogError(
@"Unable to find a device with udid %@. Use 'xcrun simctl list' to "
@"see valid device udids.",
udid);
exit(kExitInvalidArguments);
}
}
if (wants_print_home) { if (wants_print_home) {
PrintDeviceHome(udid); PrintDeviceHome(udid);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment