Start adding unit tests of SkRuntimeEffect
- Change SkRuntimeEffect::Make so *it* can fail, and returns
[Effect, ErrorText].
- Initial tests just test for expected failure conditions.
Next steps are to add tests for effects that should work,
and to validate results on CPU and GPU.
Change-Id: Ibac8c3046104577434034263e9e4a4b177e89129
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/261095
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
new file mode 100644
index 0000000..c6a521c
--- /dev/null
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2019 Google LLC
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "src/core/SkRuntimeEffect.h"
+#include "tests/Test.h"
+
+DEF_TEST(SkRuntimeEffectInvalidPrograms, r) {
+ auto test = [r](const char* src, const char* expected) {
+ auto [effect, errorText] = SkRuntimeEffect::Make(SkString(src));
+ REPORTER_ASSERT(r, !effect);
+ REPORTER_ASSERT(r, errorText.contains(expected),
+ "Expected error message to contain \"%s\". Actual message: \"%s\"",
+ expected, errorText.c_str());
+ };
+
+ // Features that are only allowed in .fp files (key, in uniform, ctype, when, tracked).
+ // Ensure that these fail, and the error messages contain the relevant keyword.
+ test("layout(key) in bool Input;"
+ "void main(float x, float y, inout half4 color) {}",
+ "key");
+
+ test("in uniform float Input;"
+ "void main(float x, float y, inout half4 color) {}",
+ "in uniform");
+
+ test("layout(ctype=SkRect) float4 Input;"
+ "void main(float x, float y, inout half4 color) {}",
+ "ctype");
+
+ test("in bool Flag; layout(when=Flag) uniform float Input;"
+ "void main(float x, float y, inout half4 color) {}",
+ "when");
+
+ test("layout(tracked) uniform float Input;"
+ "void main(float x, float y, inout half4 color) {}",
+ "tracked");
+}
diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp
index cea6949..28a8340 100644
--- a/tests/SkSLGLSLTest.cpp
+++ b/tests/SkSLGLSLTest.cpp
@@ -1245,11 +1245,11 @@
SkSL::Program::kVertex_Kind);
test(r,
- "in uniform float4 sk_RTAdjust; in float4 pos; void main() { sk_Position = pos; }",
+ "uniform float4 sk_RTAdjust; in float4 pos; void main() { sk_Position = pos; }",
*SkSL::ShaderCapsFactory::CannotUseFragCoord(),
"#version 400\n"
"out vec4 sk_FragCoord_Workaround;\n"
- "in uniform vec4 sk_RTAdjust;\n"
+ "uniform vec4 sk_RTAdjust;\n"
"in vec4 pos;\n"
"void main() {\n"
" sk_FragCoord_Workaround = (gl_Position = pos);\n"