blob: f58d5e130e4089bfcc7d8128f751b062615292f6 [file] [log] [blame]
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001#include <vulkan.h>
2#include <vkDbg.h>
Tony Barbour30486ea2015-04-07 13:44:53 -06003#include "gtest-1.7.0/include/gtest/gtest.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06004#include "vkrenderframework.h"
Tony Barbour30486ea2015-04-07 13:44:53 -06005
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06006void VKAPI myDbgFunc(
7 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06008 VkValidationLevel validationLevel,
Mike Stroyan230e6252015-04-17 12:36:38 -06009 VkObject srcObject,
Tony Barbour30486ea2015-04-07 13:44:53 -060010 size_t location,
11 int32_t msgCode,
12 const char* pMsg,
13 void* pUserData);
14
15class ErrorMonitor {
16public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060017 ErrorMonitor(VkInstance inst)
Tony Barbour30486ea2015-04-07 13:44:53 -060018 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060019 vkDbgRegisterMsgCallback(inst, myDbgFunc, this);
20 m_msgType = VK_DBG_MSG_UNKNOWN;
Tony Barbour30486ea2015-04-07 13:44:53 -060021 }
22 void ClearState()
23 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060024 m_msgType = VK_DBG_MSG_UNKNOWN;
Tony Barbour30486ea2015-04-07 13:44:53 -060025 m_msgString.clear();
26 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060027 VK_DBG_MSG_TYPE GetState(std::string *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060028 {
29 *msgString = m_msgString;
30 return m_msgType;
31 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060032 void SetState(VK_DBG_MSG_TYPE msgType, const char *msgString)
Tony Barbour30486ea2015-04-07 13:44:53 -060033 {
34 m_msgType = msgType;
Tony Barbour8508b8e2015-04-09 10:48:04 -060035 m_msgString.reserve(strlen(msgString));
36 m_msgString = msgString;
Tony Barbour30486ea2015-04-07 13:44:53 -060037 }
38
39private:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060040 VK_DBG_MSG_TYPE m_msgType;
Tony Barbour30486ea2015-04-07 13:44:53 -060041 std::string m_msgString;
42
43};
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060044void VKAPI myDbgFunc(
Mike Stroyan230e6252015-04-17 12:36:38 -060045 VK_DBG_MSG_TYPE msgType,
46 VkValidationLevel validationLevel,
47 VkObject srcObject,
Tony Barbour30486ea2015-04-07 13:44:53 -060048 size_t location,
49 int32_t msgCode,
50 const char* pMsg,
51 void* pUserData)
52{
Tony Barbour8508b8e2015-04-09 10:48:04 -060053 if (msgType == VK_DBG_MSG_WARNING || msgType == VK_DBG_MSG_ERROR) {
54 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
55 errMonitor->SetState(msgType, pMsg);
56 }
Tony Barbour30486ea2015-04-07 13:44:53 -060057}
Tony Barbour01999182015-04-09 12:58:51 -060058class VkLayerTest : public VkRenderFramework
Tony Barbour30486ea2015-04-07 13:44:53 -060059{
60public:
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060061 VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer);
62 VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -060063
64protected:
Tony Barbour01999182015-04-09 12:58:51 -060065 VkMemoryRefManager m_memoryRefManager;
66 ErrorMonitor *m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -060067
68 virtual void SetUp() {
Tony Barbour04ada4a2015-04-23 15:28:27 -060069 const char *extension_names[] = {"MemTracker", "ObjectTracker"};
70 const std::vector<const char *> extensions(extension_names, extension_names + 2);
Tony Barbour950ebc02015-04-23 12:55:36 -060071
72 size_t extSize = sizeof(uint32_t);
73 uint32_t extCount = 0;
Tony Barbour04ada4a2015-04-23 15:28:27 -060074 VkResult U_ASSERT_ONLY err;
Tony Barbour950ebc02015-04-23 12:55:36 -060075 err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_COUNT, 0, &extSize, &extCount);
76 assert(!err);
77
78 VkExtensionProperties extProp;
79 extSize = sizeof(VkExtensionProperties);
80 bool32_t extFound;
81
Tony Barbour04ada4a2015-04-23 15:28:27 -060082 for (uint32_t i = 0; i < extensions.size(); i++) {
Tony Barbour950ebc02015-04-23 12:55:36 -060083 extFound = 0;
84 for (uint32_t j = 0; j < extCount; j++) {
85 err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_PROPERTIES, j, &extSize, &extProp);
Tony Barbour04ada4a2015-04-23 15:28:27 -060086 assert(!err);
87 if (!strcmp(extensions[i], extProp.extName)) {
Tony Barbour950ebc02015-04-23 12:55:36 -060088 extFound = 1;
89 break;
90 }
91 }
Tony Barbour04ada4a2015-04-23 15:28:27 -060092 ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << extensions[i] << " which is necessary to pass this test";
Tony Barbour950ebc02015-04-23 12:55:36 -060093 }
Tony Barbour30486ea2015-04-07 13:44:53 -060094
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060095 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -060096 this->app_info.pNext = NULL;
97 this->app_info.pAppName = "layer_tests";
98 this->app_info.appVersion = 1;
99 this->app_info.pEngineName = "unittest";
100 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600101 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -0600102
Tony Barbour04ada4a2015-04-23 15:28:27 -0600103 InitFramework(extensions);
Tony Barbour30486ea2015-04-07 13:44:53 -0600104 m_errorMonitor = new ErrorMonitor(inst);
105 }
106
107 virtual void TearDown() {
108 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -0600109 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600110 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -0600111 }
112};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600113VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600114{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600115 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600116
117 result = cmdBuffer.BeginCommandBuffer();
118
119 /*
120 * For render test all drawing happens in a single render pass
121 * on a single command buffer.
122 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600123 if (VK_SUCCESS == result) {
Tony Barbour30486ea2015-04-07 13:44:53 -0600124 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
125 }
126
127 return result;
128}
129
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600130VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600131{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600132 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600133
134 cmdBuffer.EndRenderPass(renderPass());
135
136 result = cmdBuffer.EndCommandBuffer();
137
138 return result;
139}
140
Tony Barbour8508b8e2015-04-09 10:48:04 -0600141TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600142{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600143 vk_testing::Fence testFence;
144 VK_DBG_MSG_TYPE msgType;
Tony Barbour30486ea2015-04-07 13:44:53 -0600145 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600146
147 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600148 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
149 fenceInfo.pNext = NULL;
150 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600151
152 // Verifiy that the appropriate layer is loaded
153
154 ASSERT_NO_FATAL_FAILURE(InitState());
155 ASSERT_NO_FATAL_FAILURE(InitViewport());
156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
157
Tony Barbour01999182015-04-09 12:58:51 -0600158 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour30486ea2015-04-07 13:44:53 -0600159 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
160
Tony Barbour8508b8e2015-04-09 10:48:04 -0600161 BeginCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600162 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600163 EndCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600164
165 testFence.init(*m_device, fenceInfo);
166 m_errorMonitor->ClearState();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600167 cmdBuffer.QueueCommandBuffer(testFence.obj());
Tony Barbour30486ea2015-04-07 13:44:53 -0600168 msgType = m_errorMonitor->GetState(&msgString);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600169 ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit";
170 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Tony Barbour9c238c42015-04-09 16:00:51 -0600171 FAIL() << "Error received was not VkQueueSubmit with fence in SIGNALED_STATE";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600172 }
173
174}
175
176TEST_F(VkLayerTest, ResetUnsignaledFence)
177{
178 vk_testing::Fence testFence;
179 VK_DBG_MSG_TYPE msgType;
180 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600181 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600182 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
183 fenceInfo.pNext = NULL;
184
185 // Verifiy that the appropriate layer is loaded
186
187 ASSERT_NO_FATAL_FAILURE(InitState());
188 testFence.init(*m_device, fenceInfo);
189 m_errorMonitor->ClearState();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600190 VkFence fences[1] = {testFence.obj()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600191 vkResetFences(m_device->device(), 1, fences);
192 msgType = m_errorMonitor->GetState(&msgString);
193 ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences";
Tony Barbour01999182015-04-09 12:58:51 -0600194 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Tony Barbour9c238c42015-04-09 16:00:51 -0600195 FAIL() << "Error received was not VkResetFences with fence in UNSIGNALED_STATE";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600196 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600197
198}
199
Tony Barbour54cdd192015-04-22 15:12:07 -0600200TEST_F(VkLayerTest, WaitForUnsubmittedFence)
201{
202 vk_testing::Fence testFence;
203 VK_DBG_MSG_TYPE msgType;
204 std::string msgString;
205 VkFenceCreateInfo fenceInfo = {};
206 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
207 fenceInfo.pNext = NULL;
208
209 // Verifiy that the appropriate layer is loaded
210
211 ASSERT_NO_FATAL_FAILURE(InitState());
212 testFence.init(*m_device, fenceInfo);
213 m_errorMonitor->ClearState();
214 vkGetFenceStatus(m_device->device(),testFence.obj());
215 msgType = m_errorMonitor->GetState(&msgString);
216 ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error asking for status of unsubmitted fence";
217 if (!strstr(msgString.c_str(),"Status Requested for Unsubmitted Fence")) {
218 FAIL() << "Error received was not Status Requested for Unsubmitted Fence";
219 }
220
221 VkFence fences[1] = {testFence.obj()};
222 m_errorMonitor->ClearState();
223 vkWaitForFences(m_device->device(), 1, fences, VK_TRUE, 0);
224 msgType = m_errorMonitor->GetState(&msgString);
225 ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error for waiting for unsubmitted fence";
226 if (!strstr(msgString.c_str(),"Waiting for Unsubmitted Fence")) {
227 FAIL() << "Error received was not Waiting for Unsubmitted Fence";
228 }
229}
230
Tony Barbour30486ea2015-04-07 13:44:53 -0600231int main(int argc, char **argv) {
232 int result;
233
234 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -0600235 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -0600236
237 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
238
239 result = RUN_ALL_TESTS();
240
Tony Barbour01999182015-04-09 12:58:51 -0600241 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -0600242 return result;
243}