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 | acb6efd | 2018-04-25 18:52:58 +0800 | [diff] [blame] | 19 | ANDROID_ROOT (if available), and |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 20 | DUT (e.g. samus-dut, if available). |
| 21 | """ |
| 22 | |
| 23 | from __future__ import print_function |
| 24 | import logging |
| 25 | |
| 26 | from bisect_kit import android_util |
| 27 | from bisect_kit import arc_util |
| 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)') |
| 66 | parser.add_argument( |
| 67 | '--android_root', |
| 68 | type=cli.argtype_dir_path, |
| 69 | default=configure.get('ANDROID_ROOT'), |
| 70 | help='For ChromeOS, default android tree to search push_to_device.py') |
| 71 | |
| 72 | @staticmethod |
| 73 | def init(opts): |
| 74 | if opts.dut: |
| 75 | assert cros_util.is_dut(opts.dut) |
| 76 | |
| 77 | if not opts.flavor: |
| 78 | assert opts.dut |
| 79 | opts.flavor = arc_util.query_flavor(opts.dut) |
| 80 | |
| 81 | if not opts.branch: |
| 82 | assert opts.dut |
| 83 | board = cros_util.query_dut_board(opts.dut) |
| 84 | version = cros_util.query_dut_short_version(opts.dut) |
| 85 | opts.branch = cros_util.query_android_branch(board, version) |
| 86 | assert opts.branch |
| 87 | |
| 88 | config = dict( |
| 89 | branch=opts.branch, flavor=opts.flavor, android_root=opts.android_root) |
| 90 | if opts.dut: |
| 91 | config['dut'] = opts.dut |
| 92 | |
| 93 | revlist = android_util.get_build_ids_between(opts.branch, opts.old, |
| 94 | opts.new) |
| 95 | |
| 96 | if opts.only_good_build: |
| 97 | revlist = [ |
| 98 | bid for bid in revlist |
| 99 | if android_util.is_good_build(opts.branch, opts.flavor, bid) |
| 100 | ] |
| 101 | |
| 102 | return config, revlist |
| 103 | |
| 104 | def __init__(self, config): |
| 105 | self.config = config |
| 106 | |
| 107 | def setenv(self, env, rev): |
| 108 | env['ANDROID_BRANCH'] = self.config['branch'] |
| 109 | env['ANDROID_FLAVOR'] = self.config['flavor'] |
| 110 | env['ANDROID_BUILD_ID'] = rev |
| 111 | if self.config.get('dut'): |
| 112 | env['DUT'] = self.config['dut'] |
| 113 | if self.config.get('android_root'): |
| 114 | env['ANDROID_ROOT'] = self.config['android_root'] |
| 115 | |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame] | 116 | def fill_candidate_summary(self, summary, interesting_indexes): |
| 117 | old, new = summary['current_range'] |
| 118 | url_template = ('https://android-build.googleplex.com/' |
| 119 | 'builds/{new}/branches/%s/targets/%s/cls?end={old}') % ( |
| 120 | self.config['branch'], self.config['flavor']) |
| 121 | summary.update({ |
| 122 | 'link_note': |
| 123 | 'Because the diff viewer is inclusive, you need to ignore changes ' |
| 124 | 'from starting version by yourself (b/118564983)', |
| 125 | 'links': { |
| 126 | 'change_list': url_template.format(old=old, new=new), |
| 127 | 'minus': url_template.format(old=old, new=old), |
| 128 | }, |
| 129 | }) |
| 130 | |
| 131 | for i in interesting_indexes: |
| 132 | if i == 0: |
| 133 | continue |
| 134 | rev_info = summary['rev_info'][i] |
| 135 | rev_info.update({ |
| 136 | 'actions': [{ |
| 137 | 'link': |
| 138 | url_template.format( |
| 139 | old=summary['rev_info'][i - 1]['rev'], |
| 140 | new=rev_info['rev']), |
| 141 | }], |
| 142 | }) |
Kuang-che Wu | 708310b | 2018-03-28 17:24:34 +0800 | [diff] [blame] | 143 | |
| 144 | |
| 145 | if __name__ == '__main__': |
Kuang-che Wu | dd7f6f0 | 2018-06-28 18:19:30 +0800 | [diff] [blame] | 146 | cli.BisectorCommandLine(AndroidBuildIDDomain).main() |