blob: 527db99ef47b5756a9690d307cb4b9cd4c654053 [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
Yunlian Jiangc5713372016-06-15 11:37:50 -070033TEST_BOARD = [
Manoj Guptad575b8a2017-03-08 10:51:28 -080034 'squawks', # x86_64, rambi (baytrail)
35 'terra', # x86_64, strago (braswell)
36 'lulu', # x86_64, auron (broadwell)
37 'peach_pit', # arm, peach (exynos-5420)
38 'peppy', # x86_64, slippy (haswell celeron)
39 'link', # x86_64, ivybridge (ivybridge)
40 'nyan_big', # arm, nyan (tegra)
41 'sentry', # x86_64, kunimitsu (skylake-u)
42 'chell', # x86_64, glados (skylake-y)
43 'daisy', # arm, daisy (exynos)
Manoj Gupta5ef88e52017-04-28 16:16:19 -070044 'caroline', # x86_64, glados (skylake-y)
Manoj Guptad575b8a2017-03-08 10:51:28 -080045 'kevin', # arm, gru (Rockchip)
Manoj Gupta5ef88e52017-04-28 16:16:19 -070046 'reef', # x86_64, reef (Apollo Lake)
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 Tice09741972016-11-02 15:22:28 -070090 _ = buildbot_utils.GetTrybotImage(
Caroline Tice1ba6d572016-10-10 11:31:54 -070091 self._chromeos_root,
92 self._build,
93 self._patches,
94 description,
Caroline Tice09741972016-11-02 15:22:28 -070095 other_flags=flags,
96 async=True)
Yunlian Jiangc5713372016-06-15 11:37:50 -070097
Yunlian Jiangc5713372016-06-15 11:37:50 -070098 return 0
99
Manoj Guptad575b8a2017-03-08 10:51:28 -0800100
Yunlian Jiangc5713372016-06-15 11:37:50 -0700101def Main(argv):
102 """The main function."""
103
104 # Common initializations
105 command_executer.InitCommandExecuter()
106 parser = argparse.ArgumentParser()
Caroline Ticea12e9742016-09-08 13:35:02 -0700107 parser.add_argument(
108 '--chromeos_root',
109 dest='chromeos_root',
110 help='The chromeos root from which to run tests.')
111 parser.add_argument(
112 '--weekday',
113 default='',
114 dest='weekday',
115 help='The day of the week for which to run tests.')
116 parser.add_argument(
117 '--board', default='', dest='board', help='The board to test.')
118 parser.add_argument(
119 '--patch',
120 dest='patches',
Caroline Ticede600772016-10-18 15:27:51 -0700121 default='',
Caroline Ticea12e9742016-09-08 13:35:02 -0700122 help='The patches to use for the testing, '
123 "seprate the patch numbers with ',' "
124 'for more than one patches.')
125 parser.add_argument(
126 '--compiler',
127 dest='compiler',
Caroline Tice4bd70462016-10-05 15:41:13 -0700128 help='Which compiler (llvm, llvm-next or gcc) to use for '
Caroline Ticea12e9742016-09-08 13:35:02 -0700129 'testing.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700130
131 options = parser.parse_args(argv[1:])
132 if not options.chromeos_root:
133 print('Please specify the ChromeOS root directory.')
134 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700135 if not options.compiler:
Caroline Tice4bd70462016-10-05 15:41:13 -0700136 print('Please specify which compiler to test (gcc, llvm, or llvm-next).')
Caroline Tice314ea562016-06-24 15:59:01 -0700137 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700138
139 if options.board:
140 fv = ToolchainVerifier(options.board, options.chromeos_root,
Manoj Guptad575b8a2017-03-08 10:51:28 -0800141 options.weekday, options.patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700142 return fv.Doall()
143
144 today = datetime.date.today()
145 delta = today - START_DATE
146 days = delta.days
147
148 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
149 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700150 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700151 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
152 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
Manoj Gupta86fe1ed2017-03-09 10:37:35 -0800153 options.patches, options.compiler)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700154 fv.DoAll()
155 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700156 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700157 with open(logfile, 'w') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700158 f.write('Verifier got an exception, please check the log.\n')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700159
Caroline Ticea12e9742016-09-08 13:35:02 -0700160
Yunlian Jiangc5713372016-06-15 11:37:50 -0700161if __name__ == '__main__':
162 retval = Main(sys.argv)
163 sys.exit(retval)