Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1 | #include <vulkan.h> |
| 2 | #include <vkDbg.h> |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 3 | #include "gtest-1.7.0/include/gtest/gtest.h" |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 4 | #include "vkrenderframework.h" |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 5 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 6 | void VKAPI myDbgFunc( |
| 7 | VK_DBG_MSG_TYPE msgType, |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 8 | VkValidationLevel validationLevel, |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 9 | VkObject srcObject, |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 10 | size_t location, |
| 11 | int32_t msgCode, |
| 12 | const char* pMsg, |
| 13 | void* pUserData); |
| 14 | |
| 15 | class ErrorMonitor { |
| 16 | public: |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 17 | ErrorMonitor() |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 18 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 19 | m_msgType = VK_DBG_MSG_UNKNOWN; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 20 | } |
| 21 | void ClearState() |
| 22 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 23 | m_msgType = VK_DBG_MSG_UNKNOWN; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 24 | m_msgString.clear(); |
| 25 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 26 | VK_DBG_MSG_TYPE GetState(std::string *msgString) |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 27 | { |
| 28 | *msgString = m_msgString; |
| 29 | return m_msgType; |
| 30 | } |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 31 | void SetState(VK_DBG_MSG_TYPE msgType, const char *msgString) |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 32 | { |
| 33 | m_msgType = msgType; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 34 | m_msgString.reserve(strlen(msgString)); |
| 35 | m_msgString = msgString; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | private: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 39 | VK_DBG_MSG_TYPE m_msgType; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 40 | std::string m_msgString; |
| 41 | |
| 42 | }; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 43 | void VKAPI myDbgFunc( |
Mike Stroyan | b050c68 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 44 | VK_DBG_MSG_TYPE msgType, |
| 45 | VkValidationLevel validationLevel, |
| 46 | VkObject srcObject, |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 47 | size_t location, |
| 48 | int32_t msgCode, |
| 49 | const char* pMsg, |
| 50 | void* pUserData) |
| 51 | { |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 52 | if (msgType == VK_DBG_MSG_WARNING || msgType == VK_DBG_MSG_ERROR) { |
| 53 | ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData; |
| 54 | errMonitor->SetState(msgType, pMsg); |
| 55 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 56 | } |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 57 | class VkLayerTest : public VkRenderFramework |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 58 | { |
| 59 | public: |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 60 | VkResult BeginCommandBuffer(VkCommandBufferObj &cmdBuffer); |
| 61 | VkResult EndCommandBuffer(VkCommandBufferObj &cmdBuffer); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 62 | |
| 63 | protected: |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 64 | VkMemoryRefManager m_memoryRefManager; |
| 65 | ErrorMonitor *m_errorMonitor; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 66 | |
| 67 | virtual void SetUp() { |
Tony Barbour | 9b9fe78 | 2015-04-23 15:28:27 -0600 | [diff] [blame] | 68 | const char *extension_names[] = {"MemTracker", "ObjectTracker"}; |
| 69 | const std::vector<const char *> extensions(extension_names, extension_names + 2); |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 70 | |
| 71 | size_t extSize = sizeof(uint32_t); |
| 72 | uint32_t extCount = 0; |
Tony Barbour | 9b9fe78 | 2015-04-23 15:28:27 -0600 | [diff] [blame] | 73 | VkResult U_ASSERT_ONLY err; |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 74 | err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_COUNT, 0, &extSize, &extCount); |
| 75 | assert(!err); |
| 76 | |
| 77 | VkExtensionProperties extProp; |
| 78 | extSize = sizeof(VkExtensionProperties); |
| 79 | bool32_t extFound; |
| 80 | |
Tony Barbour | 9b9fe78 | 2015-04-23 15:28:27 -0600 | [diff] [blame] | 81 | for (uint32_t i = 0; i < extensions.size(); i++) { |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 82 | extFound = 0; |
| 83 | for (uint32_t j = 0; j < extCount; j++) { |
| 84 | err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_PROPERTIES, j, &extSize, &extProp); |
Tony Barbour | 9b9fe78 | 2015-04-23 15:28:27 -0600 | [diff] [blame] | 85 | assert(!err); |
| 86 | if (!strcmp(extensions[i], extProp.extName)) { |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 87 | extFound = 1; |
| 88 | break; |
| 89 | } |
| 90 | } |
Tony Barbour | 9b9fe78 | 2015-04-23 15:28:27 -0600 | [diff] [blame] | 91 | ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << extensions[i] << " which is necessary to pass this test"; |
Tony Barbour | 3fdff9e | 2015-04-23 12:55:36 -0600 | [diff] [blame] | 92 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 93 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 94 | this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 95 | this->app_info.pNext = NULL; |
| 96 | this->app_info.pAppName = "layer_tests"; |
| 97 | this->app_info.appVersion = 1; |
| 98 | this->app_info.pEngineName = "unittest"; |
| 99 | this->app_info.engineVersion = 1; |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 100 | this->app_info.apiVersion = VK_API_VERSION; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 101 | |
Tony Barbour | 15524c3 | 2015-04-29 17:34:29 -0600 | [diff] [blame] | 102 | m_errorMonitor = new ErrorMonitor; |
| 103 | InitFramework(extensions, myDbgFunc, m_errorMonitor); |
| 104 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | virtual void TearDown() { |
| 108 | // Clean up resources before we reset |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 109 | ShutdownFramework(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 110 | delete m_errorMonitor; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 111 | } |
| 112 | }; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 113 | VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 114 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 115 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 116 | |
| 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 Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 123 | if (VK_SUCCESS == result) { |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 124 | cmdBuffer.BeginRenderPass(renderPass(), framebuffer()); |
| 125 | } |
| 126 | |
| 127 | return result; |
| 128 | } |
| 129 | |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 130 | VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer) |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 131 | { |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 132 | VkResult result; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 133 | |
| 134 | cmdBuffer.EndRenderPass(renderPass()); |
| 135 | |
| 136 | result = cmdBuffer.EndCommandBuffer(); |
| 137 | |
| 138 | return result; |
| 139 | } |
| 140 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 141 | TEST_F(VkLayerTest, SubmitSignaledFence) |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 142 | { |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 143 | vk_testing::Fence testFence; |
| 144 | VK_DBG_MSG_TYPE msgType; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 145 | std::string msgString; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 146 | |
| 147 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 148 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 149 | fenceInfo.pNext = NULL; |
| 150 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 151 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 152 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 153 | ASSERT_NO_FATAL_FAILURE(InitViewport()); |
| 154 | ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); |
| 155 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 156 | VkCommandBufferObj cmdBuffer(m_device); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 157 | cmdBuffer.AddRenderTarget(m_renderTargets[0]); |
| 158 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 159 | BeginCommandBuffer(cmdBuffer); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 160 | cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 161 | EndCommandBuffer(cmdBuffer); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 162 | |
| 163 | testFence.init(*m_device, fenceInfo); |
| 164 | m_errorMonitor->ClearState(); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 165 | cmdBuffer.QueueCommandBuffer(testFence.obj()); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 166 | msgType = m_errorMonitor->GetState(&msgString); |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 167 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit"; |
| 168 | if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) { |
Tony Barbour | 22c8f0c | 2015-04-09 16:00:51 -0600 | [diff] [blame] | 169 | FAIL() << "Error received was not VkQueueSubmit with fence in SIGNALED_STATE"; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | } |
| 173 | |
| 174 | TEST_F(VkLayerTest, ResetUnsignaledFence) |
| 175 | { |
| 176 | vk_testing::Fence testFence; |
| 177 | VK_DBG_MSG_TYPE msgType; |
| 178 | std::string msgString; |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 179 | VkFenceCreateInfo fenceInfo = {}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 180 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 181 | fenceInfo.pNext = NULL; |
| 182 | |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 183 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 184 | testFence.init(*m_device, fenceInfo); |
| 185 | m_errorMonitor->ClearState(); |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 186 | VkFence fences[1] = {testFence.obj()}; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 187 | vkResetFences(m_device->device(), 1, fences); |
| 188 | msgType = m_errorMonitor->GetState(&msgString); |
| 189 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error from submitting fence with UNSIGNALED state to vkResetFences"; |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 190 | if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) { |
Tony Barbour | 22c8f0c | 2015-04-09 16:00:51 -0600 | [diff] [blame] | 191 | FAIL() << "Error received was not VkResetFences with fence in UNSIGNALED_STATE"; |
Tony Barbour | 0b4d956 | 2015-04-09 10:48:04 -0600 | [diff] [blame] | 192 | } |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 193 | |
| 194 | } |
| 195 | |
Tony Barbour | 806c906 | 2015-04-22 15:12:07 -0600 | [diff] [blame] | 196 | TEST_F(VkLayerTest, WaitForUnsubmittedFence) |
| 197 | { |
| 198 | vk_testing::Fence testFence; |
| 199 | VK_DBG_MSG_TYPE msgType; |
| 200 | std::string msgString; |
| 201 | VkFenceCreateInfo fenceInfo = {}; |
| 202 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 203 | fenceInfo.pNext = NULL; |
| 204 | |
Tony Barbour | 806c906 | 2015-04-22 15:12:07 -0600 | [diff] [blame] | 205 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 206 | testFence.init(*m_device, fenceInfo); |
| 207 | m_errorMonitor->ClearState(); |
| 208 | vkGetFenceStatus(m_device->device(),testFence.obj()); |
| 209 | msgType = m_errorMonitor->GetState(&msgString); |
| 210 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error asking for status of unsubmitted fence"; |
| 211 | if (!strstr(msgString.c_str(),"Status Requested for Unsubmitted Fence")) { |
| 212 | FAIL() << "Error received was not Status Requested for Unsubmitted Fence"; |
| 213 | } |
| 214 | |
| 215 | VkFence fences[1] = {testFence.obj()}; |
| 216 | m_errorMonitor->ClearState(); |
| 217 | vkWaitForFences(m_device->device(), 1, fences, VK_TRUE, 0); |
| 218 | msgType = m_errorMonitor->GetState(&msgString); |
| 219 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error for waiting for unsubmitted fence"; |
| 220 | if (!strstr(msgString.c_str(),"Waiting for Unsubmitted Fence")) { |
| 221 | FAIL() << "Error received was not Waiting for Unsubmitted Fence"; |
| 222 | } |
| 223 | } |
| 224 | |
Tony Barbour | d866ad0 | 2015-05-06 09:35:56 -0600 | [diff] [blame^] | 225 | TEST_F(VkLayerTest, GetObjectInfoMismatchedType) |
| 226 | { |
| 227 | VkEventCreateInfo event_info; |
| 228 | VkEvent event; |
| 229 | VkMemoryRequirements mem_req; |
| 230 | size_t data_size = sizeof(mem_req); |
| 231 | VK_DBG_MSG_TYPE msgType; |
| 232 | std::string msgString; |
| 233 | VkResult err; |
| 234 | |
| 235 | ASSERT_NO_FATAL_FAILURE(InitState()); |
| 236 | memset(&event_info, 0, sizeof(event_info)); |
| 237 | event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; |
| 238 | |
| 239 | err = vkCreateEvent(device(), &event_info, &event); |
| 240 | ASSERT_VK_SUCCESS(err); |
| 241 | m_errorMonitor->ClearState(); |
| 242 | err = vkGetObjectInfo(device(), VK_OBJECT_TYPE_IMAGE, event, VK_OBJECT_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 243 | &data_size, &mem_req); |
| 244 | msgType = m_errorMonitor->GetState(&msgString); |
| 245 | ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an error from mismatched types in vkGetObjectInfo"; |
| 246 | if (!strstr(msgString.c_str(),"does not match designated type")) { |
| 247 | FAIL() << "Error received was not event does not match designated type image"; |
| 248 | } |
| 249 | |
| 250 | } |
| 251 | |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 252 | int main(int argc, char **argv) { |
| 253 | int result; |
| 254 | |
| 255 | ::testing::InitGoogleTest(&argc, argv); |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 256 | VkTestFramework::InitArgs(&argc, argv); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 257 | |
| 258 | ::testing::AddGlobalTestEnvironment(new TestEnvironment); |
| 259 | |
| 260 | result = RUN_ALL_TESTS(); |
| 261 | |
Tony Barbour | 6918cd5 | 2015-04-09 12:58:51 -0600 | [diff] [blame] | 262 | VkTestFramework::Finish(); |
Tony Barbour | 300a608 | 2015-04-07 13:44:53 -0600 | [diff] [blame] | 263 | return result; |
| 264 | } |