xref: /aosp_15_r20/external/OpenCL-CTS/test_common/harness/ref_counting.h (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1 //
2 // Copyright (c) 2017 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 #ifndef _ref_counting_h
17 #define _ref_counting_h
18 
19 #define MARK_REF_COUNT_BASE(c, type, bigType)                                  \
20     cl_uint c##_refCount;                                                      \
21     error = clGet##type##Info(c, CL_##bigType##_REFERENCE_COUNT,               \
22                               sizeof(c##_refCount), &c##_refCount, NULL);      \
23     test_error(error, "Unable to check reference count for " #type);
24 
25 #define TEST_REF_COUNT_BASE(c, type, bigType)                                  \
26     cl_uint c##_refCount_new;                                                  \
27     error =                                                                    \
28         clGet##type##Info(c, CL_##bigType##_REFERENCE_COUNT,                   \
29                           sizeof(c##_refCount_new), &c##_refCount_new, NULL);  \
30     test_error(error, "Unable to check reference count for " #type);           \
31     if (c##_refCount != c##_refCount_new)                                      \
32     {                                                                          \
33         log_error("ERROR: Reference count for " #type                          \
34                   " changed! (was %d, now %d)\n",                              \
35                   c##_refCount, c##_refCount_new);                             \
36         return -1;                                                             \
37     }
38 
39 #define MARK_REF_COUNT_CONTEXT(c) MARK_REF_COUNT_BASE(c, Context, CONTEXT)
40 #define TEST_REF_COUNT_CONTEXT(c) TEST_REF_COUNT_BASE(c, Context, CONTEXT)
41 
42 #define MARK_REF_COUNT_DEVICE(c) MARK_REF_COUNT_BASE(c, Device, DEVICE)
43 #define TEST_REF_COUNT_DEVICE(c) TEST_REF_COUNT_BASE(c, Device, DEVICE)
44 
45 #define MARK_REF_COUNT_QUEUE(c) MARK_REF_COUNT_BASE(c, CommandQueue, QUEUE)
46 #define TEST_REF_COUNT_QUEUE(c) TEST_REF_COUNT_BASE(c, CommandQueue, QUEUE)
47 
48 #define MARK_REF_COUNT_PROGRAM(c) MARK_REF_COUNT_BASE(c, Program, PROGRAM)
49 #define TEST_REF_COUNT_PROGRAM(c) TEST_REF_COUNT_BASE(c, Program, PROGRAM)
50 
51 #define MARK_REF_COUNT_MEM(c) MARK_REF_COUNT_BASE(c, MemObject, MEM)
52 #define TEST_REF_COUNT_MEM(c) TEST_REF_COUNT_BASE(c, MemObject, MEM)
53 
54 #endif // _ref_counting_h
55