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