liyujie
2025-08-28 786ff4f4ca2374bdd9177f2e24b503d43e7a3b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
 
#-------------------------------------------------------------------------
# drawElements Quality Program utilities
# --------------------------------------
#
# Copyright 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-------------------------------------------------------------------------
 
import re
import sys
from fnmatch import fnmatch
 
def fail (msg):
   print "ERROR: " + msg
   sys.exit(-1)
 
# filename -> [case name]
def readCaseList (filename):
   f = open(filename, 'rb')
   cases = []
   for line in f:
       if line[0:6] == "TEST: ":
           cases.append(line[6:].strip())
   f.close()
   return cases
 
# filename -> [(filter, min, recommended)]
def readResolutionList (filename):
   f = open(filename, 'rb')
   resList = []
   for line in f:
       line = line.strip()
       params = line.split('\t')
       if len(params) == 3:
           resList.append((params[0], params[1], params[2]))
       elif len(params) != 0:
           fail("Invalid line in resolution list: '%s'" % line)
   f.close()
   return resList
 
def getMatchingCases (cases, pattern):
   matching = []
   for case in cases:
       if fnmatch(case, pattern):
           matching.append(case)
   return matching
 
def isResolutionOk (res):
   return re.match('^[1-9][0-9]*x[1-9][0-9]*$', res) != None
 
if __name__ == "__main__":
   if len(sys.argv) != 3:
       print "%s: [caselist] [resolution list]" % sys.argv[0]
       sys.exit(-1)
 
   caseList    = readCaseList(sys.argv[1])
   resList        = readResolutionList(sys.argv[2])
 
   # Pass 1: sanity check for resolution values
   for pattern, minRes, recRes in resList:
       if not isResolutionOk(minRes) or not isResolutionOk(recRes):
           fail("Invalid resolution: '%s %s %s'" % (pattern, minRes, recRes))
 
   # Pass 2: check that each case is specified by one rule
   markedCases = set()
   for pattern, minRes, recRes in resList:
       matchingCases = getMatchingCases(caseList, pattern)
 
       if len(matchingCases) == 0:
           fail("Pattern '%s' does not match any cases" % pattern)
 
       for case in matchingCases:
           if case in markedCases:
               fail("Case '%s' specified multiple times (when processing '%s')" % (case, pattern))
           markedCases.add(case)
 
   for case in caseList:
       if not case in markedCases:
           fail("Case '%s' not specified by any rule" % case)