Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1 | // |
Courtney Goeltzenleuchter | fcbe16f | 2015-10-29 13:50:34 -0600 | [diff] [blame] | 2 | // Copyright (C) 2015 Valve Corporation |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 3 | // |
| 4 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | // copy of this software and associated documentation files (the "Software"), |
| 6 | // to deal in the Software without restriction, including without limitation |
| 7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | // and/or sell copies of the Software, and to permit persons to whom the |
| 9 | // Software is furnished to do so, subject to the following conditions: |
| 10 | // |
| 11 | // The above copyright notice and this permission notice shall be included |
| 12 | // in all copies or substantial portions of the Software. |
| 13 | // |
| 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 21 | // |
| 22 | // Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 23 | // Author: Tony Barbour <tony@LunarG.com> |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 24 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 25 | #ifndef VKTESTFRAMEWORK_H |
| 26 | #define VKTESTFRAMEWORK_H |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 27 | |
Courtney Goeltzenleuchter | 58f3eff | 2015-10-07 13:28:58 -0600 | [diff] [blame] | 28 | //#include "gtest-1.7.0/include/gtest/gtest.h" |
Cody Northrop | 5a95b47 | 2015-06-03 13:01:54 -0600 | [diff] [blame] | 29 | #include "glslang/Public/ShaderLang.h" |
GregF | 5af3f77 | 2015-09-22 13:58:21 -0600 | [diff] [blame] | 30 | #include "SPIRV/GLSL.std.450.h" |
Cody Northrop | 054a470 | 2015-03-17 14:54:35 -0600 | [diff] [blame] | 31 | #include "icd-spv.h" |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 32 | #include "test_common.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 33 | #include "vktestbinding.h" |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 34 | #include "test_environment.h" |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 35 | |
| 36 | #include <stdlib.h> |
| 37 | #include <stdio.h> |
| 38 | #include <stdbool.h> |
| 39 | #include <string.h> |
| 40 | #include <iostream> |
| 41 | #include <fstream> |
| 42 | #include <list> |
Courtney Goeltzenleuchter | c5e00a1 | 2014-10-27 13:04:37 -0600 | [diff] [blame] | 43 | |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 44 | #ifdef _WIN32 |
Courtney Goeltzenleuchter | 8e52a12 | 2015-12-16 16:03:43 -0700 | [diff] [blame] | 45 | #ifndef WIN32_LEAN_AND_MEAN |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 46 | #define WIN32_LEAN_AND_MEAN |
Courtney Goeltzenleuchter | 8e52a12 | 2015-12-16 16:03:43 -0700 | [diff] [blame] | 47 | #endif |
Tony Barbour | 3d69c9e | 2015-05-20 16:53:31 -0600 | [diff] [blame] | 48 | #include <windows.h> |
| 49 | #endif |
| 50 | |
Tony Barbour | f20f87b | 2015-04-22 09:02:32 -0600 | [diff] [blame] | 51 | #if defined(NDEBUG) && defined(__GNUC__) |
| 52 | #define U_ASSERT_ONLY __attribute__((unused)) |
| 53 | #else |
| 54 | #define U_ASSERT_ONLY |
| 55 | #endif |
| 56 | |
Courtney Goeltzenleuchter | c5e00a1 | 2014-10-27 13:04:37 -0600 | [diff] [blame] | 57 | // Can be used by tests to record additional details / description of test |
| 58 | #define TEST_DESCRIPTION(desc) RecordProperty("description", desc) |
| 59 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 60 | using namespace std; |
| 61 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 62 | class VkImageObj; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 63 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 64 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 65 | class VkTestImageRecord |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 66 | { |
| 67 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 68 | VkTestImageRecord(); |
| 69 | VkTestImageRecord(const VkTestImageRecord &); |
| 70 | ~VkTestImageRecord(); |
| 71 | VkTestImageRecord &operator=(const VkTestImageRecord &rhs); |
| 72 | int operator==(const VkTestImageRecord &rhs) const; |
| 73 | int operator<(const VkTestImageRecord &rhs) const; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 74 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 75 | string m_title; |
| 76 | int m_width; |
| 77 | int m_height; |
| 78 | void *m_data; |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 79 | unsigned m_data_size; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 80 | }; |
| 81 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 82 | class VkTestFramework : public ::testing::Test |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 83 | { |
| 84 | public: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 85 | VkTestFramework(); |
| 86 | ~VkTestFramework(); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 87 | |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 88 | static bool optionMatch(const char* option, char* optionLine); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 89 | static void InitArgs(int *argc, char *argv[]); |
| 90 | static void Finish(); |
| 91 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 92 | void WritePPM( const char *basename, VkImageObj *image ); |
| 93 | void Show(const char *comment, VkImageObj *image); |
| 94 | void Compare(const char *comment, VkImageObj *image); |
| 95 | void RecordImage(VkImageObj * image); |
| 96 | void RecordImages(vector<VkImageObj *> image); |
Tony Barbour | 2d6d54e | 2015-12-03 16:05:11 -0700 | [diff] [blame] | 97 | VkFormat GetFormat(VkInstance instance, vk_testing::Device *device); |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 98 | bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 99 | const char *pshader, |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 100 | std::vector<unsigned int> &spv); |
Cody Northrop | 50a2a4b | 2015-06-03 16:49:20 -0600 | [diff] [blame] | 101 | static bool m_use_glsl; |
Cody Northrop | 5a95b47 | 2015-06-03 13:01:54 -0600 | [diff] [blame] | 102 | static bool m_canonicalize_spv; |
| 103 | static bool m_strip_spv; |
| 104 | static bool m_do_everything_spv; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 105 | |
Courtney Goeltzenleuchter | 8bc46f4 | 2014-10-21 15:24:51 -0600 | [diff] [blame] | 106 | char** ReadFileData(const char* fileName); |
| 107 | void FreeFileData(char** data); |
| 108 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 109 | private: |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 110 | int m_compile_options; |
| 111 | int m_num_shader_strings; |
| 112 | TBuiltInResource Resources; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 113 | void SetMessageOptions(EShMessages& messages); |
| 114 | void ProcessConfigFile(); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 115 | EShLanguage FindLanguage(const std::string& name); |
Courtney Goeltzenleuchter | d263550 | 2015-10-21 17:08:06 -0600 | [diff] [blame] | 116 | EShLanguage FindLanguage(const VkShaderStageFlagBits shader_type); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 117 | std::string ConfigFile; |
| 118 | bool SetConfigFile(const std::string& name); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 119 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 120 | static bool m_show_images; |
| 121 | static bool m_save_images; |
| 122 | static bool m_compare_images; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 123 | |
Courtney Goeltzenleuchter | d6079ec | 2015-04-22 10:09:35 -0600 | [diff] [blame] | 124 | static std::list<VkTestImageRecord> m_images; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 125 | static std::list<VkTestImageRecord>::iterator m_display_image; |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 126 | static int m_display_image_idx; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 127 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 128 | static int m_width; // Window width |
| 129 | static int m_height; // Window height |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 130 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 131 | int m_frameNum; |
| 132 | string m_testName; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 133 | }; |
| 134 | |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 135 | class TestEnvironment : public ::testing::Environment |
| 136 | { |
| 137 | public: |
| 138 | void SetUp(); |
| 139 | |
| 140 | void TearDown(); |
| 141 | }; |
| 142 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 143 | #endif // VKTESTFRAMEWORK_H |