Use _exit() instead of exit() in child processes
[piglit.git] / tests / cl / api / retain_release-mem-object.c
blob286d46ed5e4320889fa711e46a908e8802c6d7e0
1 /*
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
13 * Software.
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.
24 /**
25 * @file retain_release-mem-object.c
27 * Test API functions:
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
47 enum piglit_result
48 piglit_cl_test(const int argc,
49 const char** argv,
50 const struct piglit_cl_api_test_config* config,
51 const struct piglit_cl_api_test_env* env)
53 int ref_count = 0;
54 const int max_ref_count = 10;
55 cl_int errNo;
56 cl_uint* ref_count_ptr;
58 /*** Normal usage ***/
60 cl_mem memobj = clCreateBuffer(env->context->cl_ctx,
61 CL_MEM_READ_WRITE,
62 512,
63 NULL,
64 &errNo);
65 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
66 fprintf(stderr,
67 "Failed (error code: %s): Create buffer.\n",
68 piglit_cl_get_error_name(errNo));
69 return PIGLIT_FAIL;
72 ref_count_ptr =
73 piglit_cl_get_mem_object_info(memobj, CL_MEM_REFERENCE_COUNT);
74 if(*ref_count_ptr != 1) {
75 free(ref_count_ptr);
76 fprintf(stderr,
77 "CL_MEM_REFERENCE_COUNT should be 1 after creating memory object.\n");
78 return PIGLIT_FAIL;
80 free(ref_count_ptr);
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)) {
86 fprintf(stderr,
87 "clRetainMemObject: Failed (error code: %s): Retain memory object.\n",
88 piglit_cl_get_error_name(errNo));
89 return PIGLIT_FAIL;
91 errNo = clReleaseMemObject(memobj);
92 if(!piglit_cl_check_error(errNo, CL_SUCCESS)){
93 fprintf(stderr,
94 "clReleaseMemObject: Failed (error code: %s): Release memory object.\n",
95 piglit_cl_get_error_name(errNo));
96 return PIGLIT_FAIL;
98 errNo = clRetainMemObject(memobj);
99 if(!piglit_cl_check_error(errNo, CL_SUCCESS)){
100 fprintf(stderr,
101 "clRetainMemObject: Failed (error code: %s): Retain memory object.\n",
102 piglit_cl_get_error_name(errNo));
103 return PIGLIT_FAIL;
106 /* check internal value of reference count */
107 ref_count_ptr =
108 piglit_cl_get_mem_object_info(memobj, CL_MEM_REFERENCE_COUNT);
109 if(*ref_count_ptr != (ref_count+1)) {
110 free(ref_count_ptr);
111 fprintf(stderr,
112 "CL_MEM_REFERENCE_COUNT is not changing accordingly.\n");
113 return PIGLIT_FAIL;
115 free(ref_count_ptr);
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)){
121 fprintf(stderr,
122 "clReleaseMemObject: Failed (error code: %s): Release memory object.\n",
123 piglit_cl_get_error_name(errNo));
124 return PIGLIT_FAIL;
127 /* check internal value of reference count */
128 if(ref_count > 1) {
129 ref_count_ptr =
130 piglit_cl_get_mem_object_info(memobj, CL_MEM_REFERENCE_COUNT);
131 if(*ref_count_ptr != (ref_count-1)) {
132 free(ref_count_ptr);
133 fprintf(stderr,
134 "CL_MEM_REFERENCE_COUNT is not changing accordingly.\n");
135 return PIGLIT_FAIL;
137 free(ref_count_ptr);
141 return PIGLIT_PASS;