• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015-2016 The Khronos Group Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Common validation fixtures for unit tests
16 
17 #ifndef LIBSPIRV_TEST_VALIDATE_FIXTURES_H_
18 #define LIBSPIRV_TEST_VALIDATE_FIXTURES_H_
19 
20 #include "unit_spirv.h"
21 #include "source/val/validation_state.h"
22 
23 namespace spvtest {
24 
25 template <typename T>
26 class ValidateBase : public ::testing::Test,
27                      public ::testing::WithParamInterface<T> {
28  public:
29   ValidateBase();
30 
31   virtual void TearDown();
32 
33   // Returns the a spv_const_binary struct
34   spv_const_binary get_const_binary();
35 
36   void CompileSuccessfully(std::string code,
37                            spv_target_env env = SPV_ENV_UNIVERSAL_1_0);
38 
39   // Overwrites the word at index 'index' with the given word.
40   // For testing purposes, it is often useful to be able to manipulate the
41   // assembled binary before running the validator on it.
42   // This function overwrites the word at the given index with a new word.
43   void OverwriteAssembledBinary(uint32_t index, uint32_t word);
44 
45   // Performs validation on the SPIR-V code and compares the result of the
46   // spvValidate function
47   spv_result_t ValidateInstructions(spv_target_env env = SPV_ENV_UNIVERSAL_1_0);
48 
49   // Performs validation. Returns the status and stores validation state into
50   // the vstate_ member.
51   spv_result_t ValidateAndRetrieveValidationState(
52       spv_target_env env = SPV_ENV_UNIVERSAL_1_0);
53 
54   std::string getDiagnosticString();
55   spv_position_t getErrorPosition();
56   spv_validator_options getValidatorOptions();
57 
58   spv_binary binary_;
59   spv_diagnostic diagnostic_;
60   spv_validator_options options_;
61   std::unique_ptr<libspirv::ValidationState_t> vstate_;
62 };
63 }
64 #endif
65