Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 1 | // XGL tests |
| 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 | |
| 23 | #ifndef XGLTESTFRAMEWORK_H |
| 24 | #define XGLTESTFRAMEWORK_H |
| 25 | |
| 26 | #include "gtest-1.7.0/include/gtest/gtest.h" |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 27 | #include "ShaderLang.h" |
| 28 | #include "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" |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 31 | #include "xgltestbinding.h" |
| 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> |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 41 | #include <xglWsiX11Ext.h> |
Courtney Goeltzenleuchter | c5e00a1 | 2014-10-27 13:04:37 -0600 | [diff] [blame] | 42 | |
| 43 | // Can be used by tests to record additional details / description of test |
| 44 | #define TEST_DESCRIPTION(desc) RecordProperty("description", desc) |
| 45 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 46 | using namespace std; |
| 47 | |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 48 | class XglImage; |
| 49 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 50 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 51 | class XglTestImageRecord |
| 52 | { |
| 53 | public: |
| 54 | XglTestImageRecord(); |
| 55 | XglTestImageRecord(const XglTestImageRecord &); |
| 56 | ~XglTestImageRecord(); |
| 57 | XglTestImageRecord &operator=(const XglTestImageRecord &rhs); |
| 58 | int operator==(const XglTestImageRecord &rhs) const; |
| 59 | int operator<(const XglTestImageRecord &rhs) const; |
| 60 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 61 | string m_title; |
| 62 | int m_width; |
| 63 | int m_height; |
| 64 | void *m_data; |
| 65 | XGL_IMAGE m_presentableImage; |
| 66 | XGL_GPU_MEMORY m_presentableMemory; |
| 67 | unsigned m_data_size; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | class XglTestFramework : public ::testing::Test |
| 71 | { |
| 72 | public: |
| 73 | XglTestFramework(); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 74 | ~XglTestFramework(); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 75 | |
| 76 | static void InitArgs(int *argc, char *argv[]); |
| 77 | static void Finish(); |
| 78 | |
| 79 | void WritePPM( const char *basename, XglImage *image ); |
| 80 | void Show(const char *comment, XglImage *image); |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 81 | void Compare(const char *comment, XglImage *image); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 82 | void RecordImage(XglImage *image); |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 83 | void RecordImage(XglImage *image, char *tag); |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 84 | bool GLSLtoSPV(const XGL_PIPELINE_SHADER_STAGE shader_type, |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 85 | const char *pshader, |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 86 | std::vector<unsigned int> &spv); |
| 87 | static bool m_use_spv; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 88 | |
Courtney Goeltzenleuchter | 8bc46f4 | 2014-10-21 15:24:51 -0600 | [diff] [blame] | 89 | char** ReadFileData(const char* fileName); |
| 90 | void FreeFileData(char** data); |
| 91 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 92 | private: |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 93 | int m_compile_options; |
| 94 | int m_num_shader_strings; |
| 95 | TBuiltInResource Resources; |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 96 | void SetMessageOptions(EShMessages& messages); |
| 97 | void ProcessConfigFile(); |
Courtney Goeltzenleuchter | 9818f78 | 2014-10-03 09:53:32 -0600 | [diff] [blame] | 98 | EShLanguage FindLanguage(const std::string& name); |
| 99 | EShLanguage FindLanguage(const XGL_PIPELINE_SHADER_STAGE shader_type); |
| 100 | std::string ConfigFile; |
| 101 | bool SetConfigFile(const std::string& name); |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 102 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 103 | static bool m_show_images; |
| 104 | static bool m_save_images; |
| 105 | static bool m_compare_images; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 106 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 107 | static std::list<XglTestImageRecord> m_images; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 108 | static std::list<XglTestImageRecord>::iterator m_display_image; |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 109 | static int m_display_image_idx; |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 110 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 111 | static int m_width; // Window width |
| 112 | static int m_height; // Window height |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 113 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 114 | int m_frameNum; |
| 115 | string m_testName; |
Tony Barbour | 247bf37 | 2014-10-30 14:29:04 -0600 | [diff] [blame] | 116 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 117 | }; |
| 118 | |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 119 | |
| 120 | class TestFrameworkXglPresent |
| 121 | { |
| 122 | public: |
| 123 | TestFrameworkXglPresent(); |
| 124 | |
| 125 | void Run(); |
| 126 | void InitPresentFramework(std::list<XglTestImageRecord> &imagesIn); |
Tony Barbour | 2b3ae0f | 2015-04-02 15:52:36 -0600 | [diff] [blame] | 127 | void CreateMyWindow(); |
Tony Barbour | 96db882 | 2015-02-25 12:28:39 -0700 | [diff] [blame] | 128 | void CreatePresentableImages(); |
| 129 | void TearDown(); |
| 130 | |
| 131 | protected: |
| 132 | xgl_testing::Device &m_device; |
| 133 | xgl_testing::Queue &m_queue; |
| 134 | xgl_testing::CmdBuffer m_cmdbuf; |
| 135 | |
| 136 | private: |
| 137 | xcb_window_t m_window; |
| 138 | xcb_intern_atom_reply_t *m_atom_wm_delete_window; |
| 139 | std::list<XglTestImageRecord> m_images; |
| 140 | |
| 141 | bool m_quit; |
| 142 | bool m_pause; |
| 143 | |
| 144 | uint32_t m_width; |
| 145 | uint32_t m_height; |
| 146 | |
| 147 | std::list<XglTestImageRecord>::iterator m_display_image; |
| 148 | |
| 149 | void Display(); |
| 150 | void HandleEvent(xcb_generic_event_t *event); |
| 151 | }; |
| 152 | |
Courtney Goeltzenleuchter | a0f74c5 | 2014-10-08 08:46:51 -0600 | [diff] [blame] | 153 | class TestEnvironment : public ::testing::Environment |
| 154 | { |
| 155 | public: |
| 156 | void SetUp(); |
| 157 | |
| 158 | void TearDown(); |
| 159 | }; |
| 160 | |
Courtney Goeltzenleuchter | 30e9dc4 | 2014-09-04 16:24:19 -0600 | [diff] [blame] | 161 | #endif // XGLTESTFRAMEWORK_H |