test: Remove HLSL & MSL Validate() logic

We have the end-to-end test-runner which validates all this stuff.
There's no need to also Validate in the unit tests.

Change-Id: I8fbc1ecd395efcedec4aa41085e691c88f3b66a5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54160
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-06-11 13:22:27 +00:00
parent 7fe0106b12
commit aff8f8f26a
17 changed files with 4 additions and 377 deletions

View File

@ -119,7 +119,7 @@ cmake --build . --config %BUILD_TYPE% || goto :error
call :status "Running tint_unittests"
@echo on
%BUILD_TYPE%\tint_unittests.exe --validate-hlsl || goto :error
%BUILD_TYPE%\tint_unittests.exe || goto :error
@echo off
call :status "Testing test/test-all.sh"

View File

@ -892,7 +892,6 @@ if(${TINT_BUILD_TESTS})
writer/msl/generator_impl_type_test.cc
writer/msl/generator_impl_unary_op_test.cc
writer/msl/generator_impl_variable_decl_statement_test.cc
writer/msl/test_helper.cc
writer/msl/test_helper.h
)
endif()
@ -930,7 +929,6 @@ if(${TINT_BUILD_TESTS})
writer/hlsl/generator_impl_unary_op_test.cc
writer/hlsl/generator_impl_variable_decl_statement_test.cc
writer/hlsl/generator_impl_workgroup_var_test.cc
writer/hlsl/test_helper.cc
writer/hlsl/test_helper.h
)
endif()
@ -947,7 +945,7 @@ if(${TINT_BUILD_TESTS})
## Test executable
target_include_directories(
tint_unittests PRIVATE ${gmock_SOURCE_DIR}/include)
target_link_libraries(tint_unittests libtint gmock tint_val)
target_link_libraries(tint_unittests libtint gmock tint_utils_io)
tint_default_compile_options(tint_unittests)
if(${TINT_BUILD_SPV_READER} OR ${TINT_BUILD_SPV_WRITER})

View File

@ -14,7 +14,6 @@
#include "gmock/gmock.h"
#include "src/reader/spirv/parser_impl_test_helper.h"
#include "src/utils/io/command.h"
#include "src/writer/hlsl/test_helper.h"
#include "src/writer/msl/test_helper.h"
@ -25,10 +24,6 @@ void TintInternalCompilerErrorReporter(const tint::diag::List& diagnostics) {
}
struct Flags {
bool validate_hlsl = false;
std::string dxc_path;
bool validate_msl = false;
std::string xcrun_path;
bool spirv_reader_dump_converted = false;
bool parse(int argc, char** argv) {
@ -36,26 +31,7 @@ struct Flags {
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 if (match("--validate-msl") ||
parse_value("--xcrun-path", xcrun_path)) {
validate_msl = true;
} else if (match("--dump-spirv")) {
if (match("--dump-spirv")) {
spirv_reader_dump_converted = true;
} else {
std::cout << "Unknown flag '" << argv[i] << "'" << std::endl;
@ -77,59 +53,6 @@ int main(int argc, char** 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
#if TINT_BUILD_MSL_WRITER
#ifdef TINT_ENABLE_MSL_VALIDATION_USING_METAL_API
std::cout << "MSL validation with metal API enabled" << std::endl;
#else
// This must be kept alive for the duration of RUN_ALL_TESTS() as the c_str()
// is passed into tint::writer::msl::EnableMSLValidation(), which does not
// make a copy. This is to work around Chromium's strict rules on globals
// having no constructors / destructors.
std::string xcrun_path;
if (flags.validate_msl) {
auto xcrun = flags.xcrun_path.empty()
? tint::utils::Command::LookPath("xcrun")
: tint::utils::Command(flags.xcrun_path);
if (!xcrun.Found()) {
std::cout << "xcrun executable not found" << std::endl;
return -1;
}
std::cout << "MSL validation with XCode SDK enabled" << std::endl;
xcrun_path = xcrun.Path();
tint::writer::msl::EnableMSLValidation(xcrun_path.c_str());
} else {
std::cout << "MSL validation with XCode SDK is not enabled" << std::endl;
}
#endif // TINT_ENABLE_MSL_VALIDATION_USING_METAL_API
#endif // TINT_BUILD_MSL_WRITER
#if TINT_BUILD_SPV_READER
if (flags.spirv_reader_dump_converted) {
tint::reader::spirv::test::DumpSuccessfullyConvertedSpirv();

View File

@ -31,8 +31,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("false"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
@ -42,8 +40,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("-12345"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
@ -53,8 +49,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("56779u"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
@ -65,8 +59,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("1073741824.0f"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
@ -76,8 +68,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("float(-0.000012f)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
@ -87,8 +77,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("bool(true)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
@ -98,8 +86,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("int(-12345)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) {
@ -109,8 +95,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("uint(12345u)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) {
@ -120,8 +104,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("float3(1.0f, 2.0f, 3.0f)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec_Empty) {
@ -131,8 +113,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec_Empty) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("float3(0.0f, 0.0f, 0.0f)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor,
@ -143,8 +123,6 @@ TEST_F(HlslGeneratorImplTest_Constructor,
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("float3((2.0f).xxx)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor,
@ -155,8 +133,6 @@ TEST_F(HlslGeneratorImplTest_Constructor,
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("bool3((true).xxx)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor,
@ -167,8 +143,6 @@ TEST_F(HlslGeneratorImplTest_Constructor,
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("int3((2).xxx)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor,
@ -179,8 +153,6 @@ TEST_F(HlslGeneratorImplTest_Constructor,
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("uint3((2u).xxx)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
@ -195,8 +167,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
result(),
HasSubstr(
"float2x3(float3(1.0f, 2.0f, 3.0f), float3(3.0f, 4.0f, 5.0f))"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat_Empty) {
@ -208,8 +178,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat_Empty) {
EXPECT_THAT(result(),
HasSubstr("float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Array) {
@ -223,8 +191,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Array) {
EXPECT_THAT(result(),
HasSubstr("{float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f),"
" float3(7.0f, 8.0f, 9.0f)}"));
Validate();
}
// TODO(bclayton): Zero-init arrays
@ -238,8 +204,6 @@ TEST_F(HlslGeneratorImplTest_Constructor,
EXPECT_THAT(result(),
HasSubstr("{float3(0.0f, 0.0f, 0.0f), float3(0.0f, 0.0f, 0.0f),"
" float3(0.0f, 0.0f, 0.0f)}"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Struct) {
@ -255,8 +219,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Struct) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("{1, 2.0f, int3(3, 4, 5)}"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Struct_Empty) {
@ -272,8 +234,6 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Struct_Empty) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("{0, 0.0f, int3(0, 0, 0)}"));
Validate();
}
} // namespace

View File

@ -96,8 +96,6 @@ TEST_F(HlslGeneratorImplTest_Function,
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function, PtrParameter) {
@ -115,8 +113,6 @@ TEST_F(HlslGeneratorImplTest_Function, PtrParameter) {
}
)"));
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -145,8 +141,6 @@ tint_symbol_2 frag_main(tint_symbol_1 tint_symbol) {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -178,8 +172,6 @@ tint_symbol_2 frag_main(tint_symbol_1 tint_symbol) {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -252,8 +244,6 @@ void frag_main(tint_symbol_3 tint_symbol_2) {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -320,8 +310,6 @@ tint_symbol_2 vert_main2() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -374,8 +362,6 @@ void frag_main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -416,8 +402,6 @@ void frag_main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -461,8 +445,6 @@ void frag_main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -505,8 +487,6 @@ void frag_main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -546,8 +526,6 @@ void frag_main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -588,8 +566,6 @@ void frag_main() {
}
)");
Validate();
}
// TODO(crbug.com/tint/697): Remove this test
@ -652,8 +628,6 @@ ep_1_out ep_1(ep_1_in tint_in) {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -695,8 +669,6 @@ ep_1_out ep_1() {
}
)");
Validate();
}
// TODO(crbug.com/tint/697): Remove this test
@ -751,8 +723,6 @@ ep_1_out ep_1(ep_1_in tint_in) {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -801,8 +771,6 @@ void frag_main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -850,8 +818,6 @@ void frag_main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -891,8 +857,6 @@ ep_1_out ep_1() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -930,8 +894,6 @@ void main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -951,8 +913,6 @@ void main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -978,8 +938,6 @@ void main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function,
@ -1014,8 +972,6 @@ void main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
@ -1112,8 +1068,6 @@ void b() {
}
)");
Validate();
}
} // namespace

View File

@ -504,8 +504,6 @@ void main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Intrinsic, WorkgroupBarrier) {
@ -523,8 +521,6 @@ void main() {
}
)");
Validate();
}
TEST_F(HlslGeneratorImplTest_Intrinsic, Ignore) {
@ -549,8 +545,6 @@ void main() {
}
)");
Validate();
}
} // namespace

View File

@ -375,8 +375,6 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
EXPECT_THAT(result(), HasSubstr(expected.pre));
EXPECT_THAT(result(), HasSubstr(expected.out));
Validate();
}
INSTANTIATE_TEST_SUITE_P(

View File

@ -184,8 +184,6 @@ TEST_P(HlslGeneratorImplTest_MemberAccessor_StorageBufferLoad, Test) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(p.expected));
Validate();
}
INSTANTIATE_TEST_SUITE_P(
@ -259,8 +257,6 @@ TEST_P(HlslGeneratorImplTest_MemberAccessor_StorageBufferStore, Test) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(p.expected));
Validate();
}
INSTANTIATE_TEST_SUITE_P(
@ -361,8 +357,6 @@ void main() {
)";
EXPECT_EQ(result(), expected);
Validate();
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -399,8 +393,6 @@ void main() {
)";
EXPECT_EQ(result(), expected);
Validate();
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -545,8 +537,6 @@ void main() {
)";
EXPECT_EQ(result(), expected);
Validate();
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -593,8 +583,6 @@ void main() {
)";
EXPECT_EQ(result(), expected);
Validate();
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -641,8 +629,6 @@ void main() {
)";
EXPECT_EQ(result(), expected);
Validate();
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -689,8 +675,6 @@ void main() {
)";
EXPECT_EQ(result(), expected);
Validate();
}
TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_MultiLevel) {
@ -733,8 +717,6 @@ void main() {
)";
EXPECT_EQ(result(), expected);
Validate();
}
TEST_F(HlslGeneratorImplTest_MemberAccessor,
@ -781,8 +763,6 @@ void main() {
)";
EXPECT_EQ(result(), expected);
Validate();
}
TEST_F(HlslGeneratorImplTest_MemberAccessor, Swizzle_xyz) {
@ -794,8 +774,6 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, Swizzle_xyz) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("my_vec.xyz"));
Validate();
}
TEST_F(HlslGeneratorImplTest_MemberAccessor, Swizzle_gbr) {
@ -807,8 +785,6 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, Swizzle_gbr) {
GeneratorImpl& gen = SanitizeAndBuild();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("my_vec.gbr"));
Validate();
}
} // namespace

View File

@ -367,8 +367,6 @@ TEST_P(HlslDepthTexturesTest, Emit) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(params.result));
Validate();
}
INSTANTIATE_TEST_SUITE_P(
HlslGeneratorImplTest_Type,
@ -425,8 +423,6 @@ TEST_P(HlslSampledTexturesTest, Emit) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(params.result));
Validate();
}
INSTANTIATE_TEST_SUITE_P(
HlslGeneratorImplTest_Type,
@ -567,8 +563,6 @@ TEST_P(HlslStorageTexturesTest, Emit) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr(params.result));
Validate();
}
INSTANTIATE_TEST_SUITE_P(
HlslGeneratorImplTest_Type,

View File

@ -34,8 +34,6 @@ TEST_F(HlslGeneratorImplTest_WorkgroupVar, Basic) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("groupshared float wg;\n"));
Validate();
}
TEST_F(HlslGeneratorImplTest_WorkgroupVar, Aliased) {
@ -49,8 +47,6 @@ TEST_F(HlslGeneratorImplTest_WorkgroupVar, Aliased) {
ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_THAT(result(), HasSubstr("groupshared float wg;\n"));
Validate();
}
} // namespace

View File

@ -1,45 +0,0 @@
// 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 "src/writer/hlsl/test_helper.h"
namespace tint {
namespace writer {
namespace hlsl {
namespace {
const char* dxc_path = nullptr;
} // namespace
void EnableHLSLValidation(const char* dxc) {
dxc_path = dxc;
}
val::Result Validate(Program* program, GeneratorImpl* generator) {
if (!dxc_path) {
return val::Result{};
}
std::ostringstream hlsl;
if (!generator->Generate(hlsl)) {
return {true, generator->error(), ""};
}
return val::Hlsl(dxc_path, hlsl.str(), program);
}
} // namespace hlsl
} // namespace writer
} // namespace tint

View File

@ -23,24 +23,12 @@
#include "src/transform/hlsl.h"
#include "src/transform/manager.h"
#include "src/transform/renamer.h"
#include "src/val/val.h"
#include "src/writer/hlsl/generator_impl.h"
namespace tint {
namespace writer {
namespace hlsl {
/// EnableHLSLValidation enables verification of HLSL shaders by running DXC and
/// checking no errors are reported.
/// @param dxc_path the path to the DXC executable
void EnableHLSLValidation(const char* dxc_path);
/// Validate attempts to compile the shader with DXC if found on PATH.
/// @param program the HLSL program
/// @param generator the HLSL generator
/// @return the result of the compile
val::Result Validate(Program* program, GeneratorImpl* generator);
/// Helper class for testing
template <typename BODY>
class TestHelperBase : public BODY, public ProgramBuilder {
@ -106,19 +94,6 @@ class TestHelperBase : public BODY, public ProgramBuilder {
return *gen_;
}
/// Validate passes the generated HLSL from the generator to the DXC compiler
/// on `PATH` for checking the program can be compiled.
/// If DXC finds problems the test will fail.
/// If DXC is not on `PATH` then Validate() does nothing.
void Validate() const {
auto res = hlsl::Validate(program.get(), gen_.get());
if (res.failed) {
FAIL() << "HLSL Validation failed.\n\n"
<< res.source << "\n\n"
<< res.output;
}
}
/// @returns the result string
std::string result() const { return out.str(); }

View File

@ -118,8 +118,6 @@ fragment tint_symbol_2 frag_main(tint_symbol_1 tint_symbol [[stage_in]]) {
}
)");
Validate();
}
TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_WithInOut_Builtins) {
@ -149,8 +147,6 @@ fragment tint_symbol_1 frag_main(float4 coord [[position]]) {
}
)");
Validate();
}
TEST_F(MslGeneratorImplTest,
@ -224,8 +220,6 @@ fragment void frag_main(float4 tint_symbol_3 [[position]], tint_symbol_4 tint_sy
}
)");
Validate();
}
TEST_F(MslGeneratorImplTest,
@ -293,8 +287,6 @@ vertex tint_symbol_2 vert_main2() {
}
)");
Validate();
}
TEST_F(MslGeneratorImplTest,

View File

@ -365,8 +365,6 @@ kernel void func() {
}
)");
Validate();
}
} // namespace

View File

@ -1,56 +0,0 @@
// 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 "src/writer/msl/test_helper.h"
#include "src/utils/io/command.h"
#include "src/utils/io/tmpfile.h"
namespace tint {
namespace writer {
namespace msl {
namespace {
const char* xcrun_path = nullptr;
} // namespace
void EnableMSLValidation(const char* xcrun) {
xcrun_path = xcrun;
}
val::Result Validate(Program* program) {
#ifdef TINT_ENABLE_MSL_VALIDATION_USING_METAL_API
auto gen = std::make_unique<GeneratorImpl>(program);
if (!gen->Generate()) {
return {true, gen->error(), ""};
}
return tint::val::MslUsingMetalAPI(gen->result());
#else // TINT_ENABLE_MSL_VALIDATION_USING_METAL_API
if (!xcrun_path) {
return val::Result{};
}
auto gen = std::make_unique<GeneratorImpl>(program);
if (!gen->Generate()) {
return {true, gen->error(), ""};
}
return val::Msl(xcrun_path, gen->result());
#endif // TINT_ENABLE_MSL_VALIDATION_USING_METAL_API
}
} // namespace msl
} // namespace writer
} // namespace tint

View File

@ -22,23 +22,12 @@
#include "gtest/gtest.h"
#include "src/program_builder.h"
#include "src/transform/msl.h"
#include "src/val/val.h"
#include "src/writer/msl/generator_impl.h"
namespace tint {
namespace writer {
namespace msl {
/// Enables verification of MSL shaders by running the Metal compiler and
/// checking no errors are reported.
/// @param xcrun_path the path to the `xcrun` executable
void EnableMSLValidation(const char* xcrun_path);
/// Validate attempts to compile the shader with DXC if found on PATH.
/// @param program the MSL program
/// @return the result of the compile
val::Result Validate(Program* program);
/// Helper class for testing
template <typename BASE>
class TestHelperBase : public BASE, public ProgramBuilder {
@ -96,22 +85,6 @@ class TestHelperBase : public BASE, public ProgramBuilder {
return *gen_;
}
/// Validate generates MSL code for the current contents of `program` and
/// passes the output of the generator to the XCode SDK Metal compiler.
///
/// If the Metal compiler finds problems, then any GTest test case that
/// invokes this function test will fail.
/// This function does nothing, if the Metal compiler path has not been
/// configured by calling `EnableMSLValidation()`.
void Validate() {
auto res = msl::Validate(program.get());
if (res.failed) {
FAIL() << "MSL Validation failed.\n\n"
<< res.source << "\n\n"
<< res.output;
}
}
/// The program built with a call to Build()
std::unique_ptr<Program> program;

View File

@ -94,7 +94,6 @@ source_set("tint_unittests_main") {
":tint_unittests_msl_writer_src",
":tint_unittests_spv_reader_src",
"${tint_root_dir}/src:libtint",
"${tint_root_dir}/src:tint_val",
]
}
}
@ -135,7 +134,7 @@ template("tint_unittests_source_set") {
deps += [
":gmock_and_gtest",
"${tint_root_dir}/src:libtint",
"${tint_root_dir}/src:tint_val",
"${tint_root_dir}/src:tint_utils_io",
]
}
}
@ -549,7 +548,6 @@ tint_unittests_source_set("tint_unittests_msl_writer_src") {
"../src/writer/msl/generator_impl_type_test.cc",
"../src/writer/msl/generator_impl_unary_op_test.cc",
"../src/writer/msl/generator_impl_variable_decl_statement_test.cc",
"../src/writer/msl/test_helper.cc",
"../src/writer/msl/test_helper.h",
]
@ -592,7 +590,6 @@ tint_unittests_source_set("tint_unittests_hlsl_writer_src") {
"../src/writer/hlsl/generator_impl_unary_op_test.cc",
"../src/writer/hlsl/generator_impl_variable_decl_statement_test.cc",
"../src/writer/hlsl/generator_impl_workgroup_var_test.cc",
"../src/writer/hlsl/test_helper.cc",
"../src/writer/hlsl/test_helper.h",
]