1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 The Android Open Source Project
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 #-------------------------------------------------------------------------
25 from fnmatch import fnmatch
31 # filename -> [case name]
32 def readCaseList (filename):
33 f = open(filename, 'rb')
36 if line[0:6] == "TEST: ":
37 cases.append(line[6:].strip())
41 # filename -> [(filter, min, recommended)]
42 def readResolutionList (filename):
43 f = open(filename, 'rb')
47 params = line.split('\t')
49 resList.append((params[0], params[1], params[2]))
50 elif len(params) != 0:
51 fail("Invalid line in resolution list: '%s'" % line)
55 def getMatchingCases (cases, pattern):
58 if fnmatch(case, pattern):
62 def isResolutionOk (res):
63 return re.match('^[1-9][0-9]*x[1-9][0-9]*$', res) != None
65 if __name__ == "__main__":
66 if len(sys.argv) != 3:
67 print "%s: [caselist] [resolution list]" % sys.argv[0]
70 caseList = readCaseList(sys.argv[1])
71 resList = readResolutionList(sys.argv[2])
73 # Pass 1: sanity check for resolution values
74 for pattern, minRes, recRes in resList:
75 if not isResolutionOk(minRes) or not isResolutionOk(recRes):
76 fail("Invalid resolution: '%s %s %s'" % (pattern, minRes, recRes))
78 # Pass 2: check that each case is specified by one rule
80 for pattern, minRes, recRes in resList:
81 matchingCases = getMatchingCases(caseList, pattern)
83 if len(matchingCases) == 0:
84 fail("Pattern '%s' does not match any cases" % pattern)
86 for case in matchingCases:
87 if case in markedCases:
88 fail("Case '%s' specified multiple times (when processing '%s')" % (case, pattern))
92 if not case in markedCases:
93 fail("Case '%s' not specified by any rule" % case)