| 1 |
// Copyright (c) 2016 Google Inc. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
#include "gmock/gmock.h" |
| 16 |
#include "test/test_fixture.h" |
| 17 |
|
| 18 |
namespace spvtools { |
| 19 |
namespace { |
| 20 |
|
| 21 |
using ::spvtest::MakeInstruction; |
| 22 |
using ::testing::Eq; |
| 23 |
|
| 24 |
using OpTypePipeStorageTest = spvtest::TextToBinaryTest; |
| 25 |
|
| 26 |
// It can assemble, but should not validate. Validation checks for version |
| 27 |
// and capability are in another test file. |
| 28 |
TEST_F(OpTypePipeStorageTest, OpcodeAssemblesInV10) { |
| 29 |
EXPECT_THAT( |
| 30 |
CompiledInstructions("%res = OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_0), |
| 31 |
Eq(MakeInstruction(SpvOpTypePipeStorage, {1}))); |
| 32 |
} |
| 33 |
|
| 34 |
TEST_F(OpTypePipeStorageTest, ArgumentCount) { |
| 35 |
EXPECT_THAT( |
| 36 |
CompileFailure("OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_1), |
| 37 |
Eq("Expected <result-id> at the beginning of an instruction, found " |
| 38 |
"'OpTypePipeStorage'.")); |
| 39 |
EXPECT_THAT( |
| 40 |
CompiledInstructions("%res = OpTypePipeStorage", SPV_ENV_UNIVERSAL_1_1), |
| 41 |
Eq(MakeInstruction(SpvOpTypePipeStorage, {1}))); |
| 42 |
EXPECT_THAT(CompileFailure("%res = OpTypePipeStorage %1 %2 %3 %4 %5", |
| 43 |
SPV_ENV_UNIVERSAL_1_1), |
| 44 |
Eq("'=' expected after result id.")); |
| 45 |
} |
| 46 |
|
| 47 |
using OpConstantPipeStorageTest = spvtest::TextToBinaryTest; |
| 48 |
|
| 49 |
TEST_F(OpConstantPipeStorageTest, OpcodeAssemblesInV10) { |
| 50 |
EXPECT_THAT(CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5", |
| 51 |
SPV_ENV_UNIVERSAL_1_0), |
| 52 |
Eq(MakeInstruction(SpvOpConstantPipeStorage, {1, 2, 3, 4, 5}))); |
| 53 |
} |
| 54 |
|
| 55 |
TEST_F(OpConstantPipeStorageTest, ArgumentCount) { |
| 56 |
EXPECT_THAT( |
| 57 |
CompileFailure("OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1), |
| 58 |
Eq("Expected <result-id> at the beginning of an instruction, found " |
| 59 |
"'OpConstantPipeStorage'.")); |
| 60 |
EXPECT_THAT( |
| 61 |
CompileFailure("%1 = OpConstantPipeStorage", SPV_ENV_UNIVERSAL_1_1), |
| 62 |
Eq("Expected operand, found end of stream.")); |
| 63 |
EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4", |
| 64 |
SPV_ENV_UNIVERSAL_1_1), |
| 65 |
Eq("Expected operand, found end of stream.")); |
| 66 |
EXPECT_THAT(CompiledInstructions("%1 = OpConstantPipeStorage %2 3 4 5", |
| 67 |
SPV_ENV_UNIVERSAL_1_1), |
| 68 |
Eq(MakeInstruction(SpvOpConstantPipeStorage, {1, 2, 3, 4, 5}))); |
| 69 |
EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 5 %6 %7", |
| 70 |
SPV_ENV_UNIVERSAL_1_1), |
| 71 |
Eq("'=' expected after result id.")); |
| 72 |
} |
| 73 |
|
| 74 |
TEST_F(OpConstantPipeStorageTest, ArgumentTypes) { |
| 75 |
EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 %3 4 5", |
| 76 |
SPV_ENV_UNIVERSAL_1_1), |
| 77 |
Eq("Invalid unsigned integer literal: %3")); |
| 78 |
EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 %4 5", |
| 79 |
SPV_ENV_UNIVERSAL_1_1), |
| 80 |
Eq("Invalid unsigned integer literal: %4")); |
| 81 |
EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage 2 3 4 5", |
| 82 |
SPV_ENV_UNIVERSAL_1_1), |
| 83 |
Eq("Expected id to start with %.")); |
| 84 |
EXPECT_THAT(CompileFailure("%1 = OpConstantPipeStorage %2 3 4 \"ab\"", |
| 85 |
SPV_ENV_UNIVERSAL_1_1), |
| 86 |
Eq("Invalid unsigned integer literal: \"ab\"")); |
| 87 |
} |
| 88 |
|
| 89 |
using OpCreatePipeFromPipeStorageTest = spvtest::TextToBinaryTest; |
| 90 |
|
| 91 |
TEST_F(OpCreatePipeFromPipeStorageTest, OpcodeAssemblesInV10) { |
| 92 |
EXPECT_THAT(CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3", |
| 93 |
SPV_ENV_UNIVERSAL_1_0), |
| 94 |
Eq(MakeInstruction(SpvOpCreatePipeFromPipeStorage, {1, 2, 3}))); |
| 95 |
} |
| 96 |
|
| 97 |
TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentCount) { |
| 98 |
EXPECT_THAT( |
| 99 |
CompileFailure("OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1), |
| 100 |
Eq("Expected <result-id> at the beginning of an instruction, found " |
| 101 |
"'OpCreatePipeFromPipeStorage'.")); |
| 102 |
EXPECT_THAT( |
| 103 |
CompileFailure("%1 = OpCreatePipeFromPipeStorage", SPV_ENV_UNIVERSAL_1_1), |
| 104 |
Eq("Expected operand, found end of stream.")); |
| 105 |
EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 OpNop", |
| 106 |
SPV_ENV_UNIVERSAL_1_1), |
| 107 |
Eq("Expected operand, found next instruction instead.")); |
| 108 |
EXPECT_THAT(CompiledInstructions("%1 = OpCreatePipeFromPipeStorage %2 %3", |
| 109 |
SPV_ENV_UNIVERSAL_1_1), |
| 110 |
Eq(MakeInstruction(SpvOpCreatePipeFromPipeStorage, {1, 2, 3}))); |
| 111 |
EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 %3 %4 %5", |
| 112 |
SPV_ENV_UNIVERSAL_1_1), |
| 113 |
Eq("'=' expected after result id.")); |
| 114 |
} |
| 115 |
|
| 116 |
TEST_F(OpCreatePipeFromPipeStorageTest, ArgumentTypes) { |
| 117 |
EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage \"\" %3", |
| 118 |
SPV_ENV_UNIVERSAL_1_1), |
| 119 |
Eq("Expected id to start with %.")); |
| 120 |
EXPECT_THAT(CompileFailure("%1 = OpCreatePipeFromPipeStorage %2 3", |
| 121 |
SPV_ENV_UNIVERSAL_1_1), |
| 122 |
Eq("Expected id to start with %.")); |
| 123 |
} |
| 124 |
|
| 125 |
} // namespace |
| 126 |
} // namespace spvtools |