/ scripts / test_check_spec_links_api_specific.py
test_check_spec_links_api_specific.py
  1  #!/usr/bin/python3
  2  #
  3  # Copyright (c) 2018-2019 Collabora, Ltd.
  4  #
  5  # Licensed under the Apache License, Version 2.0 (the "License");
  6  # you may not use this file except in compliance with the License.
  7  # You may obtain a copy of the License at
  8  #
  9  #     http://www.apache.org/licenses/LICENSE-2.0
 10  #
 11  # Unless required by applicable law or agreed to in writing, software
 12  # distributed under the License is distributed on an "AS IS" BASIS,
 13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  # See the License for the specific language governing permissions and
 15  # limitations under the License.
 16  #
 17  # Author(s):    Ryan Pavlik <ryan.pavlik@collabora.com>
 18  #
 19  # Purpose:      This file contains tests for check_spec_links.py
 20  #               that depend on the API being used.
 21  
 22  import pytest
 23  
 24  from check_spec_links import MacroChecker, MessageId, makeMacroChecker
 25  from spec_tools.console_printer import ConsolePrinter
 26  from spec_tools.macro_checker_file import shouldEntityBeText
 27  from test_check_spec_links import (CheckerWrapper, allMessages,
 28                                     loneMsgReplacement, message, msgReplacement)
 29  
 30  
 31  @pytest.fixture
 32  def ckr(capsys):
 33      """Fixture - add an arg named ckr to your test function to automatically get one passed to you."""
 34      return CheckerWrapper(capsys)
 35  
 36  
 37  def test_vulkan_refpage_mismatch(ckr):
 38      """Vulkan-specific tests of the REFPAGE_MISMATCH message."""
 39      ckr.enabled([MessageId.REFPAGE_MISMATCH])
 40      # Should error: this is actually a mismatch in Vulkan
 41      assert(ckr.check(
 42          """[open,refpage='VkQueueFlags']
 43          --
 44          include::../api/enums/VkQueueFlagBits.txt[]""").numDiagnostics() == 1)
 45      assert(ckr.check(
 46          """[open,refpage='VkQueueFlags']
 47          --
 48          include::../validity/enums/VkQueueFlagBits.txt[]""").numDiagnostics() == 1)
 49  
 50      # Should not error: this is just an alias
 51      assert(ckr.check(
 52          """[open,refpage='vkUpdateDescriptorSetWithTemplate']
 53          --
 54          include::../api/protos/vkUpdateDescriptorSetWithTemplateKHR.txt[]""").numDiagnostics() == 0)
 55  
 56  
 57  def test_vulkan_refpage_missing(ckr):
 58      """Vulkan-specific tests of the REFPAGE_MISSING message."""
 59      ckr.enabled([MessageId.REFPAGE_MISSING])
 60  
 61      # Should error: flags are expected to have their own ref page.
 62      assert(ckr.check(
 63          "include::../api/flags/VkQueueFlags.txt[]").numDiagnostics() == 1)
 64  
 65  
 66  def test_vulkan_refpage_block(ckr):
 67      """Vulkan-specific tests of the REFPAGE_BLOCK message."""
 68      ckr.enabled([MessageId.REFPAGE_BLOCK])
 69  
 70      # Should have no errors: Non-refpage usage of '--' is acceptable
 71      assert(not ckr.check(
 72          """--
 73          bla
 74          --""").messages)
 75  
 76      # Should have 1 error:
 77      #  - line after tag isn't '--'
 78      result = ckr.check(
 79          """--
 80          [open,]
 81          bla
 82          --""")
 83      assert(result.numDiagnostics() == 1)
 84      # Internally, it's as if the following were the spec source, after putting in the "fake" lines
 85      # (each of the added lines comes from one message):
 86      #
 87      # --
 88      # [open,]
 89      # --
 90      # bla
 91      # --
 92      assert("but did not find, a line containing only -- following a reference page tag" in message(result))
 93  
 94  
 95  def test_vulkan_legacy(ckr):
 96      """Test the LEGACY message which is Vulkan-only."""
 97      ckr.enabled([MessageId.LEGACY])
 98      # Should complain about LEGACY
 99      assert(ckr.check('sname:VkDeviceMemory').numDiagnostics() == 1)
100  
101  
102  def test_vulkan_alias(ckr):
103      """Tests of the aliasing data structure, dependent on Vulkan-specific registry."""
104      entity_db = ckr.ckr.entity_db
105  
106      assert(entity_db.areAliases(
107          'VkCommandPoolTrimFlagsKHR', 'VkCommandPoolTrimFlags'))
108      # Try one reversed-order, though the assert in that method should fire if this is wrong.
109      assert(entity_db.areAliases(
110          'VkCommandPoolTrimFlags', 'VkCommandPoolTrimFlagsKHR'))
111  
112      assert(entity_db.areAliases(
113          'VkDescriptorUpdateTemplateKHR', 'VkDescriptorUpdateTemplate'))
114      assert(entity_db.areAliases('VkDescriptorUpdateTemplateTypeKHR',
115                                  'VkDescriptorUpdateTemplateType'))
116      assert(entity_db.areAliases('VkQueueFamilyProperties2KHR',
117                                  'VkQueueFamilyProperties2'))
118      assert(entity_db.areAliases('VK_COLORSPACE_SRGB_NONLINEAR_KHR',
119                                  'VK_COLOR_SPACE_SRGB_NONLINEAR_KHR'))
120      assert(entity_db.areAliases('vkEnumeratePhysicalDeviceGroupsKHR',
121                                  'vkEnumeratePhysicalDeviceGroups'))
122      assert(entity_db.areAliases(
123          'vkCmdDrawIndirectCountAMD', 'vkCmdDrawIndirectCountKHR'))
124      assert(entity_db.areAliases('VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT',
125                                  'VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT'))
126  
127      assert(entity_db.areAliases('VK_LUID_SIZE_KHR', 'VK_LUID_SIZE'))