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 int  gTypesToTest;
28 cl_channel_type  gChannelTypeToUse = (cl_channel_type)-1;
29 cl_channel_order gChannelOrderToUse = (cl_channel_order)-1;
30 
31 extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, MethodsToTest testMethod );
32 static void printUsage( const char *execName );
33 
34 
test_1D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)35 int test_1D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
36 {
37     return test_image_set(device, context, queue, k1D);
38 }
test_2D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)39 int test_2D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
40 {
41     return test_image_set(device, context, queue, k2D);
42 }
test_3D(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)43 int test_3D(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
44 {
45     return test_image_set(device, context, queue, k3D);
46 }
test_1Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)47 int test_1Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
48 {
49     return test_image_set(device, context, queue, k1DArray);
50 }
test_2Darray(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)51 int test_2Darray(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements)
52 {
53     return test_image_set(device, context, queue, k2DArray);
54 }
55 
56 test_definition test_list[] = {
57     ADD_TEST( 1D ),
58     ADD_TEST( 2D ),
59     ADD_TEST( 3D ),
60     ADD_TEST( 1Darray ),
61     ADD_TEST( 2Darray ),
62 };
63 
64 const int test_num = ARRAY_SIZE( test_list );
65 
main(int argc,const char * argv[])66 int main(int argc, const char *argv[])
67 {
68     cl_channel_type  chanType;
69     cl_channel_order chanOrder;
70 
71     const char ** argList = (const char **)calloc( argc, sizeof( char*) );
72 
73     if( NULL == argList )
74     {
75         log_error( "Failed to allocate memory for argList array.\n" );
76         return 1;
77     }
78 
79     argList[0] = argv[0];
80     size_t argCount = 1;
81 
82     // Parse arguments
83     for ( int i = 1; i < argc; i++ )
84     {
85         if ( strcmp( argv[i], "debug_trace" ) == 0 )
86             gDebugTrace = true;
87 
88         else if ( strcmp( argv[i], "small_images" ) == 0 )
89             gTestSmallImages = true;
90         else if ( strcmp( argv[i], "max_images" ) == 0 )
91             gTestMaxImages = true;
92 
93         else if ( strcmp( argv[i], "use_pitches" ) == 0 )
94             gEnablePitch = true;
95 
96         else if( strcmp( argv[i], "int" ) == 0 )
97             gTypesToTest |= kTestInt;
98         else if( strcmp( argv[i], "uint" ) == 0 )
99             gTypesToTest |= kTestUInt;
100         else if( strcmp( argv[i], "float" ) == 0 )
101             gTypesToTest |= kTestFloat;
102 
103         else if ( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 )
104         {
105             printUsage( argv[ 0 ] );
106             return -1;
107         }
108 
109         else if ( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 )
110             gChannelTypeToUse = chanType;
111 
112         else if ( ( chanOrder = get_channel_order_from_name( argv[i] ) ) != (cl_channel_order)-1 )
113             gChannelOrderToUse = chanOrder;
114         else
115         {
116             argList[argCount] = argv[i];
117             argCount++;
118         }
119     }
120 
121     if ( gTypesToTest == 0 )
122         gTypesToTest = kTestAllTypes;
123 
124     if ( gTestSmallImages )
125         log_info( "Note: Using small test images\n" );
126 
127     int ret = runTestHarnessWithCheck(argCount, argList, test_num, test_list,
128                                       false, 0, verifyImageSupport);
129 
130     free(argList);
131     return ret;
132 }
133 
printUsage(const char * execName)134 static void printUsage( const char *execName )
135 {
136     const char *p = strrchr( execName, '/' );
137     if ( p != NULL )
138         execName = p + 1;
139 
140     log_info( "Usage: %s [options] [test_names]\n", execName );
141     log_info( "Options:\n" );
142     log_info( "\tThe following flags specify the types to test. They can be combined; if none are specified, all are tested:\n" );
143     log_info( "\t\tint - Test integer fill\n" );
144     log_info( "\t\tuint - Test unsigned integer fill\n" );
145     log_info( "\t\tfloat - Test float fill\n" );
146     log_info( "\n" );
147     log_info( "\trandomize - Uses random seed\n" );
148     log_info( "\tdebug_trace - Enables additional debug info logging\n" );
149     log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
150     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" );
151     log_info( "\tuse_pitches - Enables row and slice pitches\n" );
152     log_info( "\n" );
153     log_info( "Test names:\n" );
154     for( int i = 0; i < test_num; i++ )
155     {
156         log_info( "\t%s\n", test_list[i].name );
157     }
158     log_info( "\n" );
159     log_info( "You may also use appropriate CL_ channel type and ordering constants.\n" );
160 }
161