blob: 2c8131e5c2caa0df230dc89f927e75d7a675e79b [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
29
30CROSTC_ROOT = '/usr/local/google/crostc'
31ROLE_ACCOUNT = 'mobiletc-prebuild'
32TOOLCHAIN_DIR = os.path.dirname(os.path.realpath(__file__))
33MAIL_PROGRAM = '~/var/bin/mail-sheriff'
34VALIDATION_RESULT_DIR = os.path.join(CROSTC_ROOT, 'validation_result')
35START_DATE = datetime.date(2016, 1, 1)
36TEST_PER_DAY = 2
37TEST_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
51TEST = [
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
63class ToolchainVerifier(object):
64 """Class for the toolchain verifier."""
65
66 def __init__(self,
67 board,
68 chromeos_root,
69 weekday,
Caroline Tice314ea562016-06-24 15:59:01 -070070 patches,
71 compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -070072 self._board = board
73 self._chromeos_root = chromeos_root
74 self._base_dir = os.getcwd()
75 self._ce = command_executer.GetCommandExecuter()
76 self._l = logger.GetLogger()
Caroline Tice314ea562016-06-24 15:59:01 -070077 self._compiler = compiler
Yunlian Jiangc5713372016-06-15 11:37:50 -070078 self._build = '%s-release' % board
79 self._patches = patches.split(',')
80 self._patches_string = '_'.join(str(p) for p in self._patches)
81
82 if not weekday:
83 self._weekday = time.strftime('%a')
84 else:
85 self._weekday = weekday
Caroline Ticed00ad412016-07-02 18:00:18 -070086 self._reports = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -070087
88 def _FinishSetup(self):
89 """Make sure testing_rsa file is properly set up."""
90 # Fix protections on ssh key
91 command = ('chmod 600 /var/cache/chromeos-cache/distfiles/target'
92 '/chrome-src-internal/src/third_party/chromite/ssh_keys'
93 '/testing_rsa')
94 ret_val = self._ce.ChrootRunCommand(self._chromeos_root, command)
95 if ret_val != 0:
96 raise RuntimeError('chmod for testing_rsa failed')
97
98 def _TestImages(self, image):
99 to_file = ''
100 for test in TEST:
101 command = ('test_that --board {board} :lab: suite:{test} '
102 '-i {image} --fast --autotest_dir '
103 '~/trunk/src/third_party/autotest/files '
104 '--web cautotest.corp.google.com'.format(
105 board=self._board,
106 test=test,
107 image=image))
108 ret_val = self._ce.ChrootRunCommand(self._chromeos_root, command)
109 timestamp = datetime.datetime.strftime(datetime.datetime.now(),
110 '%Y-%m-%d_%H:%M:%S')
111 if ret_val:
112 out = 'FAILED'
113 else:
114 out = ' '
115 to_file += out + ' ' + test + ' ' + timestamp + '\n'
116 with open(self._reports, 'w') as f:
117 f.write(to_file)
118
119 def DoAll(self):
120 """Main function inside ToolchainComparator class.
121
122 Launch trybot, get image names, create crosperf experiment file, run
123 crosperf, and copy images into seven-day report directories.
124 """
125 date_str = datetime.date.today()
126 description = 'master_%s_%s_%s' % (self._patches_string, self._build,
127 date_str)
128 trybot_image = buildbot_utils.GetTrybotImage(self._chromeos_root,
129 self._build,
130 self._patches,
131 description,
Caroline Tice0ded5152016-07-25 11:47:58 -0700132 other_flags=['--hwtest'],
Yunlian Jiangc5713372016-06-15 11:37:50 -0700133 build_toolchain=True)
134 if len(trybot_image) == 0:
135 self._l.LogError('Unable to find trybot_image for %s!' % description)
136 return 1
137
138 if os.getlogin() == ROLE_ACCOUNT:
139 self._FinishSetup()
140
141 self._TestImages(trybot_image)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700142 return 0
143
Caroline Tice314ea562016-06-24 15:59:01 -0700144def SendEmail(start_board, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -0700145 """Send out the test results for all the boards."""
146 results = ""
147 for i in range(len(TEST_BOARD)):
148 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
Caroline Ticed00ad412016-07-02 18:00:18 -0700149 f = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700150 if not os.path.exists(f):
151 continue
152 results += board
153 results += '\n'
154 file_name = os.path.join(VALIDATION_RESULT_DIR, f)
155 with open(file_name, 'r') as readin:
156 read_data = readin.read()
157 results += read_data
158
Caroline Ticed00ad412016-07-02 18:00:18 -0700159 output = os.path.join(VALIDATION_RESULT_DIR, compiler, "result")
Yunlian Jiangc5713372016-06-15 11:37:50 -0700160 with open(output, 'w') as out:
161 out.write(results)
162
163 ce = command_executer.GetCommandExecuter()
164 if os.path.exists(os.path.expanduser(MAIL_PROGRAM)):
Caroline Tice314ea562016-06-24 15:59:01 -0700165 email_title = '%s validation test results' % compiler
Yunlian Jiangc5713372016-06-15 11:37:50 -0700166 command = ('cat %s | %s -s "%s" -team' %
167 (output, MAIL_PROGRAM, email_title))
168 ce.RunCommand(command)
169
170
171def Main(argv):
172 """The main function."""
173
174 # Common initializations
175 command_executer.InitCommandExecuter()
176 parser = argparse.ArgumentParser()
177 parser.add_argument('--chromeos_root',
178 dest='chromeos_root',
179 help='The chromeos root from which to run tests.')
180 parser.add_argument('--weekday',
181 default='',
182 dest='weekday',
183 help='The day of the week for which to run tests.')
184 parser.add_argument('--board',
185 default='',
186 dest='board',
187 help='The board to test.')
188 parser.add_argument('--patch',
189 dest='patches',
190 help='The patches to use for the testing, '
191 "seprate the patch numbers with ',' "
192 'for more than one patches.')
Caroline Tice314ea562016-06-24 15:59:01 -0700193 parser.add_argument('--compiler',
194 dest='compiler',
195 help='Which compiler (llvm or gcc) to use for '
196 'testing.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700197
198 options = parser.parse_args(argv[1:])
199 if not options.chromeos_root:
200 print('Please specify the ChromeOS root directory.')
201 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700202 if not options.compiler:
203 print('Please specify which compiler to test (gcc or llvm).')
204 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700205 if options.patches:
206 patches = options.patches
Caroline Tice314ea562016-06-24 15:59:01 -0700207 elif options.compiler == 'llvm':
Yunlian Jiangc5713372016-06-15 11:37:50 -0700208 patches = USE_LLVM_PATCH
209
210 if options.board:
211 fv = ToolchainVerifier(options.board, options.chromeos_root,
Caroline Tice314ea562016-06-24 15:59:01 -0700212 options.weekday, patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700213 return fv.Doall()
214
215 today = datetime.date.today()
216 delta = today - START_DATE
217 days = delta.days
218
219 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
220 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700221 try:
222 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
223 fv = ToolchainVerifier(board, options.chromeos_root,
Caroline Tice314ea562016-06-24 15:59:01 -0700224 options.weekday, patches, options.compiler)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700225 fv.DoAll()
226 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700227 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700228 with open(logfile, 'w') as f:
229 f.write("Verifier got an exception, please check the log.\n")
Yunlian Jiangc5713372016-06-15 11:37:50 -0700230
Caroline Tice314ea562016-06-24 15:59:01 -0700231 SendEmail(start_board, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700232
233if __name__ == '__main__':
234 retval = Main(sys.argv)
235 sys.exit(retval)