1fd4e5da5Sopenharmony_ci// Copyright (c) 2016 Google 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// Assembler tests for instructions in the "Barrier Instructions" section 16fd4e5da5Sopenharmony_ci// of the SPIR-V spec. 17fd4e5da5Sopenharmony_ci 18fd4e5da5Sopenharmony_ci#include "test/unit_spirv.h" 19fd4e5da5Sopenharmony_ci 20fd4e5da5Sopenharmony_ci#include "gmock/gmock.h" 21fd4e5da5Sopenharmony_ci#include "test/test_fixture.h" 22fd4e5da5Sopenharmony_ci 23fd4e5da5Sopenharmony_cinamespace spvtools { 24fd4e5da5Sopenharmony_cinamespace { 25fd4e5da5Sopenharmony_ci 26fd4e5da5Sopenharmony_ciusing ::spvtest::MakeInstruction; 27fd4e5da5Sopenharmony_ciusing ::testing::Eq; 28fd4e5da5Sopenharmony_ci 29fd4e5da5Sopenharmony_ciusing OpGetKernelLocalSizeForSubgroupCountTest = spvtest::TextToBinaryTest; 30fd4e5da5Sopenharmony_ci 31fd4e5da5Sopenharmony_ci// We should be able to assemble it. Validation checks are in another test 32fd4e5da5Sopenharmony_ci// file. 33fd4e5da5Sopenharmony_ciTEST_F(OpGetKernelLocalSizeForSubgroupCountTest, OpcodeAssemblesInV10) { 34fd4e5da5Sopenharmony_ci EXPECT_THAT( 35fd4e5da5Sopenharmony_ci CompiledInstructions("%res = OpGetKernelLocalSizeForSubgroupCount %type " 36fd4e5da5Sopenharmony_ci "%sgcount %invoke %param %param_size %param_align", 37fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_0), 38fd4e5da5Sopenharmony_ci Eq(MakeInstruction(spv::Op::OpGetKernelLocalSizeForSubgroupCount, 39fd4e5da5Sopenharmony_ci {1, 2, 3, 4, 5, 6, 7}))); 40fd4e5da5Sopenharmony_ci} 41fd4e5da5Sopenharmony_ci 42fd4e5da5Sopenharmony_ciTEST_F(OpGetKernelLocalSizeForSubgroupCountTest, ArgumentCount) { 43fd4e5da5Sopenharmony_ci EXPECT_THAT(CompileFailure("OpGetKernelLocalSizeForSubgroupCount", 44fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 45fd4e5da5Sopenharmony_ci Eq("Expected <result-id> at the beginning of an instruction, " 46fd4e5da5Sopenharmony_ci "found 'OpGetKernelLocalSizeForSubgroupCount'.")); 47fd4e5da5Sopenharmony_ci EXPECT_THAT(CompileFailure("%res = OpGetKernelLocalSizeForSubgroupCount", 48fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 49fd4e5da5Sopenharmony_ci Eq("Expected operand for OpGetKernelLocalSizeForSubgroupCount " 50fd4e5da5Sopenharmony_ci "instruction, but found the end of the stream.")); 51fd4e5da5Sopenharmony_ci EXPECT_THAT( 52fd4e5da5Sopenharmony_ci CompileFailure("%1 = OpGetKernelLocalSizeForSubgroupCount %2 %3 %4 %5 %6", 53fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 54fd4e5da5Sopenharmony_ci Eq("Expected operand for OpGetKernelLocalSizeForSubgroupCount " 55fd4e5da5Sopenharmony_ci "instruction, but found the end of the stream.")); 56fd4e5da5Sopenharmony_ci EXPECT_THAT( 57fd4e5da5Sopenharmony_ci CompiledInstructions("%res = OpGetKernelLocalSizeForSubgroupCount %type " 58fd4e5da5Sopenharmony_ci "%sgcount %invoke %param %param_size %param_align", 59fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 60fd4e5da5Sopenharmony_ci Eq(MakeInstruction(spv::Op::OpGetKernelLocalSizeForSubgroupCount, 61fd4e5da5Sopenharmony_ci {1, 2, 3, 4, 5, 6, 7}))); 62fd4e5da5Sopenharmony_ci EXPECT_THAT( 63fd4e5da5Sopenharmony_ci CompileFailure("%res = OpGetKernelLocalSizeForSubgroupCount %type " 64fd4e5da5Sopenharmony_ci "%sgcount %invoke %param %param_size %param_align %extra", 65fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 66fd4e5da5Sopenharmony_ci Eq("Expected '=', found end of stream.")); 67fd4e5da5Sopenharmony_ci} 68fd4e5da5Sopenharmony_ci 69fd4e5da5Sopenharmony_ciTEST_F(OpGetKernelLocalSizeForSubgroupCountTest, ArgumentTypes) { 70fd4e5da5Sopenharmony_ci EXPECT_THAT(CompileFailure( 71fd4e5da5Sopenharmony_ci "%1 = OpGetKernelLocalSizeForSubgroupCount 2 %3 %4 %5 %6 %7", 72fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 73fd4e5da5Sopenharmony_ci Eq("Expected id to start with %.")); 74fd4e5da5Sopenharmony_ci EXPECT_THAT( 75fd4e5da5Sopenharmony_ci CompileFailure( 76fd4e5da5Sopenharmony_ci "%1 = OpGetKernelLocalSizeForSubgroupCount %2 %3 %4 %5 %6 \"abc\"", 77fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 78fd4e5da5Sopenharmony_ci Eq("Expected id to start with %.")); 79fd4e5da5Sopenharmony_ci} 80fd4e5da5Sopenharmony_ci 81fd4e5da5Sopenharmony_ciusing OpGetKernelMaxNumSubgroupsTest = spvtest::TextToBinaryTest; 82fd4e5da5Sopenharmony_ci 83fd4e5da5Sopenharmony_ciTEST_F(OpGetKernelMaxNumSubgroupsTest, OpcodeAssemblesInV10) { 84fd4e5da5Sopenharmony_ci EXPECT_THAT(CompiledInstructions("%res = OpGetKernelMaxNumSubgroups %type " 85fd4e5da5Sopenharmony_ci "%invoke %param %param_size %param_align", 86fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_0), 87fd4e5da5Sopenharmony_ci Eq(MakeInstruction(spv::Op::OpGetKernelMaxNumSubgroups, 88fd4e5da5Sopenharmony_ci {1, 2, 3, 4, 5, 6}))); 89fd4e5da5Sopenharmony_ci} 90fd4e5da5Sopenharmony_ci 91fd4e5da5Sopenharmony_ciTEST_F(OpGetKernelMaxNumSubgroupsTest, ArgumentCount) { 92fd4e5da5Sopenharmony_ci EXPECT_THAT( 93fd4e5da5Sopenharmony_ci CompileFailure("OpGetKernelMaxNumSubgroups", SPV_ENV_UNIVERSAL_1_1), 94fd4e5da5Sopenharmony_ci Eq("Expected <result-id> at the beginning of an instruction, found " 95fd4e5da5Sopenharmony_ci "'OpGetKernelMaxNumSubgroups'.")); 96fd4e5da5Sopenharmony_ci EXPECT_THAT(CompileFailure("%res = OpGetKernelMaxNumSubgroups", 97fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 98fd4e5da5Sopenharmony_ci Eq("Expected operand for OpGetKernelMaxNumSubgroups instruction, " 99fd4e5da5Sopenharmony_ci "but found the end of the stream.")); 100fd4e5da5Sopenharmony_ci EXPECT_THAT(CompileFailure("%1 = OpGetKernelMaxNumSubgroups %2 %3 %4 %5", 101fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 102fd4e5da5Sopenharmony_ci Eq("Expected operand for OpGetKernelMaxNumSubgroups instruction, " 103fd4e5da5Sopenharmony_ci "but found the end of the stream.")); 104fd4e5da5Sopenharmony_ci EXPECT_THAT(CompiledInstructions("%res = OpGetKernelMaxNumSubgroups %type " 105fd4e5da5Sopenharmony_ci "%invoke %param %param_size %param_align", 106fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 107fd4e5da5Sopenharmony_ci Eq(MakeInstruction(spv::Op::OpGetKernelMaxNumSubgroups, 108fd4e5da5Sopenharmony_ci {1, 2, 3, 4, 5, 6}))); 109fd4e5da5Sopenharmony_ci EXPECT_THAT(CompileFailure("%res = OpGetKernelMaxNumSubgroups %type %invoke " 110fd4e5da5Sopenharmony_ci "%param %param_size %param_align %extra", 111fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 112fd4e5da5Sopenharmony_ci Eq("Expected '=', found end of stream.")); 113fd4e5da5Sopenharmony_ci} 114fd4e5da5Sopenharmony_ci 115fd4e5da5Sopenharmony_ciTEST_F(OpGetKernelMaxNumSubgroupsTest, ArgumentTypes) { 116fd4e5da5Sopenharmony_ci EXPECT_THAT(CompileFailure("%1 = OpGetKernelMaxNumSubgroups 2 %3 %4 %5 %6", 117fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 118fd4e5da5Sopenharmony_ci Eq("Expected id to start with %.")); 119fd4e5da5Sopenharmony_ci EXPECT_THAT( 120fd4e5da5Sopenharmony_ci CompileFailure("%1 = OpGetKernelMaxNumSubgroups %2 %3 %4 %5 \"abc\"", 121fd4e5da5Sopenharmony_ci SPV_ENV_UNIVERSAL_1_1), 122fd4e5da5Sopenharmony_ci Eq("Expected id to start with %.")); 123fd4e5da5Sopenharmony_ci} 124fd4e5da5Sopenharmony_ci 125fd4e5da5Sopenharmony_ci} // namespace 126fd4e5da5Sopenharmony_ci} // namespace spvtools 127