Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | #include "Regs.h" |
| 22 | |
| 23 | class RegsTest : public ::testing::Test {}; |
| 24 | |
| 25 | TEST_F(RegsTest, regs32) { |
| 26 | Regs32 regs32(10, 20, 30); |
| 27 | |
| 28 | ASSERT_EQ(10U, regs32.pc_reg()); |
| 29 | ASSERT_EQ(20U, regs32.sp_reg()); |
| 30 | ASSERT_EQ(30U, regs32.total_regs()); |
| 31 | |
| 32 | uint32_t* raw = reinterpret_cast<uint32_t*>(regs32.raw_data()); |
| 33 | for (size_t i = 0; i < 30; i++) { |
| 34 | raw[i] = 0xf0000000 + i; |
| 35 | } |
| 36 | |
| 37 | ASSERT_EQ(0xf000000aU, regs32.pc()); |
| 38 | ASSERT_EQ(0xf0000014U, regs32.sp()); |
| 39 | |
| 40 | ASSERT_EQ(0xf0000001U, regs32[1]); |
| 41 | regs32[1] = 10; |
| 42 | ASSERT_EQ(10U, regs32[1]); |
| 43 | |
| 44 | ASSERT_EQ(0xf000001dU, regs32[29]); |
| 45 | } |
| 46 | |
| 47 | TEST_F(RegsTest, regs64) { |
| 48 | Regs64 regs64(10, 20, 30); |
| 49 | |
| 50 | ASSERT_EQ(10U, regs64.pc_reg()); |
| 51 | ASSERT_EQ(20U, regs64.sp_reg()); |
| 52 | ASSERT_EQ(30U, regs64.total_regs()); |
| 53 | |
| 54 | uint64_t* raw = reinterpret_cast<uint64_t*>(regs64.raw_data()); |
| 55 | for (size_t i = 0; i < 30; i++) { |
| 56 | raw[i] = 0xf123456780000000UL + i; |
| 57 | } |
| 58 | |
| 59 | ASSERT_EQ(0xf12345678000000aUL, regs64.pc()); |
| 60 | ASSERT_EQ(0xf123456780000014UL, regs64.sp()); |
| 61 | |
| 62 | ASSERT_EQ(0xf123456780000008U, regs64[8]); |
| 63 | regs64[8] = 10; |
| 64 | ASSERT_EQ(10U, regs64[8]); |
| 65 | |
| 66 | ASSERT_EQ(0xf12345678000001dU, regs64[29]); |
| 67 | } |