11import android.content.res.AssetManager;
12import android.content.res.Resources;
13import android.graphics.RuntimeShader;
15import androidx.test.InstrumentationRegistry;
17import java.io.IOException;
18import java.text.SimpleDateFormat;
20import java.util.regex.Pattern;
21import org.junit.runner.Description;
22import org.junit.runner.RunWith;
23import org.junit.runner.Runner;
24import org.junit.runner.manipulation.Filter;
25import org.junit.runner.manipulation.Filterable;
26import org.junit.runner.manipulation.NoTestsRemainException;
27import org.junit.runner.notification.Failure;
28import org.junit.runner.notification.RunNotifier;
30@RunWith(SkQPRunner.class)
31public class
SkQPRunner extends Runner implements Filterable {
32 private Description[] mUnitTestDesc;
33 private Description[] mSkSLErrorTestDesc;
34 private Description mSuiteDesc;
35 private String mOutputDirectory;
39 private interface TestExecutor {
40 public int numTests();
41 public String
name(
int index);
42 public Description
desc(
int index);
43 public boolean run(RunNotifier notifier,
int index);
46 private static void Fail(Description
desc, RunNotifier notifier, String failure) {
54 Context context = InstrumentationRegistry.getTargetContext();
55 String now = (
new SimpleDateFormat(
"yyyy-MM-dd'T'HHmmss")).
format(
new Date());
56 File reportPath =
new File(context.getExternalFilesDir(
null),
"skqp_report_" + now);
58 mOutputDirectory = reportPath.getAbsolutePath();
59 Log.i(
TAG, String.format(
"output written to \"%s\"", mOutputDirectory));
61 AssetManager assetManager = context.getResources().getAssets();
62 mImpl.
nInit(assetManager, mOutputDirectory);
64 mUnitTestDesc =
new Description[mImpl.
mUnitTests.length];
65 for (
int index = 0; index < mUnitTestDesc.length; ++index) {
66 mUnitTestDesc[index] = Description.createTestDescription(
71 for (
int index = 0; index < mSkSLErrorTestDesc.length; ++index) {
72 mSkSLErrorTestDesc[index] = Description.createTestDescription(
76 this.applyFilter(
null);
79 private void applyFilter(
Filter filter) {
80 mSuiteDesc = Description.createSuiteDescription(
SkQP.class);
81 addFilteredTestsToSuite(mUnitTestDesc, filter);
82 addFilteredTestsToSuite(mSkSLErrorTestDesc, filter);
85 private void addFilteredTestsToSuite(Description[]
tests,
Filter filter) {
86 for (
int i = 0;
i <
tests.length; ++
i) {
87 if (filter ==
null || filter.shouldRun(
tests[
i])) {
88 mSuiteDesc.addChild(
tests[
i]);
90 tests[
i] = Description.EMPTY;
97 this.applyFilter(filter);
98 if (mSuiteDesc.isEmpty()) {
99 throw new NoTestsRemainException();
109 public void run(RunNotifier notifier) {
115 Log.i(
TAG, String.format(
"output written to \"%s\"", mOutputDirectory));
118 private int runTests(RunNotifier notifier, TestExecutor executor,
int testNumber) {
119 for (
int index = 0; index < executor.numTests(); index++) {
120 Description
desc = executor.desc(index);
121 if (
desc.isEmpty()) {
127 notifier.fireTestStarted(
desc);
129 String
result = executor.run(notifier, index) ?
"pass" :
"FAIL";
131 notifier.fireTestFinished(
desc);
132 Log.i(
TAG, String.format(
"Test '%s' complete (%d/%d). [%s]", executor.name(index),
133 testNumber, mSuiteDesc.testCount(),
result));
140 return mUnitTestDesc.length;
142 public String
name(
int index) {
143 return desc(index).getMethodName();
145 public Description
desc(
int index) {
146 return mUnitTestDesc[index];
148 public boolean run(RunNotifier notifier,
int index) {
151 Log.w(
TAG, String.format(
"[FAIL] Test '%s' had %d failures.",
166 return mSkSLErrorTestDesc.length;
168 public String
name(
int index) {
171 public Description
desc(
int index) {
172 return mSkSLErrorTestDesc[index];
174 public boolean run(RunNotifier notifier,
int index) {
177 new RuntimeShader(shaderText);
180 SkQPRunner.Fail(
desc(index), notifier,
"Shader did not generate any errors.");
181 Log.w(
TAG, String.format(
"[FAIL] '%s': Shader did not generate any errors",
185 catch (Exception ex) { }
boolean run(RunNotifier notifier, int index)
Description desc(int index)
Description desc(int index)
boolean run(RunNotifier notifier, int index)
Description getDescription()
SkQPRunner(Class testClass)
void run(RunNotifier notifier)
void filter(Filter filter)
native void nMakeReport()
static final String LOG_PREFIX
native String[] nExecuteUnitTest(int test)
native void nInit(AssetManager assetManager, String dataDir)
String[] mSkSLErrorTestShader
String[] mSkSLErrorTestName
void Fail(const char *name, Dart_Handle result)
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
void Log(const char *format,...) SK_PRINTF_LIKE(1
static TTSTestCase Failure(const TTSTestCase &original)
DEF_SWITCHES_START aot vmservice shared library name
GrSamplerState::Filter Filter