blob: 343a7d414f52abc332f7565182a5e01753da77db [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',
Yunlian Jiangbe2c71a2016-09-22 15:26:46 -070053 'toolchain-tests',
Yunlian Jiangc5713372016-06-15 11:37:50 -070054 '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:
Caroline Tice6395d392016-09-14 11:54:44 -070096 # Do not run the kernel tests with the LLVM compiler.
97 if self._compiler == 'gcc' or not 'kernel' in test:
98 command = ('test_that --board {board} :lab: suite:{test} '
99 '-i {image} --fast --autotest_dir '
100 '~/trunk/src/third_party/autotest/files '
101 '--web cautotest.corp.google.com'.format(
102 board=self._board, test=test, image=image))
103 ret_val = self._ce.ChrootRunCommand(self._chromeos_root, command)
104 timestamp = datetime.datetime.strftime(datetime.datetime.now(),
105 '%Y-%m-%d_%H:%M:%S')
106 if ret_val:
107 out = 'FAILED'
108 else:
109 out = ' '
110 to_file += out + ' ' + test + ' ' + timestamp + '\n'
111 with open(self._reports, 'w') as f:
112 f.write(to_file)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700113
114 def DoAll(self):
115 """Main function inside ToolchainComparator class.
116
117 Launch trybot, get image names, create crosperf experiment file, run
118 crosperf, and copy images into seven-day report directories.
119 """
120 date_str = datetime.date.today()
121 description = 'master_%s_%s_%s' % (self._patches_string, self._build,
122 date_str)
Caroline Ticea12e9742016-09-08 13:35:02 -0700123 trybot_image = buildbot_utils.GetTrybotImage(
124 self._chromeos_root,
125 self._build,
126 self._patches,
127 description,
128 other_flags=['--hwtest'],
129 build_toolchain=True)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700130 if len(trybot_image) == 0:
131 self._l.LogError('Unable to find trybot_image for %s!' % description)
132 return 1
133
134 if os.getlogin() == ROLE_ACCOUNT:
135 self._FinishSetup()
136
137 self._TestImages(trybot_image)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700138 return 0
139
Caroline Ticea12e9742016-09-08 13:35:02 -0700140
Caroline Tice314ea562016-06-24 15:59:01 -0700141def SendEmail(start_board, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -0700142 """Send out the test results for all the boards."""
Caroline Ticea12e9742016-09-08 13:35:02 -0700143 results = ''
Yunlian Jiangc5713372016-06-15 11:37:50 -0700144 for i in range(len(TEST_BOARD)):
145 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
Caroline Ticed00ad412016-07-02 18:00:18 -0700146 f = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700147 if not os.path.exists(f):
148 continue
149 results += board
150 results += '\n'
151 file_name = os.path.join(VALIDATION_RESULT_DIR, f)
152 with open(file_name, 'r') as readin:
153 read_data = readin.read()
154 results += read_data
155
Caroline Ticea12e9742016-09-08 13:35:02 -0700156 output = os.path.join(VALIDATION_RESULT_DIR, compiler, 'result')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700157 with open(output, 'w') as out:
158 out.write(results)
159
160 ce = command_executer.GetCommandExecuter()
161 if os.path.exists(os.path.expanduser(MAIL_PROGRAM)):
Caroline Tice314ea562016-06-24 15:59:01 -0700162 email_title = '%s validation test results' % compiler
Yunlian Jiangc5713372016-06-15 11:37:50 -0700163 command = ('cat %s | %s -s "%s" -team' %
164 (output, MAIL_PROGRAM, email_title))
165 ce.RunCommand(command)
166
167
168def Main(argv):
169 """The main function."""
170
171 # Common initializations
172 command_executer.InitCommandExecuter()
173 parser = argparse.ArgumentParser()
Caroline Ticea12e9742016-09-08 13:35:02 -0700174 parser.add_argument(
175 '--chromeos_root',
176 dest='chromeos_root',
177 help='The chromeos root from which to run tests.')
178 parser.add_argument(
179 '--weekday',
180 default='',
181 dest='weekday',
182 help='The day of the week for which to run tests.')
183 parser.add_argument(
184 '--board', default='', dest='board', help='The board to test.')
185 parser.add_argument(
186 '--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 parser.add_argument(
192 '--compiler',
193 dest='compiler',
194 help='Which compiler (llvm or gcc) to use for '
195 'testing.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700196
197 options = parser.parse_args(argv[1:])
198 if not options.chromeos_root:
199 print('Please specify the ChromeOS root directory.')
200 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700201 if not options.compiler:
202 print('Please specify which compiler to test (gcc or llvm).')
203 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700204 if options.patches:
205 patches = options.patches
Caroline Tice314ea562016-06-24 15:59:01 -0700206 elif options.compiler == 'llvm':
Yunlian Jiangc5713372016-06-15 11:37:50 -0700207 patches = USE_LLVM_PATCH
208
209 if options.board:
210 fv = ToolchainVerifier(options.board, options.chromeos_root,
Caroline Tice314ea562016-06-24 15:59:01 -0700211 options.weekday, patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700212 return fv.Doall()
213
214 today = datetime.date.today()
215 delta = today - START_DATE
216 days = delta.days
217
218 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
219 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700220 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700221 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
222 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
223 patches, options.compiler)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700224 fv.DoAll()
225 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700226 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700227 with open(logfile, 'w') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700228 f.write('Verifier got an exception, please check the log.\n')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700229
Caroline Tice314ea562016-06-24 15:59:01 -0700230 SendEmail(start_board, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700231
Caroline Ticea12e9742016-09-08 13:35:02 -0700232
Yunlian Jiangc5713372016-06-15 11:37:50 -0700233if __name__ == '__main__':
234 retval = Main(sys.argv)
235 sys.exit(retval)