1 //
2 // Copyright (c) 2023 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
19 namespace {
20
21 // Test that finalizing a command-buffer that has already been finalized returns
22 // the correct error code.
23 struct FinalizeInvalid : public BasicCommandBufferTest
24 {
25 using BasicCommandBufferTest::BasicCommandBufferTest;
26
Run__anonfd65ac570111::FinalizeInvalid27 cl_int Run() override
28 {
29 cl_int error = clCommandNDRangeKernelKHR(
30 command_buffer, nullptr, nullptr, kernel, 1, nullptr, &num_elements,
31 nullptr, 0, nullptr, nullptr, nullptr);
32 test_error(error, "clCommandNDRangeKernelKHR failed");
33
34 error = clFinalizeCommandBufferKHR(command_buffer);
35 test_error(error, "clFinalizeCommandBufferKHR failed");
36
37 // Finalizing an already finalized command-buffer must return
38 // CL_INVALID_OPERATION
39 error = clFinalizeCommandBufferKHR(command_buffer);
40 test_failure_error_ret(
41 error, CL_INVALID_OPERATION,
42 "clFinalizeCommandBufferKHR should return CL_INVALID_OPERATION",
43 TEST_FAIL);
44
45 return CL_SUCCESS;
46 }
47 };
48
49 // Check that an empty command-buffer can be finalized and then executed.
50 struct FinalizeEmpty : public BasicCommandBufferTest
51 {
52 using BasicCommandBufferTest::BasicCommandBufferTest;
53
Run__anonfd65ac570111::FinalizeEmpty54 cl_int Run() override
55 {
56 // Finalize an empty command-buffer
57 cl_int error = clFinalizeCommandBufferKHR(command_buffer);
58 test_error(error, "clFinalizeCommandBufferKHR failed");
59
60 // Execute empty command-buffer and then wait to complete
61 clEventWrapper event;
62 error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
63 nullptr, &event);
64 test_error(error, "clEnqueueCommandBufferKHR failed");
65
66 error = clWaitForEvents(1, &event);
67 test_error(error, "clWaitForEvents failed");
68
69 return CL_SUCCESS;
70 }
71 };
72 } // anonymous namespace
73
test_finalize_invalid(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)74 int test_finalize_invalid(cl_device_id device, cl_context context,
75 cl_command_queue queue, int num_elements)
76 {
77 return MakeAndRunTest<FinalizeInvalid>(device, context, queue,
78 num_elements);
79 }
80
test_finalize_empty(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)81 int test_finalize_empty(cl_device_id device, cl_context context,
82 cl_command_queue queue, int num_elements)
83 {
84 return MakeAndRunTest<FinalizeEmpty>(device, context, queue, num_elements);
85 }
86