[validation] Add a helper function to create a fake entry point

Change-Id: I234c04315bec006597caed38f1872baf348a3651
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27482
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Sarah Mashayekhi 2020-08-27 17:59:20 +00:00 committed by Commit Bot service account
parent 8d72a2bc4e
commit 4bc38c3f63
4 changed files with 31 additions and 5 deletions

View File

@ -83,6 +83,7 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
body->append(std::make_unique<ast::ReturnStatement>()); body->append(std::make_unique<ast::ReturnStatement>());
func->set_body(std::move(body)); func->set_body(std::move(body));
mod()->AddFunction(std::move(func)); mod()->AddFunction(std::move(func));
AddFakeEntryPoint();
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod())) << v()->error(); EXPECT_TRUE(v()->Validate(mod())) << v()->error();

View File

@ -263,9 +263,10 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
auto global_var = std::make_unique<ast::Variable>( auto global_var = std::make_unique<ast::Variable>(
Source{12, 34}, "global_var", ast::StorageClass::kInput, &f32); Source{12, 34}, "global_var", ast::StorageClass::kInput, &f32);
mod()->AddGlobalVariable(std::move(global_var)); mod()->AddGlobalVariable(std::move(global_var));
AddFakeEntryPoint();
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
tint::ValidatorImpl v; EXPECT_TRUE(v()->Validate(mod())) << v()->error();
EXPECT_TRUE(v.Validate(mod())) << v.error();
} }
TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) { TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
@ -275,9 +276,8 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
Source{12, 34}, "global_var", ast::StorageClass::kNone, &f32); Source{12, 34}, "global_var", ast::StorageClass::kNone, &f32);
mod()->AddGlobalVariable(std::move(global_var)); mod()->AddGlobalVariable(std::move(global_var));
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
tint::ValidatorImpl v; EXPECT_FALSE(v()->Validate(mod()));
EXPECT_FALSE(v.Validate(mod())); EXPECT_EQ(v()->error(),
EXPECT_EQ(v.error(),
"12:34: v-0022: global variables must have a storage class"); "12:34: v-0022: global variables must have a storage class");
} }
@ -346,6 +346,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
func->set_body(std::move(body)); func->set_body(std::move(body));
auto* func_ptr = func.get(); auto* func_ptr = func.get();
mod()->AddFunction(std::move(func)); mod()->AddFunction(std::move(func));
AddFakeEntryPoint();
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func_ptr)) << td()->error(); EXPECT_TRUE(td()->DetermineFunction(func_ptr)) << td()->error();
@ -440,6 +441,7 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
var1->set_constructor(std::make_unique<ast::ScalarConstructorExpression>( var1->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 0))); std::make_unique<ast::SintLiteral>(&i32, 0)));
mod()->AddGlobalVariable(std::move(var1)); mod()->AddGlobalVariable(std::move(var1));
AddFakeEntryPoint();
EXPECT_TRUE(v()->Validate(mod())) << v()->error(); EXPECT_TRUE(v()->Validate(mod())) << v()->error();
} }
@ -674,6 +676,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
mod()->AddFunction(std::move(func0)); mod()->AddFunction(std::move(func0));
mod()->AddFunction(std::move(func1)); mod()->AddFunction(std::move(func1));
AddFakeEntryPoint();
EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod())) << v()->error(); EXPECT_TRUE(v()->Validate(mod())) << v()->error();

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include "src/validator_test_helper.h" #include "src/validator_test_helper.h"
#include "src/type_manager.h"
namespace tint { namespace tint {
@ -23,4 +24,22 @@ ValidatorTestHelper::ValidatorTestHelper() {
ValidatorTestHelper::~ValidatorTestHelper() = default; ValidatorTestHelper::~ValidatorTestHelper() = default;
void ValidatorTestHelper::AddFakeEntryPoint() {
// entry_point vertex as "fake_entry_point" = fake_func
// fn fake_func() -> void {}
auto ep = std::make_unique<ast::EntryPoint>(ast::PipelineStage::kVertex,
"fake_entry_point", "fake_func");
ast::VariableList fake_params;
auto fake_func = std::make_unique<ast::Function>(
"fake_func", std::move(fake_params),
ctx_.type_mgr().Get(std::make_unique<ast::type::VoidType>()));
auto fake_body = std::make_unique<ast::BlockStatement>();
auto return_stmt = std::make_unique<ast::ReturnStatement>();
fake_body->append(std::move(return_stmt));
fake_func->set_body(std::move(fake_body));
mod()->AddFunction(std::move(fake_func));
mod()->AddEntryPoint(std::move(ep));
return;
}
} // namespace tint } // namespace tint

View File

@ -15,6 +15,7 @@
#ifndef SRC_VALIDATOR_TEST_HELPER_H_ #ifndef SRC_VALIDATOR_TEST_HELPER_H_
#define SRC_VALIDATOR_TEST_HELPER_H_ #define SRC_VALIDATOR_TEST_HELPER_H_
#include "src/ast/type/void_type.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/validator_impl.h" #include "src/validator_impl.h"
@ -36,6 +37,8 @@ class ValidatorTestHelper {
/// A handle to the created module /// A handle to the created module
/// @return a pointer to the test module /// @return a pointer to the test module
ast::Module* mod() { return &mod_; } ast::Module* mod() { return &mod_; }
/// Create a function and add an entry point to it
void AddFakeEntryPoint();
private: private:
std::unique_ptr<ValidatorImpl> v_; std::unique_ptr<ValidatorImpl> v_;