blob: ef7dd86c9e6d336a123d2cc56247a47b6b98342f [file] [log] [blame]
Andy Doan61b4d772012-04-24 10:03:28 -05001#!/usr/bin/python
2
Andy Doan61b4d772012-04-24 10:03:28 -05003import os
Andy Doan61b4d772012-04-24 10:03:28 -05004import sys
Fathi Boudrac14068b2012-12-06 17:42:11 +02005import json
Andy Doan61b4d772012-04-24 10:03:28 -05006import xmlrpclib
Fathi Boudrac14068b2012-12-06 17:42:11 +02007import re
Andy Doan61b4d772012-04-24 10:03:28 -05008
Fathi Boudra2486ee12013-06-28 13:39:07 +03009tests_timeout = {
10 'bluetooth-enablement': 7200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030011 'bootchart': 800,
12 'busybox': 800,
Fathi Boudra0ce7fd22013-10-16 19:51:24 +030013 'cyclictest': 90000,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030014 'device-tree': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030015 'e2eaudiotest': 7200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030016 'ethernet': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030017 'gatortests': 1200,
Andrew McDermott51bb8b92013-12-17 09:46:50 +000018 'jtreg-hotspot-compiler': 54000,
19 'jtreg-hotspot-gc': 14400,
20 'jtreg-hotspot-runtime': 14400,
Andrew McDermottec97cb52013-09-24 11:50:57 +010021 'jtreg-hotspot-sanity': 7200,
22 'jtreg-hotspot-serviceability': 7200,
23 'jtreg-hotspot-testlibrary': 7200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030024 'kernel-version': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030025 'leb-basic-graphics': 7200,
26 'ltp': 7200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030027 'mysql': 800,
Fathi Boudrac13926a2013-07-03 11:36:37 +030028 'network-tests-basic': 1200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030029 'perf': 800,
30 'phpinfo': 800,
31 'phpmysql': 800,
32 'pwrmgmt': 800,
33 'sdkhelloc': 800,
34 'sdkhellocxx': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030035 'smoke-tests-basic': 1200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030036 'toolchain': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030037 'wifi-enablement': 7200,
38}
39
Fathi Boudrac14068b2012-12-06 17:42:11 +020040tests_nano = [
41 'device-tree',
42 'gatortests',
Fathi Boudrac13926a2013-07-03 11:36:37 +030043 'network-tests-basic',
Fathi Boudrac14068b2012-12-06 17:42:11 +020044 'perf',
45 'pwrmgmt',
Fathi Boudra2486ee12013-06-28 13:39:07 +030046 'smoke-tests-basic',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030047]
Fathi Boudrac14068b2012-12-06 17:42:11 +020048
49tests_alip = [
50 'bootchart',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030051]
Fathi Boudrac14068b2012-12-06 17:42:11 +020052
53tests_desktop = [
54 'e2eaudiotest',
55 'bluetooth-enablement',
56 'wifi-enablement',
57 'leb-basic-graphics',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030058]
Fathi Boudrac14068b2012-12-06 17:42:11 +020059
Fathi Boudra60d0e972013-04-19 10:49:47 +030060tests_openembedded_minimal = [
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020061 'busybox',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020062 'device-tree',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020063 'ethernet',
64 'kernel-version',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020065 'perf',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020066 'toolchain',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030067]
Andy Doan61b4d772012-04-24 10:03:28 -050068
Fathi Boudra60d0e972013-04-19 10:49:47 +030069tests_openembedded_lamp = [
Fathi Boudra60d0e972013-04-19 10:49:47 +030070 'mysql',
71 'phpinfo',
72 'phpmysql',
73 'sdkhelloc',
74 'sdkhellocxx',
75]
76
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010077tests_openembedded_leg_java = [
Andrew McDermottedd9b8d2013-08-24 00:07:53 +010078 'openjdk8-sanity',
Andrew McDermott114e7662013-07-03 16:12:37 +010079 'mauve',
Andrew McDermotte47afbd2013-09-23 19:19:51 +010080 'jtreg-hotspot-compiler',
81 'jtreg-hotspot-gc',
82 'jtreg-hotspot-runtime',
83 'jtreg-hotspot-sanity',
84 'jtreg-hotspot-serviceability',
85 'jtreg-hotspot-testlibrary',
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010086]
87
Fathi Boudra8e4ce562012-12-08 14:35:17 +020088# Mapping device type - bundle stream
Andy Doan3462e4c2012-05-18 10:58:06 -050089DEVICE_STREAM = {
Fathi Boudra8b59a502013-01-18 10:20:04 +020090 'arndale': 'arndale',
Koen Kooid401dbd2013-10-11 12:48:01 +020091 'beaglebone-black': 'beaglebone',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020092 'beaglexm': 'beaglexm',
Fathi Boudrab97042a2013-04-04 17:49:22 +030093 'highbank': 'highbank',
Fathi Boudra66a6e9d2013-12-15 10:14:50 +020094 'midway': 'midway',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020095 'origen': 'leb-origen',
Andy Doan3462e4c2012-05-18 10:58:06 -050096 'panda': 'leb-panda-4430',
Paul Larson27308512012-08-17 14:09:05 -050097 'panda-es': 'leb-panda-es',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020098 'rtsm_foundation-armv8': 'vexpress64',
Fathi Boudra81c62312013-11-21 13:48:23 +020099 'rtsm_fvp_base-aemv8a': 'vexpress64',
100 'rtsm_fvp_base_cortex-a57x1-a53x1': 'vexpress64',
101 'rtsm_fvp_base_cortex-a57x4-a53x4': 'vexpress64',
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200102 'rtsm_ve-a15x1-a7x1': 'vexpress',
103 'rtsm_ve-a15x4-a7x4': 'vexpress',
Fathi Boudra81c62312013-11-21 13:48:23 +0200104 'rtsm_ve-armv8': 'vexpress64',
Andy Doan3462e4c2012-05-18 10:58:06 -0500105 'snowball_sd': 'leb-snowball',
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200106 'vexpress-a5': 'vexpress',
Fathi Boudra76551e52012-09-19 17:51:33 +0300107 'vexpress-a9': 'vexpress',
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200108 'vexpress-tc2': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -0500109}
110
Andy Doan61b4d772012-04-24 10:03:28 -0500111
112def obfuscate_credentials(s):
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300113 return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)
Andy Doan61b4d772012-04-24 10:03:28 -0500114
Fathi Boudrac14068b2012-12-06 17:42:11 +0200115
Andy Doan61b4d772012-04-24 10:03:28 -0500116def main():
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200117 """Script entry point: return some JSON based on calling args.
118 We should be called from Jenkins and expect the following to be defined:
119 $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
120 """
Andy Doan61b4d772012-04-24 10:03:28 -0500121
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200122 # CI base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300123 ci_base_url = 'https://ci.linaro.org/jenkins/job/'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200124 # Snapshots base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300125 snapshots_url = 'http://snapshots.linaro.org'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200126
127 # Name of the hardware pack project
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300128 hwpack_job_name = os.environ.get('HWPACK_JOB_NAME')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200129 # The hardware pack build number
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300130 hwpack_build_number = os.environ.get('HWPACK_BUILD_NUMBER')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200131 # Hardware pack file name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300132 hwpack_file_name = os.environ.get('HWPACK_FILE_NAME', 'Undefined')
133 if hwpack_file_name == 'Undefined':
134 sys.exit('Hardware pack is not defined.')
135
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200136 # Device type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300137 device_type = os.environ.get('DEVICE_TYPE', 'Undefined')
138 if device_type == 'Undefined':
139 sys.exit('Device type is not defined.')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200140
141 # Distribution, architecture and hardware pack type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300142 ret_split = hwpack_job_name.split('-', 2)
143 (distribution, architecture, hwpack_type) = \
144 ret_split[0], ret_split[1], ret_split[2]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200145 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300146 hwpack_type = hwpack_type[(len('pre-built-images-')):]
Fathi Boudra65aaf1a2013-01-10 10:35:57 +0200147 if '=' in hwpack_type:
Fathi Boudra5cae8992013-10-19 15:46:31 +0300148 hwpack_type = hwpack_type[(len('pre-built-images/')):]
149 ret_split = dict(
150 token.split('=') for token in hwpack_type.split(','))
151 hwpack_type = ret_split['hwpack']
152
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200153 # Rootfs type, default is developer
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300154 rootfs_type = os.getenv('ROOTFS_TYPE', 'developer')
Fathi Boudrac14068b2012-12-06 17:42:11 +0200155
156 # Bundle stream name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300157 bundle_stream_name = os.environ.get(
158 'BUNDLE_STREAM_NAME',
159 '/private/team/linaro/pre-built-%s/' % DEVICE_STREAM[device_type])
160
Fathi Boudrac14068b2012-12-06 17:42:11 +0200161 # LAVA user
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300162 lava_user = os.environ.get('LAVA_USER')
163 if lava_user is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200164 f = open('/var/run/lava/lava-user')
165 lava_user = f.read().strip()
166 f.close()
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300167
Fathi Boudrac14068b2012-12-06 17:42:11 +0200168 # LAVA token
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300169 lava_token = os.environ.get('LAVA_TOKEN')
170 if lava_token is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200171 f = open('/var/run/lava/lava-token')
172 lava_token = f.read().strip()
173 f.close()
Fathi Boudrac14068b2012-12-06 17:42:11 +0200174
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300175 # LAVA server URL
176 lava_server = os.environ.get('LAVA_SERVER',
Fathi Boudra62997d92013-07-27 09:58:28 +0300177 'validation.linaro.org/RPC2/')
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300178 # LAVA server base URL
179 lava_server_root = lava_server.rstrip('/')
180 if lava_server_root.endswith('/RPC2'):
181 lava_server_root = lava_server_root[:-len('/RPC2')]
182
183 image_url = '%s/%s/pre-built/%s/%s/%s' % \
184 (snapshots_url,
185 distribution,
186 hwpack_type,
187 hwpack_build_number,
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200188 hwpack_file_name)
189
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300190 git_repo = 'git://git.linaro.org/qa/test-definitions.git'
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530191
Fathi Boudra0293e672013-12-03 20:14:54 +0200192 lava_test_plan = os.environ.get('LAVA_TEST_PLAN')
193 if lava_test_plan is None:
194 # tests set specific to an image
195 if distribution == 'openembedded':
196 tests = tests_openembedded_minimal
197 if 'lamp' in rootfs_type:
198 tests += tests_openembedded_lamp
199 if 'leg-java' in rootfs_type:
200 tests += tests_openembedded_leg_java
201 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
202 tests = tests_nano
203 # if ubuntu-desktop, cover more test cases (LEB)
204 if rootfs_type == 'ubuntu-desktop':
205 tests += tests_desktop
206 # if alip, specific tests like bootchart (which should be first)
207 if rootfs_type == 'alip':
208 tests = tests_alip + tests
209 else:
210 lava_test_plan = lava_test_plan.strip("'")
211 tests = lava_test_plan.split()
Andrew McDermottb62dfaf2013-06-26 12:32:30 +0100212
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300213 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200214 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300215 try:
216 tests.remove('bluetooth-enablement')
217 tests.remove('wifi-enablement')
218 except ValueError:
219 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300220
221 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200222 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300223 try:
224 tests.remove('pwrmgmt')
225 except ValueError:
226 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500227
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200228 if distribution == 'openembedded':
Fathi Boudra4079a582012-12-06 19:42:58 +0200229 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300230 'command': 'deploy_linaro_image',
231 'parameters': {
232 'image': '%s' % image_url,
233 },
234 'metadata': {
235 'hwpack.type': '%s' % hwpack_type,
236 'hwpack.build': '%s' % hwpack_build_number,
237 'rootfs.type': '%s' % rootfs_type,
238 'distribution': '%s' % distribution,
239 }
240 },
241 {
242 'command': 'boot_linaro_image',
243 'parameters': {
244 'options': ['boot_cmds=boot_cmds_oe']
245 }
246 }]
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300247 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra4079a582012-12-06 19:42:58 +0200248 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300249 'command': 'deploy_linaro_image',
250 'parameters': {
251 'image': '%s' % image_url,
252 },
253 'metadata': {
254 'ubuntu.name': '%s' % hwpack_type,
255 'ubuntu.build': '%s' % hwpack_build_number,
256 'rootfs.type': '%s' % rootfs_type,
257 'ubuntu.distribution': '%s' % distribution,
258 }
259 }]
Fathi Boudra4079a582012-12-06 19:42:58 +0200260
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200261 if len(tests) > 0:
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300262 if distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300263 distribution = 'ubuntu'
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530264 for test in tests:
Fathi Boudraebb2f192013-06-17 10:01:09 +0300265 test_list = [(
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300266 {'git-repo': git_repo,
267 'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
Fathi Boudraebb2f192013-06-17 10:01:09 +0300268 distribution=distribution, test=test)})]
Senthil Kumaran007181c2013-04-16 14:43:19 +0530269
Fathi Boudraebb2f192013-06-17 10:01:09 +0300270 actions.append({
271 'command': 'lava_test_shell',
272 'parameters': {
Fathi Boudrab088b142013-07-19 09:54:04 +0300273 'timeout': tests_timeout.get(test, 18000),
Fathi Boudraebb2f192013-06-17 10:01:09 +0300274 'testdef_repos': test_list
275 }
276 })
Fathi Boudrac14068b2012-12-06 17:42:11 +0200277
278 actions.append({
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300279 'command': 'submit_results',
280 'parameters': {
281 'stream': bundle_stream_name,
282 'server': '%s%s' % ('http://', lava_server)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200283 }
284 })
285
Fathi Boudra4c0dd222013-11-21 13:34:35 +0200286 # XXX Global timeout in LAVA is hardcoded to 24h (24 * 60 60)
287 # https://bugs.launchpad.net/bugs/1226017
288 # Set to 172800s (48h) to workaround the limitation
289 # A sane default is 900s (15m)
290 config = json.dumps({'timeout': 172800,
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300291 'actions': actions,
292 'job_name': '%s%s/%s/' % (ci_base_url,
293 hwpack_job_name,
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200294 hwpack_build_number),
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300295 'device_type': device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200296 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200297
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200298 print config
299
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300300 skip_lava = os.environ.get('SKIP_LAVA')
301 if skip_lava is None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200302 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200303 server_url = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300304 'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
Fathi Boudrac14068b2012-12-06 17:42:11 +0200305 server = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300306 xmlrpclib.ServerProxy(server_url.format(
307 lava_user=lava_user,
308 lava_token=lava_token,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200309 lava_server=lava_server))
310 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200311 except xmlrpclib.ProtocolError, e:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300312 print 'Error making a LAVA request:', obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200313 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200314
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300315 print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200316 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300317 json.dump({'lava_url': 'http://' + lava_server_root,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200318 'job_id': lava_job_id},
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300319 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200320
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300321 lava_job_info_orig = hwpack_file_name.replace('.img.gz', '.html')
322 top_dir = os.environ.get('WORKSPACE', '.')
Fathi Boudrade020592012-12-10 13:25:14 +0200323 for root, dirs, files in os.walk(top_dir):
324 for file in files:
325 if file == lava_job_info_orig:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300326 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200327
Fathi Boudrade020592012-12-10 13:25:14 +0200328 with open(lava_job_info_orig) as f:
329 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200330
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300331 buffer = buffer.replace(
332 'var lavaJobId = 0',
333 'var lavaJobId = ' + str(lava_job_id), 1)
Fathi Boudrade020592012-12-10 13:25:14 +0200334
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300335 lava_job_info = lava_job_info_orig.replace(
336 '.html',
337 '-' + device_type + '.html')
Fathi Boudrade020592012-12-10 13:25:14 +0200338 with open(lava_job_info, 'w') as f:
339 f.write(buffer)
340 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200341 else:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300342 print 'LAVA job submission skipped.'
Andy Doan61b4d772012-04-24 10:03:28 -0500343
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300344
345if __name__ == '__main__':
Andy Doan61b4d772012-04-24 10:03:28 -0500346 main()