aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Stiles <johnstiles@google.com>2022-03-18 14:24:34 +0000
committerDerek Sollenberger <djsollen@google.com>2022-03-22 17:56:43 +0000
commit70782b757f6d6b8f39ec9dee2db1f76a5534ec00 (patch)
treef85ae275a6e5150aef287327c4f2554b2440bebf
parent50517e07bea76af2a0a3009638ae0400afdb8227 (diff)
downloadskia-70782b757f6d6b8f39ec9dee2db1f76a5534ec00.tar.gz
Refactor SkQPTestRunner to support running SkSL error tests.
Previously, when we wanted to run multiple test types, we cloned the outer testing loop and had a bunch of duplicated logic for translating test results into TestRunner success/failure. This worked, but maintaining duplicate code can be a chore (see http://cs/h/skia/skia/+/c5d130aac064cd10a04a9b8d1b9e64f9df1e91b5:platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java?l=102 ) Instead of going back to that approach, I've factored out the logic for individual tests into a bare-bones "TestExecutor" interface. The outer work loop takes a TestExecutor and iterates over every test in it. Unit tests and SkSL error tests can each implement this interface as needed. For this CL, actual SkSL error test handling is not yet implemented, so the SkSL tests will all be listed as passing (in 0-1 milliseconds). In a followup CL, SkSLErrorTestExecutor#run will be implemented to match the behavior of the C++ SkSL error tests. Bug: skia:13042 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/522101 Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com> Change-Id: I4c596133bd3aec9edbe26ab215a1944871ca46eb Reviewed-on: https://skia-review.googlesource.com/c/skia/+/523182 Reviewed-by: John Stiles <johnstiles@google.com>
-rw-r--r--platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java88
1 files changed, 72 insertions, 16 deletions
diff --git a/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java b/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java
index 3590077c08..3b831eec43 100644
--- a/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java
+++ b/platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQPRunner.java
@@ -28,11 +28,19 @@ import org.junit.runner.notification.RunNotifier;
@RunWith(SkQPRunner.class)
public class SkQPRunner extends Runner implements Filterable {
private Description[] mUnitTestDesc;
+ private Description[] mSkSLErrorTestDesc;
private Description mSuiteDesc;
private String mOutputDirectory;
private SkQP mImpl;
private static final String TAG = SkQP.LOG_PREFIX;
+ private interface TestExecutor {
+ public int numTests();
+ public String name(int index);
+ public Description desc(int index);
+ public boolean run(RunNotifier notifier, int index);
+ }
+
private static void Fail(Description desc, RunNotifier notifier, String failure) {
notifier.fireTestFailure(new Failure(desc, new SkQPFailure(failure)));
}
@@ -52,9 +60,15 @@ public class SkQPRunner extends Runner implements Filterable {
mImpl.nInit(assetManager, mOutputDirectory);
mUnitTestDesc = new Description[mImpl.mUnitTests.length];
- for (int index = 0; index < mImpl.mUnitTests.length; ++index) {
+ for (int index = 0; index < mUnitTestDesc.length; ++index) {
mUnitTestDesc[index] = Description.createTestDescription(
- SkQPRunner.class, "unitTest_" + mImpl.mUnitTests[index]);
+ SkQPRunner.class, "UnitTest_" + mImpl.mUnitTests[index]);
+ }
+
+ mSkSLErrorTestDesc = new Description[mImpl.mSkSLErrorTestName.length];
+ for (int index = 0; index < mSkSLErrorTestDesc.length; ++index) {
+ mSkSLErrorTestDesc[index] = Description.createTestDescription(
+ SkQPRunner.class, "SkSLErrorTest_" + mImpl.mSkSLErrorTestName[index]);
}
this.applyFilter(null);
@@ -63,6 +77,7 @@ public class SkQPRunner extends Runner implements Filterable {
private void applyFilter(Filter filter) {
mSuiteDesc = Description.createSuiteDescription(SkQP.class);
addFilteredTestsToSuite(mUnitTestDesc, filter);
+ addFilteredTestsToSuite(mSkSLErrorTestDesc, filter);
}
private void addFilteredTestsToSuite(Description[] tests, Filter filter) {
@@ -90,32 +105,73 @@ public class SkQPRunner extends Runner implements Filterable {
@Override
public void run(RunNotifier notifier) {
- int testNumber = 0; // out of number of actually run tests.
- for (int index = 0; index < mUnitTestDesc.length; index++) {
- Description desc = mUnitTestDesc[index];
+ int testNumber = 0;
+ testNumber = runTests(notifier, new SkSLErrorTestExecutor(), testNumber);
+ testNumber = runTests(notifier, new UnitTestExecutor(), testNumber);
+
+ mImpl.nMakeReport();
+ Log.i(TAG, String.format("output written to \"%s\"", mOutputDirectory));
+ }
+
+ private int runTests(RunNotifier notifier, TestExecutor executor, int testNumber) {
+ for (int index = 0; index < executor.numTests(); index++) {
+ Description desc = executor.desc(index);
if (desc.isEmpty()) {
// This test was filtered out and can be skipped.
continue;
}
- String name = desc.getMethodName();
++testNumber;
notifier.fireTestStarted(desc);
+
+ String result = executor.run(notifier, index) ? "pass" : "FAIL";
+
+ notifier.fireTestFinished(desc);
+ Log.i(TAG, String.format("Test '%s' complete (%d/%d). [%s]", executor.name(index),
+ testNumber, mSuiteDesc.testCount(), result));
+ }
+ return testNumber;
+ }
+
+ class UnitTestExecutor implements TestExecutor {
+ public int numTests() {
+ return mUnitTestDesc.length;
+ }
+ public String name(int index) {
+ return desc(index).getMethodName();
+ }
+ public Description desc(int index) {
+ return mUnitTestDesc[index];
+ }
+ public boolean run(RunNotifier notifier, int index) {
String[] errors = mImpl.nExecuteUnitTest(index);
- String result = "pass";
if (errors != null && errors.length > 0) {
- Log.w(TAG, String.format("[FAIL] Test '%s' had %d failures.", name, errors.length));
+ Log.w(TAG, String.format("[FAIL] Test '%s' had %d failures.",
+ name(index), errors.length));
for (String error : errors) {
- SkQPRunner.Fail(desc, notifier, error);
- Log.w(TAG, String.format("[FAIL] '%s': %s", name, error));
+ SkQPRunner.Fail(desc(index), notifier, error);
+ Log.w(TAG, String.format("[FAIL] '%s': %s", name(index), error));
}
- result = "FAIL";
+ return false;
}
- notifier.fireTestFinished(desc);
- Log.i(TAG, String.format("Test '%s' complete (%d/%d). [%s]",
- name, testNumber, mSuiteDesc.testCount(), result));
+
+ return true;
+ }
+ }
+
+ class SkSLErrorTestExecutor implements TestExecutor {
+ public int numTests() {
+ return mSkSLErrorTestDesc.length;
+ }
+ public String name(int index) {
+ return desc(index).getMethodName();
+ }
+ public Description desc(int index) {
+ return mSkSLErrorTestDesc[index];
+ }
+ public boolean run(RunNotifier notifier, int index) {
+ // TODO(skia:13042): compile SkSL and check error conditions
+ return true;
}
- mImpl.nMakeReport();
- Log.i(TAG, String.format("output written to \"%s\"", mOutputDirectory));
}
}