blob: dd88b5bd6329869799a93b6ec62e5323ccb90228 [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 Gupta5ef88e52017-04-28 16:16:19 -070036TEST_PER_DAY = 3
Caroline Tice09cacd02017-08-11 13:02:29 -070037
38# Information about Rotating Boards
39# 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# eve x86_64 poppy kabylake-y 4.4.79
45# gale armv7 3.18
46# kevin armv7 gru rockchip-3399 4.4.79
47# lakitu x86_64 4.4.79
48# link x86_64 ivybridge ivybridge 3.8.11
49# lumpy x86_64 -- sandybridge 3.8.11
50# nyan_big armv7 nyan tegra 3.10.18
51# peach_pit armv7 peach exynos-5420 3.8.11
52# peppy x86_64 slippy haswell 3.8.11
53# reef x86_64 reef apollo lake 4.4.79
54# sentry x86_64 kunimitsu skylake-u 3.18
55# squawks x86_64 rambi baytrail 4.4.79
56# terra x86_64 strago braswell 3.18
57# whirlwind armv7 3.14
58
Yunlian Jiangc5713372016-06-15 11:37:50 -070059TEST_BOARD = [
Caroline Tice09cacd02017-08-11 13:02:29 -070060 'caroline',
61 'daisy',
62 'eve',
63 'gale',
64 'kevin',
Caroline Tice856bc6c2017-06-29 16:21:43 -070065 'lakitu',
Caroline Tice09cacd02017-08-11 13:02:29 -070066 'link',
67 'lumpy',
68 'nyan_big',
69 'peach_pit',
70 'peppy',
71 'reef',
72 'sentry',
73 'squawks',
74 'terra',
Caroline Tice856bc6c2017-06-29 16:21:43 -070075 'whirlwind',
Caroline Ticea12e9742016-09-08 13:35:02 -070076]
77
Yunlian Jiangc5713372016-06-15 11:37:50 -070078
79class ToolchainVerifier(object):
80 """Class for the toolchain verifier."""
81
Caroline Ticea12e9742016-09-08 13:35:02 -070082 def __init__(self, board, chromeos_root, weekday, patches, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -070083 self._board = board
84 self._chromeos_root = chromeos_root
85 self._base_dir = os.getcwd()
86 self._ce = command_executer.GetCommandExecuter()
87 self._l = logger.GetLogger()
Caroline Tice314ea562016-06-24 15:59:01 -070088 self._compiler = compiler
Caroline Tice4bd70462016-10-05 15:41:13 -070089 self._build = '%s-%s-toolchain' % (board, compiler)
Caroline Ticede600772016-10-18 15:27:51 -070090 self._patches = patches.split(',') if patches else []
Yunlian Jiangc5713372016-06-15 11:37:50 -070091 self._patches_string = '_'.join(str(p) for p in self._patches)
92
93 if not weekday:
94 self._weekday = time.strftime('%a')
95 else:
96 self._weekday = weekday
Caroline Ticed00ad412016-07-02 18:00:18 -070097 self._reports = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -070098
99 def _FinishSetup(self):
100 """Make sure testing_rsa file is properly set up."""
101 # Fix protections on ssh key
102 command = ('chmod 600 /var/cache/chromeos-cache/distfiles/target'
103 '/chrome-src-internal/src/third_party/chromite/ssh_keys'
104 '/testing_rsa')
105 ret_val = self._ce.ChrootRunCommand(self._chromeos_root, command)
106 if ret_val != 0:
107 raise RuntimeError('chmod for testing_rsa failed')
108
Yunlian Jiangc5713372016-06-15 11:37:50 -0700109 def DoAll(self):
110 """Main function inside ToolchainComparator class.
111
112 Launch trybot, get image names, create crosperf experiment file, run
113 crosperf, and copy images into seven-day report directories.
114 """
115 date_str = datetime.date.today()
116 description = 'master_%s_%s_%s' % (self._patches_string, self._build,
117 date_str)
Caroline Tice09741972016-11-02 15:22:28 -0700118 _ = buildbot_utils.GetTrybotImage(
Caroline Tice1ba6d572016-10-10 11:31:54 -0700119 self._chromeos_root,
120 self._build,
121 self._patches,
122 description,
Ting-Yuan Huang4f59a622017-08-16 12:32:56 -0700123 tryjob_flags=['--hwtest'],
Caroline Tice09741972016-11-02 15:22:28 -0700124 async=True)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700125
Yunlian Jiangc5713372016-06-15 11:37:50 -0700126 return 0
127
Manoj Guptad575b8a2017-03-08 10:51:28 -0800128
Yunlian Jiangc5713372016-06-15 11:37:50 -0700129def 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',
Caroline Ticede600772016-10-18 15:27:51 -0700149 default='',
Caroline Ticea12e9742016-09-08 13:35:02 -0700150 help='The patches to use for the testing, '
151 "seprate the patch numbers with ',' "
152 'for more than one patches.')
153 parser.add_argument(
154 '--compiler',
155 dest='compiler',
Caroline Tice4bd70462016-10-05 15:41:13 -0700156 help='Which compiler (llvm, llvm-next or gcc) to use for '
Caroline Ticea12e9742016-09-08 13:35:02 -0700157 'testing.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700158
159 options = parser.parse_args(argv[1:])
160 if not options.chromeos_root:
161 print('Please specify the ChromeOS root directory.')
162 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700163 if not options.compiler:
Caroline Tice4bd70462016-10-05 15:41:13 -0700164 print('Please specify which compiler to test (gcc, llvm, or llvm-next).')
Caroline Tice314ea562016-06-24 15:59:01 -0700165 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700166
167 if options.board:
168 fv = ToolchainVerifier(options.board, options.chromeos_root,
Manoj Guptad575b8a2017-03-08 10:51:28 -0800169 options.weekday, options.patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700170 return fv.Doall()
171
172 today = datetime.date.today()
173 delta = today - START_DATE
174 days = delta.days
175
176 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
177 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700178 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700179 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
180 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
Manoj Gupta86fe1ed2017-03-09 10:37:35 -0800181 options.patches, options.compiler)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700182 fv.DoAll()
183 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700184 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700185 with open(logfile, 'w') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700186 f.write('Verifier got an exception, please check the log.\n')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700187
Caroline Ticea12e9742016-09-08 13:35:02 -0700188
Yunlian Jiangc5713372016-06-15 11:37:50 -0700189if __name__ == '__main__':
190 retval = Main(sys.argv)
191 sys.exit(retval)