blob: 76343465474ed93f3111dcb8a05e2b9f110089d8 [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 Boudra8c7aa552013-09-17 09:19:41 +030013 'cyclictest': 86400,
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 McDermottec97cb52013-09-24 11:50:57 +010018 'jtreg-setup': 7200,
Andrew McDermott58796ed2013-10-02 18:04:56 +010019 'jtreg-hotspot-compiler': 36000,
Andrew McDermottec97cb52013-09-24 11:50:57 +010020 'jtreg-hotspot-gc': 7200,
21 'jtreg-hotspot-runtime': 7200,
22 'jtreg-hotspot-sanity': 7200,
23 'jtreg-hotspot-serviceability': 7200,
24 'jtreg-hotspot-testlibrary': 7200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030025 'kernel-version': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030026 'leb-basic-graphics': 7200,
27 'ltp': 7200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030028 'mysql': 800,
Fathi Boudrac13926a2013-07-03 11:36:37 +030029 'network-tests-basic': 1200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030030 'perf': 800,
31 'phpinfo': 800,
32 'phpmysql': 800,
33 'pwrmgmt': 800,
34 'sdkhelloc': 800,
35 'sdkhellocxx': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030036 'smoke-tests-basic': 1200,
Fathi Boudra63d5cbb2013-08-02 08:55:36 +030037 'toolchain': 800,
Fathi Boudra2486ee12013-06-28 13:39:07 +030038 'wifi-enablement': 7200,
39}
40
Fathi Boudrac14068b2012-12-06 17:42:11 +020041tests_nano = [
42 'device-tree',
43 'gatortests',
Fathi Boudrac13926a2013-07-03 11:36:37 +030044 'network-tests-basic',
Fathi Boudrac14068b2012-12-06 17:42:11 +020045 'perf',
46 'pwrmgmt',
Fathi Boudra2486ee12013-06-28 13:39:07 +030047 'smoke-tests-basic',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030048]
Fathi Boudrac14068b2012-12-06 17:42:11 +020049
50tests_alip = [
51 'bootchart',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030052]
Fathi Boudrac14068b2012-12-06 17:42:11 +020053
54tests_desktop = [
55 'e2eaudiotest',
56 'bluetooth-enablement',
57 'wifi-enablement',
58 'leb-basic-graphics',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030059]
Fathi Boudrac14068b2012-12-06 17:42:11 +020060
Fathi Boudra60d0e972013-04-19 10:49:47 +030061tests_openembedded_minimal = [
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020062 'busybox',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020063 'device-tree',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020064 'ethernet',
65 'kernel-version',
Marcin Juszkiewicz1678f112013-04-09 09:55:46 +020066 'perf',
Marcin Juszkiewicz59172832013-04-18 09:35:00 +020067 'toolchain',
Fathi Boudra3f7ace92013-04-11 13:06:11 +030068]
Andy Doan61b4d772012-04-24 10:03:28 -050069
Fathi Boudra60d0e972013-04-19 10:49:47 +030070tests_openembedded_lamp = [
Fathi Boudra60d0e972013-04-19 10:49:47 +030071 'mysql',
72 'phpinfo',
73 'phpmysql',
74 'sdkhelloc',
75 'sdkhellocxx',
76]
77
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010078tests_openembedded_leg_java = [
Andrew McDermottedd9b8d2013-08-24 00:07:53 +010079 'openjdk7-sanity',
80 'openjdk8-sanity',
Andrew McDermott114e7662013-07-03 16:12:37 +010081 'mauve',
Andrew McDermotte47afbd2013-09-23 19:19:51 +010082 'jtreg-setup',
83 'jtreg-hotspot-compiler',
84 'jtreg-hotspot-gc',
85 'jtreg-hotspot-runtime',
86 'jtreg-hotspot-sanity',
87 'jtreg-hotspot-serviceability',
88 'jtreg-hotspot-testlibrary',
Andrew McDermottb62dfaf2013-06-26 12:32:30 +010089]
90
Fathi Boudra8e4ce562012-12-08 14:35:17 +020091# Mapping device type - bundle stream
Andy Doan3462e4c2012-05-18 10:58:06 -050092DEVICE_STREAM = {
Fathi Boudra8b59a502013-01-18 10:20:04 +020093 'arndale': 'arndale',
Koen Kooid401dbd2013-10-11 12:48:01 +020094 'beaglebone-black': 'beaglebone',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020095 'beaglexm': 'beaglexm',
Fathi Boudrab97042a2013-04-04 17:49:22 +030096 'highbank': 'highbank',
Fathi Boudra8e4ce562012-12-08 14:35:17 +020097 'origen': 'leb-origen',
Andy Doan3462e4c2012-05-18 10:58:06 -050098 'panda': 'leb-panda-4430',
Paul Larson27308512012-08-17 14:09:05 -050099 'panda-es': 'leb-panda-es',
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200100 'rtsm_foundation-armv8': 'vexpress64',
101 'rtsm_ve-a15x1-a7x1': 'vexpress',
102 'rtsm_ve-a15x4-a7x4': 'vexpress',
103 'rtsm_ve-armv8': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -0500104 'snowball_sd': 'leb-snowball',
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200105 'vexpress-a5': 'vexpress',
Fathi Boudra76551e52012-09-19 17:51:33 +0300106 'vexpress-a9': 'vexpress',
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200107 'vexpress-tc2': 'vexpress',
Andy Doan3462e4c2012-05-18 10:58:06 -0500108}
109
Andy Doan61b4d772012-04-24 10:03:28 -0500110
111def obfuscate_credentials(s):
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300112 return re.sub(r'([^ ]:).+?(@)', r'\1xxx\2', s)
Andy Doan61b4d772012-04-24 10:03:28 -0500113
Fathi Boudrac14068b2012-12-06 17:42:11 +0200114
Andy Doan61b4d772012-04-24 10:03:28 -0500115def main():
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200116 """Script entry point: return some JSON based on calling args.
117 We should be called from Jenkins and expect the following to be defined:
118 $HWPACK_BUILD_NUMBER $HWPACK_JOB_NAME HWPACK_FILE_NAME $DEVICE_TYPE
119 """
Andy Doan61b4d772012-04-24 10:03:28 -0500120
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200121 # CI base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300122 ci_base_url = 'https://ci.linaro.org/jenkins/job/'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200123 # Snapshots base URL
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300124 snapshots_url = 'http://snapshots.linaro.org'
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200125
126 # Name of the hardware pack project
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300127 hwpack_job_name = os.environ.get('HWPACK_JOB_NAME')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200128 # The hardware pack build number
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300129 hwpack_build_number = os.environ.get('HWPACK_BUILD_NUMBER')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200130 # Hardware pack file name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300131 hwpack_file_name = os.environ.get('HWPACK_FILE_NAME', 'Undefined')
132 if hwpack_file_name == 'Undefined':
133 sys.exit('Hardware pack is not defined.')
134
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200135 # Device type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300136 device_type = os.environ.get('DEVICE_TYPE', 'Undefined')
137 if device_type == 'Undefined':
138 sys.exit('Device type is not defined.')
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200139
140 # Distribution, architecture and hardware pack type
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300141 ret_split = hwpack_job_name.split('-', 2)
142 (distribution, architecture, hwpack_type) = \
143 ret_split[0], ret_split[1], ret_split[2]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200144 if hwpack_type.startswith('pre-built-images-'):
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300145 hwpack_type = hwpack_type[(len('pre-built-images-')):]
Fathi Boudra65aaf1a2013-01-10 10:35:57 +0200146 if '=' in hwpack_type:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300147 hwpack_type = hwpack_type[(len('pre-built-images/hwpack=')):]
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200148 # Rootfs type, default is developer
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300149 rootfs_type = os.getenv('ROOTFS_TYPE', 'developer')
Fathi Boudrac14068b2012-12-06 17:42:11 +0200150
151 # Bundle stream name
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300152 bundle_stream_name = os.environ.get(
153 'BUNDLE_STREAM_NAME',
154 '/private/team/linaro/pre-built-%s/' % DEVICE_STREAM[device_type])
155
Fathi Boudrac14068b2012-12-06 17:42:11 +0200156 # LAVA user
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300157 lava_user = os.environ.get('LAVA_USER')
158 if lava_user is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200159 f = open('/var/run/lava/lava-user')
160 lava_user = f.read().strip()
161 f.close()
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300162
Fathi Boudrac14068b2012-12-06 17:42:11 +0200163 # LAVA token
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300164 lava_token = os.environ.get('LAVA_TOKEN')
165 if lava_token is None:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200166 f = open('/var/run/lava/lava-token')
167 lava_token = f.read().strip()
168 f.close()
Fathi Boudrac14068b2012-12-06 17:42:11 +0200169
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300170 # LAVA server URL
171 lava_server = os.environ.get('LAVA_SERVER',
Fathi Boudra62997d92013-07-27 09:58:28 +0300172 'validation.linaro.org/RPC2/')
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300173 # LAVA server base URL
174 lava_server_root = lava_server.rstrip('/')
175 if lava_server_root.endswith('/RPC2'):
176 lava_server_root = lava_server_root[:-len('/RPC2')]
177
178 image_url = '%s/%s/pre-built/%s/%s/%s' % \
179 (snapshots_url,
180 distribution,
181 hwpack_type,
182 hwpack_build_number,
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200183 hwpack_file_name)
184
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300185 git_repo = 'git://git.linaro.org/qa/test-definitions.git'
Senthil Kumaran672ac4d2012-12-19 15:10:59 +0530186
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200187 # tests set specific to an image
Fathi Boudra60d0e972013-04-19 10:49:47 +0300188 if distribution == 'openembedded':
189 tests = tests_openembedded_minimal
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300190 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300191 tests = tests_nano
Fathi Boudrac51e0912012-06-15 18:18:41 +0300192
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300193 # if ubuntu-desktop, cover more test cases (LEB)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200194 if rootfs_type == 'ubuntu-desktop':
Fathi Boudrac51e0912012-06-15 18:18:41 +0300195 tests += tests_desktop
Andy Doanbc19b7c2012-05-17 12:08:16 -0500196
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300197 # if alip, specific tests like bootchart (which should be first)
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200198 if rootfs_type == 'alip':
Ricardo Salveti de Araujo6ad94332012-06-29 02:48:18 -0300199 tests = tests_alip + tests
200
Fathi Boudra60d0e972013-04-19 10:49:47 +0300201 if 'lamp' in rootfs_type:
202 tests += tests_openembedded_lamp
203
Andrew McDermottb62dfaf2013-06-26 12:32:30 +0100204 if 'leg-java' in rootfs_type:
205 tests += tests_openembedded_leg_java
206
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300207 # removing bluetooth and wifi for devices that don't support it
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200208 if device_type in ['beaglexm', 'vexpress-a9', 'mx53loco']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300209 try:
210 tests.remove('bluetooth-enablement')
211 tests.remove('wifi-enablement')
212 except ValueError:
213 pass
Ricardo Salveti de Araujoacf28542012-06-27 18:56:00 -0300214
215 # vexpress doesn't support PM, so disable pwrmgmt
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200216 if device_type in ['vexpress-a9']:
Ricardo Salveti de Araujodd780972012-06-29 11:48:47 -0300217 try:
218 tests.remove('pwrmgmt')
219 except ValueError:
220 pass
Andy Doane9bf2152012-06-12 15:42:10 -0500221
Fathi Boudra62eb6a92012-12-06 19:02:56 +0200222 if distribution == 'openembedded':
Fathi Boudra4079a582012-12-06 19:42:58 +0200223 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300224 'command': 'deploy_linaro_image',
225 'parameters': {
226 'image': '%s' % image_url,
227 },
228 'metadata': {
229 'hwpack.type': '%s' % hwpack_type,
230 'hwpack.build': '%s' % hwpack_build_number,
231 'rootfs.type': '%s' % rootfs_type,
232 'distribution': '%s' % distribution,
233 }
234 },
235 {
236 'command': 'boot_linaro_image',
237 'parameters': {
238 'options': ['boot_cmds=boot_cmds_oe']
239 }
240 }]
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300241 elif distribution == 'ubuntu' or distribution == 'quantal' or distribution == 'raring':
Fathi Boudra4079a582012-12-06 19:42:58 +0200242 actions = [{
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300243 'command': 'deploy_linaro_image',
244 'parameters': {
245 'image': '%s' % image_url,
246 },
247 'metadata': {
248 'ubuntu.name': '%s' % hwpack_type,
249 'ubuntu.build': '%s' % hwpack_build_number,
250 'rootfs.type': '%s' % rootfs_type,
251 'ubuntu.distribution': '%s' % distribution,
252 }
253 }]
Fathi Boudra4079a582012-12-06 19:42:58 +0200254
Fathi Boudraa9bbadb2012-12-07 16:10:29 +0200255 if len(tests) > 0:
Fathi Boudrad2bd08b2013-05-06 15:00:00 +0300256 if distribution == 'quantal' or distribution == 'raring':
Fathi Boudra60d0e972013-04-19 10:49:47 +0300257 distribution = 'ubuntu'
Senthil Kumaranb30d7382012-12-19 15:11:47 +0530258 for test in tests:
Fathi Boudraebb2f192013-06-17 10:01:09 +0300259 test_list = [(
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300260 {'git-repo': git_repo,
261 'testdef': '{distribution:>s}/{test:>s}.yaml'.format(
Fathi Boudraebb2f192013-06-17 10:01:09 +0300262 distribution=distribution, test=test)})]
Senthil Kumaran007181c2013-04-16 14:43:19 +0530263
Fathi Boudraebb2f192013-06-17 10:01:09 +0300264 actions.append({
265 'command': 'lava_test_shell',
266 'parameters': {
Fathi Boudrab088b142013-07-19 09:54:04 +0300267 'timeout': tests_timeout.get(test, 18000),
Fathi Boudraebb2f192013-06-17 10:01:09 +0300268 'testdef_repos': test_list
269 }
270 })
Fathi Boudrac14068b2012-12-06 17:42:11 +0200271
272 actions.append({
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300273 'command': 'submit_results',
274 'parameters': {
275 'stream': bundle_stream_name,
276 'server': '%s%s' % ('http://', lava_server)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200277 }
278 })
279
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300280 config = json.dumps({'timeout': 18000,
281 'actions': actions,
282 'job_name': '%s%s/%s/' % (ci_base_url,
283 hwpack_job_name,
Fathi Boudrad1f9a862012-12-28 14:46:04 +0200284 hwpack_build_number),
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300285 'device_type': device_type,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200286 }, indent=2)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200287
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200288 print config
289
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300290 skip_lava = os.environ.get('SKIP_LAVA')
291 if skip_lava is None:
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200292 try:
Fathi Boudrac14068b2012-12-06 17:42:11 +0200293 server_url = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300294 'https://{lava_user:>s}:{lava_token:>s}@{lava_server:>s}'
Fathi Boudrac14068b2012-12-06 17:42:11 +0200295 server = \
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300296 xmlrpclib.ServerProxy(server_url.format(
297 lava_user=lava_user,
298 lava_token=lava_token,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200299 lava_server=lava_server))
300 lava_job_id = server.scheduler.submit_job(config)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200301 except xmlrpclib.ProtocolError, e:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300302 print 'Error making a LAVA request:', obfuscate_credentials(str(e))
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200303 sys.exit(1)
Fathi Boudrac14068b2012-12-06 17:42:11 +0200304
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300305 print 'LAVA Job Id: %s, URL: http://%s/scheduler/job/%s' % \
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200306 (lava_job_id, lava_server_root, lava_job_id)
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300307 json.dump({'lava_url': 'http://' + lava_server_root,
Fathi Boudrac14068b2012-12-06 17:42:11 +0200308 'job_id': lava_job_id},
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300309 open('lava-job-info', 'w'))
Fathi Boudra8e4ce562012-12-08 14:35:17 +0200310
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300311 lava_job_info_orig = hwpack_file_name.replace('.img.gz', '.html')
312 top_dir = os.environ.get('WORKSPACE', '.')
Fathi Boudrade020592012-12-10 13:25:14 +0200313 for root, dirs, files in os.walk(top_dir):
314 for file in files:
315 if file == lava_job_info_orig:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300316 lava_job_info_orig = os.path.join(root, file)
Fathi Boudra5e481022012-12-08 19:21:16 +0200317
Fathi Boudrade020592012-12-10 13:25:14 +0200318 with open(lava_job_info_orig) as f:
319 buffer = f.read()
Fathi Boudra5e481022012-12-08 19:21:16 +0200320
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300321 buffer = buffer.replace(
322 'var lavaJobId = 0',
323 'var lavaJobId = ' + str(lava_job_id), 1)
Fathi Boudrade020592012-12-10 13:25:14 +0200324
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300325 lava_job_info = lava_job_info_orig.replace(
326 '.html',
327 '-' + device_type + '.html')
Fathi Boudrade020592012-12-10 13:25:14 +0200328 with open(lava_job_info, 'w') as f:
329 f.write(buffer)
330 os.remove(lava_job_info_orig)
Fathi Boudra79c1e8b2012-12-02 10:36:57 +0200331 else:
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300332 print 'LAVA job submission skipped.'
Andy Doan61b4d772012-04-24 10:03:28 -0500333
Fathi Boudra3f7ace92013-04-11 13:06:11 +0300334
335if __name__ == '__main__':
Andy Doan61b4d772012-04-24 10:03:28 -0500336 main()