tint: add parse_hlsl_errors.py to help triage hlsl errors

Change-Id: If160a8c72c407874060024c365faca83722b541f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/103760
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2022-10-04 19:48:41 +00:00 committed by Dawn LUCI CQ
parent 1dbda6f254
commit cf47d6147c
1 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,74 @@
#!/usr/bin/env python3
# Copyright 2021 The Tint Authors.
#
# 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.
# Parses expected.*.hlsl files for errors and outputs a report.
#
# Usage:
# parse_hlsl_erors
import glob
import re
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--list-files', dest='list_files', action='store_true')
parser.add_argument('--no-list-files', dest='list_files', action='store_false')
parser.set_defaults(list_files=True)
args = parser.parse_args()
def add_error(error_to_file, error, file):
if not error in error_to_file:
error_to_file[error] = [file]
else:
error_to_file[error].append(file)
def find_and_print_errors(glob_pathname):
files = glob.glob(glob_pathname, recursive=True)
error_to_file = {}
for f in files:
found_error = False
with open(f, "r") as fs:
first_line = fs.readline()
if not first_line.startswith("SKIP:"):
continue
for line in fs:
m = re.search('error( X[0-9]+)*?:(.*)', line)
if m:
add_error(error_to_file, m.group(), f)
found_error = True
else:
if "exit status" in line:
add_error(error_to_file, line, f)
found_error = True
if found_error:
break # Stop on first error string found
if not found_error:
# If no error message was found, add the SKIP line as it may contain the reason for skipping
add_error(error_to_file, first_line.strip(), f)
for error,files in sorted(error_to_file.items()):
print('{} (count: {})'.format(error, len(files)))
if args.list_files:
for f in files:
print('\t{}'.format(f))
print("=== FXC ===")
find_and_print_errors('./**/*.fxc.hlsl')
print("=== DXC ===")
find_and_print_errors('./**/*.dxc.hlsl')