Handle review feedback.

This CL implements review feedback from previous CL.

Change-Id: I913c09d11b4eeb1831494653c38227387775b346
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25600
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-07-23 15:51:02 +00:00 committed by dan sinclair
parent 429aa812a0
commit 453eb97a30
1 changed files with 31 additions and 6 deletions

View File

@ -13,7 +13,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# Test runner for executing a test of tests with Tint. The runner will
# find all .wgsl files in the given folder and attempt to convert them
# to each of the backend formats. If the file contains a '.fail.' in the
# name then the runner will expect the file to fail conversion.
import base64 import base64
import copy
import difflib import difflib
import optparse import optparse
import os import os
@ -24,6 +30,12 @@ import sys
import tempfile import tempfile
"""
A single test case to be executed. Stores the path to the test file
and the result of executing the test.
"""
class TestCase: class TestCase:
def __init__(self, input_path, parse_only): def __init__(self, input_path, parse_only):
self.input_path = input_path self.input_path = input_path
@ -44,8 +56,15 @@ class TestCase:
return self.results[fmt] return self.results[fmt]
"""
The test runner, will execute a series of test cases and record the
results.
"""
class TestRunner: class TestRunner:
def RunTest(self, tc): def RunTest(self, tc):
"""Runs a single test."""
print("Testing {}".format(tc.GetInputPath())) print("Testing {}".format(tc.GetInputPath()))
cmd = [self.options.test_prog_path] cmd = [self.options.test_prog_path]
@ -55,7 +74,7 @@ class TestRunner:
languages = ["wgsl", "spvasm", "msl", "hlsl"] languages = ["wgsl", "spvasm", "msl", "hlsl"]
try: try:
for lang in languages: for lang in languages:
lang_cmd = cmd.copy() lang_cmd = copy.copy(cmd)
lang_cmd += ['--format', lang] lang_cmd += ['--format', lang]
lang_cmd += [tc.GetInputPath()] lang_cmd += [tc.GetInputPath()]
err = subprocess.check_output(lang_cmd, err = subprocess.check_output(lang_cmd,
@ -70,6 +89,7 @@ class TestRunner:
return True return True
def RunTests(self): def RunTests(self):
"""Runs a set of test cases"""
for tc in self.test_cases: for tc in self.test_cases:
result = self.RunTest(tc) result = self.RunTest(tc)
@ -81,6 +101,8 @@ class TestRunner:
self.failures.append(tc.GetInputPath()) self.failures.append(tc.GetInputPath())
def SummarizeResults(self): def SummarizeResults(self):
"""Prints a summarization of the test results to STDOUT"""
if len(self.failures) > 0: if len(self.failures) > 0:
self.failures.sort() self.failures.sort()
@ -96,6 +118,7 @@ class TestRunner:
print('') print('')
def Run(self): def Run(self):
"""Executes the test runner."""
base_path = os.path.abspath( base_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..')) os.path.join(os.path.dirname(__file__), '..'))
@ -110,9 +133,10 @@ class TestRunner:
'src', 'webgpu', 'shader', 'src', 'webgpu', 'shader',
'validation', 'wgsl'), 'validation', 'wgsl'),
help='path to directory containing test files') help='path to directory containing test files')
parser.add_option('--test-prog-path', parser.add_option(
default=None, '--test-prog-path',
help='path to program to test') default=None,
help='path to program to test (default build-dir/tint)')
parser.add_option('--parse-only', parser.add_option('--parse-only',
action="store_true", action="store_true",
default=False, default=False,
@ -130,7 +154,8 @@ class TestRunner:
self.options.test_prog_path = test_prog self.options.test_prog_path = test_prog
if not os.path.isfile(self.options.test_prog_path): if not os.path.isfile(self.options.test_prog_path):
print("--test-prog-path must point to an executable") print("Cannot find test program '{}'".format(
self.options.test_prog_path))
return 1 return 1
input_file_re = re.compile('^.+[\.]wgsl') input_file_re = re.compile('^.+[\.]wgsl')
@ -160,7 +185,7 @@ class TestRunner:
self.RunTests() self.RunTests()
self.SummarizeResults() self.SummarizeResults()
return len(self.failures) != 0 return len(self.failures)
def main(): def main():