Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 1 | #!/usr/bin/python2 |
| 2 | """Script for running llvm validation tests on ChromeOS. |
| 3 | |
| 4 | This script launches a buildbot to build ChromeOS with the llvm on |
| 5 | a particular board; then it finds and downloads the trybot image and the |
| 6 | corresponding official image, and runs test for correctness. |
| 7 | It then generates a report, emails it to the c-compiler-chrome, as |
| 8 | well as copying the result into a directory. |
| 9 | """ |
| 10 | |
| 11 | # Script to test different toolchains against ChromeOS benchmarks. |
| 12 | |
| 13 | from __future__ import print_function |
| 14 | |
| 15 | import argparse |
| 16 | import datetime |
| 17 | import os |
| 18 | import sys |
| 19 | import time |
| 20 | |
Caroline Tice | a8af9a7 | 2016-07-20 12:52:59 -0700 | [diff] [blame] | 21 | from cros_utils import command_executer |
| 22 | from cros_utils import logger |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 23 | |
Caroline Tice | a8af9a7 | 2016-07-20 12:52:59 -0700 | [diff] [blame] | 24 | from cros_utils import buildbot_utils |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 25 | |
| 26 | # CL that uses LLVM to build the peppy image. |
| 27 | USE_LLVM_PATCH = '295217' |
| 28 | |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 29 | CROSTC_ROOT = '/usr/local/google/crostc' |
| 30 | ROLE_ACCOUNT = 'mobiletc-prebuild' |
| 31 | TOOLCHAIN_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 32 | MAIL_PROGRAM = '~/var/bin/mail-sheriff' |
| 33 | VALIDATION_RESULT_DIR = os.path.join(CROSTC_ROOT, 'validation_result') |
| 34 | START_DATE = datetime.date(2016, 1, 1) |
| 35 | TEST_PER_DAY = 2 |
| 36 | TEST_BOARD = [ |
| 37 | 'squawks', |
| 38 | 'terra', |
| 39 | 'lulu', |
| 40 | 'peach_pit', |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 41 | 'peppy', |
| 42 | 'link', |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 43 | 'veyron_jaq', |
| 44 | 'lumpy', |
| 45 | 'sentry', |
| 46 | 'chell', |
| 47 | 'nyan_big', |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 48 | ] |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 49 | |
| 50 | TEST = [ |
| 51 | 'bvt-inline', |
| 52 | 'bvt-cq', |
| 53 | 'paygen_au_canary', |
| 54 | 'security', |
| 55 | #'kernel_per-build_regression', |
| 56 | #'kernel_per-build_benchmarks', |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 57 | 'kernel_daily_regression', |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 58 | 'kernel_daily_benchmarks', |
| 59 | #'stress', |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 60 | ] |
| 61 | |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 62 | |
| 63 | class ToolchainVerifier(object): |
| 64 | """Class for the toolchain verifier.""" |
| 65 | |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 66 | def __init__(self, board, chromeos_root, weekday, patches, compiler): |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 67 | self._board = board |
| 68 | self._chromeos_root = chromeos_root |
| 69 | self._base_dir = os.getcwd() |
| 70 | self._ce = command_executer.GetCommandExecuter() |
| 71 | self._l = logger.GetLogger() |
Caroline Tice | 314ea56 | 2016-06-24 15:59:01 -0700 | [diff] [blame] | 72 | self._compiler = compiler |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 73 | self._build = '%s-release' % board |
| 74 | self._patches = patches.split(',') |
| 75 | self._patches_string = '_'.join(str(p) for p in self._patches) |
| 76 | |
| 77 | if not weekday: |
| 78 | self._weekday = time.strftime('%a') |
| 79 | else: |
| 80 | self._weekday = weekday |
Caroline Tice | d00ad41 | 2016-07-02 18:00:18 -0700 | [diff] [blame] | 81 | self._reports = os.path.join(VALIDATION_RESULT_DIR, compiler, board) |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 82 | |
| 83 | def _FinishSetup(self): |
| 84 | """Make sure testing_rsa file is properly set up.""" |
| 85 | # Fix protections on ssh key |
| 86 | command = ('chmod 600 /var/cache/chromeos-cache/distfiles/target' |
| 87 | '/chrome-src-internal/src/third_party/chromite/ssh_keys' |
| 88 | '/testing_rsa') |
| 89 | ret_val = self._ce.ChrootRunCommand(self._chromeos_root, command) |
| 90 | if ret_val != 0: |
| 91 | raise RuntimeError('chmod for testing_rsa failed') |
| 92 | |
| 93 | def _TestImages(self, image): |
| 94 | to_file = '' |
| 95 | for test in TEST: |
| 96 | command = ('test_that --board {board} :lab: suite:{test} ' |
| 97 | '-i {image} --fast --autotest_dir ' |
| 98 | '~/trunk/src/third_party/autotest/files ' |
| 99 | '--web cautotest.corp.google.com'.format( |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 100 | board=self._board, test=test, image=image)) |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 101 | ret_val = self._ce.ChrootRunCommand(self._chromeos_root, command) |
| 102 | timestamp = datetime.datetime.strftime(datetime.datetime.now(), |
| 103 | '%Y-%m-%d_%H:%M:%S') |
| 104 | if ret_val: |
| 105 | out = 'FAILED' |
| 106 | else: |
| 107 | out = ' ' |
| 108 | to_file += out + ' ' + test + ' ' + timestamp + '\n' |
| 109 | with open(self._reports, 'w') as f: |
| 110 | f.write(to_file) |
| 111 | |
| 112 | def DoAll(self): |
| 113 | """Main function inside ToolchainComparator class. |
| 114 | |
| 115 | Launch trybot, get image names, create crosperf experiment file, run |
| 116 | crosperf, and copy images into seven-day report directories. |
| 117 | """ |
| 118 | date_str = datetime.date.today() |
| 119 | description = 'master_%s_%s_%s' % (self._patches_string, self._build, |
| 120 | date_str) |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 121 | trybot_image = buildbot_utils.GetTrybotImage( |
| 122 | self._chromeos_root, |
| 123 | self._build, |
| 124 | self._patches, |
| 125 | description, |
| 126 | other_flags=['--hwtest'], |
| 127 | build_toolchain=True) |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 128 | if len(trybot_image) == 0: |
| 129 | self._l.LogError('Unable to find trybot_image for %s!' % description) |
| 130 | return 1 |
| 131 | |
| 132 | if os.getlogin() == ROLE_ACCOUNT: |
| 133 | self._FinishSetup() |
| 134 | |
| 135 | self._TestImages(trybot_image) |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 136 | return 0 |
| 137 | |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 138 | |
Caroline Tice | 314ea56 | 2016-06-24 15:59:01 -0700 | [diff] [blame] | 139 | def SendEmail(start_board, compiler): |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 140 | """Send out the test results for all the boards.""" |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 141 | results = '' |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 142 | for i in range(len(TEST_BOARD)): |
| 143 | board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)] |
Caroline Tice | d00ad41 | 2016-07-02 18:00:18 -0700 | [diff] [blame] | 144 | f = os.path.join(VALIDATION_RESULT_DIR, compiler, board) |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 145 | if not os.path.exists(f): |
| 146 | continue |
| 147 | results += board |
| 148 | results += '\n' |
| 149 | file_name = os.path.join(VALIDATION_RESULT_DIR, f) |
| 150 | with open(file_name, 'r') as readin: |
| 151 | read_data = readin.read() |
| 152 | results += read_data |
| 153 | |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 154 | output = os.path.join(VALIDATION_RESULT_DIR, compiler, 'result') |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 155 | with open(output, 'w') as out: |
| 156 | out.write(results) |
| 157 | |
| 158 | ce = command_executer.GetCommandExecuter() |
| 159 | if os.path.exists(os.path.expanduser(MAIL_PROGRAM)): |
Caroline Tice | 314ea56 | 2016-06-24 15:59:01 -0700 | [diff] [blame] | 160 | email_title = '%s validation test results' % compiler |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 161 | command = ('cat %s | %s -s "%s" -team' % |
| 162 | (output, MAIL_PROGRAM, email_title)) |
| 163 | ce.RunCommand(command) |
| 164 | |
| 165 | |
| 166 | def Main(argv): |
| 167 | """The main function.""" |
| 168 | |
| 169 | # Common initializations |
| 170 | command_executer.InitCommandExecuter() |
| 171 | parser = argparse.ArgumentParser() |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 172 | parser.add_argument( |
| 173 | '--chromeos_root', |
| 174 | dest='chromeos_root', |
| 175 | help='The chromeos root from which to run tests.') |
| 176 | parser.add_argument( |
| 177 | '--weekday', |
| 178 | default='', |
| 179 | dest='weekday', |
| 180 | help='The day of the week for which to run tests.') |
| 181 | parser.add_argument( |
| 182 | '--board', default='', dest='board', help='The board to test.') |
| 183 | parser.add_argument( |
| 184 | '--patch', |
| 185 | dest='patches', |
| 186 | help='The patches to use for the testing, ' |
| 187 | "seprate the patch numbers with ',' " |
| 188 | 'for more than one patches.') |
| 189 | parser.add_argument( |
| 190 | '--compiler', |
| 191 | dest='compiler', |
| 192 | help='Which compiler (llvm or gcc) to use for ' |
| 193 | 'testing.') |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 194 | |
| 195 | options = parser.parse_args(argv[1:]) |
| 196 | if not options.chromeos_root: |
| 197 | print('Please specify the ChromeOS root directory.') |
| 198 | return 1 |
Caroline Tice | 314ea56 | 2016-06-24 15:59:01 -0700 | [diff] [blame] | 199 | if not options.compiler: |
| 200 | print('Please specify which compiler to test (gcc or llvm).') |
| 201 | return 1 |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 202 | if options.patches: |
| 203 | patches = options.patches |
Caroline Tice | 314ea56 | 2016-06-24 15:59:01 -0700 | [diff] [blame] | 204 | elif options.compiler == 'llvm': |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 205 | patches = USE_LLVM_PATCH |
| 206 | |
| 207 | if options.board: |
| 208 | fv = ToolchainVerifier(options.board, options.chromeos_root, |
Caroline Tice | 314ea56 | 2016-06-24 15:59:01 -0700 | [diff] [blame] | 209 | options.weekday, patches, options.compiler) |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 210 | return fv.Doall() |
| 211 | |
| 212 | today = datetime.date.today() |
| 213 | delta = today - START_DATE |
| 214 | days = delta.days |
| 215 | |
| 216 | start_board = (days * TEST_PER_DAY) % len(TEST_BOARD) |
| 217 | for i in range(TEST_PER_DAY): |
Yunlian Jiang | 54e72b3 | 2016-06-21 14:13:03 -0700 | [diff] [blame] | 218 | try: |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 219 | board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)] |
| 220 | fv = ToolchainVerifier(board, options.chromeos_root, options.weekday, |
| 221 | patches, options.compiler) |
Yunlian Jiang | 54e72b3 | 2016-06-21 14:13:03 -0700 | [diff] [blame] | 222 | fv.DoAll() |
| 223 | except SystemExit: |
Caroline Tice | d00ad41 | 2016-07-02 18:00:18 -0700 | [diff] [blame] | 224 | logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board) |
Yunlian Jiang | 54e72b3 | 2016-06-21 14:13:03 -0700 | [diff] [blame] | 225 | with open(logfile, 'w') as f: |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 226 | f.write('Verifier got an exception, please check the log.\n') |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 227 | |
Caroline Tice | 314ea56 | 2016-06-24 15:59:01 -0700 | [diff] [blame] | 228 | SendEmail(start_board, options.compiler) |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 229 | |
Caroline Tice | a12e974 | 2016-09-08 13:35:02 -0700 | [diff] [blame] | 230 | |
Yunlian Jiang | c571337 | 2016-06-15 11:37:50 -0700 | [diff] [blame] | 231 | if __name__ == '__main__': |
| 232 | retval = Main(sys.argv) |
| 233 | sys.exit(retval) |