// Copyright (c) 2015-2016 The Khronos Group 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. // Common validation fixtures for unit tests #include "val_fixtures.h" #include #include #include #include "test_fixture.h" namespace spvtest { template ValidateBase::ValidateBase() : binary_(), diagnostic_() {} template spv_const_binary ValidateBase::get_const_binary() { return spv_const_binary(binary_); } template void ValidateBase::TearDown() { if (diagnostic_) { spvDiagnosticPrint(diagnostic_); } spvDiagnosticDestroy(diagnostic_); spvBinaryDestroy(binary_); } template void ValidateBase::CompileSuccessfully(std::string code, spv_target_env env) { spv_diagnostic diagnostic = nullptr; ASSERT_EQ(SPV_SUCCESS, spvTextToBinary(ScopedContext(env).context, code.c_str(), code.size(), &binary_, &diagnostic)) << "ERROR: " << diagnostic->error << "\nSPIR-V could not be compiled into binary:\n" << code; } template void ValidateBase::OverwriteAssembledBinary(uint32_t index, uint32_t word) { ASSERT_TRUE(index < binary_->wordCount) << "OverwriteAssembledBinary: The given index is larger than the binary " "word count."; binary_->code[index] = word; } template spv_result_t ValidateBase::ValidateInstructions(spv_target_env env) { return spvValidate(ScopedContext(env).context, get_const_binary(), &diagnostic_); } template std::string ValidateBase::getDiagnosticString() { return std::string(diagnostic_->error); } template spv_position_t ValidateBase::getErrorPosition() { return diagnostic_->position; } template class spvtest::ValidateBase; template class spvtest::ValidateBase; template class spvtest::ValidateBase; template class spvtest::ValidateBase>; template class spvtest::ValidateBase< std::tuple>>>; template class spvtest::ValidateBase< std::tuple, std::function>>>; template class spvtest::ValidateBase; }