From 08d89bb7a550e4546ce891a63ef4b9b66fb10a18 Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 9 Sep 2015 10:58:02 -0400 Subject: [PATCH] Test assembly of OpSource using all language enums Adds a file to test assembly of instructions in the "Debug" section of the SPIR-V spec. --- CMakeLists.txt | 1 + test/TextToBinary.Debug.cpp | 83 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 test/TextToBinary.Debug.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ad21babb..813c57d60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -184,6 +184,7 @@ if (NOT ${SPIRV_SKIP_EXECUTABLES}) ${CMAKE_CURRENT_SOURCE_DIR}/test/TextLiteral.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/TextStartsNewInst.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Debug.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/TextToBinary.Miscellaneous.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/TextWordGet.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/Validate.cpp diff --git a/test/TextToBinary.Debug.cpp b/test/TextToBinary.Debug.cpp new file mode 100644 index 000000000..688c966fd --- /dev/null +++ b/test/TextToBinary.Debug.cpp @@ -0,0 +1,83 @@ +// Copyright (c) 2015 The Khronos Group Inc. +// +// 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. + +// Assembler tests for instructions in the "Debug" section of the +// SPIR-V spec. + +#include "UnitSPIRV.h" + +#include + +#include "gmock/gmock.h" +#include "TestFixture.h" + +namespace { + +using spvtest::MakeInstruction; +using ::testing::Eq; + +// A single test case for OpSource +struct LanguageCase { + const char* language_name; + const spv::SourceLanguage language_value; + const uint32_t version; +}; + +// clang-format off +// The list of OpSource cases to use. +const LanguageCase kLanguageCases[] = { +#define CASE(NAME, VERSION) \ + { #NAME, spv::SourceLanguage##NAME, VERSION } + CASE(Unknown, 0), + CASE(Unknown, 999), + CASE(ESSL, 310), + CASE(GLSL, 450), + CASE(OpenCL, 210), +#undef CASE +}; +// clang-format on + +using OpSourceTest = + test_fixture::TextToBinaryTestBase<::testing::TestWithParam>; + +TEST_P(OpSourceTest, AnyLanguage) { + std::string input = std::string("OpSource ") + GetParam().language_name + + " " + std::to_string(GetParam().version); + EXPECT_THAT(CompiledInstructions(input), + Eq(MakeInstruction(spv::OpSource, {GetParam().language_value, + GetParam().version}))); +} + +INSTANTIATE_TEST_CASE_P(TextToBinaryTestDebug, OpSourceTest, + ::testing::ValuesIn(kLanguageCases)); + +// TODO(dneto): OpSourceExtension +// TODO(dneto): OpName +// TODO(dneto): OpMemberName +// TODO(dneto): OpString +// TODO(dneto): OpLine. OpLine is significantly different after Rev31. + +} // anonymous namespace