Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | // VK tests |
Courtney Goeltzenleuchter | d0d7ccc | 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 | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 23 | #ifndef VKTESTFRAMEWORK_H |
| 24 | #define VKTESTFRAMEWORK_H |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 25 | |
| 26 | #include "gtest-1.7.0/include/gtest/gtest.h" |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 27 | #include "ShaderLang.h" |
| 28 | #include "GLSL450Lib.h" |
Cody Northrop | d4e020a | 2015-03-17 14:54:35 -0600 | [diff] [blame] | 29 | #include "icd-spv.h" |
Chia-I Wu | 13ecdcd | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 30 | #include "test_common.h" |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | #include "vktestbinding.h" |
Tony Barbour | ef20d32 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 32 | #include "test_environment.h" |
Courtney Goeltzenleuchter | d0d7ccc | 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 | 28d3396 | 2014-10-27 13:04:37 -0600 | [diff] [blame] | 41 | |
| 42 | // Can be used by tests to record additional details / description of test |
| 43 | #define TEST_DESCRIPTION(desc) RecordProperty("description", desc) |
| 44 | |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 45 | using namespace std; |
| 46 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 47 | class VkImageObj; |
Chia-I Wu | 13ecdcd | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 48 | |
Tony Barbour | ef20d32 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 49 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 50 | class VkTestImageRecord |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 51 | { |
| 52 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 53 | VkTestImageRecord(); |
| 54 | VkTestImageRecord(const VkTestImageRecord &); |
| 55 | ~VkTestImageRecord(); |
| 56 | VkTestImageRecord &operator=(const VkTestImageRecord &rhs); |
| 57 | int operator==(const VkTestImageRecord &rhs) const; |
| 58 | int operator<(const VkTestImageRecord &rhs) const; |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 59 | |
Tony Barbour | ef20d32 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 60 | string m_title; |
| 61 | int m_width; |
| 62 | int m_height; |
| 63 | void *m_data; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 64 | VkImage m_presentableImage; |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 65 | VkDeviceMemory m_presentableMemory; |
Tony Barbour | ef20d32 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 66 | unsigned m_data_size; |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 67 | }; |
| 68 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 69 | class VkTestFramework : public ::testing::Test |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 70 | { |
| 71 | public: |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 72 | VkTestFramework(); |
| 73 | ~VkTestFramework(); |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 74 | |
| 75 | static void InitArgs(int *argc, char *argv[]); |
| 76 | static void Finish(); |
| 77 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 78 | void WritePPM( const char *basename, VkImageObj *image ); |
| 79 | void Show(const char *comment, VkImageObj *image); |
| 80 | void Compare(const char *comment, VkImageObj *image); |
| 81 | void RecordImage(VkImageObj * image); |
| 82 | void RecordImages(vector<VkImageObj *> image); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 83 | bool GLSLtoSPV(const VkShaderStage shader_type, |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 84 | const char *pshader, |
Cody Northrop | acfb049 | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 85 | std::vector<unsigned int> &spv); |
| 86 | static bool m_use_spv; |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 87 | |
Courtney Goeltzenleuchter | 5c25faa | 2014-10-21 15:24:51 -0600 | [diff] [blame] | 88 | char** ReadFileData(const char* fileName); |
| 89 | void FreeFileData(char** data); |
| 90 | |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 91 | private: |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 92 | int m_compile_options; |
| 93 | int m_num_shader_strings; |
| 94 | TBuiltInResource Resources; |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 95 | void SetMessageOptions(EShMessages& messages); |
| 96 | void ProcessConfigFile(); |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 97 | EShLanguage FindLanguage(const std::string& name); |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 98 | EShLanguage FindLanguage(const VkShaderStage shader_type); |
Courtney Goeltzenleuchter | 9419203 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 99 | std::string ConfigFile; |
| 100 | bool SetConfigFile(const std::string& name); |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 101 | |
Tony Barbour | ef20d32 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 102 | static bool m_show_images; |
| 103 | static bool m_save_images; |
| 104 | static bool m_compare_images; |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 105 | |
Tony Barbour | 0199918 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 106 | static std::list<VkTestImageRecord> m_images; |
| 107 | static std::list<VkTestImageRecord>::iterator m_display_image; |
Tony Barbour | ef20d32 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 108 | static int m_display_image_idx; |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 109 | |
Tony Barbour | ef20d32 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 110 | static int m_width; // Window width |
| 111 | static int m_height; // Window height |
Tony Barbour | 32f368c | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 112 | |
Tony Barbour | ef20d32 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 113 | int m_frameNum; |
| 114 | string m_testName; |
Tony Barbour | 32f368c | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 115 | |
Courtney Goeltzenleuchter | d0d7ccc | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 116 | }; |
| 117 | |
Courtney Goeltzenleuchter | f12c776 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 118 | class TestEnvironment : public ::testing::Environment |
| 119 | { |
| 120 | public: |
| 121 | void SetUp(); |
| 122 | |
| 123 | void TearDown(); |
| 124 | }; |
| 125 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 126 | #endif // VKTESTFRAMEWORK_H |