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