mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-20 21:43:29 +00:00
Move remaining Validator tests to Resolver
Bug: tint:642 Change-Id: I0f983d8c0391f4e500562faadf0a621c4edb46ab Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46942 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
bfc97945f3
commit
e93d46fcbc
@ -522,8 +522,6 @@ if(${TINT_BUILD_TESTS})
|
||||
utils/tmpfile_test.cc
|
||||
utils/tmpfile.h
|
||||
utils/unique_vector_test.cc
|
||||
validator/validator_function_test.cc
|
||||
validator/validator_test.cc
|
||||
validator/validator_test_helper.cc
|
||||
validator/validator_test_helper.h
|
||||
writer/append_vector_test.cc
|
||||
|
@ -45,6 +45,24 @@ TEST_F(ResolverFunctionValidationTest, FunctionNamesMustBeUnique_fail) {
|
||||
"12:34 error v-0016: function names must be unique 'func'");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
VoidFunctionEndWithoutReturnStatement_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn func -> void { var a:i32 = 2; }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||
// fn func -> int { var a:i32 = 2; }
|
||||
|
||||
@ -62,6 +80,20 @@ TEST_F(ResolverFunctionValidationTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||
"12:34 error v-0002: non-void function must end with a return statement");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
VoidFunctionEndWithoutReturnStatementEmptyBody_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn func -> void {}
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
FunctionEndWithoutReturnStatementEmptyBody_Fail) {
|
||||
// fn func -> int {}
|
||||
@ -201,5 +233,43 @@ TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
|
||||
"point");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, NoPipelineEntryPoints) {
|
||||
Func("vtx_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, FunctionVarInitWithParam) {
|
||||
// fn foo(bar : f32) -> void{
|
||||
// var baz : f32 = bar;
|
||||
// }
|
||||
|
||||
auto* bar = Var("bar", ty.f32(), ast::StorageClass::kFunction);
|
||||
auto* baz = Var("baz", ty.f32(), ast::StorageClass::kFunction, Expr("bar"));
|
||||
|
||||
Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest, FunctionConstInitWithParam) {
|
||||
// fn foo(bar : f32) -> void{
|
||||
// const baz : f32 = bar;
|
||||
// }
|
||||
|
||||
auto* bar = Var("bar", ty.f32(), ast::StorageClass::kFunction);
|
||||
auto* baz = Const("baz", ty.f32(), Expr("bar"));
|
||||
|
||||
Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
||||
|
@ -26,6 +26,28 @@ namespace {
|
||||
class ResolverTypeValidationTest : public resolver::TestHelper,
|
||||
public testing::Test {};
|
||||
|
||||
TEST_F(ResolverTypeValidationTest, VariableDeclNoConstructor_Pass) {
|
||||
// {
|
||||
// var a :i32;
|
||||
// a = 2;
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, nullptr);
|
||||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
|
||||
rhs),
|
||||
});
|
||||
|
||||
WrapInFunction(body);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||
}
|
||||
|
||||
TEST_F(ResolverTypeValidationTest, GlobalVariableWithStorageClass_Pass) {
|
||||
// var<in> global_var: f32;
|
||||
Global(Source{{12, 34}}, "global_var", ty.f32(), ast::StorageClass::kInput);
|
||||
|
@ -1,104 +0,0 @@
|
||||
// Copyright 2020 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/ast/stage_decoration.h"
|
||||
#include "src/validator/validator_test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace {
|
||||
|
||||
class ValidateFunctionTest : public ValidatorTestHelper,
|
||||
public testing::Test {};
|
||||
|
||||
TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn func -> void { var a:i32 = 2; }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate());
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest,
|
||||
VoidFunctionEndWithoutReturnStatementEmptyBody_Pass) {
|
||||
// [[stage(vertex)]]
|
||||
// fn func -> void {}
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate());
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest, NoPipelineEntryPoints) {
|
||||
Func("vtx_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate()) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest, FunctionVarInitWithParam) {
|
||||
// fn foo(bar : f32) -> void{
|
||||
// var baz : f32 = bar;
|
||||
// }
|
||||
|
||||
auto* bar = Var("bar", ty.f32(), ast::StorageClass::kFunction);
|
||||
auto* baz = Var("baz", ty.f32(), ast::StorageClass::kFunction, Expr("bar"));
|
||||
|
||||
Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
|
||||
ast::DecorationList{});
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate()) << v.error();
|
||||
}
|
||||
|
||||
TEST_F(ValidateFunctionTest, FunctionConstInitWithParam) {
|
||||
// fn foo(bar : f32) -> void{
|
||||
// const baz : f32 = bar;
|
||||
// }
|
||||
|
||||
auto* bar = Var("bar", ty.f32(), ast::StorageClass::kFunction);
|
||||
auto* baz = Const("baz", ty.f32(), Expr("bar"));
|
||||
|
||||
Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
|
||||
ast::DecorationList{});
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
EXPECT_TRUE(v.Validate()) << v.error();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
@ -1,50 +0,0 @@
|
||||
// Copyright 2020 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/ast/if_statement.h"
|
||||
#include "src/ast/stage_decoration.h"
|
||||
#include "src/validator/validator_test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace {
|
||||
|
||||
class ValidatorTest : public ValidatorTestHelper, public testing::Test {};
|
||||
|
||||
TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
|
||||
// {
|
||||
// var a :i32;
|
||||
// a = 2;
|
||||
// }
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, nullptr);
|
||||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
|
||||
rhs),
|
||||
});
|
||||
|
||||
WrapInFunction(body);
|
||||
|
||||
ValidatorImpl& v = Build();
|
||||
|
||||
ASSERT_NE(TypeOf(lhs), nullptr);
|
||||
ASSERT_NE(TypeOf(rhs), nullptr);
|
||||
|
||||
EXPECT_TRUE(v.ValidateStatements(body)) << v.error();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint
|
@ -225,8 +225,6 @@ source_set("tint_unittests_core_src") {
|
||||
"../src/utils/tmpfile.h",
|
||||
"../src/utils/tmpfile_test.cc",
|
||||
"../src/utils/unique_vector_test.cc",
|
||||
"../src/validator/validator_function_test.cc",
|
||||
"../src/validator/validator_test.cc",
|
||||
"../src/validator/validator_test_helper.cc",
|
||||
"../src/validator/validator_test_helper.h",
|
||||
"../src/writer/append_vector_test.cc",
|
||||
|
Loading…
x
Reference in New Issue
Block a user