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 #include "../harness/testHarness.h"
22
23 bool gDebugTrace;
24 bool gTestSmallImages;
25 bool gTestMaxImages;
26 bool gEnablePitch;
27 bool gTestMipmaps;
28 int gTypesToTest;
29 cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
30 cl_channel_order gChannelOrderToUse = (cl_channel_order)-1;
31
32 extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod );
33
34 static void printUsage( const char *execName );
35
test_1D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)36 int test_1D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
37 {
38 return test_image_set( device, context, queue, k1D );
39 }
test_2D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)40 int test_2D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
41 {
42 return test_image_set( device, context, queue, k2D );
43 }
test_3D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)44 int test_3D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
45 {
46 return test_image_set( device, context, queue, k3D );
47 }
test_1Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)48 int test_1Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
49 {
50 return test_image_set( device, context, queue, k1DArray );
51 }
test_2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)52 int test_2Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
53 {
54 return test_image_set( device, context, queue, k2DArray );
55 }
test_2Dto3D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)56 int test_2Dto3D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
57 {
58 return test_image_set( device, context, queue, k2DTo3D );
59 }
test_3Dto2D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)60 int test_3Dto2D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
61 {
62 return test_image_set( device, context, queue, k3DTo2D );
63 }
test_2Darrayto2D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)64 int test_2Darrayto2D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
65 {
66 return test_image_set( device, context, queue, k2DArrayTo2D );
67 }
test_2Dto2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)68 int test_2Dto2Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
69 {
70 return test_image_set( device, context, queue, k2DTo2DArray );
71 }
test_2Darrayto3D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)72 int test_2Darrayto3D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
73 {
74 return test_image_set( device, context, queue, k2DArrayTo3D );
75 }
test_3Dto2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)76 int test_3Dto2Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
77 {
78 return test_image_set( device, context, queue, k3DTo2DArray );
79 }
80
81 test_definition test_list[] = {
82 ADD_TEST( 1D ),
83 ADD_TEST( 2D ),
84 ADD_TEST( 3D ),
85 ADD_TEST( 1Darray ),
86 ADD_TEST( 2Darray ),
87 ADD_TEST( 2Dto3D ),
88 ADD_TEST( 3Dto2D ),
89 ADD_TEST( 2Darrayto2D ),
90 ADD_TEST( 2Dto2Darray ),
91 ADD_TEST( 2Darrayto3D ),
92 ADD_TEST( 3Dto2Darray ),
93 };
94
95 const int test_num = ARRAY_SIZE( test_list );
96
main(int argc,const char * argv[])97 int main(int argc, const char *argv[])
98 {
99 cl_channel_type chanType;
100 cl_channel_order chanOrder;
101
102 const char ** argList = (const char **)calloc( argc, sizeof( char*) );
103
104 if( NULL == argList )
105 {
106 log_error( "Failed to allocate memory for argList array.\n" );
107 return 1;
108 }
109
110 argList[0] = argv[0];
111 size_t argCount = 1;
112
113 // Parse arguments
114 for( int i = 1; i < argc; i++ )
115 {
116 if( strcmp( argv[i], "test_mipmaps" ) == 0 )
117 {
118 gTestMipmaps = true;
119 // Don't test pitches with mipmaps, at least currently.
120 gEnablePitch = false;
121 }
122 else if( strcmp( argv[i], "debug_trace" ) == 0 )
123 gDebugTrace = true;
124
125 else if( strcmp( argv[i], "small_images" ) == 0 )
126 gTestSmallImages = true;
127 else if( strcmp( argv[i], "max_images" ) == 0 )
128 gTestMaxImages = true;
129
130 else if( strcmp( argv[i], "use_pitches" ) == 0 )
131 gEnablePitch = true;
132
133 else if( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 )
134 {
135 printUsage( argv[ 0 ] );
136 return -1;
137 }
138
139 else if( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 )
140 gChannelTypeToUse = chanType;
141
142 else if( ( chanOrder = get_channel_order_from_name( argv[i] ) ) != (cl_channel_order)-1 )
143 gChannelOrderToUse = chanOrder;
144 else
145 {
146 argList[argCount] = argv[i];
147 argCount++;
148 }
149 }
150
151 if( gTestSmallImages )
152 log_info( "Note: Using small test images\n" );
153
154 int ret = runTestHarnessWithCheck(argCount, argList, test_num, test_list,
155 false, 0, verifyImageSupport);
156
157 free(argList);
158 return ret;
159 }
160
printUsage(const char * execName)161 static void printUsage( const char *execName )
162 {
163 const char *p = strrchr( execName, '/' );
164 if( p != NULL )
165 execName = p + 1;
166
167 log_info( "Usage: %s [option] [test_names]\n", execName );
168 log_info( "Options:\n" );
169 log_info( "\ttest_mipmaps - Test with mipmapped images\n" );
170 log_info( "\tdebug_trace - Enables additional debug info logging\n" );
171 log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
172 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" );
173 log_info( "\trandomize - Use random seed\n" );
174 log_info( "\tuse_pitches - Enables row and slice pitches\n" );
175 log_info( "\n" );
176 log_info( "Test names:\n" );
177 for( int i = 0; i < test_num; i++ )
178 {
179 log_info( "\t%s\n", test_list[i].name );
180 }
181 }
182