| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 #ifndef NACL_TRUSTED_BUT_NOT_TCB |
| 7 #error This file is not meant for use in the TCB |
| 8 #endif |
| 6 | 9 |
| 7 #include "native_client/src/trusted/validator_arm/inst_classes_testers.h" | 10 #include "native_client/src/trusted/validator_arm/inst_classes_testers.h" |
| 8 | 11 |
| 9 #include "gtest/gtest.h" | 12 #include "gtest/gtest.h" |
| 10 #include "native_client/src/trusted/validator_arm/gen/arm32_decode_named.h" | 13 #include "native_client/src/trusted/validator_arm/decoder_tester.h" |
| 11 | 14 |
| 12 using nacl_arm_dec::kRegisterFlags; | 15 using nacl_arm_dec::kRegisterFlags; |
| 13 using nacl_arm_dec::kRegisterNone; | 16 using nacl_arm_dec::kRegisterNone; |
| 14 using nacl_arm_dec::kRegisterPc; | 17 using nacl_arm_dec::kRegisterPc; |
| 15 using nacl_arm_dec::ClassDecoder; | |
| 16 using nacl_arm_dec::Instruction; | 18 using nacl_arm_dec::Instruction; |
| 17 using nacl_arm_dec::NamedBinary4RegisterShiftedOp; | |
| 18 | 19 |
| 19 namespace nacl_arm_test { | 20 namespace nacl_arm_test { |
| 20 | 21 |
| 21 Binary4RegisterShiftedOpTester::Binary4RegisterShiftedOpTester() | 22 Binary4RegisterShiftedOpTester::Binary4RegisterShiftedOpTester() |
| 22 : Arm32DecoderTester(state_.Binary4RegisterShiftedOp_instance_) {} | 23 : Arm32DecoderTester(state_.Binary4RegisterShiftedOp_instance_) |
| 24 {} |
| 25 |
| 26 Binary4RegisterShiftedOpTester::Binary4RegisterShiftedOpTester( |
| 27 const NamedBinary4RegisterShiftedOp& decoder) |
| 28 : Arm32DecoderTester(decoder) {} |
| 23 | 29 |
| 24 void Binary4RegisterShiftedOpTester:: | 30 void Binary4RegisterShiftedOpTester:: |
| 25 ApplySanityChecks(Instruction inst, const ClassDecoder& decoder) { | 31 ApplySanityChecks(Instruction inst, |
| 26 NamedBinary4RegisterShiftedOp &expected_decoder = | 32 const NamedClassDecoder& decoder) { |
| 27 state_.Binary4RegisterShiftedOp_instance_; | 33 nacl_arm_dec::Binary4RegisterShiftedOp expected_decoder; |
| 28 | 34 |
| 29 // Check that condition is defined correctly. | 35 // Check that condition is defined correctly. |
| 30 EXPECT_EQ(expected_decoder.cond_.value(inst), inst.bits(31, 28)); | 36 EXPECT_EQ(expected_decoder.cond_.value(inst), inst.bits(31, 28)); |
| 31 | 37 |
| 32 // Didn't parse undefined conditional. | 38 // Didn't parse undefined conditional. |
| 33 if (expected_decoder.cond_.undefined(inst) && | 39 if (expected_decoder.cond_.undefined(inst) && |
| 34 (&expected_decoder != &decoder)) return; | 40 (&state_.Binary4RegisterShiftedOp_instance_ != &decoder)) return; |
| 35 | 41 |
| 36 // Check if expected class name found. | 42 // Check if expected class name found. |
| 37 Arm32DecoderTester::ApplySanityChecks(inst, decoder); | 43 Arm32DecoderTester::ApplySanityChecks(inst, decoder); |
| 38 | 44 |
| 39 // Check Registers and flags used in DataProc. | 45 // Check Registers and flags used in DataProc. |
| 40 EXPECT_EQ(expected_decoder.n_.number(inst), inst.bits(19, 16)); | 46 EXPECT_EQ(expected_decoder.n_.number(inst), inst.bits(19, 16)); |
| 41 EXPECT_EQ(expected_decoder.d_.number(inst), inst.bits(15, 12)); | 47 EXPECT_EQ(expected_decoder.d_.number(inst), inst.bits(15, 12)); |
| 42 EXPECT_EQ(expected_decoder.s_.number(inst), inst.bits(11, 8)); | 48 EXPECT_EQ(expected_decoder.s_.number(inst), inst.bits(11, 8)); |
| 43 EXPECT_EQ(expected_decoder.m_.number(inst), inst.bits(3, 0)); | 49 EXPECT_EQ(expected_decoder.m_.number(inst), inst.bits(3, 0)); |
| 44 EXPECT_EQ(expected_decoder.flags_.is_updated(inst), inst.bit(20)); | 50 EXPECT_EQ(expected_decoder.flags_.is_updated(inst), inst.bit(20)); |
| 45 if (expected_decoder.flags_.is_updated(inst)) { | 51 if (expected_decoder.flags_.is_updated(inst)) { |
| 46 EXPECT_EQ(expected_decoder.flags_.reg_if_updated(inst), kRegisterFlags); | 52 EXPECT_EQ(expected_decoder.flags_.reg_if_updated(inst), kRegisterFlags); |
| 47 } else { | 53 } else { |
| 48 EXPECT_EQ(expected_decoder.flags_.reg_if_updated(inst), kRegisterNone); | 54 EXPECT_EQ(expected_decoder.flags_.reg_if_updated(inst), kRegisterNone); |
| 49 } | 55 } |
| 56 } |
| 57 |
| 58 Binary4RegisterShiftedOpTesterRegsNotPc:: |
| 59 Binary4RegisterShiftedOpTesterRegsNotPc() |
| 60 : Binary4RegisterShiftedOpTester() {} |
| 61 |
| 62 Binary4RegisterShiftedOpTesterRegsNotPc:: |
| 63 Binary4RegisterShiftedOpTesterRegsNotPc( |
| 64 const NamedBinary4RegisterShiftedOp& decoder) |
| 65 : Binary4RegisterShiftedOpTester(decoder) {} |
| 66 |
| 67 void Binary4RegisterShiftedOpTesterRegsNotPc:: |
| 68 ApplySanityChecks(Instruction inst, |
| 69 const NamedClassDecoder& decoder) { |
| 70 nacl_arm_dec::Binary4RegisterShiftedOp expected_decoder; |
| 71 |
| 72 Binary4RegisterShiftedOpTester::ApplySanityChecks(inst, decoder); |
| 50 | 73 |
| 51 // Other ARM constraints about this instruction. | 74 // Other ARM constraints about this instruction. |
| 52 EXPECT_NE(expected_decoder.n_.reg(inst), kRegisterPc) | 75 EXPECT_NE(expected_decoder.n_.reg(inst), kRegisterPc) |
| 53 << "Expected Unpredictable for " << InstContents(); | 76 << "Expected Unpredictable for " << InstContents(); |
| 54 EXPECT_NE(expected_decoder.d_.reg(inst), kRegisterPc) | 77 EXPECT_NE(expected_decoder.d_.reg(inst), kRegisterPc) |
| 55 << "Expected Unpredictable for " << InstContents(); | 78 << "Expected Unpredictable for " << InstContents(); |
| 56 EXPECT_NE(expected_decoder.s_.reg(inst), kRegisterPc) | 79 EXPECT_NE(expected_decoder.s_.reg(inst), kRegisterPc) |
| 57 << "Expected Unpredictable for " << InstContents(); | 80 << "Expected Unpredictable for " << InstContents(); |
| 58 EXPECT_NE(expected_decoder.m_.reg(inst), kRegisterPc) | 81 EXPECT_NE(expected_decoder.m_.reg(inst), kRegisterPc) |
| 59 << "Expected Unpredictable for " << InstContents(); | 82 << "Expected Unpredictable for " << InstContents(); |
| 60 } | 83 } |
| 61 | 84 |
| 62 } // namespace | 85 } // namespace |
| OLD | NEW |