blob: 964db88287a652d9fd109fe9284f25e3d4f1ad32 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001// VK tests
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -06002//
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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060023#ifndef VKTESTFRAMEWORK_H
24#define VKTESTFRAMEWORK_H
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060025
26#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060027#include "ShaderLang.h"
28#include "GLSL450Lib.h"
Cody Northropd4e020a2015-03-17 14:54:35 -060029#include "icd-spv.h"
Chia-I Wu13ecdcd2014-12-29 14:38:28 +080030#include "test_common.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060031#include "vktestbinding.h"
Tony Barbouref20d322015-02-25 12:28:39 -070032#include "test_environment.h"
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060033
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 Goeltzenleuchter28d33962014-10-27 13:04:37 -060041
Tony Barbour25e3b832015-05-20 16:53:31 -060042#ifdef _WIN32
43#define WIN32_LEAN_AND_MEAN
44#include <windows.h>
45#endif
46
Tony Barbour22a30862015-04-22 09:02:32 -060047#if defined(NDEBUG) && defined(__GNUC__)
48#define U_ASSERT_ONLY __attribute__((unused))
49#else
50#define U_ASSERT_ONLY
51#endif
52
Courtney Goeltzenleuchter28d33962014-10-27 13:04:37 -060053// Can be used by tests to record additional details / description of test
54#define TEST_DESCRIPTION(desc) RecordProperty("description", desc)
55
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060056using namespace std;
57
Tony Barbour01999182015-04-09 12:58:51 -060058class VkImageObj;
Chia-I Wu13ecdcd2014-12-29 14:38:28 +080059
Tony Barbouref20d322015-02-25 12:28:39 -070060
Tony Barbour01999182015-04-09 12:58:51 -060061class VkTestImageRecord
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060062{
63public:
Tony Barbour01999182015-04-09 12:58:51 -060064 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 Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060070
Tony Barbouref20d322015-02-25 12:28:39 -070071 string m_title;
72 int m_width;
73 int m_height;
74 void *m_data;
Tony Barbouref20d322015-02-25 12:28:39 -070075 unsigned m_data_size;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060076};
77
Tony Barbour01999182015-04-09 12:58:51 -060078class VkTestFramework : public ::testing::Test
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060079{
80public:
Tony Barbour01999182015-04-09 12:58:51 -060081 VkTestFramework();
82 ~VkTestFramework();
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060083
84 static void InitArgs(int *argc, char *argv[]);
Tony Barbour25e3b832015-05-20 16:53:31 -060085 static void InitWindow();
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060086 static void Finish();
87
Tony Barbour01999182015-04-09 12:58:51 -060088 void WritePPM( const char *basename, VkImageObj *image );
89 void Show(const char *comment, VkImageObj *image);
90 void Compare(const char *comment, VkImageObj *image);
91 void RecordImage(VkImageObj * image);
92 void RecordImages(vector<VkImageObj *> image);
Tony Barbour8205d902015-04-16 15:59:00 -060093 bool GLSLtoSPV(const VkShaderStage shader_type,
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -060094 const char *pshader,
Cody Northropacfb0492015-03-17 15:55:58 -060095 std::vector<unsigned int> &spv);
96 static bool m_use_spv;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -060097
Courtney Goeltzenleuchter5c25faa2014-10-21 15:24:51 -060098 char** ReadFileData(const char* fileName);
99 void FreeFileData(char** data);
100
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600101private:
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -0600102 int m_compile_options;
103 int m_num_shader_strings;
104 TBuiltInResource Resources;
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -0600105 void SetMessageOptions(EShMessages& messages);
106 void ProcessConfigFile();
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -0600107 EShLanguage FindLanguage(const std::string& name);
Tony Barbour8205d902015-04-16 15:59:00 -0600108 EShLanguage FindLanguage(const VkShaderStage shader_type);
Courtney Goeltzenleuchter94192032014-10-03 09:53:32 -0600109 std::string ConfigFile;
110 bool SetConfigFile(const std::string& name);
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600111
Tony Barbouref20d322015-02-25 12:28:39 -0700112 static bool m_show_images;
113 static bool m_save_images;
114 static bool m_compare_images;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600115
Courtney Goeltzenleuchterec69b9c2015-04-22 10:09:35 -0600116 static std::list<VkTestImageRecord> m_images;
Tony Barbour01999182015-04-09 12:58:51 -0600117 static std::list<VkTestImageRecord>::iterator m_display_image;
Tony Barbouref20d322015-02-25 12:28:39 -0700118 static int m_display_image_idx;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600119
Tony Barbouref20d322015-02-25 12:28:39 -0700120 static int m_width; // Window width
121 static int m_height; // Window height
Tony Barbour32f368c2014-10-30 14:29:04 -0600122
Tony Barbouref20d322015-02-25 12:28:39 -0700123 int m_frameNum;
124 string m_testName;
Courtney Goeltzenleuchterd0d7ccc2014-09-04 16:24:19 -0600125};
126
Chris Forbes2127e812015-05-25 11:13:04 +1200127class ScopedUseSpv
128{
129 bool saved_value;
130public:
131 ScopedUseSpv(bool value)
132 : saved_value(VkTestFramework::m_use_spv)
133 {
134 VkTestFramework::m_use_spv = value;
135 }
136
137 ~ScopedUseSpv() {
138 VkTestFramework::m_use_spv = saved_value;
139 }
140};
141
Courtney Goeltzenleuchterf12c7762014-10-08 08:46:51 -0600142class TestEnvironment : public ::testing::Environment
143{
144 public:
145 void SetUp();
146
147 void TearDown();
148};
149
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600150#endif // VKTESTFRAMEWORK_H