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.
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
29 import chrome_installer_win
30 from install_test import InstallTest
32 _DIRECTORY = os.path.dirname(os.path.abspath(__file__))
33 sys.path.append(os.path.join(_DIRECTORY, os.path.pardir, os.path.pardir,
34 os.path.pardir, 'build', 'util', 'lib'))
36 from common import unittest_util
37 from common import util
39 # To run tests from a module, append the module name to this list.
40 _TEST_MODULES = ['sample_updater', 'theme_updater']
42 for module in _TEST_MODULES:
47 """Main program for running 'Fresh Install' and 'Updater' tests."""
50 self._SetLoggingConfiguration()
55 """Parses command line arguments."""
56 parser = optparse.OptionParser()
58 '-u', '--url', type='string', default='', dest='url',
59 help='Specifies the build url, without the build number.')
61 '-o', '--options', type='string', default='',
62 help='Specifies any additional Chrome options (i.e. --system-level).')
64 '--install-build', type='string', default='', dest='install_build',
65 help='Specifies the build to be used for fresh install testing.')
67 '--update-builds', type='string', default='', dest='update_builds',
68 help='Specifies the builds to be used for updater testing.')
70 '--install-type', type='string', default='user', dest='install_type',
71 help='Type of installation (i.e., user, system, or both)')
73 '-f', '--filter', type='string', default='*', dest='filter',
74 help='Filter that specifies the test or testsuite to run.')
75 self._opts, self._args = parser.parse_args()
77 if self._opts.install_type == 'system':
78 InstallTest.SetInstallType(chrome_installer_win.InstallationType.SYSTEM)
79 update_builds = (self._opts.update_builds.split(',') if
80 self._opts.update_builds else [])
81 options = self._opts.options.split(',') if self._opts.options else []
82 InstallTest.InitTestFixture(self._opts.install_build, update_builds,
83 self._opts.url, options)
85 def _ValidateArgs(self):
86 """Verifies the sanity of the command arguments.
88 Confirms that all specified builds have a valid version number, and the
92 if self._opts.install_build:
93 builds.append(self._opts.install_build)
94 if self._opts.update_builds:
95 builds.extend(self._opts.update_builds.split(','))
96 builds = list(frozenset(builds))
98 if not re.match('\d+\.\d+\.\d+\.\d+', build):
99 raise RuntimeError('Invalid build number: %s' % build)
100 if not util.DoesUrlExist('%s/%s/' % (self._opts.url, build)):
101 raise RuntimeError('Could not locate build no. %s' % build)
103 def _SetLoggingConfiguration(self):
104 """Sets the basic logging configuration."""
105 log_format = '%(asctime)s %(levelname)-8s %(message)s'
106 logging.basicConfig(level=logging.INFO, format=log_format)
109 """Runs the unit tests."""
110 all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES)
111 tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter)
112 result = unittest_util.TextTestRunner(verbosity=1).run(tests)
113 # Run tests again if installation type is 'both'(i.e., user and system).
114 if self._opts.install_type == 'both':
115 # Load the tests again so test parameters can be reinitialized.
116 all_tests = unittest.defaultTestLoader.loadTestsFromNames(_TEST_MODULES)
117 tests = unittest_util.FilterTestSuite(all_tests, self._opts.filter)
118 InstallTest.SetInstallType(chrome_installer_win.InstallationType.SYSTEM)
119 result = unittest_util.TextTestRunner(verbosity=1).run(tests)
121 if not result.wasSuccessful():
122 print >>sys.stderr, ('Not all tests were successful.')
127 if __name__ == '__main__':