TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / cpu_features / test / cpuinfo_arm_test.cc
1 // Copyright 2017 Google Inc.
2 //
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
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 #include "cpuinfo_arm.h"
16 #include "filesystem_for_testing.h"
17 #include "hwcaps_for_testing.h"
18
19 #include "gtest/gtest.h"
20
21 namespace cpu_features {
22 namespace {
23
24 void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
25
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);
35
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);
44 }
45
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)
51 BogoMIPS        : 120.00
52 Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae
53 CPU implementer : 0x41
54 CPU architecture: 7
55 CPU variant     : 0x2
56 CPU part        : 0xc0f
57 CPU revision    : 3)");
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);
64
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);
78 }
79
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) 
86 BogoMIPS        : 199.47 
87 Features        : swp half thumb fastmult vfp edsp java 
88 CPU implementer : 0x41 
89 CPU architecture: 7 
90 CPU variant     : 0x0 
91 CPU part        : 0xb76 
92 CPU revision    : 6 
93
94 Hardware        : SPICA 
95 Revision        : 0020 
96 Serial          : 33323613546d00ec )");
97   const auto info = GetArmInfo();
98   EXPECT_EQ(info.architecture, 6);
99 }
100
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)
106 processor: 0
107 BogoMIPS: 13.50
108
109 Processor: 1
110 BogoMIPS: 13.50
111
112 Features: swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
113 CPU implementer : 0x51
114 CPU architecture: 7
115 CPU variant: 0x1
116 CPU part: 0x04d
117 CPU revision: 0
118
119 Hardware: SAMSUNG M2
120 Revision: 0010
121 Serial: 00001e030000354e)");
122   const auto info = GetArmInfo();
123   EXPECT_FALSE(info.features.neon);
124 }
125
126 // The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV
127 // support.
128 TEST(CpuinfoArmTest, Nexus4_0x510006f2) {
129   DisableHardwareCapabilities();
130   auto& fs = GetEmptyFilesystem();
131   fs.CreateFile("/proc/cpuinfo",
132                 R"(CPU implementer      : 0x51
133 CPU architecture: 7
134 CPU variant     : 0x0
135 CPU part        : 0x6f
136 CPU revision    : 2)");
137   const auto info = GetArmInfo();
138   EXPECT_TRUE(info.features.idiva);
139   EXPECT_TRUE(info.features.idivt);
140 }
141
142 // The Nexus 4 (Qualcomm Krait) kernel configuration forgets to report IDIV
143 // support.
144 TEST(CpuinfoArmTest, Nexus4_0x510006f3) {
145   DisableHardwareCapabilities();
146   auto& fs = GetEmptyFilesystem();
147   fs.CreateFile("/proc/cpuinfo",
148                 R"(CPU implementer      : 0x51
149 CPU architecture: 7
150 CPU variant     : 0x0
151 CPU part        : 0x6f
152 CPU revision    : 3)");
153   const auto info = GetArmInfo();
154   EXPECT_TRUE(info.features.idiva);
155   EXPECT_TRUE(info.features.idivt);
156 }
157
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)
166 BogoMIPS        : 629.14
167 Features        : swp half thumb fastmult vfp edsp neon vfpv3
168 CPU implementer : 0x41
169 CPU architecture: 7
170 CPU variant     : 0x0
171 CPU part        : 0xc08
172 CPU revision    : 0
173
174 Hardware        : Goldfish
175 Revision        : 0000
176 Serial          : 0000000000000000)");
177   const auto info = GetArmInfo();
178   EXPECT_TRUE(info.features.idiva);
179 }
180
181 }  // namespace
182 }  // namespace cpu_features