xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/images/clReadWriteImage/main.cpp (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 
17 #include <stdio.h>
18 #include <string.h>
19 #include "../testBase.h"
20 #include "../harness/compat.h"
21 
22 bool gDebugTrace;
23 bool gTestSmallImages;
24 bool gTestMaxImages;
25 bool gTestMipmaps;
26 cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
27 cl_channel_order gChannelOrderToUse = (cl_channel_order)-1;
28 bool            gEnablePitch = false;
29 
30 static void printUsage( const char *execName );
31 
32 extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, cl_mem_object_type image_type );
33 
test_1D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)34 int test_1D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
35 {
36     return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE1D );
37 }
test_2D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)38 int test_2D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
39 {
40     return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE2D );
41 }
test_3D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)42 int test_3D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
43 {
44     return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE3D );
45 }
test_1Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)46 int test_1Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
47 {
48     return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE1D_ARRAY );
49 }
test_2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)50 int test_2Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
51 {
52     return test_image_set( device, context, queue, CL_MEM_OBJECT_IMAGE2D_ARRAY );
53 }
54 
55 test_definition test_list[] = {
56     ADD_TEST( 1D ),
57     ADD_TEST( 2D ),
58     ADD_TEST( 3D ),
59     ADD_TEST( 1Darray ),
60     ADD_TEST( 2Darray ),
61 };
62 
63 const int test_num = ARRAY_SIZE( test_list );
64 
main(int argc,const char * argv[])65 int main(int argc, const char *argv[])
66 {
67     cl_channel_type chanType;
68 
69     const char ** argList = (const char **)calloc( argc, sizeof( char*) );
70 
71     if( NULL == argList )
72     {
73         log_error( "Failed to allocate memory for argList array.\n" );
74         return 1;
75     }
76 
77     argList[0] = argv[0];
78     size_t argCount = 1;
79 
80     // Parse arguments
81     for( int i = 1; i < argc; i++ )
82     {
83         if( strcmp( argv[i], "debug_trace" ) == 0 )
84             gDebugTrace = true;
85 
86         else if( strcmp( argv[i], "small_images" ) == 0 )
87             gTestSmallImages = true;
88         else if( strcmp( argv[i], "max_images" ) == 0 )
89             gTestMaxImages = true;
90         else if( strcmp( argv[i], "use_pitches" ) == 0 )
91             gEnablePitch = true;
92         else if( strcmp( argv[i], "test_mipmaps") == 0 ) {
93             gTestMipmaps = true;
94             // Don't test pitches with mipmaps right now.
95             gEnablePitch = false;
96         }
97 
98         else if( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 )
99         {
100             printUsage( argv[ 0 ] );
101             return -1;
102         }
103         else if( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 )
104             gChannelTypeToUse = chanType;
105         else
106         {
107             argList[argCount] = argv[i];
108             argCount++;
109         }
110     }
111 
112     if( gTestSmallImages )
113         log_info( "Note: Using small test images\n" );
114 
115     int ret = runTestHarnessWithCheck(argCount, argList, test_num, test_list,
116                                       false, 0, verifyImageSupport);
117 
118     free(argList);
119     return ret;
120 }
121 
printUsage(const char * execName)122 static void printUsage( const char *execName )
123 {
124     const char *p = strrchr( execName, '/' );
125     if( p != NULL )
126         execName = p + 1;
127 
128     log_info( "Usage: %s [options] [test_names]\n", execName );
129     log_info( "Options:\n" );
130     log_info( "\tdebug_trace - Enables additional debug info logging\n" );
131     log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
132     log_info( "\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" );
133     log_info( "\tuse_pitches - Enables row and slice pitches\n" );
134     log_info( "\ttest_mipmaps - Test mipmapped images\n" );
135     log_info( "\trandomize - Uses random seed\n" );
136     log_info( "\n" );
137     log_info( "Test names:\n" );
138     for( int i = 0; i < test_num; i++ )
139     {
140         log_info( "\t%s\n", test_list[i].name );
141     }
142 }
143