• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * Copyright (C) 2020 Matthew Waters <matthew@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <gst/gst.h>
26 #include <gst/check/gstcheck.h>
27 #include <gst/vulkan/vulkan.h>
28 
GST_START_TEST(test_instance_new)29 GST_START_TEST (test_instance_new)
30 {
31   GstVulkanInstance *instance;
32 
33   instance = gst_vulkan_instance_new ();
34   fail_unless (instance != NULL);
35   gst_object_unref (instance);
36 }
37 
38 GST_END_TEST;
39 
GST_START_TEST(test_instance_open)40 GST_START_TEST (test_instance_open)
41 {
42   GstVulkanInstance *instance;
43 
44   instance = gst_vulkan_instance_new ();
45   fail_unless (instance != NULL);
46   fail_unless (gst_vulkan_instance_open (instance, NULL));
47   gst_object_unref (instance);
48 }
49 
50 GST_END_TEST;
51 
GST_START_TEST(test_instance_version_before_open)52 GST_START_TEST (test_instance_version_before_open)
53 {
54   GstVulkanInstance *instance;
55   guint major, minor, patch;
56 
57   instance = gst_vulkan_instance_new ();
58   fail_unless (instance != NULL);
59   gst_vulkan_instance_get_version (instance, &major, &minor, &patch);
60   gst_object_unref (instance);
61 }
62 
63 GST_END_TEST;
64 
GST_START_TEST(test_instance_default_max_version)65 GST_START_TEST (test_instance_default_max_version)
66 {
67   GstVulkanInstance *instance;
68   guint major, minor, patch;
69 
70   instance = gst_vulkan_instance_new ();
71   fail_unless (instance != NULL);
72   gst_vulkan_instance_get_version (instance, &major, &minor, &patch);
73   fail_unless (gst_vulkan_instance_open (instance, NULL));
74   fail_unless (gst_vulkan_instance_check_version (instance, 1, 0, 0));
75   fail_unless (gst_vulkan_instance_check_version (instance, major, minor,
76           patch));
77   fail_unless (!gst_vulkan_instance_check_version (instance, major, minor,
78           patch + 1));
79   fail_unless (!gst_vulkan_instance_check_version (instance, major, minor + 1,
80           patch));
81   gst_object_unref (instance);
82 }
83 
84 GST_END_TEST;
85 
GST_START_TEST(test_instance_request_version)86 GST_START_TEST (test_instance_request_version)
87 {
88   GstVulkanInstance *instance;
89   guint major, minor;
90 
91   instance = gst_vulkan_instance_new ();
92   fail_unless (instance != NULL);
93   gst_vulkan_instance_get_version (instance, &major, &minor, NULL);
94 
95   if (major > 1 || minor > 0) {
96     g_object_set (instance, "requested-api-major", 1, "requested_api_minor", 0,
97         NULL);
98     fail_unless (gst_vulkan_instance_open (instance, NULL));
99     fail_unless (gst_vulkan_instance_check_version (instance, 1, 0, 0));
100     fail_unless (!gst_vulkan_instance_check_version (instance, major, minor,
101             0));
102     fail_unless (!gst_vulkan_instance_check_version (instance, major, minor + 1,
103             0));
104   }
105   gst_object_unref (instance);
106 }
107 
108 GST_END_TEST;
109 
GST_START_TEST(test_instance_enable_extension)110 GST_START_TEST (test_instance_enable_extension)
111 {
112   GstVulkanInstance *instance;
113   /* test with a very common extension */
114   const gchar *test_ext_name = VK_KHR_SURFACE_EXTENSION_NAME;
115 
116   instance = gst_vulkan_instance_new ();
117   fail_unless (instance != NULL);
118   fail_unless (gst_vulkan_instance_fill_info (instance, NULL));
119 
120   /* only run the test if the extension is available. otherwise, skip. */
121   if (gst_vulkan_instance_get_extension_info (instance, test_ext_name, NULL)) {
122     /* ensure it has been disabled */
123     if (gst_vulkan_instance_is_extension_enabled (instance, test_ext_name))
124       gst_vulkan_instance_disable_extension (instance, test_ext_name);
125 
126     fail_unless (gst_vulkan_instance_enable_extension (instance,
127             test_ext_name));
128     fail_unless (gst_vulkan_instance_is_extension_enabled (instance,
129             test_ext_name));
130     fail_unless (gst_vulkan_instance_disable_extension (instance,
131             test_ext_name));
132     fail_unless (!gst_vulkan_instance_is_extension_enabled (instance,
133             test_ext_name));
134 
135     fail_unless (gst_vulkan_instance_enable_extension (instance,
136             test_ext_name));
137     fail_unless (gst_vulkan_instance_open (instance, NULL));
138     fail_unless (gst_vulkan_instance_is_extension_enabled (instance,
139             test_ext_name));
140   }
141 
142   gst_object_unref (instance);
143 }
144 
145 GST_END_TEST;
146 
147 static Suite *
vkinstance_suite(void)148 vkinstance_suite (void)
149 {
150   Suite *s = suite_create ("vkinstance");
151   TCase *tc_basic = tcase_create ("general");
152   GstVulkanInstance *instance;
153   gboolean have_instance;
154 
155   suite_add_tcase (s, tc_basic);
156 
157   tcase_add_test (tc_basic, test_instance_new);
158   tcase_add_test (tc_basic, test_instance_version_before_open);
159 
160   /* FIXME: CI doesn't have a software vulkan renderer (and none exists currently) */
161   instance = gst_vulkan_instance_new ();
162   have_instance = gst_vulkan_instance_open (instance, NULL);
163   gst_object_unref (instance);
164   if (have_instance) {
165     tcase_add_test (tc_basic, test_instance_open);
166     tcase_add_test (tc_basic, test_instance_default_max_version);
167     tcase_add_test (tc_basic, test_instance_request_version);
168     tcase_add_test (tc_basic, test_instance_enable_extension);
169   }
170 
171   return s;
172 }
173 
174 GST_CHECK_MAIN (vkinstance);
175