1 # -*- coding: utf-8 -*- 2 3 #------------------------------------------------------------------------- 4 # drawElements Quality Program utilities 5 # -------------------------------------- 6 # 7 # Copyright 2015 The Android Open Source Project 8 # 9 # Licensed under the Apache License, Version 2.0 (the "License"); 10 # you may not use this file except in compliance with the License. 11 # You may obtain a copy of the License at 12 # 13 # http://www.apache.org/licenses/LICENSE-2.0 14 # 15 # Unless required by applicable law or agreed to in writing, software 16 # distributed under the License is distributed on an "AS IS" BASIS, 17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 # See the License for the specific language governing permissions and 19 # limitations under the License. 20 # 21 #------------------------------------------------------------------------- 22 23 import os 24 import string 25 26 from common import * 27 from khr_util.format import indentLines 28 29 class LogSpec: 30 def __init__ (self, argInPrints, argOutPrints = {}, returnPrint = None): 31 self.argInPrints = argInPrints 32 self.argOutPrints = argOutPrints 33 self.returnPrint = returnPrint 34 35 def enum (group): 36 return lambda name: "get%sStr(%s)" % (group, name) 37 38 def pointer (size): 39 return lambda name: "getPointerStr(%s, %s)" % (name, size) 40 41 def enumPointer (group, size): 42 return lambda name: "getEnumPointerStr<%(nameFunc)s>(%(name)s, %(size)s)" % {"name": name, "size": size, "nameFunc": ("get%sName" % group)} 43 44 def configAttrib (attribNdx): 45 return lambda name: "getConfigAttribValueStr(param%d, %s)" % (attribNdx, name) 46 47 # Special rules for printing call arguments 48 CALL_LOG_SPECS = { 49 "eglBindAPI": LogSpec({0: enum("API")}), 50 "eglChooseConfig": LogSpec({1: lambda n: "getConfigAttribListStr(%s)" % n}, argOutPrints = {2: pointer("(num_config && returnValue) ? deMin32(config_size, *num_config) : 0"), 4: lambda n: "(%s ? de::toString(*%s) : \"NULL\")" % (n, n)}), 51 "eglCreateContext": LogSpec({3: lambda n: "getContextAttribListStr(%s)" % n}), 52 "eglCreatePbufferSurface": LogSpec({2: lambda n: "getSurfaceAttribListStr(%s)" % n}), 53 "eglCreatePixmapSurface": LogSpec({3: lambda n: "getSurfaceAttribListStr(%s)" % n}), 54 "eglCreateWindowSurface": LogSpec({3: lambda n: "getSurfaceAttribListStr(%s)" % n}), 55 "eglGetError": LogSpec({}, returnPrint = enum("Error")), 56 "eglGetConfigAttrib": LogSpec({2: enum("ConfigAttrib")}, argOutPrints = {3: lambda n: "getConfigAttribValuePointerStr(attribute, %s)" % n}), 57 "eglGetCurrentSurface": LogSpec({0: enum("SurfaceTarget")}), 58 "eglGetProcAddress": LogSpec({}, returnPrint = lambda n: "tcu::toHex(%s)" % (n)), 59 "eglQueryAPI": LogSpec({}, returnPrint = enum("API")), 60 "eglQueryContext": LogSpec({2: enum("ContextAttrib")}, argOutPrints = {3: lambda n: "getContextAttribValuePointerStr(attribute, %s)" % n}), 61 "eglQuerySurface": LogSpec({2: enum("SurfaceAttrib")}, argOutPrints = {3: lambda n: "getSurfaceAttribValuePointerStr(attribute, %s)" % n}), 62 "eglSurfaceAttrib": LogSpec({2: enum("SurfaceAttrib"), 3: lambda n: "getSurfaceAttribValueStr(attribute, %s)" % n}), 63 } 64 65 def eglwPrefix (string): 66 if string[:5] == "__egl": 67 return "eglw::" + string 68 else: 69 return re.sub(r'\bEGL', 'eglw::EGL', string) 70 71 def prefixedParams (command): 72 if len(command.params) > 0: 73 return ", ".join(eglwPrefix(param.declaration) for param in command.params) 74 else: 75 return "void" 76 77 def commandLogWrapperMemberDecl (command): 78 return "%s\t%s\t(%s);" % (eglwPrefix(command.type), command.name, prefixedParams(command)) 79 80 def getVarDefaultPrint (type, varName): 81 if re.match(r'^const +char *\*$', type): 82 return "getStringStr(%s)" % varName 83 elif re.match(r'(EGLenum|EGLConfig|EGLSurface|EGLClientBuffer|EGLNativeDisplayType|EGLNativeWindowType|EGLNativePixmapType|\*)$', type): 84 return "toHex(%s)" % varName 85 elif type == 'EGLBoolean': 86 return "getBooleanStr(%s)" % varName 87 else: 88 return varName 89 90 def commandLogWrapperMemberDef (command): 91 src = "" 92 try: 93 logSpec = CALL_LOG_SPECS[command.name] 94 except KeyError: 95 logSpec = None 96 97 src += "\n" 98 src += "%s CallLogWrapper::%s (%s)\n{\n" % (eglwPrefix(command.type), command.name, ", ".join(eglwPrefix(p.declaration) for p in command.params)) 99 100 # Append paramemetrs 101 callPrintItems = ["\"%s(\"" % command.name] 102 for paramNdx, param in enumerate(command.params): 103 if paramNdx > 0: 104 callPrintItems.append("\", \"") 105 106 if logSpec and paramNdx in logSpec.argInPrints: 107 callPrintItems.append(logSpec.argInPrints[paramNdx](param.name)) 108 else: 109 callPrintItems.append(getVarDefaultPrint(param.type, param.name)) 110 111 callPrintItems += ["\");\"", "TestLog::EndMessage"] 112 113 src += "\tif (m_enableLog)\n" 114 src += "\t\tm_log << TestLog::Message << %s;\n" % " << ".join(callPrintItems) 115 116 callStr = "m_egl.%s(%s)" % (getFunctionMemberName(command.name), ", ".join([p.name for p in command.params])) 117 118 isVoid = command.type == 'void' 119 if isVoid: 120 src += "\t%s;\n" % callStr 121 else: 122 src += "\t%s returnValue = %s;\n" % (eglwPrefix(command.type), callStr) 123 124 if logSpec and len(logSpec.argOutPrints) > 0: 125 # Print values returned in pointers 126 src += "\tif (m_enableLog)\n\t{\n" 127 128 for paramNdx, param in enumerate(command.params): 129 if paramNdx in logSpec.argOutPrints: 130 src += "\t\tm_log << TestLog::Message << \"// %s = \" << %s << TestLog::EndMessage;\n" % (param.name, logSpec.argOutPrints[paramNdx](param.name)) 131 132 src += "\t}\n" 133 134 if not isVoid: 135 # Print return value 136 returnPrint = getVarDefaultPrint(command.type, "returnValue") 137 if logSpec and logSpec.returnPrint: 138 returnPrint = logSpec.returnPrint("returnValue") 139 140 src += "\tif (m_enableLog)\n" 141 src += "\t\tm_log << TestLog::Message << \"// \" << %s << \" returned\" << TestLog::EndMessage;\n" % returnPrint 142 src += "\treturn returnValue;\n" 143 144 src += "}" 145 return src 146 147 def gen (iface): 148 genCommandList(iface, commandLogWrapperMemberDecl, EGL_DIR, "egluCallLogWrapperApi.inl", True) 149 genCommandList(iface, commandLogWrapperMemberDef, EGL_DIR, "egluCallLogWrapper.inl", False) 150