blob: 69932e5303b235f7d93a0e127cdb8ac1a85c3ede [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)
Yunlian Jiangc5713372016-06-15 11:37:50 -070061 self._patches = patches.split(',')
62 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 """
86 date_str = datetime.date.today()
87 description = 'master_%s_%s_%s' % (self._patches_string, self._build,
88 date_str)
Caroline Tice4bd70462016-10-05 15:41:13 -070089 trybot_image = buildbot_utils.GetTrybotImage(self._chromeos_root,
90 self._build, self._patches,
91 description)
Yunlian Jiangc5713372016-06-15 11:37:50 -070092 if len(trybot_image) == 0:
93 self._l.LogError('Unable to find trybot_image for %s!' % description)
94 return 1
95
96 if os.getlogin() == ROLE_ACCOUNT:
97 self._FinishSetup()
98
Yunlian Jiangc5713372016-06-15 11:37:50 -070099 return 0
100
Caroline Ticea12e9742016-09-08 13:35:02 -0700101
Caroline Tice314ea562016-06-24 15:59:01 -0700102def SendEmail(start_board, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -0700103 """Send out the test results for all the boards."""
Caroline Ticea12e9742016-09-08 13:35:02 -0700104 results = ''
Yunlian Jiangc5713372016-06-15 11:37:50 -0700105 for i in range(len(TEST_BOARD)):
106 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
Caroline Ticed00ad412016-07-02 18:00:18 -0700107 f = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700108 if not os.path.exists(f):
109 continue
110 results += board
111 results += '\n'
112 file_name = os.path.join(VALIDATION_RESULT_DIR, f)
113 with open(file_name, 'r') as readin:
114 read_data = readin.read()
115 results += read_data
116
Caroline Ticea12e9742016-09-08 13:35:02 -0700117 output = os.path.join(VALIDATION_RESULT_DIR, compiler, 'result')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700118 with open(output, 'w') as out:
119 out.write(results)
120
121 ce = command_executer.GetCommandExecuter()
122 if os.path.exists(os.path.expanduser(MAIL_PROGRAM)):
Caroline Tice314ea562016-06-24 15:59:01 -0700123 email_title = '%s validation test results' % compiler
Yunlian Jiangc5713372016-06-15 11:37:50 -0700124 command = ('cat %s | %s -s "%s" -team' %
125 (output, MAIL_PROGRAM, email_title))
126 ce.RunCommand(command)
127
128
129def Main(argv):
130 """The main function."""
131
132 # Common initializations
133 command_executer.InitCommandExecuter()
134 parser = argparse.ArgumentParser()
Caroline Ticea12e9742016-09-08 13:35:02 -0700135 parser.add_argument(
136 '--chromeos_root',
137 dest='chromeos_root',
138 help='The chromeos root from which to run tests.')
139 parser.add_argument(
140 '--weekday',
141 default='',
142 dest='weekday',
143 help='The day of the week for which to run tests.')
144 parser.add_argument(
145 '--board', default='', dest='board', help='The board to test.')
146 parser.add_argument(
147 '--patch',
148 dest='patches',
149 help='The patches to use for the testing, '
150 "seprate the patch numbers with ',' "
151 'for more than one patches.')
152 parser.add_argument(
153 '--compiler',
154 dest='compiler',
Caroline Tice4bd70462016-10-05 15:41:13 -0700155 help='Which compiler (llvm, llvm-next or gcc) to use for '
Caroline Ticea12e9742016-09-08 13:35:02 -0700156 'testing.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700157
158 options = parser.parse_args(argv[1:])
159 if not options.chromeos_root:
160 print('Please specify the ChromeOS root directory.')
161 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700162 if not options.compiler:
Caroline Tice4bd70462016-10-05 15:41:13 -0700163 print('Please specify which compiler to test (gcc, llvm, or llvm-next).')
Caroline Tice314ea562016-06-24 15:59:01 -0700164 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700165 if options.patches:
166 patches = options.patches
Caroline Tice314ea562016-06-24 15:59:01 -0700167 elif options.compiler == 'llvm':
Yunlian Jiangc5713372016-06-15 11:37:50 -0700168 patches = USE_LLVM_PATCH
169
170 if options.board:
171 fv = ToolchainVerifier(options.board, options.chromeos_root,
Caroline Tice314ea562016-06-24 15:59:01 -0700172 options.weekday, patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700173 return fv.Doall()
174
175 today = datetime.date.today()
176 delta = today - START_DATE
177 days = delta.days
178
179 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
180 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700181 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700182 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
183 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
184 patches, options.compiler)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700185 fv.DoAll()
186 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700187 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700188 with open(logfile, 'w') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700189 f.write('Verifier got an exception, please check the log.\n')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700190
Caroline Tice314ea562016-06-24 15:59:01 -0700191 SendEmail(start_board, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700192
Caroline Ticea12e9742016-09-08 13:35:02 -0700193
Yunlian Jiangc5713372016-06-15 11:37:50 -0700194if __name__ == '__main__':
195 retval = Main(sys.argv)
196 sys.exit(retval)