TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / external / cpu_features / test / cpuinfo_ppc_test.cc
1 // 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
22 namespace cpu_features {
23 namespace {
24
25 void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }
26
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);
40 }
41
42 TEST(CpustringsPPCTest, Blade) {
43   DisableHardwareCapabilities();
44   auto& fs = GetEmptyFilesystem();
45   fs.CreateFile("/proc/cpuinfo",
46                 R"(processor       : 14
47 cpu             : POWER7 (architected), altivec supported
48 clock           : 3000.000000MHz
49 revision        : 2.1 (pvr 003f 0201)
50
51 processor       : 15
52 cpu             : POWER7 (architected), altivec supported
53 clock           : 3000.000000MHz
54 revision        : 2.1 (pvr 003f 0201)
55
56 timebase        : 512000000
57 platform        : pSeries
58 model           : IBM,8406-70Y
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");
68 }
69
70 TEST(CpustringsPPCTest, Firestone) {
71   DisableHardwareCapabilities();
72   auto& fs = GetEmptyFilesystem();
73   fs.CreateFile("/proc/cpuinfo",
74                 R"(processor       : 126
75 cpu             : POWER8 (raw), altivec supported
76 clock           : 2061.000000MHz
77 revision        : 2.0 (pvr 004d 0200)
78
79 processor       : 127
80 cpu             : POWER8 (raw), altivec supported
81 clock           : 2061.000000MHz
82 revision        : 2.0 (pvr 004d 0200)
83
84 timebase        : 512000000
85 platform        : PowerNV
86 model           : 8335-GTA
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");
94 }
95
96 TEST(CpustringsPPCTest, w8) {
97   DisableHardwareCapabilities();
98   auto& fs = GetEmptyFilesystem();
99   fs.CreateFile("/proc/cpuinfo",
100                 R"(processor       : 143
101 cpu             : POWER9, altivec supported
102 clock           : 2300.000000MHz
103 revision        : 2.2 (pvr 004e 1202)
104
105 timebase        : 512000000
106 platform        : PowerNV
107 model           : 0000000000000000
108 machine         : PowerNV 0000000000000000
109 firmware        : OPAL
110 MMU             : 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