24 [](
const char*
message,
const char* file,
int line) ->
bool {
30 [
message, file, line]() ->
void {
31 GTEST_MESSAGE_AT_(file, line,
"Impeller Validation Error",
32 ::testing::TestPartResult::kFatalFailure)
45 GTEST_SKIP() <<
"Playground doesn't support this backend type.";
50 GTEST_SKIP() <<
"Skipping due to user action.";
63class PlaygroundTestEnvironment :
public ::testing::Environment {
65 static std::optional<std::string> ValidateGoldenDirectory(
66 const std::string& dir) {
70 wordexp_t wordexp_result;
71 int code = wordexp(dir.c_str(), &wordexp_result, 0);
72 FML_CHECK(code == 0) <<
"Could not parse golden output directory: " << dir;
74 <<
"Exactly one directory must be specified for Golden image output: "
76 std::optional<std::string> working_dir = wordexp_result.we_wordv[0];
77 wordfree(&wordexp_result);
79 FML_CHECK(working_dir) <<
"Unrecognized golden output directory: " << dir;
83 <<
"Golden output directory must be a directory with read/write"
84 <<
" permissions: " << dir;
89 void SetUp()
override {
91 std::string golden_output_dir;
92 if (
args.GetOptionValue(
"golden_output_dir", &golden_output_dir)) {
93 const std::optional<std::string> validated_dir =
94 ValidateGoldenDirectory(golden_output_dir);
96 golden_manager_.emplace(*validated_dir);
99 <<
"Did not recognize golden output directory: "
100 << golden_output_dir;
105 void TearDown()
override {
106 if (golden_manager_) {
107 if (::testing::UnitTest::GetInstance()->Passed()) {
108 golden_manager_->Write();
111 << ::testing::UnitTest::GetInstance()->failed_test_count()
112 <<
" tests failed, golden digest will not be written";
113 golden_manager_->ClearDigestData();
115 golden_manager_.reset();
121 static testing::GoldenDigestManager* GetGoldenDigestManager() {
122 return golden_manager_ ? &golden_manager_.value() :
nullptr;
126 static std::optional<testing::GoldenDigestManager> golden_manager_;
129std::optional<testing::GoldenDigestManager>
130 PlaygroundTestEnvironment::golden_manager_;
136#undef APPLY_METAL_VALIDATION
137#undef ENABLE_VK_SWIFTSHADER
140#ifdef ENABLE_VK_SWIFTSHADER
142 std::filesystem::path testing_assets_path =
144 std::filesystem::path target_path = testing_assets_path.parent_path()
148 std::filesystem::path icd_path = target_path /
"vk_swiftshader_icd.json";
149 setenv(
"VK_ICD_FILENAMES", icd_path.c_str(), 1);
152#ifdef APPLY_METAL_VALIDATION
155 setenv(
"MTL_SHADER_VALIDATION",
"1",
true);
157 setenv(
"MTL_SHADER_VALIDATION_GLOBAL_MEMORY",
"1",
true);
159 setenv(
"MTL_SHADER_VALIDATION_THREADGROUP_MEMORY",
"1",
true);
161 setenv(
"MTL_SHADER_VALIDATION_TEXTURE_USAGE",
"1",
true);
163 setenv(
"METAL_DEBUG_ERROR_MODE",
"0",
true);
165 setenv(
"METAL_DEVICE_WRAPPER_TYPE",
"1",
true);
168 ::testing::AddGlobalTestEnvironment(
new PlaygroundTestEnvironment());
173 return PlaygroundTestEnvironment::GetGoldenDigestManager();
186 std::string asset_name)
const {
191 const char* asset_name)
const {
192 const std::shared_ptr<fml::Mapping> fixture =
194 if (!fixture || fixture->GetSize() == 0) {
195 return absl::NotFoundError(
"Asset not found or empty.");
202 std::stringstream stream;
203 stream <<
"Impeller Playground for '"
212 stream <<
" (Angle) ";
217 stream <<
" (SwiftShader) ";
221 stream <<
" (Press ESC to quit)";
226bool PlaygroundTest::ShouldKeepRendering()
const {
static void OnTearDownTestEnvironment()
static bool ShouldOpenNewPlaygrounds()
void TearDownContextData()
static bool SupportsBackend(PlaygroundBackend backend)
const PlaygroundSwitches & GetSwitches() const
Return an unmodifiable reference to the current switches. The switches might change at the start of a...
void SetEnableWriteGolden(bool write_golden)
Sets a particular test to either write a golden or not, false by default.
Scalar GetSecondsElapsed() const
Get the amount of time elapsed from the start of the playground's execution.
static void OnTearDownTestEnvironment()
std::unique_ptr< fml::Mapping > OpenAssetAsMapping(std::string asset_name) const override
std::string GetWindowTitle() const override
absl::StatusOr< RuntimeStage::Map > OpenAssetAsRuntimeStage(const char *asset_name) const
PlaygroundBackend GetBackend() const
virtual ~PlaygroundTest()
static void SetupTestEnvironment()
testing::GoldenDigestManager * GetGoldenDigestManager() const override
virtual bool IsGoldenTestSuite() const
This method is overridden on a test suite basis and establishes whether a given set of tests is inten...
static absl::StatusOr< Map > DecodeRuntimeStages(const std::shared_ptr< fml::Mapping > &payload)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define FML_LOG(severity)
#define FML_CHECK(condition)
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
const char * GetTestingAssetsPath()
Returns the directory containing assets shared across all tests.
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
const fml::CommandLine & GetArgsForProcess()
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
bool IsDirectory(const fml::UniqueFD &directory)
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback)
Sets a callback that callers (usually tests) can set to intercept validation failures.
std::chrono::duration< float > SecondsF
std::optional< std::chrono::milliseconds > timeout