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 12 13_SDCARD_EXEC = '/sdcard/gralloctest' 14_EXEC_DIRECTORY = '/data/executables/' 15_ANDROID_EXEC = _EXEC_DIRECTORY + 'gralloctest' 16 17 18class graphics_Gralloc(arc.ArcTest): 19 """gralloc test.""" 20 version = 1 21 22 def setup(self): 23 os.chdir(self.srcdir) 24 utils.make('clean') 25 utils.make('all') 26 27 def initialize(self): 28 super(graphics_Gralloc, self).initialize(autotest_ext=True) 29 30 def arc_setup(self): 31 super(graphics_Gralloc, self).arc_setup() 32 # Get the executable from CrOS and copy it to Android container. Due to 33 # weird permission issues inside the container, we first have to copy 34 # the test to /sdcard/, then move it to a /data/ subdirectory we create. 35 # The permissions on the exectuable have to be modified as well. 36 arc.adb_root() 37 cmd = os.path.join(self.srcdir, 'gralloctest') 38 arc.adb_cmd('-e push %s %s' % (cmd, _SDCARD_EXEC)) 39 arc._android_shell('mkdir -p %s' % (_EXEC_DIRECTORY)) 40 arc._android_shell('mv %s %s' % (_SDCARD_EXEC, _ANDROID_EXEC)) 41 arc._android_shell('chmod o+rwx %s' % (_ANDROID_EXEC)) 42 43 def arc_teardown(self): 44 # Remove test contents from Android container. 45 arc._android_shell('rm -rf %s' % (_EXEC_DIRECTORY)) 46 super(graphics_Gralloc, self).arc_teardown() 47 48 def run_once(self): 49 failures = [] 50 # TODO(ihf): shard this test into multiple control files. 51 test_names = [ 52 'alloc_varying_sizes', 'alloc_usage', 'api', 'gralloc_order', 53 'uninitialized_handle', 'freed_handle', 'mapping', 'perform', 54 'ycbcr', 'async' 55 ] 56 57 # Run the tests and capture stdout. 58 for test_name in test_names: 59 try: 60 cmd = '%s %s' % (_ANDROID_EXEC, test_name) 61 stdout = arc._android_shell(cmd) 62 except Exception: 63 logging.error('Exception running %s', cmd) 64 # Look for the regular expression indicating success. 65 match = re.search(r'\[ PASSED \]', stdout) 66 if not match: 67 failures.append(test_name) 68 logging.error(stdout) 69 else: 70 logging.debug(stdout) 71 72 if failures: 73 gpu_family = utils.get_gpu_family() 74 raise error.TestFail('Failed: gralloc on %s in %s.' % 75 (gpu_family, failures)) 76