1# Copyright 2018 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# Recipe which runs the SKQP apk using docker and an Android Emulator 6 7DEPS = [ 8 'checkout', 9 'infra', 10 'recipe_engine/file', 11 'recipe_engine/path', 12 'recipe_engine/properties', 13 'recipe_engine/python', 14 'recipe_engine/step', 15 'run', 16 'vars', 17] 18 19# This image is public, and thus doesn't require log-in to read. 20DOCKER_IMAGE = ('butomo1989/docker-android-x86-8.1@sha256:' 21 'ad75c888e373d9ea7a2821fd8f64b53c9a22b5827e6fa516b396739a20b9bb88') 22INNER_TEST_SCRIPT = '/SRC/skia/infra/skqp/run_skqp.sh' 23 24 25def RunSteps(api): 26 api.vars.setup() 27 checkout_root = api.checkout.default_checkout_root 28 api.checkout.bot_update(checkout_root=checkout_root) 29 30 # This is where the APK should be, that is, where Swarming puts the inputs. 31 apk_location = api.vars.build_dir 32 33 container_name = 'android_em' 34 35 # Make sure the emulator starts up, with some resilence against 36 # occasional flakes. 37 api.python.inline( 38 name='Start Emulator', 39 program=''' 40import os 41import subprocess 42import sys 43 44container_name = sys.argv[1] 45checkout_root = sys.argv[2] 46apk_location = sys.argv[3] 47DOCKER_IMAGE = sys.argv[4] 48 49MAX_TRIES = 5 50 51start_cmd = ['docker', 'run', '--privileged', '--rm', '-d', # detached/daemon 52 '--name', container_name, 53 '--env', 'DEVICE=Samsung Galaxy S6', 54 '--volume', '%s:/SRC' % checkout_root, 55 '--volume', '%s:/OUT' % apk_location, 56 DOCKER_IMAGE] 57 58wait_cmd = ['docker', 'exec', container_name, 59 'timeout', '45', 'adb', 'wait-for-device'] 60 61for t in range(MAX_TRIES): 62 print 'Starting Emulator try %d' % t 63 try: 64 # Start emulator 65 print subprocess.check_output(start_cmd) 66 # Wait a short time using adb-wait-for-device 67 print subprocess.check_output(wait_cmd) 68 # if exit code 0, we are good so end loop 69 print 'Emulator started' 70 sys.exit(0) 71 except subprocess.CalledProcessError: 72 # else kill docker container 73 print 'Killing and trying again' 74 print subprocess.check_output(['docker', 'kill', container_name]) 75print 'Could not start emulator' 76sys.exit(1) 77''', 78 args=[container_name, checkout_root, apk_location, DOCKER_IMAGE], 79 infra_step=True) 80 81 api.run( 82 api.step, 83 'Test SQKP with Android Emulator in Docker', 84 cmd=['docker', 'exec', container_name, 85 INNER_TEST_SCRIPT]) 86 87 api.run( 88 api.step, 89 'Stop Emulator', 90 cmd=['docker', 'kill', container_name], 91 infra_step=True) 92 93 94def GenTests(api): 95 yield ( 96 api.test('Test-Debian9-Clang-GCE-CPU-Emulator-x86-devrel' 97 '-All-Android_SKQP') + 98 api.properties(buildername=('Test-Debian9-Clang-GCE-CPU-Emulator' 99 '-x86-devrel-All-Android_SKQP'), 100 repository='https://skia.googlesource.com/skia.git', 101 revision='abc123', 102 path_config='kitchen', 103 swarm_out_dir='[SWARM_OUT_DIR]') 104 ) 105