xref: /aosp_15_r20/external/cpu_features/test/cpuinfo_ppc_test.cc (revision eca53ba6d2e951e174b64682eaf56a36b8204c89)
1*eca53ba6SRoland Levillain // Copyright 2018 IBM.
2*eca53ba6SRoland Levillain //
3*eca53ba6SRoland Levillain // Licensed under the Apache License, Version 2.0 (the "License");
4*eca53ba6SRoland Levillain // you may not use this file except in compliance with the License.
5*eca53ba6SRoland Levillain // You may obtain a copy of the License at
6*eca53ba6SRoland Levillain //
7*eca53ba6SRoland Levillain //    http://www.apache.org/licenses/LICENSE-2.0
8*eca53ba6SRoland Levillain //
9*eca53ba6SRoland Levillain // Unless required by applicable law or agreed to in writing, software
10*eca53ba6SRoland Levillain // distributed under the License is distributed on an "AS IS" BASIS,
11*eca53ba6SRoland Levillain // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*eca53ba6SRoland Levillain // See the License for the specific language governing permissions and
13*eca53ba6SRoland Levillain // limitations under the License.
14*eca53ba6SRoland Levillain 
15*eca53ba6SRoland Levillain #include "cpuinfo_ppc.h"
16*eca53ba6SRoland Levillain 
17*eca53ba6SRoland Levillain #include "filesystem_for_testing.h"
18*eca53ba6SRoland Levillain #include "gtest/gtest.h"
19*eca53ba6SRoland Levillain #include "hwcaps_for_testing.h"
20*eca53ba6SRoland Levillain #include "internal/string_view.h"
21*eca53ba6SRoland Levillain 
22*eca53ba6SRoland Levillain namespace cpu_features {
23*eca53ba6SRoland Levillain namespace {
24*eca53ba6SRoland Levillain 
TEST(CpustringsPPCTest,PPCFeaturesEnum)25*eca53ba6SRoland Levillain TEST(CpustringsPPCTest, PPCFeaturesEnum) {
26*eca53ba6SRoland Levillain    const char *last_name = GetPPCFeaturesEnumName(PPC_LAST_);
27*eca53ba6SRoland Levillain    EXPECT_STREQ(last_name, "unknown_feature");
28*eca53ba6SRoland Levillain    for (int i = static_cast<int>(PPC_32); i != static_cast<int>(PPC_LAST_); ++i) {
29*eca53ba6SRoland Levillain       const auto feature = static_cast<PPCFeaturesEnum>(i);
30*eca53ba6SRoland Levillain       const char *name = GetPPCFeaturesEnumName(feature);
31*eca53ba6SRoland Levillain       ASSERT_FALSE(name == nullptr);
32*eca53ba6SRoland Levillain       EXPECT_STRNE(name, "");
33*eca53ba6SRoland Levillain       EXPECT_STRNE(name, last_name);
34*eca53ba6SRoland Levillain    }
35*eca53ba6SRoland Levillain }
36*eca53ba6SRoland Levillain 
TEST(CpustringsPPCTest,FromHardwareCap)37*eca53ba6SRoland Levillain TEST(CpustringsPPCTest, FromHardwareCap) {
38*eca53ba6SRoland Levillain   ResetHwcaps();
39*eca53ba6SRoland Levillain   SetHardwareCapabilities(PPC_FEATURE_HAS_FPU | PPC_FEATURE_HAS_VSX,
40*eca53ba6SRoland Levillain                           PPC_FEATURE2_ARCH_3_00);
41*eca53ba6SRoland Levillain   GetEmptyFilesystem();  // disabling /proc/cpuinfo
42*eca53ba6SRoland Levillain   const auto info = GetPPCInfo();
43*eca53ba6SRoland Levillain   EXPECT_TRUE(info.features.fpu);
44*eca53ba6SRoland Levillain   EXPECT_FALSE(info.features.mmu);
45*eca53ba6SRoland Levillain   EXPECT_TRUE(info.features.vsx);
46*eca53ba6SRoland Levillain   EXPECT_TRUE(info.features.arch300);
47*eca53ba6SRoland Levillain   EXPECT_FALSE(info.features.power4);
48*eca53ba6SRoland Levillain   EXPECT_FALSE(info.features.altivec);
49*eca53ba6SRoland Levillain   EXPECT_FALSE(info.features.vcrypto);
50*eca53ba6SRoland Levillain   EXPECT_FALSE(info.features.htm);
51*eca53ba6SRoland Levillain }
52*eca53ba6SRoland Levillain 
TEST(CpustringsPPCTest,Blade)53*eca53ba6SRoland Levillain TEST(CpustringsPPCTest, Blade) {
54*eca53ba6SRoland Levillain   ResetHwcaps();
55*eca53ba6SRoland Levillain   auto& fs = GetEmptyFilesystem();
56*eca53ba6SRoland Levillain   fs.CreateFile("/proc/cpuinfo",
57*eca53ba6SRoland Levillain                 R"(processor       : 14
58*eca53ba6SRoland Levillain cpu             : POWER7 (architected), altivec supported
59*eca53ba6SRoland Levillain clock           : 3000.000000MHz
60*eca53ba6SRoland Levillain revision        : 2.1 (pvr 003f 0201)
61*eca53ba6SRoland Levillain 
62*eca53ba6SRoland Levillain processor       : 15
63*eca53ba6SRoland Levillain cpu             : POWER7 (architected), altivec supported
64*eca53ba6SRoland Levillain clock           : 3000.000000MHz
65*eca53ba6SRoland Levillain revision        : 2.1 (pvr 003f 0201)
66*eca53ba6SRoland Levillain 
67*eca53ba6SRoland Levillain timebase        : 512000000
68*eca53ba6SRoland Levillain platform        : pSeries
69*eca53ba6SRoland Levillain model           : IBM,8406-70Y
70*eca53ba6SRoland Levillain machine         : CHRP IBM,8406-70Y)");
71*eca53ba6SRoland Levillain   SetPlatformPointer("power7");
72*eca53ba6SRoland Levillain   SetBasePlatformPointer("power8");
73*eca53ba6SRoland Levillain   const auto strings = GetPPCPlatformStrings();
74*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.platform, "pSeries");
75*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.model, "IBM,8406-70Y");
76*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.machine, "CHRP IBM,8406-70Y");
77*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.cpu, "POWER7 (architected), altivec supported");
78*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.type.platform, "power7");
79*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.type.base_platform, "power8");
80*eca53ba6SRoland Levillain }
81*eca53ba6SRoland Levillain 
TEST(CpustringsPPCTest,Firestone)82*eca53ba6SRoland Levillain TEST(CpustringsPPCTest, Firestone) {
83*eca53ba6SRoland Levillain   ResetHwcaps();
84*eca53ba6SRoland Levillain   auto& fs = GetEmptyFilesystem();
85*eca53ba6SRoland Levillain   fs.CreateFile("/proc/cpuinfo",
86*eca53ba6SRoland Levillain                 R"(processor       : 126
87*eca53ba6SRoland Levillain cpu             : POWER8 (raw), altivec supported
88*eca53ba6SRoland Levillain clock           : 2061.000000MHz
89*eca53ba6SRoland Levillain revision        : 2.0 (pvr 004d 0200)
90*eca53ba6SRoland Levillain 
91*eca53ba6SRoland Levillain processor       : 127
92*eca53ba6SRoland Levillain cpu             : POWER8 (raw), altivec supported
93*eca53ba6SRoland Levillain clock           : 2061.000000MHz
94*eca53ba6SRoland Levillain revision        : 2.0 (pvr 004d 0200)
95*eca53ba6SRoland Levillain 
96*eca53ba6SRoland Levillain timebase        : 512000000
97*eca53ba6SRoland Levillain platform        : PowerNV
98*eca53ba6SRoland Levillain model           : 8335-GTA
99*eca53ba6SRoland Levillain machine         : PowerNV 8335-GTA
100*eca53ba6SRoland Levillain firmware        : OPAL v3)");
101*eca53ba6SRoland Levillain   const auto strings = GetPPCPlatformStrings();
102*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.platform, "PowerNV");
103*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.model, "8335-GTA");
104*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.machine, "PowerNV 8335-GTA");
105*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.cpu, "POWER8 (raw), altivec supported");
106*eca53ba6SRoland Levillain }
107*eca53ba6SRoland Levillain 
TEST(CpustringsPPCTest,w8)108*eca53ba6SRoland Levillain TEST(CpustringsPPCTest, w8) {
109*eca53ba6SRoland Levillain   ResetHwcaps();
110*eca53ba6SRoland Levillain   auto& fs = GetEmptyFilesystem();
111*eca53ba6SRoland Levillain   fs.CreateFile("/proc/cpuinfo",
112*eca53ba6SRoland Levillain                 R"(processor       : 143
113*eca53ba6SRoland Levillain cpu             : POWER9, altivec supported
114*eca53ba6SRoland Levillain clock           : 2300.000000MHz
115*eca53ba6SRoland Levillain revision        : 2.2 (pvr 004e 1202)
116*eca53ba6SRoland Levillain 
117*eca53ba6SRoland Levillain timebase        : 512000000
118*eca53ba6SRoland Levillain platform        : PowerNV
119*eca53ba6SRoland Levillain model           : 0000000000000000
120*eca53ba6SRoland Levillain machine         : PowerNV 0000000000000000
121*eca53ba6SRoland Levillain firmware        : OPAL
122*eca53ba6SRoland Levillain MMU             : Radix)");
123*eca53ba6SRoland Levillain   const auto strings = GetPPCPlatformStrings();
124*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.platform, "PowerNV");
125*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.model, "0000000000000000");
126*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.machine, "PowerNV 0000000000000000");
127*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.cpu, "POWER9, altivec supported");
128*eca53ba6SRoland Levillain }
129*eca53ba6SRoland Levillain 
130*eca53ba6SRoland Levillain }  // namespace
131*eca53ba6SRoland Levillain }  // namespace cpu_features
132