[3/3] Add a test for bug 104809

Submitted by Jason Ekstrand on Aug. 25, 2018, 11:42 p.m.

Details

Message ID 20180825234200.8017-3-jason.ekstrand@intel.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Jason Ekstrand Aug. 25, 2018, 11:42 p.m.
---
 Makefile.am                        |   3 +
 src/framework/test/t_dump.c        |   2 +-
 src/framework/test/t_result.c      |   6 +-
 src/tests/bug/104809.c             | 160 +++++++++++++++++++++++++++++
 src/tests/self/concurrent-output.c |   4 +-
 5 files changed, 169 insertions(+), 6 deletions(-)
 create mode 100644 src/tests/bug/104809.c

Patch hide | download patch | download mbox

diff --git a/Makefile.am b/Makefile.am
index a96da9d..dc24a99 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,6 +31,7 @@  CPPFLAGS = \
 
 common_CFLAGS = -Wall -O0 -g3 \
 	-Werror=format \
+	-Werror=format-security \
 	-Werror=incompatible-pointer-types \
 	-Werror=int-conversion \
 	$(libpng_CFLAGS) \
@@ -72,6 +73,7 @@  bin_crucible_SOURCES = \
 	src/framework/test/test_def.c \
 	src/qonos/qonos.c \
 	src/qonos/qonos_pipeline.c \
+	src/tests/bug/104809.c \
 	src/tests/example/basic.c \
 	src/tests/example/images.c \
 	src/tests/example/messages.c \
@@ -127,6 +129,7 @@  bin_crucible_SOURCES = \
 BUILT_SOURCES = \
 	src/qonos/qonos_pipeline-spirv.h \
 	src/util/simple_pipeline-spirv.h \
+	src/tests/bug/104809-spirv.h \
 	src/tests/func/4-vertex-buffers-spirv.h \
 	src/tests/func/depthstencil/basic-spirv.h \
 	src/tests/func/depthstencil/arrayed-clear-spirv.h \
diff --git a/src/framework/test/t_dump.c b/src/framework/test/t_dump.c
index 04f55c3..edfb3fa 100644
--- a/src/framework/test/t_dump.c
+++ b/src/framework/test/t_dump.c
@@ -71,7 +71,7 @@  t_dump_image_fv(cru_image_t *image, const char *format, va_list va)
         return;
 
     string_t filename = STRING_INIT;
-    string_appendf(&filename, t_name);
+    string_append_cstr(&filename, t_name);
     string_append_char(&filename, '.');
     string_vappendf(&filename, format, va);
 
diff --git a/src/framework/test/t_result.c b/src/framework/test/t_result.c
index 80ab731..209d6b2 100644
--- a/src/framework/test/t_result.c
+++ b/src/framework/test/t_result.c
@@ -78,7 +78,7 @@  __t_skipfv(const char *file, int line, const char *format, va_list va)
         string_vappendf(&s, format, va);
     }
 
-    logi(string_data(&s));
+    logi("%s", string_data(&s));
     string_finish(&s);
 
     __t_skip_silent();
@@ -127,7 +127,7 @@  __t_failfv(const char *file, int line, const char *format, va_list va)
         string_vappendf(&s, format, va);
     }
 
-    loge(string_data(&s));
+    loge("%s", string_data(&s));
     string_finish(&s);
 
     __t_fail_silent();
@@ -179,7 +179,7 @@  __t_assertfv(const char *file, int line, bool cond, const char *cond_string,
         string_t s = STRING_INIT;
         string_appendf(&s, "%s:%d: ", file, line);
         string_vappendf(&s, format, va);
-        loge(string_data(&s));
+        loge("%s", string_data(&s));
         string_finish(&s);
     }
 
diff --git a/src/tests/bug/104809.c b/src/tests/bug/104809.c
new file mode 100644
index 0000000..162b421
--- /dev/null
+++ b/src/tests/bug/104809.c
@@ -0,0 +1,160 @@ 
+// Copyright 2015 Intel Corporation
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice (including the next
+// paragraph) shall be included in all copies or substantial portions of the
+// Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+
+#include "tapi/t.h"
+#include "util/misc.h"
+
+/* This is a test for https://bugs.freedesktop.org/show_bug.cgi?id=104809
+ *
+ * At the root of the hang was the fact that we had a hole in our vertex
+ * element state array.  Because the Intel Vulkan driver compacts down the
+ * inputs to only those used by the shader, you need to have a location
+ * which is used by the shader but not provided by the vertex input state
+ * in order to trigger the hang.  This test provides a simple pipeline
+ * which does just that.
+ */
+
+#include "104809-spirv.h"
+
+static void
+test(void)
+{
+    VkShaderModule vs = qoCreateShaderModuleGLSL(t_device, VERTEX,
+        layout(location = 0) in vec4 a_position;
+        layout(location = 1) in vec4 a_junk;
+        layout(location = 2) in vec4 a_zero;
+        void main()
+        {
+            gl_Position = a_position + a_junk * a_zero;
+        }
+    );
+
+    VkShaderModule fs = qoCreateShaderModuleGLSL(t_device, FRAGMENT,
+        layout(location = 0) out vec4 f_color;
+        layout(set = 0, binding = 1) uniform sampler2D tex;
+
+        void main()
+        {
+            f_color = vec4(0, 1, 0, 1);
+        }
+    );
+
+    VkPipelineVertexInputStateCreateInfo vi_create_info = {
+        .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+        .vertexBindingDescriptionCount = 2,
+        .pVertexBindingDescriptions = (VkVertexInputBindingDescription[]) {
+            {
+                .binding = 0,
+                .stride = 16,
+                .inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
+            },
+            {
+                .binding = 1,
+                .stride = 0,
+                .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE,
+            },
+        },
+        .vertexAttributeDescriptionCount = 2,
+        .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[]) {
+            {
+                .location = 0,
+                .binding = 0,
+                .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+                .offset = 0,
+            },
+            {
+                .location = 2,
+                .binding = 1,
+                .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+                .offset = 0,
+            },
+        },
+    };
+
+    VkPipeline pipeline = qoCreateGraphicsPipeline(t_device, t_pipeline_cache,
+        &(QoExtraGraphicsPipelineCreateInfo) {
+            .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
+            .vertexShader = vs,
+            .fragmentShader = fs,
+            .pNext =
+        &(VkGraphicsPipelineCreateInfo) {
+            .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
+            .pVertexInputState = &vi_create_info,
+            .flags = 0,
+            .layout = qoCreatePipelineLayout(t_device, 0, NULL),
+            .renderPass = t_render_pass,
+            .subpass = 0,
+        }});
+
+    static const float vertex_data[] = {
+        // Triangle coordinates
+        -1.0, -1.0, 0.0, 1.0,
+         1.0, -1.0, 0.0, 1.0,
+        -1.0,  1.0, 0.0, 1.0,
+         1.0,  1.0, 0.0, 1.0,
+
+         // Zeros
+         0.0,  0.0, 0.0, 0.0,
+    };
+
+    VkBuffer vertex_buffer = qoCreateBuffer(t_device,
+        .size = sizeof(vertex_data),
+        .usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
+
+    VkDeviceMemory vertex_mem = qoAllocBufferMemory(t_device, vertex_buffer,
+        .properties = VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
+                      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
+
+    memcpy(qoMapMemory(t_device, vertex_mem, /*offset*/ 0,
+                       sizeof(vertex_data), /*flags*/ 0),
+           vertex_data,
+           sizeof(vertex_data));
+
+    qoBindBufferMemory(t_device, vertex_buffer, vertex_mem,
+                       /*offset*/ 0);
+
+    vkCmdBeginRenderPass(t_cmd_buffer,
+        &(VkRenderPassBeginInfo) {
+            .renderPass = t_render_pass,
+            .framebuffer = t_framebuffer,
+            .renderArea = { { 0, 0 }, { t_width, t_height } },
+            .clearValueCount = 1,
+            .pClearValues = (VkClearValue[]) {
+                { .color = { .float32 = { 1.0, 0.0, 0.0, 1.0 } } },
+            }
+        }, VK_SUBPASS_CONTENTS_INLINE);
+
+    vkCmdBindVertexBuffers(t_cmd_buffer, 0, 2,
+                           (VkBuffer[]) { vertex_buffer, vertex_buffer },
+                           (VkDeviceSize[]) { 0, 4 * 4 * sizeof(float) });
+    vkCmdBindPipeline(t_cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
+    vkCmdDraw(t_cmd_buffer, /*vertexCount*/ 4, /*instanceCount*/ 1,
+              /*firstVertex*/ 0, /*firstInstance*/ 0);
+    vkCmdEndRenderPass(t_cmd_buffer);
+    qoEndCommandBuffer(t_cmd_buffer);
+    qoQueueSubmit(t_queue, 1, &t_cmd_buffer, VK_NULL_HANDLE);
+}
+
+test_define {
+    .name = "bug.104809",
+    .start = test,
+    .image_filename = "32x32-green.ref.png",
+};
diff --git a/src/tests/self/concurrent-output.c b/src/tests/self/concurrent-output.c
index 002d4ed..4114af6 100644
--- a/src/tests/self/concurrent-output.c
+++ b/src/tests/self/concurrent-output.c
@@ -45,7 +45,7 @@  test_logi_a(void)
     char *a = mk_big_str('a');
 
     for (int i = 0; i < 1024; ++i) {
-        logi(a);
+        logi("%s", a);
     }
 }
 
@@ -61,7 +61,7 @@  test_logi_b(void)
     char *b = mk_big_str('b');
 
     for (int i = 0; i < 1024; ++i) {
-        logi(b);
+        logi("%s", b);
     }
 }