xref: /aosp_15_r20/external/cpu_features/test/cpuinfo_s390x_test.cc (revision eca53ba6d2e951e174b64682eaf56a36b8204c89)
1*eca53ba6SRoland Levillain // Copyright 2022 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_s390x.h"
16*eca53ba6SRoland Levillain #include "filesystem_for_testing.h"
17*eca53ba6SRoland Levillain #include "gtest/gtest.h"
18*eca53ba6SRoland Levillain #include "hwcaps_for_testing.h"
19*eca53ba6SRoland Levillain 
20*eca53ba6SRoland Levillain namespace cpu_features {
21*eca53ba6SRoland Levillain namespace {
22*eca53ba6SRoland Levillain 
TEST(CpustringsS390XTest,S390XFeaturesEnum)23*eca53ba6SRoland Levillain TEST(CpustringsS390XTest, S390XFeaturesEnum) {
24*eca53ba6SRoland Levillain    const char *last_name = GetS390XFeaturesEnumName(S390X_LAST_);
25*eca53ba6SRoland Levillain    EXPECT_STREQ(last_name, "unknown_feature");
26*eca53ba6SRoland Levillain    for (int i = static_cast<int>(S390_ZARCH); i != static_cast<int>(S390X_LAST_); ++i) {
27*eca53ba6SRoland Levillain       const auto feature = static_cast<S390XFeaturesEnum>(i);
28*eca53ba6SRoland Levillain       const char *name = GetS390XFeaturesEnumName(feature);
29*eca53ba6SRoland Levillain       ASSERT_FALSE(name == nullptr);
30*eca53ba6SRoland Levillain       EXPECT_STRNE(name, "");
31*eca53ba6SRoland Levillain       EXPECT_STRNE(name, last_name);
32*eca53ba6SRoland Levillain    }
33*eca53ba6SRoland Levillain }
34*eca53ba6SRoland Levillain 
TEST(CpustringsS390XTest,FromHardwareCap)35*eca53ba6SRoland Levillain TEST(CpustringsS390XTest, FromHardwareCap) {
36*eca53ba6SRoland Levillain   ResetHwcaps();
37*eca53ba6SRoland Levillain   SetHardwareCapabilities(HWCAP_S390_ESAN3 | HWCAP_S390_HPAGE |
38*eca53ba6SRoland Levillain           HWCAP_S390_NNPA | HWCAP_S390_SIE, 0);
39*eca53ba6SRoland Levillain   GetEmptyFilesystem();  // disabling /proc/cpuinfo
40*eca53ba6SRoland Levillain   const auto info = GetS390XInfo();
41*eca53ba6SRoland Levillain   EXPECT_TRUE(info.features.esan3);
42*eca53ba6SRoland Levillain   EXPECT_TRUE(info.features.edat);
43*eca53ba6SRoland Levillain   EXPECT_TRUE(info.features.nnpa);
44*eca53ba6SRoland Levillain   EXPECT_TRUE(info.features.sie);
45*eca53ba6SRoland Levillain   EXPECT_FALSE(info.features.msa);
46*eca53ba6SRoland Levillain   EXPECT_FALSE(info.features.stfle);
47*eca53ba6SRoland Levillain   EXPECT_FALSE(info.features.vxp2);
48*eca53ba6SRoland Levillain   EXPECT_FALSE(info.features.pcimio);
49*eca53ba6SRoland Levillain }
50*eca53ba6SRoland Levillain 
TEST(CpustringsS390XTest,z16)51*eca53ba6SRoland Levillain TEST(CpustringsS390XTest, z16) {
52*eca53ba6SRoland Levillain   ResetHwcaps();
53*eca53ba6SRoland Levillain   auto& fs = GetEmptyFilesystem();
54*eca53ba6SRoland Levillain   fs.CreateFile("/proc/cpuinfo",
55*eca53ba6SRoland Levillain                 R"(vendor_id       : IBM/S390
56*eca53ba6SRoland Levillain # processors    : 24
57*eca53ba6SRoland Levillain bogomips per cpu: 26315.00
58*eca53ba6SRoland Levillain max thread id   : 1
59*eca53ba6SRoland Levillain features	: esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs te vx vxd vxe gs vxe2 vxp sort dflt vxp2 nnpa pcimio sie )");
60*eca53ba6SRoland Levillain   SetPlatformPointer("z16");
61*eca53ba6SRoland Levillain   const auto strings = GetS390XPlatformStrings();
62*eca53ba6SRoland Levillain   EXPECT_EQ(strings.num_processors, 24);
63*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.type.platform, "z16");
64*eca53ba6SRoland Levillain }
65*eca53ba6SRoland Levillain 
TEST(CpustringsS390XTest,z15)66*eca53ba6SRoland Levillain TEST(CpustringsS390XTest, z15) {
67*eca53ba6SRoland Levillain   ResetHwcaps();
68*eca53ba6SRoland Levillain   auto& fs = GetEmptyFilesystem();
69*eca53ba6SRoland Levillain   fs.CreateFile("/proc/cpuinfo",
70*eca53ba6SRoland Levillain                 R"(vendor_id       : IBM/S390
71*eca53ba6SRoland Levillain # processors    : 2
72*eca53ba6SRoland Levillain bogomips per cpu: 24038.00
73*eca53ba6SRoland Levillain max thread id   : 1
74*eca53ba6SRoland Levillain features    : esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs te vx vxd vxe gs vxe2 vxp sort dflt sie)");
75*eca53ba6SRoland Levillain   SetPlatformPointer("z15");
76*eca53ba6SRoland Levillain   const auto strings = GetS390XPlatformStrings();
77*eca53ba6SRoland Levillain   EXPECT_EQ(strings.num_processors, 2);
78*eca53ba6SRoland Levillain   ASSERT_STREQ(strings.type.platform, "z15");
79*eca53ba6SRoland Levillain }
80*eca53ba6SRoland Levillain 
81*eca53ba6SRoland Levillain }  // namespace
82*eca53ba6SRoland Levillain }  // namespace cpu_features
83