Guillaume Chatelet | 439d371 | 2018-02-01 10:03:09 +0100 | [diff] [blame] | 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_aarch64.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(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); |
| 37 | } |
| 38 | |
| 39 | TEST(CpuinfoAarch64Test, ARMCortexA53) { |
| 40 | DisableHardwareCapabilities(); |
| 41 | auto& fs = GetEmptyFilesystem(); |
| 42 | fs.CreateFile("/proc/cpuinfo", |
| 43 | R"(Processor : AArch64 Processor rev 3 (aarch64) |
| 44 | processor : 0 |
| 45 | processor : 1 |
| 46 | processor : 2 |
| 47 | processor : 3 |
| 48 | processor : 4 |
| 49 | processor : 5 |
| 50 | processor : 6 |
| 51 | processor : 7 |
| 52 | Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 |
| 53 | CPU implementer : 0x41 |
| 54 | CPU architecture: AArch64 |
| 55 | CPU variant : 0x0 |
| 56 | CPU part : 0xd03 |
| 57 | CPU revision : 3)"); |
| 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); |
| 63 | |
| 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); |
| 71 | } |
| 72 | |
| 73 | } // namespace |
| 74 | } // namespace cpu_features |