• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2022 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 #include "basic_command_buffer.h"
17 #include "procs.h"
18 #include <vector>
19 
20 namespace {
21 
22 ////////////////////////////////////////////////////////////////////////////////
23 // get event info tests which handles below cases:
24 //
25 // -command type
26 // -command queue
27 // -context
28 // -execution status
29 // -reference count
30 
31 struct CommandType : public BasicCommandBufferTest
32 {
33     using BasicCommandBufferTest::BasicCommandBufferTest;
34 
Run__anon9712a6910111::CommandType35     cl_int Run() override
36     {
37         clEventWrapper event;
38         cl_int status;
39 
40         cl_int error = clFinalizeCommandBufferKHR(command_buffer);
41         test_error(error, "clFinalizeCommandBufferKHR failed");
42 
43         error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
44                                           nullptr, &event);
45         test_error(error, "clEnqueueCommandBufferKHR failed");
46 
47         error = clWaitForEvents(1, &event);
48         test_error(error, "Unable to wait for event");
49 
50         error = clGetEventInfo(event, CL_EVENT_COMMAND_TYPE, sizeof(status),
51                                &status, NULL);
52         test_error(error, "clGetEventInfo failed");
53 
54         if (status != CL_COMMAND_COMMAND_BUFFER_KHR)
55         {
56             log_error(
57                 "ERROR: Incorrect status returned from clGetEventInfo (%d)\n",
58                 status);
59 
60             return TEST_FAIL;
61         }
62 
63         return CL_SUCCESS;
64     }
65 };
66 
67 struct CommandQueue : public BasicCommandBufferTest
68 {
69     using BasicCommandBufferTest::BasicCommandBufferTest;
70 
Run__anon9712a6910111::CommandQueue71     cl_int Run() override
72     {
73         clEventWrapper event;
74         size_t size;
75 
76         cl_int error = clFinalizeCommandBufferKHR(command_buffer);
77         test_error(error, "clFinalizeCommandBufferKHR failed");
78 
79         error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
80                                           nullptr, &event);
81         test_error(error, "clEnqueueCommandBufferKHR failed");
82 
83         cl_command_queue otherQueue;
84         error = clGetEventInfo(event, CL_EVENT_COMMAND_QUEUE,
85                                sizeof(otherQueue), &otherQueue, &size);
86         test_error(error, "Unable to get event info!");
87 
88         // We can not check if this is the right queue because this is an opaque
89         // object.
90         if (size != sizeof(queue) || otherQueue == NULL)
91         {
92             log_error("ERROR: Returned command queue size does not validate "
93                       "(expected %zu, got %zu)\n",
94                       sizeof(queue), size);
95             return TEST_FAIL;
96         }
97 
98         return CL_SUCCESS;
99     }
100 };
101 
102 struct Context : public BasicCommandBufferTest
103 {
104     using BasicCommandBufferTest::BasicCommandBufferTest;
105 
Run__anon9712a6910111::Context106     cl_int Run() override
107     {
108         clEventWrapper event;
109         size_t size;
110 
111         cl_int error = clFinalizeCommandBufferKHR(command_buffer);
112         test_error(error, "clFinalizeCommandBufferKHR failed");
113 
114         error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
115                                           nullptr, &event);
116         test_error(error, "clEnqueueCommandBufferKHR failed");
117 
118         cl_context testCtx;
119         error = clGetEventInfo(event, CL_EVENT_CONTEXT, sizeof(testCtx),
120                                &testCtx, &size);
121         test_error(error, "Unable to get event context info!");
122         if (size != sizeof(context))
123         {
124             log_error(
125                 "ERROR: Returned context size does not validate (expected "
126                 "%zu, got %zu)\n",
127                 sizeof(context), size);
128             return TEST_FAIL;
129         }
130         if (testCtx != context)
131         {
132             log_error("ERROR: Returned context does not match (expected %p, "
133                       "got %p)\n",
134                       (void *)context, (void *)testCtx);
135             return TEST_FAIL;
136         }
137 
138         return CL_SUCCESS;
139     }
140 };
141 
142 struct ExecutionStatus : public BasicCommandBufferTest
143 {
144     using BasicCommandBufferTest::BasicCommandBufferTest;
145 
Run__anon9712a6910111::ExecutionStatus146     cl_int Run() override
147     {
148         clEventWrapper event;
149         cl_int status;
150 
151         cl_int error = clFinalizeCommandBufferKHR(command_buffer);
152         test_error(error, "clFinalizeCommandBufferKHR failed");
153 
154         error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
155                                           nullptr, &event);
156         test_error(error, "clEnqueueCommandBufferKHR failed");
157 
158         error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS,
159                                sizeof(status), &status, NULL);
160         test_error(error, "clGetEventInfo failed");
161 
162         if (!(status == CL_QUEUED || status == CL_SUBMITTED
163               || status == CL_RUNNING || status == CL_COMPLETE))
164         {
165             log_error(
166                 "ERROR: Incorrect status returned from clGetEventInfo (%d)\n",
167                 status);
168             return TEST_FAIL;
169         }
170 
171         error = clWaitForEvents(1, &event);
172         test_error(error, "clWaitForEvents failed");
173 
174         error = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS,
175                                sizeof(status), &status, NULL);
176         test_error(error, "clGetEventInfo failed");
177 
178         if (status != CL_COMPLETE)
179         {
180             log_error(
181                 "ERROR: Incorrect status returned from clGetEventInfo (%d)\n",
182                 status);
183             return TEST_FAIL;
184         }
185 
186         return CL_SUCCESS;
187     }
188 };
189 
190 struct ReferenceCount : public BasicCommandBufferTest
191 {
192     using BasicCommandBufferTest::BasicCommandBufferTest;
193 
Run__anon9712a6910111::ReferenceCount194     cl_int Run() override
195     {
196         clEventWrapper event;
197         size_t size;
198         cl_uint count;
199 
200         cl_int error = clFinalizeCommandBufferKHR(command_buffer);
201         test_error(error, "clFinalizeCommandBufferKHR failed");
202 
203         error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
204                                           nullptr, &event);
205         test_error(error, "clEnqueueCommandBufferKHR failed");
206 
207         error = clGetEventInfo(event, CL_EVENT_REFERENCE_COUNT, sizeof(count),
208                                &count, &size);
209         test_error(error, "clGetEventInfo failed");
210 
211         if (size != sizeof(count) || count == 0)
212         {
213             log_error(
214                 "ERROR: Wrong command reference count (expected return value 1 "
215                 "of size %zu, returned size %zu, returned value %u)\n",
216                 sizeof(count), size, count);
217             return TEST_FAIL;
218         }
219 
220         return CL_SUCCESS;
221     }
222 };
223 };
224 
test_event_info_command_type(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)225 int test_event_info_command_type(cl_device_id device, cl_context context,
226                                  cl_command_queue queue, int num_elements)
227 {
228     return MakeAndRunTest<CommandType>(device, context, queue, num_elements);
229 }
230 
test_event_info_command_queue(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)231 int test_event_info_command_queue(cl_device_id device, cl_context context,
232                                   cl_command_queue queue, int num_elements)
233 {
234     return MakeAndRunTest<CommandQueue>(device, context, queue, num_elements);
235 }
236 
test_event_info_context(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)237 int test_event_info_context(cl_device_id device, cl_context context,
238                             cl_command_queue queue, int num_elements)
239 {
240     return MakeAndRunTest<Context>(device, context, queue, num_elements);
241 }
242 
test_event_info_execution_status(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)243 int test_event_info_execution_status(cl_device_id device, cl_context context,
244                                      cl_command_queue queue, int num_elements)
245 {
246     return MakeAndRunTest<ExecutionStatus>(device, context, queue,
247                                            num_elements);
248 }
249 
test_event_info_reference_count(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)250 int test_event_info_reference_count(cl_device_id device, cl_context context,
251                                     cl_command_queue queue, int num_elements)
252 {
253     return MakeAndRunTest<ReferenceCount>(device, context, queue, num_elements);
254 }