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