blob: bdb4d17c65e35162704e8b6859efac22e6cf929b [file] [log] [blame]
Guillaume Chatelet439d3712018-02-01 10:03:09 +01001// 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
21namespace cpu_features {
22namespace {
23
24void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
25
26TEST(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
39TEST(CpuinfoAarch64Test, ARMCortexA53) {
40 DisableHardwareCapabilities();
41 auto& fs = GetEmptyFilesystem();
42 fs.CreateFile("/proc/cpuinfo",
43 R"(Processor : AArch64 Processor rev 3 (aarch64)
44processor : 0
45processor : 1
46processor : 2
47processor : 3
48processor : 4
49processor : 5
50processor : 6
51processor : 7
52Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
53CPU implementer : 0x41
54CPU architecture: AArch64
55CPU variant : 0x0
56CPU part : 0xd03
57CPU 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