Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Start of tests
  • Loading branch information
bdero committed Dec 11, 2023
commit e57b927a7394f41fba5337a1bbda2a1ec07ab28e
1 change: 1 addition & 0 deletions impeller/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impeller_component("compiler_unittests") {
"compiler_test.cc",
"compiler_test.h",
"compiler_unittests.cc",
"shader_bundle_unittests.cc",
"switches_unittests.cc",
]

Expand Down
4 changes: 2 additions & 2 deletions impeller/compiler/shader_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
namespace impeller {
namespace compiler {

static std::optional<ShaderBundleConfig> ParseShaderBundleConfig(
std::string& json_config) {
std::optional<ShaderBundleConfig> ParseShaderBundleConfig(
const std::string& json_config) {
auto json = nlohmann::json::parse(json_config);
if (!json.is_object()) {
std::cerr << "The shader bundle must be a JSON object." << std::endl;
Expand Down
3 changes: 3 additions & 0 deletions impeller/compiler/shader_bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
namespace impeller {
namespace compiler {

std::optional<ShaderBundleConfig> ParseShaderBundleConfig(
const std::string& json_config);

bool GenerateShaderBundle(Switches& switches, SourceOptions& options);

} // namespace compiler
Expand Down
24 changes: 24 additions & 0 deletions impeller/compiler/shader_bundle_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.

#include <initializer_list>
#include <vector>

#include "impeller/compiler/shader_bundle.h"

#include "flutter/testing/testing.h"

namespace impeller {
namespace compiler {
namespace testing {

TEST(ShaderBundleTest, ShaderBundleConfigFailsForInvalidJSON) {
std::string bundle = "";
auto result = ParseShaderBundleConfig(bundle);
ASSERT_FALSE(result.has_value());
}

} // namespace testing
} // namespace compiler
} // namespace impeller
13 changes: 13 additions & 0 deletions impeller/compiler/switches_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ TEST(SwitchesTEst, ConvertToEntrypointName) {
ASSERT_EQ(ConvertToEntrypointName(""), "");
}

TEST(SwitchesTest, ShaderBundleModeValid) {
// Shader bundles process multiple shaders, and so the single-file input/spirv
// flags are not required.
std::vector<const char*> options = {
"--shader-bundle={}", "--sl=test.shaderbundle", "--runtime-stage-metal"};

auto cl = fml::CommandLineFromIteratorsWithArgv0("impellerc", options.begin(),
options.end());
Switches switches(cl);
ASSERT_TRUE(switches.AreValid(std::cout));
ASSERT_EQ(switches.shader_bundle, "{}");
}

} // namespace testing
} // namespace compiler
} // namespace impeller