blob: 397602badeddc5ed4320dabec2927579fa83302b [file] [log] [blame]
Caroline Tice4bd70462016-10-05 15:41:13 -07001#!/usr/bin/env python2
Ting-Yuan Huang4f59a622017-08-16 12:32:56 -07002#
3# Copyright 2017 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
Yunlian Jiangc5713372016-06-15 11:37:50 -07006"""Script for running llvm validation tests on ChromeOS.
7
8This script launches a buildbot to build ChromeOS with the llvm on
9a particular board; then it finds and downloads the trybot image and the
10corresponding official image, and runs test for correctness.
11It then generates a report, emails it to the c-compiler-chrome, as
12well as copying the result into a directory.
13"""
14
15# Script to test different toolchains against ChromeOS benchmarks.
16
17from __future__ import print_function
18
19import argparse
20import datetime
21import os
22import sys
23import time
24
Caroline Ticea8af9a72016-07-20 12:52:59 -070025from cros_utils import command_executer
26from cros_utils import logger
Yunlian Jiangc5713372016-06-15 11:37:50 -070027
Caroline Ticea8af9a72016-07-20 12:52:59 -070028from cros_utils import buildbot_utils
Yunlian Jiangc5713372016-06-15 11:37:50 -070029
Yunlian Jiangc5713372016-06-15 11:37:50 -070030CROSTC_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)
Manoj Guptadd8675b2018-01-25 10:59:06 -080036TEST_PER_DAY = 4
Caroline Tice09cacd02017-08-11 13:02:29 -070037
38# Information about Rotating Boards
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080039# Board Arch Reference Platform Kernel
40# Board Version
41# ------------ ------- ------------ ------------- -------
42# caroline x86_64 glados skylake-y 3.18
43# daisy armv7 daisy exynos-5250 3.8.11
44# elm aarch64 oak mediatek-8173 3.18
45# eve x86_64 poppy kabylake-y 4.4.*
46# fizz x86_64 fizz kabylake-u/r 4.4.*
47# gale armv7 3.18
48# guado_moblab x86_64 3.14
49# kahlee x86_64 kahlee stoney ridge 4.14.*
50# kevin aarch64 gru rockchip-3399 4.4.*
51# lakitu x86_64 4.4.*
52# link x86_64 ivybridge ivybridge 3.8.11
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080053# nyan_big armv7 nyan tegra 3.10.18
54# peach_pit armv7 peach exynos-5420 3.8.11
55# peppy x86_64 slippy haswell 3.8.11
56# pyro x86_64 reef apollo lake 4.4.*
57# samus x86_64 auron broadwell 3.14
58# sentry x86_64 kunimitsu skylake-u 3.18
59# swanky x86_64 rambi baytrail 4.4.*
60# terra x86_64 strago braswell 3.18
61# veyron_jaq armv7 veyron-pinky rockchip-3288 3.14
62# whirlwind armv7 3.14
63# zoombini x86_64 zoombini cannonlake-y 4.14.*
Caroline Tice09cacd02017-08-11 13:02:29 -070064
Yunlian Jiangc5713372016-06-15 11:37:50 -070065TEST_BOARD = [
Caroline Tice09cacd02017-08-11 13:02:29 -070066 'caroline',
67 'daisy',
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080068 # 'elm', tested by arm64-llvm-next-toolchain builder.
Caroline Tice09cacd02017-08-11 13:02:29 -070069 'eve',
Manoj Gupta470bbf52018-01-23 09:54:28 -080070 'fizz',
Caroline Tice09cacd02017-08-11 13:02:29 -070071 'gale',
Manoj Guptadd8675b2018-01-25 10:59:06 -080072 'guado_moblab',
Manoj Guptafc7d1e62018-01-16 16:21:18 -080073 'kahlee',
Caroline Tice09cacd02017-08-11 13:02:29 -070074 'kevin',
Caroline Tice856bc6c2017-06-29 16:21:43 -070075 'lakitu',
Caroline Tice09cacd02017-08-11 13:02:29 -070076 'link',
Caroline Tice09cacd02017-08-11 13:02:29 -070077 'nyan_big',
78 'peach_pit',
79 'peppy',
Manoj Guptaac5072d2017-09-29 10:51:20 -070080 'pyro',
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080081 # 'samus', tested by amd64-llvm-next-toolchain builder.
Caroline Tice09cacd02017-08-11 13:02:29 -070082 'sentry',
Manoj Guptaac5072d2017-09-29 10:51:20 -070083 'swanky',
Caroline Tice09cacd02017-08-11 13:02:29 -070084 'terra',
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080085 # 'veyron_jaq', tested by arm-llvm-next-toolchain builder.
Caroline Tice856bc6c2017-06-29 16:21:43 -070086 'whirlwind',
Manoj Gupta470bbf52018-01-23 09:54:28 -080087 'zoombini',
Caroline Ticea12e9742016-09-08 13:35:02 -070088]
89
Yunlian Jiangc5713372016-06-15 11:37:50 -070090
91class ToolchainVerifier(object):
92 """Class for the toolchain verifier."""
93
Caroline Ticea12e9742016-09-08 13:35:02 -070094 def __init__(self, board, chromeos_root, weekday, patches, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -070095 self._board = board
96 self._chromeos_root = chromeos_root
97 self._base_dir = os.getcwd()
98 self._ce = command_executer.GetCommandExecuter()
99 self._l = logger.GetLogger()
Caroline Tice314ea562016-06-24 15:59:01 -0700100 self._compiler = compiler
Yunlian Jiangbddbcd32017-11-27 10:59:30 -0800101 self._build = '%s-%s-toolchain-tryjob' % (board, compiler)
Caroline Ticede600772016-10-18 15:27:51 -0700102 self._patches = patches.split(',') if patches else []
Yunlian Jiangc5713372016-06-15 11:37:50 -0700103 self._patches_string = '_'.join(str(p) for p in self._patches)
104
105 if not weekday:
106 self._weekday = time.strftime('%a')
107 else:
108 self._weekday = weekday
Caroline Ticed00ad412016-07-02 18:00:18 -0700109 self._reports = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700110
111 def _FinishSetup(self):
112 """Make sure testing_rsa file is properly set up."""
113 # Fix protections on ssh key
114 command = ('chmod 600 /var/cache/chromeos-cache/distfiles/target'
115 '/chrome-src-internal/src/third_party/chromite/ssh_keys'
116 '/testing_rsa')
117 ret_val = self._ce.ChrootRunCommand(self._chromeos_root, command)
118 if ret_val != 0:
119 raise RuntimeError('chmod for testing_rsa failed')
120
Caroline Tice9c4003a2017-11-07 16:37:33 -0800121 def DoAll(self, crostc_dir):
Yunlian Jiangc5713372016-06-15 11:37:50 -0700122 """Main function inside ToolchainComparator class.
123
124 Launch trybot, get image names, create crosperf experiment file, run
125 crosperf, and copy images into seven-day report directories.
126 """
127 date_str = datetime.date.today()
128 description = 'master_%s_%s_%s' % (self._patches_string, self._build,
129 date_str)
Caroline Tice9c4003a2017-11-07 16:37:33 -0800130 if crostc_dir:
131 _ = buildbot_utils.GetTrybotImage(
132 self._chromeos_root,
133 self._build,
134 self._patches,
135 description,
136 tryjob_flags=['--hwtest'],
137 credentials_dir=crostc_dir,
138 async=True)
139 else:
140 _ = buildbot_utils.GetTrybotImage(
141 self._chromeos_root,
142 self._build,
143 self._patches,
144 description,
145 tryjob_flags=['--hwtest'],
146 async=True)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700147
Yunlian Jiangc5713372016-06-15 11:37:50 -0700148 return 0
149
Manoj Guptad575b8a2017-03-08 10:51:28 -0800150
Yunlian Jiangc5713372016-06-15 11:37:50 -0700151def Main(argv):
152 """The main function."""
153
154 # Common initializations
155 command_executer.InitCommandExecuter()
156 parser = argparse.ArgumentParser()
Caroline Ticea12e9742016-09-08 13:35:02 -0700157 parser.add_argument(
158 '--chromeos_root',
159 dest='chromeos_root',
160 help='The chromeos root from which to run tests.')
161 parser.add_argument(
162 '--weekday',
163 default='',
164 dest='weekday',
165 help='The day of the week for which to run tests.')
166 parser.add_argument(
167 '--board', default='', dest='board', help='The board to test.')
168 parser.add_argument(
169 '--patch',
170 dest='patches',
Caroline Ticede600772016-10-18 15:27:51 -0700171 default='',
Caroline Ticea12e9742016-09-08 13:35:02 -0700172 help='The patches to use for the testing, '
173 "seprate the patch numbers with ',' "
174 'for more than one patches.')
175 parser.add_argument(
176 '--compiler',
177 dest='compiler',
Caroline Tice4bd70462016-10-05 15:41:13 -0700178 help='Which compiler (llvm, llvm-next or gcc) to use for '
Caroline Ticea12e9742016-09-08 13:35:02 -0700179 'testing.')
Caroline Tice9c4003a2017-11-07 16:37:33 -0800180 parser.add_argument(
181 '--crostc_dir',
182 dest='crostc_dir',
183 help='Path to the directory containing the '
184 'chromeos-toolchain-credentials.json file; normally in the '
185 'crostc repo.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700186
187 options = parser.parse_args(argv[1:])
188 if not options.chromeos_root:
189 print('Please specify the ChromeOS root directory.')
190 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700191 if not options.compiler:
Caroline Tice4bd70462016-10-05 15:41:13 -0700192 print('Please specify which compiler to test (gcc, llvm, or llvm-next).')
Caroline Tice314ea562016-06-24 15:59:01 -0700193 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700194
195 if options.board:
196 fv = ToolchainVerifier(options.board, options.chromeos_root,
Manoj Guptad575b8a2017-03-08 10:51:28 -0800197 options.weekday, options.patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700198 return fv.Doall()
199
200 today = datetime.date.today()
201 delta = today - START_DATE
202 days = delta.days
203
204 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
205 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700206 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700207 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
208 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
Manoj Gupta86fe1ed2017-03-09 10:37:35 -0800209 options.patches, options.compiler)
Caroline Tice9c4003a2017-11-07 16:37:33 -0800210 fv.DoAll(options.crostc_dir)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700211 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700212 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700213 with open(logfile, 'w') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700214 f.write('Verifier got an exception, please check the log.\n')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700215
Caroline Ticea12e9742016-09-08 13:35:02 -0700216
Yunlian Jiangc5713372016-06-15 11:37:50 -0700217if __name__ == '__main__':
218 retval = Main(sys.argv)
219 sys.exit(retval)