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