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