| 1 |
// Copyright (c) 2024-2025 Arm Ltd. |
| 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 |
#include <string> |
| 16 |
|
| 17 |
#include "gmock/gmock.h" |
| 18 |
#include "source/util/string_utils.h" |
| 19 |
#include "spirv/unified1/TOSA.001000.1.h" |
| 20 |
#include "test/test_fixture.h" |
| 21 |
#include "test/unit_spirv.h" |
| 22 |
|
| 23 |
namespace spvtools { |
| 24 |
namespace { |
| 25 |
|
| 26 |
using spvtest::Concatenate; |
| 27 |
using spvtest::MakeInstruction; |
| 28 |
using spvtest::TextToBinaryTest; |
| 29 |
using testing::Eq; |
| 30 |
using utils::MakeVector; |
| 31 |
|
| 32 |
TEST_F(TextToBinaryTest, TOSAImportTest) { |
| 33 |
const std::string src = "%1 = OpExtInstImport \"TOSA.001000.1\""; |
| 34 |
EXPECT_THAT(CompiledInstructions(src), |
| 35 |
Eq(MakeInstruction(spv::Op::OpExtInstImport, {1}, |
| 36 |
MakeVector("TOSA.001000.1")))); |
| 37 |
} |
| 38 |
|
| 39 |
TEST_F(TextToBinaryTest, TOSAInstructionSmokeTest) { |
| 40 |
const std::string src = |
| 41 |
"%1 = OpExtInstImport \"TOSA.001000.1\"\n" |
| 42 |
"%3 = OpExtInst %2 %1 ARGMAX %4 %5 %6\n"; |
| 43 |
|
| 44 |
// First make sure it assembles correctly. |
| 45 |
EXPECT_THAT( |
| 46 |
CompiledInstructions(src), |
| 47 |
Eq(Concatenate({MakeInstruction(spv::Op::OpExtInstImport, {1}, |
| 48 |
MakeVector("TOSA.001000.1")), |
| 49 |
MakeInstruction(spv::Op::OpExtInst, |
| 50 |
{2, 3, 1, TOSAARGMAX, 4, 5, 6})}))) |
| 51 |
<< src; |
| 52 |
// Now check the round trip through the disassembler. |
| 53 |
EXPECT_THAT(EncodeAndDecodeSuccessfully(src), src) << src; |
| 54 |
} |
| 55 |
|
| 56 |
} // namespace |
| 57 |
} // namespace spvtools |