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