SPIRV-Tools/test/ValidationState.cpp
David Neto 273920c554 Handle capabilities larger than value 63
Use libspirv::CapabilitySet instead of a 64-bit mask.

Remove dead function spvOpcodeRequiresCapability and its tests.

The JSON grammar parser is simplified since it just writes the
list of capabilities as a braced list, and takes advantage of
the CapabilitySet intializer-list constructor.
2016-08-30 15:41:39 -04:00

103 lines
3.9 KiB
C++

// Copyright (c) 2015-2016 The Khronos Group Inc.
// Copyright (c) 2016 Google
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and/or associated documentation files (the
// "Materials"), to deal in the Materials without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Materials, and to
// permit persons to whom the Materials are furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Materials.
//
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
// https://www.khronos.org/registry/
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
// Unit tests for ValidationState_t.
#include "val/ValidationState.h"
#include <vector>
#include "gtest/gtest.h"
#include "spirv/1.1/spirv.h"
#include "capability_set.h"
#include "val/Construct.h"
#include "val/Function.h"
#include "validate.h"
namespace {
using libspirv::CapabilitySet;
using libspirv::ValidationState_t;
using std::vector;
// A test with a ValidationState_t member transparently.
class ValidationStateTest : public testing::Test {
public:
ValidationStateTest()
: context_(spvContextCreate(SPV_ENV_UNIVERSAL_1_0)),
state_(&diag_, context_) {}
protected:
spv_diagnostic diag_;
spv_context context_;
ValidationState_t state_;
};
// A test of ValidationState_t::HasAnyOf().
using ValidationState_HasAnyOfTest = ValidationStateTest;
TEST_F(ValidationState_HasAnyOfTest, EmptyMask) {
EXPECT_TRUE(state_.HasAnyOf({}));
state_.RegisterCapability(SpvCapabilityMatrix);
EXPECT_TRUE(state_.HasAnyOf({}));
state_.RegisterCapability(SpvCapabilityImageMipmap);
EXPECT_TRUE(state_.HasAnyOf({}));
state_.RegisterCapability(SpvCapabilityPipes);
EXPECT_TRUE(state_.HasAnyOf({}));
state_.RegisterCapability(SpvCapabilityStorageImageArrayDynamicIndexing);
EXPECT_TRUE(state_.HasAnyOf({}));
state_.RegisterCapability(SpvCapabilityClipDistance);
EXPECT_TRUE(state_.HasAnyOf({}));
state_.RegisterCapability(SpvCapabilityStorageImageWriteWithoutFormat);
EXPECT_TRUE(state_.HasAnyOf({}));
}
TEST_F(ValidationState_HasAnyOfTest, SingleCapMask) {
EXPECT_FALSE(state_.HasAnyOf({SpvCapabilityMatrix}));
EXPECT_FALSE(state_.HasAnyOf({SpvCapabilityImageMipmap}));
state_.RegisterCapability(SpvCapabilityMatrix);
EXPECT_TRUE(state_.HasAnyOf({SpvCapabilityMatrix}));
EXPECT_FALSE(state_.HasAnyOf({SpvCapabilityImageMipmap}));
state_.RegisterCapability(SpvCapabilityImageMipmap);
EXPECT_TRUE(state_.HasAnyOf({SpvCapabilityMatrix}));
EXPECT_TRUE(state_.HasAnyOf({SpvCapabilityImageMipmap}));
}
TEST_F(ValidationState_HasAnyOfTest, MultiCapMask) {
const auto set1 =
CapabilitySet{SpvCapabilitySampledRect, SpvCapabilityImageBuffer};
const auto set2 = CapabilitySet{SpvCapabilityStorageImageWriteWithoutFormat,
SpvCapabilityStorageImageReadWithoutFormat,
SpvCapabilityGeometryStreams};
EXPECT_FALSE(state_.HasAnyOf(set1));
EXPECT_FALSE(state_.HasAnyOf(set2));
state_.RegisterCapability(SpvCapabilityImageBuffer);
EXPECT_TRUE(state_.HasAnyOf(set1));
EXPECT_FALSE(state_.HasAnyOf(set2));
}
}