1 /*
2  * Copyright (C) 2014 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 "instruction_set_features_mips.h"
18 
19 #include <gtest/gtest.h>
20 
21 namespace art {
22 
TEST(MipsInstructionSetFeaturesTest,MipsFeaturesFromDefaultVariant)23 TEST(MipsInstructionSetFeaturesTest, MipsFeaturesFromDefaultVariant) {
24   std::string error_msg;
25   std::unique_ptr<const InstructionSetFeatures> mips_features(
26       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "default", &error_msg));
27   ASSERT_TRUE(mips_features.get() != nullptr) << error_msg;
28   EXPECT_EQ(mips_features->GetInstructionSet(), InstructionSet::kMips);
29   EXPECT_TRUE(mips_features->Equals(mips_features.get()));
30   EXPECT_STREQ("fpu32,mips2,-msa", mips_features->GetFeatureString().c_str());
31   EXPECT_EQ(mips_features->AsBitmap(), 3U);
32 }
33 
TEST(MipsInstructionSetFeaturesTest,MipsFeaturesFromR1Variant)34 TEST(MipsInstructionSetFeaturesTest, MipsFeaturesFromR1Variant) {
35   std::string error_msg;
36   std::unique_ptr<const InstructionSetFeatures> mips32r1_features(
37       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r1", &error_msg));
38   ASSERT_TRUE(mips32r1_features.get() != nullptr) << error_msg;
39   EXPECT_EQ(mips32r1_features->GetInstructionSet(), InstructionSet::kMips);
40   EXPECT_TRUE(mips32r1_features->Equals(mips32r1_features.get()));
41   EXPECT_STREQ("fpu32,-mips2,-msa", mips32r1_features->GetFeatureString().c_str());
42   EXPECT_EQ(mips32r1_features->AsBitmap(), 1U);
43 
44   std::unique_ptr<const InstructionSetFeatures> mips_default_features(
45       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "default", &error_msg));
46   ASSERT_TRUE(mips_default_features.get() != nullptr) << error_msg;
47   EXPECT_FALSE(mips32r1_features->Equals(mips_default_features.get()));
48 }
49 
TEST(MipsInstructionSetFeaturesTest,MipsFeaturesFromR2Variant)50 TEST(MipsInstructionSetFeaturesTest, MipsFeaturesFromR2Variant) {
51   std::string error_msg;
52   std::unique_ptr<const InstructionSetFeatures> mips32r2_features(
53       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r2", &error_msg));
54   ASSERT_TRUE(mips32r2_features.get() != nullptr) << error_msg;
55   EXPECT_EQ(mips32r2_features->GetInstructionSet(), InstructionSet::kMips);
56   EXPECT_TRUE(mips32r2_features->Equals(mips32r2_features.get()));
57   EXPECT_STREQ("fpu32,mips2,-msa", mips32r2_features->GetFeatureString().c_str());
58   EXPECT_EQ(mips32r2_features->AsBitmap(), 3U);
59 
60   std::unique_ptr<const InstructionSetFeatures> mips_default_features(
61       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "default", &error_msg));
62   ASSERT_TRUE(mips_default_features.get() != nullptr) << error_msg;
63   EXPECT_TRUE(mips32r2_features->Equals(mips_default_features.get()));
64 
65   std::unique_ptr<const InstructionSetFeatures> mips32r1_features(
66       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r1", &error_msg));
67   ASSERT_TRUE(mips32r1_features.get() != nullptr) << error_msg;
68   EXPECT_FALSE(mips32r2_features->Equals(mips32r1_features.get()));
69 }
70 
TEST(MipsInstructionSetFeaturesTest,MipsFeaturesFromR5Variant)71 TEST(MipsInstructionSetFeaturesTest, MipsFeaturesFromR5Variant) {
72   std::string error_msg;
73   std::unique_ptr<const InstructionSetFeatures> mips32r5_features(
74       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r5", &error_msg));
75   ASSERT_TRUE(mips32r5_features.get() != nullptr) << error_msg;
76   EXPECT_EQ(mips32r5_features->GetInstructionSet(), InstructionSet::kMips);
77   EXPECT_TRUE(mips32r5_features->Equals(mips32r5_features.get()));
78   EXPECT_STREQ("-fpu32,mips2,msa", mips32r5_features->GetFeatureString().c_str());
79   EXPECT_EQ(mips32r5_features->AsBitmap(), 10U);
80 
81   std::unique_ptr<const InstructionSetFeatures> mips_default_features(
82       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "default", &error_msg));
83   ASSERT_TRUE(mips_default_features.get() != nullptr) << error_msg;
84   EXPECT_FALSE(mips32r5_features->Equals(mips_default_features.get()));
85 
86   std::unique_ptr<const InstructionSetFeatures> mips32r1_features(
87       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r1", &error_msg));
88   ASSERT_TRUE(mips32r1_features.get() != nullptr) << error_msg;
89   EXPECT_FALSE(mips32r5_features->Equals(mips32r1_features.get()));
90 
91   std::unique_ptr<const InstructionSetFeatures> mips32r2_features(
92       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r2", &error_msg));
93   ASSERT_TRUE(mips32r2_features.get() != nullptr) << error_msg;
94   EXPECT_FALSE(mips32r5_features->Equals(mips32r2_features.get()));
95 }
96 
TEST(MipsInstructionSetFeaturesTest,MipsFeaturesFromR6Variant)97 TEST(MipsInstructionSetFeaturesTest, MipsFeaturesFromR6Variant) {
98   std::string error_msg;
99   std::unique_ptr<const InstructionSetFeatures> mips32r6_features(
100       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r6", &error_msg));
101   ASSERT_TRUE(mips32r6_features.get() != nullptr) << error_msg;
102   EXPECT_EQ(mips32r6_features->GetInstructionSet(), InstructionSet::kMips);
103   EXPECT_TRUE(mips32r6_features->Equals(mips32r6_features.get()));
104   EXPECT_STREQ("-fpu32,mips2,r6,msa", mips32r6_features->GetFeatureString().c_str());
105   EXPECT_EQ(mips32r6_features->AsBitmap(), 14U);
106 
107   std::unique_ptr<const InstructionSetFeatures> mips_default_features(
108       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "default", &error_msg));
109   ASSERT_TRUE(mips_default_features.get() != nullptr) << error_msg;
110   EXPECT_FALSE(mips32r6_features->Equals(mips_default_features.get()));
111 
112   std::unique_ptr<const InstructionSetFeatures> mips32r1_features(
113       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r1", &error_msg));
114   ASSERT_TRUE(mips32r1_features.get() != nullptr) << error_msg;
115   EXPECT_FALSE(mips32r6_features->Equals(mips32r1_features.get()));
116 
117   std::unique_ptr<const InstructionSetFeatures> mips32r2_features(
118       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r2", &error_msg));
119   ASSERT_TRUE(mips32r2_features.get() != nullptr) << error_msg;
120   EXPECT_FALSE(mips32r6_features->Equals(mips32r2_features.get()));
121 
122   std::unique_ptr<const InstructionSetFeatures> mips32r5_features(
123       InstructionSetFeatures::FromVariant(InstructionSet::kMips, "mips32r5", &error_msg));
124   ASSERT_TRUE(mips32r5_features.get() != nullptr) << error_msg;
125   EXPECT_FALSE(mips32r6_features->Equals(mips32r5_features.get()));
126 }
127 
128 }  // namespace art
129