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_aarch64.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(CpuinfoAarch64Test, FromHardwareCap) {
27 SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_AES, 0);
28 GetEmptyFilesystem(); // disabling /proc/cpuinfo
29 const auto info = GetAarch64Info();
30 EXPECT_TRUE(info.features.fp);
31 EXPECT_FALSE(info.features.asimd);
32 EXPECT_TRUE(info.features.aes);
33 EXPECT_FALSE(info.features.pmull);
34 EXPECT_FALSE(info.features.sha1);
35 EXPECT_FALSE(info.features.sha2);
36 EXPECT_FALSE(info.features.crc32);
39 TEST(CpuinfoAarch64Test, ARMCortexA53) {
40 DisableHardwareCapabilities();
41 auto& fs = GetEmptyFilesystem();
42 fs.CreateFile("/proc/cpuinfo",
43 R"(Processor : AArch64 Processor rev 3 (aarch64)
52 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
53 CPU implementer : 0x41
54 CPU architecture: AArch64
58 const auto info = GetAarch64Info();
59 EXPECT_EQ(info.implementer, 0x41);
60 EXPECT_EQ(info.variant, 0x0);
61 EXPECT_EQ(info.part, 0xd03);
62 EXPECT_EQ(info.revision, 3);
64 EXPECT_TRUE(info.features.fp);
65 EXPECT_TRUE(info.features.asimd);
66 EXPECT_TRUE(info.features.aes);
67 EXPECT_TRUE(info.features.pmull);
68 EXPECT_TRUE(info.features.sha1);
69 EXPECT_TRUE(info.features.sha2);
70 EXPECT_TRUE(info.features.crc32);
74 } // namespace cpu_features