1 //
2 // Copyright (c) 2020 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 
17 
18 #include "testBase.h"
19 #include "harness/typeWrappers.h"
20 
test_queue_flush_on_release(cl_device_id deviceID,cl_context context,cl_command_queue defaultQueue,int num_elements)21 int test_queue_flush_on_release(cl_device_id deviceID, cl_context context,
22                                 cl_command_queue defaultQueue, int num_elements)
23 {
24     cl_int err;
25 
26     // Create a command queue
27     cl_command_queue queue = clCreateCommandQueue(context, deviceID, 0, &err);
28     test_error(err, "Could not create command queue");
29 
30     // Create a kernel
31     clProgramWrapper program;
32     clKernelWrapper kernel;
33     const char *source = "void kernel test(){}";
34     err = create_single_kernel_helper(context, &program, &kernel, 1, &source,
35                                       "test");
36     test_error(err, "Could not create kernel");
37 
38     // Enqueue the kernel
39     size_t gws = 1;
40     clEventWrapper event;
41     err = clEnqueueNDRangeKernel(queue, kernel, 1, nullptr, &gws, nullptr, 0,
42                                  nullptr, &event);
43     test_error(err, "Could not enqueue kernel");
44 
45     // Release the queue
46     err = clReleaseCommandQueue(queue);
47 
48     // Wait for kernel to execute since the queue must flush on release
49     bool success = poll_until(2000, 50, [&event]() {
50         cl_int status;
51         cl_int err = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS,
52                                     sizeof(cl_int), &status, nullptr);
53         if ((err != CL_SUCCESS) || (status != CL_COMPLETE))
54         {
55             return false;
56         }
57         return true;
58     });
59 
60     return success ? TEST_PASS : TEST_FAIL;
61 }
62