• 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 #ifndef TESTPRINTF_INCLUDED_H
17 #define TESTPRINTF_INCLUDED_H
18 
19 #include "harness/compat.h"
20 #include "harness/testHarness.h"
21 #include "harness/rounding_mode.h"
22 
23 #include <stdio.h>
24 #include <string.h>
25 #include <vector>
26 
27 #ifdef __APPLE__
28 #include <OpenCL/opencl.h>
29 #include <OpenCL/cl_platform.h>
30 #else
31 #include <CL/opencl.h>
32 #include <CL/cl_platform.h>
33 #endif
34 
35 #define ANALYSIS_BUFFER_SIZE 256
36 
37 //-----------------------------------------
38 // Definitions and initializations
39 //-----------------------------------------
40 
41 //-----------------------------------------
42 // Types
43 //-----------------------------------------
44 enum PrintfTestType
45  {
46      TYPE_INT,
47      TYPE_FLOAT,
48      TYPE_FLOAT_LIMITS,
49      TYPE_OCTAL,
50      TYPE_UNSIGNED,
51      TYPE_HEXADEC,
52      TYPE_CHAR,
53      TYPE_STRING,
54      TYPE_VECTOR,
55      TYPE_ADDRESS_SPACE,
56      TYPE_COUNT
57 };
58 
59 struct printDataGenParameters
60 {
61     const char* genericFormat;
62     const char* dataRepresentation;
63     const char* vectorFormatFlag;
64     const char* vectorFormatSpecifier;
65     const char* dataType;
66     const char* vectorSize;
67     const char* addrSpaceArgumentTypeQualifier;
68     const char* addrSpaceVariableTypeQualifier;
69     const char* addrSpaceParameter;
70     const char* addrSpacePAdd;
71 };
72 
73 // Reference results - filled out at run-time
74 static std::vector<std::string> correctBufferInt;
75 static std::vector<std::string> correctBufferFloat;
76 static std::vector<std::string> correctBufferOctal;
77 static std::vector<std::string> correctBufferUnsigned;
78 static std::vector<std::string> correctBufferHexadecimal;
79 // Reference results - Compile-time known
80 extern std::vector<std::string> correctBufferChar;
81 extern std::vector<std::string> correctBufferString;
82 extern std::vector<std::string> correctBufferFloatLimits;
83 extern std::vector<std::string> correctBufferVector;
84 extern std::vector<std::string> correctAddrSpace;
85 
86 // Helper for generating reference results
87 void generateRef(const cl_device_id device);
88 
89 //-----------------------------------------
90 //Test Case
91 //-----------------------------------------
92 
93 struct testCase
94 {
95     enum PrintfTestType _type;                           //(data)type for test
96     std::vector<std::string>& _correctBuffer;            //look-up table for correct results for printf
97     std::vector<printDataGenParameters>& _genParameters; //auxiliary data to build the code for kernel source
98     void (*printFN)(printDataGenParameters&,
99                     char*,
100                     const size_t);                       //function pointer for generating reference results
101     Type dataType;                                       //the data type that will be printed during reference result generation (used for setting rounding mode)
102 };
103 
104 extern const char* strType[];
105 extern std::vector<testCase*> allTestCase;
106 
107 size_t verifyOutputBuffer(char *analysisBuffer,testCase* pTestCase,size_t testId,cl_ulong pAddr = 0);
108 
109 // Helpful macros
110 
111 // The next three functions check on different return values.  Returns -1
112 // if the check failed
113 #define checkErr(err, msg)                \
114     if (err != CL_SUCCESS) {                \
115     log_error("%s failed errcode:%d\n", msg, err);    \
116     return -1;                    \
117     }
118 
119 #define checkZero(val, msg)                \
120     if (val == 0) {                    \
121     log_error("%s failed errcode:%d\n", msg, err);    \
122     return -1;                    \
123     }
124 
125 #define checkNull(ptr, msg)            \
126     if (!ptr) {                    \
127     log_error("%s failed\n", msg);        \
128     return TEST_FAIL;                \
129     }
130 
131 // When a helper returns a negative one, we want to return from main
132 // with negative one. This helper prevents me from having to write
133 // this multiple time
134 #define checkHelperErr(err)            \
135     if (err == -1) {                \
136     return err;                \
137     }
138 
139 #endif // TESTSPRINTF_INCLUDED_H
140