blob: 164fa32206d15d67764088e5e98eb51df11fbef1 [file] [log] [blame]
Kuang-che Wu875c89a2020-01-08 14:30:55 +08001#!/usr/bin/env python3
Kuang-che Wu32f27242019-05-16 17:34:50 +08002# -*- coding: utf-8 -*-
3# Copyright 2019 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"""Diagnose ChromeOS tast regressions.
7
8This is integrated bisection utility. Given ChromeOS, Chrome, Android source
9tree, and necessary parameters, this script can determine which components to
10bisect, and hopefully output the culprit CL of regression.
11
12Sometimes the script failed to figure out the final CL for various reasons, it
13will cut down the search range as narrow as it can.
14"""
15from __future__ import print_function
Kuang-che Wu32f27242019-05-16 17:34:50 +080016import logging
17
18from bisect_kit import cros_lab_util
19from bisect_kit import cros_util
20from bisect_kit import diagnoser_cros
21from bisect_kit import errors
22import setup_cros_bisect
23
24logger = logging.getLogger(__name__)
25
Kuang-che Wu32f27242019-05-16 17:34:50 +080026
27class DiagnoseTastCommandLine(diagnoser_cros.DiagnoseCommandLineBase):
28 """Diagnose command line interface."""
29
30 def check_options(self, opts, path_factory):
31 super(DiagnoseTastCommandLine, self).check_options(opts, path_factory)
32 if not opts.test_name:
33 self.argument_parser.error('argument --test_name is required')
34
35 def init_hook(self, opts):
36 pass
37
38 def _build_cmds(self):
39 common_eval_cmd = [
40 './eval_cros_tast.py',
Kuang-che Wu4fc0f1c2019-08-02 21:56:49 +080041 '--with_private_bundles',
Kuang-che Wu32f27242019-05-16 17:34:50 +080042 '--chromeos_root', self.config['chromeos_root'],
43 '--test_name', self.config['test_name'],
44 ] # yapf: disable
45 if self.config['metric']:
46 common_eval_cmd += [
47 '--metric', self.config['metric'],
48 ] # yapf: disable
49 if self.config['fail_to_pass']:
50 common_eval_cmd.append('--fail_to_pass')
51 if self.config['reboot_before_test']:
52 common_eval_cmd.append('--reboot_before_test')
53
54 return common_eval_cmd
55
56 def cmd_run(self, opts):
57 del opts # unused
58
59 self.states.load()
60
61 try:
62 path_factory = setup_cros_bisect.DefaultProjectPathFactory(
63 self.config['mirror_base'], self.config['work_base'],
64 self.config['session'])
65 common_eval_cmd = self._build_cmds()
66
Kuang-che Wu0c9b7942019-10-30 16:55:39 +080067 with cros_lab_util.dut_manager(
68 self.config['dut'],
69 lambda: diagnoser_cros.grab_dut(self.config)) as dut:
Kuang-che Wu32f27242019-05-16 17:34:50 +080070 if not dut:
71 raise errors.NoDutAvailable('unable to allocate DUT')
Kuang-che Wu7cb08df2019-06-04 19:12:29 +080072 if not cros_util.is_good_dut(dut):
73 if not cros_lab_util.repair(dut):
74 raise errors.ExternalError('Not a good DUT and unable to repair')
Kuang-che Wu32f27242019-05-16 17:34:50 +080075 assert cros_util.is_dut(dut)
76 if self.config['dut'] == cros_lab_util.LAB_DUT:
77 self.config['allocated_dut'] = dut
78 self.states.save()
79 common_eval_cmd.append(dut)
80
81 diagnoser = diagnoser_cros.CrosDiagnoser(self.states, path_factory,
82 self.config, dut)
83
84 diagnoser.narrow_down_chromeos_prebuilt(
85 self.config['old'], self.config['new'], common_eval_cmd)
86
87 diagnoser.switch_chromeos_to_old(force=self.config['always_reflash'])
Kuang-che Wuc8c495d2019-08-19 17:48:58 +080088 dut_os_version = cros_util.query_dut_short_version(dut)
Kuang-che Wu32f27242019-05-16 17:34:50 +080089
90 try:
91 if diagnoser.narrow_down_android(common_eval_cmd):
92 return
93 except errors.DiagnoseContradiction:
94 raise
95 except Exception:
96 logger.exception('exception in android bisector before verification; '
97 'assume culprit is not inside android and continue')
98 # Assume it's ok to leave random version of android prebuilt on DUT.
99
Kuang-che Wuc8c495d2019-08-19 17:48:58 +0800100 # Sanity check. The OS version should not change after android bisect.
Kuang-che Wu523bdf22019-08-20 12:11:09 +0800101 assert dut_os_version == cros_util.query_dut_short_version(dut), \
102 'Someone else reflashed the DUT. ' \
103 'DUT locking is not respected? b/126141102'
Kuang-che Wuc8c495d2019-08-19 17:48:58 +0800104
Kuang-che Wu32f27242019-05-16 17:34:50 +0800105 try:
Kuang-che Wude5bfc32019-09-12 21:56:48 +0800106 if self.config['chrome_deploy_image']:
107 eval_cmd = common_eval_cmd + ['--tast_build']
108 else:
109 eval_cmd = common_eval_cmd
Kuang-che Wuda9cb702019-11-11 14:40:56 +0800110 if diagnoser.narrow_down_chrome(eval_cmd):
Kuang-che Wu32f27242019-05-16 17:34:50 +0800111 return
112 except errors.DiagnoseContradiction:
113 raise
114 except Exception:
115 logger.exception('exception in chrome bisector before verification; '
116 'assume culprit is not inside chrome and continue')
117
Kuang-che Wude5bfc32019-09-12 21:56:48 +0800118 if not self.config['chrome_deploy_image']:
119 # Sanity check. The OS version should not change after chrome bisect.
120 assert dut_os_version == cros_util.query_dut_short_version(dut), \
121 'Someone else reflashed the DUT. ' \
122 'DUT locking is not respected? b/126141102'
Kuang-che Wuc8c495d2019-08-19 17:48:58 +0800123
Zheng-Jie Changd3fd8f12020-04-14 11:41:06 +0800124 if self.config['disable_buildbucket_chromeos']:
Zheng-Jie Chang181be6f2020-03-17 16:16:08 +0800125 eval_cmd = common_eval_cmd + ['--tast_build']
Zheng-Jie Changd3fd8f12020-04-14 11:41:06 +0800126 else:
127 eval_cmd = common_eval_cmd
Kuang-che Wu32f27242019-05-16 17:34:50 +0800128 diagnoser.narrow_down_chromeos_localbuild(eval_cmd)
129 logger.info('%s done', __file__)
130 except Exception as e:
131 logger.exception('got exception; stop')
132 exception_name = e.__class__.__name__
133 self.states.add_history(
134 'failed', '%s: %s' % (exception_name, e), exception=exception_name)
135
136
137if __name__ == '__main__':
138 DiagnoseTastCommandLine().main()