• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2017-2019 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 _testHarness_h
17 #define _testHarness_h
18 
19 #include "threadTesting.h"
20 #include "clImageHelper.h"
21 #include <string>
22 #include <sstream>
23 
24 #include <string>
25 
26 class Version {
27 public:
Version()28     Version(): m_major(0), m_minor(0) {}
Version(int major,int minor)29     Version(int major, int minor): m_major(major), m_minor(minor) {}
30     bool operator>(const Version &rhs) const { return to_int() > rhs.to_int(); }
31     bool operator<(const Version &rhs) const { return to_int() < rhs.to_int(); }
32     bool operator<=(const Version &rhs) const
33     {
34         return to_int() <= rhs.to_int();
35     }
36     bool operator>=(const Version &rhs) const
37     {
38         return to_int() >= rhs.to_int();
39     }
40     bool operator==(const Version &rhs) const
41     {
42         return to_int() == rhs.to_int();
43     }
to_int()44     int to_int() const { return m_major * 10 + m_minor; }
to_string()45     std::string to_string() const
46     {
47         std::stringstream ss;
48         ss << m_major << "." << m_minor;
49         return ss.str();
50     }
51 
52 private:
53     int m_major;
54     int m_minor;
55 };
56 
57 Version get_device_cl_version(cl_device_id device);
58 
59 #define ADD_TEST(fn)                                                           \
60     {                                                                          \
61         test_##fn, #fn, Version(1, 0)                                          \
62     }
63 #define ADD_TEST_VERSION(fn, ver)                                              \
64     {                                                                          \
65         test_##fn, #fn, ver                                                    \
66     }
67 
68 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
69 
70 typedef struct test_definition
71 {
72     basefn func;
73     const char *name;
74     Version min_version;
75 } test_definition;
76 
77 
78 typedef enum test_status
79 {
80     TEST_PASS = 0,
81     TEST_FAIL = 1,
82     TEST_SKIP = 2,
83     TEST_SKIPPED_ITSELF = -100,
84 } test_status;
85 
86 extern int gFailCount;
87 extern int gTestCount;
88 extern cl_uint gReSeed;
89 extern cl_uint gRandomSeed;
90 
91 // Supply a list of functions to test here. This will allocate a CL device,
92 // create a context, all that setup work, and then call each function in turn as
93 // dictatated by the passed arguments. Returns EXIT_SUCCESS iff all tests
94 // succeeded or the tests were listed, otherwise return EXIT_FAILURE.
95 extern int runTestHarness(int argc, const char *argv[], int testNum,
96                           test_definition testList[],
97                           int forceNoContextCreation,
98                           cl_command_queue_properties queueProps);
99 
100 // Device checking function. See runTestHarnessWithCheck. If this function
101 // returns anything other than TEST_PASS, the harness exits.
102 typedef test_status (*DeviceCheckFn)(cl_device_id device);
103 
104 // Same as runTestHarness, but also supplies a function that checks the created
105 // device for required functionality. Returns EXIT_SUCCESS iff all tests
106 // succeeded or the tests were listed, otherwise return EXIT_FAILURE.
107 extern int runTestHarnessWithCheck(int argc, const char *argv[], int testNum,
108                                    test_definition testList[],
109                                    int forceNoContextCreation,
110                                    cl_command_queue_properties queueProps,
111                                    DeviceCheckFn deviceCheckFn);
112 
113 // The command line parser used by runTestHarness to break up parameters into
114 // calls to callTestFunctions
115 extern int parseAndCallCommandLineTests(int argc, const char *argv[],
116                                         cl_device_id device, int testNum,
117                                         test_definition testList[],
118                                         int forceNoContextCreation,
119                                         cl_command_queue_properties queueProps,
120                                         int num_elements);
121 
122 // Call this function if you need to do all the setup work yourself, and just
123 // need the function list called/ managed.
124 //    testList is the data structure that contains test functions and its names
125 //    selectedTestList is an array of integers (treated as bools) which tell
126 //    which function is to be called,
127 //       each element at index i, corresponds to the element in testList at
128 //       index i
129 //    resultTestList is an array of statuses which contain the result of each
130 //    selected test testNum is the number of tests in testList, selectedTestList
131 //    and resultTestList contextProps are used to create a testing context for
132 //    each test deviceToUse and numElementsToUse are all just passed to each
133 //    test function
134 extern void callTestFunctions(test_definition testList[],
135                               unsigned char selectedTestList[],
136                               test_status resultTestList[], int testNum,
137                               cl_device_id deviceToUse,
138                               int forceNoContextCreation, int numElementsToUse,
139                               cl_command_queue_properties queueProps);
140 
141 // This function is called by callTestFunctions, once per function, to do setup,
142 // call, logging and cleanup
143 extern test_status
144 callSingleTestFunction(test_definition test, cl_device_id deviceToUse,
145                        int forceNoContextCreation, int numElementsToUse,
146                        cl_command_queue_properties queueProps);
147 
148 ///// Miscellaneous steps
149 
150 // standard callback function for context pfn_notify
151 extern void CL_CALLBACK notify_callback(const char *errinfo,
152                                         const void *private_info, size_t cb,
153                                         void *user_data);
154 
155 extern cl_device_type GetDeviceType(cl_device_id);
156 
157 // Given a device (most likely passed in by the harness, but not required), will
158 // attempt to find a DIFFERENT device and return it. Useful for finding another
159 // device to run multi-device tests against. Note that returning NULL means an
160 // error was hit, but if no error was hit and the device passed in is the only
161 // device available, the SAME device is returned, so check!
162 extern cl_device_id GetOpposingDevice(cl_device_id device);
163 
164 Version get_device_spirv_il_version(cl_device_id device);
165 bool check_device_spirv_il_support(cl_device_id device);
166 void version_expected_info(const char *test_name, const char *api_name,
167                            const char *expected_version,
168                            const char *device_version);
169 test_status check_spirv_compilation_readiness(cl_device_id device);
170 
171 
172 extern int gFlushDenormsToZero; // This is set to 1 if the device does not
173                                 // support denorms (CL_FP_DENORM)
174 extern int gInfNanSupport; // This is set to 1 if the device supports infinities
175                            // and NaNs
176 extern int gIsEmbedded; // This is set to 1 if the device is an embedded device
177 extern int gHasLong; // This is set to 1 if the device suppots long and ulong
178                      // types in OpenCL C.
179 extern bool gCoreILProgram;
180 
181 extern cl_platform_id getPlatformFromDevice(cl_device_id deviceID);
182 
183 #if !defined(__APPLE__)
184 void memset_pattern4(void *, const void *, size_t);
185 #endif
186 
187 extern void PrintArch(void);
188 
189 
190 #endif // _testHarness_h
191