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 <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #if !defined (_WIN32)
21 #include <sys/resource.h>
22 #if defined(__APPLE__)
23 #include <sys/sysctl.h>
24 #endif
25 #include <libgen.h>
26 #include <sys/param.h>
27 #endif
28
29 #include "harness/testHarness.h"
30 #include "harness/mingw_compat.h"
31 #include "harness/parseParameters.h"
32 #if defined (__MINGW32__)
33 #include <sys/param.h>
34 #endif
35
36 #include "cl_utils.h"
37 #include "tests.h"
38
39 const char ** argList = NULL;
40 size_t argCount = 0;
41 char appName[64] = "ctest";
42 const char *addressSpaceNames[AS_NumAddressSpaces] = {"global", "private", "local", "constant"};
43
44 #pragma mark -
45 #pragma mark Declarations
46
47
48 static int ParseArgs( int argc, const char **argv );
49 static void PrintUsage( void );
50
51
52 int g_arrVecSizes[kVectorSizeCount+kStrangeVectorSizeCount];
53 int g_arrVecAligns[kLargestVectorSize+1];
54 static int arrStrangeVecSizes[kStrangeVectorSizeCount] = {3};
55
56 test_definition test_list[] = {
57 ADD_TEST( vload_half ),
58 ADD_TEST( vloada_half ),
59 ADD_TEST( vstore_half ),
60 ADD_TEST( vstorea_half ),
61 ADD_TEST( vstore_half_rte ),
62 ADD_TEST( vstorea_half_rte ),
63 ADD_TEST( vstore_half_rtz ),
64 ADD_TEST( vstorea_half_rtz ),
65 ADD_TEST( vstore_half_rtp ),
66 ADD_TEST( vstorea_half_rtp ),
67 ADD_TEST( vstore_half_rtn ),
68 ADD_TEST( vstorea_half_rtn ),
69 ADD_TEST( roundTrip ),
70 };
71
72 const int test_num = ARRAY_SIZE( test_list );
73
main(int argc,const char ** argv)74 int main (int argc, const char **argv )
75 {
76 int error;
77 int i;
78 int alignbound;
79
80 for(i = 0; i < kVectorSizeCount; ++i) {
81 g_arrVecSizes[i] = (1<<i);
82 }
83 for(i = 0; i < kStrangeVectorSizeCount; ++i) {
84 g_arrVecSizes[i+kVectorSizeCount] =
85 arrStrangeVecSizes[i];
86 }
87
88 for(i = 0, alignbound=1; i <= kLargestVectorSize; ++i) {
89 while(alignbound < i) {
90 alignbound = alignbound<<1;
91 }
92 g_arrVecAligns[i] = alignbound;
93 }
94
95 argc = parseCustomParam(argc, argv);
96 if (argc == -1)
97 {
98 return -1;
99 }
100
101 if( (error = ParseArgs( argc, argv )) )
102 goto exit;
103
104 if (gIsEmbedded) {
105 vlog( "\tProfile: Embedded\n" );
106 }else
107 {
108 vlog( "\tProfile: Full\n" );
109 }
110
111 fflush( stdout );
112 error = runTestHarnessWithCheck( argCount, argList, test_num, test_list, true, 0, InitCL );
113
114 exit:
115 if(gQueue)
116 {
117 int flush_error = clFinish(gQueue);
118 if(flush_error)
119 {
120 vlog_error("clFinish failed: %d\n", flush_error);
121 }
122 }
123
124 ReleaseCL();
125 return error;
126 }
127
128 #pragma mark -
129 #pragma mark setup
130
ParseArgs(int argc,const char ** argv)131 static int ParseArgs( int argc, const char **argv )
132 {
133 int i;
134 argList = (const char **)calloc( argc - 1, sizeof( char*) );
135
136 if( NULL == argList )
137 {
138 vlog_error( "Failed to allocate memory for argList.\n" );
139 return 1;
140 }
141
142 argList[0] = argv[0];
143 argCount = 1;
144
145 #if (defined( __APPLE__ ) || defined(__linux__) || defined(__MINGW32__))
146 { // Extract the app name
147 char baseName[ MAXPATHLEN ];
148 strncpy( baseName, argv[0], MAXPATHLEN );
149 char *base = basename( baseName );
150 if( NULL != base )
151 {
152 strncpy( appName, base, sizeof( appName ) );
153 appName[ sizeof( appName ) -1 ] = '\0';
154 }
155 }
156 #elif defined (_WIN32)
157 {
158 char fname[_MAX_FNAME + _MAX_EXT + 1];
159 char ext[_MAX_EXT];
160
161 errno_t err = _splitpath_s( argv[0], NULL, 0, NULL, 0,
162 fname, _MAX_FNAME, ext, _MAX_EXT );
163 if (err == 0) { // no error
164 strcat (fname, ext); //just cat them, size of frame can keep both
165 strncpy (appName, fname, sizeof(appName));
166 appName[ sizeof( appName ) -1 ] = '\0';
167 }
168 }
169 #endif
170
171 vlog( "\n%s", appName );
172 for( i = 1; i < argc; i++ )
173 {
174 const char *arg = argv[i];
175 if( NULL == arg )
176 break;
177
178 vlog( "\t%s", arg );
179 if( arg[0] == '-' )
180 {
181 arg++;
182 while( *arg != '\0' )
183 {
184 switch( *arg )
185 {
186 case 'd':
187 gTestDouble ^= 1;
188 break;
189
190 case 'h':
191 PrintUsage();
192 return -1;
193
194 case 't':
195 gReportTimes ^= 1;
196 break;
197
198 case 'w': // Wimpy mode
199 gWimpyMode = true;
200 break;
201 case '[':
202 parseWimpyReductionFactor( arg, gWimpyReductionFactor);
203 break;
204 default:
205 vlog_error( " <-- unknown flag: %c (0x%2.2x)\n)", *arg, *arg );
206 PrintUsage();
207 return -1;
208 }
209 arg++;
210 }
211 }
212 else
213 {
214 argList[ argCount ] = arg;
215 argCount++;
216 }
217 }
218
219 if (getenv("CL_WIMPY_MODE")) {
220 vlog( "\n" );
221 vlog( "*** Detected CL_WIMPY_MODE env ***\n" );
222 gWimpyMode = 1;
223 }
224
225 vlog( "Test binary built %s %s\n", __DATE__, __TIME__ );
226 PrintArch();
227 if( gWimpyMode )
228 {
229 vlog( "\n" );
230 vlog( "*** WARNING: Testing in Wimpy mode! ***\n" );
231 vlog( "*** Wimpy mode is not sufficient to verify correctness. ***\n" );
232 vlog( "*** It gives warm fuzzy feelings and then nevers calls. ***\n\n" );
233 vlog( "*** Wimpy Reduction Factor: %-27u ***\n\n", gWimpyReductionFactor);
234 }
235 return 0;
236 }
237
PrintUsage(void)238 static void PrintUsage( void )
239 {
240 vlog( "%s [-dthw]: <optional: test names>\n", appName );
241 vlog( "\t\t-d\tToggle double precision testing (default: on if double supported)\n" );
242 vlog( "\t\t-t\tToggle reporting performance data.\n" );
243 vlog( "\t\t-w\tRun in wimpy mode\n" );
244 vlog( "\t\t-[2^n]\tSet wimpy reduction factor, recommended range of n is 1-12, default factor(%u)\n", gWimpyReductionFactor);
245 vlog( "\t\t-h\tHelp\n" );
246 for( int i = 0; i < test_num; i++ )
247 {
248 vlog("\t\t%s\n", test_list[i].name );
249 }
250 }
251
252