Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """Switcher for ChromeOS autotest prebuilt |
| 7 | |
Kuang-che Wu | 99e808f | 2019-06-26 12:17:32 +0800 | [diff] [blame] | 8 | It unpacks autotest prebuilt packages into |
| 9 | $CHROMEOS_ROOT/src/third_party/autotest (that is, autotest_dir). |
| 10 | Later, you can run tests using "eval_cros_autotest.py --prebuilt" or |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 11 | "test_that --autotest_dir". |
| 12 | """ |
| 13 | |
| 14 | from __future__ import print_function |
| 15 | import argparse |
| 16 | import logging |
| 17 | import os |
| 18 | import shutil |
| 19 | import tempfile |
| 20 | |
| 21 | from bisect_kit import cli |
| 22 | from bisect_kit import common |
| 23 | from bisect_kit import configure |
| 24 | from bisect_kit import cros_util |
| 25 | from bisect_kit import util |
| 26 | |
| 27 | logger = logging.getLogger(__name__) |
| 28 | |
| 29 | AUTOTEST_CLIENT_TARBALL = 'autotest_packages.tar' |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 30 | GS_BUILD_PATH = 'gs://chromeos-image-archive/{board}-release/{full_version}' |
| 31 | GS_AUTOTEST_CLIENT_PATH = GS_BUILD_PATH + '/' + AUTOTEST_CLIENT_TARBALL |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 32 | |
| 33 | |
| 34 | def create_argument_parser(): |
| 35 | parser = argparse.ArgumentParser(description=__doc__) |
| 36 | common.add_common_arguments(parser) |
| 37 | parser.add_argument( |
| 38 | '--chromeos_root', |
| 39 | type=cli.argtype_dir_path, |
| 40 | default=configure.get('CHROMEOS_ROOT', ''), |
| 41 | help='ChromeOS tree root') |
| 42 | parser.add_argument( |
| 43 | '--test_name', |
| 44 | help='Client test name, like "video_VideoDecodeAccelerator.h264"') |
| 45 | parser.add_argument( |
| 46 | '--board', |
| 47 | metavar='BOARD', |
| 48 | default=configure.get('BOARD', ''), |
| 49 | help='ChromeOS board name') |
| 50 | parser.add_argument( |
| 51 | 'version', |
| 52 | nargs='?', |
| 53 | type=cros_util.argtype_cros_version, |
| 54 | metavar='CROS_VERSION', |
| 55 | default=configure.get('CROS_VERSION', ''), |
| 56 | help='ChromeOS version number, short (10162.0.0) or full (R64-10162.0.0)') |
| 57 | |
| 58 | return parser |
| 59 | |
| 60 | |
Kuang-che Wu | 99e808f | 2019-06-26 12:17:32 +0800 | [diff] [blame] | 61 | def switch(autotest_dir, board, version): |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 62 | full_version = cros_util.version_to_full(board, version) |
| 63 | logger.info('Unpack autotest packages for %s %s', board, full_version) |
| 64 | |
| 65 | autotest_client_path = GS_AUTOTEST_CLIENT_PATH.format( |
| 66 | board=board, full_version=full_version) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 67 | |
| 68 | # TODO(kcwu): cache downloaded tarballs |
| 69 | tmp_dir = tempfile.mkdtemp() |
Kuang-che Wu | 99e808f | 2019-06-26 12:17:32 +0800 | [diff] [blame] | 70 | packages_dir = os.path.join(autotest_dir, 'packages') |
| 71 | if os.path.exists(packages_dir): |
| 72 | shutil.rmtree(packages_dir) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 73 | |
| 74 | cros_util.gsutil('cp', autotest_client_path, tmp_dir) |
| 75 | tarball = os.path.join(tmp_dir, AUTOTEST_CLIENT_TARBALL) |
| 76 | # strip 'autotest/' |
| 77 | util.check_call( |
Kuang-che Wu | 99e808f | 2019-06-26 12:17:32 +0800 | [diff] [blame] | 78 | 'tar', |
| 79 | 'xvf', |
| 80 | tarball, |
| 81 | '--strip-components=1', |
| 82 | 'autotest/packages', |
| 83 | cwd=autotest_dir) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 84 | |
| 85 | shutil.rmtree(tmp_dir) |
| 86 | |
| 87 | |
| 88 | def main(args=None): |
| 89 | common.init() |
| 90 | parser = create_argument_parser() |
| 91 | opts = parser.parse_args(args) |
| 92 | common.config_logging(opts) |
| 93 | |
Kuang-che Wu | 99e808f | 2019-06-26 12:17:32 +0800 | [diff] [blame] | 94 | autotest_dir = os.path.join(opts.chromeos_root, cros_util.autotest_path) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 95 | # Verify test control file exists. |
| 96 | if opts.test_name: |
| 97 | found = cros_util.get_autotest_test_info(autotest_dir, opts.test_name) |
Kuang-che Wu | 99e808f | 2019-06-26 12:17:32 +0800 | [diff] [blame] | 98 | if not found: |
| 99 | names = [] |
| 100 | for control_file in cros_util.enumerate_autotest_control_files( |
| 101 | autotest_dir): |
| 102 | info = cros_util.parse_autotest_control_file(control_file) |
| 103 | names.append(info.name) |
| 104 | util.show_similar_candidates('test_name', opts.test_name, names) |
| 105 | |
| 106 | switch(autotest_dir, opts.board, opts.version) |
Kuang-che Wu | b9705bd | 2018-06-28 17:59:18 +0800 | [diff] [blame] | 107 | |
| 108 | |
| 109 | if __name__ == '__main__': |
| 110 | main() |