Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 1 | #!/usr/bin/python2 |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 4 | """Script adapter used by automation client for testing dejagnu. |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 5 | |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 6 | This is not intended to be run on command line. |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 7 | To kick off a single dejagnu run, use ./dejagnu/run_dejagnu.py |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 8 | """ |
| 9 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 10 | from __future__ import print_function |
| 11 | |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 12 | __author__ = 'shenhan@google.com (Han Shen)' |
| 13 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 14 | import argparse |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 15 | import sys |
| 16 | import setup_chromeos |
| 17 | import build_tc |
| 18 | |
| 19 | from dejagnu import run_dejagnu |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 20 | from cros_utils import command_executer |
| 21 | from cros_utils import email_sender |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 22 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 23 | |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 24 | class DejagnuAdapter(object): |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 25 | """Dejagnu Adapter class""" |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 26 | |
| 27 | # TODO(shenhan): move these to constants.py. |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 28 | _CHROMIUM_GCC_GIT = ('https://chromium.googlesource.com/' |
| 29 | 'chromiumos/third_party/gcc.git') |
| 30 | _CHROMIUM_GCC_BRANCH = 'gcc.gnu.org/branches/google/gcc-4_7-mobile' |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 31 | |
| 32 | _cmd_exec = command_executer.GetCommandExecuter() |
| 33 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 34 | def __init__(self, board, remote, gcc_dir, chromeos_root, runtestflags, |
| 35 | cleanup): |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 36 | self._board = board |
| 37 | self._remote = remote |
| 38 | self._gcc_dir = gcc_dir |
| 39 | self._chromeos_root = chromeos_root |
shenhan | c60576f | 2013-02-19 21:11:00 +0000 | [diff] [blame] | 40 | self._runtestflags = runtestflags |
| 41 | self._cleanup = cleanup |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 42 | |
| 43 | def SetupChromeOS(self): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 44 | cmd = [setup_chromeos.__file__, '--dir=' + self._chromeos_root, |
| 45 | '--minilayout', '--jobs=8'] |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 46 | ret = setup_chromeos.Main(cmd) |
| 47 | if ret: |
Caroline Tice | 9099a78 | 2016-07-22 16:28:12 -0700 | [diff] [blame] | 48 | raise RuntimeError('Failed to checkout chromeos') |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 49 | ## Do cros_sdk and setup_board, otherwise build_tc in next step will fail. |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 50 | cmd = 'cd {0} && cros_sdk --download'.format(self._chromeos_root) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 51 | ret = self._cmd_exec.RunCommand(cmd, terminated_timeout=9000) |
| 52 | if ret: |
Caroline Tice | 9099a78 | 2016-07-22 16:28:12 -0700 | [diff] [blame] | 53 | raise RuntimeError('Failed to create chroot.') |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 54 | |
| 55 | def SetupBoard(self): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 56 | cmd = './setup_board --board=' + self._board |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 57 | ret = self._cmd_exec.ChrootRunCommand(self._chromeos_root, |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 58 | cmd, |
| 59 | terminated_timeout=4000) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 60 | if ret: |
Caroline Tice | 9099a78 | 2016-07-22 16:28:12 -0700 | [diff] [blame] | 61 | raise RuntimeError('Failed to setup board.') |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 62 | |
| 63 | def CheckoutGCC(self): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 64 | cmd = 'git clone {0} {1} && cd {1} && git checkout {2}'.format( |
| 65 | self._CHROMIUM_GCC_GIT, self._gcc_dir, self._CHROMIUM_GCC_BRANCH) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 66 | |
| 67 | ret = self._cmd_exec.RunCommand(cmd, terminated_timeout=300) |
| 68 | if ret: |
Caroline Tice | 9099a78 | 2016-07-22 16:28:12 -0700 | [diff] [blame] | 69 | raise RuntimeError('Failed to checkout gcc.') |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 70 | ## Handle build_tc bug. |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 71 | cmd = ('touch {0}/gcc/config/arm/arm-tune.md ' + \ |
| 72 | '{0}/gcc/config/arm/arm-tables.opt').format(self._gcc_dir) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 73 | ret = self._cmd_exec.RunCommand(cmd) |
| 74 | |
| 75 | def BuildGCC(self): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 76 | build_gcc_args = [build_tc.__file__, '--board=' + self._board, |
| 77 | '--chromeos_root=' + self._chromeos_root, |
| 78 | '--gcc_dir=' + self._gcc_dir] |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 79 | ret = build_tc.Main(build_gcc_args) |
| 80 | if ret: |
Caroline Tice | 9099a78 | 2016-07-22 16:28:12 -0700 | [diff] [blame] | 81 | raise RuntimeError('Building gcc failed.') |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 82 | |
| 83 | def CheckGCC(self): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 84 | args = [run_dejagnu.__file__, '--board=' + self._board, |
| 85 | '--chromeos_root=' + self._chromeos_root, |
| 86 | '--mount=' + self._gcc_dir, '--remote=' + self._remote] |
shenhan | c60576f | 2013-02-19 21:11:00 +0000 | [diff] [blame] | 87 | if self._cleanup: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 88 | args.append('--cleanup=' + self._cleanup) |
shenhan | c60576f | 2013-02-19 21:11:00 +0000 | [diff] [blame] | 89 | if self._runtestflags: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 90 | args.append('--flags=' + self._runtestflags) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 91 | return run_dejagnu.Main(args) |
| 92 | |
shenhan | c0c0b35 | 2013-02-19 21:11:36 +0000 | [diff] [blame] | 93 | |
| 94 | # Parse the output log to determine how many failures we have. |
| 95 | # Return -1 if parse output log failed. |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 96 | def GetNumNewFailures(input_str): |
| 97 | if not input_str: |
shenhan | c0c0b35 | 2013-02-19 21:11:36 +0000 | [diff] [blame] | 98 | return 0 |
| 99 | start_counting = False |
| 100 | n_failures = 0 |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 101 | for l in input_str.splitlines(): |
| 102 | print(l) |
shenhan | c0c0b35 | 2013-02-19 21:11:36 +0000 | [diff] [blame] | 103 | if not start_counting and 'Build results not in the manifest' in l: |
| 104 | start_counting = True |
| 105 | elif start_counting and l and ( |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 106 | l.find('UNRESOLVED:') == 0 or l.find('FAIL:') == 0 or |
shenhan | c0c0b35 | 2013-02-19 21:11:36 +0000 | [diff] [blame] | 107 | l.find('XFAIL:') == 0 or l.find('XPASS:') == 0): |
| 108 | n_failures = n_failures + 1 |
| 109 | if not start_counting: |
| 110 | return -1 |
| 111 | return n_failures |
| 112 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 113 | |
shenhan | c60576f | 2013-02-19 21:11:00 +0000 | [diff] [blame] | 114 | # Do not throw any exception in this function! |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 115 | def EmailResult(result): |
shenhan | e0a6d8a | 2013-02-19 20:42:29 +0000 | [diff] [blame] | 116 | email_to = ['c-compiler-chrome@google.com'] |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 117 | if len(result) == 4: |
| 118 | subject = 'Job failed: dejagnu test didn\'t finish' |
| 119 | email_text = 'Job failed prematurely, check exception below.\n' + \ |
| 120 | result[3] |
| 121 | elif result[0]: |
| 122 | subject = 'Job finished: dejagnu test failed' |
shenhan | c0c0b35 | 2013-02-19 21:11:36 +0000 | [diff] [blame] | 123 | num_new_failures = GetNumNewFailures(result[1]) |
| 124 | if num_new_failures >= 0: |
| 125 | summary = '{0} new fail(s), check log below.'.format(num_new_failures) |
| 126 | else: |
| 127 | summary = 'At least 1 new fail found, check log below.' |
| 128 | email_text = summary + \ |
| 129 | ('\nStdout ====\n' |
| 130 | '{0}\n' |
| 131 | '\nStderr ===\n' |
| 132 | '{1}\n').format(result[1], result[2]) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 133 | else: |
| 134 | subject = 'Job finished: dejagnu test passed' |
| 135 | email_text = ('Cool! No new fail found.\n' |
| 136 | '\nStdout ====\n' |
| 137 | '{0}\n' |
| 138 | '\nStderr ====\n' |
| 139 | '{1}\n').format(result[1], result[2]) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 140 | |
| 141 | try: |
| 142 | email_sender.EmailSender().SendEmail(email_to, subject, email_text) |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 143 | print('Email sent.') |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 144 | except Exception as e: |
| 145 | # Do not propagate this email sending exception, you want to email an |
| 146 | # email exception? Just log it on console. |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 147 | print('Sending email failed - {0}' |
| 148 | 'Subject: {1}' |
| 149 | 'Text: {2}').format( |
| 150 | str(e), subject, email_text) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 151 | |
| 152 | |
| 153 | def ProcessArguments(argv): |
| 154 | """Processing script arguments.""" |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 155 | parser = argparse.ArgumentParser( |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 156 | description=('This script is used by nightly client to test gcc. ' |
| 157 | 'DO NOT run it unless you know what you are doing.'), |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 158 | usage='test_gcc_dejagnu.py options') |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 159 | parser.add_argument('-b', |
| 160 | '--board', |
| 161 | dest='board', |
| 162 | help=('Required. Specify board type. For example ' |
| 163 | '\'lumpy\' and \'daisy\'')) |
| 164 | parser.add_argument('-r', |
| 165 | '--remote', |
| 166 | dest='remote', |
| 167 | help=('Required. Specify remote board address')) |
| 168 | parser.add_argument('-g', |
| 169 | '--gcc_dir', |
| 170 | dest='gcc_dir', |
| 171 | default='gcc.live', |
| 172 | help=('Optional. Specify gcc checkout directory.')) |
| 173 | parser.add_argument('-c', |
| 174 | '--chromeos_root', |
| 175 | dest='chromeos_root', |
| 176 | default='chromeos.live', |
| 177 | help=('Optional. Specify chromeos checkout directory.')) |
| 178 | parser.add_argument('--cleanup', |
| 179 | dest='cleanup', |
| 180 | default=None, |
| 181 | help=('Optional. Do cleanup after the test.')) |
| 182 | parser.add_argument('--runtestflags', |
| 183 | dest='runtestflags', |
| 184 | default=None, |
| 185 | help=('Optional. Options to RUNTESTFLAGS env var ' |
| 186 | 'while invoking make check. ' |
| 187 | '(Mainly used for testing purpose.)')) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 188 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 189 | options = parser.parse_args(argv[1:]) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 190 | |
| 191 | if not options.board or not options.remote: |
Caroline Tice | 9099a78 | 2016-07-22 16:28:12 -0700 | [diff] [blame] | 192 | raise SyntaxError('--board and --remote are mandatory options.') |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 193 | |
| 194 | return options |
| 195 | |
shenhan | c60576f | 2013-02-19 21:11:00 +0000 | [diff] [blame] | 196 | |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 197 | def Main(argv): |
| 198 | opt = ProcessArguments(argv) |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 199 | adapter = DejagnuAdapter(opt.board, opt.remote, opt.gcc_dir, |
| 200 | opt.chromeos_root, opt.runtestflags, opt.cleanup) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 201 | try: |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 202 | adapter.SetupChromeOS() |
| 203 | adapter.SetupBoard() |
| 204 | adapter.CheckoutGCC() |
| 205 | adapter.BuildGCC() |
| 206 | ret = adapter.CheckGCC() |
| 207 | except Exception as e: |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 208 | print(e) |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 209 | ret = (1, '', '', str(e)) |
| 210 | finally: |
| 211 | EmailResult(ret) |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 212 | |
| 213 | return ret |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 214 | |
| 215 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 216 | if __name__ == '__main__': |
shenhan | f844b43 | 2013-02-19 20:42:07 +0000 | [diff] [blame] | 217 | retval = Main(sys.argv) |
| 218 | sys.exit(retval[0]) |