blob: dfb049940d0c02fb7d536b3b9af43d73f8dfca5a [file] [log] [blame]
Caroline Tice4bd70462016-10-05 15:41:13 -07001#!/usr/bin/env python2
Yunlian Jiangc5713372016-06-15 11:37:50 -07002"""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 'sentry',
44 'chell',
45 'nyan_big',
Caroline Tice4bd70462016-10-05 15:41:13 -070046 'daisy',
Caroline Ticea12e9742016-09-08 13:35:02 -070047]
48
Yunlian Jiangc5713372016-06-15 11:37:50 -070049
50class ToolchainVerifier(object):
51 """Class for the toolchain verifier."""
52
Caroline Ticea12e9742016-09-08 13:35:02 -070053 def __init__(self, board, chromeos_root, weekday, patches, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -070054 self._board = board
55 self._chromeos_root = chromeos_root
56 self._base_dir = os.getcwd()
57 self._ce = command_executer.GetCommandExecuter()
58 self._l = logger.GetLogger()
Caroline Tice314ea562016-06-24 15:59:01 -070059 self._compiler = compiler
Caroline Tice4bd70462016-10-05 15:41:13 -070060 self._build = '%s-%s-toolchain' % (board, compiler)
Caroline Ticede600772016-10-18 15:27:51 -070061 self._patches = patches.split(',') if patches else []
Yunlian Jiangc5713372016-06-15 11:37:50 -070062 self._patches_string = '_'.join(str(p) for p in self._patches)
63
64 if not weekday:
65 self._weekday = time.strftime('%a')
66 else:
67 self._weekday = weekday
Caroline Ticed00ad412016-07-02 18:00:18 -070068 self._reports = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -070069
70 def _FinishSetup(self):
71 """Make sure testing_rsa file is properly set up."""
72 # Fix protections on ssh key
73 command = ('chmod 600 /var/cache/chromeos-cache/distfiles/target'
74 '/chrome-src-internal/src/third_party/chromite/ssh_keys'
75 '/testing_rsa')
76 ret_val = self._ce.ChrootRunCommand(self._chromeos_root, command)
77 if ret_val != 0:
78 raise RuntimeError('chmod for testing_rsa failed')
79
Yunlian Jiangc5713372016-06-15 11:37:50 -070080 def DoAll(self):
81 """Main function inside ToolchainComparator class.
82
83 Launch trybot, get image names, create crosperf experiment file, run
84 crosperf, and copy images into seven-day report directories.
85 """
Caroline Tice1ba6d572016-10-10 11:31:54 -070086 flags = ['--hwtest']
Yunlian Jiangc5713372016-06-15 11:37:50 -070087 date_str = datetime.date.today()
88 description = 'master_%s_%s_%s' % (self._patches_string, self._build,
89 date_str)
Caroline Tice1ba6d572016-10-10 11:31:54 -070090 trybot_image = buildbot_utils.GetTrybotImage(
91 self._chromeos_root,
92 self._build,
93 self._patches,
94 description,
95 other_flags=flags)
Yunlian Jiangc5713372016-06-15 11:37:50 -070096 if len(trybot_image) == 0:
97 self._l.LogError('Unable to find trybot_image for %s!' % description)
98 return 1
99
100 if os.getlogin() == ROLE_ACCOUNT:
101 self._FinishSetup()
102
Yunlian Jiangc5713372016-06-15 11:37:50 -0700103 return 0
104
Caroline Ticea12e9742016-09-08 13:35:02 -0700105
Caroline Tice314ea562016-06-24 15:59:01 -0700106def SendEmail(start_board, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -0700107 """Send out the test results for all the boards."""
Caroline Ticede600772016-10-18 15:27:51 -0700108
109 # This is no longer the correct way to get results. Until
110 # this is fixed, don't send any email at all.
111 return 0
112
Caroline Ticea12e9742016-09-08 13:35:02 -0700113 results = ''
Yunlian Jiangc5713372016-06-15 11:37:50 -0700114 for i in range(len(TEST_BOARD)):
115 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
Caroline Ticed00ad412016-07-02 18:00:18 -0700116 f = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700117 if not os.path.exists(f):
118 continue
119 results += board
120 results += '\n'
121 file_name = os.path.join(VALIDATION_RESULT_DIR, f)
122 with open(file_name, 'r') as readin:
123 read_data = readin.read()
124 results += read_data
125
Caroline Ticea12e9742016-09-08 13:35:02 -0700126 output = os.path.join(VALIDATION_RESULT_DIR, compiler, 'result')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700127 with open(output, 'w') as out:
128 out.write(results)
129
130 ce = command_executer.GetCommandExecuter()
131 if os.path.exists(os.path.expanduser(MAIL_PROGRAM)):
Caroline Tice314ea562016-06-24 15:59:01 -0700132 email_title = '%s validation test results' % compiler
Yunlian Jiangc5713372016-06-15 11:37:50 -0700133 command = ('cat %s | %s -s "%s" -team' %
134 (output, MAIL_PROGRAM, email_title))
135 ce.RunCommand(command)
136
137
138def Main(argv):
139 """The main function."""
140
141 # Common initializations
142 command_executer.InitCommandExecuter()
143 parser = argparse.ArgumentParser()
Caroline Ticea12e9742016-09-08 13:35:02 -0700144 parser.add_argument(
145 '--chromeos_root',
146 dest='chromeos_root',
147 help='The chromeos root from which to run tests.')
148 parser.add_argument(
149 '--weekday',
150 default='',
151 dest='weekday',
152 help='The day of the week for which to run tests.')
153 parser.add_argument(
154 '--board', default='', dest='board', help='The board to test.')
155 parser.add_argument(
156 '--patch',
157 dest='patches',
Caroline Ticede600772016-10-18 15:27:51 -0700158 default='',
Caroline Ticea12e9742016-09-08 13:35:02 -0700159 help='The patches to use for the testing, '
160 "seprate the patch numbers with ',' "
161 'for more than one patches.')
162 parser.add_argument(
163 '--compiler',
164 dest='compiler',
Caroline Tice4bd70462016-10-05 15:41:13 -0700165 help='Which compiler (llvm, llvm-next or gcc) to use for '
Caroline Ticea12e9742016-09-08 13:35:02 -0700166 'testing.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700167
168 options = parser.parse_args(argv[1:])
169 if not options.chromeos_root:
170 print('Please specify the ChromeOS root directory.')
171 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700172 if not options.compiler:
Caroline Tice4bd70462016-10-05 15:41:13 -0700173 print('Please specify which compiler to test (gcc, llvm, or llvm-next).')
Caroline Tice314ea562016-06-24 15:59:01 -0700174 return 1
Caroline Ticede600772016-10-18 15:27:51 -0700175 patches = options.patches
176 if not patches and options.compiler == 'llvm':
Yunlian Jiangc5713372016-06-15 11:37:50 -0700177 patches = USE_LLVM_PATCH
178
179 if options.board:
180 fv = ToolchainVerifier(options.board, options.chromeos_root,
Caroline Tice314ea562016-06-24 15:59:01 -0700181 options.weekday, patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700182 return fv.Doall()
183
184 today = datetime.date.today()
185 delta = today - START_DATE
186 days = delta.days
187
188 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
189 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700190 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700191 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
192 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
193 patches, options.compiler)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700194 fv.DoAll()
195 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700196 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700197 with open(logfile, 'w') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700198 f.write('Verifier got an exception, please check the log.\n')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700199
Caroline Tice314ea562016-06-24 15:59:01 -0700200 SendEmail(start_board, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700201
Caroline Ticea12e9742016-09-08 13:35:02 -0700202
Yunlian Jiangc5713372016-06-15 11:37:50 -0700203if __name__ == '__main__':
204 retval = Main(sys.argv)
205 sys.exit(retval)