blob: 51413829880582c8d92244403ef60237dbcfb689 [file] [log] [blame]
Caroline Tice4bd70462016-10-05 15:41:13 -07001#!/usr/bin/env python2
Tiancong Wangcca93c32019-03-19 14:42:27 -07002# -*- coding: utf-8 -*-
Ting-Yuan Huang4f59a622017-08-16 12:32:56 -07003#
4# Copyright 2017 The Chromium OS Authors. All rights reserved.
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
Tiancong Wangcca93c32019-03-19 14:42:27 -07007
Yunlian Jiangc5713372016-06-15 11:37:50 -07008"""Script for running llvm validation tests on ChromeOS.
9
10This script launches a buildbot to build ChromeOS with the llvm on
11a particular board; then it finds and downloads the trybot image and the
12corresponding official image, and runs test for correctness.
13It then generates a report, emails it to the c-compiler-chrome, as
14well as copying the result into a directory.
15"""
16
17# Script to test different toolchains against ChromeOS benchmarks.
18
19from __future__ import print_function
20
21import argparse
22import datetime
23import os
24import sys
25import time
26
Caroline Ticea8af9a72016-07-20 12:52:59 -070027from cros_utils import command_executer
28from cros_utils import logger
Yunlian Jiangc5713372016-06-15 11:37:50 -070029
Caroline Ticea8af9a72016-07-20 12:52:59 -070030from cros_utils import buildbot_utils
Yunlian Jiangc5713372016-06-15 11:37:50 -070031
Yunlian Jiangc5713372016-06-15 11:37:50 -070032CROSTC_ROOT = '/usr/local/google/crostc'
33ROLE_ACCOUNT = 'mobiletc-prebuild'
34TOOLCHAIN_DIR = os.path.dirname(os.path.realpath(__file__))
35MAIL_PROGRAM = '~/var/bin/mail-sheriff'
36VALIDATION_RESULT_DIR = os.path.join(CROSTC_ROOT, 'validation_result')
37START_DATE = datetime.date(2016, 1, 1)
Manoj Guptadd8675b2018-01-25 10:59:06 -080038TEST_PER_DAY = 4
Caroline Ticefeb442e2018-04-19 23:27:38 -070039DATA_DIR = '/google/data/rw/users/mo/mobiletc-prebuild/waterfall-report-data/'
Caroline Tice09cacd02017-08-11 13:02:29 -070040
41# Information about Rotating Boards
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080042# Board Arch Reference Platform Kernel
43# Board Version
44# ------------ ------- ------------ ------------- -------
Manoj Gupta26391db2018-03-15 11:14:18 -070045# cave x86_64 glados skylake-y 3.18
Tiancong Wangcca93c32019-03-19 14:42:27 -070046# daisy_skate armv7 daisy exynos-5250 3.8.11
Manoj Guptacd2cf152019-03-01 10:50:59 -080047# elm aarch64 oak mediatek-8173 3.18 arm32 userspace
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080048# fizz x86_64 fizz kabylake-u/r 4.4.*
49# gale armv7 3.18
Manoj Guptae8ba0542018-04-18 13:58:43 -070050# grunt x86_64 grunt stoney ridge 4.14.*
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080051# guado_moblab x86_64 3.14
Manoj Guptacd2cf152019-03-01 10:50:59 -080052# kevin aarch64 gru rockchip-3399 4.4.* arm32 userspace
53# kevin64 aarch64 gru rockchip-3399 4.4.* arm64 userspace
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080054# lakitu x86_64 4.4.*
Manoj Gupta26391db2018-03-15 11:14:18 -070055# lars x86_64 kunimitsu skylake-u 3.18
Tiancong Wangcca93c32019-03-19 14:42:27 -070056# leon x86_64 slippy haswell 3.8.11
Manoj Gupta26391db2018-03-15 11:14:18 -070057# nautilus x86_64 poppy kabylake-y 4.4.*
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080058# nyan_big armv7 nyan tegra 3.10.18
59# peach_pit armv7 peach exynos-5420 3.8.11
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080060# samus x86_64 auron broadwell 3.14
Manoj Gupta26391db2018-03-15 11:14:18 -070061# snappy x86_64 reef apollo lake 4.4.*
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080062# swanky x86_64 rambi baytrail 4.4.*
63# terra x86_64 strago braswell 3.18
64# veyron_jaq armv7 veyron-pinky rockchip-3288 3.14
65# whirlwind armv7 3.14
Caroline Tice09cacd02017-08-11 13:02:29 -070066
Yunlian Jiangc5713372016-06-15 11:37:50 -070067TEST_BOARD = [
Manoj Gupta26391db2018-03-15 11:14:18 -070068 'cave',
Tiancong Wangcca93c32019-03-19 14:42:27 -070069 'daisy_skate',
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080070 # 'elm', tested by arm64-llvm-next-toolchain builder.
Manoj Gupta470bbf52018-01-23 09:54:28 -080071 'fizz',
Caroline Tice09cacd02017-08-11 13:02:29 -070072 'gale',
Manoj Guptae8ba0542018-04-18 13:58:43 -070073 'grunt',
Manoj Guptadd8675b2018-01-25 10:59:06 -080074 'guado_moblab',
Caroline Tice09cacd02017-08-11 13:02:29 -070075 'kevin',
Manoj Guptacd2cf152019-03-01 10:50:59 -080076 'kevin64',
Caroline Tice856bc6c2017-06-29 16:21:43 -070077 'lakitu',
Manoj Gupta26391db2018-03-15 11:14:18 -070078 'lars',
Tiancong Wangcca93c32019-03-19 14:42:27 -070079 'leon',
Manoj Gupta26391db2018-03-15 11:14:18 -070080 'nautilus',
Caroline Tice09cacd02017-08-11 13:02:29 -070081 'nyan_big',
82 'peach_pit',
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080083 # 'samus', tested by amd64-llvm-next-toolchain builder.
Manoj Gupta26391db2018-03-15 11:14:18 -070084 'snappy',
Manoj Guptaac5072d2017-09-29 10:51:20 -070085 'swanky',
Caroline Tice09cacd02017-08-11 13:02:29 -070086 'terra',
Rahul Chaudhryedcf3d32018-01-30 13:50:37 -080087 # 'veyron_jaq', tested by arm-llvm-next-toolchain builder.
Caroline Tice856bc6c2017-06-29 16:21:43 -070088 'whirlwind',
Caroline Ticea12e9742016-09-08 13:35:02 -070089]
90
Yunlian Jiangc5713372016-06-15 11:37:50 -070091
92class ToolchainVerifier(object):
93 """Class for the toolchain verifier."""
94
Caroline Ticea12e9742016-09-08 13:35:02 -070095 def __init__(self, board, chromeos_root, weekday, patches, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -070096 self._board = board
97 self._chromeos_root = chromeos_root
98 self._base_dir = os.getcwd()
99 self._ce = command_executer.GetCommandExecuter()
100 self._l = logger.GetLogger()
Caroline Tice314ea562016-06-24 15:59:01 -0700101 self._compiler = compiler
Yunlian Jiangbddbcd32017-11-27 10:59:30 -0800102 self._build = '%s-%s-toolchain-tryjob' % (board, compiler)
Caroline Ticede600772016-10-18 15:27:51 -0700103 self._patches = patches.split(',') if patches else []
Yunlian Jiangc5713372016-06-15 11:37:50 -0700104 self._patches_string = '_'.join(str(p) for p in self._patches)
105
106 if not weekday:
107 self._weekday = time.strftime('%a')
108 else:
109 self._weekday = weekday
Caroline Ticed00ad412016-07-02 18:00:18 -0700110 self._reports = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700111
Ting-Yuan Huang6a9a98a2018-03-07 17:35:13 -0800112 def DoAll(self):
Yunlian Jiangc5713372016-06-15 11:37:50 -0700113 """Main function inside ToolchainComparator class.
114
115 Launch trybot, get image names, create crosperf experiment file, run
116 crosperf, and copy images into seven-day report directories.
117 """
Caroline Ticefeb442e2018-04-19 23:27:38 -0700118 buildbucket_id, _ = buildbot_utils.GetTrybotImage(
Ting-Yuan Huang6a9a98a2018-03-07 17:35:13 -0800119 self._chromeos_root,
120 self._build,
121 self._patches,
Ting-Yuan Huang6a9a98a2018-03-07 17:35:13 -0800122 tryjob_flags=['--hwtest'],
123 async=True)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700124
Caroline Ticefeb442e2018-04-19 23:27:38 -0700125 return buildbucket_id
126
127
128def WriteRotatingReportsData(results_dict, date):
129 """Write data for waterfall report."""
130 fname = '%d-%02d-%02d.builds' % (date.year, date.month, date.day)
131 filename = os.path.join(DATA_DIR, 'rotating-builders', fname)
132 with open(filename, 'w') as out_file:
133 for board in results_dict.keys():
134 buildbucket_id = results_dict[board]
135 out_file.write('%s,%s\n' % (buildbucket_id, board))
Yunlian Jiangc5713372016-06-15 11:37:50 -0700136
Manoj Guptad575b8a2017-03-08 10:51:28 -0800137
Yunlian Jiangc5713372016-06-15 11:37:50 -0700138def Main(argv):
139 """The main function."""
140
141 # Common initializations
142 command_executer.InitCommandExecuter()
143 parser = argparse.ArgumentParser()
Caroline Ticea12e9742016-09-08 13:35:02 -0700144 parser.add_argument(
145 '--chromeos_root',
146 dest='chromeos_root',
147 help='The chromeos root from which to run tests.')
148 parser.add_argument(
149 '--weekday',
150 default='',
151 dest='weekday',
152 help='The day of the week for which to run tests.')
153 parser.add_argument(
154 '--board', default='', dest='board', help='The board to test.')
155 parser.add_argument(
156 '--patch',
157 dest='patches',
Caroline Ticede600772016-10-18 15:27:51 -0700158 default='',
Caroline Ticea12e9742016-09-08 13:35:02 -0700159 help='The patches to use for the testing, '
160 "seprate the patch numbers with ',' "
161 'for more than one patches.')
162 parser.add_argument(
163 '--compiler',
164 dest='compiler',
Caroline Tice4bd70462016-10-05 15:41:13 -0700165 help='Which compiler (llvm, llvm-next or gcc) to use for '
Caroline Ticea12e9742016-09-08 13:35:02 -0700166 'testing.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700167
168 options = parser.parse_args(argv[1:])
169 if not options.chromeos_root:
170 print('Please specify the ChromeOS root directory.')
171 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700172 if not options.compiler:
Caroline Tice4bd70462016-10-05 15:41:13 -0700173 print('Please specify which compiler to test (gcc, llvm, or llvm-next).')
Caroline Tice314ea562016-06-24 15:59:01 -0700174 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700175
176 if options.board:
177 fv = ToolchainVerifier(options.board, options.chromeos_root,
Manoj Guptad575b8a2017-03-08 10:51:28 -0800178 options.weekday, options.patches, options.compiler)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700179 return fv.Doall()
180
181 today = datetime.date.today()
182 delta = today - START_DATE
183 days = delta.days
184
185 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
Caroline Ticefeb442e2018-04-19 23:27:38 -0700186 results_dict = dict()
Yunlian Jiangc5713372016-06-15 11:37:50 -0700187 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700188 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700189 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
190 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
Manoj Gupta86fe1ed2017-03-09 10:37:35 -0800191 options.patches, options.compiler)
Caroline Ticefeb442e2018-04-19 23:27:38 -0700192 buildbucket_id = fv.DoAll()
193 if buildbucket_id:
194 results_dict[board] = buildbucket_id
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700195 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700196 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700197 with open(logfile, 'w') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700198 f.write('Verifier got an exception, please check the log.\n')
Caroline Ticefeb442e2018-04-19 23:27:38 -0700199 WriteRotatingReportsData(results_dict, today)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700200
Caroline Ticea12e9742016-09-08 13:35:02 -0700201
Yunlian Jiangc5713372016-06-15 11:37:50 -0700202if __name__ == '__main__':
203 retval = Main(sys.argv)
204 sys.exit(retval)