Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | # Copyright 2021 The Dawn & Tint Authors |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 4 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are met: |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 7 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 8 | # 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | # list of conditions and the following disclaimer. |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 10 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | # this list of conditions and the following disclaimer in the documentation |
| 13 | # and/or other materials provided with the distribution. |
| 14 | # |
| 15 | # 3. Neither the name of the copyright holder nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 23 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 25 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 26 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 27 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 29 | |
| 30 | # Parses expected.*.hlsl files for errors and outputs a report. |
| 31 | # |
| 32 | # Usage: |
| 33 | # parse_hlsl_erors |
| 34 | |
| 35 | import glob |
| 36 | import re |
| 37 | import argparse |
| 38 | |
| 39 | parser = argparse.ArgumentParser() |
| 40 | parser.add_argument('--list-files', dest='list_files', action='store_true') |
| 41 | parser.add_argument('--no-list-files', dest='list_files', action='store_false') |
| 42 | parser.set_defaults(list_files=True) |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 43 | parser.add_argument('--ir-only', dest='ir_only', action='store_false') |
| 44 | parser.set_defaults(ir_only=False) |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 45 | args = parser.parse_args() |
| 46 | |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 47 | def add_error(error_to_files, error, file): |
| 48 | error = error.strip() |
| 49 | if not error in error_to_files: |
| 50 | error_to_files[error] = [file] |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 51 | else: |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 52 | error_to_files[error].append(file) |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 53 | |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 54 | def find_error(f, all_lines, error_to_files, is_fxc): |
| 55 | # Search for specific errors from top to bottom |
| 56 | for line in all_lines: |
| 57 | # Both |
| 58 | if line.startswith('test timed out after'): |
| 59 | add_error(error_to_files, line, f) |
| 60 | return True |
| 61 | if 'internal compiler error' in line: |
| 62 | add_error(error_to_files, line, f) |
| 63 | return True |
| 64 | if line.startswith('tint executable returned error:'): |
| 65 | add_error(error_to_files, line, f) |
| 66 | return True |
| 67 | m = re.search('Failed to generate:.*?(error:.*)', line) |
| 68 | if m: |
| 69 | add_error(error_to_files, m.groups()[0], f) |
| 70 | return True |
| 71 | # DXC |
| 72 | if not is_fxc: |
| 73 | if line.startswith('error: validation errors'): |
| 74 | continue # Skip line, next line should have better error |
| 75 | |
| 76 | if line.startswith('error:'): |
| 77 | add_error(error_to_files, line, f) |
| 78 | return True |
| 79 | |
| 80 | m = re.search('.*\.hlsl:[0-9]+:.*?(error.*)', line) # DXC??? |
| 81 | if m: |
| 82 | add_error(error_to_files, m.groups()[0], f) |
| 83 | return True |
| 84 | # FXC |
| 85 | else: |
| 86 | if line.startswith('internal error:'): |
| 87 | add_error(error_to_files, line, f) |
| 88 | return True |
| 89 | m = re.search('error( X[0-9]+)+?:(.*)', line) |
| 90 | if m: |
| 91 | add_error(error_to_files, m.group(), f) |
| 92 | return True |
| 93 | return False |
| 94 | |
| 95 | |
| 96 | def find_and_print_errors(glob_pathname, is_fxc): |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 97 | files = glob.glob(glob_pathname, recursive=True) |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 98 | error_to_files = {} |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 99 | |
| 100 | for f in files: |
| 101 | found_error = False |
| 102 | with open(f, "r") as fs: |
Antonio Maiorano | 71e72ee | 2023-08-30 14:48:24 +0000 | [diff] [blame] | 103 | all_lines = fs.readlines() |
| 104 | first_line = all_lines[0] |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 105 | if not first_line.startswith("SKIP:"): # Only process SKIPs |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 106 | continue |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 107 | if first_line.startswith("SKIP: INVALID"): # Except for INVALIDs |
| 108 | continue |
| 109 | found_error = find_error(f, all_lines, error_to_files, is_fxc) |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 110 | |
| 111 | if not found_error: |
| 112 | # If no error message was found, add the SKIP line as it may contain the reason for skipping |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 113 | add_error(error_to_files, first_line, f) |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 114 | |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 115 | for error,files in sorted(error_to_files.items()): |
| 116 | print('[{}] {} (count: {})'.format('fxc' if is_fxc else 'dxc', error, len(files))) |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 117 | if args.list_files: |
| 118 | for f in files: |
| 119 | print('\t{}'.format(f)) |
| 120 | |
Antonio Maiorano | cf47d61 | 2022-10-04 19:48:41 +0000 | [diff] [blame] | 121 | |
Antonio Maiorano | 9f7ab42 | 2024-09-18 21:13:34 +0000 | [diff] [blame] | 122 | if args.ir_only: |
| 123 | print("=== FXC (IR only) ===") |
| 124 | find_and_print_errors('./**/*.ir.fxc.hlsl', is_fxc=True) |
| 125 | print("=== DXC (IR only) ===") |
| 126 | find_and_print_errors('./**/*.ir.dxc.hlsl', is_fxc=False) |
| 127 | else: |
| 128 | print("=== FXC ===") |
| 129 | find_and_print_errors('./**/*.fxc.hlsl', is_fxc=True) |
| 130 | print("=== DXC ===") |
| 131 | find_and_print_errors('./**/*.dxc.hlsl', is_fxc=False) |