Home | History | Annotate | Download | only in scripts
      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 re
     24 import sys
     25 from fnmatch import fnmatch
     26 
     27 def fail (msg):
     28 	print "ERROR: " + msg
     29 	sys.exit(-1)
     30 
     31 # filename -> [case name]
     32 def readCaseList (filename):
     33 	f = open(filename, 'rb')
     34 	cases = []
     35 	for line in f:
     36 		if line[0:6] == "TEST: ":
     37 			cases.append(line[6:].strip())
     38 	f.close()
     39 	return cases
     40 
     41 # filename -> [(filter, min, recommended)]
     42 def readResolutionList (filename):
     43 	f = open(filename, 'rb')
     44 	resList = []
     45 	for line in f:
     46 		line = line.strip()
     47 		params = line.split('\t')
     48 		if len(params) == 3:
     49 			resList.append((params[0], params[1], params[2]))
     50 		elif len(params) != 0:
     51 			fail("Invalid line in resolution list: '%s'" % line)
     52 	f.close()
     53 	return resList
     54 
     55 def getMatchingCases (cases, pattern):
     56 	matching = []
     57 	for case in cases:
     58 		if fnmatch(case, pattern):
     59 			matching.append(case)
     60 	return matching
     61 
     62 def isResolutionOk (res):
     63 	return re.match('^[1-9][0-9]*x[1-9][0-9]*$', res) != None
     64 
     65 if __name__ == "__main__":
     66 	if len(sys.argv) != 3:
     67 		print "%s: [caselist] [resolution list]" % sys.argv[0]
     68 		sys.exit(-1)
     69 
     70 	caseList	= readCaseList(sys.argv[1])
     71 	resList		= readResolutionList(sys.argv[2])
     72 
     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))
     77 
     78 	# Pass 2: check that each case is specified by one rule
     79 	markedCases = set()
     80 	for pattern, minRes, recRes in resList:
     81 		matchingCases = getMatchingCases(caseList, pattern)
     82 
     83 		if len(matchingCases) == 0:
     84 			fail("Pattern '%s' does not match any cases" % pattern)
     85 
     86 		for case in matchingCases:
     87 			if case in markedCases:
     88 				fail("Case '%s' specified multiple times (when processing '%s')" % (case, pattern))
     89 			markedCases.add(case)
     90 
     91 	for case in caseList:
     92 		if not case in markedCases:
     93 			fail("Case '%s' not specified by any rule" % case)
     94