test/vulkan: add simple memory test
authorMatthew Waters <matthew@centricular.com>
Mon, 20 May 2019 03:54:56 +0000 (13:54 +1000)
committerMatthew Waters <matthew@centricular.com>
Tue, 4 Jun 2019 09:03:44 +0000 (09:03 +0000)
tests/check/libs/vkmemory.c [new file with mode: 0644]
tests/check/meson.build

diff --git a/tests/check/libs/vkmemory.c b/tests/check/libs/vkmemory.c
new file mode 100644 (file)
index 0000000..f019cb1
--- /dev/null
@@ -0,0 +1,104 @@
+/* GStreamer
+ *
+ * Copyright (C) 2019 Jan Schmidt <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <gst/check/gstcheck.h>
+#include <gst/vulkan/vulkan.h>
+
+static GstVulkanInstance *instance;
+static GstVulkanDevice *device;
+
+static void
+setup (void)
+{
+  instance = gst_vulkan_instance_new ();
+  fail_unless (gst_vulkan_instance_open (instance, NULL));
+  device = gst_vulkan_device_new (instance);
+  fail_unless (gst_vulkan_device_open (device, NULL));
+}
+
+static void
+teardown (void)
+{
+  gst_object_unref (instance);
+  gst_object_unref (device);
+}
+
+static void
+check_size (GstMemory * mem, gsize at_least)
+{
+  gsize size, maxsize, offset;
+
+  size = gst_memory_get_sizes (mem, &offset, &maxsize);
+  fail_unless (size <= maxsize);
+  fail_unless (size >= at_least);
+}
+
+GST_START_TEST (test_buffer_mem_allocate)
+{
+  VkBufferUsageFlags usage;
+  GstVulkanBufferMemory *vk_mem;
+  gsize orig_size = 1024, size, offset;
+  GstMemory *mem;
+
+  usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
+  mem =
+      gst_vulkan_buffer_memory_alloc (device, VK_FORMAT_R8_UNORM, orig_size,
+      usage, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
+  fail_unless (gst_is_vulkan_buffer_memory (mem));
+  vk_mem = (GstVulkanBufferMemory *) mem;
+
+  fail_unless (vk_mem->device == device);
+  fail_unless (vk_mem->usage == usage);
+  fail_unless (vk_mem->vk_mem != NULL);
+
+  size = gst_memory_get_sizes (mem, &offset, NULL);
+  fail_unless (offset == 0);
+  check_size (mem, orig_size);
+  fail_unless (vk_mem->requirements.size >= size);
+
+  size = gst_memory_get_sizes ((GstMemory *) vk_mem->vk_mem, &offset, NULL);
+  fail_unless (offset == 0);
+  check_size ((GstMemory *) vk_mem->vk_mem, orig_size);
+
+  gst_memory_unref (mem);
+}
+
+GST_END_TEST;
+
+static Suite *
+insert_bin_suite (void)
+{
+  Suite *s = suite_create ("vkmemory");
+  TCase *tc_basic = tcase_create ("general");
+
+  suite_add_tcase (s, tc_basic);
+  tcase_add_checked_fixture (tc_basic, setup, teardown);
+  tcase_add_test (tc_basic, test_buffer_mem_allocate);
+
+  return s;
+}
+
+
+GST_CHECK_MAIN (insert_bin);
index 5eb401d..651d3f5 100644 (file)
@@ -61,6 +61,7 @@ base_tests = [
   [['libs/player.c'], not enable_gst_player_tests, [gstplayer_dep]],
   [['libs/vc1parser.c'], false, [gstcodecparsers_dep]],
   [['libs/vp8parser.c'], false, [gstcodecparsers_dep]],
+  [['libs/vkmemory.c'], not gstvulkan_dep.found(), [gstvulkan_dep]],
 ]
 
 # FIXME: unistd dependency, unstable or not tested yet on windows