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