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