blob: 0aaa45bedd7137ff20eeb05e094074a9cc60750c [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,
9 VkBaseObject 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(
45 VK_DBG_MSG_TYPE msgType,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060046 VkValidationLevel validationLevel,
47 VkBaseObject 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() {
69
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060070 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour30486ea2015-04-07 13:44:53 -060071 this->app_info.pNext = NULL;
72 this->app_info.pAppName = "layer_tests";
73 this->app_info.appVersion = 1;
74 this->app_info.pEngineName = "unittest";
75 this->app_info.engineVersion = 1;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060076 this->app_info.apiVersion = VK_API_VERSION;
Tony Barbour30486ea2015-04-07 13:44:53 -060077
78 InitFramework();
79 m_errorMonitor = new ErrorMonitor(inst);
80 }
81
82 virtual void TearDown() {
83 // Clean up resources before we reset
Tony Barbour30486ea2015-04-07 13:44:53 -060084 ShutdownFramework();
Tony Barbour8508b8e2015-04-09 10:48:04 -060085 delete m_errorMonitor;
Tony Barbour30486ea2015-04-07 13:44:53 -060086 }
87};
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060088VkResult VkLayerTest::BeginCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -060089{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060090 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -060091
92 result = cmdBuffer.BeginCommandBuffer();
93
94 /*
95 * For render test all drawing happens in a single render pass
96 * on a single command buffer.
97 */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060098 if (VK_SUCCESS == result) {
Tony Barbour30486ea2015-04-07 13:44:53 -060099 cmdBuffer.BeginRenderPass(renderPass(), framebuffer());
100 }
101
102 return result;
103}
104
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600105VkResult VkLayerTest::EndCommandBuffer(VkCommandBufferObj &cmdBuffer)
Tony Barbour30486ea2015-04-07 13:44:53 -0600106{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600107 VkResult result;
Tony Barbour30486ea2015-04-07 13:44:53 -0600108
109 cmdBuffer.EndRenderPass(renderPass());
110
111 result = cmdBuffer.EndCommandBuffer();
112
113 return result;
114}
115
Tony Barbour8508b8e2015-04-09 10:48:04 -0600116TEST_F(VkLayerTest, SubmitSignaledFence)
Tony Barbour30486ea2015-04-07 13:44:53 -0600117{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600118 vk_testing::Fence testFence;
119 VK_DBG_MSG_TYPE msgType;
Tony Barbour30486ea2015-04-07 13:44:53 -0600120 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600121
122 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600123 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
124 fenceInfo.pNext = NULL;
125 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour30486ea2015-04-07 13:44:53 -0600126
127 // Verifiy that the appropriate layer is loaded
128
129 ASSERT_NO_FATAL_FAILURE(InitState());
130 ASSERT_NO_FATAL_FAILURE(InitViewport());
131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
132
Tony Barbour01999182015-04-09 12:58:51 -0600133 VkCommandBufferObj cmdBuffer(m_device);
Tony Barbour30486ea2015-04-07 13:44:53 -0600134 cmdBuffer.AddRenderTarget(m_renderTargets[0]);
135
Tony Barbour8508b8e2015-04-09 10:48:04 -0600136 BeginCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600137 cmdBuffer.ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600138 EndCommandBuffer(cmdBuffer);
Tony Barbour30486ea2015-04-07 13:44:53 -0600139
140 testFence.init(*m_device, fenceInfo);
141 m_errorMonitor->ClearState();
Tony Barbour8508b8e2015-04-09 10:48:04 -0600142 cmdBuffer.QueueCommandBuffer(testFence.obj());
Tony Barbour30486ea2015-04-07 13:44:53 -0600143 msgType = m_errorMonitor->GetState(&msgString);
Tony Barbour8508b8e2015-04-09 10:48:04 -0600144 ASSERT_EQ(msgType, VK_DBG_MSG_ERROR) << "Did not receive an err from using a fence in SIGNALED state in call to vkQueueSubmit";
145 if (!strstr(msgString.c_str(),"submitted in SIGNALED state. Fences must be reset before being submitted")) {
Tony Barbour9c238c42015-04-09 16:00:51 -0600146 FAIL() << "Error received was not VkQueueSubmit with fence in SIGNALED_STATE";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600147 }
148
149}
150
151TEST_F(VkLayerTest, ResetUnsignaledFence)
152{
153 vk_testing::Fence testFence;
154 VK_DBG_MSG_TYPE msgType;
155 std::string msgString;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600156 VkFenceCreateInfo fenceInfo = {};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600157 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
158 fenceInfo.pNext = NULL;
159
160 // Verifiy that the appropriate layer is loaded
161
162 ASSERT_NO_FATAL_FAILURE(InitState());
163 testFence.init(*m_device, fenceInfo);
164 m_errorMonitor->ClearState();
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600165 VkFence fences[1] = {testFence.obj()};
Tony Barbour8508b8e2015-04-09 10:48:04 -0600166 vkResetFences(m_device->device(), 1, fences);
167 msgType = m_errorMonitor->GetState(&msgString);
168 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 -0600169 if (!strstr(msgString.c_str(),"submitted to VkResetFences in UNSIGNALED STATE")) {
Tony Barbour9c238c42015-04-09 16:00:51 -0600170 FAIL() << "Error received was not VkResetFences with fence in UNSIGNALED_STATE";
Tony Barbour8508b8e2015-04-09 10:48:04 -0600171 }
Tony Barbour30486ea2015-04-07 13:44:53 -0600172
173}
174
175int main(int argc, char **argv) {
176 int result;
177
178 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour01999182015-04-09 12:58:51 -0600179 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour30486ea2015-04-07 13:44:53 -0600180
181 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
182
183 result = RUN_ALL_TESTS();
184
Tony Barbour01999182015-04-09 12:58:51 -0600185 VkTestFramework::Finish();
Tony Barbour30486ea2015-04-07 13:44:53 -0600186 return result;
187}