dawn-cmake/src/test_main.cc
Ben Clayton 5b36d2c612 Remove all unnecessary includes
All includes from .cc to .h are preserved, even when transitively included.

It's clear that there are far too many includes in header files, and we should be more aggressive with forward declarations. tint:532 will continue to track this work.

There are, however, plenty of includes that have accumulated over time which are no longer required directly or transitively, so this change starts with a clean slate of *required* includes.

Bug: tint:532
Change-Id: Ie1718dad565f8309fa180ef91bcf3920e76dba18
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44042
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-09 11:11:17 +00:00

100 lines
2.8 KiB
C++

// Copyright 2021 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "gmock/gmock.h"
#include "src/utils/command.h"
#include "src/writer/hlsl/test_helper.h"
namespace {
void TintInternalCompilerErrorReporter(const tint::diag::List& diagnostics) {
FAIL() << diagnostics.str();
}
struct Flags {
bool validate_hlsl = false;
std::string dxc_path;
bool parse(int argc, char** argv) {
bool errored = false;
for (int i = 1; i < argc && !errored; i++) {
auto match = [&](std::string name) { return name == argv[i]; };
auto parse_value = [&](std::string name, std::string& value) {
if (!match(name)) {
return false;
}
if (i + 1 >= argc) {
std::cout << "Expected value for flag " << name << "" << std::endl;
errored = true;
return false;
}
i++;
value = argv[i];
return true;
};
if (match("--validate-hlsl") || parse_value("--dxc-path", dxc_path)) {
validate_hlsl = true;
} else {
std::cout << "Unknown flag '" << argv[i] << "'" << std::endl;
return false;
}
}
return true;
}
};
} // namespace
// Entry point for tint unit tests
int main(int argc, char** argv) {
testing::InitGoogleMock(&argc, argv);
Flags flags;
if (!flags.parse(argc, argv)) {
return -1;
}
#if TINT_BUILD_HLSL_WRITER
// This must be kept alive for the duration of RUN_ALL_TESTS() as the c_str()
// is passed into tint::writer::hlsl::EnableHLSLValidation(), which does not
// make a copy. This is to work around Chromium's strict rules on globals
// having no constructors / destructors.
std::string dxc_path;
if (flags.validate_hlsl) {
auto dxc = flags.dxc_path.empty() ? tint::utils::Command::LookPath("dxc")
: tint::utils::Command(flags.dxc_path);
if (!dxc.Found()) {
std::cout << "DXC executable not found" << std::endl;
return -1;
}
std::cout << "HLSL validation with DXC enabled" << std::endl;
dxc_path = dxc.Path();
tint::writer::hlsl::EnableHLSLValidation(dxc_path.c_str());
} else {
std::cout << "HLSL validation with DXC is not enabled" << std::endl;
}
#endif // TINT_BUILD_HLSL_WRITER
tint::SetInternalCompilerErrorReporter(&TintInternalCompilerErrorReporter);
auto res = RUN_ALL_TESTS();
return res;
}