2 * Copyright © 2012 Blaž Tomažič <blaz.tomazic@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 * @file retain_release-mem-object.c
29 * cl_int clRetainMemObject (cl_mem memobj)
30 * cl_int clReleaseMemObject (cl_mem memobj)
33 #include "piglit-framework-cl-api.h"
36 PIGLIT_CL_API_TEST_CONFIG_BEGIN
38 config
.name
= "clRetainMemObject and clReleaseMemObject";
39 config
.version_min
= 10;
41 config
.run_per_device
= true;
42 config
.create_context
= true;
44 PIGLIT_CL_API_TEST_CONFIG_END
48 piglit_cl_test(const int argc
,
50 const struct piglit_cl_api_test_config
* config
,
51 const struct piglit_cl_api_test_env
* env
)
54 const int max_ref_count
= 10;
56 cl_uint
* ref_count_ptr
;
58 /*** Normal usage ***/
60 cl_mem memobj
= clCreateBuffer(env
->context
->cl_ctx
,
65 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)) {
67 "Failed (error code: %s): Create buffer.\n",
68 piglit_cl_get_error_name(errNo
));
73 piglit_cl_get_mem_object_info(memobj
, CL_MEM_REFERENCE_COUNT
);
74 if(*ref_count_ptr
!= 1) {
77 "CL_MEM_REFERENCE_COUNT should be 1 after creating memory object.\n");
82 /* increase by two and decrease by one on each iteration */
83 for(ref_count
= 1; ref_count
< max_ref_count
; ref_count
++) {
84 errNo
= clRetainMemObject(memobj
);
85 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)) {
87 "clRetainMemObject: Failed (error code: %s): Retain memory object.\n",
88 piglit_cl_get_error_name(errNo
));
91 errNo
= clReleaseMemObject(memobj
);
92 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)){
94 "clReleaseMemObject: Failed (error code: %s): Release memory object.\n",
95 piglit_cl_get_error_name(errNo
));
98 errNo
= clRetainMemObject(memobj
);
99 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)){
101 "clRetainMemObject: Failed (error code: %s): Retain memory object.\n",
102 piglit_cl_get_error_name(errNo
));
106 /* check internal value of reference count */
108 piglit_cl_get_mem_object_info(memobj
, CL_MEM_REFERENCE_COUNT
);
109 if(*ref_count_ptr
!= (ref_count
+1)) {
112 "CL_MEM_REFERENCE_COUNT is not changing accordingly.\n");
117 /* Decrease reference count to 0 */
118 for(ref_count
= max_ref_count
; ref_count
> 0; ref_count
--) {
119 errNo
= clReleaseMemObject(memobj
);
120 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)){
122 "clReleaseMemObject: Failed (error code: %s): Release memory object.\n",
123 piglit_cl_get_error_name(errNo
));
127 /* check internal value of reference count */
130 piglit_cl_get_mem_object_info(memobj
, CL_MEM_REFERENCE_COUNT
);
131 if(*ref_count_ptr
!= (ref_count
-1)) {
134 "CL_MEM_REFERENCE_COUNT is not changing accordingly.\n");