blob: c95dcf677390e2150bb6e8acbfa4852233f0d36b [file] [log] [blame]
Yunlian Jiangc5713372016-06-15 11:37:50 -07001#!/usr/bin/python2
2"""Script for running llvm validation tests on ChromeOS.
3
4This script launches a buildbot to build ChromeOS with the llvm on
5a particular board; then it finds and downloads the trybot image and the
6corresponding official image, and runs test for correctness.
7It then generates a report, emails it to the c-compiler-chrome, as
8well as copying the result into a directory.
9"""
10
11# Script to test different toolchains against ChromeOS benchmarks.
12
13from __future__ import print_function
14
15import argparse
16import datetime
17import os
18import sys
19import time
20
Caroline Ticea8af9a72016-07-20 12:52:59 -070021from cros_utils import command_executer
22from cros_utils import logger
Yunlian Jiangc5713372016-06-15 11:37:50 -070023
Caroline Ticea8af9a72016-07-20 12:52:59 -070024from cros_utils import buildbot_utils
Yunlian Jiangc5713372016-06-15 11:37:50 -070025
26# CL that uses LLVM to build the peppy image.
27USE_LLVM_PATCH = '295217'
28
Yunlian Jiangc5713372016-06-15 11:37:50 -070029CROSTC_ROOT = '/usr/local/google/crostc'
30ROLE_ACCOUNT = 'mobiletc-prebuild'
31TOOLCHAIN_DIR = os.path.dirname(os.path.realpath(__file__))
32MAIL_PROGRAM = '~/var/bin/mail-sheriff'
33VALIDATION_RESULT_DIR = os.path.join(CROSTC_ROOT, 'validation_result')
34START_DATE = datetime.date(2016, 1, 1)
35TEST_PER_DAY = 2
36TEST_BOARD = [
37 'squawks',
38 'terra',
39 'lulu',
40 'peach_pit',
Caroline Ticea12e9742016-09-08 13:35:02 -070041 'peppy',
42 'link',
Yunlian Jiangc5713372016-06-15 11:37:50 -070043 'veyron_jaq',
44 'lumpy',
45 'sentry',
46 'chell',
47 'nyan_big',
Caroline Ticea12e9742016-09-08 13:35:02 -070048]
Yunlian Jiangc5713372016-06-15 11:37:50 -070049
50TEST = [
51 'bvt-inline',
52 'bvt-cq',
53 'paygen_au_canary',
54 'security',
55 #'kernel_per-build_regression',
56 #'kernel_per-build_benchmarks',
Caroline Ticea12e9742016-09-08 13:35:02 -070057 'kernel_daily_regression',
Yunlian Jiangc5713372016-06-15 11:37:50 -070058 'kernel_daily_benchmarks',
59 #'stress',
Caroline Ticea12e9742016-09-08 13:35:02 -070060]
61
Yunlian Jiangc5713372016-06-15 11:37:50 -070062
63class ToolchainVerifier(object):
64 """Class for the toolchain verifier."""
65
Caroline Ticea12e9742016-09-08 13:35:02 -070066 def __init__(self, board, chromeos_root, weekday, patches, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -070067 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 Tice314ea562016-06-24 15:59:01 -070072 self._compiler = compiler
Yunlian Jiangc5713372016-06-15 11:37:50 -070073 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 Ticed00ad412016-07-02 18:00:18 -070081 self._reports = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -070082
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 Ticea12e9742016-09-08 13:35:02 -0700100 board=self._board, test=test, image=image))
Yunlian Jiangc5713372016-06-15 11:37:50 -0700101 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 Ticea12e9742016-09-08 13:35:02 -0700121 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 Jiangc5713372016-06-15 11:37:50 -0700128 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 Jiangc5713372016-06-15 11:37:50 -0700136 return 0
137
Caroline Ticea12e9742016-09-08 13:35:02 -0700138
Caroline Tice314ea562016-06-24 15:59:01 -0700139def SendEmail(start_board, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -0700140 """Send out the test results for all the boards."""
Caroline Ticea12e9742016-09-08 13:35:02 -0700141 results = ''
Yunlian Jiangc5713372016-06-15 11:37:50 -0700142 for i in range(len(TEST_BOARD)):
143 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
Caroline Ticed00ad412016-07-02 18:00:18 -0700144 f = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700145 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 Ticea12e9742016-09-08 13:35:02 -0700154 output = os.path.join(VALIDATION_RESULT_DIR, compiler, 'result')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700155 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 Tice314ea562016-06-24 15:59:01 -0700160 email_title = '%s validation test results' % compiler
Yunlian Jiangc5713372016-06-15 11:37:50 -0700161 command = ('cat %s | %s -s "%s" -team' %
162 (output, MAIL_PROGRAM, email_title))
163 ce.RunCommand(command)
164
165
166def Main(argv):
167 """The main function."""
168
169 # Common initializations
170 command_executer.InitCommandExecuter()
171 parser = argparse.ArgumentParser()
Caroline Ticea12e9742016-09-08 13:35:02 -0700172 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 Jiangc5713372016-06-15 11:37:50 -0700194
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 Tice314ea562016-06-24 15:59:01 -0700199 if not options.compiler:
200 print('Please specify which compiler to test (gcc or llvm).')
201 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700202 if options.patches:
203 patches = options.patches
Caroline Tice314ea562016-06-24 15:59:01 -0700204 elif options.compiler == 'llvm':
Yunlian Jiangc5713372016-06-15 11:37:50 -0700205 patches = USE_LLVM_PATCH
206
207 if options.board:
208 fv = ToolchainVerifier(options.board, options.chromeos_root,
Caroline Tice314ea562016-06-24 15:59:01 -0700209 options.weekday, patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700210 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 Jiang54e72b32016-06-21 14:13:03 -0700218 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700219 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
220 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
221 patches, options.compiler)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700222 fv.DoAll()
223 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700224 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700225 with open(logfile, 'w') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700226 f.write('Verifier got an exception, please check the log.\n')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700227
Caroline Tice314ea562016-06-24 15:59:01 -0700228 SendEmail(start_board, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700229
Caroline Ticea12e9742016-09-08 13:35:02 -0700230
Yunlian Jiangc5713372016-06-15 11:37:50 -0700231if __name__ == '__main__':
232 retval = Main(sys.argv)
233 sys.exit(retval)