xref: /aosp_15_r20/art/libartbase/arch/instruction_set_test.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #include "instruction_set.h"
18*795d594fSAndroid Build Coastguard Worker 
19*795d594fSAndroid Build Coastguard Worker #include <gtest/gtest.h>
20*795d594fSAndroid Build Coastguard Worker 
21*795d594fSAndroid Build Coastguard Worker #include "base/pointer_size.h"
22*795d594fSAndroid Build Coastguard Worker 
23*795d594fSAndroid Build Coastguard Worker namespace art {
24*795d594fSAndroid Build Coastguard Worker 
TEST(InstructionSetTest,GetInstructionSetFromString)25*795d594fSAndroid Build Coastguard Worker TEST(InstructionSetTest, GetInstructionSetFromString) {
26*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(InstructionSet::kArm, GetInstructionSetFromString("arm"));
27*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(InstructionSet::kArm64, GetInstructionSetFromString("arm64"));
28*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(InstructionSet::kX86, GetInstructionSetFromString("x86"));
29*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(InstructionSet::kX86_64, GetInstructionSetFromString("x86_64"));
30*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(InstructionSet::kNone, GetInstructionSetFromString("none"));
31*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(InstructionSet::kNone, GetInstructionSetFromString("random-string"));
32*795d594fSAndroid Build Coastguard Worker }
33*795d594fSAndroid Build Coastguard Worker 
TEST(InstructionSetTest,GetInstructionSetString)34*795d594fSAndroid Build Coastguard Worker TEST(InstructionSetTest, GetInstructionSetString) {
35*795d594fSAndroid Build Coastguard Worker   EXPECT_STREQ("arm", GetInstructionSetString(InstructionSet::kArm));
36*795d594fSAndroid Build Coastguard Worker   EXPECT_STREQ("arm", GetInstructionSetString(InstructionSet::kThumb2));
37*795d594fSAndroid Build Coastguard Worker   EXPECT_STREQ("arm64", GetInstructionSetString(InstructionSet::kArm64));
38*795d594fSAndroid Build Coastguard Worker   EXPECT_STREQ("x86", GetInstructionSetString(InstructionSet::kX86));
39*795d594fSAndroid Build Coastguard Worker   EXPECT_STREQ("x86_64", GetInstructionSetString(InstructionSet::kX86_64));
40*795d594fSAndroid Build Coastguard Worker   EXPECT_STREQ("none", GetInstructionSetString(InstructionSet::kNone));
41*795d594fSAndroid Build Coastguard Worker }
42*795d594fSAndroid Build Coastguard Worker 
TEST(InstructionSetTest,GetInstructionSetInstructionAlignment)43*795d594fSAndroid Build Coastguard Worker TEST(InstructionSetTest, GetInstructionSetInstructionAlignment) {
44*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(GetInstructionSetInstructionAlignment(InstructionSet::kThumb2),
45*795d594fSAndroid Build Coastguard Worker             kThumb2InstructionAlignment);
46*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(GetInstructionSetInstructionAlignment(InstructionSet::kArm64),
47*795d594fSAndroid Build Coastguard Worker             kArm64InstructionAlignment);
48*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(GetInstructionSetInstructionAlignment(InstructionSet::kX86),
49*795d594fSAndroid Build Coastguard Worker             kX86InstructionAlignment);
50*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(GetInstructionSetInstructionAlignment(InstructionSet::kX86_64),
51*795d594fSAndroid Build Coastguard Worker             kX86_64InstructionAlignment);
52*795d594fSAndroid Build Coastguard Worker }
53*795d594fSAndroid Build Coastguard Worker 
TEST(InstructionSetTest,TestRoundTrip)54*795d594fSAndroid Build Coastguard Worker TEST(InstructionSetTest, TestRoundTrip) {
55*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(kRuntimeISA, GetInstructionSetFromString(GetInstructionSetString(kRuntimeISA)));
56*795d594fSAndroid Build Coastguard Worker }
57*795d594fSAndroid Build Coastguard Worker 
TEST(InstructionSetTest,PointerSize)58*795d594fSAndroid Build Coastguard Worker TEST(InstructionSetTest, PointerSize) {
59*795d594fSAndroid Build Coastguard Worker   EXPECT_EQ(kRuntimePointerSize, GetInstructionSetPointerSize(kRuntimeISA));
60*795d594fSAndroid Build Coastguard Worker }
61*795d594fSAndroid Build Coastguard Worker 
62*795d594fSAndroid Build Coastguard Worker }  // namespace art
63