[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>
diff --git a/src/validator_function_test.cc b/src/validator_function_test.cc
index 601bc2c..864d9cb 100644
--- a/src/validator_function_test.cc
+++ b/src/validator_function_test.cc
@@ -83,6 +83,7 @@
   body->append(std::make_unique<ast::ReturnStatement>());
   func->set_body(std::move(body));
   mod()->AddFunction(std::move(func));
+  AddFakeEntryPoint();
 
   EXPECT_TRUE(td()->Determine()) << td()->error();
   EXPECT_TRUE(v()->Validate(mod())) << v()->error();
diff --git a/src/validator_test.cc b/src/validator_test.cc
index 6dc58c26..32bf883 100644
--- a/src/validator_test.cc
+++ b/src/validator_test.cc
@@ -263,9 +263,10 @@
   auto global_var = std::make_unique<ast::Variable>(
       Source{12, 34}, "global_var", ast::StorageClass::kInput, &f32);
   mod()->AddGlobalVariable(std::move(global_var));
+  AddFakeEntryPoint();
+
   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) {
@@ -275,9 +276,8 @@
       Source{12, 34}, "global_var", ast::StorageClass::kNone, &f32);
   mod()->AddGlobalVariable(std::move(global_var));
   EXPECT_TRUE(td()->Determine()) << td()->error();
-  tint::ValidatorImpl v;
-  EXPECT_FALSE(v.Validate(mod()));
-  EXPECT_EQ(v.error(),
+  EXPECT_FALSE(v()->Validate(mod()));
+  EXPECT_EQ(v()->error(),
             "12:34: v-0022: global variables must have a storage class");
 }
 
@@ -346,6 +346,7 @@
   func->set_body(std::move(body));
   auto* func_ptr = func.get();
   mod()->AddFunction(std::move(func));
+  AddFakeEntryPoint();
 
   EXPECT_TRUE(td()->Determine()) << td()->error();
   EXPECT_TRUE(td()->DetermineFunction(func_ptr)) << td()->error();
@@ -440,6 +441,7 @@
   var1->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
       std::make_unique<ast::SintLiteral>(&i32, 0)));
   mod()->AddGlobalVariable(std::move(var1));
+  AddFakeEntryPoint();
 
   EXPECT_TRUE(v()->Validate(mod())) << v()->error();
 }
@@ -674,6 +676,7 @@
 
   mod()->AddFunction(std::move(func0));
   mod()->AddFunction(std::move(func1));
+  AddFakeEntryPoint();
 
   EXPECT_TRUE(td()->Determine()) << td()->error();
   EXPECT_TRUE(v()->Validate(mod())) << v()->error();
diff --git a/src/validator_test_helper.cc b/src/validator_test_helper.cc
index 349ad8a..75151c0 100644
--- a/src/validator_test_helper.cc
+++ b/src/validator_test_helper.cc
@@ -13,6 +13,7 @@
 // limitations under the License.
 
 #include "src/validator_test_helper.h"
+#include "src/type_manager.h"
 
 namespace tint {
 
@@ -23,4 +24,22 @@
 
 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
diff --git a/src/validator_test_helper.h b/src/validator_test_helper.h
index 9dbde6c..990e2ab 100644
--- a/src/validator_test_helper.h
+++ b/src/validator_test_helper.h
@@ -15,6 +15,7 @@
 #ifndef 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/validator_impl.h"
 
@@ -36,6 +37,8 @@
   /// A handle to the created module
   /// @return a pointer to the test module
   ast::Module* mod() { return &mod_; }
+  /// Create a function and add an entry point to it
+  void AddFakeEntryPoint();
 
  private:
   std::unique_ptr<ValidatorImpl> v_;