Suppression for crbug/241044.
[chromium-blink-merge.git] / chrome / test / install_test / run_install_tests.py
blob9e5be379ab688243b62202664ae527c124101259
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Runs install and update tests.
8 Install tests are performed using a single Chrome build, whereas two or more
9 builds are needed for Update tests. There are separate command arguments for
10 the builds that will be used for each of the tests. If a test file contains
11 both types of tests(install and update), both arguments should be specified.
12 Otherwise, specify only the command argument that is required for the test.
13 To run a test with this script, append the module name to the _TEST_MODULES
14 list. Modules added to the list must be in the same directory or in a sub-
15 directory that's in the same location as this script.
17 Example:
18 $ python run_install_tests.py --url=<chrome_builds_url> --filter=* \
19 --install-build=24.0.1290.0 --update-builds=24.0.1289.0,24.0.1290.0
20 """
22 import logging
23 import optparse
24 import os
25 import re
26 import sys
27 import unittest
29 import chrome_installer_win
30 from install_test import InstallTest
32 from common import unittest_util
33 from common import util
35 # To run tests from a module, append the module name to this list.
36 _TEST_MODULES = ['sample_updater', 'theme_updater']
38 for module in _TEST_MODULES:
39 __import__(module)
42 class Main(object):
43 """Main program for running 'Fresh Install' and 'Updater' tests."""
45 def __init__(self):
46 self._SetLoggingConfiguration()
47 self._ParseArgs()
48 self._Run()
50 def _ParseArgs(self):
51 """Parses command line arguments."""
52 parser = optparse.OptionParser()
53 parser.add_option(
54 '-u', '--url', type='string', default='', dest='url',
55 help='Specifies the build url, without the build number.')
56 parser.add_option(
57 '-o', '--options', type='string', default='',
58 help='Specifies any additional Chrome options (i.e. --system-level).')
59 parser.add_option(
60 '--install-build', type='string', default='', dest='install_build',
61 help='Specifies the build to be used for fresh install testing.')
62 parser.add_option(
63 '--update-builds', type='string', default='', dest='update_builds',
64 help='Specifies the builds to be used for updater testing.')
65 parser.add_option(
66 '--install-type', type='string', default='user', dest='install_type',
67 help='Type of installation (i.e., user, system, or both)')
68 parser.add_option(
69 '-f', '--filter', type='string', default='*', dest='filter',
70 help='Filter that specifies the test or testsuite to run.')
71 self._opts, self._args = parser.parse_args()
72 self._ValidateArgs()
73 if self._opts.install_type == 'system':
74 InstallTest.SetInstallType(chrome_installer_win.InstallationType.SYSTEM)
75 update_builds = (self._opts.update_builds.split(',') if
76 self._opts.update_builds else [])
77 options = self._opts.options.split(',') if self._opts.options else []
78 InstallTest.InitTestFixture(self._opts.install_build, update_builds,
79 self._opts.url, options)
81 def _ValidateArgs(self):
82 """Verifies the sanity of the command arguments.
84 Confirms that all specified builds have a valid version number, and the
85 build urls are valid.
86 """
87 builds = []
88 if self._opts.install_build:
89 builds.append(self._opts.install_build)
90 if self._opts.update_builds:
91 builds.extend(self._opts.update_builds.split(','))
92 builds = list(frozenset(builds))
93 for build in builds:
94 if not re.match('\d+\.\d+\.\d+\.\d+', build):
95 raise RuntimeError('Invalid build number: %s' % build)
96 if not util.DoesUrlExist('%s/%s/' % (self._opts.url, build)):
97 raise RuntimeError('Could not locate build no. %s' % build)
99 def _SetLoggingConfiguration(self):
100 """Sets the basic logging configuration."""
101 log_format = '%(asctime)s %(levelname)-8s %(message)s'
102 logging.basicConfig(level=logging.INFO, format=log_format)
104 def _Run(self):
105 """Runs the unit tests."""
106 all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES)
107 tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter)
108 result = unittest_util.TextTestRunner(verbosity=1).run(tests)
109 # Run tests again if installation type is 'both'(i.e., user and system).
110 if self._opts.install_type == 'both':
111 # Load the tests again so test parameters can be reinitialized.
112 all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES)
113 tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter)
114 InstallTest.SetInstallType(chrome_installer_win.InstallationType.SYSTEM)
115 result = unittest_util.TextTestRunner(verbosity=1).run(tests)
116 del(tests)
117 if not result.wasSuccessful():
118 print >>sys.stderr, ('Not all tests were successful.')
119 sys.exit(1)
120 sys.exit(0)
123 if __name__ == '__main__':
124 Main()