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_ppc.h"
16 #include "filesystem_for_testing.h"
17 #include "hwcaps_for_testing.h"
18 #include "internal/string_view.h"
20 #include "gtest/gtest.h"
22 namespace cpu_features {
25 void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
27 TEST(CpustringsPPCTest, FromHardwareCap) {
28 SetHardwareCapabilities(PPC_FEATURE_HAS_FPU | PPC_FEATURE_HAS_VSX,
29 PPC_FEATURE2_ARCH_3_00);
30 GetEmptyFilesystem(); // disabling /proc/cpuinfo
31 const auto info = GetPPCInfo();
32 EXPECT_TRUE(info.features.fpu);
33 EXPECT_FALSE(info.features.mmu);
34 EXPECT_TRUE(info.features.vsx);
35 EXPECT_TRUE(info.features.arch300);
36 EXPECT_FALSE(info.features.power4);
37 EXPECT_FALSE(info.features.altivec);
38 EXPECT_FALSE(info.features.vcrypto);
39 EXPECT_FALSE(info.features.htm);
42 TEST(CpustringsPPCTest, Blade) {
43 DisableHardwareCapabilities();
44 auto& fs = GetEmptyFilesystem();
45 fs.CreateFile("/proc/cpuinfo",
47 cpu : POWER7 (architected), altivec supported
48 clock : 3000.000000MHz
49 revision : 2.1 (pvr 003f 0201)
52 cpu : POWER7 (architected), altivec supported
53 clock : 3000.000000MHz
54 revision : 2.1 (pvr 003f 0201)
59 machine : CHRP IBM,8406-70Y)");
60 SetPlatformTypes("power7", "power8");
61 const auto strings = GetPPCPlatformStrings();
62 ASSERT_STREQ(strings.platform, "pSeries");
63 ASSERT_STREQ(strings.model, "IBM,8406-70Y");
64 ASSERT_STREQ(strings.machine, "CHRP IBM,8406-70Y");
65 ASSERT_STREQ(strings.cpu, "POWER7 (architected), altivec supported");
66 ASSERT_STREQ(strings.type.platform, "power7");
67 ASSERT_STREQ(strings.type.base_platform, "power8");
70 TEST(CpustringsPPCTest, Firestone) {
71 DisableHardwareCapabilities();
72 auto& fs = GetEmptyFilesystem();
73 fs.CreateFile("/proc/cpuinfo",
75 cpu : POWER8 (raw), altivec supported
76 clock : 2061.000000MHz
77 revision : 2.0 (pvr 004d 0200)
80 cpu : POWER8 (raw), altivec supported
81 clock : 2061.000000MHz
82 revision : 2.0 (pvr 004d 0200)
87 machine : PowerNV 8335-GTA
88 firmware : OPAL v3)");
89 const auto strings = GetPPCPlatformStrings();
90 ASSERT_STREQ(strings.platform, "PowerNV");
91 ASSERT_STREQ(strings.model, "8335-GTA");
92 ASSERT_STREQ(strings.machine, "PowerNV 8335-GTA");
93 ASSERT_STREQ(strings.cpu, "POWER8 (raw), altivec supported");
96 TEST(CpustringsPPCTest, w8) {
97 DisableHardwareCapabilities();
98 auto& fs = GetEmptyFilesystem();
99 fs.CreateFile("/proc/cpuinfo",
101 cpu : POWER9, altivec supported
102 clock : 2300.000000MHz
103 revision : 2.2 (pvr 004e 1202)
107 model : 0000000000000000
108 machine : PowerNV 0000000000000000
111 const auto strings = GetPPCPlatformStrings();
112 ASSERT_STREQ(strings.platform, "PowerNV");
113 ASSERT_STREQ(strings.model, "0000000000000000");
114 ASSERT_STREQ(strings.machine, "PowerNV 0000000000000000");
115 ASSERT_STREQ(strings.cpu, "POWER9, altivec supported");
119 } // namespace cpu_features