• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015-2019 The Khronos Group Inc.
3  * Copyright (c) 2015-2019 Valve Corporation
4  * Copyright (c) 2015-2019 LunarG, Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
19  * Author: Tony Barbour <tony@LunarG.com>
20  */
21 
22 #ifndef VKTESTFRAMEWORK_H
23 #define VKTESTFRAMEWORK_H
24 
25 #include "SPIRV/GLSL.std.450.h"
26 #include "spirv-tools/libspirv.h"
27 #include "glslang/Public/ShaderLang.h"
28 #include "icd-spv.h"
29 #include "test_common.h"
30 #include "test_environment.h"
31 
32 #include <fstream>
33 #include <iostream>
34 #include <list>
35 #include <stdbool.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 
40 #ifdef _WIN32
41 #ifndef WIN32_LEAN_AND_MEAN
42 #define WIN32_LEAN_AND_MEAN
43 #endif
44 #include <windows.h>
45 #endif
46 
47 #if defined(NDEBUG) && defined(__GNUC__)
48 #define U_ASSERT_ONLY __attribute__((unused))
49 #else
50 #define U_ASSERT_ONLY
51 #endif
52 
53 // Can be used by tests to record additional details / description of test
54 #define TEST_DESCRIPTION(desc) RecordProperty("description", desc)
55 
56 using namespace std;
57 
58 class VkImageObj;
59 
60 class VkTestFramework : public ::testing::Test {
61    public:
62     VkFormat GetFormat(VkInstance instance, vk_testing::Device *device);
63     static bool optionMatch(const char *option, char *optionLine);
64     static void InitArgs(int *argc, char *argv[]);
65     static void Finish();
66 
67     bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *pshader, std::vector<unsigned int> &spv,
68                    bool debug = false);
69     bool ASMtoSPV(const spv_target_env target_env, const uint32_t options, const char *pasm, std::vector<unsigned int> &spv);
70     static bool m_canonicalize_spv;
71     static bool m_strip_spv;
72     static bool m_do_everything_spv;
73     static bool m_devsim_layer;
74     static bool m_khronos_layer_disable;
75 
76     char **ReadFileData(const char *fileName);
77     void FreeFileData(char **data);
78 
79    protected:
80     VkTestFramework();
81     virtual ~VkTestFramework() = 0;
82 
83    private:
84     int m_compile_options;
85     int m_num_shader_strings;
86     TBuiltInResource Resources;
87     void SetMessageOptions(EShMessages &messages);
88     void ProcessConfigFile();
89     EShLanguage FindLanguage(const std::string &name);
90     EShLanguage FindLanguage(const VkShaderStageFlagBits shader_type);
91     std::string ConfigFile;
92     bool SetConfigFile(const std::string &name);
93     static int m_width;
94     static int m_height;
95     string m_testName;
96 };
97 
98 class TestEnvironment : public ::testing::Environment {
99    public:
100     void SetUp();
101 
102     void TearDown();
103 };
104 
105 #endif  // VKTESTFRAMEWORK_H
106