1# Copyright 2016 The Chromium OS 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 5import logging 6import os 7import re 8 9from autotest_lib.client.bin import utils 10from autotest_lib.client.common_lib import error 11from autotest_lib.client.common_lib.cros import arc 12from autotest_lib.client.cros.graphics import graphics_utils 13 14_SDCARD_EXEC = '/sdcard/gralloctest' 15_EXEC_DIRECTORY = '/data/executables/' 16# The tests still can be run individually, though we run with the 'all' option 17# Run ./gralloctest in Android to get a list of options. 18_ANDROID_EXEC = _EXEC_DIRECTORY + 'gralloctest' 19_OPTION = 'all' 20 21# GraphicsTest should go first as it will pass initialize/cleanup function 22# to ArcTest. GraphicsTest initialize would not be called if ArcTest goes first 23class graphics_Gralloc(graphics_utils.GraphicsTest, arc.ArcTest): 24 """gralloc test.""" 25 version = 1 26 27 def setup(self): 28 os.chdir(self.srcdir) 29 utils.make('clean') 30 utils.make('all') 31 32 def initialize(self): 33 super(graphics_Gralloc, self).initialize(autotest_ext=True) 34 35 def arc_setup(self): 36 super(graphics_Gralloc, self).arc_setup() 37 # Get the executable from CrOS and copy it to Android container. Due to 38 # weird permission issues inside the container, we first have to copy 39 # the test to /sdcard/, then move it to a /data/ subdirectory we create. 40 # The permissions on the exectuable have to be modified as well. 41 arc.adb_root() 42 cmd = os.path.join(self.srcdir, 'gralloctest') 43 arc.adb_cmd('-e push %s %s' % (cmd, _SDCARD_EXEC)) 44 arc._android_shell('mkdir -p %s' % (_EXEC_DIRECTORY)) 45 arc._android_shell('mv %s %s' % (_SDCARD_EXEC, _ANDROID_EXEC)) 46 arc._android_shell('chmod o+rwx %s' % (_ANDROID_EXEC)) 47 48 def arc_teardown(self): 49 # Remove test contents from Android container. 50 arc._android_shell('rm -rf %s' % (_EXEC_DIRECTORY)) 51 super(graphics_Gralloc, self).arc_teardown() 52 53 def run_once(self): 54 try: 55 cmd = '%s %s' % (_ANDROID_EXEC, _OPTION) 56 stdout = arc._android_shell(cmd) 57 except Exception: 58 logging.error('Exception running %s', cmd) 59 # Look for the regular expression indicating failure. 60 for line in stdout.splitlines(): 61 match = re.search(r'\[ FAILED \]', stdout) 62 if match: 63 self.add_failures(line) 64 logging.error(line) 65 else: 66 logging.debug(stdout) 67 68 if self.get_failures(): 69 gpu_family = utils.get_gpu_family() 70 raise error.TestFail('Failed: gralloc on %s in %s.' % 71 (gpu_family, self.get_failures())) 72