| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library("test_options_parser"); | 5 #library("test_options_parser"); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Specification of a single test option. | 8 * Specification of a single test option. |
| 9 * | 9 * |
| 10 * The name of the specification is used as the key for the option in | 10 * The name of the specification is used as the key for the option in |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 [ new _TestOptionSpecification( | 38 [ new _TestOptionSpecification( |
| 39 'mode', | 39 'mode', |
| 40 'Mode in which to run the tests', | 40 'Mode in which to run the tests', |
| 41 ['-m', '--mode'], | 41 ['-m', '--mode'], |
| 42 ['all', 'debug', 'release'], | 42 ['all', 'debug', 'release'], |
| 43 'debug'), | 43 'debug'), |
| 44 new _TestOptionSpecification( | 44 new _TestOptionSpecification( |
| 45 'component', | 45 'component', |
| 46 'The component to test against', | 46 'The component to test against', |
| 47 ['-c', '--component'], | 47 ['-c', '--component'], |
| 48 ['most', 'vm', 'dartc', 'chromium', 'dartium'], | 48 ['most', 'vm', 'dartc', 'frog', 'frogsh', 'leg', |
| 49 'chromium', 'dartium', 'frogium', 'webdriver'], |
| 49 'vm'), | 50 'vm'), |
| 50 new _TestOptionSpecification( | 51 new _TestOptionSpecification( |
| 51 'architecture', | 52 'architecture', |
| 52 'The architecture to run tests for', | 53 'The architecture to run tests for', |
| 53 ['-a', '--arch'], | 54 ['-a', '--arch'], |
| 54 ['all', 'ia32', 'x64', 'simarm', 'arm'], | 55 ['all', 'ia32', 'x64', 'simarm'], |
| 55 'ia32'), | 56 'ia32'), |
| 56 new _TestOptionSpecification( | 57 new _TestOptionSpecification( |
| 57 'os', | 58 'os', |
| 58 'The operating system to run tests on', | 59 'The operating system to run tests on', |
| 59 ['-o', '--os'], | 60 ['-o', '--os'], |
| 60 ['linux', 'macos', 'windows'], | 61 ['linux', 'macos', 'windows'], |
| 61 new Platform().operatingSystem()), | 62 new Platform().operatingSystem()), |
| 62 new _TestOptionSpecification( | 63 new _TestOptionSpecification( |
| 63 'checked', | 64 'checked', |
| 64 'Run tests in checked mode', | 65 'Run tests in checked mode', |
| 65 ['--checked'], | 66 ['--checked'], |
| 66 [], | 67 [], |
| 67 false, | 68 false, |
| 68 'bool'), | 69 'bool'), |
| 69 new _TestOptionSpecification( | 70 new _TestOptionSpecification( |
| 71 'timeout', |
| 72 'Timeout in seconds', |
| 73 ['-t', '--timeout'], |
| 74 [], |
| 75 -1, |
| 76 'int'), |
| 77 new _TestOptionSpecification( |
| 70 'tasks', | 78 'tasks', |
| 71 'The number of parallel tasks to run', | 79 'The number of parallel tasks to run', |
| 72 ['-j', '--tasks'], | 80 ['-j', '--tasks'], |
| 73 [], | 81 [], |
| 74 new Platform().numberOfProcessors(), | 82 new Platform().numberOfProcessors(), |
| 75 'int'), | 83 'int'), |
| 76 new _TestOptionSpecification( | 84 new _TestOptionSpecification( |
| 77 'help', | 85 'help', |
| 78 'Print list of options', | 86 'Print list of options', |
| 79 ['-h', '--help'], | 87 ['-h', '--help'], |
| 80 [], | 88 [], |
| 81 false, | 89 false, |
| 82 'bool')]; | 90 'bool')]; |
| 83 } | 91 } |
| 84 | 92 |
| 85 | 93 |
| 86 /** | 94 /** |
| 87 * Parse a list of strings as test options. | 95 * Parse a list of strings as test options. |
| 88 * | 96 * |
| 89 * Returns a Map mapping from option keys to values. When | 97 * Returns a list of configurations in which to run the |
| 90 * encountering the first non-option string, the rest of the | 98 * tests. Configurations are maps mapping from option keys to |
| 91 * arguments are stored in the returned Map under the 'rest' key. | 99 * values. When encountering the first non-option string, the rest |
| 100 * of the arguments are stored in the returned Map under the 'rest' |
| 101 * key. |
| 92 */ | 102 */ |
| 93 Map parse(List<String> arguments) { | 103 List<Map> parse(List<String> arguments) { |
| 94 var configuration = new Map(); | 104 var configuration = new Map(); |
| 95 // Build configuration of default values. | 105 // Build configuration of default values. |
| 96 for (var option in _options) { | 106 for (var option in _options) { |
| 97 configuration[option.name] = option.defaultValue; | 107 configuration[option.name] = option.defaultValue; |
| 98 } | 108 } |
| 99 // Overwrite with the arguments passed to the test script. | 109 // Overwrite with the arguments passed to the test script. |
| 100 var numArguments = arguments.length; | 110 var numArguments = arguments.length; |
| 101 for (var i = 0; i < numArguments; i++) { | 111 for (var i = 0; i < numArguments; i++) { |
| 102 // Extract name and value for options. | 112 // Extract name and value for options. |
| 103 var arg = arguments[i]; | 113 var arg = arguments[i]; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 configuration[spec.name] = true; | 158 configuration[spec.name] = true; |
| 149 } else if (spec.type == 'int') { | 159 } else if (spec.type == 'int') { |
| 150 try { | 160 try { |
| 151 configuration[spec.name] = Math.parseInt(value); | 161 configuration[spec.name] = Math.parseInt(value); |
| 152 } catch (var e) { | 162 } catch (var e) { |
| 153 print('Integer value expected for int option $name'); | 163 print('Integer value expected for int option $name'); |
| 154 return null; | 164 return null; |
| 155 } | 165 } |
| 156 } else { | 166 } else { |
| 157 assert(spec.type == 'string'); | 167 assert(spec.type == 'string'); |
| 158 if (spec.values.lastIndexOf(value) == -1) { | 168 for (var v in value.split(',')) { |
| 159 print('Unknown value ($value) for option $name'); | 169 if (spec.values.lastIndexOf(v) == -1) { |
| 160 return null; | 170 print('Unknown value ($v) for option $name'); |
| 171 return null; |
| 172 } |
| 161 } | 173 } |
| 162 configuration[spec.name] = value; | 174 configuration[spec.name] = value; |
| 163 } | 175 } |
| 164 } | 176 } |
| 165 | 177 |
| 166 return configuration; | 178 return _expandConfigurations(configuration); |
| 167 } | 179 } |
| 168 | 180 |
| 169 | 181 |
| 182 /** |
| 183 * Recursively expand a configuration with multiple values per key |
| 184 * into a list of configurations with exactly one value per key. |
| 185 */ |
| 186 List<Map> _expandConfigurations(Map configuration) { |
| 187 // Expand the pseudo-values such as 'all'. |
| 188 if (configuration['architecture'] == 'all') { |
| 189 configuration['architecture'] = 'ia32,x64,simarm'; |
| 190 } |
| 191 if (configuration['mode'] == 'all') { |
| 192 configuration['mode'] = 'debug,release'; |
| 193 } |
| 194 if (configuration['component'] == 'most') { |
| 195 configuration['component'] = 'vm,dartc'; |
| 196 } |
| 197 |
| 198 // Expand the architectures. |
| 199 var archs = configuration['architecture']; |
| 200 if (archs.contains(',')) { |
| 201 var result = new List<Map>(); |
| 202 for (var arch in archs.split(',')) { |
| 203 var newConfiguration = new Map.from(configuration); |
| 204 newConfiguration['architecture'] = arch; |
| 205 result.addAll(_expandConfigurations(newConfiguration)); |
| 206 } |
| 207 return result; |
| 208 } |
| 209 |
| 210 // Expand modes. |
| 211 var modes = configuration['mode']; |
| 212 if (modes.contains(',')) { |
| 213 var result = new List<Map>(); |
| 214 for (var mode in modes.split(',')) { |
| 215 var newConfiguration = new Map.from(configuration); |
| 216 newConfiguration['mode'] = mode; |
| 217 result.addAll(_expandConfigurations(newConfiguration)); |
| 218 } |
| 219 return result; |
| 220 } |
| 221 |
| 222 // Expand components. |
| 223 var components = configuration['component']; |
| 224 if (components.contains(',')) { |
| 225 var result = new List<Map>(); |
| 226 for (var component in components.split(',')) { |
| 227 var newConfiguration = new Map.from(configuration); |
| 228 newConfiguration['component'] = component; |
| 229 result.addAll(_expandConfigurations(newConfiguration)); |
| 230 } |
| 231 return result; |
| 232 } |
| 233 |
| 234 // Adjust default timeout based on mode and component. |
| 235 if (configuration['timeout'] == -1) { |
| 236 var timeout = 60; |
| 237 switch (configuration['component']) { |
| 238 case 'dartc': |
| 239 case 'chromium': |
| 240 case 'dartium': |
| 241 case 'frogium': |
| 242 timeout *= 4; |
| 243 break; |
| 244 default: |
| 245 if (configuration['mode'] == 'debug') { |
| 246 timeout *= 2; |
| 247 } |
| 248 break; |
| 249 } |
| 250 configuration['timeout'] = timeout; |
| 251 } |
| 252 |
| 253 return [configuration]; |
| 254 } |
| 255 |
| 256 |
| 170 /** | 257 /** |
| 171 * Print out usage information. | 258 * Print out usage information. |
| 172 */ | 259 */ |
| 173 void _printHelp() { | 260 void _printHelp() { |
| 174 print('usage: dart_bin test.dart [options]\n'); | 261 print('usage: dart_bin test.dart [options]\n'); |
| 175 print('Options:\n'); | 262 print('Options:\n'); |
| 176 for (var option in _options) { | 263 for (var option in _options) { |
| 177 print('${option.name}: ${option.description}.'); | 264 print('${option.name}: ${option.description}.'); |
| 178 for (var name in option.keys) { | 265 for (var name in option.keys) { |
| 179 assert(name.startsWith('-')); | 266 assert(name.startsWith('-')); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 if (option.keys.some((key) => key == name)) { | 300 if (option.keys.some((key) => key == name)) { |
| 214 return option; | 301 return option; |
| 215 } | 302 } |
| 216 } | 303 } |
| 217 return null; | 304 return null; |
| 218 } | 305 } |
| 219 | 306 |
| 220 | 307 |
| 221 List<_TestOptionSpecification> _options; | 308 List<_TestOptionSpecification> _options; |
| 222 } | 309 } |
| 223 | |
| OLD | NEW |