2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-09-09 14:58:02 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// 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
|
2015-09-09 14:58:02 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-09-09 14:58:02 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// 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.
|
2015-09-09 14:58:02 +00:00
|
|
|
|
|
|
|
// Assembler tests for instructions in the "Debug" section of the
|
|
|
|
// SPIR-V spec.
|
|
|
|
|
|
|
|
#include <string>
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <vector>
|
2015-09-09 14:58:02 +00:00
|
|
|
|
2016-05-11 14:34:27 +00:00
|
|
|
#include "gmock/gmock.h"
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "test/test_fixture.h"
|
|
|
|
#include "test/unit_spirv.h"
|
2015-09-09 14:58:02 +00:00
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
namespace spvtools {
|
2015-09-09 14:58:02 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using spvtest::MakeInstruction;
|
2015-09-09 22:10:01 +00:00
|
|
|
using spvtest::MakeVector;
|
2015-09-24 21:11:15 +00:00
|
|
|
using spvtest::TextToBinaryTest;
|
2015-09-09 14:58:02 +00:00
|
|
|
using ::testing::Eq;
|
|
|
|
|
2015-09-09 22:10:01 +00:00
|
|
|
// Test OpSource
|
|
|
|
|
2015-09-09 14:58:02 +00:00
|
|
|
// A single test case for OpSource
|
|
|
|
struct LanguageCase {
|
2015-09-18 15:50:54 +00:00
|
|
|
uint32_t get_language_value() const {
|
|
|
|
return static_cast<uint32_t>(language_value);
|
|
|
|
}
|
2015-09-18 16:08:36 +00:00
|
|
|
const char* language_name;
|
2015-10-28 17:40:52 +00:00
|
|
|
SpvSourceLanguage language_value;
|
2015-09-18 15:50:54 +00:00
|
|
|
uint32_t version;
|
2015-09-09 14:58:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
// The list of OpSource cases to use.
|
|
|
|
const LanguageCase kLanguageCases[] = {
|
|
|
|
#define CASE(NAME, VERSION) \
|
2015-10-28 17:40:52 +00:00
|
|
|
{ #NAME, SpvSourceLanguage##NAME, VERSION }
|
2015-09-09 14:58:02 +00:00
|
|
|
CASE(Unknown, 0),
|
|
|
|
CASE(Unknown, 999),
|
|
|
|
CASE(ESSL, 310),
|
|
|
|
CASE(GLSL, 450),
|
2015-11-11 17:32:21 +00:00
|
|
|
CASE(OpenCL_C, 120),
|
|
|
|
CASE(OpenCL_C, 200),
|
|
|
|
CASE(OpenCL_C, 210),
|
|
|
|
CASE(OpenCL_CPP, 210),
|
2017-04-06 15:04:09 +00:00
|
|
|
CASE(HLSL, 5),
|
|
|
|
CASE(HLSL, 6),
|
2015-09-09 14:58:02 +00:00
|
|
|
#undef CASE
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
using OpSourceTest =
|
2015-09-21 15:36:44 +00:00
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<LanguageCase>>;
|
2015-09-09 14:58:02 +00:00
|
|
|
|
|
|
|
TEST_P(OpSourceTest, AnyLanguage) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = std::string("OpSource ") +
|
|
|
|
GetParam().language_name + " " +
|
|
|
|
std::to_string(GetParam().version);
|
2015-11-02 14:41:20 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
|
|
|
Eq(MakeInstruction(SpvOpSource, {GetParam().get_language_value(),
|
|
|
|
GetParam().version})));
|
2015-09-09 14:58:02 +00:00
|
|
|
}
|
|
|
|
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryTestDebug, OpSourceTest,
|
|
|
|
::testing::ValuesIn(kLanguageCases));
|
2015-09-09 14:58:02 +00:00
|
|
|
|
2015-10-09 15:06:10 +00:00
|
|
|
TEST_F(OpSourceTest, WrongLanguage) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpSource xxyyzz 12345"),
|
|
|
|
Eq("Invalid source language 'xxyyzz'."));
|
|
|
|
}
|
|
|
|
|
2015-09-28 14:56:16 +00:00
|
|
|
TEST_F(TextToBinaryTest, OpSourceAcceptsOptionalFileId) {
|
|
|
|
// In the grammar, the file id is an OperandOptionalId.
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "OpSource GLSL 450 %file_id";
|
2015-09-28 14:56:16 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpSource, {SpvSourceLanguageGLSL, 450, 1})));
|
2016-03-18 18:13:16 +00:00
|
|
|
}
|
2015-09-28 14:56:16 +00:00
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, OpSourceAcceptsOptionalSourceText) {
|
|
|
|
std::string fake_source = "To be or not to be";
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input =
|
|
|
|
"OpSource GLSL 450 %file_id \"" + fake_source + "\"";
|
2015-11-02 14:41:20 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
|
|
|
Eq(MakeInstruction(SpvOpSource, {SpvSourceLanguageGLSL, 450, 1},
|
|
|
|
MakeVector(fake_source))));
|
2016-03-18 18:13:16 +00:00
|
|
|
}
|
2015-09-28 14:56:16 +00:00
|
|
|
|
2015-09-24 21:11:15 +00:00
|
|
|
// Test OpSourceContinued
|
|
|
|
|
|
|
|
using OpSourceContinuedTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<const char*>>;
|
|
|
|
|
|
|
|
TEST_P(OpSourceContinuedTest, AnyExtension) {
|
|
|
|
// TODO(dneto): utf-8, quoting, escaping
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input =
|
|
|
|
std::string("OpSourceContinued \"") + GetParam() + "\"";
|
2015-09-24 21:11:15 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpSourceContinued, MakeVector(GetParam()))));
|
2015-09-24 21:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dneto): utf-8, quoting, escaping
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryTestDebug, OpSourceContinuedTest,
|
|
|
|
::testing::ValuesIn(std::vector<const char*>{
|
|
|
|
"", "foo bar this and that"}));
|
2015-09-24 21:11:15 +00:00
|
|
|
|
2015-09-09 22:10:01 +00:00
|
|
|
// Test OpSourceExtension
|
|
|
|
|
|
|
|
using OpSourceExtensionTest =
|
2015-09-21 15:36:44 +00:00
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<const char*>>;
|
2015-09-09 22:10:01 +00:00
|
|
|
|
|
|
|
TEST_P(OpSourceExtensionTest, AnyExtension) {
|
|
|
|
// TODO(dneto): utf-8, quoting, escaping
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input =
|
|
|
|
std::string("OpSourceExtension \"") + GetParam() + "\"";
|
2015-09-24 21:11:15 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpSourceExtension, MakeVector(GetParam()))));
|
2015-09-09 22:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dneto): utf-8, quoting, escaping
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryTestDebug, OpSourceExtensionTest,
|
|
|
|
::testing::ValuesIn(std::vector<const char*>{
|
|
|
|
"", "foo bar this and that"}));
|
2015-09-09 22:10:01 +00:00
|
|
|
|
2015-09-24 21:11:15 +00:00
|
|
|
TEST_F(TextToBinaryTest, OpLine) {
|
|
|
|
EXPECT_THAT(CompiledInstructions("OpLine %srcfile 42 99"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpLine, {1, 42, 99})));
|
2015-09-24 21:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, OpNoLine) {
|
|
|
|
EXPECT_THAT(CompiledInstructions("OpNoLine"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpNoLine, {})));
|
2015-09-24 21:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using OpStringTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<const char*>>;
|
|
|
|
|
|
|
|
TEST_P(OpStringTest, AnyString) {
|
|
|
|
// TODO(dneto): utf-8, quoting, escaping
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input =
|
|
|
|
std::string("%result = OpString \"") + GetParam() + "\"";
|
2015-09-24 21:11:15 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpString, {1}, MakeVector(GetParam()))));
|
2015-09-24 21:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dneto): utf-8, quoting, escaping
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryTestDebug, OpStringTest,
|
|
|
|
::testing::ValuesIn(std::vector<const char*>{
|
|
|
|
"", "foo bar this and that"}));
|
2015-09-24 21:11:15 +00:00
|
|
|
|
|
|
|
using OpNameTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<const char*>>;
|
|
|
|
|
|
|
|
TEST_P(OpNameTest, AnyString) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input =
|
|
|
|
std::string("OpName %target \"") + GetParam() + "\"";
|
2015-09-24 21:11:15 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpName, {1}, MakeVector(GetParam()))));
|
2015-09-24 21:11:15 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 14:34:27 +00:00
|
|
|
// UTF-8, quoting, escaping, etc. are covered in the StringLiterals tests in
|
|
|
|
// BinaryToText.Literal.cpp.
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryTestDebug, OpNameTest,
|
|
|
|
::testing::Values("", "foo bar this and that"));
|
2015-09-24 21:11:15 +00:00
|
|
|
|
|
|
|
using OpMemberNameTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<const char*>>;
|
|
|
|
|
|
|
|
TEST_P(OpMemberNameTest, AnyString) {
|
|
|
|
// TODO(dneto): utf-8, quoting, escaping
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input =
|
2015-09-24 21:11:15 +00:00
|
|
|
std::string("OpMemberName %type 42 \"") + GetParam() + "\"";
|
2015-10-01 15:24:11 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpMemberName, {1, 42}, MakeVector(GetParam()))));
|
2015-09-24 21:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dneto): utf-8, quoting, escaping
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryTestDebug, OpMemberNameTest,
|
|
|
|
::testing::ValuesIn(std::vector<const char*>{
|
|
|
|
"", "foo bar this and that"}));
|
2015-09-24 21:11:15 +00:00
|
|
|
|
|
|
|
// TODO(dneto): Parse failures?
|
2015-09-09 14:58:02 +00:00
|
|
|
|
2016-05-11 16:40:59 +00:00
|
|
|
using OpModuleProcessedTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<const char*>>;
|
|
|
|
|
|
|
|
TEST_P(OpModuleProcessedTest, AnyString) {
|
|
|
|
const std::string input =
|
|
|
|
std::string("OpModuleProcessed \"") + GetParam() + "\"";
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions(input, SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq(MakeInstruction(SpvOpModuleProcessed, MakeVector(GetParam()))));
|
|
|
|
}
|
|
|
|
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryTestDebug, OpModuleProcessedTest,
|
|
|
|
::testing::Values("", "foo bar this and that"));
|
2018-07-11 13:24:49 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace spvtools
|