• 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 
17 #include <stdio.h>
18 #include <string.h>
19 #include "../testBase.h"
20 #include "../harness/compat.h"
21 #include "../harness/parseParameters.h"
22 
23 bool gDebugTrace;
24 bool gTestSmallImages;
25 bool gTestMaxImages;
26 
27 cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
28 cl_channel_order gChannelOrderToUse = (cl_channel_order)-1;
29 
30 extern int test_image_set( cl_device_id device, cl_context context, cl_command_queue queue, cl_mem_object_type imageType );
31 
32 static void printUsage( const char *execName );
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     argc = parseCustomParam(argc, argv);
70     if (argc == -1)
71     {
72         return -1;
73     }
74 
75     const char ** argList = (const char **)calloc( argc, sizeof( char*) );
76 
77     if( NULL == argList )
78     {
79         log_error( "Failed to allocate memory for argList array.\n" );
80         return 1;
81     }
82 
83     argList[0] = argv[0];
84     size_t argCount = 1;
85 
86     // Parse arguments
87     for( int i = 1; i < argc; i++ )
88     {
89         if( strcmp( argv[i], "debug_trace" ) == 0 )
90             gDebugTrace = true;
91 
92         else if( strcmp( argv[i], "small_images" ) == 0 )
93             gTestSmallImages = true;
94         else if( strcmp( argv[i], "max_images" ) == 0 )
95             gTestMaxImages = true;
96 
97         else if( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 )
98         {
99             printUsage( argv[ 0 ] );
100             return -1;
101         }
102         else if( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 )
103             gChannelTypeToUse = chanType;
104         else
105         {
106             argList[argCount] = argv[i];
107             argCount++;
108         }
109     }
110 
111     if( gTestSmallImages )
112         log_info( "Note: Using small test images\n" );
113 
114     int ret = runTestHarnessWithCheck(argCount, argList, test_num, test_list,
115                                       false, 0, verifyImageSupport);
116 
117     free(argList);
118     return ret;
119 }
120 
printUsage(const char * execName)121 static void printUsage( const char *execName )
122 {
123     const char *p = strrchr( execName, '/' );
124     if( p != NULL )
125         execName = p + 1;
126 
127     log_info( "Usage: %s [options] [test_names]\n", execName );
128     log_info( "Options:\n" );
129     log_info( "\tdebug_trace - Enables additional debug info logging\n" );
130     log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
131     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" );
132     log_info( "\trandomize - Uses random seed\n" );
133     log_info( "\n" );
134     log_info( "Test names:\n" );
135     for( int i = 0; i < test_num; i++ )
136     {
137         log_info( "\t%s\n", test_list[i].name );
138     }
139 }
140