• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************
2 Copyright (c) 2016 The Khronos Group Inc. All Rights Reserved.
3 
4 This code is protected by copyright laws and contains material proprietary to the Khronos Group, Inc.
5 This is UNPUBLISHED PROPRIETARY SOURCE CODE that may not be disclosed in whole or in part to
6 third parties, and may not be reproduced, republished, distributed, transmitted, displayed,
7 broadcast or otherwise exploited in any manner without the express prior written permission
8 of Khronos Group. The receipt or possession of this code does not convey any rights to reproduce,
9 disclose, or distribute its contents, or to manufacture, use, or sell anything that it may describe,
10 in whole or in part other than under the terms of the Khronos Adopters Agreement
11 or Khronos Conformance Test Source License Agreement as executed between Khronos and the recipient.
12 ******************************************************************/
13 
14 #pragma once
15 
16 #include "harness/errorHelpers.h"
17 #include "harness/kernelHelpers.h"
18 #include "harness/typeWrappers.h"
19 #include "harness/conversions.h"
20 #include "harness/mt19937.h"
21 #include "harness/compat.h"
22 #include "harness/testHarness.h"
23 #include "harness/parseParameters.h"
24 
25 #include <vector>
26 
27 #define SPIRV_CHECK_ERROR(err, fmt, ...) do {               \
28         if (err == CL_SUCCESS) break;                       \
29         log_error("%s(%d): Error %d\n" fmt "\n",            \
30                   __FILE__, __LINE__, err, ##__VA_ARGS__);  \
31         return -1;                                          \
32     } while(0)
33 
34 
35 class baseTestClass
36 {
37 public:
baseTestClass()38     baseTestClass() {}
39     virtual basefn getFunction() = 0;
40 };
41 
42 class spirvTestsRegistry {
43 private:
44     std::vector<baseTestClass *> testClasses;
45     std::vector<test_definition> testDefinitions;
46 
47 public:
48 
49     static spirvTestsRegistry& getInstance();
50 
51     test_definition *getTestDefinitions();
52 
53     size_t getNumTests();
54 
55     void addTestClass(baseTestClass *test, const char *testName);
spirvTestsRegistry()56     spirvTestsRegistry() {}
57 };
58 
59 template<typename T>
createAndRegister(const char * name)60 T* createAndRegister(const char *name)
61 {
62     T *testClass = new T();
63     spirvTestsRegistry::getInstance().addTestClass((baseTestClass *)testClass, name);
64     return testClass;
65 }
66 
67 #define TEST_SPIRV_FUNC(name)                           \
68     extern int test_##name(cl_device_id deviceID,       \
69                            cl_context context,          \
70                            cl_command_queue queue,      \
71                            int num_elements);           \
72     class test_##name##_class  : public baseTestClass   \
73     {                                                   \
74     private:                                            \
75         basefn fn;                                      \
76                                                         \
77     public:                                             \
78     test_##name##_class() : fn(test_##name)             \
79         {                                               \
80         }                                               \
81         basefn getFunction()                            \
82         {                                               \
83             return fn;                                  \
84         }                                               \
85     };                                                  \
86     test_##name##_class *var_##name =                   \
87         createAndRegister<test_##name##_class>(#name);  \
88     int test_##name(cl_device_id deviceID,              \
89                     cl_context context,                 \
90                     cl_command_queue queue,             \
91                     int num_elements)
92 
93 std::vector<unsigned char> readSPIRV(const char *file_name);
94 
95 int get_program_with_il(clProgramWrapper &prog,
96                         const cl_device_id deviceID,
97                         const cl_context context,
98                         const char *prog_name);
99