blob: 20824a309c53c58cdc46289c3c5a164e42d9c0e7 [file] [log] [blame]
Brian Sheedyd2c98642022-03-24 22:31:45 +00001#!/usr/bin/env python3
2#
Austin Engcc2516a2023-10-17 20:57:54 +00003# Copyright 2022 The Dawn & Tint Authors
Brian Sheedyd2c98642022-03-24 22:31:45 +00004#
Austin Engcc2516a2023-10-17 20:57:54 +00005# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
Brian Sheedyd2c98642022-03-24 22:31:45 +00007#
Austin Engcc2516a2023-10-17 20:57:54 +00008# 1. Redistributions of source code must retain the above copyright notice, this
9# list of conditions and the following disclaimer.
Brian Sheedyd2c98642022-03-24 22:31:45 +000010#
Austin Engcc2516a2023-10-17 20:57:54 +000011# 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.
Brian Sheedyd2c98642022-03-24 22:31:45 +000029"""Script for easily adding expectations to expectations.txt
30
31Converts one or more WebGPU CTS queries into one or more individual expectations
32and appends them to the end of the file.
33"""
34
35import argparse
36import logging
37import os
38import subprocess
39import sys
40
41import dir_paths
42
43LIST_SCRIPT_PATH = os.path.join(dir_paths.webgpu_cts_scripts_dir, 'list.py')
44TRANSPILE_DIR = os.path.join(dir_paths.dawn_dir, '.node_transpile_work_dir')
45EXPECTATION_FILE_PATH = os.path.join(dir_paths.dawn_dir, 'webgpu-cts',
46 'expectations.txt')
47
48
49def expand_query(query):
50 cmd = [
51 sys.executable,
52 LIST_SCRIPT_PATH,
53 '--js-out-dir',
54 TRANSPILE_DIR,
55 '--query',
56 query,
57 ]
58 p = subprocess.run(cmd, stdout=subprocess.PIPE, check=True)
59 return p.stdout.decode('utf-8').splitlines()
60
61
62def generate_expectations(queries, tags, results, bug):
63 tags = '[ %s ] ' % ' '.join(tags) if tags else ''
64 results = ' [ %s ]' % ' '.join(results)
65 bug = bug + ' ' if bug else ''
66 content = ''
67 for q in queries:
68 test_names = expand_query(q)
69 if not test_names:
70 logging.warning('Did not get any test names for query %s', q)
71 for tn in test_names:
72 content += '{bug}{tags}{test}{results}\n'.format(bug=bug,
73 tags=tags,
74 test=tn,
75 results=results)
76 with open(EXPECTATION_FILE_PATH, 'a') as outfile:
77 outfile.write(content)
78
79
80if __name__ == '__main__':
81 parser = argparse.ArgumentParser(
82 description=('Converts one or more WebGPU CTS queries into one or '
83 'more individual expectations and appends them to the '
84 'end of expectations.txt'))
85 parser.add_argument('-b',
86 '--bug',
87 help='The bug link to associate with the expectations')
88 parser.add_argument('-t',
89 '--tag',
90 action='append',
91 default=[],
92 dest='tags',
93 help=('A tag to restrict the expectation to. Can be '
94 'specified multiple times.'))
95 parser.add_argument('-r',
96 '--result',
97 action='append',
98 default=[],
99 dest='results',
100 required=True,
101 help=('An expected result for the expectation. Can be '
102 'specified multiple times, although a single '
103 'result is the most common usage.'))
104 parser.add_argument('-q',
105 '--query',
106 action='append',
107 default=[],
108 dest='queries',
109 help=('A CTS query to expand into expectations. Can '
110 'be specified multiple times.'))
111 args = parser.parse_args()
112 generate_expectations(args.queries, args.tags, args.results, args.bug)