| 1 | //===-- TestAArch64Emulator.cpp ------------------------------------------===// |
| 2 | |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "gtest/gtest.h" |
| 11 | |
| 12 | #include "lldb/Core/Address.h" |
| 13 | #include "lldb/Core/Disassembler.h" |
| 14 | #include "lldb/Target/ExecutionContext.h" |
| 15 | #include "lldb/Utility/ArchSpec.h" |
| 16 | |
| 17 | #include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h" |
| 18 | |
| 19 | using namespace lldb; |
| 20 | using namespace lldb_private; |
| 21 | |
| 22 | struct Arch64EmulatorTester : public EmulateInstructionARM64 { |
| 23 | Arch64EmulatorTester() |
| 24 | : EmulateInstructionARM64(ArchSpec("arm64-apple-ios" )) {} |
| 25 | |
| 26 | static uint64_t AddWithCarry(uint32_t N, uint64_t x, uint64_t y, bool carry_in, |
| 27 | EmulateInstructionARM64::ProcState &proc_state) { |
| 28 | return EmulateInstructionARM64::AddWithCarry(N, x, y, carry_in, proc_state); |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | class TestAArch64Emulator : public testing::Test { |
| 33 | public: |
| 34 | static void SetUpTestCase(); |
| 35 | static void TearDownTestCase(); |
| 36 | |
| 37 | protected: |
| 38 | }; |
| 39 | |
| 40 | void TestAArch64Emulator::SetUpTestCase() { |
| 41 | EmulateInstructionARM64::Initialize(); |
| 42 | } |
| 43 | |
| 44 | void TestAArch64Emulator::TearDownTestCase() { |
| 45 | EmulateInstructionARM64::Terminate(); |
| 46 | } |
| 47 | |
| 48 | TEST_F(TestAArch64Emulator, TestOverflow) { |
| 49 | EmulateInstructionARM64::ProcState pstate; |
| 50 | memset(s: &pstate, c: 0, n: sizeof(pstate)); |
| 51 | uint64_t ll_max = std::numeric_limits<int64_t>::max(); |
| 52 | Arch64EmulatorTester emu; |
| 53 | ASSERT_EQ(emu.AddWithCarry(64, ll_max, 0, 0, pstate), ll_max); |
| 54 | ASSERT_EQ(pstate.V, 0ULL); |
| 55 | ASSERT_EQ(pstate.C, 0ULL); |
| 56 | ASSERT_EQ(emu.AddWithCarry(64, ll_max, 1, 0, pstate), (uint64_t)(ll_max + 1)); |
| 57 | ASSERT_EQ(pstate.V, 1ULL); |
| 58 | ASSERT_EQ(pstate.C, 0ULL); |
| 59 | ASSERT_EQ(emu.AddWithCarry(64, ll_max, 0, 1, pstate), (uint64_t)(ll_max + 1)); |
| 60 | ASSERT_EQ(pstate.V, 1ULL); |
| 61 | ASSERT_EQ(pstate.C, 0ULL); |
| 62 | } |
| 63 | |