From c3a2afd16d5ad881a59f569fb4e4825301a3e8bf Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Thu, 1 Jul 2021 11:55:24 -0700 Subject: [PATCH] Cleanup test targets. --- engine/src/flutter/impeller/BUILD.gn | 1 + engine/src/flutter/impeller/compiler/BUILD.gn | 15 ++---- .../impeller/compiler/compiler_unittests.cc | 53 +++++++++---------- .../impeller/compiler/fixtures/sample.frag | 18 ------- engine/src/flutter/impeller/fixtures/BUILD.gn | 13 +++++ .../{compiler => }/fixtures/sample.vert | 0 .../impeller/{compiler => }/fixtures/types.h | 0 7 files changed, 42 insertions(+), 58 deletions(-) delete mode 100644 engine/src/flutter/impeller/compiler/fixtures/sample.frag create mode 100644 engine/src/flutter/impeller/fixtures/BUILD.gn rename engine/src/flutter/impeller/{compiler => }/fixtures/sample.vert (100%) rename engine/src/flutter/impeller/{compiler => }/fixtures/types.h (100%) diff --git a/engine/src/flutter/impeller/BUILD.gn b/engine/src/flutter/impeller/BUILD.gn index 31d5db2990..01e77b316d 100644 --- a/engine/src/flutter/impeller/BUILD.gn +++ b/engine/src/flutter/impeller/BUILD.gn @@ -26,6 +26,7 @@ executable("impeller_unittests") { deps = [ "compiler:compiler_unittests", "compositor:compositor_unittests", + "fixtures", "//flutter/testing", ] } diff --git a/engine/src/flutter/impeller/compiler/BUILD.gn b/engine/src/flutter/impeller/compiler/BUILD.gn index f60c6e12de..9b13cf0a76 100644 --- a/engine/src/flutter/impeller/compiler/BUILD.gn +++ b/engine/src/flutter/impeller/compiler/BUILD.gn @@ -2,9 +2,9 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("//flutter/testing/testing.gni") +import("//flutter/impeller/tools/impeller.gni") -source_set("compiler_lib") { +impeller_component("compiler_lib") { sources = [ "code_gen_template.h", "compiler.cc", @@ -40,15 +40,7 @@ group("compiler") { deps = [ ":impellerc" ] } -test_fixtures("compiler_test_fixtures") { - fixtures = [ - "fixtures/sample.frag", - "fixtures/sample.vert", - "fixtures/types.h", - ] -} - -source_set("compiler_unittests") { +impeller_component("compiler_unittests") { testonly = true output_name = "impellerc_unittests" @@ -57,7 +49,6 @@ source_set("compiler_unittests") { deps = [ ":compiler_lib", - ":compiler_test_fixtures", "//flutter/testing:testing_lib", ] } diff --git a/engine/src/flutter/impeller/compiler/compiler_unittests.cc b/engine/src/flutter/impeller/compiler/compiler_unittests.cc index a578292378..bdaabc4e76 100644 --- a/engine/src/flutter/impeller/compiler/compiler_unittests.cc +++ b/engine/src/flutter/impeller/compiler/compiler_unittests.cc @@ -5,6 +5,7 @@ #include "flutter/impeller/compiler/compiler.h" #include "flutter/testing/testing.h" #include "gtest/gtest.h" +#include "third_party/inja/include/inja/inja.hpp" namespace impeller { namespace compiler { @@ -13,27 +14,35 @@ namespace testing { class CompilerTest : public ::testing::Test { public: CompilerTest() - : directory_(fml::OpenDirectory("/Users/chinmaygarde/Desktop/shaders", - false, - fml::FilePermission::kRead)) { - FML_CHECK(directory_.is_valid()); + : intermediates_directory_( + fml::OpenDirectory(flutter::testing::GetFixturesPath(), + false, + fml::FilePermission::kRead)) { + FML_CHECK(intermediates_directory_.is_valid()); } - ~CompilerTest() {} + ~CompilerTest() = default; - void WriteCompilerIntermediates(const Compiler& compiler, - const std::string& base_name) { - ASSERT_TRUE(compiler.IsValid()); - fml::WriteAtomically(directory_, - std::string{base_name + std::string{".spirv"}}.c_str(), - *compiler.GetSPIRVAssembly()); - fml::WriteAtomically(directory_, - std::string{base_name + std::string{".metal"}}.c_str(), - *compiler.GetMSLShaderSource()); + bool CanCompileFixture(const char* fixture_name) const { + auto fixture = flutter::testing::OpenFixtureAsMapping(fixture_name); + if (!fixture->GetMapping()) { + FML_LOG(ERROR) << "Could not find shader in fixtures: " << fixture_name; + return false; + } + Compiler::SourceOptions compiler_options(fixture_name); + compiler_options.working_directory = std::make_shared( + flutter::testing::OpenFixturesDirectory()); + Reflector::Options reflector_options; + Compiler compiler(*fixture.get(), compiler_options, reflector_options); + if (!compiler.IsValid()) { + FML_LOG(ERROR) << "Compilation failed: " << compiler.GetErrorMessages(); + return false; + } + return true; } private: - fml::UniqueFD directory_; + fml::UniqueFD intermediates_directory_; FML_DISALLOW_COPY_AND_ASSIGN(CompilerTest); }; @@ -50,19 +59,7 @@ TEST_F(CompilerTest, ShaderKindMatchingIsSuccessful) { } TEST_F(CompilerTest, CanCompileSample) { - constexpr const char* kShaderFixtureName = "sample.vert"; - auto fixture = flutter::testing::OpenFixtureAsMapping(kShaderFixtureName); - ASSERT_NE(fixture->GetMapping(), nullptr); - Compiler::SourceOptions compiler_options(kShaderFixtureName); - compiler_options.working_directory = std::make_shared( - flutter::testing::OpenFixturesDirectory()); - Reflector::Options reflector_options; - Compiler compiler(*fixture.get(), compiler_options, reflector_options); - if (!compiler.IsValid()) { - FML_LOG(ERROR) << compiler.GetErrorMessages(); - } - ASSERT_TRUE(compiler.IsValid()); - WriteCompilerIntermediates(compiler, kShaderFixtureName); + ASSERT_TRUE(CanCompileFixture("sample.vert")); } } // namespace testing diff --git a/engine/src/flutter/impeller/compiler/fixtures/sample.frag b/engine/src/flutter/impeller/compiler/fixtures/sample.frag deleted file mode 100644 index eef7915f18..0000000000 --- a/engine/src/flutter/impeller/compiler/fixtures/sample.frag +++ /dev/null @@ -1,18 +0,0 @@ - -#include "types.h" - -uniform Uniforms { - Hello myHello; - vec4 hi; - Hello goodbyeHello; -}; - -uniform sampler2D textureSampler; - -layout(location = 3) in vec2 inTextureCoord; - -layout(location = 4) out vec4 outColor; - -void main() { - outColor = texture(textureSampler, inTextureCoord * goodbyeHello.yet_more_stuff); -} diff --git a/engine/src/flutter/impeller/fixtures/BUILD.gn b/engine/src/flutter/impeller/fixtures/BUILD.gn new file mode 100644 index 0000000000..519515d514 --- /dev/null +++ b/engine/src/flutter/impeller/fixtures/BUILD.gn @@ -0,0 +1,13 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//flutter/impeller/tools/impeller.gni") +import("//flutter/testing/testing.gni") + +test_fixtures("fixtures") { + fixtures = [ + "sample.vert", + "types.h", + ] +} diff --git a/engine/src/flutter/impeller/compiler/fixtures/sample.vert b/engine/src/flutter/impeller/fixtures/sample.vert similarity index 100% rename from engine/src/flutter/impeller/compiler/fixtures/sample.vert rename to engine/src/flutter/impeller/fixtures/sample.vert diff --git a/engine/src/flutter/impeller/compiler/fixtures/types.h b/engine/src/flutter/impeller/fixtures/types.h similarity index 100% rename from engine/src/flutter/impeller/compiler/fixtures/types.h rename to engine/src/flutter/impeller/fixtures/types.h