Use _exit() instead of exit() in child processes
[piglit.git] / tests / cl / api / get-platform-ids.c
blobd160bd6eb8e37f6636923d01dc3c7e78a0cc77b8
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 get-platform-ids.c
27 * Test API function:
29 * cl_int clGetPlatformIDs(cl_uint num_entries,
30 * cl_platform_id *platforms,
31 * cl_uint *num_platforms)
34 #include "piglit-framework-cl-api.h"
37 PIGLIT_CL_API_TEST_CONFIG_BEGIN
39 config.name = "clGetPlatformIDs";
40 config.version_min = 10;
42 PIGLIT_CL_API_TEST_CONFIG_END
45 enum piglit_result
46 piglit_cl_test(const int argc,
47 const char** argv,
48 const struct piglit_cl_api_test_config* config,
49 const struct piglit_cl_api_test_env* env)
51 enum piglit_result result = PIGLIT_PASS;
53 int i;
54 cl_int errNo;
55 cl_uint num_platforms;
56 cl_platform_id* platforms = NULL;
58 /*** Normal usage ***/
60 /* get number of platforms */
61 errNo = clGetPlatformIDs(0, NULL, &num_platforms);
62 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
63 fprintf(stderr,
64 "Failed (error code: %s): Get size of platform list.\n",
65 piglit_cl_get_error_name(errNo));
66 piglit_merge_result(&result, PIGLIT_FAIL);
67 } else {
69 * Get platform list.
70 * Try returning from 1 to num_platforms platforms.
72 for(i = 1; i <= num_platforms; i++) {
73 platforms = malloc(i * sizeof(cl_platform_id));
74 errNo = clGetPlatformIDs(i, platforms, NULL);
75 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
76 fprintf(stderr,
77 "Failed (error code: %s): Get platform list.\n",
78 piglit_cl_get_error_name(errNo));
79 piglit_merge_result(&result, PIGLIT_FAIL);
81 free(platforms);
85 /*** Errors ***/
88 * CL_INVALID_VALUE if num_entries is equal
89 * to zero and platforms is not NULL, or if both num_platforms
90 * and platforms are NULL.
92 errNo = clGetPlatformIDs(0, platforms, NULL);
93 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
94 fprintf(stderr,
95 "Failed (error code: %s): Trigger CL_INVALID_VALUE if num_entries is equeal to zero and platforms is not NULL.\n",
96 piglit_cl_get_error_name(errNo));
97 piglit_merge_result(&result, PIGLIT_FAIL);
99 errNo = clGetPlatformIDs(100, NULL, NULL);
100 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
101 fprintf(stderr,
102 "Failed (error code: %s): Trigger CL_INVALID_VALUE if both num_platforms and platforms are NULL.\n",
103 piglit_cl_get_error_name(errNo));
104 piglit_merge_result(&result, PIGLIT_FAIL);
107 return result;