1# Lint as: python2, python3 2# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import logging 7import os 8import re 9from autotest_lib.client.bin import test, utils 10from autotest_lib.client.common_lib import error 11from autotest_lib.client.cros.graphics import graphics_utils 12 13 14class graphics_GLAPICheck(graphics_utils.GraphicsTest): 15 """ 16 Verify correctness of OpenGL/GLES. 17 """ 18 version = 1 19 error_message = '' 20 21 def __check_extensions(self, info, ext_entries): 22 info_split = info.split() 23 comply = True 24 for extension in ext_entries: 25 match = extension in info_split 26 if not match: 27 self.error_message += ' ' + extension 28 comply = False 29 return comply 30 31 def __check_gles_extensions(self, info): 32 extensions = [ 33 'GL_OES_EGL_image', 34 'EGL_KHR_image' 35 ] 36 extensions2 = [ 37 'GL_OES_EGL_image', 38 'EGL_KHR_image_base', 39 'EGL_KHR_image_pixmap' 40 ] 41 return (self.__check_extensions(info, extensions) or 42 self.__check_extensions(info, extensions2)) 43 44 def __check_wflinfo(self): 45 # TODO(ihf): Extend this function once gl(es)_APICheck code has 46 # been upstreamed to waffle. 47 version_major, version_minor = graphics_utils.get_gles_version() 48 if version_major: 49 version_info = ('GLES_VERSION = %d.%d' % 50 (version_major, version_minor)) 51 logging.info(version_info) 52 # GLES version has to be 2.0 or above. 53 if version_major < 2: 54 self.error_message = ' %s' % version_info 55 return False 56 version_major, version_minor = graphics_utils.get_egl_version() 57 if version_major: 58 version_info = ('EGL_VERSION = %d.%d' % 59 (version_major, version_minor)) 60 logging.info(version_info) 61 # EGL version has to be 1.3 or above. 62 if (version_major == 1 and version_minor >= 3 or 63 version_major > 1): 64 logging.warning('Please add missing extension check. ' 65 'Details crbug.com/413079') 66 # return self.__check_gles_extensions(wflinfo + eglinfo) 67 return True 68 else: 69 self.error_message = version_info 70 return False 71 # No EGL version info found. 72 self.error_message = ' missing EGL version info' 73 return False 74 # No GLES version info found. 75 self.error_message = ' missing GLES version info' 76 return False 77 78 def initialize(self): 79 super(graphics_GLAPICheck, self).initialize() 80 81 def cleanup(self): 82 super(graphics_GLAPICheck, self).cleanup() 83 84 @graphics_utils.GraphicsTest.failure_report_decorator('graphics_GLAPICheck') 85 def run_once(self): 86 if not self.__check_wflinfo(): 87 raise error.TestFail('Failed: GLES API insufficient:' + 88 self.error_message) 89 return 90