Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::compiler::testing::CompilerTestBase Class Reference

#include <compiler_test.h>

Inheritance diagram for impeller::compiler::testing::CompilerTestBase:
impeller::compiler::testing::CompilerTest impeller::compiler::testing::CompilerTestRuntime impeller::compiler::testing::CompilerTestSkSL

Public Member Functions

 CompilerTestBase ()
 
 ~CompilerTestBase ()
 
std::unique_ptr< fml::FileMappingGetReflectionJson (const char *fixture_name) const
 
std::unique_ptr< fml::FileMappingGetShaderFile (const char *fixture_name, TargetPlatform platform) const
 
bool CanCompileAndReflect (const char *fixture_name, SourceType source_type=SourceType::kUnknown, SourceLanguage source_language=SourceLanguage::kGLSL, const char *entry_point_name="main") const
 

Detailed Description

Definition at line 18 of file compiler_test.h.

Constructor & Destructor Documentation

◆ CompilerTestBase()

impeller::compiler::testing::CompilerTestBase::CompilerTestBase ( )

Definition at line 26 of file compiler_test.cc.

27 : intermediates_path_(GetIntermediatesPath()) {
28 intermediates_directory_ =
29 fml::OpenDirectory(intermediates_path_.c_str(),
30 true, // create if necessary
32 FML_CHECK(intermediates_directory_.is_valid());
33}
bool is_valid() const
#define FML_CHECK(condition)
Definition logging.h:104
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition file_posix.cc:97
static std::string GetIntermediatesPath()

References FML_CHECK, fml::UniqueObject< T, Traits >::is_valid(), fml::kReadWrite, and fml::OpenDirectory().

◆ ~CompilerTestBase()

impeller::compiler::testing::CompilerTestBase::~CompilerTestBase ( )

Definition at line 35 of file compiler_test.cc.

35 {
36 intermediates_directory_.reset();
37
38 std::filesystem::remove_all(std::filesystem::path(intermediates_path_));
39}
void reset(const T &value=Traits::InvalidValue())

References fml::UniqueObject< T, Traits >::reset().

Member Function Documentation

◆ CanCompileAndReflect()

bool impeller::compiler::testing::CompilerTestBase::CanCompileAndReflect ( const char *  fixture_name,
SourceType  source_type = SourceType::kUnknown,
SourceLanguage  source_language = SourceLanguage::kGLSL,
const char *  entry_point_name = "main" 
) const

Definition at line 87 of file compiler_test.cc.

91 {
92 std::shared_ptr<fml::Mapping> fixture =
94 if (!fixture || !fixture->GetMapping()) {
95 VALIDATION_LOG << "Could not find shader in fixtures: " << fixture_name;
96 return false;
97 }
98
99 SourceOptions source_options(fixture_name, source_type);
100 source_options.target_platform = GetParam();
101 source_options.source_language = source_language;
102 source_options.working_directory = std::make_shared<fml::UniqueFD>(
104 source_options.entry_point_name = EntryPointFunctionNameFromSourceName(
105 fixture_name, SourceTypeFromFileName(fixture_name), source_language,
106 entry_point_name);
107
108 Reflector::Options reflector_options;
109 reflector_options.target_platform = GetParam();
110 reflector_options.header_file_name = ReflectionHeaderName(fixture_name);
111 reflector_options.shader_name = "shader_name";
112
113 Compiler compiler(fixture, source_options, reflector_options);
114 if (!compiler.IsValid()) {
115 VALIDATION_LOG << "Compilation failed: " << compiler.GetErrorMessages();
116 return false;
117 }
118
119 auto spirv_assembly = compiler.GetSPIRVAssembly();
120 if (!spirv_assembly) {
121 VALIDATION_LOG << "No spirv was generated.";
122 return false;
123 }
124
125 if (!fml::WriteAtomically(intermediates_directory_,
126 SPIRVFileName(fixture_name).c_str(),
127 *spirv_assembly)) {
128 VALIDATION_LOG << "Could not write SPIRV intermediates.";
129 return false;
130 }
131
132 auto sl_source = compiler.GetSLShaderSource();
133 if (!sl_source) {
134 VALIDATION_LOG << "No SL source was generated.";
135 return false;
136 }
137
138 if (!fml::WriteAtomically(intermediates_directory_,
139 SLFileName(fixture_name, GetParam()).c_str(),
140 *sl_source)) {
141 VALIDATION_LOG << "Could not write SL intermediates.";
142 return false;
143 }
144
145 if (TargetPlatformNeedsReflection(GetParam())) {
146 auto reflector = compiler.GetReflector();
147 if (!reflector) {
149 << "No reflector was found for target platform SL compiler.";
150 return false;
151 }
152
153 auto reflection_json = reflector->GetReflectionJSON();
154 auto reflection_header = reflector->GetReflectionHeader();
155 auto reflection_source = reflector->GetReflectionCC();
156
157 if (!reflection_json) {
158 VALIDATION_LOG << "Reflection JSON was not found.";
159 return false;
160 }
161
162 if (!reflection_header) {
163 VALIDATION_LOG << "Reflection header was not found.";
164 return false;
165 }
166
167 if (!reflection_source) {
168 VALIDATION_LOG << "Reflection source was not found.";
169 return false;
170 }
171
172 if (!fml::WriteAtomically(intermediates_directory_,
173 ReflectionHeaderName(fixture_name).c_str(),
174 *reflection_header)) {
175 VALIDATION_LOG << "Could not write reflection header intermediates.";
176 return false;
177 }
178
179 if (!fml::WriteAtomically(intermediates_directory_,
180 ReflectionCCName(fixture_name).c_str(),
181 *reflection_source)) {
182 VALIDATION_LOG << "Could not write reflection CC intermediates.";
183 return false;
184 }
185
186 if (!fml::WriteAtomically(intermediates_directory_,
187 ReflectionJSONName(fixture_name).c_str(),
188 *reflection_json)) {
189 VALIDATION_LOG << "Could not write reflection json intermediates.";
190 return false;
191 }
192 }
193 return true;
194}
fml::UniqueFD OpenFixturesDirectory()
Opens the fixtures directory for the unit-test harness.
Definition testing.cc:22
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.
Definition testing.cc:58
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
static std::string ReflectionCCName(const char *fixture_name)
static std::string ReflectionJSONName(const char *fixture_name)
static std::string ReflectionHeaderName(const char *fixture_name)
static std::string SLFileName(const char *fixture_name, TargetPlatform platform)
static std::string SPIRVFileName(const char *fixture_name)
SourceType SourceTypeFromFileName(const std::filesystem::path &file_name)
Definition types.cc:17
std::string EntryPointFunctionNameFromSourceName(const std::filesystem::path &file_name, SourceType type, SourceLanguage source_language, const std::string &entry_point_name)
Definition types.cc:101
bool TargetPlatformNeedsReflection(TargetPlatform platform)
Definition types.cc:130
#define VALIDATION_LOG
Definition validation.h:91

References impeller::compiler::SourceOptions::entry_point_name, impeller::compiler::EntryPointFunctionNameFromSourceName(), impeller::compiler::Compiler::GetErrorMessages(), impeller::compiler::Reflector::GetReflectionJSON(), impeller::compiler::Compiler::GetReflector(), impeller::compiler::Compiler::GetSLShaderSource(), impeller::compiler::Compiler::GetSPIRVAssembly(), impeller::compiler::Reflector::Options::header_file_name, impeller::compiler::Compiler::IsValid(), flutter::testing::OpenFixtureAsMapping(), flutter::testing::OpenFixturesDirectory(), impeller::compiler::testing::ReflectionCCName(), impeller::compiler::testing::ReflectionHeaderName(), impeller::compiler::testing::ReflectionJSONName(), impeller::compiler::Reflector::Options::shader_name, impeller::compiler::testing::SLFileName(), impeller::compiler::SourceOptions::source_language, impeller::compiler::SourceTypeFromFileName(), impeller::compiler::testing::SPIRVFileName(), impeller::compiler::Reflector::Options::target_platform, impeller::compiler::SourceOptions::target_platform, impeller::compiler::TargetPlatformNeedsReflection(), VALIDATION_LOG, impeller::compiler::SourceOptions::working_directory, and fml::WriteAtomically().

◆ GetReflectionJson()

std::unique_ptr< fml::FileMapping > impeller::compiler::testing::CompilerTestBase::GetReflectionJson ( const char *  fixture_name) const

Definition at line 72 of file compiler_test.cc.

73 {
74 auto filename = ReflectionJSONName(fixture_name);
75 auto fd = fml::OpenFileReadOnly(intermediates_directory_, filename.c_str());
77}
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition mapping.cc:20
fml::UniqueFD OpenFileReadOnly(const fml::UniqueFD &base_directory, const char *path)
Definition file.cc:92

References fml::FileMapping::CreateReadOnly(), fml::OpenFileReadOnly(), and impeller::compiler::testing::ReflectionJSONName().

◆ GetShaderFile()

std::unique_ptr< fml::FileMapping > impeller::compiler::testing::CompilerTestBase::GetShaderFile ( const char *  fixture_name,
TargetPlatform  platform 
) const

Definition at line 79 of file compiler_test.cc.

81 {
82 auto filename = SLFileName(fixture_name, platform);
83 auto fd = fml::OpenFileReadOnly(intermediates_directory_, filename.c_str());
85}

References fml::FileMapping::CreateReadOnly(), fml::OpenFileReadOnly(), and impeller::compiler::testing::SLFileName().


The documentation for this class was generated from the following files: