1*35238bceSAndroid Build Coastguard Worker# -*- coding: utf-8 -*- 2*35238bceSAndroid Build Coastguard Worker 3*35238bceSAndroid Build Coastguard Worker#------------------------------------------------------------------------- 4*35238bceSAndroid Build Coastguard Worker# Vulkan CTS 5*35238bceSAndroid Build Coastguard Worker# ---------- 6*35238bceSAndroid Build Coastguard Worker# 7*35238bceSAndroid Build Coastguard Worker# Copyright (c) 2016 Google Inc. 8*35238bceSAndroid Build Coastguard Worker# 9*35238bceSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 10*35238bceSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 11*35238bceSAndroid Build Coastguard Worker# You may obtain a copy of the License at 12*35238bceSAndroid Build Coastguard Worker# 13*35238bceSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 14*35238bceSAndroid Build Coastguard Worker# 15*35238bceSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 16*35238bceSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 17*35238bceSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18*35238bceSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 19*35238bceSAndroid Build Coastguard Worker# limitations under the License. 20*35238bceSAndroid Build Coastguard Worker# 21*35238bceSAndroid Build Coastguard Worker#------------------------------------------------------------------------- 22*35238bceSAndroid Build Coastguard Worker 23*35238bceSAndroid Build Coastguard Workerimport os 24*35238bceSAndroid Build Coastguard Workerimport sys 25*35238bceSAndroid Build Coastguard Worker 26*35238bceSAndroid Build Coastguard Workersys.path.append(os.path.join(os.path.dirname(__file__), "..", "log")) 27*35238bceSAndroid Build Coastguard Workersys.path.append(os.path.join(os.path.dirname(__file__), "..", "build")) 28*35238bceSAndroid Build Coastguard Worker 29*35238bceSAndroid Build Coastguard Workerfrom common import readFile 30*35238bceSAndroid Build Coastguard Workerfrom message import * 31*35238bceSAndroid Build Coastguard Workerfrom log_parser import StatusCode, BatchResultParser 32*35238bceSAndroid Build Coastguard Worker 33*35238bceSAndroid Build Coastguard WorkerALLOWED_STATUS_CODES = set([ 34*35238bceSAndroid Build Coastguard Worker StatusCode.PASS, 35*35238bceSAndroid Build Coastguard Worker StatusCode.NOT_SUPPORTED, 36*35238bceSAndroid Build Coastguard Worker StatusCode.QUALITY_WARNING, 37*35238bceSAndroid Build Coastguard Worker StatusCode.COMPATIBILITY_WARNING 38*35238bceSAndroid Build Coastguard Worker ]) 39*35238bceSAndroid Build Coastguard Worker 40*35238bceSAndroid Build Coastguard Workerdef readMustpass (filename): 41*35238bceSAndroid Build Coastguard Worker f = open(filename, 'rt') 42*35238bceSAndroid Build Coastguard Worker cases = [] 43*35238bceSAndroid Build Coastguard Worker for line in f: 44*35238bceSAndroid Build Coastguard Worker s = line.strip() 45*35238bceSAndroid Build Coastguard Worker if len(s) > 0: 46*35238bceSAndroid Build Coastguard Worker cases.append(s) 47*35238bceSAndroid Build Coastguard Worker return cases 48*35238bceSAndroid Build Coastguard Worker 49*35238bceSAndroid Build Coastguard Workerdef readTestLog (filename): 50*35238bceSAndroid Build Coastguard Worker parser = BatchResultParser() 51*35238bceSAndroid Build Coastguard Worker return parser.parseFile(filename) 52*35238bceSAndroid Build Coastguard Worker 53*35238bceSAndroid Build Coastguard Workerdef verifyTestLog (filename, mustpass): 54*35238bceSAndroid Build Coastguard Worker results = readTestLog(filename) 55*35238bceSAndroid Build Coastguard Worker messages = [] 56*35238bceSAndroid Build Coastguard Worker resultOrderOk = True 57*35238bceSAndroid Build Coastguard Worker 58*35238bceSAndroid Build Coastguard Worker # Mustpass case names must be unique 59*35238bceSAndroid Build Coastguard Worker assert len(mustpass) == len(set(mustpass)) 60*35238bceSAndroid Build Coastguard Worker 61*35238bceSAndroid Build Coastguard Worker # Verify number of results 62*35238bceSAndroid Build Coastguard Worker if len(results) != len(mustpass): 63*35238bceSAndroid Build Coastguard Worker messages.append(error(filename, "Wrong number of test results, expected %d, found %d" % (len(mustpass), len(results)))) 64*35238bceSAndroid Build Coastguard Worker 65*35238bceSAndroid Build Coastguard Worker caseNameToResultNdx = {} 66*35238bceSAndroid Build Coastguard Worker for ndx in range(len(results)): 67*35238bceSAndroid Build Coastguard Worker result = results[ndx] 68*35238bceSAndroid Build Coastguard Worker if not result in caseNameToResultNdx: 69*35238bceSAndroid Build Coastguard Worker caseNameToResultNdx[result.name] = ndx 70*35238bceSAndroid Build Coastguard Worker else: 71*35238bceSAndroid Build Coastguard Worker messages.append(error(filename, "Multiple results for " + result.name)) 72*35238bceSAndroid Build Coastguard Worker 73*35238bceSAndroid Build Coastguard Worker # Verify that all results are present and valid 74*35238bceSAndroid Build Coastguard Worker for ndx in range(len(mustpass)): 75*35238bceSAndroid Build Coastguard Worker caseName = mustpass[ndx] 76*35238bceSAndroid Build Coastguard Worker 77*35238bceSAndroid Build Coastguard Worker if caseName in caseNameToResultNdx: 78*35238bceSAndroid Build Coastguard Worker resultNdx = caseNameToResultNdx[caseName] 79*35238bceSAndroid Build Coastguard Worker result = results[resultNdx] 80*35238bceSAndroid Build Coastguard Worker 81*35238bceSAndroid Build Coastguard Worker if resultNdx != ndx: 82*35238bceSAndroid Build Coastguard Worker resultOrderOk = False 83*35238bceSAndroid Build Coastguard Worker 84*35238bceSAndroid Build Coastguard Worker if not result.statusCode in ALLOWED_STATUS_CODES: 85*35238bceSAndroid Build Coastguard Worker messages.append(error(filename, result.name + ": " + result.statusCode)) 86*35238bceSAndroid Build Coastguard Worker else: 87*35238bceSAndroid Build Coastguard Worker messages.append(error(filename, "Missing result for " + caseName)) 88*35238bceSAndroid Build Coastguard Worker 89*35238bceSAndroid Build Coastguard Worker if len(results) == len(mustpass) and not resultOrderOk: 90*35238bceSAndroid Build Coastguard Worker messages.append(error(filename, "Results are not in the expected order")) 91*35238bceSAndroid Build Coastguard Worker 92*35238bceSAndroid Build Coastguard Worker return messages 93*35238bceSAndroid Build Coastguard Worker 94*35238bceSAndroid Build Coastguard Workerdef beginsWith (str, prefix): 95*35238bceSAndroid Build Coastguard Worker return str[:len(prefix)] == prefix 96*35238bceSAndroid Build Coastguard Worker 97*35238bceSAndroid Build Coastguard Workerdef verifyStatement (package): 98*35238bceSAndroid Build Coastguard Worker messages = [] 99*35238bceSAndroid Build Coastguard Worker 100*35238bceSAndroid Build Coastguard Worker if package.statement != None: 101*35238bceSAndroid Build Coastguard Worker statementPath = os.path.join(package.basePath, package.statement) 102*35238bceSAndroid Build Coastguard Worker statement = readFile(statementPath) 103*35238bceSAndroid Build Coastguard Worker hasVersion = False 104*35238bceSAndroid Build Coastguard Worker hasProduct = False 105*35238bceSAndroid Build Coastguard Worker hasCpu = False 106*35238bceSAndroid Build Coastguard Worker hasOs = False 107*35238bceSAndroid Build Coastguard Worker 108*35238bceSAndroid Build Coastguard Worker for line in statement.splitlines(): 109*35238bceSAndroid Build Coastguard Worker if beginsWith(line, "CONFORM_VERSION:"): 110*35238bceSAndroid Build Coastguard Worker if hasVersion: 111*35238bceSAndroid Build Coastguard Worker messages.append(error(statementPath, "Multiple CONFORM_VERSIONs")) 112*35238bceSAndroid Build Coastguard Worker else: 113*35238bceSAndroid Build Coastguard Worker assert len(line.split()) >= 2 114*35238bceSAndroid Build Coastguard Worker package.conformVersion = line.split()[1] 115*35238bceSAndroid Build Coastguard Worker hasVersion = True 116*35238bceSAndroid Build Coastguard Worker elif beginsWith(line, "PRODUCT:"): 117*35238bceSAndroid Build Coastguard Worker hasProduct = True # Multiple products allowed 118*35238bceSAndroid Build Coastguard Worker elif beginsWith(line, "CPU:"): 119*35238bceSAndroid Build Coastguard Worker if hasCpu: 120*35238bceSAndroid Build Coastguard Worker messages.append(error(statementPath, "Multiple PRODUCTs")) 121*35238bceSAndroid Build Coastguard Worker else: 122*35238bceSAndroid Build Coastguard Worker hasCpu = True 123*35238bceSAndroid Build Coastguard Worker elif beginsWith(line, "OS:"): 124*35238bceSAndroid Build Coastguard Worker if hasOs: 125*35238bceSAndroid Build Coastguard Worker messages.append(error(statementPath, "Multiple OSes")) 126*35238bceSAndroid Build Coastguard Worker else: 127*35238bceSAndroid Build Coastguard Worker assert len(line.split()) >= 2 128*35238bceSAndroid Build Coastguard Worker package.conformOs = line.split()[1] 129*35238bceSAndroid Build Coastguard Worker hasOs = True 130*35238bceSAndroid Build Coastguard Worker 131*35238bceSAndroid Build Coastguard Worker if not hasVersion: 132*35238bceSAndroid Build Coastguard Worker messages.append(error(statementPath, "No CONFORM_VERSION")) 133*35238bceSAndroid Build Coastguard Worker if not hasProduct: 134*35238bceSAndroid Build Coastguard Worker messages.append(error(statementPath, "No PRODUCT")) 135*35238bceSAndroid Build Coastguard Worker if not hasCpu: 136*35238bceSAndroid Build Coastguard Worker messages.append(error(statementPath, "No CPU")) 137*35238bceSAndroid Build Coastguard Worker if not hasOs: 138*35238bceSAndroid Build Coastguard Worker messages.append(error(statementPath, "No OS")) 139*35238bceSAndroid Build Coastguard Worker else: 140*35238bceSAndroid Build Coastguard Worker messages.append(error(package.basePath, "Missing conformance statement file")) 141*35238bceSAndroid Build Coastguard Worker 142*35238bceSAndroid Build Coastguard Worker return messages 143*35238bceSAndroid Build Coastguard Worker 144*35238bceSAndroid Build Coastguard Workerdef verifyGitStatus (package): 145*35238bceSAndroid Build Coastguard Worker messages = [] 146*35238bceSAndroid Build Coastguard Worker 147*35238bceSAndroid Build Coastguard Worker if len(package.gitStatus) > 0: 148*35238bceSAndroid Build Coastguard Worker for s in package.gitStatus: 149*35238bceSAndroid Build Coastguard Worker statusPath = os.path.join(package.basePath, s) 150*35238bceSAndroid Build Coastguard Worker status = readFile(statusPath) 151*35238bceSAndroid Build Coastguard Worker 152*35238bceSAndroid Build Coastguard Worker if status.find("nothing to commit, working directory clean") < 0 and status.find("nothing to commit, working tree clean") < 0: 153*35238bceSAndroid Build Coastguard Worker messages.append(error(package.basePath, "Working directory is not clean")) 154*35238bceSAndroid Build Coastguard Worker else: 155*35238bceSAndroid Build Coastguard Worker messages.append(error(package.basePath, "Missing git status files")) 156*35238bceSAndroid Build Coastguard Worker 157*35238bceSAndroid Build Coastguard Worker return messages 158*35238bceSAndroid Build Coastguard Worker 159*35238bceSAndroid Build Coastguard Workerdef isGitLogEmpty (package, gitLog): 160*35238bceSAndroid Build Coastguard Worker logPath = os.path.join(package.basePath, gitLog) 161*35238bceSAndroid Build Coastguard Worker log = readFile(logPath) 162*35238bceSAndroid Build Coastguard Worker 163*35238bceSAndroid Build Coastguard Worker return len(log.strip()) == 0 164*35238bceSAndroid Build Coastguard Worker 165*35238bceSAndroid Build Coastguard Workerdef verifyGitLog (package): 166*35238bceSAndroid Build Coastguard Worker messages = [] 167*35238bceSAndroid Build Coastguard Worker 168*35238bceSAndroid Build Coastguard Worker if len(package.gitLog) > 0: 169*35238bceSAndroid Build Coastguard Worker for log, path in package.gitLog: 170*35238bceSAndroid Build Coastguard Worker if not isGitLogEmpty(package, log): 171*35238bceSAndroid Build Coastguard Worker messages.append(warning(os.path.join(package.basePath, log), "Log is not empty")) 172*35238bceSAndroid Build Coastguard Worker else: 173*35238bceSAndroid Build Coastguard Worker messages.append(error(package.basePath, "Missing git log files")) 174*35238bceSAndroid Build Coastguard Worker 175*35238bceSAndroid Build Coastguard Worker return messages 176*35238bceSAndroid Build Coastguard Worker 177*35238bceSAndroid Build Coastguard Workerdef verifyPatches (package): 178*35238bceSAndroid Build Coastguard Worker messages = [] 179*35238bceSAndroid Build Coastguard Worker hasPatches = len(package.patches) 180*35238bceSAndroid Build Coastguard Worker logEmpty = True 181*35238bceSAndroid Build Coastguard Worker for log, path in package.gitLog: 182*35238bceSAndroid Build Coastguard Worker logEmpty &= isGitLogEmpty(package, log) 183*35238bceSAndroid Build Coastguard Worker 184*35238bceSAndroid Build Coastguard Worker if hasPatches and logEmpty: 185*35238bceSAndroid Build Coastguard Worker messages.append(error(package.basePath, "Package includes patches but log is empty")) 186*35238bceSAndroid Build Coastguard Worker elif not hasPatches and not logEmpty: 187*35238bceSAndroid Build Coastguard Worker messages.append(error(package.basePath, "Test log is not empty but package doesn't contain patches")) 188*35238bceSAndroid Build Coastguard Worker 189*35238bceSAndroid Build Coastguard Worker return messages 190