blob: 8e6047829cb03f327f9380157faa4305ac45142b [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
Yunlian Jiangc5713372016-06-15 11:37:50 -070026CROSTC_ROOT = '/usr/local/google/crostc'
27ROLE_ACCOUNT = 'mobiletc-prebuild'
28TOOLCHAIN_DIR = os.path.dirname(os.path.realpath(__file__))
29MAIL_PROGRAM = '~/var/bin/mail-sheriff'
30VALIDATION_RESULT_DIR = os.path.join(CROSTC_ROOT, 'validation_result')
31START_DATE = datetime.date(2016, 1, 1)
Manoj Gupta5ef88e52017-04-28 16:16:19 -070032TEST_PER_DAY = 3
Caroline Tice09cacd02017-08-11 13:02:29 -070033
34# Information about Rotating Boards
35# Board Arch Reference Platform Kernel
36# Board Version
37# -------- ------ --------- ---------- -------
38# caroline x86_64 glados skylake-y 3.18
39# daisy armv7 daisy exynos-5250 3.8.11
40# eve x86_64 poppy kabylake-y 4.4.79
41# gale armv7 3.18
42# kevin armv7 gru rockchip-3399 4.4.79
43# lakitu x86_64 4.4.79
44# link x86_64 ivybridge ivybridge 3.8.11
45# lumpy x86_64 -- sandybridge 3.8.11
46# nyan_big armv7 nyan tegra 3.10.18
47# peach_pit armv7 peach exynos-5420 3.8.11
48# peppy x86_64 slippy haswell 3.8.11
49# reef x86_64 reef apollo lake 4.4.79
50# sentry x86_64 kunimitsu skylake-u 3.18
51# squawks x86_64 rambi baytrail 4.4.79
52# terra x86_64 strago braswell 3.18
53# whirlwind armv7 3.14
54
Yunlian Jiangc5713372016-06-15 11:37:50 -070055TEST_BOARD = [
Caroline Tice09cacd02017-08-11 13:02:29 -070056 'caroline',
57 'daisy',
58 'eve',
59 'gale',
60 'kevin',
Caroline Tice856bc6c2017-06-29 16:21:43 -070061 'lakitu',
Caroline Tice09cacd02017-08-11 13:02:29 -070062 'link',
63 'lumpy',
64 'nyan_big',
65 'peach_pit',
66 'peppy',
67 'reef',
68 'sentry',
69 'squawks',
70 'terra',
Caroline Tice856bc6c2017-06-29 16:21:43 -070071 'whirlwind',
Caroline Ticea12e9742016-09-08 13:35:02 -070072]
73
Yunlian Jiangc5713372016-06-15 11:37:50 -070074
75class ToolchainVerifier(object):
76 """Class for the toolchain verifier."""
77
Caroline Ticea12e9742016-09-08 13:35:02 -070078 def __init__(self, board, chromeos_root, weekday, patches, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -070079 self._board = board
80 self._chromeos_root = chromeos_root
81 self._base_dir = os.getcwd()
82 self._ce = command_executer.GetCommandExecuter()
83 self._l = logger.GetLogger()
Caroline Tice314ea562016-06-24 15:59:01 -070084 self._compiler = compiler
Caroline Tice4bd70462016-10-05 15:41:13 -070085 self._build = '%s-%s-toolchain' % (board, compiler)
Caroline Ticede600772016-10-18 15:27:51 -070086 self._patches = patches.split(',') if patches else []
Yunlian Jiangc5713372016-06-15 11:37:50 -070087 self._patches_string = '_'.join(str(p) for p in self._patches)
88
89 if not weekday:
90 self._weekday = time.strftime('%a')
91 else:
92 self._weekday = weekday
Caroline Ticed00ad412016-07-02 18:00:18 -070093 self._reports = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -070094
95 def _FinishSetup(self):
96 """Make sure testing_rsa file is properly set up."""
97 # Fix protections on ssh key
98 command = ('chmod 600 /var/cache/chromeos-cache/distfiles/target'
99 '/chrome-src-internal/src/third_party/chromite/ssh_keys'
100 '/testing_rsa')
101 ret_val = self._ce.ChrootRunCommand(self._chromeos_root, command)
102 if ret_val != 0:
103 raise RuntimeError('chmod for testing_rsa failed')
104
Yunlian Jiangc5713372016-06-15 11:37:50 -0700105 def DoAll(self):
106 """Main function inside ToolchainComparator class.
107
108 Launch trybot, get image names, create crosperf experiment file, run
109 crosperf, and copy images into seven-day report directories.
110 """
Caroline Tice1ba6d572016-10-10 11:31:54 -0700111 flags = ['--hwtest']
Yunlian Jiangc5713372016-06-15 11:37:50 -0700112 date_str = datetime.date.today()
113 description = 'master_%s_%s_%s' % (self._patches_string, self._build,
114 date_str)
Caroline Tice09741972016-11-02 15:22:28 -0700115 _ = buildbot_utils.GetTrybotImage(
Caroline Tice1ba6d572016-10-10 11:31:54 -0700116 self._chromeos_root,
117 self._build,
118 self._patches,
119 description,
Caroline Tice09741972016-11-02 15:22:28 -0700120 other_flags=flags,
121 async=True)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700122
Yunlian Jiangc5713372016-06-15 11:37:50 -0700123 return 0
124
Manoj Guptad575b8a2017-03-08 10:51:28 -0800125
Yunlian Jiangc5713372016-06-15 11:37:50 -0700126def Main(argv):
127 """The main function."""
128
129 # Common initializations
130 command_executer.InitCommandExecuter()
131 parser = argparse.ArgumentParser()
Caroline Ticea12e9742016-09-08 13:35:02 -0700132 parser.add_argument(
133 '--chromeos_root',
134 dest='chromeos_root',
135 help='The chromeos root from which to run tests.')
136 parser.add_argument(
137 '--weekday',
138 default='',
139 dest='weekday',
140 help='The day of the week for which to run tests.')
141 parser.add_argument(
142 '--board', default='', dest='board', help='The board to test.')
143 parser.add_argument(
144 '--patch',
145 dest='patches',
Caroline Ticede600772016-10-18 15:27:51 -0700146 default='',
Caroline Ticea12e9742016-09-08 13:35:02 -0700147 help='The patches to use for the testing, '
148 "seprate the patch numbers with ',' "
149 'for more than one patches.')
150 parser.add_argument(
151 '--compiler',
152 dest='compiler',
Caroline Tice4bd70462016-10-05 15:41:13 -0700153 help='Which compiler (llvm, llvm-next or gcc) to use for '
Caroline Ticea12e9742016-09-08 13:35:02 -0700154 'testing.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700155
156 options = parser.parse_args(argv[1:])
157 if not options.chromeos_root:
158 print('Please specify the ChromeOS root directory.')
159 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700160 if not options.compiler:
Caroline Tice4bd70462016-10-05 15:41:13 -0700161 print('Please specify which compiler to test (gcc, llvm, or llvm-next).')
Caroline Tice314ea562016-06-24 15:59:01 -0700162 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700163
164 if options.board:
165 fv = ToolchainVerifier(options.board, options.chromeos_root,
Manoj Guptad575b8a2017-03-08 10:51:28 -0800166 options.weekday, options.patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700167 return fv.Doall()
168
169 today = datetime.date.today()
170 delta = today - START_DATE
171 days = delta.days
172
173 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
174 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700175 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700176 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
177 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
Manoj Gupta86fe1ed2017-03-09 10:37:35 -0800178 options.patches, options.compiler)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700179 fv.DoAll()
180 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700181 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700182 with open(logfile, 'w') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700183 f.write('Verifier got an exception, please check the log.\n')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700184
Caroline Ticea12e9742016-09-08 13:35:02 -0700185
Yunlian Jiangc5713372016-06-15 11:37:50 -0700186if __name__ == '__main__':
187 retval = Main(sys.argv)
188 sys.exit(retval)