aboutsummaryrefslogtreecommitdiff
path: root/test/val/val_state_test.cpp
diff options
context:
space:
mode:
authorDavid Neto <dneto@google.com>2016-11-30 13:48:32 -0500
committerDavid Neto <dneto@google.com>2016-11-30 13:58:40 -0500
commit160da1d4e3a5c5b23facfa3277154a44b73cab59 (patch)
tree999983b1cfece234b7ed8c504bcbf086605183cf /test/val/val_state_test.cpp
parent1401a61b1e7d1516578171a94edbac33858fb1a2 (diff)
parentbd5b0bfca1bf067563c9e03a7c30c3590189b5c0 (diff)
downloadspirv-tools-160da1d4e3a5c5b23facfa3277154a44b73cab59.tar.gz
Merge remote-tracking branch 'aosp/upstream-master' into update-shadercHEADmastermain
Includes the following: bd5b0bf Checks that result IDs are within the ID bound specified in the SPIR-V header f72189c Validation for OpSampledImage instruction. 6fa6a3f Adding validation for OpSpecConstantComposite. 8c414eb Adding validation code for OpTypeStruct. 5c19de2 Skip building example executable when asked c935253 Make friendly number-based names for OpConstant 4f750c0 Extract EmitNumericLiteral from disassembler d062006 Adding validation code for more data rules. 38036a7 Rename validation source files to comply with Google style guide. 2881fe9 Rename validation tests to comply with Google style guide. 6c899a5 Adding validation for vector data rule. 4f57e14 Renaming test files to comply with Google style guide. bf190ec Remove source/instruction.cpp b371439 enum_set: Fix bool performance warning. Test: checkbuild.py on Linux x86; unit tests on Windows Change-Id: I96b8f8d6156f2ee5a5dbf070ea9b5e67ccd5e445
Diffstat (limited to 'test/val/val_state_test.cpp')
-rw-r--r--test/val/val_state_test.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/test/val/val_state_test.cpp b/test/val/val_state_test.cpp
new file mode 100644
index 00000000..2e6dafbc
--- /dev/null
+++ b/test/val/val_state_test.cpp
@@ -0,0 +1,87 @@
+// Copyright (c) 2015-2016 The Khronos Group Inc.
+// Copyright (c) 2016 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Unit tests for ValidationState_t.
+
+#include <vector>
+
+#include "gtest/gtest.h"
+#include "spirv/1.1/spirv.h"
+
+#include "enum_set.h"
+#include "val/construct.h"
+#include "val/function.h"
+#include "val/validation_state.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_(context_) {}
+
+ protected:
+ 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));
+}
+}