blob: 5d5e79808710e0c3f09011548e8005a02d71303e [file] [log] [blame]
Rashmica Gupta3adafbf2018-04-23 10:46:47 +10001// Copyright 2018 IBM.
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_ppc.h"
16#include "filesystem_for_testing.h"
17#include "hwcaps_for_testing.h"
18#include "internal/string_view.h"
19
20#include "gtest/gtest.h"
21
22namespace cpu_features {
23namespace {
24
25void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
26
27TEST(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);
40}
41
42TEST(CpustringsPPCTest, Blade) {
43 DisableHardwareCapabilities();
44 auto& fs = GetEmptyFilesystem();
45 fs.CreateFile("/proc/cpuinfo",
46 R"(processor : 14
47cpu : POWER7 (architected), altivec supported
48clock : 3000.000000MHz
49revision : 2.1 (pvr 003f 0201)
50
51processor : 15
52cpu : POWER7 (architected), altivec supported
53clock : 3000.000000MHz
54revision : 2.1 (pvr 003f 0201)
55
56timebase : 512000000
57platform : pSeries
58model : IBM,8406-70Y
59machine : CHRP IBM,8406-70Y)");
Rashmica Guptac45e32f2018-05-02 14:30:25 +100060 SetPlatformTypes("power7", "power8");
Rashmica Gupta3adafbf2018-04-23 10:46:47 +100061 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");
Rashmica Guptac45e32f2018-05-02 14:30:25 +100066 ASSERT_STREQ(strings.type.platform, "power7");
67 ASSERT_STREQ(strings.type.base_platform, "power8");
Rashmica Gupta3adafbf2018-04-23 10:46:47 +100068}
69
70TEST(CpustringsPPCTest, Firestone) {
71 DisableHardwareCapabilities();
72 auto& fs = GetEmptyFilesystem();
73 fs.CreateFile("/proc/cpuinfo",
74 R"(processor : 126
75cpu : POWER8 (raw), altivec supported
76clock : 2061.000000MHz
77revision : 2.0 (pvr 004d 0200)
78
79processor : 127
80cpu : POWER8 (raw), altivec supported
81clock : 2061.000000MHz
82revision : 2.0 (pvr 004d 0200)
83
84timebase : 512000000
85platform : PowerNV
86model : 8335-GTA
87machine : PowerNV 8335-GTA
88firmware : 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");
94}
95
96TEST(CpustringsPPCTest, w8) {
97 DisableHardwareCapabilities();
98 auto& fs = GetEmptyFilesystem();
99 fs.CreateFile("/proc/cpuinfo",
100 R"(processor : 143
101cpu : POWER9, altivec supported
102clock : 2300.000000MHz
103revision : 2.2 (pvr 004e 1202)
104
105timebase : 512000000
106platform : PowerNV
107model : 0000000000000000
108machine : PowerNV 0000000000000000
109firmware : OPAL
110MMU : Radix)");
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");
116}
117
118} // namespace
119} // namespace cpu_features