Cleanup test targets.

This commit is contained in:
Chinmay Garde
2021-07-01 11:55:24 -07:00
committed by Dan Field
parent 524ec504bb
commit c3a2afd16d
7 changed files with 42 additions and 58 deletions

View File

@@ -26,6 +26,7 @@ executable("impeller_unittests") {
deps = [
"compiler:compiler_unittests",
"compositor:compositor_unittests",
"fixtures",
"//flutter/testing",
]
}

View File

@@ -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",
]
}

View File

@@ -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<fml::UniqueFD>(
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<fml::UniqueFD>(
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

View File

@@ -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);
}

View File

@@ -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",
]
}