1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
7 # Copyright (c) 2016 Google Inc.
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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.
21 #-------------------------------------------------------------------------
26 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "log"))
27 sys.path.append(os.path.join(os.path.dirname(__file__), "..", "build"))
29 from common import readFile
31 from log_parser import StatusCode, BatchResultParser
33 ALLOWED_STATUS_CODES = set([
35 StatusCode.NOT_SUPPORTED,
36 StatusCode.QUALITY_WARNING,
37 StatusCode.COMPATIBILITY_WARNING
40 def readMustpass (filename):
41 f = open(filename, 'rb')
49 def readTestLog (filename):
50 parser = BatchResultParser()
51 return parser.parseFile(filename)
53 def verifyTestLog (filename, mustpass):
54 results = readTestLog(filename)
58 # Mustpass case names must be unique
59 assert len(mustpass) == len(set(mustpass))
61 # Verify number of results
62 if len(results) != len(mustpass):
63 messages.append(error(filename, "Wrong number of test results, expected %d, found %d" % (len(mustpass), len(results))))
65 caseNameToResultNdx = {}
66 for ndx in xrange(len(results)):
68 if not result in caseNameToResultNdx:
69 caseNameToResultNdx[result.name] = ndx
71 messages.append(error(filename, "Multiple results for " + result.name))
73 # Verify that all results are present and valid
74 for ndx in xrange(len(mustpass)):
75 caseName = mustpass[ndx]
77 if caseName in caseNameToResultNdx:
78 resultNdx = caseNameToResultNdx[caseName]
79 result = results[resultNdx]
84 if not result.statusCode in ALLOWED_STATUS_CODES:
85 messages.append(error(filename, result.name + ": " + result.statusCode))
87 messages.append(error(filename, "Missing result for " + caseName))
89 if len(results) == len(mustpass) and not resultOrderOk:
90 messages.append(error(filename, "Results are not in the expected order"))
94 def beginsWith (str, prefix):
95 return str[:len(prefix)] == prefix
97 def verifyStatement (package):
100 if package.statement != None:
101 statementPath = os.path.join(package.basePath, package.statement)
102 statement = readFile(statementPath)
108 for line in statement.splitlines():
109 if beginsWith(line, "CONFORM_VERSION:"):
111 messages.append(error(statementPath, "Multiple CONFORM_VERSIONs"))
113 assert len(line.split()) >= 2
114 package.conformVersion = line.split()[1]
116 elif beginsWith(line, "PRODUCT:"):
117 hasProduct = True # Multiple products allowed
118 elif beginsWith(line, "CPU:"):
120 messages.append(error(statementPath, "Multiple PRODUCTs"))
123 elif beginsWith(line, "OS:"):
125 messages.append(error(statementPath, "Multiple OSes"))
127 assert len(line.split()) >= 2
128 package.conformOs = line.split()[1]
132 messages.append(error(statementPath, "No CONFORM_VERSION"))
134 messages.append(error(statementPath, "No PRODUCT"))
136 messages.append(error(statementPath, "No CPU"))
138 messages.append(error(statementPath, "No OS"))
140 messages.append(error(package.basePath, "Missing conformance statement file"))
144 def verifyGitStatus (package):
147 if len(package.gitStatus) > 0:
148 for s in package.gitStatus:
149 statusPath = os.path.join(package.basePath, s)
150 status = readFile(statusPath)
152 if status.find("nothing to commit, working directory clean") < 0 and status.find("nothing to commit, working tree clean") < 0:
153 messages.append(error(package.basePath, "Working directory is not clean"))
155 messages.append(error(package.basePath, "Missing git status files"))
159 def isGitLogEmpty (package, gitLog):
160 logPath = os.path.join(package.basePath, gitLog)
161 log = readFile(logPath)
163 return len(log.strip()) == 0
165 def verifyGitLog (package):
168 if len(package.gitLog) > 0:
169 for log, path in package.gitLog:
170 if not isGitLogEmpty(package, log):
171 messages.append(warning(os.path.join(package.basePath, log), "Log is not empty"))
173 messages.append(error(package.basePath, "Missing git log files"))
177 def verifyPatches (package):
179 hasPatches = len(package.patches)
181 for log, path in package.gitLog:
182 logEmpty &= isGitLogEmpty(package, log)
184 if hasPatches and logEmpty:
185 messages.append(error(package.basePath, "Package includes patches but log is empty"))
186 elif not hasPatches and not logEmpty:
187 messages.append(error(package.basePath, "Test log is not empty but package doesn't contain patches"))