1fd4e5da5Sopenharmony_ci// Copyright (c) 2019 Samsung Inc
2fd4e5da5Sopenharmony_ci//
3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License.
5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at
6fd4e5da5Sopenharmony_ci//
7fd4e5da5Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8fd4e5da5Sopenharmony_ci//
9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and
13fd4e5da5Sopenharmony_ci// limitations under the License.
14fd4e5da5Sopenharmony_ci
15fd4e5da5Sopenharmony_ci#include <string>
16fd4e5da5Sopenharmony_ci
17fd4e5da5Sopenharmony_ci#include "gmock/gmock.h"
18fd4e5da5Sopenharmony_ci#include "test/unit_spirv.h"
19fd4e5da5Sopenharmony_ci#include "test/val/val_fixtures.h"
20fd4e5da5Sopenharmony_ci
21fd4e5da5Sopenharmony_cinamespace spvtools {
22fd4e5da5Sopenharmony_cinamespace {
23fd4e5da5Sopenharmony_ci
24fd4e5da5Sopenharmony_ciusing ::testing::Eq;
25fd4e5da5Sopenharmony_ciusing ::testing::HasSubstr;
26fd4e5da5Sopenharmony_ci
27fd4e5da5Sopenharmony_ciusing ValidateEntryPoints = spvtest::ValidateBase<bool>;
28fd4e5da5Sopenharmony_ci
29fd4e5da5Sopenharmony_ciTEST_F(ValidateEntryPoints, DuplicateEntryPoints) {
30fd4e5da5Sopenharmony_ci  const std::string body = R"(
31fd4e5da5Sopenharmony_ciOpCapability Shader
32fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
33fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %3 "foo"
34fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %4 "foo"
35fd4e5da5Sopenharmony_ci%1 = OpTypeVoid
36fd4e5da5Sopenharmony_ci%2 = OpTypeFunction %1
37fd4e5da5Sopenharmony_ci%3 = OpFunction %1 None %2
38fd4e5da5Sopenharmony_ci%20 = OpLabel
39fd4e5da5Sopenharmony_ciOpReturn
40fd4e5da5Sopenharmony_ciOpFunctionEnd
41fd4e5da5Sopenharmony_ci%4 = OpFunction %1 None %2
42fd4e5da5Sopenharmony_ci%21 = OpLabel
43fd4e5da5Sopenharmony_ciOpReturn
44fd4e5da5Sopenharmony_ciOpFunctionEnd
45fd4e5da5Sopenharmony_ci)";
46fd4e5da5Sopenharmony_ci
47fd4e5da5Sopenharmony_ci  CompileSuccessfully(body);
48fd4e5da5Sopenharmony_ci  EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
49fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
50fd4e5da5Sopenharmony_ci              HasSubstr("Entry points cannot share the same name"));
51fd4e5da5Sopenharmony_ci}
52fd4e5da5Sopenharmony_ci
53fd4e5da5Sopenharmony_ciTEST_F(ValidateEntryPoints, UniqueEntryPoints) {
54fd4e5da5Sopenharmony_ci  const std::string body = R"(
55fd4e5da5Sopenharmony_ciOpCapability Shader
56fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
57fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %3 "foo"
58fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %4 "foo2"
59fd4e5da5Sopenharmony_ci%1 = OpTypeVoid
60fd4e5da5Sopenharmony_ci%2 = OpTypeFunction %1
61fd4e5da5Sopenharmony_ci%3 = OpFunction %1 None %2
62fd4e5da5Sopenharmony_ci%20 = OpLabel
63fd4e5da5Sopenharmony_ciOpReturn
64fd4e5da5Sopenharmony_ciOpFunctionEnd
65fd4e5da5Sopenharmony_ci%4 = OpFunction %1 None %2
66fd4e5da5Sopenharmony_ci%21 = OpLabel
67fd4e5da5Sopenharmony_ciOpReturn
68fd4e5da5Sopenharmony_ciOpFunctionEnd
69fd4e5da5Sopenharmony_ci)";
70fd4e5da5Sopenharmony_ci
71fd4e5da5Sopenharmony_ci  CompileSuccessfully(body);
72fd4e5da5Sopenharmony_ci  EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
73fd4e5da5Sopenharmony_ci}
74fd4e5da5Sopenharmony_ci
75fd4e5da5Sopenharmony_ci}  // namespace
76fd4e5da5Sopenharmony_ci}  // namespace spvtools
77