Setup dependent external sources
[platform/upstream/VK-GL-CTS.git] / external / spirv-tools / src / test / text_to_binary.device_side_enqueue_test.cpp
1 // Copyright (c) 2015-2016 The Khronos Group 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 // Assembler tests for instructions in the "Device-Side Enqueue Instructions"
16 // section of the SPIR-V spec.
17
18 #include "unit_spirv.h"
19
20 #include "gmock/gmock.h"
21 #include "test_fixture.h"
22
23 namespace {
24 using spvtest::MakeInstruction;
25 using ::testing::Eq;
26
27 // Test OpEnqueueKernel
28
29 struct KernelEnqueueCase {
30   std::string local_size_source;
31   std::vector<uint32_t> local_size_operands;
32 };
33
34 using OpEnqueueKernelGood =
35     spvtest::TextToBinaryTestBase<::testing::TestWithParam<KernelEnqueueCase>>;
36
37 TEST_P(OpEnqueueKernelGood, Sample) {
38   const std::string input =
39       "%result = OpEnqueueKernel %type %queue %flags %NDRange %num_events"
40       " %wait_events %ret_event %invoke %param %param_size %param_align " +
41       GetParam().local_size_source;
42   EXPECT_THAT(CompiledInstructions(input),
43               Eq(MakeInstruction(SpvOpEnqueueKernel,
44                                  {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
45                                  GetParam().local_size_operands)));
46 }
47
48 INSTANTIATE_TEST_CASE_P(
49     TextToBinaryTest, OpEnqueueKernelGood,
50     ::testing::ValuesIn(std::vector<KernelEnqueueCase>{
51         // Provide IDs for pointer-to-local arguments for the
52         // invoked function.
53         // Test up to 10 such arguments.
54         // I (dneto) can't find a limit on the number of kernel
55         // arguments in OpenCL C 2.0 Rev 29, e.g. in section 6.9
56         // Restrictions.
57         {"", {}},
58         {"%l0", {13}},
59         {"%l0 %l1", {13, 14}},
60         {"%l0 %l1 %l2", {13, 14, 15}},
61         {"%l0 %l1 %l2 %l3", {13, 14, 15, 16}},
62         {"%l0 %l1 %l2 %l3 %l4", {13, 14, 15, 16, 17}},
63         {"%l0 %l1 %l2 %l3 %l4 %l5", {13, 14, 15, 16, 17, 18}},
64         {"%l0 %l1 %l2 %l3 %l4 %l5 %l6", {13, 14, 15, 16, 17, 18, 19}},
65         {"%l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7", {13, 14, 15, 16, 17, 18, 19, 20}},
66         {"%l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7 %l8",
67          {13, 14, 15, 16, 17, 18, 19, 20, 21}},
68         {"%l0 %l1 %l2 %l3 %l4 %l5 %l6 %l7 %l8 %l9",
69          {13, 14, 15, 16, 17, 18, 19, 20, 21, 22}},
70     }),);
71
72 // Test some bad parses of OpEnqueueKernel.  For other cases, we're relying
73 // on the uniformity of the parsing algorithm.  The following two tests, ensure
74 // that every required ID operand is specified, and is actually an ID operand.
75 using OpKernelEnqueueBad = spvtest::TextToBinaryTest;
76
77 TEST_F(OpKernelEnqueueBad, MissingLastOperand) {
78   EXPECT_THAT(
79       CompileFailure(
80           "%result = OpEnqueueKernel %type %queue %flags %NDRange %num_events"
81           " %wait_events %ret_event %invoke %param %param_size"),
82       Eq("Expected operand, found end of stream."));
83 }
84
85 TEST_F(OpKernelEnqueueBad, InvalidLastOperand) {
86   EXPECT_THAT(
87       CompileFailure(
88           "%result = OpEnqueueKernel %type %queue %flags %NDRange %num_events"
89           " %wait_events %ret_event %invoke %param %param_size 42"),
90       Eq("Expected id to start with %."));
91 }
92
93 // TODO(dneto): OpEnqueueMarker
94 // TODO(dneto): OpGetKernelNDRangeSubGroupCount
95 // TODO(dneto): OpGetKernelNDRangeMaxSubGroupSize
96 // TODO(dneto): OpGetKernelWorkGroupSize
97 // TODO(dneto): OpGetKernelPreferredWorkGroupSizeMultiple
98 // TODO(dneto): OpRetainEvent
99 // TODO(dneto): OpReleaseEvent
100 // TODO(dneto): OpCreateUserEvent
101 // TODO(dneto): OpSetUserEventStatus
102 // TODO(dneto): OpCaptureEventProfilingInfo
103 // TODO(dneto): OpGetDefaultQueue
104 // TODO(dneto): OpBuildNDRange
105 // TODO(dneto): OpBuildNDRange
106
107 }  // anonymous namespace