From 3bdeedc4970b637fdb097bba45819a3af88b3236 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Tue, 15 Mar 2022 18:44:33 -0400 Subject: [PATCH] Load the SkSL error tests when SkQP::init is executed. Change-Id: I28d4859c13dfdf42da12d02899416aa86c944662 Bug: skia:13042 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/521219 Auto-Submit: John Stiles Reviewed-by: Leon Scroggins Reviewed-by: Brian Osman --- tools/skqp/src/skqp.cpp | 46 +++++++++++++++++++++++++++++++++++------ tools/skqp/src/skqp.h | 17 +++++++++++---- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tools/skqp/src/skqp.cpp b/tools/skqp/src/skqp.cpp index df3ffec206..2278e7dc45 100644 --- a/tools/skqp/src/skqp.cpp +++ b/tools/skqp/src/skqp.cpp @@ -23,6 +23,7 @@ #include "src/utils/SkOSPath.h" #include "tests/Test.h" #include "tests/TestHarness.h" +#include "tools/Resources.h" #include "tools/fonts/TestFontMgr.h" #ifdef SK_GL #include "tools/gpu/gl/GLTestContext.h" @@ -109,6 +110,38 @@ static std::vector get_unit_tests(const ExclusionList& exclusion return unitTests; } +// Returns a list of every SkSL error test to be run. +static std::vector get_sksl_error_tests(const ExclusionList& exclusionList) { + std::vector skslErrorTests; + + auto iterateFn = [&](const char* directory, const char* extension) { + SkString resourceDirectory = GetResourcePath(directory); + SkOSFile::Iter iter(resourceDirectory.c_str(), extension); + SkString name; + + while (iter.next(&name, /*getDir=*/false)) { + if (exclusionList.isExcluded(name.c_str())) { + continue; + } + SkString path(SkOSPath::Join(directory, name.c_str())); + sk_sp shaderText = GetResourceAsData(path.c_str()); + if (!shaderText) { + continue; + } + skslErrorTests.push_back({name.c_str(), static_cast(shaderText->data())}); + } + }; + + // Android only supports runtime shaders, not color filters or blenders. + iterateFn("sksl/runtime_errors/", ".rts"); + + auto lt = [](const SkQP::SkSLErrorTest& a, const SkQP::SkSLErrorTest& b) { + return a.name < b.name; + }; + std::sort(skslErrorTests.begin(), skslErrorTests.end(), lt); + return skslErrorTests; +} + static std::unique_ptr make_test_context(SkQP::SkiaBackend backend) { using U = std::unique_ptr; switch (backend) { @@ -213,6 +246,7 @@ void SkQP::init(SkQPAssetManager* assetManager, const char* reportDirectory) { } fUnitTests = get_unit_tests(exclusionList); + fSkSLErrorTests = get_sksl_error_tests(exclusionList); fSupportedBackends = get_backends(); print_backend_info((fReportDirectory + "/grdump.txt").c_str(), fSupportedBackends); @@ -232,7 +266,7 @@ std::vector SkQP::executeTest(SkQP::UnitTest test) { test->fContextOptionsProc(&options); } test->fProc(&r, options); - fUnitTestResults.push_back(UnitTestResult{test, r.fErrors}); + fTestResults.push_back(TestResult{test->fName, r.fErrors}); return r.fErrors; } @@ -250,13 +284,13 @@ void SkQP::makeReport() { } SkFILEWStream unitOut(SkOSPath::Join(fReportDirectory.c_str(), kUnitTestReportPath).c_str()); SkASSERT_RELEASE(unitOut.isValid()); - for (const SkQP::UnitTestResult& result : fUnitTestResults) { - unitOut.writeText(GetUnitTestName(result.fUnitTest)); - if (result.fErrors.empty()) { + for (const SkQP::TestResult& result : fTestResults) { + unitOut.writeText(result.name.c_str()); + if (result.errors.empty()) { unitOut.writeText(" PASSED\n* * *\n"); } else { - write(&unitOut, SkStringPrintf(" FAILED (%zu errors)\n", result.fErrors.size())); - for (const std::string& err : result.fErrors) { + write(&unitOut, SkStringPrintf(" FAILED (%zu errors)\n", result.errors.size())); + for (const std::string& err : result.errors) { write(&unitOut, err); unitOut.newline(); } diff --git a/tools/skqp/src/skqp.h b/tools/skqp/src/skqp.h index d56676556b..6093e0f1ca 100644 --- a/tools/skqp/src/skqp.h +++ b/tools/skqp/src/skqp.h @@ -46,6 +46,11 @@ public: }; using UnitTest = const skiatest::Test*; + struct SkSLErrorTest { + std::string name; + std::string shaderText; + }; + //////////////////////////////////////////////////////////////////////////// /** These functions provide a descriptive name for the given value.*/ @@ -71,17 +76,21 @@ public: /** @return a sorted list of all Skia GPU unit tests */ const std::vector& getUnitTests() const { return fUnitTests; } + /** @return a sorted list of all SkSL error tests */ + const std::vector& getSkSLErrorTests() const { return fSkSLErrorTests; } + //////////////////////////////////////////////////////////////////////////// private: - struct UnitTestResult { - UnitTest fUnitTest; - std::vector fErrors; + struct TestResult { + std::string name; + std::vector errors; }; - std::vector fUnitTestResults; + std::vector fTestResults; std::vector fSupportedBackends; std::string fReportDirectory; std::vector fUnitTests; + std::vector fSkSLErrorTests; SkQP(const SkQP&) = delete; SkQP& operator=(const SkQP&) = delete;