Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 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 | """Android bisector to bisect a range of android build id. |
| 7 | |
| 8 | Example: |
| 9 | $ ./bisect_android_build_id.py init --old rev1 --new rev2 --dut DUT |
| 10 | $ ./bisect_android_build_id.py config switch ./switch_arc_prebuilt.py |
| 11 | $ ./bisect_android_build_id.py config eval ./eval-manually.sh |
| 12 | $ ./bisect_android_build_id.py run |
| 13 | |
| 14 | When running switcher and evaluator, following environment variables |
| 15 | will be set: |
| 16 | ANDROID_BRANCH (e.g. git_mnc-dr-arc-dev), |
| 17 | ANDROID_FLAVOR (e.g. cheets_x86-user), |
| 18 | ANDROID_BUILD_ID (e.g. 9876543), |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 19 | DUT (e.g. samus-dut, if available). |
| 20 | """ |
| 21 | |
| 22 | from __future__ import print_function |
| 23 | import logging |
| 24 | |
| 25 | from bisect_kit import android_util |
| 26 | from bisect_kit import arc_util |
Kuang-che Wu | 2526a67 | 2019-09-10 16:23:59 +0800 | [diff] [blame] | 27 | from bisect_kit import bisector_cli |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 28 | from bisect_kit import cli |
| 29 | from bisect_kit import configure |
| 30 | from bisect_kit import core |
| 31 | from bisect_kit import cros_util |
| 32 | |
| 33 | logger = logging.getLogger(__name__) |
| 34 | |
| 35 | |
| 36 | class AndroidBuildIDDomain(core.BisectDomain): |
| 37 | """BisectDomain for Android build IDs.""" |
| 38 | revtype = staticmethod(android_util.argtype_android_build_id) |
| 39 | help = globals()['__doc__'] |
| 40 | |
| 41 | @staticmethod |
| 42 | def add_init_arguments(parser): |
| 43 | parser.add_argument( |
| 44 | '--branch', |
| 45 | metavar='ANDROID_BRANCH', |
| 46 | default=configure.get('ANDROID_BRANCH'), |
| 47 | help='git branch like "git_mnc-dr-arc-dev"') |
| 48 | parser.add_argument( |
| 49 | '--flavor', |
| 50 | metavar='ANDROID_FLAVOR', |
| 51 | default=configure.get('ANDROID_FLAVOR'), |
| 52 | help='example: cheets_x86-user') |
| 53 | parser.add_argument( |
| 54 | '--only_good_build', |
| 55 | action='store_true', |
| 56 | help='Bisect only good builds. ' |
| 57 | 'This flag is only needed if weird builds blocked bisection') |
| 58 | |
| 59 | # Only used for Android on ChromeOS. |
| 60 | parser.add_argument( |
| 61 | '--dut', |
| 62 | type=cli.argtype_notempty, |
| 63 | metavar='DUT', |
| 64 | default=configure.get('DUT'), |
| 65 | help='For ChromeOS, address of DUT (Device Under Test)') |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 66 | |
| 67 | @staticmethod |
| 68 | def init(opts): |
| 69 | if opts.dut: |
| 70 | assert cros_util.is_dut(opts.dut) |
| 71 | |
| 72 | if not opts.flavor: |
| 73 | assert opts.dut |
| 74 | opts.flavor = arc_util.query_flavor(opts.dut) |
| 75 | |
| 76 | if not opts.branch: |
| 77 | assert opts.dut |
| 78 | board = cros_util.query_dut_board(opts.dut) |
| 79 | version = cros_util.query_dut_short_version(opts.dut) |
| 80 | opts.branch = cros_util.query_android_branch(board, version) |
| 81 | assert opts.branch |
| 82 | |
Kuang-che Wu | 94ef56e | 2019-01-15 21:17:42 +0800 | [diff] [blame] | 83 | config = dict(branch=opts.branch, flavor=opts.flavor) |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 84 | if opts.dut: |
| 85 | config['dut'] = opts.dut |
| 86 | |
Kuang-che Wu | 0a902f4 | 2019-01-21 18:58:32 +0800 | [diff] [blame] | 87 | revlist = android_util.get_build_ids_between(opts.branch, opts.flavor, |
| 88 | opts.old, opts.new) |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 89 | |
| 90 | if opts.only_good_build: |
| 91 | revlist = [ |
| 92 | bid for bid in revlist |
| 93 | if android_util.is_good_build(opts.branch, opts.flavor, bid) |
| 94 | ] |
| 95 | |
| 96 | return config, revlist |
| 97 | |
| 98 | def __init__(self, config): |
| 99 | self.config = config |
| 100 | |
| 101 | def setenv(self, env, rev): |
| 102 | env['ANDROID_BRANCH'] = self.config['branch'] |
| 103 | env['ANDROID_FLAVOR'] = self.config['flavor'] |
| 104 | env['ANDROID_BUILD_ID'] = rev |
| 105 | if self.config.get('dut'): |
| 106 | env['DUT'] = self.config['dut'] |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 107 | |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame] | 108 | def fill_candidate_summary(self, summary, interesting_indexes): |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame] | 109 | url_template = ('https://android-build.googleplex.com/' |
| 110 | 'builds/{new}/branches/%s/targets/%s/cls?end={old}') % ( |
| 111 | self.config['branch'], self.config['flavor']) |
Kuang-che Wu | 948a79c | 2019-06-19 19:13:56 +0800 | [diff] [blame] | 112 | if 'current_range' in summary: |
| 113 | old, new = summary['current_range'] |
| 114 | summary['links'] = [ |
| 115 | { |
| 116 | 'name': 'change_list', |
| 117 | 'url': url_template.format(old=old, new=new), |
Kuang-che Wu | 948a79c | 2019-06-19 19:13:56 +0800 | [diff] [blame] | 118 | }, |
| 119 | ] |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame] | 120 | |
| 121 | for i in interesting_indexes: |
| 122 | if i == 0: |
| 123 | continue |
| 124 | rev_info = summary['rev_info'][i] |
| 125 | rev_info.update({ |
| 126 | 'actions': [{ |
| 127 | 'link': |
| 128 | url_template.format( |
| 129 | old=summary['rev_info'][i - 1]['rev'], |
| 130 | new=rev_info['rev']), |
| 131 | }], |
| 132 | }) |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 133 | |
| 134 | |
| 135 | if __name__ == '__main__': |
Kuang-che Wu | 2526a67 | 2019-09-10 16:23:59 +0800 | [diff] [blame] | 136 | bisector_cli.BisectorCommandLine(AndroidBuildIDDomain).main() |