Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 1 | /* |
Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 2 | * Copyright (c) 2015-2019 The Khronos Group Inc. |
| 3 | * Copyright (c) 2015-2019 Valve Corporation |
| 4 | * Copyright (c) 2015-2019 LunarG, Inc. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 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 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 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. |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 17 | * |
| 18 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 19 | * Author: Tony Barbour <tony@LunarG.com> |
| 20 | */ |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 21 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 22 | #ifndef VKTESTFRAMEWORK_H |
| 23 | #define VKTESTFRAMEWORK_H |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 24 | |
GregF | 5af3f77 | 2015-09-22 13:58:21 -0600 | [diff] [blame] | 25 | #include "SPIRV/GLSL.std.450.h" |
Karl Schultz | 2370762 | 2018-08-22 10:20:33 -0600 | [diff] [blame] | 26 | #include "spirv-tools/libspirv.h" |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 27 | #include "glslang/Public/ShaderLang.h" |
Cody Northrop | 054a470 | 2015-03-17 14:54:35 -0600 | [diff] [blame] | 28 | #include "icd-spv.h" |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 29 | #include "test_common.h" |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 30 | #include "test_environment.h" |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 31 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 32 | #include <fstream> |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 33 | #include <iostream> |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 34 | #include <list> |
Mark Lobodzinski | c6a6214 | 2016-09-07 16:35:55 -0600 | [diff] [blame] | 35 | #include <stdbool.h> |
| 36 | #include <stdio.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <string.h> |
Courtney Goeltzenleuchter | c5e00a1 | 2014-10-27 13:04:37 -0600 | [diff] [blame] | 39 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 40 | #ifdef _WIN32 |
Courtney Goeltzenleuchter | 8e52a12 | 2015-12-16 16:03:43 -0700 | [diff] [blame] | 41 | #ifndef WIN32_LEAN_AND_MEAN |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 42 | #define WIN32_LEAN_AND_MEAN |
Courtney Goeltzenleuchter | 8e52a12 | 2015-12-16 16:03:43 -0700 | [diff] [blame] | 43 | #endif |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 44 | #include <windows.h> |
| 45 | #endif |
| 46 | |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 47 | #if defined(NDEBUG) && defined(__GNUC__) |
| 48 | #define U_ASSERT_ONLY __attribute__((unused)) |
| 49 | #else |
| 50 | #define U_ASSERT_ONLY |
| 51 | #endif |
| 52 | |
Courtney Goeltzenleuchter | c5e00a1 | 2014-10-27 13:04:37 -0600 | [diff] [blame] | 53 | // Can be used by tests to record additional details / description of test |
| 54 | #define TEST_DESCRIPTION(desc) RecordProperty("description", desc) |
| 55 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 56 | using namespace std; |
| 57 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 58 | class VkImageObj; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 59 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 60 | class VkTestFramework : public ::testing::Test { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 61 | public: |
Tony Barbour | 7b60e49 | 2016-02-02 14:43:55 -0700 | [diff] [blame] | 62 | VkFormat GetFormat(VkInstance instance, vk_testing::Device *device); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 63 | static bool optionMatch(const char *option, char *optionLine); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 64 | static void InitArgs(int *argc, char *argv[]); |
| 65 | static void Finish(); |
| 66 | |
Karl Schultz | 9d09ee9 | 2018-10-19 14:31:49 -0600 | [diff] [blame] | 67 | bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *pshader, std::vector<unsigned int> &spv, |
| 68 | bool debug = false); |
Karl Schultz | 2370762 | 2018-08-22 10:20:33 -0600 | [diff] [blame] | 69 | bool ASMtoSPV(const spv_target_env target_env, const uint32_t options, const char *pasm, std::vector<unsigned int> &spv); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 70 | static bool m_canonicalize_spv; |
| 71 | static bool m_strip_spv; |
| 72 | static bool m_do_everything_spv; |
Tobin Ehlis | 7288864 | 2017-11-15 09:43:56 -0700 | [diff] [blame] | 73 | static bool m_devsim_layer; |
Mark Lobodzinski | 2cf94fd | 2019-03-18 14:53:33 -0600 | [diff] [blame] | 74 | static bool m_khronos_layer_disable; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 75 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 76 | char **ReadFileData(const char *fileName); |
| 77 | void FreeFileData(char **data); |
Courtney Goeltzenleuchter | 8bc46f4 | 2014-10-21 15:24:51 -0600 | [diff] [blame] | 78 | |
Petr Kraus | 13b625d | 2019-03-25 15:29:47 +0100 | [diff] [blame] | 79 | protected: |
| 80 | VkTestFramework(); |
| 81 | virtual ~VkTestFramework() = 0; |
| 82 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 83 | private: |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 84 | int m_compile_options; |
| 85 | int m_num_shader_strings; |
| 86 | TBuiltInResource Resources; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 87 | void SetMessageOptions(EShMessages &messages); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 88 | void ProcessConfigFile(); |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 89 | EShLanguage FindLanguage(const std::string &name); |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 90 | EShLanguage FindLanguage(const VkShaderStageFlagBits shader_type); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 91 | std::string ConfigFile; |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 92 | bool SetConfigFile(const std::string &name); |
| 93 | static int m_width; |
| 94 | static int m_height; |
| 95 | string m_testName; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 96 | }; |
| 97 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 98 | class TestEnvironment : public ::testing::Environment { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 99 | public: |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 100 | void SetUp(); |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 101 | |
Karl Schultz | 6addd81 | 2016-02-02 17:17:23 -0700 | [diff] [blame] | 102 | void TearDown(); |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 103 | }; |
| 104 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 105 | #endif // VKTESTFRAMEWORK_H |