| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """This script tests the installer with test cases specified in the config file. | 5 """This script tests the installer with test cases specified in the config file. |
| 6 | 6 |
| 7 For each test case, it checks that the machine states after the execution of | 7 For each test case, it checks that the machine states after the execution of |
| 8 each command match the expected machine states. For more details, take a look at | 8 each command match the expected machine states. For more details, take a look at |
| 9 the design documentation at http://goo.gl/Q0rGM6 | 9 the design documentation at http://goo.gl/Q0rGM6 |
| 10 """ | 10 """ |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 config = Config() | 225 config = Config() |
| 226 config.tests = config_data['tests'] | 226 config.tests = config_data['tests'] |
| 227 for state_name, state_property_filenames in config_data['states']: | 227 for state_name, state_property_filenames in config_data['states']: |
| 228 config.states[state_name] = ParsePropertyFiles(directory, | 228 config.states[state_name] = ParsePropertyFiles(directory, |
| 229 state_property_filenames) | 229 state_property_filenames) |
| 230 for action_name, action_command in config_data['actions']: | 230 for action_name, action_command in config_data['actions']: |
| 231 config.actions[action_name] = action_command | 231 config.actions[action_name] = action_command |
| 232 return config | 232 return config |
| 233 | 233 |
| 234 | 234 |
| 235 def RunTests(mini_installer_path, config, force_clean, verbosity, | |
| 236 json_output_path, tests): | |
| 237 """Tests the installer using the given Config object. | |
| 238 | |
| 239 Args: | |
| 240 mini_installer_path: The path to mini_installer.exe. | |
| 241 config: A Config object. | |
| 242 force_clean: A boolean indicating whether to force cleaning existing | |
| 243 installations. | |
| 244 verbosity: Verbosity level for the test runner (0..n). | |
| 245 json_output_path: Path to JSON output file. | |
| 246 tests: List of tests to run. All tests are run if omitted. | |
| 247 | |
| 248 Returns: | |
| 249 True if all the tests passed, or False otherwise. | |
| 250 """ | |
| 251 suite = unittest.TestSuite() | |
| 252 variable_expander = VariableExpander(mini_installer_path) | |
| 253 RunCleanCommand(force_clean, variable_expander) | |
| 254 for test in config.tests: | |
| 255 # If tests were specified via |tests|, their names are formatted like this: | |
| 256 test_name = '%s.%s.%s' % (InstallerTest.__module__, InstallerTest.__name__, | |
| 257 test['name']) | |
| 258 if not tests or test_name in tests: | |
| 259 suite.addTest(InstallerTest(test['name'], test['traversal'], config, | |
| 260 variable_expander)) | |
| 261 result = unittest.TextTestRunner(verbosity=(verbosity + 1)).run(suite) | |
| 262 if json_output_path: | |
| 263 with open(json_output_path, 'w') as fp: | |
| 264 json.dump(_FullResults(suite, result, {}), fp, indent=2) | |
| 265 fp.write("\n") | |
| 266 return result.wasSuccessful() | |
| 267 | |
| 268 | |
| 269 def IsComponentBuild(mini_installer_path): | 235 def IsComponentBuild(mini_installer_path): |
| 270 """ Invokes the mini_installer asking whether it is a component build. | 236 """ Invokes the mini_installer asking whether it is a component build. |
| 271 | 237 |
| 272 Args: | 238 Args: |
| 273 mini_installer_path: The path to mini_installer.exe. | 239 mini_installer_path: The path to mini_installer.exe. |
| 274 | 240 |
| 275 Returns: | 241 Returns: |
| 276 True if the mini_installer is a component build, False otherwise. | 242 True if the mini_installer is a component build, False otherwise. |
| 277 """ | 243 """ |
| 278 query_command = [ mini_installer_path, '--query-component-build' ] | 244 query_command = [ mini_installer_path, '--query-component-build' ] |
| (...skipping 20 matching lines...) Expand all Loading... |
| 299 help='Name(s) of tests to run.') | 265 help='Name(s) of tests to run.') |
| 300 args = parser.parse_args() | 266 args = parser.parse_args() |
| 301 if not args.config: | 267 if not args.config: |
| 302 parser.error('missing mandatory --config FILENAME argument') | 268 parser.error('missing mandatory --config FILENAME argument') |
| 303 | 269 |
| 304 mini_installer_path = os.path.join(args.build_dir, args.target, | 270 mini_installer_path = os.path.join(args.build_dir, args.target, |
| 305 'mini_installer.exe') | 271 'mini_installer.exe') |
| 306 assert os.path.exists(mini_installer_path), ('Could not find file %s' % | 272 assert os.path.exists(mini_installer_path), ('Could not find file %s' % |
| 307 mini_installer_path) | 273 mini_installer_path) |
| 308 | 274 |
| 275 suite = unittest.TestSuite() |
| 276 |
| 309 # Set the env var used by mini_installer.exe to decide to not show UI. | 277 # Set the env var used by mini_installer.exe to decide to not show UI. |
| 310 os.environ['MINI_INSTALLER_TEST'] = '1' | 278 os.environ['MINI_INSTALLER_TEST'] = '1' |
| 311 if IsComponentBuild(mini_installer_path): | 279 is_component_build = IsComponentBuild(mini_installer_path) |
| 280 if not is_component_build: |
| 281 config = ParseConfigFile(args.config) |
| 282 |
| 283 variable_expander = VariableExpander(mini_installer_path) |
| 284 RunCleanCommand(args.force_clean, variable_expander) |
| 285 for test in config.tests: |
| 286 # If tests were specified via |tests|, their names are formatted like so: |
| 287 test_name = '%s.%s.%s' % (InstallerTest.__module__, |
| 288 InstallerTest.__name__, |
| 289 test['name']) |
| 290 if not args.test or test_name in args.test: |
| 291 suite.addTest(InstallerTest(test['name'], test['traversal'], config, |
| 292 variable_expander)) |
| 293 |
| 294 result = unittest.TextTestRunner(verbosity=(args.verbose + 1)).run(suite) |
| 295 if is_component_build: |
| 312 print ('Component build is currently unsupported by the mini_installer: ' | 296 print ('Component build is currently unsupported by the mini_installer: ' |
| 313 'http://crbug.com/377839') | 297 'http://crbug.com/377839') |
| 314 return 0 | 298 if args.write_full_results_to: |
| 315 | 299 with open(args.write_full_results_to, 'w') as fp: |
| 316 config = ParseConfigFile(args.config) | 300 json.dump(_FullResults(suite, result, {}), fp, indent=2) |
| 317 if not RunTests(mini_installer_path, config, args.force_clean, args.verbose, | 301 fp.write("\n") |
| 318 args.write_full_results_to, args.test): | 302 return 0 if result.wasSuccessful() else 1 |
| 319 return 1 | |
| 320 return 0 | |
| 321 | 303 |
| 322 | 304 |
| 323 # TODO(dpranke): Find a way for this to be shared with the mojo and other tests. | 305 # TODO(dpranke): Find a way for this to be shared with the mojo and other tests. |
| 324 TEST_SEPARATOR = '.' | 306 TEST_SEPARATOR = '.' |
| 325 | 307 |
| 326 | 308 |
| 327 def _FullResults(suite, result, metadata): | 309 def _FullResults(suite, result, metadata): |
| 328 """Convert the unittest results to the Chromium JSON test result format. | 310 """Convert the unittest results to the Chromium JSON test result format. |
| 329 | 311 |
| 330 This matches run-webkit-tests (the layout tests) and the flakiness dashboard. | 312 This matches run-webkit-tests (the layout tests) and the flakiness dashboard. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 trie[path] = value | 364 trie[path] = value |
| 383 return | 365 return |
| 384 directory, rest = path.split(TEST_SEPARATOR, 1) | 366 directory, rest = path.split(TEST_SEPARATOR, 1) |
| 385 if directory not in trie: | 367 if directory not in trie: |
| 386 trie[directory] = {} | 368 trie[directory] = {} |
| 387 _AddPathToTrie(trie[directory], rest, value) | 369 _AddPathToTrie(trie[directory], rest, value) |
| 388 | 370 |
| 389 | 371 |
| 390 if __name__ == '__main__': | 372 if __name__ == '__main__': |
| 391 sys.exit(main()) | 373 sys.exit(main()) |
| OLD | NEW |