|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright 2025 The Dawn & Tint Authors |
| 3 | +# |
| 4 | +# Redistribution and use in source and binary forms, with or without |
| 5 | +# modification, are permitted provided that the following conditions are met: |
| 6 | +# |
| 7 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 8 | +# list of conditions and the following disclaimer. |
| 9 | +# |
| 10 | +# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | +# this list of conditions and the following disclaimer in the documentation |
| 12 | +# and/or other materials provided with the distribution. |
| 13 | +# |
| 14 | +# 3. Neither the name of the copyright holder nor the names of its |
| 15 | +# contributors may be used to endorse or promote products derived from |
| 16 | +# this software without specific prior written permission. |
| 17 | +# |
| 18 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 22 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | +"""Runs the Tint fuzzer corpus tests. |
| 29 | +
|
| 30 | +This script is necessary in order to support running tests on Swarming, but it |
| 31 | +is effectively a thin wrapper around the underlying tool in //tools/. |
| 32 | +""" |
| 33 | + |
| 34 | +import argparse |
| 35 | +import json |
| 36 | +import os |
| 37 | +import subprocess |
| 38 | +import sys |
| 39 | + |
| 40 | +THIS_DIR = os.path.realpath(os.path.dirname(__file__)) |
| 41 | +DAWN_ROOT = os.path.realpath(os.path.join(THIS_DIR, '..')) |
| 42 | +TOOLS_DIR = os.path.join(DAWN_ROOT, 'tools') |
| 43 | + |
| 44 | + |
| 45 | +def run_fuzzer_corpus_tests( |
| 46 | + args_to_forward: list[str], |
| 47 | + append_cwd_as_build: bool) -> subprocess.CompletedProcess: |
| 48 | + cmd = [ |
| 49 | + sys.executable, |
| 50 | + os.path.join(TOOLS_DIR, 'run.py'), |
| 51 | + 'fuzz', |
| 52 | + ] |
| 53 | + cmd.extend(args_to_forward) |
| 54 | + if append_cwd_as_build: |
| 55 | + cmd.extend([ |
| 56 | + '-build', |
| 57 | + os.getcwd(), |
| 58 | + ]) |
| 59 | + |
| 60 | + return subprocess.run(cmd, check=False) |
| 61 | + |
| 62 | + |
| 63 | +def generate_results_for_resultdb_ingestion(success: bool, |
| 64 | + output_file: str) -> None: |
| 65 | + # This is a very crude pass/fail result since the fuzz command does not |
| 66 | + # have an option to output more complete information in a machine-readable |
| 67 | + # format. If the information is ever provided, this should be changed to |
| 68 | + # convert the information instead of generating it from scratch. If more |
| 69 | + # than a pass/fail for a single test is needed, this should be replaced with |
| 70 | + # native ResultDB integration instead of relying on result_adapter. |
| 71 | + generated_test_results = { |
| 72 | + 'failures': [], |
| 73 | + 'valid': True, |
| 74 | + } |
| 75 | + if not success: |
| 76 | + generated_test_results['failures'].append('tint_fuzzer_corpus_tests') |
| 77 | + |
| 78 | + with open(output_file, 'w', encoding='utf-8') as outfile: |
| 79 | + json.dump(generated_test_results, outfile) |
| 80 | + |
| 81 | + |
| 82 | +def main() -> None: |
| 83 | + parser = argparse.ArgumentParser( |
| 84 | + description='Runs the Tint fuzzer corpus tests') |
| 85 | + # Doing the opposite (passing in . for build and making other paths relative |
| 86 | + # to it) doesn't work properly for the "fuzz" command. When checking IR, |
| 87 | + # the .tirb files are not correctly generated due to the -input value not |
| 88 | + # matching the default WGSL corpus directory. |
| 89 | + parser.add_argument( |
| 90 | + '--append-cwd-as-build', |
| 91 | + action='store_true', |
| 92 | + help=('Automatically appends the current directory as a -build ' |
| 93 | + 'argument. Meant for use on bots.')) |
| 94 | + parser.add_argument('--isolated-script-test-output', |
| 95 | + help='Path to the location to output JSON results.') |
| 96 | + parser.add_argument('--isolated-script-test-perf-output', |
| 97 | + help='Currently unused, needed for bot support.') |
| 98 | + args, unknown_args = parser.parse_known_args() |
| 99 | + |
| 100 | + proc = run_fuzzer_corpus_tests(unknown_args, args.append_cwd_as_build) |
| 101 | + if args.isolated_script_test_output: |
| 102 | + generate_results_for_resultdb_ingestion( |
| 103 | + not proc.returncode, args.isolated_script_test_output) |
| 104 | + proc.check_returncode() |
| 105 | + |
| 106 | + |
| 107 | +if __name__ == '__main__': |
| 108 | + main() |
0 commit comments