tests:Add "--devsim" option
authorTobin Ehlis <tobine@google.com>
Wed, 15 Nov 2017 16:43:56 +0000 (09:43 -0700)
committerTobin Ehlis <tobine@google.com>
Fri, 17 Nov 2017 16:38:09 +0000 (09:38 -0700)
Add "--devsim" option to vk_layer_validation_tests. This will enable
the Device Simulation layer as the bottom layer on the stack.
It still requires the caller to set the VK_DEVSIM_FILENAME env var in
order to select the json profile that they want to test with.

When "--devsim" option is specified, the device_profile layer will not
be enabled by default when InitFramework() is called. Instead, any
tests that require the device_profile layer can call
EnableDeviceProfileLayer(). This function will cause the device profile
layer to replace the dev sim layer as the bottome layer on the stack.

tests/layer_validation_tests.cpp
tests/vkrenderframework.cpp
tests/vkrenderframework.h
tests/vktestframework.cpp
tests/vktestframework.h
tests/vktestframeworkandroid.cpp
tests/vktestframeworkandroid.h

index d0a5aee..b07905d 100644 (file)
@@ -448,7 +448,14 @@ class VkLayerTest : public VkRenderFramework {
         m_instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
         m_instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
         m_instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
-
+        if (VkTestFramework::m_devsim_layer) {
+            if (InstanceLayerSupported("VK_LAYER_LUNARG_device_simulation")) {
+                m_instance_layer_names.push_back("VK_LAYER_LUNARG_device_simulation");
+            } else {
+                VkTestFramework::m_devsim_layer = false;
+                printf("             Did not find VK_LAYER_LUNARG_device_simulation layer so it will not be enabled.\n");
+            }
+        }
         if (m_enableWSI) {
             m_instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
             m_device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
@@ -2807,12 +2814,7 @@ TEST_F(VkLayerTest, ExceedMemoryAllocationCount) {
     const int max_mems = 32;
     VkDeviceMemory mems[max_mems + 1];
 
-    if (InstanceLayerSupported("VK_LAYER_LUNARG_device_profile_api")) {
-        m_instance_layer_names.push_back("VK_LAYER_LUNARG_device_profile_api");
-    } else {
-        printf("             Did not find VK_LAYER_LUNARG_device_profile_api layer; skipped.\n");
-        return;
-    }
+    if (!EnableDeviceProfileLayer()) return;
 
     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
 
@@ -10246,9 +10248,7 @@ TEST_F(VkLayerTest, VALIDATION_ERROR_14a004dc) {
         "Test VALIDATION_ERROR_14a004dc: offset must be less than or equal to "
         "VkPhysicalDeviceLimits::maxVertexInputAttributeOffset");
 
-    if (InstanceLayerSupported("VK_LAYER_LUNARG_device_profile_api")) {
-        m_instance_layer_names.push_back("VK_LAYER_LUNARG_device_profile_api");
-    }
+    EnableDeviceProfileLayer();
 
     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
 
@@ -14285,6 +14285,8 @@ TEST_F(VkLayerTest, CreateImageViewBreaksParameterCompatibilityRequirements) {
 TEST_F(VkLayerTest, CreateImageViewFormatFeatureMismatch) {
     TEST_DESCRIPTION("Create view with a format that does not have the same features as the image format.");
 
+    if (!EnableDeviceProfileLayer()) return;
+
     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
     ASSERT_NO_FATAL_FAILURE(InitState());
 
@@ -17752,12 +17754,8 @@ TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
 TEST_F(VkLayerTest, CreateImageViewFormatMismatchUnrelated) {
     TEST_DESCRIPTION("Create an image with a color format, then try to create a depth view of it");
 
-    if (InstanceLayerSupported("VK_LAYER_LUNARG_device_profile_api")) {
-        m_instance_layer_names.push_back("VK_LAYER_LUNARG_device_profile_api");
-    } else {
-        printf("             Did not find VK_LAYER_LUNARG_device_profile_api layer; skipped.\n");
-        return;
-    }
+    if (!EnableDeviceProfileLayer()) return;
+
     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
     ASSERT_NO_FATAL_FAILURE(InitState());
 
@@ -17810,6 +17808,8 @@ TEST_F(VkLayerTest, CreateImageViewFormatMismatchUnrelated) {
 TEST_F(VkLayerTest, CreateImageViewNoMutableFormatBit) {
     TEST_DESCRIPTION("Create an image view with a different format, when the image does not have MUTABLE_FORMAT bit");
 
+    if (!EnableDeviceProfileLayer()) return;
+
     ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
     ASSERT_NO_FATAL_FAILURE(InitState());
 
index e3b34af..e860f3f 100644 (file)
@@ -89,6 +89,23 @@ bool VkRenderFramework::InstanceLayerSupported(const char *name, uint32_t spec,
     return false;
 };
 
+// Enable device profile as last layer on stack overriding devsim if there, or return if not available
+bool VkRenderFramework::EnableDeviceProfileLayer() {
+    if (InstanceLayerSupported("VK_LAYER_LUNARG_device_profile_api")) {
+        if (VkTestFramework::m_devsim_layer) {
+            assert(0 == strcmp(m_instance_layer_names.back(), "VK_LAYER_LUNARG_device_simulation"));
+            m_instance_layer_names.pop_back();
+            m_instance_layer_names.push_back("VK_LAYER_LUNARG_device_profile_api");
+        } else {
+            m_instance_layer_names.push_back("VK_LAYER_LUNARG_device_profile_api");
+        }
+    } else {
+        printf("             Did not find VK_LAYER_LUNARG_device_profile_api layer; skipped.\n");
+        return false;
+    }
+    return true;
+}
+
 // Return true if extension name is found and spec value is >= requested spec value
 bool VkRenderFramework::InstanceExtensionSupported(const char *ext_name, uint32_t spec) {
     uint32_t ext_count = 0;
@@ -134,7 +151,8 @@ bool VkRenderFramework::DeviceExtensionSupported(VkPhysicalDevice dev, const cha
 };
 
 void VkRenderFramework::InitFramework(PFN_vkDebugReportCallbackEXT dbgFunction, void *userData) {
-    if (InstanceLayerSupported("VK_LAYER_LUNARG_device_profile_api")) {
+    // Only enable device profile layer by default if devsim is not enabled
+    if (!VkTestFramework::m_devsim_layer && InstanceLayerSupported("VK_LAYER_LUNARG_device_profile_api")) {
         m_instance_layer_names.push_back("VK_LAYER_LUNARG_device_profile_api");
     }
 
index 03ffc8d..7221ca9 100644 (file)
@@ -82,6 +82,7 @@ class VkRenderFramework : public VkTestFramework {
     const VkRenderPassBeginInfo &renderPassBeginInfo() const { return m_renderPassBeginInfo; }
 
     bool InstanceLayerSupported(const char *name, uint32_t specVersion = 0, uint32_t implementationVersion = 0);
+    bool EnableDeviceProfileLayer();
     bool InstanceExtensionSupported(const char *name, uint32_t specVersion = 0);
     bool DeviceExtensionSupported(VkPhysicalDevice dev, const char *layer, const char *name, uint32_t specVersion = 0);
 
index 693aba0..9c120cb 100644 (file)
@@ -143,6 +143,7 @@ VkTestFramework::~VkTestFramework() {}
 bool VkTestFramework::m_canonicalize_spv = false;
 bool VkTestFramework::m_strip_spv = false;
 bool VkTestFramework::m_do_everything_spv = false;
+bool VkTestFramework::m_devsim_layer = false;
 int VkTestFramework::m_width = 0;
 int VkTestFramework::m_height = 0;
 
@@ -161,6 +162,8 @@ void VkTestFramework::InitArgs(int *argc, char *argv[]) {
             m_strip_spv = true;
         else if (optionMatch("--canonicalize-SPV", argv[i]))
             m_canonicalize_spv = true;
+        else if (optionMatch("--devsim", argv[i]))
+            m_devsim_layer = true;
         else if (optionMatch("--help", argv[i]) || optionMatch("-h", argv[i])) {
             printf("\nOther options:\n");
             printf(
index f2ed24b..d8e9b98 100644 (file)
@@ -72,6 +72,7 @@ class VkTestFramework : public ::testing::Test {
     static bool m_canonicalize_spv;
     static bool m_strip_spv;
     static bool m_do_everything_spv;
+    static bool m_devsim_layer;
 
     char **ReadFileData(const char *fileName);
     void FreeFileData(char **data);
index 56a8b5c..eef9218 100644 (file)
@@ -24,6 +24,9 @@
 VkTestFramework::VkTestFramework() {}
 VkTestFramework::~VkTestFramework() {}
 
+// Define static elements
+bool VkTestFramework::m_devsim_layer = false;
+
 VkFormat VkTestFramework::GetFormat(VkInstance instance, vk_testing::Device *device) {
     VkFormatProperties format_props;
     vkGetPhysicalDeviceFormatProperties(device->phy().handle(), VK_FORMAT_B8G8R8A8_UNORM, &format_props);
index f5668c6..7094050 100644 (file)
@@ -44,6 +44,7 @@ class VkTestFramework : public ::testing::Test {
 
     VkFormat GetFormat(VkInstance instance, vk_testing::Device *device);
     bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *pshader, std::vector<unsigned int> &spv);
+    static bool m_devsim_layer;
 };
 
 class TestEnvironment : public ::testing::Environment {