1 // Copyright 2017 Google Inc.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #include "cpuinfo_arm.h"
16 #include "filesystem_for_testing.h"
17 #include "hwcaps_for_testing.h"
19 #include "gtest/gtest.h"
21 namespace cpu_features {
24 void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
26 TEST(CpuinfoArmTest, FromHardwareCap) {
27 SetHardwareCapabilities(ARM_HWCAP_NEON, ARM_HWCAP2_AES | ARM_HWCAP2_CRC32);
28 GetEmptyFilesystem(); // disabling /proc/cpuinfo
29 const auto info = GetArmInfo();
30 EXPECT_TRUE(info.features.vfp); // triggered by vfpv3
31 EXPECT_TRUE(info.features.vfpv3); // triggered by neon
32 EXPECT_TRUE(info.features.neon);
33 EXPECT_TRUE(info.features.aes);
34 EXPECT_TRUE(info.features.crc32);
36 EXPECT_FALSE(info.features.vfpv4);
37 EXPECT_FALSE(info.features.iwmmxt);
38 EXPECT_FALSE(info.features.vfpv3d16);
39 EXPECT_FALSE(info.features.idiva);
40 EXPECT_FALSE(info.features.idivt);
41 EXPECT_FALSE(info.features.pmull);
42 EXPECT_FALSE(info.features.sha1);
43 EXPECT_FALSE(info.features.sha2);
46 TEST(CpuinfoArmTest, ODroidFromCpuInfo) {
47 DisableHardwareCapabilities();
48 auto& fs = GetEmptyFilesystem();
49 fs.CreateFile("/proc/cpuinfo", R"(processor : 0
50 model name : ARMv7 Processor rev 3 (v71)
52 Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae
53 CPU implementer : 0x41
58 const auto info = GetArmInfo();
59 EXPECT_EQ(info.implementer, 0x41);
60 EXPECT_EQ(info.variant, 0x2);
61 EXPECT_EQ(info.part, 0xc0f);
62 EXPECT_EQ(info.revision, 3);
63 EXPECT_EQ(info.architecture, 7);
65 EXPECT_TRUE(info.features.vfp);
66 EXPECT_FALSE(info.features.iwmmxt);
67 EXPECT_TRUE(info.features.neon);
68 EXPECT_TRUE(info.features.vfpv3);
69 EXPECT_FALSE(info.features.vfpv3d16);
70 EXPECT_TRUE(info.features.vfpv4);
71 EXPECT_TRUE(info.features.idiva);
72 EXPECT_TRUE(info.features.idivt);
73 EXPECT_FALSE(info.features.aes);
74 EXPECT_FALSE(info.features.pmull);
75 EXPECT_FALSE(info.features.sha1);
76 EXPECT_FALSE(info.features.sha2);
77 EXPECT_FALSE(info.features.crc32);
80 // http://code.google.com/p/android/issues/detail?id=10812
81 TEST(CpuinfoArmTest, InvalidArmv7) {
82 DisableHardwareCapabilities();
83 auto& fs = GetEmptyFilesystem();
84 fs.CreateFile("/proc/cpuinfo",
85 R"(Processor : ARMv6-compatible processor rev 6 (v6l)
87 Features : swp half thumb fastmult vfp edsp java
88 CPU implementer : 0x41
96 Serial : 33323613546d00ec )");
97 const auto info = GetArmInfo();
98 EXPECT_EQ(info.architecture, 6);
101 // https://crbug.com/341598.
102 TEST(CpuinfoArmTest, InvalidNeon) {
103 auto& fs = GetEmptyFilesystem();
104 fs.CreateFile("/proc/cpuinfo",
105 R"(Processor: ARMv7 Processory rev 0 (v71)
112 Features: swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
113 CPU implementer : 0x51
121 Serial: 00001e030000354e)");
122 const auto info = GetArmInfo();
123 EXPECT_FALSE(info.features.neon);
126 // The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV
128 TEST(CpuinfoArmTest, Nexus4_0x510006f2) {
129 DisableHardwareCapabilities();
130 auto& fs = GetEmptyFilesystem();
131 fs.CreateFile("/proc/cpuinfo",
132 R"(CPU implementer : 0x51
137 const auto info = GetArmInfo();
138 EXPECT_TRUE(info.features.idiva);
139 EXPECT_TRUE(info.features.idivt);
142 // The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV
144 TEST(CpuinfoArmTest, Nexus4_0x510006f3) {
145 DisableHardwareCapabilities();
146 auto& fs = GetEmptyFilesystem();
147 fs.CreateFile("/proc/cpuinfo",
148 R"(CPU implementer : 0x51
153 const auto info = GetArmInfo();
154 EXPECT_TRUE(info.features.idiva);
155 EXPECT_TRUE(info.features.idivt);
158 // The emulator-specific Android 4.2 kernel fails to report support for the
159 // 32-bit ARM IDIV instruction. Technically, this is a feature of the virtual
160 // CPU implemented by the emulator.
161 TEST(CpuinfoArmTest, EmulatorSpecificIdiv) {
162 DisableHardwareCapabilities();
163 auto& fs = GetEmptyFilesystem();
164 fs.CreateFile("/proc/cpuinfo",
165 R"(Processor : ARMv7 Processor rev 0 (v7l)
167 Features : swp half thumb fastmult vfp edsp neon vfpv3
168 CPU implementer : 0x41
176 Serial : 0000000000000000)");
177 const auto info = GetArmInfo();
178 EXPECT_TRUE(info.features.idiva);
182 } // namespace cpu_features