Support testing error cases in our SkSL unit test goldens.

Change-Id: I56e19153597e2c4393c5821314b82937828c0d50
Bug: skia:10694
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/316569
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-09-14 16:46:40 -04:00 committed by Skia Commit-Bot
parent eaed918a1d
commit ea9e7ca1ce
8 changed files with 70 additions and 23 deletions

View File

@ -9,29 +9,50 @@ import os
import subprocess
import sys
def unlinkIfExists(path):
try:
os.unlink(path)
except OSError:
pass
def compile(skslc, input, target, extension):
target += extension
try:
subprocess.check_output([skslc, input, target], stderr=subprocess.STDOUT)
return True
except subprocess.CalledProcessError as err:
with open(target, 'wb') as dst:
dst.write("### Compilation failed:\n\n")
dst.write(err.output)
return False
skslc = sys.argv[1]
inputs = sys.argv[2:]
for input in inputs:
try:
noExt, ext = os.path.splitext(input)
head, tail = os.path.split(noExt)
targetDir = os.path.join(head, "golden")
if not os.path.isdir(targetDir):
os.mkdir(targetDir)
target = os.path.join(targetDir, tail)
if ext == ".fp":
subprocess.check_output([skslc, input, target + ".h"],
stderr=subprocess.STDOUT)
subprocess.check_output([skslc, input, target + ".cpp"],
stderr=subprocess.STDOUT)
elif ext == ".sksl":
subprocess.check_output([skslc, input, target + ".glsl"],
stderr=subprocess.STDOUT)
noExt, ext = os.path.splitext(input)
head, tail = os.path.split(noExt)
targetDir = os.path.join(head, "golden")
if not os.path.isdir(targetDir):
os.mkdir(targetDir)
target = os.path.join(targetDir, tail)
if ext == ".fp":
# First, compile the CPP. If we get an error, stop here.
if compile(skslc, input, target, ".cpp"):
# Next, compile the header.
if compile(skslc, input, target, ".h"):
# Both files built successfully.
continue
else:
# The header generated an error; this counts as an overall failure for this test.
# Remove the passing CPP output since it's not relevant in a failure case.
unlinkIfExists(target + ".cpp")
else:
print("### Unrecognized file type for " + input + ", skipped")
except subprocess.CalledProcessError as err:
print("### Error compiling " + input + ":")
print(err.output)
exit(1)
# The CPP generated an error. We didn't actually generate a header, but there might be
# one from prior runs. Let's remove it for clarity.
unlinkIfExists(target + ".h")
elif ext == ".sksl":
compile(skslc, input, target, ".glsl")
else:
print("### Unrecognized file type for " + input + ", skipped")

View File

@ -6,6 +6,13 @@
# Things are easiest for everyone if these source paths are absolute.
_tests = get_path_info("../tests", "abspath")
sksl_fp_tests_sources = [ "$_tests/sksl/fp/GrHelloWorld.fp" ]
sksl_fp_tests_sources = [
"$_tests/sksl/errors/GrBothExplicitReturnAndSkOutColor.fp",
"$_tests/sksl/fp/GrHelloWorld.fp",
]
sksl_glsl_tests_sources = [ "$_tests/sksl/glsl/HelloWorld.sksl" ]
sksl_glsl_tests_sources = [
"$_tests/sksl/errors/OpenArray.sksl",
"$_tests/sksl/errors/UndefinedSymbol.sksl",
"$_tests/sksl/glsl/HelloWorld.sksl",
]

View File

@ -0,0 +1,4 @@
half4 main() {
sk_OutColor = half4(1, 0, 1, 0);
return half4(0, 1, 0, 1);
}

View File

@ -0,0 +1 @@
void main(inout float4 color) { color.r[ = ( color.g ); }

View File

@ -0,0 +1 @@
void main() { x = float2(1); }

View File

@ -0,0 +1,5 @@
### Compilation failed:
error: 3: Fragment processors must not mix sk_OutColor and return statements
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected expression, but found '='
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: unknown identifier 'x'
1 error