blob: 6d563c4cd438fbd1a1ad1e5d98dd3f3126ce1577 [file] [log] [blame]
Tobin Ehlis35308dd2016-10-31 13:27:36 -06001#!/usr/bin/env python3
Mike Weiblenfe186122017-02-03 12:44:53 -07002# Copyright (c) 2015-2017 The Khronos Group Inc.
3# Copyright (c) 2015-2017 Valve Corporation
4# Copyright (c) 2015-2017 LunarG, Inc.
5# Copyright (c) 2015-2017 Google Inc.
Tobin Ehlis35308dd2016-10-31 13:27:36 -06006#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19# Author: Tobin Ehlis <tobine@google.com>
20
21import argparse
22import os
23import sys
24import platform
25
26# vk_validation_stats.py overview
27# This script is intended to generate statistics on the state of validation code
28# based on information parsed from the source files and the database file
29# Here's what it currently does:
30# 1. Parse vk_validation_error_database.txt to store claimed state of validation checks
31# 2. Parse vk_validation_error_messages.h to verify the actual checks in header vs. the
32# claimed state of the checks
33# 3. Parse source files to identify which checks are implemented and verify that this
34# exactly matches the list of checks claimed to be implemented in the database
35# 4. Parse test file(s) and verify that reported tests exist
36# 5. Report out stats on number of checks, implemented checks, and duplicated checks
37#
Tobin Ehlis20e32582016-12-05 14:50:03 -070038# If a mis-match is found during steps 2, 3, or 4, then the script exits w/ a non-zero error code
39# otherwise, the script will exit(0)
40#
Tobin Ehlis35308dd2016-10-31 13:27:36 -060041# TODO:
42# 1. Would also like to report out number of existing checks that don't yet use new, unique enum
43# 2. Could use notes to store custom fields (like TODO) and print those out here
44# 3. Update test code to check if tests use new, unique enums to check for errors instead of strings
45
46db_file = 'vk_validation_error_database.txt'
47layer_source_files = [
48'core_validation.cpp',
49'descriptor_sets.cpp',
50'parameter_validation.cpp',
51'object_tracker.cpp',
Chris Forbesb4b19bd2017-06-09 15:41:57 -070052'shader_validation.cpp',
Mark Lobodzinskibfab4a62017-01-27 15:34:37 -070053'buffer_validation.cpp',
Mike Weiblen6a27de52016-12-09 17:36:28 -070054'swapchain.cpp'
Tobin Ehlis35308dd2016-10-31 13:27:36 -060055]
56header_file = 'vk_validation_error_messages.h'
57# TODO : Don't hardcode linux path format if we want this to run on windows
58test_file = '../tests/layer_validation_tests.cpp'
Tobin Ehlis225b59c2016-12-22 13:59:42 -070059# List of enums that are allowed to be used more than once so don't warn on their duplicates
60duplicate_exceptions = [
Tobin Ehlis3c37fb32017-05-24 09:31:13 -060061'VALIDATION_ERROR_258004ea', # This covers the broad case that all child objects must be destroyed at DestroyInstance time
62'VALIDATION_ERROR_24a002f4', # This covers the broad case that all child objects must be destroyed at DestroyDevice time
63'VALIDATION_ERROR_0280006e', # Obj tracker check makes sure non-null framebuffer is valid & CV check makes sure it's compatible w/ renderpass framebuffer
64'VALIDATION_ERROR_12200682', # This is an aliasing error that we report twice, for each of the two allocations that are aliasing
65'VALIDATION_ERROR_1060d201', # Covers valid shader module handle for both Compute & Graphics pipelines
66'VALIDATION_ERROR_0c20c601', # This is a case for VkMappedMemoryRange struct that is used by both Flush & Invalidate MappedMemoryRange
67'VALIDATION_ERROR_0a400c01', # This is a blanket case for all invalid image aspect bit errors. The spec link has appropriate details for all separate cases.
68'VALIDATION_ERROR_0a8007fc', # This case covers two separate checks which are done independently
69'VALIDATION_ERROR_0a800800', # This case covers two separate checks which are done independently
70'VALIDATION_ERROR_15c0028a', # This is a descriptor set write update error that we use for a couple copy cases as well
71'VALIDATION_ERROR_1bc002de', # Single error for mis-matched stageFlags of vkCmdPushConstants() that is flagged for no stage flags & mis-matched flags
72'VALIDATION_ERROR_1880000e', # Handles both depth/stencil & compressed image errors for vkCmdClearColorImage()
73'VALIDATION_ERROR_0a600152', # Used for the mipLevel check of both dst & src images on vkCmdCopyImage call
74'VALIDATION_ERROR_0a600154', # Used for the arraySize check of both dst & src images on vkCmdCopyImage call
75'VALIDATION_ERROR_1500099e', # Used for both x & y bounds of viewport
76'VALIDATION_ERROR_1d8004a6', # Used for both x & y value of scissors to make sure they're not negative
77'VALIDATION_ERROR_1462ec01', # Surface of VkSwapchainCreateInfoKHR must be valid when creating both single or shared swapchains
78'VALIDATION_ERROR_1460de01', # oldSwapchain of VkSwapchainCreateInfoKHR must be valid when creating both single or shared swapchains
79'VALIDATION_ERROR_146009f2', # Single error for both imageFormat & imageColorSpace requirements when creating swapchain
80'VALIDATION_ERROR_15c00294', # Used twice for the same error codepath as both a param & to set a variable, so not really a duplicate
Tobin Ehlis225b59c2016-12-22 13:59:42 -070081]
Tobin Ehlis35308dd2016-10-31 13:27:36 -060082
83class ValidationDatabase:
84 def __init__(self, filename=db_file):
85 self.db_file = filename
86 self.delimiter = '~^~'
87 self.db_dict = {} # complete dict of all db values per error enum
88 # specialized data structs with slices of complete dict
89 self.db_implemented_enums = [] # list of all error enums claiming to be implemented in database file
Tobin Ehlis2bedc242017-01-12 13:45:55 -070090 self.db_unimplemented_implicit = [] # list of all implicit checks that aren't marked implemented
Tobin Ehlis35308dd2016-10-31 13:27:36 -060091 self.db_enum_to_tests = {} # dict where enum is key to lookup list of tests implementing the enum
Mike Weiblenfe186122017-02-03 12:44:53 -070092 self.db_invalid_implemented = [] # list of checks with invalid check_implemented flags
Tobin Ehlis35308dd2016-10-31 13:27:36 -060093 #self.src_implemented_enums
94 def read(self):
95 """Read a database file into internal data structures, format of each line is <enum><implemented Y|N?><testname><api><errormsg><notes>"""
96 #db_dict = {} # This is a simple db of just enum->errormsg, the same as is created from spec
97 #max_id = 0
98 with open(self.db_file, "r") as infile:
99 for line in infile:
100 line = line.strip()
101 if line.startswith('#') or '' == line:
102 continue
103 db_line = line.split(self.delimiter)
Tobin Ehlisf7fc6672017-05-25 14:55:42 -0600104 if len(db_line) != 8:
105 print("ERROR: Bad database line doesn't have 8 elements: %s" % (line))
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600106 error_enum = db_line[0]
107 implemented = db_line[1]
108 testname = db_line[2]
109 api = db_line[3]
Tobin Ehlisf7fc6672017-05-25 14:55:42 -0600110 vuid_string = db_line[4]
111 core_ext = db_line[5]
112 error_str = db_line[6]
113 note = db_line[7]
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600114 # Read complete database contents into our class var for later use
115 self.db_dict[error_enum] = {}
116 self.db_dict[error_enum]['check_implemented'] = implemented
117 self.db_dict[error_enum]['testname'] = testname
118 self.db_dict[error_enum]['api'] = api
Tobin Ehlisf7fc6672017-05-25 14:55:42 -0600119 self.db_dict[error_enum]['vuid_string'] = vuid_string
120 self.db_dict[error_enum]['core_ext'] = core_ext
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600121 self.db_dict[error_enum]['error_string'] = error_str
122 self.db_dict[error_enum]['note'] = note
123 # Now build custom data structs
124 if 'Y' == implemented:
125 self.db_implemented_enums.append(error_enum)
Tobin Ehlis2bedc242017-01-12 13:45:55 -0700126 elif 'implicit' in note: # only make note of non-implemented implicit checks
127 self.db_unimplemented_implicit.append(error_enum)
Mike Weiblenfe186122017-02-03 12:44:53 -0700128 if implemented not in ['Y', 'N']:
129 self.db_invalid_implemented.append(error_enum)
Dave Houltona536fae2017-05-18 15:56:22 -0600130 if testname.lower() not in ['unknown', 'none', 'nottestable']:
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600131 self.db_enum_to_tests[error_enum] = testname.split(',')
132 #if len(self.db_enum_to_tests[error_enum]) > 1:
133 # print "Found check %s that has multiple tests: %s" % (error_enum, self.db_enum_to_tests[error_enum])
134 #else:
135 # print "Check %s has single test: %s" % (error_enum, self.db_enum_to_tests[error_enum])
136 #unique_id = int(db_line[0].split('_')[-1])
137 #if unique_id > max_id:
138 # max_id = unique_id
139 #print "Found %d total enums in database" % (len(self.db_dict.keys()))
140 #print "Found %d enums claiming to be implemented in source" % (len(self.db_implemented_enums))
141 #print "Found %d enums claiming to have tests implemented" % (len(self.db_enum_to_tests.keys()))
142
143class ValidationHeader:
144 def __init__(self, filename=header_file):
145 self.filename = header_file
146 self.enums = []
147 def read(self):
148 """Read unique error enum header file into internal data structures"""
149 grab_enums = False
150 with open(self.filename, "r") as infile:
151 for line in infile:
152 line = line.strip()
153 if 'enum UNIQUE_VALIDATION_ERROR_CODE {' in line:
154 grab_enums = True
155 continue
156 if grab_enums:
157 if 'VALIDATION_ERROR_MAX_ENUM' in line:
158 grab_enums = False
159 break # done
Tobin Ehlisf53eac32016-12-09 14:10:47 -0700160 elif 'VALIDATION_ERROR_UNDEFINED' in line:
161 continue
162 elif 'VALIDATION_ERROR_' in line:
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600163 enum = line.split(' = ')[0]
164 self.enums.append(enum)
165 #print "Found %d error enums. First is %s and last is %s." % (len(self.enums), self.enums[0], self.enums[-1])
166
167class ValidationSource:
168 def __init__(self, source_file_list):
169 self.source_files = source_file_list
Tobin Ehlis3d1f2bd2016-12-22 11:19:15 -0700170 self.enum_count_dict = {} # dict of enum values to the count of how much they're used, and location of where they're used
Mark Lobodzinski996fd042017-06-06 13:59:27 -0600171 # 1500099c is a special case that provides an exception when an extension is enabled. No specific error is flagged, but the exception is handled so add it here
Tobin Ehlis3c37fb32017-05-24 09:31:13 -0600172 self.enum_count_dict['VALIDATION_ERROR_1500099c'] = {}
173 self.enum_count_dict['VALIDATION_ERROR_1500099c']['count'] = 1
Mark Lobodzinski082844a2017-06-02 16:31:30 -0600174 self.enum_count_dict['VALIDATION_ERROR_1500099c']['file_line'] = []
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600175 def parse(self):
176 duplicate_checks = 0
177 for sf in self.source_files:
Tobin Ehlis3d1f2bd2016-12-22 11:19:15 -0700178 line_num = 0
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600179 with open(sf) as f:
180 for line in f:
Tobin Ehlis3d1f2bd2016-12-22 11:19:15 -0700181 line_num = line_num + 1
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600182 if True in [line.strip().startswith(comment) for comment in ['//', '/*']]:
183 continue
184 # Find enums
185 #if 'VALIDATION_ERROR_' in line and True not in [ignore in line for ignore in ['[VALIDATION_ERROR_', 'UNIQUE_VALIDATION_ERROR_CODE']]:
Tobin Ehlisf53eac32016-12-09 14:10:47 -0700186 if ' VALIDATION_ERROR_' in line:
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600187 # Need to isolate the validation error enum
188 #print("Line has check:%s" % (line))
189 line_list = line.split()
Tobin Ehlis928742e2016-12-09 17:11:13 -0700190 enum_list = []
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600191 for str in line_list:
Tobin Ehlisf53eac32016-12-09 14:10:47 -0700192 if 'VALIDATION_ERROR_' in str and True not in [ignore_str in str for ignore_str in ['[VALIDATION_ERROR_', 'VALIDATION_ERROR_UNDEFINED', 'UNIQUE_VALIDATION_ERROR_CODE']]:
Tobin Ehlis928742e2016-12-09 17:11:13 -0700193 enum_list.append(str.strip(',);'))
194 #break
195 for enum in enum_list:
196 if enum != '':
197 if enum not in self.enum_count_dict:
Tobin Ehlis3d1f2bd2016-12-22 11:19:15 -0700198 self.enum_count_dict[enum] = {}
199 self.enum_count_dict[enum]['count'] = 1
200 self.enum_count_dict[enum]['file_line'] = []
201 self.enum_count_dict[enum]['file_line'].append('%s,%d' % (sf, line_num))
Tobin Ehlis928742e2016-12-09 17:11:13 -0700202 #print "Found enum %s implemented for first time in file %s" % (enum, sf)
203 else:
Tobin Ehlis3d1f2bd2016-12-22 11:19:15 -0700204 self.enum_count_dict[enum]['count'] = self.enum_count_dict[enum]['count'] + 1
205 self.enum_count_dict[enum]['file_line'].append('%s,%d' % (sf, line_num))
Tobin Ehlis928742e2016-12-09 17:11:13 -0700206 #print "Found enum %s implemented for %d time in file %s" % (enum, self.enum_count_dict[enum], sf)
207 duplicate_checks = duplicate_checks + 1
208 #else:
209 #print("Didn't find actual check in line:%s" % (line))
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600210 #print "Found %d unique implemented checks and %d are duplicated at least once" % (len(self.enum_count_dict.keys()), duplicate_checks)
211
212# Class to parse the validation layer test source and store testnames
213# TODO: Enhance class to detect use of unique error enums in the test
214class TestParser:
215 def __init__(self, test_file_list, test_group_name=['VkLayerTest', 'VkPositiveLayerTest', 'VkWsiEnabledLayerTest']):
216 self.test_files = test_file_list
Tobin Ehlis9a68c982016-12-29 14:51:17 -0700217 self.test_to_errors = {} # Dict where testname maps to list of error enums found in that test
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600218 self.test_trigger_txt_list = []
219 for tg in test_group_name:
220 self.test_trigger_txt_list.append('TEST_F(%s' % tg)
221 #print('Test trigger test list: %s' % (self.test_trigger_txt_list))
222
223 # Parse test files into internal data struct
224 def parse(self):
225 # For each test file, parse test names into set
226 grab_next_line = False # handle testname on separate line than wildcard
Tobin Ehlis9a68c982016-12-29 14:51:17 -0700227 testname = ''
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600228 for test_file in self.test_files:
229 with open(test_file) as tf:
230 for line in tf:
231 if True in [line.strip().startswith(comment) for comment in ['//', '/*']]:
232 continue
233
234 if True in [ttt in line for ttt in self.test_trigger_txt_list]:
235 #print('Test wildcard in line: %s' % (line))
236 testname = line.split(',')[-1]
237 testname = testname.strip().strip(' {)')
238 #print('Inserting test: "%s"' % (testname))
239 if ('' == testname):
240 grab_next_line = True
241 continue
Tobin Ehlis9a68c982016-12-29 14:51:17 -0700242 self.test_to_errors[testname] = []
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600243 if grab_next_line: # test name on its own line
244 grab_next_line = False
245 testname = testname.strip().strip(' {)')
Tobin Ehlis9a68c982016-12-29 14:51:17 -0700246 self.test_to_errors[testname] = []
247 if ' VALIDATION_ERROR_' in line:
248 line_list = line.split()
Tobin Ehlis71f38c12017-01-12 14:26:56 -0700249 for sub_str in line_list:
250 if 'VALIDATION_ERROR_' in sub_str and True not in [ignore_str in sub_str for ignore_str in ['VALIDATION_ERROR_UNDEFINED', 'UNIQUE_VALIDATION_ERROR_CODE', 'VALIDATION_ERROR_MAX_ENUM']]:
251 #print("Trying to add enums for line: %s" % ())
252 #print("Adding enum %s to test %s" % (sub_str.strip(',);'), testname))
253 self.test_to_errors[testname].append(sub_str.strip(',);'))
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600254
255# Little helper class for coloring cmd line output
256class bcolors:
257
258 def __init__(self):
259 self.GREEN = '\033[0;32m'
260 self.RED = '\033[0;31m'
261 self.YELLOW = '\033[1;33m'
262 self.ENDC = '\033[0m'
263 if 'Linux' != platform.system():
264 self.GREEN = ''
265 self.RED = ''
266 self.YELLOW = ''
267 self.ENDC = ''
268
269 def green(self):
270 return self.GREEN
271
272 def red(self):
273 return self.RED
274
275 def yellow(self):
276 return self.YELLOW
277
278 def endc(self):
279 return self.ENDC
280
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600281def main(argv=None):
Tobin Ehlis20e32582016-12-05 14:50:03 -0700282 result = 0 # Non-zero result indicates an error case
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600283 # parse db
284 val_db = ValidationDatabase()
285 val_db.read()
286 # parse header
287 val_header = ValidationHeader()
288 val_header.read()
289 # Create parser for layer files
290 val_source = ValidationSource(layer_source_files)
291 val_source.parse()
292 # Parse test files
293 test_parser = TestParser([test_file, ])
294 test_parser.parse()
295
296 # Process stats - Just doing this inline in main, could make a fancy class to handle
297 # all the processing of data and then get results from that
298 txt_color = bcolors()
Mike Weiblenfe186122017-02-03 12:44:53 -0700299
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600300 print("Validation Statistics")
301 # First give number of checks in db & header and report any discrepancies
302 db_enums = len(val_db.db_dict.keys())
303 hdr_enums = len(val_header.enums)
304 print(" Database file includes %d unique checks" % (db_enums))
305 print(" Header file declares %d unique checks" % (hdr_enums))
Mike Weiblenfe186122017-02-03 12:44:53 -0700306
307 # Report any checks that have an invalid check_implemented flag
308 if len(val_db.db_invalid_implemented) > 0:
309 result = 1
310 print(txt_color.red() + "The following checks have an invalid check_implemented flag (must be 'Y' or 'N'):" + txt_color.endc())
311 for invalid_imp_enum in val_db.db_invalid_implemented:
312 check_implemented = val_db.db_dict[invalid_imp_enum]['check_implemented']
313 print(txt_color.red() + " %s has check_implemented flag '%s'" % (invalid_imp_enum, check_implemented) + txt_color.endc())
314
315 # Report details about how well the Database and Header are synchronized.
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600316 tmp_db_dict = val_db.db_dict
317 db_missing = []
318 for enum in val_header.enums:
319 if not tmp_db_dict.pop(enum, False):
320 db_missing.append(enum)
321 if db_enums == hdr_enums and len(db_missing) == 0 and len(tmp_db_dict.keys()) == 0:
322 print(txt_color.green() + " Database and Header match, GREAT!" + txt_color.endc())
323 else:
324 print(txt_color.red() + " Uh oh, Database doesn't match Header :(" + txt_color.endc())
Tobin Ehlis20e32582016-12-05 14:50:03 -0700325 result = 1
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600326 if len(db_missing) != 0:
327 print(txt_color.red() + " The following checks are in header but missing from database:" + txt_color.endc())
328 for missing_enum in db_missing:
329 print(txt_color.red() + " %s" % (missing_enum) + txt_color.endc())
330 if len(tmp_db_dict.keys()) != 0:
331 print(txt_color.red() + " The following checks are in database but haven't been declared in the header:" + txt_color.endc())
332 for extra_enum in tmp_db_dict:
333 print(txt_color.red() + " %s" % (extra_enum) + txt_color.endc())
Mike Weiblenfe186122017-02-03 12:44:53 -0700334
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600335 # Report out claimed implemented checks vs. found actual implemented checks
336 imp_not_found = [] # Checks claimed to implemented in DB file but no source found
337 imp_not_claimed = [] # Checks found implemented but not claimed to be in DB
338 multiple_uses = False # Flag if any enums are used multiple times
339 for db_imp in val_db.db_implemented_enums:
340 if db_imp not in val_source.enum_count_dict:
341 imp_not_found.append(db_imp)
342 for src_enum in val_source.enum_count_dict:
Tobin Ehlis225b59c2016-12-22 13:59:42 -0700343 if val_source.enum_count_dict[src_enum]['count'] > 1 and src_enum not in duplicate_exceptions:
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600344 multiple_uses = True
345 if src_enum not in val_db.db_implemented_enums:
346 imp_not_claimed.append(src_enum)
347 print(" Database file claims that %d checks (%s) are implemented in source." % (len(val_db.db_implemented_enums), "{0:.0f}%".format(float(len(val_db.db_implemented_enums))/db_enums * 100)))
Mike Weiblenfe186122017-02-03 12:44:53 -0700348
Tobin Ehlis2bedc242017-01-12 13:45:55 -0700349 if len(val_db.db_unimplemented_implicit) > 0:
350 print(" Database file claims %d implicit checks (%s) that are not implemented." % (len(val_db.db_unimplemented_implicit), "{0:.0f}%".format(float(len(val_db.db_unimplemented_implicit))/db_enums * 100)))
351 total_checks = len(val_db.db_implemented_enums) + len(val_db.db_unimplemented_implicit)
352 print(" If all implicit checks are handled by parameter validation this is a total of %d (%s) checks covered." % (total_checks, "{0:.0f}%".format(float(total_checks)/db_enums * 100)))
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600353 if len(imp_not_found) == 0 and len(imp_not_claimed) == 0:
354 print(txt_color.green() + " All claimed Database implemented checks have been found in source, and no source checks aren't claimed in Database, GREAT!" + txt_color.endc())
355 else:
Tobin Ehlis20e32582016-12-05 14:50:03 -0700356 result = 1
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600357 print(txt_color.red() + " Uh oh, Database claimed implemented don't match Source :(" + txt_color.endc())
358 if len(imp_not_found) != 0:
Tobin Ehlis3f0b2772016-11-18 16:56:15 -0700359 print(txt_color.red() + " The following %d checks are claimed to be implemented in Database, but weren't found in source:" % (len(imp_not_found)) + txt_color.endc())
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600360 for not_imp_enum in imp_not_found:
361 print(txt_color.red() + " %s" % (not_imp_enum) + txt_color.endc())
362 if len(imp_not_claimed) != 0:
363 print(txt_color.red() + " The following checks are implemented in source, but not claimed to be in Database:" + txt_color.endc())
364 for imp_enum in imp_not_claimed:
365 print(txt_color.red() + " %s" % (imp_enum) + txt_color.endc())
Mike Weiblenfe186122017-02-03 12:44:53 -0700366
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600367 if multiple_uses:
368 print(txt_color.yellow() + " Note that some checks are used multiple times. These may be good candidates for new valid usage spec language." + txt_color.endc())
369 print(txt_color.yellow() + " Here is a list of each check used multiple times with its number of uses:" + txt_color.endc())
370 for enum in val_source.enum_count_dict:
Tobin Ehlis225b59c2016-12-22 13:59:42 -0700371 if val_source.enum_count_dict[enum]['count'] > 1 and enum not in duplicate_exceptions:
Tobin Ehlis3d1f2bd2016-12-22 11:19:15 -0700372 print(txt_color.yellow() + " %s: %d uses in file,line:" % (enum, val_source.enum_count_dict[enum]['count']) + txt_color.endc())
373 for file_line in val_source.enum_count_dict[enum]['file_line']:
374 print(txt_color.yellow() + " \t%s" % (file_line) + txt_color.endc())
Mike Weiblenfe186122017-02-03 12:44:53 -0700375
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600376 # Now check that tests claimed to be implemented are actual test names
377 bad_testnames = []
Tobin Ehlis9a68c982016-12-29 14:51:17 -0700378 tests_missing_enum = {} # Report tests that don't use validation error enum to check for error case
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600379 for enum in val_db.db_enum_to_tests:
380 for testname in val_db.db_enum_to_tests[enum]:
Tobin Ehlis9a68c982016-12-29 14:51:17 -0700381 if testname not in test_parser.test_to_errors:
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600382 bad_testnames.append(testname)
Tobin Ehlis9a68c982016-12-29 14:51:17 -0700383 else:
384 enum_found = False
385 for test_enum in test_parser.test_to_errors[testname]:
386 if test_enum == enum:
387 #print("Found test that correctly checks for enum: %s" % (enum))
388 enum_found = True
389 if not enum_found:
390 #print("Test %s is not using enum %s to check for error" % (testname, enum))
391 if testname not in tests_missing_enum:
392 tests_missing_enum[testname] = []
393 tests_missing_enum[testname].append(enum)
394 if tests_missing_enum:
395 print(txt_color.yellow() + " \nThe following tests do not use their reported enums to check for the validation error. You may want to update these to pass the expected enum to SetDesiredFailureMsg:" + txt_color.endc())
396 for testname in tests_missing_enum:
397 print(txt_color.yellow() + " Testname %s does not explicitly check for these ids:" % (testname) + txt_color.endc())
398 for enum in tests_missing_enum[testname]:
399 print(txt_color.yellow() + " %s" % (enum) + txt_color.endc())
Mike Weiblenfe186122017-02-03 12:44:53 -0700400
Tobin Ehlis9a68c982016-12-29 14:51:17 -0700401 # TODO : Go through all enums found in the test file and make sure they're correctly documented in the database file
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600402 print(" Database file claims that %d checks have tests written." % len(val_db.db_enum_to_tests))
403 if len(bad_testnames) == 0:
404 print(txt_color.green() + " All claimed tests have valid names. That's good!" + txt_color.endc())
405 else:
406 print(txt_color.red() + " The following testnames in Database appear to be invalid:")
Tobin Ehlis20e32582016-12-05 14:50:03 -0700407 result = 1
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600408 for bt in bad_testnames:
Tobin Ehlisb04c2c62016-11-21 15:51:45 -0700409 print(txt_color.red() + " %s" % (bt) + txt_color.endc())
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600410
Tobin Ehlis20e32582016-12-05 14:50:03 -0700411 return result
Tobin Ehlis35308dd2016-10-31 13:27:36 -0600412
413if __name__ == "__main__":
414 sys.exit(main())
415