From: Boris Zanin Date: Wed, 10 Jan 2018 12:15:36 +0000 (+0100) Subject: Add INTxx_MAX checks into check_all.py X-Git-Tag: upstream/1.3.5~2830 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6b79fc4088417d29f263cf6fa592d3bc3ae63a21;p=platform%2Fupstream%2FVK-GL-CTS.git Add INTxx_MAX checks into check_all.py The mentioned consts are not defined in Windows, but are defined in linux. Presence of this consts breaks Windows builds. To make it easyily detectable under linux additional check for [U]INT[8,16,32,64]_MAX consts is added into check_all.py script. Components: Framework VK-GL-CTS Issue: 934 Change-Id: I1882c0cd283a63a623972cb69ffb292531e37d10 --- diff --git a/scripts/src_util/check_all.py b/scripts/src_util/check_all.py index b8378a54e..4fc2abc0e 100644 --- a/scripts/src_util/check_all.py +++ b/scripts/src_util/check_all.py @@ -26,7 +26,7 @@ from common import getChangedFiles, getAllProjectFiles from check_include_guards import checkIncludeGuards from check_whitespace import checkWhitespace from check_license import checkLicense -from check_invalid_types import checkInvalidTypes +from check_invalid_literals import checkInvalidLiterals if __name__ == "__main__": parser = ArgumentParser() @@ -44,7 +44,7 @@ if __name__ == "__main__": checkWhitespace(files), checkIncludeGuards(files), checkLicense(files), - checkInvalidTypes(files), + checkInvalidLiterals(files), #todo checkRedundantIncludeGuards(files), ]) diff --git a/scripts/src_util/check_invalid_literals.py b/scripts/src_util/check_invalid_literals.py new file mode 100644 index 000000000..8f7f79e91 --- /dev/null +++ b/scripts/src_util/check_invalid_literals.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- + +#------------------------------------------------------------------------- +# drawElements Quality Program utilities +# -------------------------------------- +# +# Copyright (c) 2017 The Khronos Group Inc. +# +# 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 os +import re +import sys +from argparse import ArgumentParser +from common import getChangedFiles, getAllProjectFiles, isTextFile + +CHECK_LITERAL_PATTERNS = [ + r'\b[us]*int[0-9]+_t\b', + r'\b[U]*INT(_LEAST|_FAST|)[0-9]+_MAX\b', +] + +CHECK_LIST = [ + ".cpp", + ".hpp", + ".c", + ".h", +] + +EXCLUSION_LIST = [ + "framework/delibs/debase/deDefs.h", + "framework/platform/android/tcuAndroidPlatform.cpp", + "framework/platform/android/tcuAndroidWindow.hpp", + "framework/platform/android/tcuAndroidWindow.cpp", + "framework/platform/lnx/X11/tcuLnxX11Xcb.cpp", + "framework/platform/lnx/wayland/tcuLnxWayland.hpp", + "framework/platform/lnx/wayland/tcuLnxWayland.cpp", +] + +def checkEnds(line, ends): + return any(line.endswith(end) for end in ends) + +def checkFileInvalidLiterals (file): + error = False + + if checkEnds(file.replace("\\", "/"), CHECK_LIST) and not checkEnds(file.replace("\\", "/"), EXCLUSION_LIST): + f = open(file, 'rb') + for lineNum, line in enumerate(f): + # Remove inline comments + idx = line.find("//") + if idx > 0: + line = line[:idx] + # Remove text in quoted literals + if line.find("\"") > 0: + list = line.split('"') + del list[1::2] + line = ' ' + line = line.join(list) + for pattern in CHECK_LITERAL_PATTERNS: + found = re.search(pattern, line) + if found is not None: + error = True + print "%s:%i Unacceptable type found (pattern:%s)" % (file, lineNum+1, pattern) + f.close() + + return not error + +def checkInvalidLiterals (files): + error = False + for file in files: + if isTextFile(file): + if not checkFileInvalidLiterals(file): + error = True + + return not error + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-e", "--only-errors", action="store_true", dest="onlyErrors", default=False, help="Print only on error") + parser.add_argument("-i", "--only-changed", action="store_true", dest="useGitIndex", default=False, help="Check only modified files. Uses git.") + + args = parser.parse_args() + + if args.useGitIndex: + files = getChangedFiles() + else: + files = getAllProjectFiles() + + error = not checkInvalidLiterals(files) + + if error: + print "One or more checks failed" + sys.exit(1) + if not args.onlyErrors: + print "All checks passed" diff --git a/scripts/src_util/check_invalid_types.py b/scripts/src_util/check_invalid_types.py deleted file mode 100644 index a4f10a298..000000000 --- a/scripts/src_util/check_invalid_types.py +++ /dev/null @@ -1,100 +0,0 @@ -# -*- coding: utf-8 -*- - -#------------------------------------------------------------------------- -# drawElements Quality Program utilities -# -------------------------------------- -# -# Copyright (c) 2017 The Khronos Group Inc. -# -# 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 os -import re -import sys -from argparse import ArgumentParser -from common import getChangedFiles, getAllProjectFiles, isTextFile - -CHECK_LIST = [ - ".cpp", - ".hpp", - ".c", - ".h", -] - -EXCLUSION_LIST = [ - "framework/delibs/debase/deDefs.h", - "framework/platform/android/tcuAndroidPlatform.cpp", - "framework/platform/android/tcuAndroidWindow.hpp", - "framework/platform/android/tcuAndroidWindow.cpp", - "framework/platform/lnx/X11/tcuLnxX11Xcb.cpp", - "framework/platform/lnx/wayland/tcuLnxWayland.hpp", - "framework/platform/lnx/wayland/tcuLnxWayland.cpp", -] - -def checkEnds(line, ends): - return any(line.endswith(end) for end in ends) - -def checkFileInvalidTypes (file): - error = False - - if checkEnds(file.replace("\\", "/"), CHECK_LIST) and not checkEnds(file.replace("\\", "/"), EXCLUSION_LIST): - f = open(file, 'rb') - for lineNum, line in enumerate(f): - # Remove inline comments - idx = line.find("//") - if idx > 0: - line = line[:idx] - # Remove text in quoted literals - if line.find("\"") > 0: - list = line.split('"') - del list[1::2] - line = ' ' - line = line.join(list) - found = re.search(r'\b[us]*int[0-9]+_t\b', line) - if found is not None: - error = True - print "%s:%i Unacceptable type found" % (file, lineNum+1) - f.close() - - return not error - -def checkInvalidTypes (files): - error = False - for file in files: - if isTextFile(file): - if not checkFileInvalidTypes(file): - error = True - - return not error - -if __name__ == "__main__": - parser = ArgumentParser() - parser.add_argument("-e", "--only-errors", action="store_true", dest="onlyErrors", default=False, help="Print only on error") - parser.add_argument("-i", "--only-changed", action="store_true", dest="useGitIndex", default=False, help="Check only modified files. Uses git.") - - args = parser.parse_args() - - if args.useGitIndex: - files = getChangedFiles() - else: - files = getAllProjectFiles() - - error = not checkInvalidTypes(files) - - if error: - print "One or more checks failed" - sys.exit(1) - if not args.onlyErrors: - print "All checks passed"