blob: 968c67b86e8e406a901233e75b50a7e61af3d3fd [file] [log] [blame]
Zhizhou Yang81d651f2020-02-10 16:51:20 -08001#!/usr/bin/env python3
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
Manoj Gupta1f0302d2019-04-19 10:53:43 -070042# Board Arch Reference Platform Kernel
43# Board Version
44# ------------ ------- ------------ ------------- -------
Manoj Gupta1f0302d2019-04-19 10:53:43 -070045# atlas x86_64 poppy kabylake-y 4.4.*
46# cave x86_64 glados skylake-y 3.18
47# coral x86_64 reef apollo lake 4.4.*
48# cyan x86_64 strago braswell 3.18
Manoj Gupta1f0302d2019-04-19 10:53:43 -070049# elm aarch64 oak mediatek-8173 3.18 arm32 userspace
50# eve x86_64 poppy kabylake-u/r 4.4.*
51# gale armv7 3.18
52# grunt x86_64 grunt stoney ridge 4.14.*
Zhizhou Yang64a2ef02019-08-20 16:20:42 -070053# fizz-moblab x86_64 4.4
Manoj Gupta1f0302d2019-04-19 10:53:43 -070054# kevin aarch64 gru rockchip-3399 4.4.* arm32 userspace
55# kevin64 aarch64 gru rockchip-3399 4.4.* arm64 userspace
56# lakitu x86_64 4.4.*
Zhizhou Yang739e6ab2019-06-28 10:23:09 -070057# nyan_kitty armv7 nyan tegra 3.10.18
58# octopus x86_64 octopus GLK 4.14.*
Tiancong Wang9506af12019-05-02 09:26:48 -070059# sentry x86_64 kunimitsu skylake-u 3.18
Manoj Gupta1f0302d2019-04-19 10:53:43 -070060# tidus x86_64 auron broadwell 3.14
61# veyron_mighty armv7 veyron-pinky rockchip-3288 3.14
62# whirlwind armv7 3.14
Zhizhou Yang739e6ab2019-06-28 10:23:09 -070063# winky x86_64 rambi baytrail 4.4.*
Caroline Tice09cacd02017-08-11 13:02:29 -070064
Yunlian Jiangc5713372016-06-15 11:37:50 -070065TEST_BOARD = [
Manoj Gupta1f0302d2019-04-19 10:53:43 -070066 'atlas',
Manoj Gupta26391db2018-03-15 11:14:18 -070067 'cave',
Manoj Gupta1f0302d2019-04-19 10:53:43 -070068 'coral',
69 'cyan',
Manoj Gupta1f0302d2019-04-19 10:53:43 -070070 'elm',
71 # 'eve', tested by amd64-llvm-next-toolchain builder.
Caroline Tice09cacd02017-08-11 13:02:29 -070072 'gale',
Manoj Guptae8ba0542018-04-18 13:58:43 -070073 'grunt',
Zhizhou Yang64a2ef02019-08-20 16:20:42 -070074 'fizz-moblab',
Manoj Gupta1f0302d2019-04-19 10:53:43 -070075 # 'kevin', tested by arm64-llvm-next-toolchain builder.
Manoj Guptacd2cf152019-03-01 10:50:59 -080076 'kevin64',
Caroline Tice856bc6c2017-06-29 16:21:43 -070077 'lakitu',
Zhizhou Yang739e6ab2019-06-28 10:23:09 -070078 'nyan_kitty',
79 'octopus',
Tiancong Wang9506af12019-05-02 09:26:48 -070080 'sentry',
Manoj Gupta1f0302d2019-04-19 10:53:43 -070081 'tidus',
82 # 'veyron_mighty', tested by arm-llvm-next-toolchain builder.
Caroline Tice856bc6c2017-06-29 16:21:43 -070083 'whirlwind',
Zhizhou Yang739e6ab2019-06-28 10:23:09 -070084 'winky',
Caroline Ticea12e9742016-09-08 13:35:02 -070085]
86
Yunlian Jiangc5713372016-06-15 11:37:50 -070087
88class ToolchainVerifier(object):
89 """Class for the toolchain verifier."""
90
Caroline Ticea12e9742016-09-08 13:35:02 -070091 def __init__(self, board, chromeos_root, weekday, patches, compiler):
Yunlian Jiangc5713372016-06-15 11:37:50 -070092 self._board = board
93 self._chromeos_root = chromeos_root
94 self._base_dir = os.getcwd()
95 self._ce = command_executer.GetCommandExecuter()
96 self._l = logger.GetLogger()
Caroline Tice314ea562016-06-24 15:59:01 -070097 self._compiler = compiler
Yunlian Jiangbddbcd32017-11-27 10:59:30 -080098 self._build = '%s-%s-toolchain-tryjob' % (board, compiler)
Caroline Ticede600772016-10-18 15:27:51 -070099 self._patches = patches.split(',') if patches else []
Yunlian Jiangc5713372016-06-15 11:37:50 -0700100 self._patches_string = '_'.join(str(p) for p in self._patches)
101
102 if not weekday:
103 self._weekday = time.strftime('%a')
104 else:
105 self._weekday = weekday
Caroline Ticed00ad412016-07-02 18:00:18 -0700106 self._reports = os.path.join(VALIDATION_RESULT_DIR, compiler, board)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700107
Ting-Yuan Huang6a9a98a2018-03-07 17:35:13 -0800108 def DoAll(self):
Yunlian Jiangc5713372016-06-15 11:37:50 -0700109 """Main function inside ToolchainComparator class.
110
111 Launch trybot, get image names, create crosperf experiment file, run
112 crosperf, and copy images into seven-day report directories.
113 """
Caroline Ticefeb442e2018-04-19 23:27:38 -0700114 buildbucket_id, _ = buildbot_utils.GetTrybotImage(
Ting-Yuan Huang6a9a98a2018-03-07 17:35:13 -0800115 self._chromeos_root,
116 self._build,
117 self._patches,
Jian Cai9d576402019-06-17 20:49:35 +0000118 tryjob_flags=['--hwtest'],
Zhizhou Yang28417332020-01-09 11:12:14 -0800119 asynchronous=True)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700120
Caroline Ticefeb442e2018-04-19 23:27:38 -0700121 return buildbucket_id
122
123
124def WriteRotatingReportsData(results_dict, date):
125 """Write data for waterfall report."""
126 fname = '%d-%02d-%02d.builds' % (date.year, date.month, date.day)
127 filename = os.path.join(DATA_DIR, 'rotating-builders', fname)
Zhizhou Yang81d651f2020-02-10 16:51:20 -0800128 with open(filename, 'w', encoding='utf-8') as out_file:
Caroline Ticefeb442e2018-04-19 23:27:38 -0700129 for board in results_dict.keys():
130 buildbucket_id = results_dict[board]
131 out_file.write('%s,%s\n' % (buildbucket_id, board))
Yunlian Jiangc5713372016-06-15 11:37:50 -0700132
Manoj Guptad575b8a2017-03-08 10:51:28 -0800133
Yunlian Jiangc5713372016-06-15 11:37:50 -0700134def Main(argv):
135 """The main function."""
136
137 # Common initializations
138 command_executer.InitCommandExecuter()
139 parser = argparse.ArgumentParser()
Caroline Ticea12e9742016-09-08 13:35:02 -0700140 parser.add_argument(
141 '--chromeos_root',
142 dest='chromeos_root',
143 help='The chromeos root from which to run tests.')
144 parser.add_argument(
145 '--weekday',
146 default='',
147 dest='weekday',
148 help='The day of the week for which to run tests.')
149 parser.add_argument(
150 '--board', default='', dest='board', help='The board to test.')
151 parser.add_argument(
152 '--patch',
153 dest='patches',
Caroline Ticede600772016-10-18 15:27:51 -0700154 default='',
Caroline Ticea12e9742016-09-08 13:35:02 -0700155 help='The patches to use for the testing, '
156 "seprate the patch numbers with ',' "
157 'for more than one patches.')
158 parser.add_argument(
159 '--compiler',
160 dest='compiler',
Caroline Tice4bd70462016-10-05 15:41:13 -0700161 help='Which compiler (llvm, llvm-next or gcc) to use for '
Caroline Ticea12e9742016-09-08 13:35:02 -0700162 'testing.')
Yunlian Jiangc5713372016-06-15 11:37:50 -0700163
164 options = parser.parse_args(argv[1:])
165 if not options.chromeos_root:
166 print('Please specify the ChromeOS root directory.')
167 return 1
Caroline Tice314ea562016-06-24 15:59:01 -0700168 if not options.compiler:
Caroline Tice4bd70462016-10-05 15:41:13 -0700169 print('Please specify which compiler to test (gcc, llvm, or llvm-next).')
Caroline Tice314ea562016-06-24 15:59:01 -0700170 return 1
Yunlian Jiangc5713372016-06-15 11:37:50 -0700171
172 if options.board:
173 fv = ToolchainVerifier(options.board, options.chromeos_root,
Manoj Guptad575b8a2017-03-08 10:51:28 -0800174 options.weekday, options.patches, options.compiler)
Zhizhou Yang81d651f2020-02-10 16:51:20 -0800175 return fv.DoAll()
Yunlian Jiangc5713372016-06-15 11:37:50 -0700176
177 today = datetime.date.today()
178 delta = today - START_DATE
179 days = delta.days
180
181 start_board = (days * TEST_PER_DAY) % len(TEST_BOARD)
Caroline Ticefeb442e2018-04-19 23:27:38 -0700182 results_dict = dict()
Yunlian Jiangc5713372016-06-15 11:37:50 -0700183 for i in range(TEST_PER_DAY):
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700184 try:
Caroline Ticea12e9742016-09-08 13:35:02 -0700185 board = TEST_BOARD[(start_board + i) % len(TEST_BOARD)]
186 fv = ToolchainVerifier(board, options.chromeos_root, options.weekday,
Manoj Gupta86fe1ed2017-03-09 10:37:35 -0800187 options.patches, options.compiler)
Caroline Ticefeb442e2018-04-19 23:27:38 -0700188 buildbucket_id = fv.DoAll()
189 if buildbucket_id:
190 results_dict[board] = buildbucket_id
Yunlian Jiang54e72b32016-06-21 14:13:03 -0700191 except SystemExit:
Caroline Ticed00ad412016-07-02 18:00:18 -0700192 logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board)
Zhizhou Yang81d651f2020-02-10 16:51:20 -0800193 with open(logfile, 'w', encoding='utf-8') as f:
Caroline Ticea12e9742016-09-08 13:35:02 -0700194 f.write('Verifier got an exception, please check the log.\n')
Caroline Ticefeb442e2018-04-19 23:27:38 -0700195 WriteRotatingReportsData(results_dict, today)
Yunlian Jiangc5713372016-06-15 11:37:50 -0700196
Caroline Ticea12e9742016-09-08 13:35:02 -0700197
Yunlian Jiangc5713372016-06-15 11:37:50 -0700198if __name__ == '__main__':
199 retval = Main(sys.argv)
200 sys.exit(retval)